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_private.h"
34 #include "util/disk_cache.h"
35 #include "util/strtod.h"
39 #include <amdgpu_drm.h>
40 #include "amdgpu_id.h"
41 #include "winsys/amdgpu/radv_amdgpu_winsys_public.h"
42 #include "ac_llvm_util.h"
43 #include "vk_format.h"
46 #include "util/debug.h"
49 radv_device_get_cache_uuid(enum radeon_family family
, void *uuid
)
51 uint32_t mesa_timestamp
, llvm_timestamp
;
53 memset(uuid
, 0, VK_UUID_SIZE
);
54 if (!disk_cache_get_function_timestamp(radv_device_get_cache_uuid
, &mesa_timestamp
) ||
55 !disk_cache_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo
, &llvm_timestamp
))
58 memcpy(uuid
, &mesa_timestamp
, 4);
59 memcpy((char*)uuid
+ 4, &llvm_timestamp
, 4);
60 memcpy((char*)uuid
+ 8, &f
, 2);
61 snprintf((char*)uuid
+ 10, VK_UUID_SIZE
- 10, "radv");
66 radv_get_device_uuid(drmDevicePtr device
, void *uuid
) {
67 memset(uuid
, 0, VK_UUID_SIZE
);
68 memcpy((char*)uuid
+ 0, &device
->businfo
.pci
->domain
, 2);
69 memcpy((char*)uuid
+ 2, &device
->businfo
.pci
->bus
, 1);
70 memcpy((char*)uuid
+ 3, &device
->businfo
.pci
->dev
, 1);
71 memcpy((char*)uuid
+ 4, &device
->businfo
.pci
->func
, 1);
74 static const VkExtensionProperties instance_extensions
[] = {
76 .extensionName
= VK_KHR_SURFACE_EXTENSION_NAME
,
79 #ifdef VK_USE_PLATFORM_XCB_KHR
81 .extensionName
= VK_KHR_XCB_SURFACE_EXTENSION_NAME
,
85 #ifdef VK_USE_PLATFORM_XLIB_KHR
87 .extensionName
= VK_KHR_XLIB_SURFACE_EXTENSION_NAME
,
91 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
93 .extensionName
= VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME
,
98 .extensionName
= VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME
,
102 .extensionName
= VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME
,
107 static const VkExtensionProperties common_device_extensions
[] = {
109 .extensionName
= VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME
,
113 .extensionName
= VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME
,
117 .extensionName
= VK_KHR_MAINTENANCE1_EXTENSION_NAME
,
121 .extensionName
= VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME
,
125 .extensionName
= VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME
,
129 .extensionName
= VK_KHR_SWAPCHAIN_EXTENSION_NAME
,
133 .extensionName
= VK_AMD_DRAW_INDIRECT_COUNT_EXTENSION_NAME
,
137 .extensionName
= VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME
,
141 .extensionName
= VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME
,
145 .extensionName
= VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME
,
149 .extensionName
= VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME
,
153 .extensionName
= VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME
,
157 .extensionName
= VK_KHR_STORAGE_BUFFER_STORAGE_CLASS_EXTENSION_NAME
,
163 radv_extensions_register(struct radv_instance
*instance
,
164 struct radv_extensions
*extensions
,
165 const VkExtensionProperties
*new_ext
,
169 VkExtensionProperties
*new_ptr
;
171 assert(new_ext
&& num_ext
> 0);
174 return VK_ERROR_INITIALIZATION_FAILED
;
176 new_size
= (extensions
->num_ext
+ num_ext
) * sizeof(VkExtensionProperties
);
177 new_ptr
= vk_realloc(&instance
->alloc
, extensions
->ext_array
,
178 new_size
, 8, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
180 /* Old array continues to be valid, update nothing */
182 return VK_ERROR_OUT_OF_HOST_MEMORY
;
184 memcpy(&new_ptr
[extensions
->num_ext
], new_ext
,
185 num_ext
* sizeof(VkExtensionProperties
));
186 extensions
->ext_array
= new_ptr
;
187 extensions
->num_ext
+= num_ext
;
193 radv_extensions_finish(struct radv_instance
*instance
,
194 struct radv_extensions
*extensions
)
199 radv_loge("Attemted to free invalid extension struct\n");
201 if (extensions
->ext_array
)
202 vk_free(&instance
->alloc
, extensions
->ext_array
);
206 is_extension_enabled(const VkExtensionProperties
*extensions
,
210 assert(extensions
&& name
);
212 for (uint32_t i
= 0; i
< num_ext
; i
++) {
213 if (strcmp(name
, extensions
[i
].extensionName
) == 0)
221 get_chip_name(enum radeon_family family
)
224 case CHIP_TAHITI
: return "AMD RADV TAHITI";
225 case CHIP_PITCAIRN
: return "AMD RADV PITCAIRN";
226 case CHIP_VERDE
: return "AMD RADV CAPE VERDE";
227 case CHIP_OLAND
: return "AMD RADV OLAND";
228 case CHIP_HAINAN
: return "AMD RADV HAINAN";
229 case CHIP_BONAIRE
: return "AMD RADV BONAIRE";
230 case CHIP_KAVERI
: return "AMD RADV KAVERI";
231 case CHIP_KABINI
: return "AMD RADV KABINI";
232 case CHIP_HAWAII
: return "AMD RADV HAWAII";
233 case CHIP_MULLINS
: return "AMD RADV MULLINS";
234 case CHIP_TONGA
: return "AMD RADV TONGA";
235 case CHIP_ICELAND
: return "AMD RADV ICELAND";
236 case CHIP_CARRIZO
: return "AMD RADV CARRIZO";
237 case CHIP_FIJI
: return "AMD RADV FIJI";
238 case CHIP_POLARIS10
: return "AMD RADV POLARIS10";
239 case CHIP_POLARIS11
: return "AMD RADV POLARIS11";
240 case CHIP_POLARIS12
: return "AMD RADV POLARIS12";
241 case CHIP_STONEY
: return "AMD RADV STONEY";
242 case CHIP_VEGA10
: return "AMD RADV VEGA";
243 case CHIP_RAVEN
: return "AMD RADV RAVEN";
244 default: return "AMD RADV unknown";
249 radv_physical_device_init(struct radv_physical_device
*device
,
250 struct radv_instance
*instance
,
251 drmDevicePtr drm_device
)
253 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
255 drmVersionPtr version
;
258 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
260 return VK_ERROR_INCOMPATIBLE_DRIVER
;
262 version
= drmGetVersion(fd
);
265 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
266 "failed to get version %s: %m", path
);
269 if (strcmp(version
->name
, "amdgpu")) {
270 drmFreeVersion(version
);
272 return VK_ERROR_INCOMPATIBLE_DRIVER
;
274 drmFreeVersion(version
);
276 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
277 device
->instance
= instance
;
278 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
279 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
281 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
282 instance
->perftest_flags
);
284 result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
288 device
->local_fd
= fd
;
289 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
290 result
= radv_init_wsi(device
);
291 if (result
!= VK_SUCCESS
) {
292 device
->ws
->destroy(device
->ws
);
296 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->uuid
)) {
297 radv_finish_wsi(device
);
298 device
->ws
->destroy(device
->ws
);
299 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
300 "cannot generate UUID");
304 result
= radv_extensions_register(instance
,
306 common_device_extensions
,
307 ARRAY_SIZE(common_device_extensions
));
308 if (result
!= VK_SUCCESS
)
311 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
312 device
->name
= get_chip_name(device
->rad_info
.family
);
314 radv_get_device_uuid(drm_device
, device
->device_uuid
);
316 if (device
->rad_info
.family
== CHIP_STONEY
||
317 device
->rad_info
.chip_class
>= GFX9
) {
318 device
->has_rbplus
= true;
319 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
;
330 radv_physical_device_finish(struct radv_physical_device
*device
)
332 radv_extensions_finish(device
->instance
, &device
->extensions
);
333 radv_finish_wsi(device
);
334 device
->ws
->destroy(device
->ws
);
335 close(device
->local_fd
);
339 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
340 VkSystemAllocationScope allocationScope
)
346 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
347 size_t align
, VkSystemAllocationScope allocationScope
)
349 return realloc(pOriginal
, size
);
353 default_free_func(void *pUserData
, void *pMemory
)
358 static const VkAllocationCallbacks default_alloc
= {
360 .pfnAllocation
= default_alloc_func
,
361 .pfnReallocation
= default_realloc_func
,
362 .pfnFree
= default_free_func
,
365 static const struct debug_control radv_debug_options
[] = {
366 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
367 {"nodcc", RADV_DEBUG_NO_DCC
},
368 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
369 {"nocache", RADV_DEBUG_NO_CACHE
},
370 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
371 {"nohiz", RADV_DEBUG_NO_HIZ
},
372 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
373 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
374 {"allbos", RADV_DEBUG_ALL_BOS
},
375 {"noibs", RADV_DEBUG_NO_IBS
},
379 static const struct debug_control radv_perftest_options
[] = {
380 {"batchchain", RADV_PERFTEST_BATCHCHAIN
},
381 {"sisched", RADV_PERFTEST_SISCHED
},
385 VkResult
radv_CreateInstance(
386 const VkInstanceCreateInfo
* pCreateInfo
,
387 const VkAllocationCallbacks
* pAllocator
,
388 VkInstance
* pInstance
)
390 struct radv_instance
*instance
;
392 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
394 uint32_t client_version
;
395 if (pCreateInfo
->pApplicationInfo
&&
396 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
397 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
399 client_version
= VK_MAKE_VERSION(1, 0, 0);
402 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
403 client_version
> VK_MAKE_VERSION(1, 0, 0xfff)) {
404 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
405 "Client requested version %d.%d.%d",
406 VK_VERSION_MAJOR(client_version
),
407 VK_VERSION_MINOR(client_version
),
408 VK_VERSION_PATCH(client_version
));
411 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
412 if (!is_extension_enabled(instance_extensions
,
413 ARRAY_SIZE(instance_extensions
),
414 pCreateInfo
->ppEnabledExtensionNames
[i
]))
415 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
418 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
419 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
421 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
423 memset(instance
, 0, sizeof(*instance
));
425 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
428 instance
->alloc
= *pAllocator
;
430 instance
->alloc
= default_alloc
;
432 instance
->apiVersion
= client_version
;
433 instance
->physicalDeviceCount
= -1;
437 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
439 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
442 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
443 radv_perftest_options
);
445 *pInstance
= radv_instance_to_handle(instance
);
450 void radv_DestroyInstance(
451 VkInstance _instance
,
452 const VkAllocationCallbacks
* pAllocator
)
454 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
459 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
460 radv_physical_device_finish(instance
->physicalDevices
+ i
);
463 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
467 vk_free(&instance
->alloc
, instance
);
471 radv_enumerate_devices(struct radv_instance
*instance
)
473 /* TODO: Check for more devices ? */
474 drmDevicePtr devices
[8];
475 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
478 instance
->physicalDeviceCount
= 0;
480 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
482 return VK_ERROR_INCOMPATIBLE_DRIVER
;
484 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
485 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
486 devices
[i
]->bustype
== DRM_BUS_PCI
&&
487 devices
[i
]->deviceinfo
.pci
->vendor_id
== 0x1002) {
489 result
= radv_physical_device_init(instance
->physicalDevices
+
490 instance
->physicalDeviceCount
,
493 if (result
== VK_SUCCESS
)
494 ++instance
->physicalDeviceCount
;
495 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
499 drmFreeDevices(devices
, max_devices
);
504 VkResult
radv_EnumeratePhysicalDevices(
505 VkInstance _instance
,
506 uint32_t* pPhysicalDeviceCount
,
507 VkPhysicalDevice
* pPhysicalDevices
)
509 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
512 if (instance
->physicalDeviceCount
< 0) {
513 result
= radv_enumerate_devices(instance
);
514 if (result
!= VK_SUCCESS
&&
515 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
519 if (!pPhysicalDevices
) {
520 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
522 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
523 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
524 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
527 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
531 void radv_GetPhysicalDeviceFeatures(
532 VkPhysicalDevice physicalDevice
,
533 VkPhysicalDeviceFeatures
* pFeatures
)
535 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
536 bool is_gfx9
= pdevice
->rad_info
.chip_class
>= GFX9
;
537 memset(pFeatures
, 0, sizeof(*pFeatures
));
539 *pFeatures
= (VkPhysicalDeviceFeatures
) {
540 .robustBufferAccess
= true,
541 .fullDrawIndexUint32
= true,
542 .imageCubeArray
= true,
543 .independentBlend
= true,
544 .geometryShader
= !is_gfx9
,
545 .tessellationShader
= !is_gfx9
,
546 .sampleRateShading
= false,
547 .dualSrcBlend
= true,
549 .multiDrawIndirect
= true,
550 .drawIndirectFirstInstance
= true,
552 .depthBiasClamp
= true,
553 .fillModeNonSolid
= true,
558 .multiViewport
= true,
559 .samplerAnisotropy
= true,
560 .textureCompressionETC2
= false,
561 .textureCompressionASTC_LDR
= false,
562 .textureCompressionBC
= true,
563 .occlusionQueryPrecise
= true,
564 .pipelineStatisticsQuery
= true,
565 .vertexPipelineStoresAndAtomics
= true,
566 .fragmentStoresAndAtomics
= true,
567 .shaderTessellationAndGeometryPointSize
= true,
568 .shaderImageGatherExtended
= true,
569 .shaderStorageImageExtendedFormats
= true,
570 .shaderStorageImageMultisample
= false,
571 .shaderUniformBufferArrayDynamicIndexing
= true,
572 .shaderSampledImageArrayDynamicIndexing
= true,
573 .shaderStorageBufferArrayDynamicIndexing
= true,
574 .shaderStorageImageArrayDynamicIndexing
= true,
575 .shaderStorageImageReadWithoutFormat
= true,
576 .shaderStorageImageWriteWithoutFormat
= true,
577 .shaderClipDistance
= true,
578 .shaderCullDistance
= true,
579 .shaderFloat64
= true,
581 .shaderInt16
= false,
582 .sparseBinding
= true,
583 .variableMultisampleRate
= true,
584 .inheritedQueries
= true,
588 void radv_GetPhysicalDeviceFeatures2KHR(
589 VkPhysicalDevice physicalDevice
,
590 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
592 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
595 void radv_GetPhysicalDeviceProperties(
596 VkPhysicalDevice physicalDevice
,
597 VkPhysicalDeviceProperties
* pProperties
)
599 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
600 VkSampleCountFlags sample_counts
= 0xf;
602 /* make sure that the entire descriptor set is addressable with a signed
603 * 32-bit int. So the sum of all limits scaled by descriptor size has to
604 * be at most 2 GiB. the combined image & samples object count as one of
605 * both. This limit is for the pipeline layout, not for the set layout, but
606 * there is no set limit, so we just set a pipeline limit. I don't think
607 * any app is going to hit this soon. */
608 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
609 (32 /* uniform buffer, 32 due to potential space wasted on alignement */ +
610 32 /* storage buffer, 32 due to potential space wasted on alignement */ +
611 32 /* sampler, largest when combined with image */ +
612 64 /* sampled image */ +
613 64 /* storage image */);
615 VkPhysicalDeviceLimits limits
= {
616 .maxImageDimension1D
= (1 << 14),
617 .maxImageDimension2D
= (1 << 14),
618 .maxImageDimension3D
= (1 << 11),
619 .maxImageDimensionCube
= (1 << 14),
620 .maxImageArrayLayers
= (1 << 11),
621 .maxTexelBufferElements
= 128 * 1024 * 1024,
622 .maxUniformBufferRange
= UINT32_MAX
,
623 .maxStorageBufferRange
= UINT32_MAX
,
624 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
625 .maxMemoryAllocationCount
= UINT32_MAX
,
626 .maxSamplerAllocationCount
= 64 * 1024,
627 .bufferImageGranularity
= 64, /* A cache line */
628 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
629 .maxBoundDescriptorSets
= MAX_SETS
,
630 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
631 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
632 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
633 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
634 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
635 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
636 .maxPerStageResources
= max_descriptor_set_size
,
637 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
638 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
639 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
640 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
641 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
642 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
643 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
644 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
645 .maxVertexInputAttributes
= 32,
646 .maxVertexInputBindings
= 32,
647 .maxVertexInputAttributeOffset
= 2047,
648 .maxVertexInputBindingStride
= 2048,
649 .maxVertexOutputComponents
= 128,
650 .maxTessellationGenerationLevel
= 64,
651 .maxTessellationPatchSize
= 32,
652 .maxTessellationControlPerVertexInputComponents
= 128,
653 .maxTessellationControlPerVertexOutputComponents
= 128,
654 .maxTessellationControlPerPatchOutputComponents
= 120,
655 .maxTessellationControlTotalOutputComponents
= 4096,
656 .maxTessellationEvaluationInputComponents
= 128,
657 .maxTessellationEvaluationOutputComponents
= 128,
658 .maxGeometryShaderInvocations
= 127,
659 .maxGeometryInputComponents
= 64,
660 .maxGeometryOutputComponents
= 128,
661 .maxGeometryOutputVertices
= 256,
662 .maxGeometryTotalOutputComponents
= 1024,
663 .maxFragmentInputComponents
= 128,
664 .maxFragmentOutputAttachments
= 8,
665 .maxFragmentDualSrcAttachments
= 1,
666 .maxFragmentCombinedOutputResources
= 8,
667 .maxComputeSharedMemorySize
= 32768,
668 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
669 .maxComputeWorkGroupInvocations
= 2048,
670 .maxComputeWorkGroupSize
= {
675 .subPixelPrecisionBits
= 4 /* FIXME */,
676 .subTexelPrecisionBits
= 4 /* FIXME */,
677 .mipmapPrecisionBits
= 4 /* FIXME */,
678 .maxDrawIndexedIndexValue
= UINT32_MAX
,
679 .maxDrawIndirectCount
= UINT32_MAX
,
680 .maxSamplerLodBias
= 16,
681 .maxSamplerAnisotropy
= 16,
682 .maxViewports
= MAX_VIEWPORTS
,
683 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
684 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
685 .viewportSubPixelBits
= 13, /* We take a float? */
686 .minMemoryMapAlignment
= 4096, /* A page */
687 .minTexelBufferOffsetAlignment
= 1,
688 .minUniformBufferOffsetAlignment
= 4,
689 .minStorageBufferOffsetAlignment
= 4,
690 .minTexelOffset
= -32,
691 .maxTexelOffset
= 31,
692 .minTexelGatherOffset
= -32,
693 .maxTexelGatherOffset
= 31,
694 .minInterpolationOffset
= -2,
695 .maxInterpolationOffset
= 2,
696 .subPixelInterpolationOffsetBits
= 8,
697 .maxFramebufferWidth
= (1 << 14),
698 .maxFramebufferHeight
= (1 << 14),
699 .maxFramebufferLayers
= (1 << 10),
700 .framebufferColorSampleCounts
= sample_counts
,
701 .framebufferDepthSampleCounts
= sample_counts
,
702 .framebufferStencilSampleCounts
= sample_counts
,
703 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
704 .maxColorAttachments
= MAX_RTS
,
705 .sampledImageColorSampleCounts
= sample_counts
,
706 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
707 .sampledImageDepthSampleCounts
= sample_counts
,
708 .sampledImageStencilSampleCounts
= sample_counts
,
709 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
710 .maxSampleMaskWords
= 1,
711 .timestampComputeAndGraphics
= true,
712 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
713 .maxClipDistances
= 8,
714 .maxCullDistances
= 8,
715 .maxCombinedClipAndCullDistances
= 8,
716 .discreteQueuePriorities
= 1,
717 .pointSizeRange
= { 0.125, 255.875 },
718 .lineWidthRange
= { 0.0, 7.9921875 },
719 .pointSizeGranularity
= (1.0 / 8.0),
720 .lineWidthGranularity
= (1.0 / 128.0),
721 .strictLines
= false, /* FINISHME */
722 .standardSampleLocations
= true,
723 .optimalBufferCopyOffsetAlignment
= 128,
724 .optimalBufferCopyRowPitchAlignment
= 128,
725 .nonCoherentAtomSize
= 64,
728 *pProperties
= (VkPhysicalDeviceProperties
) {
729 .apiVersion
= VK_MAKE_VERSION(1, 0, 42),
730 .driverVersion
= vk_get_driver_version(),
732 .deviceID
= pdevice
->rad_info
.pci_id
,
733 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
735 .sparseProperties
= {0},
738 strcpy(pProperties
->deviceName
, pdevice
->name
);
739 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->uuid
, VK_UUID_SIZE
);
742 void radv_GetPhysicalDeviceProperties2KHR(
743 VkPhysicalDevice physicalDevice
,
744 VkPhysicalDeviceProperties2KHR
*pProperties
)
746 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
747 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
749 vk_foreach_struct(ext
, pProperties
->pNext
) {
750 switch (ext
->sType
) {
751 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
752 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
753 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
754 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
757 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
758 VkPhysicalDeviceIDPropertiesKHR
*properties
= (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
759 radv_device_get_cache_uuid(0, properties
->driverUUID
);
760 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
761 properties
->deviceLUIDValid
= false;
770 static void radv_get_physical_device_queue_family_properties(
771 struct radv_physical_device
* pdevice
,
773 VkQueueFamilyProperties
** pQueueFamilyProperties
)
775 int num_queue_families
= 1;
777 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
778 pdevice
->rad_info
.chip_class
>= CIK
&&
779 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
780 num_queue_families
++;
782 if (pQueueFamilyProperties
== NULL
) {
783 *pCount
= num_queue_families
;
792 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
793 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
794 VK_QUEUE_COMPUTE_BIT
|
795 VK_QUEUE_TRANSFER_BIT
|
796 VK_QUEUE_SPARSE_BINDING_BIT
,
798 .timestampValidBits
= 64,
799 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
804 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
805 pdevice
->rad_info
.chip_class
>= CIK
&&
806 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
808 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
809 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
810 VK_QUEUE_TRANSFER_BIT
|
811 VK_QUEUE_SPARSE_BINDING_BIT
,
812 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
813 .timestampValidBits
= 64,
814 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
822 void radv_GetPhysicalDeviceQueueFamilyProperties(
823 VkPhysicalDevice physicalDevice
,
825 VkQueueFamilyProperties
* pQueueFamilyProperties
)
827 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
828 if (!pQueueFamilyProperties
) {
829 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
832 VkQueueFamilyProperties
*properties
[] = {
833 pQueueFamilyProperties
+ 0,
834 pQueueFamilyProperties
+ 1,
835 pQueueFamilyProperties
+ 2,
837 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
838 assert(*pCount
<= 3);
841 void radv_GetPhysicalDeviceQueueFamilyProperties2KHR(
842 VkPhysicalDevice physicalDevice
,
844 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
846 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
847 if (!pQueueFamilyProperties
) {
848 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
851 VkQueueFamilyProperties
*properties
[] = {
852 &pQueueFamilyProperties
[0].queueFamilyProperties
,
853 &pQueueFamilyProperties
[1].queueFamilyProperties
,
854 &pQueueFamilyProperties
[2].queueFamilyProperties
,
856 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
857 assert(*pCount
<= 3);
860 void radv_GetPhysicalDeviceMemoryProperties(
861 VkPhysicalDevice physicalDevice
,
862 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
864 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
866 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
868 pMemoryProperties
->memoryTypeCount
= RADV_MEM_TYPE_COUNT
;
869 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_VRAM
] = (VkMemoryType
) {
870 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
871 .heapIndex
= RADV_MEM_HEAP_VRAM
,
873 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_GTT_WRITE_COMBINE
] = (VkMemoryType
) {
874 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
875 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
876 .heapIndex
= RADV_MEM_HEAP_GTT
,
878 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_VRAM_CPU_ACCESS
] = (VkMemoryType
) {
879 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
880 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
881 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
882 .heapIndex
= RADV_MEM_HEAP_VRAM_CPU_ACCESS
,
884 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_GTT_CACHED
] = (VkMemoryType
) {
885 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
886 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
887 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
888 .heapIndex
= RADV_MEM_HEAP_GTT
,
891 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
893 pMemoryProperties
->memoryHeapCount
= RADV_MEM_HEAP_COUNT
;
894 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_VRAM
] = (VkMemoryHeap
) {
895 .size
= physical_device
->rad_info
.vram_size
-
896 physical_device
->rad_info
.vram_vis_size
,
897 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
899 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_VRAM_CPU_ACCESS
] = (VkMemoryHeap
) {
900 .size
= physical_device
->rad_info
.vram_vis_size
,
901 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
903 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_GTT
] = (VkMemoryHeap
) {
904 .size
= physical_device
->rad_info
.gart_size
,
909 void radv_GetPhysicalDeviceMemoryProperties2KHR(
910 VkPhysicalDevice physicalDevice
,
911 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
913 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
914 &pMemoryProperties
->memoryProperties
);
918 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
919 int queue_family_index
, int idx
)
921 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
922 queue
->device
= device
;
923 queue
->queue_family_index
= queue_family_index
;
924 queue
->queue_idx
= idx
;
926 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
);
928 return VK_ERROR_OUT_OF_HOST_MEMORY
;
934 radv_queue_finish(struct radv_queue
*queue
)
937 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
939 if (queue
->initial_preamble_cs
)
940 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
941 if (queue
->continue_preamble_cs
)
942 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
943 if (queue
->descriptor_bo
)
944 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
945 if (queue
->scratch_bo
)
946 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
947 if (queue
->esgs_ring_bo
)
948 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
949 if (queue
->gsvs_ring_bo
)
950 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
951 if (queue
->tess_factor_ring_bo
)
952 queue
->device
->ws
->buffer_destroy(queue
->tess_factor_ring_bo
);
953 if (queue
->tess_offchip_ring_bo
)
954 queue
->device
->ws
->buffer_destroy(queue
->tess_offchip_ring_bo
);
955 if (queue
->compute_scratch_bo
)
956 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
960 radv_device_init_gs_info(struct radv_device
*device
)
962 switch (device
->physical_device
->rad_info
.family
) {
971 device
->gs_table_depth
= 16;
985 device
->gs_table_depth
= 32;
988 unreachable("unknown GPU");
992 VkResult
radv_CreateDevice(
993 VkPhysicalDevice physicalDevice
,
994 const VkDeviceCreateInfo
* pCreateInfo
,
995 const VkAllocationCallbacks
* pAllocator
,
998 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1000 struct radv_device
*device
;
1002 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1003 if (!is_extension_enabled(physical_device
->extensions
.ext_array
,
1004 physical_device
->extensions
.num_ext
,
1005 pCreateInfo
->ppEnabledExtensionNames
[i
]))
1006 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1009 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
1011 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1013 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1015 memset(device
, 0, sizeof(*device
));
1017 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1018 device
->instance
= physical_device
->instance
;
1019 device
->physical_device
= physical_device
;
1021 device
->debug_flags
= device
->instance
->debug_flags
;
1023 device
->ws
= physical_device
->ws
;
1025 device
->alloc
= *pAllocator
;
1027 device
->alloc
= physical_device
->instance
->alloc
;
1029 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1030 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1031 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1033 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1034 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1035 if (!device
->queues
[qfi
]) {
1036 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1040 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1042 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1044 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1045 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
], qfi
, q
);
1046 if (result
!= VK_SUCCESS
)
1051 #if HAVE_LLVM < 0x0400
1052 device
->llvm_supports_spill
= false;
1054 device
->llvm_supports_spill
= true;
1057 /* The maximum number of scratch waves. Scratch space isn't divided
1058 * evenly between CUs. The number is only a function of the number of CUs.
1059 * We can decrease the constant to decrease the scratch buffer size.
1061 * sctx->scratch_waves must be >= the maximum posible size of
1062 * 1 threadgroup, so that the hw doesn't hang from being unable
1065 * The recommended value is 4 per CU at most. Higher numbers don't
1066 * bring much benefit, but they still occupy chip resources (think
1067 * async compute). I've seen ~2% performance difference between 4 and 32.
1069 uint32_t max_threads_per_block
= 2048;
1070 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1071 max_threads_per_block
/ 64);
1073 radv_device_init_gs_info(device
);
1075 device
->tess_offchip_block_dw_size
=
1076 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1077 device
->has_distributed_tess
=
1078 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1079 device
->physical_device
->rad_info
.max_se
>= 2;
1081 result
= radv_device_init_meta(device
);
1082 if (result
!= VK_SUCCESS
)
1085 radv_device_init_msaa(device
);
1087 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1088 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1090 case RADV_QUEUE_GENERAL
:
1091 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1092 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1093 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1095 case RADV_QUEUE_COMPUTE
:
1096 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1097 radeon_emit(device
->empty_cs
[family
], 0);
1100 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1102 device
->flush_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1104 case RADV_QUEUE_GENERAL
:
1105 case RADV_QUEUE_COMPUTE
:
1106 si_cs_emit_cache_flush(device
->flush_cs
[family
],
1108 device
->physical_device
->rad_info
.chip_class
,
1110 family
== RADV_QUEUE_COMPUTE
&& device
->physical_device
->rad_info
.chip_class
>= CIK
,
1111 RADV_CMD_FLAG_INV_ICACHE
|
1112 RADV_CMD_FLAG_INV_SMEM_L1
|
1113 RADV_CMD_FLAG_INV_VMEM_L1
|
1114 RADV_CMD_FLAG_INV_GLOBAL_L2
);
1117 device
->ws
->cs_finalize(device
->flush_cs
[family
]);
1119 device
->flush_shader_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1121 case RADV_QUEUE_GENERAL
:
1122 case RADV_QUEUE_COMPUTE
:
1123 si_cs_emit_cache_flush(device
->flush_shader_cs
[family
],
1125 device
->physical_device
->rad_info
.chip_class
,
1127 family
== RADV_QUEUE_COMPUTE
&& device
->physical_device
->rad_info
.chip_class
>= CIK
,
1128 family
== RADV_QUEUE_COMPUTE
? RADV_CMD_FLAG_CS_PARTIAL_FLUSH
: (RADV_CMD_FLAG_CS_PARTIAL_FLUSH
| RADV_CMD_FLAG_PS_PARTIAL_FLUSH
) |
1129 RADV_CMD_FLAG_INV_ICACHE
|
1130 RADV_CMD_FLAG_INV_SMEM_L1
|
1131 RADV_CMD_FLAG_INV_VMEM_L1
|
1132 RADV_CMD_FLAG_INV_GLOBAL_L2
);
1135 device
->ws
->cs_finalize(device
->flush_shader_cs
[family
]);
1138 if (getenv("RADV_TRACE_FILE")) {
1139 device
->trace_bo
= device
->ws
->buffer_create(device
->ws
, 4096, 8,
1140 RADEON_DOMAIN_VRAM
, RADEON_FLAG_CPU_ACCESS
);
1141 if (!device
->trace_bo
)
1144 device
->trace_id_ptr
= device
->ws
->buffer_map(device
->trace_bo
);
1145 if (!device
->trace_id_ptr
)
1149 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1150 cik_create_gfx_config(device
);
1152 VkPipelineCacheCreateInfo ci
;
1153 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1156 ci
.pInitialData
= NULL
;
1157 ci
.initialDataSize
= 0;
1159 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1161 if (result
!= VK_SUCCESS
)
1164 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1166 *pDevice
= radv_device_to_handle(device
);
1170 if (device
->trace_bo
)
1171 device
->ws
->buffer_destroy(device
->trace_bo
);
1173 if (device
->gfx_init
)
1174 device
->ws
->buffer_destroy(device
->gfx_init
);
1176 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1177 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1178 radv_queue_finish(&device
->queues
[i
][q
]);
1179 if (device
->queue_count
[i
])
1180 vk_free(&device
->alloc
, device
->queues
[i
]);
1183 vk_free(&device
->alloc
, device
);
1187 void radv_DestroyDevice(
1189 const VkAllocationCallbacks
* pAllocator
)
1191 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1196 if (device
->trace_bo
)
1197 device
->ws
->buffer_destroy(device
->trace_bo
);
1199 if (device
->gfx_init
)
1200 device
->ws
->buffer_destroy(device
->gfx_init
);
1202 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1203 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1204 radv_queue_finish(&device
->queues
[i
][q
]);
1205 if (device
->queue_count
[i
])
1206 vk_free(&device
->alloc
, device
->queues
[i
]);
1207 if (device
->empty_cs
[i
])
1208 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1209 if (device
->flush_cs
[i
])
1210 device
->ws
->cs_destroy(device
->flush_cs
[i
]);
1211 if (device
->flush_shader_cs
[i
])
1212 device
->ws
->cs_destroy(device
->flush_shader_cs
[i
]);
1214 radv_device_finish_meta(device
);
1216 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1217 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1219 vk_free(&device
->alloc
, device
);
1222 VkResult
radv_EnumerateInstanceExtensionProperties(
1223 const char* pLayerName
,
1224 uint32_t* pPropertyCount
,
1225 VkExtensionProperties
* pProperties
)
1227 if (pProperties
== NULL
) {
1228 *pPropertyCount
= ARRAY_SIZE(instance_extensions
);
1232 *pPropertyCount
= MIN2(*pPropertyCount
, ARRAY_SIZE(instance_extensions
));
1233 typed_memcpy(pProperties
, instance_extensions
, *pPropertyCount
);
1235 if (*pPropertyCount
< ARRAY_SIZE(instance_extensions
))
1236 return VK_INCOMPLETE
;
1241 VkResult
radv_EnumerateDeviceExtensionProperties(
1242 VkPhysicalDevice physicalDevice
,
1243 const char* pLayerName
,
1244 uint32_t* pPropertyCount
,
1245 VkExtensionProperties
* pProperties
)
1247 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1249 if (pProperties
== NULL
) {
1250 *pPropertyCount
= pdevice
->extensions
.num_ext
;
1254 *pPropertyCount
= MIN2(*pPropertyCount
, pdevice
->extensions
.num_ext
);
1255 typed_memcpy(pProperties
, pdevice
->extensions
.ext_array
, *pPropertyCount
);
1257 if (*pPropertyCount
< pdevice
->extensions
.num_ext
)
1258 return VK_INCOMPLETE
;
1263 VkResult
radv_EnumerateInstanceLayerProperties(
1264 uint32_t* pPropertyCount
,
1265 VkLayerProperties
* pProperties
)
1267 if (pProperties
== NULL
) {
1268 *pPropertyCount
= 0;
1272 /* None supported at this time */
1273 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1276 VkResult
radv_EnumerateDeviceLayerProperties(
1277 VkPhysicalDevice physicalDevice
,
1278 uint32_t* pPropertyCount
,
1279 VkLayerProperties
* pProperties
)
1281 if (pProperties
== NULL
) {
1282 *pPropertyCount
= 0;
1286 /* None supported at this time */
1287 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1290 void radv_GetDeviceQueue(
1292 uint32_t queueFamilyIndex
,
1293 uint32_t queueIndex
,
1296 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1298 *pQueue
= radv_queue_to_handle(&device
->queues
[queueFamilyIndex
][queueIndex
]);
1301 static void radv_dump_trace(struct radv_device
*device
,
1302 struct radeon_winsys_cs
*cs
)
1304 const char *filename
= getenv("RADV_TRACE_FILE");
1305 FILE *f
= fopen(filename
, "w");
1307 fprintf(stderr
, "Failed to write trace dump to %s\n", filename
);
1311 fprintf(f
, "Trace ID: %x\n", *device
->trace_id_ptr
);
1312 device
->ws
->cs_dump(cs
, f
, *device
->trace_id_ptr
);
1317 fill_geom_tess_rings(struct radv_queue
*queue
,
1319 bool add_sample_positions
,
1320 uint32_t esgs_ring_size
,
1321 struct radeon_winsys_bo
*esgs_ring_bo
,
1322 uint32_t gsvs_ring_size
,
1323 struct radeon_winsys_bo
*gsvs_ring_bo
,
1324 uint32_t tess_factor_ring_size
,
1325 struct radeon_winsys_bo
*tess_factor_ring_bo
,
1326 uint32_t tess_offchip_ring_size
,
1327 struct radeon_winsys_bo
*tess_offchip_ring_bo
)
1329 uint64_t esgs_va
= 0, gsvs_va
= 0;
1330 uint64_t tess_factor_va
= 0, tess_offchip_va
= 0;
1331 uint32_t *desc
= &map
[4];
1334 esgs_va
= queue
->device
->ws
->buffer_get_va(esgs_ring_bo
);
1336 gsvs_va
= queue
->device
->ws
->buffer_get_va(gsvs_ring_bo
);
1337 if (tess_factor_ring_bo
)
1338 tess_factor_va
= queue
->device
->ws
->buffer_get_va(tess_factor_ring_bo
);
1339 if (tess_offchip_ring_bo
)
1340 tess_offchip_va
= queue
->device
->ws
->buffer_get_va(tess_offchip_ring_bo
);
1342 /* stride 0, num records - size, add tid, swizzle, elsize4,
1345 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1346 S_008F04_STRIDE(0) |
1347 S_008F04_SWIZZLE_ENABLE(true);
1348 desc
[2] = esgs_ring_size
;
1349 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1350 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1351 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1352 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1353 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1354 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1355 S_008F0C_ELEMENT_SIZE(1) |
1356 S_008F0C_INDEX_STRIDE(3) |
1357 S_008F0C_ADD_TID_ENABLE(true);
1360 /* GS entry for ES->GS ring */
1361 /* stride 0, num records - size, elsize0,
1364 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1365 S_008F04_STRIDE(0) |
1366 S_008F04_SWIZZLE_ENABLE(false);
1367 desc
[2] = esgs_ring_size
;
1368 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1369 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1370 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1371 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1372 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1373 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1374 S_008F0C_ELEMENT_SIZE(0) |
1375 S_008F0C_INDEX_STRIDE(0) |
1376 S_008F0C_ADD_TID_ENABLE(false);
1379 /* VS entry for GS->VS ring */
1380 /* stride 0, num records - size, elsize0,
1383 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1384 S_008F04_STRIDE(0) |
1385 S_008F04_SWIZZLE_ENABLE(false);
1386 desc
[2] = gsvs_ring_size
;
1387 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1388 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1389 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1390 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1391 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1392 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1393 S_008F0C_ELEMENT_SIZE(0) |
1394 S_008F0C_INDEX_STRIDE(0) |
1395 S_008F0C_ADD_TID_ENABLE(false);
1398 /* stride gsvs_itemsize, num records 64
1399 elsize 4, index stride 16 */
1400 /* shader will patch stride and desc[2] */
1402 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1403 S_008F04_STRIDE(0) |
1404 S_008F04_SWIZZLE_ENABLE(true);
1406 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1407 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1408 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1409 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1410 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1411 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1412 S_008F0C_ELEMENT_SIZE(1) |
1413 S_008F0C_INDEX_STRIDE(1) |
1414 S_008F0C_ADD_TID_ENABLE(true);
1417 desc
[0] = tess_factor_va
;
1418 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_factor_va
>> 32) |
1419 S_008F04_STRIDE(0) |
1420 S_008F04_SWIZZLE_ENABLE(false);
1421 desc
[2] = tess_factor_ring_size
;
1422 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1423 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1424 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1425 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1426 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1427 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1428 S_008F0C_ELEMENT_SIZE(0) |
1429 S_008F0C_INDEX_STRIDE(0) |
1430 S_008F0C_ADD_TID_ENABLE(false);
1433 desc
[0] = tess_offchip_va
;
1434 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
1435 S_008F04_STRIDE(0) |
1436 S_008F04_SWIZZLE_ENABLE(false);
1437 desc
[2] = tess_offchip_ring_size
;
1438 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1439 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1440 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1441 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1442 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1443 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1444 S_008F0C_ELEMENT_SIZE(0) |
1445 S_008F0C_INDEX_STRIDE(0) |
1446 S_008F0C_ADD_TID_ENABLE(false);
1449 /* add sample positions after all rings */
1450 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
1452 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
1454 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
1456 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
1458 memcpy(desc
, queue
->device
->sample_locations_16x
, 128);
1462 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
1464 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
1465 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
1466 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
1467 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1468 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1469 device
->physical_device
->rad_info
.max_se
;
1470 unsigned offchip_granularity
;
1471 unsigned hs_offchip_param
;
1472 switch (device
->tess_offchip_block_dw_size
) {
1477 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1480 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1484 switch (device
->physical_device
->rad_info
.chip_class
) {
1486 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
1492 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
1496 *max_offchip_buffers_p
= max_offchip_buffers
;
1497 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1498 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
1499 --max_offchip_buffers
;
1501 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1502 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1505 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1507 return hs_offchip_param
;
1511 radv_get_preamble_cs(struct radv_queue
*queue
,
1512 uint32_t scratch_size
,
1513 uint32_t compute_scratch_size
,
1514 uint32_t esgs_ring_size
,
1515 uint32_t gsvs_ring_size
,
1516 bool needs_tess_rings
,
1517 bool needs_sample_positions
,
1518 struct radeon_winsys_cs
**initial_preamble_cs
,
1519 struct radeon_winsys_cs
**continue_preamble_cs
)
1521 struct radeon_winsys_bo
*scratch_bo
= NULL
;
1522 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
1523 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
1524 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
1525 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
1526 struct radeon_winsys_bo
*tess_factor_ring_bo
= NULL
;
1527 struct radeon_winsys_bo
*tess_offchip_ring_bo
= NULL
;
1528 struct radeon_winsys_cs
*dest_cs
[2] = {0};
1529 bool add_tess_rings
= false, add_sample_positions
= false;
1530 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
1531 unsigned max_offchip_buffers
;
1532 unsigned hs_offchip_param
= 0;
1533 if (!queue
->has_tess_rings
) {
1534 if (needs_tess_rings
)
1535 add_tess_rings
= true;
1537 if (!queue
->has_sample_positions
) {
1538 if (needs_sample_positions
)
1539 add_sample_positions
= true;
1541 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
1542 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
1543 &max_offchip_buffers
);
1544 tess_offchip_ring_size
= max_offchip_buffers
*
1545 queue
->device
->tess_offchip_block_dw_size
* 4;
1547 if (scratch_size
<= queue
->scratch_size
&&
1548 compute_scratch_size
<= queue
->compute_scratch_size
&&
1549 esgs_ring_size
<= queue
->esgs_ring_size
&&
1550 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
1551 !add_tess_rings
&& !add_sample_positions
&&
1552 queue
->initial_preamble_cs
) {
1553 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1554 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1555 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1556 *continue_preamble_cs
= NULL
;
1560 if (scratch_size
> queue
->scratch_size
) {
1561 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1565 RADEON_FLAG_NO_CPU_ACCESS
);
1569 scratch_bo
= queue
->scratch_bo
;
1571 if (compute_scratch_size
> queue
->compute_scratch_size
) {
1572 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1573 compute_scratch_size
,
1576 RADEON_FLAG_NO_CPU_ACCESS
);
1577 if (!compute_scratch_bo
)
1581 compute_scratch_bo
= queue
->compute_scratch_bo
;
1583 if (esgs_ring_size
> queue
->esgs_ring_size
) {
1584 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1588 RADEON_FLAG_NO_CPU_ACCESS
);
1592 esgs_ring_bo
= queue
->esgs_ring_bo
;
1593 esgs_ring_size
= queue
->esgs_ring_size
;
1596 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
1597 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1601 RADEON_FLAG_NO_CPU_ACCESS
);
1605 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
1606 gsvs_ring_size
= queue
->gsvs_ring_size
;
1609 if (add_tess_rings
) {
1610 tess_factor_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1611 tess_factor_ring_size
,
1614 RADEON_FLAG_NO_CPU_ACCESS
);
1615 if (!tess_factor_ring_bo
)
1617 tess_offchip_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1618 tess_offchip_ring_size
,
1621 RADEON_FLAG_NO_CPU_ACCESS
);
1622 if (!tess_offchip_ring_bo
)
1625 tess_factor_ring_bo
= queue
->tess_factor_ring_bo
;
1626 tess_offchip_ring_bo
= queue
->tess_offchip_ring_bo
;
1629 if (scratch_bo
!= queue
->scratch_bo
||
1630 esgs_ring_bo
!= queue
->esgs_ring_bo
||
1631 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
1632 tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
||
1633 tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
|| add_sample_positions
) {
1635 if (gsvs_ring_bo
|| esgs_ring_bo
||
1636 tess_factor_ring_bo
|| tess_offchip_ring_bo
|| add_sample_positions
) {
1637 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
1638 if (add_sample_positions
)
1639 size
+= 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
1641 else if (scratch_bo
)
1642 size
= 8; /* 2 dword */
1644 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1648 RADEON_FLAG_CPU_ACCESS
);
1652 descriptor_bo
= queue
->descriptor_bo
;
1654 for(int i
= 0; i
< 2; ++i
) {
1655 struct radeon_winsys_cs
*cs
= NULL
;
1656 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
1657 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
1664 queue
->device
->ws
->cs_add_buffer(cs
, scratch_bo
, 8);
1667 queue
->device
->ws
->cs_add_buffer(cs
, esgs_ring_bo
, 8);
1670 queue
->device
->ws
->cs_add_buffer(cs
, gsvs_ring_bo
, 8);
1672 if (tess_factor_ring_bo
)
1673 queue
->device
->ws
->cs_add_buffer(cs
, tess_factor_ring_bo
, 8);
1675 if (tess_offchip_ring_bo
)
1676 queue
->device
->ws
->cs_add_buffer(cs
, tess_offchip_ring_bo
, 8);
1679 queue
->device
->ws
->cs_add_buffer(cs
, descriptor_bo
, 8);
1681 if (descriptor_bo
!= queue
->descriptor_bo
) {
1682 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
1685 uint64_t scratch_va
= queue
->device
->ws
->buffer_get_va(scratch_bo
);
1686 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1687 S_008F04_SWIZZLE_ENABLE(1);
1688 map
[0] = scratch_va
;
1692 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_factor_ring_bo
|| tess_offchip_ring_bo
||
1693 add_sample_positions
)
1694 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
1695 esgs_ring_size
, esgs_ring_bo
,
1696 gsvs_ring_size
, gsvs_ring_bo
,
1697 tess_factor_ring_size
, tess_factor_ring_bo
,
1698 tess_offchip_ring_size
, tess_offchip_ring_bo
);
1700 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
1703 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_factor_ring_bo
|| tess_offchip_ring_bo
) {
1704 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1705 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
1706 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1707 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
1710 if (esgs_ring_bo
|| gsvs_ring_bo
) {
1711 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1712 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
1713 radeon_emit(cs
, esgs_ring_size
>> 8);
1714 radeon_emit(cs
, gsvs_ring_size
>> 8);
1716 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
1717 radeon_emit(cs
, esgs_ring_size
>> 8);
1718 radeon_emit(cs
, gsvs_ring_size
>> 8);
1722 if (tess_factor_ring_bo
) {
1723 uint64_t tf_va
= queue
->device
->ws
->buffer_get_va(tess_factor_ring_bo
);
1724 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1725 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
1726 S_030938_SIZE(tess_factor_ring_size
/ 4));
1727 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
1729 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
1730 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
1733 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
, hs_offchip_param
);
1735 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
1736 S_008988_SIZE(tess_factor_ring_size
/ 4));
1737 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
1739 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
1744 if (descriptor_bo
) {
1745 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
1746 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
1747 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
1748 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
1749 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
1750 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
1752 uint64_t va
= queue
->device
->ws
->buffer_get_va(descriptor_bo
);
1754 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
1755 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
1756 radeon_emit(cs
, va
);
1757 radeon_emit(cs
, va
>> 32);
1761 if (compute_scratch_bo
) {
1762 uint64_t scratch_va
= queue
->device
->ws
->buffer_get_va(compute_scratch_bo
);
1763 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1764 S_008F04_SWIZZLE_ENABLE(1);
1766 queue
->device
->ws
->cs_add_buffer(cs
, compute_scratch_bo
, 8);
1768 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
1769 radeon_emit(cs
, scratch_va
);
1770 radeon_emit(cs
, rsrc1
);
1774 si_cs_emit_cache_flush(cs
,
1776 queue
->device
->physical_device
->rad_info
.chip_class
,
1778 queue
->queue_family_index
== RING_COMPUTE
&&
1779 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
1780 RADV_CMD_FLAG_INV_ICACHE
|
1781 RADV_CMD_FLAG_INV_SMEM_L1
|
1782 RADV_CMD_FLAG_INV_VMEM_L1
|
1783 RADV_CMD_FLAG_INV_GLOBAL_L2
);
1786 if (!queue
->device
->ws
->cs_finalize(cs
))
1790 if (queue
->initial_preamble_cs
)
1791 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1793 if (queue
->continue_preamble_cs
)
1794 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1796 queue
->initial_preamble_cs
= dest_cs
[0];
1797 queue
->continue_preamble_cs
= dest_cs
[1];
1799 if (scratch_bo
!= queue
->scratch_bo
) {
1800 if (queue
->scratch_bo
)
1801 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1802 queue
->scratch_bo
= scratch_bo
;
1803 queue
->scratch_size
= scratch_size
;
1806 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
1807 if (queue
->compute_scratch_bo
)
1808 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1809 queue
->compute_scratch_bo
= compute_scratch_bo
;
1810 queue
->compute_scratch_size
= compute_scratch_size
;
1813 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
1814 if (queue
->esgs_ring_bo
)
1815 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1816 queue
->esgs_ring_bo
= esgs_ring_bo
;
1817 queue
->esgs_ring_size
= esgs_ring_size
;
1820 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
1821 if (queue
->gsvs_ring_bo
)
1822 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1823 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
1824 queue
->gsvs_ring_size
= gsvs_ring_size
;
1827 if (tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
) {
1828 queue
->tess_factor_ring_bo
= tess_factor_ring_bo
;
1831 if (tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
) {
1832 queue
->tess_offchip_ring_bo
= tess_offchip_ring_bo
;
1833 queue
->has_tess_rings
= true;
1836 if (descriptor_bo
!= queue
->descriptor_bo
) {
1837 if (queue
->descriptor_bo
)
1838 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1840 queue
->descriptor_bo
= descriptor_bo
;
1843 if (add_sample_positions
)
1844 queue
->has_sample_positions
= true;
1846 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1847 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1848 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1849 *continue_preamble_cs
= NULL
;
1852 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
1854 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
1855 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
1856 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
1857 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
1858 queue
->device
->ws
->buffer_destroy(scratch_bo
);
1859 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
1860 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
1861 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
1862 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
1863 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
1864 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
1865 if (tess_factor_ring_bo
&& tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
)
1866 queue
->device
->ws
->buffer_destroy(tess_factor_ring_bo
);
1867 if (tess_offchip_ring_bo
&& tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
)
1868 queue
->device
->ws
->buffer_destroy(tess_offchip_ring_bo
);
1869 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
1872 VkResult
radv_QueueSubmit(
1874 uint32_t submitCount
,
1875 const VkSubmitInfo
* pSubmits
,
1878 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
1879 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
1880 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
1881 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
1883 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
1884 uint32_t scratch_size
= 0;
1885 uint32_t compute_scratch_size
= 0;
1886 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
1887 struct radeon_winsys_cs
*initial_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
1889 bool fence_emitted
= false;
1890 bool tess_rings_needed
= false;
1891 bool sample_positions_needed
= false;
1893 /* Do this first so failing to allocate scratch buffers can't result in
1894 * partially executed submissions. */
1895 for (uint32_t i
= 0; i
< submitCount
; i
++) {
1896 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
1897 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
1898 pSubmits
[i
].pCommandBuffers
[j
]);
1900 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
1901 compute_scratch_size
= MAX2(compute_scratch_size
,
1902 cmd_buffer
->compute_scratch_size_needed
);
1903 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
1904 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
1905 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
1906 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
1910 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
1911 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
1912 sample_positions_needed
,
1913 &initial_preamble_cs
, &continue_preamble_cs
);
1914 if (result
!= VK_SUCCESS
)
1917 for (uint32_t i
= 0; i
< submitCount
; i
++) {
1918 struct radeon_winsys_cs
**cs_array
;
1919 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
1920 bool can_patch
= !do_flush
;
1923 if (!pSubmits
[i
].commandBufferCount
) {
1924 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
1925 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
1926 &queue
->device
->empty_cs
[queue
->queue_family_index
],
1928 (struct radeon_winsys_sem
**)pSubmits
[i
].pWaitSemaphores
,
1929 pSubmits
[i
].waitSemaphoreCount
,
1930 (struct radeon_winsys_sem
**)pSubmits
[i
].pSignalSemaphores
,
1931 pSubmits
[i
].signalSemaphoreCount
,
1934 radv_loge("failed to submit CS %d\n", i
);
1937 fence_emitted
= true;
1942 cs_array
= malloc(sizeof(struct radeon_winsys_cs
*) *
1943 (pSubmits
[i
].commandBufferCount
+ do_flush
));
1946 cs_array
[0] = pSubmits
[i
].waitSemaphoreCount
?
1947 queue
->device
->flush_shader_cs
[queue
->queue_family_index
] :
1948 queue
->device
->flush_cs
[queue
->queue_family_index
];
1950 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
1951 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
1952 pSubmits
[i
].pCommandBuffers
[j
]);
1953 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
1955 cs_array
[j
+ do_flush
] = cmd_buffer
->cs
;
1956 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
1960 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
+ do_flush
; j
+= advance
) {
1961 advance
= MIN2(max_cs_submission
,
1962 pSubmits
[i
].commandBufferCount
+ do_flush
- j
);
1964 bool e
= j
+ advance
== pSubmits
[i
].commandBufferCount
+ do_flush
;
1966 if (queue
->device
->trace_bo
)
1967 *queue
->device
->trace_id_ptr
= 0;
1969 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
1970 advance
, initial_preamble_cs
, continue_preamble_cs
,
1971 (struct radeon_winsys_sem
**)pSubmits
[i
].pWaitSemaphores
,
1972 b
? pSubmits
[i
].waitSemaphoreCount
: 0,
1973 (struct radeon_winsys_sem
**)pSubmits
[i
].pSignalSemaphores
,
1974 e
? pSubmits
[i
].signalSemaphoreCount
: 0,
1975 can_patch
, base_fence
);
1978 radv_loge("failed to submit CS %d\n", i
);
1981 fence_emitted
= true;
1982 if (queue
->device
->trace_bo
) {
1983 bool success
= queue
->device
->ws
->ctx_wait_idle(
1985 radv_queue_family_to_ring(
1986 queue
->queue_family_index
),
1989 if (!success
) { /* Hang */
1990 radv_dump_trace(queue
->device
, cs_array
[j
]);
2000 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2001 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2002 1, NULL
, NULL
, NULL
, 0, NULL
, 0,
2005 fence
->submitted
= true;
2011 VkResult
radv_QueueWaitIdle(
2014 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2016 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2017 radv_queue_family_to_ring(queue
->queue_family_index
),
2022 VkResult
radv_DeviceWaitIdle(
2025 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2027 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2028 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2029 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2035 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
2036 VkInstance instance
,
2039 return radv_lookup_entrypoint(pName
);
2042 /* The loader wants us to expose a second GetInstanceProcAddr function
2043 * to work around certain LD_PRELOAD issues seen in apps.
2046 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2047 VkInstance instance
,
2051 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2052 VkInstance instance
,
2055 return radv_GetInstanceProcAddr(instance
, pName
);
2058 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
2062 return radv_lookup_entrypoint(pName
);
2065 bool radv_get_memory_fd(struct radv_device
*device
,
2066 struct radv_device_memory
*memory
,
2069 struct radeon_bo_metadata metadata
;
2071 if (memory
->image
) {
2072 radv_init_metadata(device
, memory
->image
, &metadata
);
2073 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
2076 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
2080 VkResult
radv_AllocateMemory(
2082 const VkMemoryAllocateInfo
* pAllocateInfo
,
2083 const VkAllocationCallbacks
* pAllocator
,
2084 VkDeviceMemory
* pMem
)
2086 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2087 struct radv_device_memory
*mem
;
2089 enum radeon_bo_domain domain
;
2092 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2094 if (pAllocateInfo
->allocationSize
== 0) {
2095 /* Apparently, this is allowed */
2096 *pMem
= VK_NULL_HANDLE
;
2100 const VkImportMemoryFdInfoKHR
*import_info
=
2101 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2102 const VkMemoryDedicatedAllocateInfoKHR
*dedicate_info
=
2103 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2105 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2106 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2108 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2110 if (dedicate_info
) {
2111 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
2112 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
2119 assert(import_info
->handleType
==
2120 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
2121 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
2124 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2130 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
2131 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
2132 pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_CACHED
)
2133 domain
= RADEON_DOMAIN_GTT
;
2135 domain
= RADEON_DOMAIN_VRAM
;
2137 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_VRAM
)
2138 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
2140 flags
|= RADEON_FLAG_CPU_ACCESS
;
2142 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
2143 flags
|= RADEON_FLAG_GTT_WC
;
2145 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
2149 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2152 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
2154 *pMem
= radv_device_memory_to_handle(mem
);
2159 vk_free2(&device
->alloc
, pAllocator
, mem
);
2164 void radv_FreeMemory(
2166 VkDeviceMemory _mem
,
2167 const VkAllocationCallbacks
* pAllocator
)
2169 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2170 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
2175 device
->ws
->buffer_destroy(mem
->bo
);
2178 vk_free2(&device
->alloc
, pAllocator
, mem
);
2181 VkResult
radv_MapMemory(
2183 VkDeviceMemory _memory
,
2184 VkDeviceSize offset
,
2186 VkMemoryMapFlags flags
,
2189 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2190 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2197 *ppData
= device
->ws
->buffer_map(mem
->bo
);
2203 return VK_ERROR_MEMORY_MAP_FAILED
;
2206 void radv_UnmapMemory(
2208 VkDeviceMemory _memory
)
2210 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2211 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2216 device
->ws
->buffer_unmap(mem
->bo
);
2219 VkResult
radv_FlushMappedMemoryRanges(
2221 uint32_t memoryRangeCount
,
2222 const VkMappedMemoryRange
* pMemoryRanges
)
2227 VkResult
radv_InvalidateMappedMemoryRanges(
2229 uint32_t memoryRangeCount
,
2230 const VkMappedMemoryRange
* pMemoryRanges
)
2235 void radv_GetBufferMemoryRequirements(
2238 VkMemoryRequirements
* pMemoryRequirements
)
2240 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2242 pMemoryRequirements
->memoryTypeBits
= (1u << RADV_MEM_TYPE_COUNT
) - 1;
2244 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2245 pMemoryRequirements
->alignment
= 4096;
2247 pMemoryRequirements
->alignment
= 16;
2249 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
2252 void radv_GetBufferMemoryRequirements2KHR(
2254 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
2255 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2257 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
2258 &pMemoryRequirements
->memoryRequirements
);
2260 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2261 switch (ext
->sType
) {
2262 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2263 VkMemoryDedicatedRequirementsKHR
*req
=
2264 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2265 req
->requiresDedicatedAllocation
= false;
2266 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2275 void radv_GetImageMemoryRequirements(
2278 VkMemoryRequirements
* pMemoryRequirements
)
2280 RADV_FROM_HANDLE(radv_image
, image
, _image
);
2282 pMemoryRequirements
->memoryTypeBits
= (1u << RADV_MEM_TYPE_COUNT
) - 1;
2284 pMemoryRequirements
->size
= image
->size
;
2285 pMemoryRequirements
->alignment
= image
->alignment
;
2288 void radv_GetImageMemoryRequirements2KHR(
2290 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
2291 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2293 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
2294 &pMemoryRequirements
->memoryRequirements
);
2296 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
2298 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2299 switch (ext
->sType
) {
2300 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2301 VkMemoryDedicatedRequirementsKHR
*req
=
2302 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2303 req
->requiresDedicatedAllocation
= image
->shareable
;
2304 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2313 void radv_GetImageSparseMemoryRequirements(
2316 uint32_t* pSparseMemoryRequirementCount
,
2317 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
2322 void radv_GetImageSparseMemoryRequirements2KHR(
2324 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
2325 uint32_t* pSparseMemoryRequirementCount
,
2326 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
2331 void radv_GetDeviceMemoryCommitment(
2333 VkDeviceMemory memory
,
2334 VkDeviceSize
* pCommittedMemoryInBytes
)
2336 *pCommittedMemoryInBytes
= 0;
2339 VkResult
radv_BindBufferMemory(
2342 VkDeviceMemory _memory
,
2343 VkDeviceSize memoryOffset
)
2345 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2346 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2349 buffer
->bo
= mem
->bo
;
2350 buffer
->offset
= memoryOffset
;
2359 VkResult
radv_BindImageMemory(
2362 VkDeviceMemory _memory
,
2363 VkDeviceSize memoryOffset
)
2365 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2366 RADV_FROM_HANDLE(radv_image
, image
, _image
);
2369 image
->bo
= mem
->bo
;
2370 image
->offset
= memoryOffset
;
2381 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
2382 const VkSparseBufferMemoryBindInfo
*bind
)
2384 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
2386 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
2387 struct radv_device_memory
*mem
= NULL
;
2389 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
2390 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
2392 device
->ws
->buffer_virtual_bind(buffer
->bo
,
2393 bind
->pBinds
[i
].resourceOffset
,
2394 bind
->pBinds
[i
].size
,
2395 mem
? mem
->bo
: NULL
,
2396 bind
->pBinds
[i
].memoryOffset
);
2401 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
2402 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
2404 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
2406 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
2407 struct radv_device_memory
*mem
= NULL
;
2409 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
2410 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
2412 device
->ws
->buffer_virtual_bind(image
->bo
,
2413 bind
->pBinds
[i
].resourceOffset
,
2414 bind
->pBinds
[i
].size
,
2415 mem
? mem
->bo
: NULL
,
2416 bind
->pBinds
[i
].memoryOffset
);
2420 VkResult
radv_QueueBindSparse(
2422 uint32_t bindInfoCount
,
2423 const VkBindSparseInfo
* pBindInfo
,
2426 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2427 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2428 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2429 bool fence_emitted
= false;
2431 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2432 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
2433 radv_sparse_buffer_bind_memory(queue
->device
,
2434 pBindInfo
[i
].pBufferBinds
+ j
);
2437 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
2438 radv_sparse_image_opaque_bind_memory(queue
->device
,
2439 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
2442 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
2443 queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2444 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2446 (struct radeon_winsys_sem
**)pBindInfo
[i
].pWaitSemaphores
,
2447 pBindInfo
[i
].waitSemaphoreCount
,
2448 (struct radeon_winsys_sem
**)pBindInfo
[i
].pSignalSemaphores
,
2449 pBindInfo
[i
].signalSemaphoreCount
,
2451 fence_emitted
= true;
2453 fence
->submitted
= true;
2457 if (fence
&& !fence_emitted
) {
2458 fence
->signalled
= true;
2464 VkResult
radv_CreateFence(
2466 const VkFenceCreateInfo
* pCreateInfo
,
2467 const VkAllocationCallbacks
* pAllocator
,
2470 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2471 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
2473 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2476 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2478 memset(fence
, 0, sizeof(*fence
));
2479 fence
->submitted
= false;
2480 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
2481 fence
->fence
= device
->ws
->create_fence();
2482 if (!fence
->fence
) {
2483 vk_free2(&device
->alloc
, pAllocator
, fence
);
2484 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2487 *pFence
= radv_fence_to_handle(fence
);
2492 void radv_DestroyFence(
2495 const VkAllocationCallbacks
* pAllocator
)
2497 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2498 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2502 device
->ws
->destroy_fence(fence
->fence
);
2503 vk_free2(&device
->alloc
, pAllocator
, fence
);
2506 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
2508 uint64_t current_time
;
2511 clock_gettime(CLOCK_MONOTONIC
, &tv
);
2512 current_time
= tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
2514 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
2516 return current_time
+ timeout
;
2519 VkResult
radv_WaitForFences(
2521 uint32_t fenceCount
,
2522 const VkFence
* pFences
,
2526 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2527 timeout
= radv_get_absolute_timeout(timeout
);
2529 if (!waitAll
&& fenceCount
> 1) {
2530 fprintf(stderr
, "radv: WaitForFences without waitAll not implemented yet\n");
2533 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
2534 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
2535 bool expired
= false;
2537 if (fence
->signalled
)
2540 if (!fence
->submitted
)
2543 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
2547 fence
->signalled
= true;
2553 VkResult
radv_ResetFences(VkDevice device
,
2554 uint32_t fenceCount
,
2555 const VkFence
*pFences
)
2557 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
2558 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
2559 fence
->submitted
= fence
->signalled
= false;
2565 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
2567 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2568 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2570 if (fence
->signalled
)
2572 if (!fence
->submitted
)
2573 return VK_NOT_READY
;
2575 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
2576 return VK_NOT_READY
;
2582 // Queue semaphore functions
2584 VkResult
radv_CreateSemaphore(
2586 const VkSemaphoreCreateInfo
* pCreateInfo
,
2587 const VkAllocationCallbacks
* pAllocator
,
2588 VkSemaphore
* pSemaphore
)
2590 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2591 struct radeon_winsys_sem
*sem
;
2593 sem
= device
->ws
->create_sem(device
->ws
);
2595 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2597 *pSemaphore
= radeon_winsys_sem_to_handle(sem
);
2601 void radv_DestroySemaphore(
2603 VkSemaphore _semaphore
,
2604 const VkAllocationCallbacks
* pAllocator
)
2606 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2607 RADV_FROM_HANDLE(radeon_winsys_sem
, sem
, _semaphore
);
2611 device
->ws
->destroy_sem(sem
);
2614 VkResult
radv_CreateEvent(
2616 const VkEventCreateInfo
* pCreateInfo
,
2617 const VkAllocationCallbacks
* pAllocator
,
2620 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2621 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
2623 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2626 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2628 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
2630 RADEON_FLAG_CPU_ACCESS
);
2632 vk_free2(&device
->alloc
, pAllocator
, event
);
2633 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2636 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
2638 *pEvent
= radv_event_to_handle(event
);
2643 void radv_DestroyEvent(
2646 const VkAllocationCallbacks
* pAllocator
)
2648 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2649 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2653 device
->ws
->buffer_destroy(event
->bo
);
2654 vk_free2(&device
->alloc
, pAllocator
, event
);
2657 VkResult
radv_GetEventStatus(
2661 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2663 if (*event
->map
== 1)
2664 return VK_EVENT_SET
;
2665 return VK_EVENT_RESET
;
2668 VkResult
radv_SetEvent(
2672 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2678 VkResult
radv_ResetEvent(
2682 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2688 VkResult
radv_CreateBuffer(
2690 const VkBufferCreateInfo
* pCreateInfo
,
2691 const VkAllocationCallbacks
* pAllocator
,
2694 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2695 struct radv_buffer
*buffer
;
2697 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2699 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
2700 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2702 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2704 buffer
->size
= pCreateInfo
->size
;
2705 buffer
->usage
= pCreateInfo
->usage
;
2708 buffer
->flags
= pCreateInfo
->flags
;
2710 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
2711 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
2712 align64(buffer
->size
, 4096),
2713 4096, 0, RADEON_FLAG_VIRTUAL
);
2715 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2716 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2720 *pBuffer
= radv_buffer_to_handle(buffer
);
2725 void radv_DestroyBuffer(
2728 const VkAllocationCallbacks
* pAllocator
)
2730 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2731 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2736 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2737 device
->ws
->buffer_destroy(buffer
->bo
);
2739 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2742 static inline unsigned
2743 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
2746 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
2748 return image
->surface
.u
.legacy
.tiling_index
[level
];
2751 static uint32_t radv_surface_layer_count(struct radv_image_view
*iview
)
2753 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: iview
->layer_count
;
2757 radv_initialise_color_surface(struct radv_device
*device
,
2758 struct radv_color_buffer_info
*cb
,
2759 struct radv_image_view
*iview
)
2761 const struct vk_format_description
*desc
;
2762 unsigned ntype
, format
, swap
, endian
;
2763 unsigned blend_clamp
= 0, blend_bypass
= 0;
2765 const struct radeon_surf
*surf
= &iview
->image
->surface
;
2767 desc
= vk_format_description(iview
->vk_format
);
2769 memset(cb
, 0, sizeof(*cb
));
2771 /* Intensity is implemented as Red, so treat it that way. */
2772 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
2774 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
2776 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2777 struct gfx9_surf_meta_flags meta
;
2778 if (iview
->image
->dcc_offset
)
2779 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
2781 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
2783 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
2784 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
2785 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
2786 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
2788 va
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
2790 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
2791 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
2793 va
+= level_info
->offset
;
2795 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
2796 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
2797 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
2799 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
2800 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
2801 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
2803 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
2804 cb
->micro_tile_mode
= iview
->image
->surface
.micro_tile_mode
;
2806 if (iview
->image
->fmask
.size
) {
2807 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
2808 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
2809 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
2810 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
2812 /* This must be set for fast clear to work without FMASK. */
2813 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
2814 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
2815 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
2816 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
2820 cb
->cb_color_base
= va
>> 8;
2821 if (device
->physical_device
->rad_info
.chip_class
< GFX9
)
2822 cb
->cb_color_base
|= iview
->image
->surface
.u
.legacy
.tile_swizzle
;
2823 /* CMASK variables */
2824 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
2825 va
+= iview
->image
->cmask
.offset
;
2826 cb
->cb_color_cmask
= va
>> 8;
2828 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
2829 va
+= iview
->image
->dcc_offset
;
2830 cb
->cb_dcc_base
= va
>> 8;
2831 if (device
->physical_device
->rad_info
.chip_class
< GFX9
)
2832 cb
->cb_dcc_base
|= iview
->image
->surface
.u
.legacy
.tile_swizzle
;
2834 uint32_t max_slice
= radv_surface_layer_count(iview
);
2835 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
2836 S_028C6C_SLICE_MAX(iview
->base_layer
+ max_slice
- 1);
2838 if (iview
->image
->info
.samples
> 1) {
2839 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
2841 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
2842 S_028C74_NUM_FRAGMENTS(log_samples
);
2845 if (iview
->image
->fmask
.size
) {
2846 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
2847 cb
->cb_color_fmask
= va
>> 8;
2848 if (device
->physical_device
->rad_info
.chip_class
< GFX9
)
2849 cb
->cb_color_fmask
|= iview
->image
->surface
.u
.legacy
.tile_swizzle
;
2851 cb
->cb_color_fmask
= cb
->cb_color_base
;
2854 ntype
= radv_translate_color_numformat(iview
->vk_format
,
2856 vk_format_get_first_non_void_channel(iview
->vk_format
));
2857 format
= radv_translate_colorformat(iview
->vk_format
);
2858 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
2859 radv_finishme("Illegal color\n");
2860 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
2861 endian
= radv_colorformat_endian_swap(format
);
2863 /* blend clamp should be set for all NORM/SRGB types */
2864 if (ntype
== V_028C70_NUMBER_UNORM
||
2865 ntype
== V_028C70_NUMBER_SNORM
||
2866 ntype
== V_028C70_NUMBER_SRGB
)
2869 /* set blend bypass according to docs if SINT/UINT or
2870 8/24 COLOR variants */
2871 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
2872 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
2873 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
2878 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
2879 (format
== V_028C70_COLOR_8
||
2880 format
== V_028C70_COLOR_8_8
||
2881 format
== V_028C70_COLOR_8_8_8_8
))
2882 ->color_is_int8
= true;
2884 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
2885 S_028C70_COMP_SWAP(swap
) |
2886 S_028C70_BLEND_CLAMP(blend_clamp
) |
2887 S_028C70_BLEND_BYPASS(blend_bypass
) |
2888 S_028C70_SIMPLE_FLOAT(1) |
2889 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
2890 ntype
!= V_028C70_NUMBER_SNORM
&&
2891 ntype
!= V_028C70_NUMBER_SRGB
&&
2892 format
!= V_028C70_COLOR_8_24
&&
2893 format
!= V_028C70_COLOR_24_8
) |
2894 S_028C70_NUMBER_TYPE(ntype
) |
2895 S_028C70_ENDIAN(endian
);
2896 if (iview
->image
->info
.samples
> 1)
2897 if (iview
->image
->fmask
.size
)
2898 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
2900 if (iview
->image
->cmask
.size
&&
2901 !(device
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
2902 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
2904 if (iview
->image
->surface
.dcc_size
&& iview
->base_mip
< surf
->num_dcc_levels
)
2905 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
2907 if (device
->physical_device
->rad_info
.chip_class
>= VI
) {
2908 unsigned max_uncompressed_block_size
= 2;
2909 if (iview
->image
->info
.samples
> 1) {
2910 if (iview
->image
->surface
.bpe
== 1)
2911 max_uncompressed_block_size
= 0;
2912 else if (iview
->image
->surface
.bpe
== 2)
2913 max_uncompressed_block_size
= 1;
2916 cb
->cb_dcc_control
= S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
2917 S_028C78_INDEPENDENT_64B_BLOCKS(1);
2920 /* This must be set for fast clear to work without FMASK. */
2921 if (!iview
->image
->fmask
.size
&&
2922 device
->physical_device
->rad_info
.chip_class
== SI
) {
2923 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
2924 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
2927 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2928 uint32_t max_slice
= radv_surface_layer_count(iview
);
2929 unsigned mip0_depth
= iview
->base_layer
+ max_slice
- 1;
2931 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
2932 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
2933 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
2934 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->image
->info
.width
- 1) |
2935 S_028C68_MIP0_HEIGHT(iview
->image
->info
.height
- 1) |
2936 S_028C68_MAX_MIP(iview
->image
->info
.levels
);
2938 cb
->gfx9_epitch
= S_0287A0_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
2944 radv_initialise_ds_surface(struct radv_device
*device
,
2945 struct radv_ds_buffer_info
*ds
,
2946 struct radv_image_view
*iview
)
2948 unsigned level
= iview
->base_mip
;
2949 unsigned format
, stencil_format
;
2950 uint64_t va
, s_offs
, z_offs
;
2951 bool stencil_only
= false;
2952 memset(ds
, 0, sizeof(*ds
));
2953 switch (iview
->image
->vk_format
) {
2954 case VK_FORMAT_D24_UNORM_S8_UINT
:
2955 case VK_FORMAT_X8_D24_UNORM_PACK32
:
2956 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
2957 ds
->offset_scale
= 2.0f
;
2959 case VK_FORMAT_D16_UNORM
:
2960 case VK_FORMAT_D16_UNORM_S8_UINT
:
2961 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
2962 ds
->offset_scale
= 4.0f
;
2964 case VK_FORMAT_D32_SFLOAT
:
2965 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
2966 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
2967 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
2968 ds
->offset_scale
= 1.0f
;
2970 case VK_FORMAT_S8_UINT
:
2971 stencil_only
= true;
2977 format
= radv_translate_dbformat(iview
->image
->vk_format
);
2978 stencil_format
= iview
->image
->surface
.flags
& RADEON_SURF_SBUFFER
?
2979 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
2981 uint32_t max_slice
= radv_surface_layer_count(iview
);
2982 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
2983 S_028008_SLICE_MAX(iview
->base_layer
+ max_slice
- 1);
2985 ds
->db_htile_data_base
= 0;
2986 ds
->db_htile_surface
= 0;
2988 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
2989 s_offs
= z_offs
= va
;
2991 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
2992 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
2993 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
2995 ds
->db_z_info
= S_028038_FORMAT(format
) |
2996 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
2997 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
2998 S_028038_MAXMIP(iview
->image
->info
.levels
- 1);
2999 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
3000 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
3002 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3003 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
3004 ds
->db_depth_view
|= S_028008_MIPID(level
);
3006 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
3007 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
3009 /* Only use HTILE for the first level. */
3010 if (iview
->image
->surface
.htile_size
&& !level
) {
3011 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
3013 if (!(iview
->image
->surface
.flags
& RADEON_SURF_SBUFFER
))
3014 /* Use all of the htile_buffer for depth if there's no stencil. */
3015 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
3016 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3017 iview
->image
->htile_offset
;
3018 ds
->db_htile_data_base
= va
>> 8;
3019 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
3020 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
3021 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
3024 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
3027 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
3029 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
3030 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
3032 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(1);
3033 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
3034 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
3036 if (iview
->image
->info
.samples
> 1)
3037 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
3039 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
3040 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
3041 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
3042 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3043 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
3044 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
3045 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
3046 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
3049 tile_mode
= stencil_tile_mode
;
3051 ds
->db_depth_info
|=
3052 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
3053 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
3054 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
3055 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
3056 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
3057 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
3058 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
3059 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
3061 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
3062 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3063 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
3064 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
3067 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
3068 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
3069 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
3071 if (iview
->image
->surface
.htile_size
&& !level
) {
3072 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
3074 if (!(iview
->image
->surface
.flags
& RADEON_SURF_SBUFFER
))
3075 /* Use all of the htile_buffer for depth if there's no stencil. */
3076 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
3078 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3079 iview
->image
->htile_offset
;
3080 ds
->db_htile_data_base
= va
>> 8;
3081 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
3085 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
3086 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
3089 VkResult
radv_CreateFramebuffer(
3091 const VkFramebufferCreateInfo
* pCreateInfo
,
3092 const VkAllocationCallbacks
* pAllocator
,
3093 VkFramebuffer
* pFramebuffer
)
3095 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3096 struct radv_framebuffer
*framebuffer
;
3098 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
3100 size_t size
= sizeof(*framebuffer
) +
3101 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
3102 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
3103 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3104 if (framebuffer
== NULL
)
3105 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3107 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
3108 framebuffer
->width
= pCreateInfo
->width
;
3109 framebuffer
->height
= pCreateInfo
->height
;
3110 framebuffer
->layers
= pCreateInfo
->layers
;
3111 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
3112 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
3113 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
3114 framebuffer
->attachments
[i
].attachment
= iview
;
3115 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
3116 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
3117 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
3118 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
3120 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
3121 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
3122 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_layer_count(iview
));
3125 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
3129 void radv_DestroyFramebuffer(
3132 const VkAllocationCallbacks
* pAllocator
)
3134 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3135 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
3139 vk_free2(&device
->alloc
, pAllocator
, fb
);
3142 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
3144 switch (address_mode
) {
3145 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
3146 return V_008F30_SQ_TEX_WRAP
;
3147 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
3148 return V_008F30_SQ_TEX_MIRROR
;
3149 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
3150 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
3151 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
3152 return V_008F30_SQ_TEX_CLAMP_BORDER
;
3153 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
3154 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
3156 unreachable("illegal tex wrap mode");
3162 radv_tex_compare(VkCompareOp op
)
3165 case VK_COMPARE_OP_NEVER
:
3166 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
3167 case VK_COMPARE_OP_LESS
:
3168 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
3169 case VK_COMPARE_OP_EQUAL
:
3170 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
3171 case VK_COMPARE_OP_LESS_OR_EQUAL
:
3172 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
3173 case VK_COMPARE_OP_GREATER
:
3174 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
3175 case VK_COMPARE_OP_NOT_EQUAL
:
3176 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
3177 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
3178 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
3179 case VK_COMPARE_OP_ALWAYS
:
3180 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
3182 unreachable("illegal compare mode");
3188 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
3191 case VK_FILTER_NEAREST
:
3192 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
3193 V_008F38_SQ_TEX_XY_FILTER_POINT
);
3194 case VK_FILTER_LINEAR
:
3195 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
3196 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
3197 case VK_FILTER_CUBIC_IMG
:
3199 fprintf(stderr
, "illegal texture filter");
3205 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
3208 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
3209 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
3210 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
3211 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
3213 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
3218 radv_tex_bordercolor(VkBorderColor bcolor
)
3221 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
3222 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
3223 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
3224 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
3225 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
3226 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
3227 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
3228 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
3229 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
3237 radv_tex_aniso_filter(unsigned filter
)
3251 radv_init_sampler(struct radv_device
*device
,
3252 struct radv_sampler
*sampler
,
3253 const VkSamplerCreateInfo
*pCreateInfo
)
3255 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
3256 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
3257 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
3258 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
3260 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
3261 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
3262 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
3263 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
3264 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
3265 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
3266 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
3267 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
3268 S_008F30_DISABLE_CUBE_WRAP(0) |
3269 S_008F30_COMPAT_MODE(is_vi
));
3270 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
3271 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
3272 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
3273 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
3274 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
3275 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
3276 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
3277 S_008F38_MIP_POINT_PRECLAMP(0) |
3278 S_008F38_DISABLE_LSB_CEIL(1) |
3279 S_008F38_FILTER_PREC_FIX(1) |
3280 S_008F38_ANISO_OVERRIDE(is_vi
));
3281 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
3282 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
3285 VkResult
radv_CreateSampler(
3287 const VkSamplerCreateInfo
* pCreateInfo
,
3288 const VkAllocationCallbacks
* pAllocator
,
3289 VkSampler
* pSampler
)
3291 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3292 struct radv_sampler
*sampler
;
3294 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
3296 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
3297 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3299 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3301 radv_init_sampler(device
, sampler
, pCreateInfo
);
3302 *pSampler
= radv_sampler_to_handle(sampler
);
3307 void radv_DestroySampler(
3310 const VkAllocationCallbacks
* pAllocator
)
3312 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3313 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
3317 vk_free2(&device
->alloc
, pAllocator
, sampler
);
3320 /* vk_icd.h does not declare this function, so we declare it here to
3321 * suppress Wmissing-prototypes.
3323 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
3324 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
3326 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
3327 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
3329 /* For the full details on loader interface versioning, see
3330 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
3331 * What follows is a condensed summary, to help you navigate the large and
3332 * confusing official doc.
3334 * - Loader interface v0 is incompatible with later versions. We don't
3337 * - In loader interface v1:
3338 * - The first ICD entrypoint called by the loader is
3339 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
3341 * - The ICD must statically expose no other Vulkan symbol unless it is
3342 * linked with -Bsymbolic.
3343 * - Each dispatchable Vulkan handle created by the ICD must be
3344 * a pointer to a struct whose first member is VK_LOADER_DATA. The
3345 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
3346 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
3347 * vkDestroySurfaceKHR(). The ICD must be capable of working with
3348 * such loader-managed surfaces.
3350 * - Loader interface v2 differs from v1 in:
3351 * - The first ICD entrypoint called by the loader is
3352 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
3353 * statically expose this entrypoint.
3355 * - Loader interface v3 differs from v2 in:
3356 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
3357 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
3358 * because the loader no longer does so.
3360 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
3364 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
3365 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
3368 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3369 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
3371 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
3373 /* We support only one handle type. */
3374 assert(pGetFdInfo
->handleType
==
3375 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
3377 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
3379 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
3383 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
3384 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
3386 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
3388 /* The valid usage section for this function says:
3390 * "handleType must not be one of the handle types defined as opaque."
3392 * Since we only handle opaque handles for now, there are no FD properties.
3394 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;