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"
36 #include "util/vk_util.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"
45 #include "util/debug.h"
48 radv_device_get_cache_uuid(enum radeon_family family
, void *uuid
)
50 uint32_t mesa_timestamp
, llvm_timestamp
;
52 memset(uuid
, 0, VK_UUID_SIZE
);
53 if (!disk_cache_get_function_timestamp(radv_device_get_cache_uuid
, &mesa_timestamp
) ||
54 !disk_cache_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo
, &llvm_timestamp
))
57 memcpy(uuid
, &mesa_timestamp
, 4);
58 memcpy((char*)uuid
+ 4, &llvm_timestamp
, 4);
59 memcpy((char*)uuid
+ 8, &f
, 2);
60 snprintf((char*)uuid
+ 10, VK_UUID_SIZE
- 10, "radv");
64 static const VkExtensionProperties instance_extensions
[] = {
66 .extensionName
= VK_KHR_SURFACE_EXTENSION_NAME
,
69 #ifdef VK_USE_PLATFORM_XCB_KHR
71 .extensionName
= VK_KHR_XCB_SURFACE_EXTENSION_NAME
,
75 #ifdef VK_USE_PLATFORM_XLIB_KHR
77 .extensionName
= VK_KHR_XLIB_SURFACE_EXTENSION_NAME
,
81 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
83 .extensionName
= VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME
,
89 static const VkExtensionProperties common_device_extensions
[] = {
91 .extensionName
= VK_KHR_MAINTENANCE1_EXTENSION_NAME
,
95 .extensionName
= VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME
,
99 .extensionName
= VK_KHR_SWAPCHAIN_EXTENSION_NAME
,
103 .extensionName
= VK_AMD_DRAW_INDIRECT_COUNT_EXTENSION_NAME
,
107 .extensionName
= VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME
,
111 .extensionName
= VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME
,
115 .extensionName
= VK_NV_DEDICATED_ALLOCATION_EXTENSION_NAME
,
121 radv_extensions_register(struct radv_instance
*instance
,
122 struct radv_extensions
*extensions
,
123 const VkExtensionProperties
*new_ext
,
127 VkExtensionProperties
*new_ptr
;
129 assert(new_ext
&& num_ext
> 0);
132 return VK_ERROR_INITIALIZATION_FAILED
;
134 new_size
= (extensions
->num_ext
+ num_ext
) * sizeof(VkExtensionProperties
);
135 new_ptr
= vk_realloc(&instance
->alloc
, extensions
->ext_array
,
136 new_size
, 8, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
138 /* Old array continues to be valid, update nothing */
140 return VK_ERROR_OUT_OF_HOST_MEMORY
;
142 memcpy(&new_ptr
[extensions
->num_ext
], new_ext
,
143 num_ext
* sizeof(VkExtensionProperties
));
144 extensions
->ext_array
= new_ptr
;
145 extensions
->num_ext
+= num_ext
;
151 radv_extensions_finish(struct radv_instance
*instance
,
152 struct radv_extensions
*extensions
)
157 radv_loge("Attemted to free invalid extension struct\n");
159 if (extensions
->ext_array
)
160 vk_free(&instance
->alloc
, extensions
->ext_array
);
164 is_extension_enabled(const VkExtensionProperties
*extensions
,
168 assert(extensions
&& name
);
170 for (uint32_t i
= 0; i
< num_ext
; i
++) {
171 if (strcmp(name
, extensions
[i
].extensionName
) == 0)
179 radv_physical_device_init(struct radv_physical_device
*device
,
180 struct radv_instance
*instance
,
184 drmVersionPtr version
;
187 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
189 return VK_ERROR_INCOMPATIBLE_DRIVER
;
191 version
= drmGetVersion(fd
);
194 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
195 "failed to get version %s: %m", path
);
198 if (strcmp(version
->name
, "amdgpu")) {
199 drmFreeVersion(version
);
201 return VK_ERROR_INCOMPATIBLE_DRIVER
;
203 drmFreeVersion(version
);
205 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
206 device
->instance
= instance
;
207 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
208 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
210 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
);
212 result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
216 device
->local_fd
= fd
;
217 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
218 result
= radv_init_wsi(device
);
219 if (result
!= VK_SUCCESS
) {
220 device
->ws
->destroy(device
->ws
);
224 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->uuid
)) {
225 radv_finish_wsi(device
);
226 device
->ws
->destroy(device
->ws
);
227 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
228 "cannot generate UUID");
232 result
= radv_extensions_register(instance
,
234 common_device_extensions
,
235 ARRAY_SIZE(common_device_extensions
));
236 if (result
!= VK_SUCCESS
)
239 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
240 device
->name
= device
->rad_info
.name
;
250 radv_physical_device_finish(struct radv_physical_device
*device
)
252 radv_extensions_finish(device
->instance
, &device
->extensions
);
253 radv_finish_wsi(device
);
254 device
->ws
->destroy(device
->ws
);
255 close(device
->local_fd
);
260 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
261 VkSystemAllocationScope allocationScope
)
267 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
268 size_t align
, VkSystemAllocationScope allocationScope
)
270 return realloc(pOriginal
, size
);
274 default_free_func(void *pUserData
, void *pMemory
)
279 static const VkAllocationCallbacks default_alloc
= {
281 .pfnAllocation
= default_alloc_func
,
282 .pfnReallocation
= default_realloc_func
,
283 .pfnFree
= default_free_func
,
286 static const struct debug_control radv_debug_options
[] = {
287 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
288 {"nodcc", RADV_DEBUG_NO_DCC
},
289 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
290 {"nocache", RADV_DEBUG_NO_CACHE
},
291 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
292 {"nohiz", RADV_DEBUG_NO_HIZ
},
293 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
294 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
295 {"allbos", RADV_DEBUG_ALL_BOS
},
296 {"noibs", RADV_DEBUG_NO_IBS
},
300 VkResult
radv_CreateInstance(
301 const VkInstanceCreateInfo
* pCreateInfo
,
302 const VkAllocationCallbacks
* pAllocator
,
303 VkInstance
* pInstance
)
305 struct radv_instance
*instance
;
307 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
309 uint32_t client_version
;
310 if (pCreateInfo
->pApplicationInfo
&&
311 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
312 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
314 client_version
= VK_MAKE_VERSION(1, 0, 0);
317 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
318 client_version
> VK_MAKE_VERSION(1, 0, 0xfff)) {
319 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
320 "Client requested version %d.%d.%d",
321 VK_VERSION_MAJOR(client_version
),
322 VK_VERSION_MINOR(client_version
),
323 VK_VERSION_PATCH(client_version
));
326 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
327 if (!is_extension_enabled(instance_extensions
,
328 ARRAY_SIZE(instance_extensions
),
329 pCreateInfo
->ppEnabledExtensionNames
[i
]))
330 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
333 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
334 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
336 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
338 memset(instance
, 0, sizeof(*instance
));
340 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
343 instance
->alloc
= *pAllocator
;
345 instance
->alloc
= default_alloc
;
347 instance
->apiVersion
= client_version
;
348 instance
->physicalDeviceCount
= -1;
352 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
354 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
357 *pInstance
= radv_instance_to_handle(instance
);
362 void radv_DestroyInstance(
363 VkInstance _instance
,
364 const VkAllocationCallbacks
* pAllocator
)
366 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
371 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
372 radv_physical_device_finish(instance
->physicalDevices
+ i
);
375 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
379 vk_free(&instance
->alloc
, instance
);
383 radv_enumerate_devices(struct radv_instance
*instance
)
385 /* TODO: Check for more devices ? */
386 drmDevicePtr devices
[8];
387 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
390 instance
->physicalDeviceCount
= 0;
392 max_devices
= drmGetDevices2(0, devices
, sizeof(devices
));
394 return VK_ERROR_INCOMPATIBLE_DRIVER
;
396 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
397 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
398 devices
[i
]->bustype
== DRM_BUS_PCI
&&
399 devices
[i
]->deviceinfo
.pci
->vendor_id
== 0x1002) {
401 result
= radv_physical_device_init(instance
->physicalDevices
+
402 instance
->physicalDeviceCount
,
404 devices
[i
]->nodes
[DRM_NODE_RENDER
]);
405 if (result
== VK_SUCCESS
)
406 ++instance
->physicalDeviceCount
;
407 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
414 VkResult
radv_EnumeratePhysicalDevices(
415 VkInstance _instance
,
416 uint32_t* pPhysicalDeviceCount
,
417 VkPhysicalDevice
* pPhysicalDevices
)
419 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
422 if (instance
->physicalDeviceCount
< 0) {
423 result
= radv_enumerate_devices(instance
);
424 if (result
!= VK_SUCCESS
&&
425 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
429 if (!pPhysicalDevices
) {
430 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
432 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
433 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
434 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
437 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
441 void radv_GetPhysicalDeviceFeatures(
442 VkPhysicalDevice physicalDevice
,
443 VkPhysicalDeviceFeatures
* pFeatures
)
445 // RADV_FROM_HANDLE(radv_physical_device, pdevice, physicalDevice);
447 memset(pFeatures
, 0, sizeof(*pFeatures
));
449 *pFeatures
= (VkPhysicalDeviceFeatures
) {
450 .robustBufferAccess
= true,
451 .fullDrawIndexUint32
= true,
452 .imageCubeArray
= true,
453 .independentBlend
= true,
454 .geometryShader
= true,
455 .tessellationShader
= false,
456 .sampleRateShading
= false,
457 .dualSrcBlend
= true,
459 .multiDrawIndirect
= true,
460 .drawIndirectFirstInstance
= true,
462 .depthBiasClamp
= true,
463 .fillModeNonSolid
= true,
468 .multiViewport
= true,
469 .samplerAnisotropy
= true,
470 .textureCompressionETC2
= false,
471 .textureCompressionASTC_LDR
= false,
472 .textureCompressionBC
= true,
473 .occlusionQueryPrecise
= true,
474 .pipelineStatisticsQuery
= false,
475 .vertexPipelineStoresAndAtomics
= true,
476 .fragmentStoresAndAtomics
= true,
477 .shaderTessellationAndGeometryPointSize
= true,
478 .shaderImageGatherExtended
= true,
479 .shaderStorageImageExtendedFormats
= true,
480 .shaderStorageImageMultisample
= false,
481 .shaderUniformBufferArrayDynamicIndexing
= true,
482 .shaderSampledImageArrayDynamicIndexing
= true,
483 .shaderStorageBufferArrayDynamicIndexing
= true,
484 .shaderStorageImageArrayDynamicIndexing
= true,
485 .shaderStorageImageReadWithoutFormat
= true,
486 .shaderStorageImageWriteWithoutFormat
= true,
487 .shaderClipDistance
= true,
488 .shaderCullDistance
= true,
489 .shaderFloat64
= true,
490 .shaderInt64
= false,
491 .shaderInt16
= false,
492 .variableMultisampleRate
= false,
493 .inheritedQueries
= false,
497 void radv_GetPhysicalDeviceFeatures2KHR(
498 VkPhysicalDevice physicalDevice
,
499 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
501 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
504 static uint32_t radv_get_driver_version()
506 const char *minor_string
= strchr(VERSION
, '.');
507 const char *patch_string
= minor_string
? strchr(minor_string
+ 1, ','): NULL
;
508 int major
= atoi(VERSION
);
509 int minor
= minor_string
? atoi(minor_string
+ 1) : 0;
510 int patch
= patch_string
? atoi(patch_string
+ 1) : 0;
511 if (strstr(VERSION
, "devel")) {
522 uint32_t version
= VK_MAKE_VERSION(major
, minor
, patch
);
526 void radv_GetPhysicalDeviceProperties(
527 VkPhysicalDevice physicalDevice
,
528 VkPhysicalDeviceProperties
* pProperties
)
530 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
531 VkSampleCountFlags sample_counts
= 0xf;
532 VkPhysicalDeviceLimits limits
= {
533 .maxImageDimension1D
= (1 << 14),
534 .maxImageDimension2D
= (1 << 14),
535 .maxImageDimension3D
= (1 << 11),
536 .maxImageDimensionCube
= (1 << 14),
537 .maxImageArrayLayers
= (1 << 11),
538 .maxTexelBufferElements
= 128 * 1024 * 1024,
539 .maxUniformBufferRange
= UINT32_MAX
,
540 .maxStorageBufferRange
= UINT32_MAX
,
541 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
542 .maxMemoryAllocationCount
= UINT32_MAX
,
543 .maxSamplerAllocationCount
= 64 * 1024,
544 .bufferImageGranularity
= 64, /* A cache line */
545 .sparseAddressSpaceSize
= 0,
546 .maxBoundDescriptorSets
= MAX_SETS
,
547 .maxPerStageDescriptorSamplers
= 64,
548 .maxPerStageDescriptorUniformBuffers
= 64,
549 .maxPerStageDescriptorStorageBuffers
= 64,
550 .maxPerStageDescriptorSampledImages
= 64,
551 .maxPerStageDescriptorStorageImages
= 64,
552 .maxPerStageDescriptorInputAttachments
= 64,
553 .maxPerStageResources
= 128,
554 .maxDescriptorSetSamplers
= 256,
555 .maxDescriptorSetUniformBuffers
= 256,
556 .maxDescriptorSetUniformBuffersDynamic
= 256,
557 .maxDescriptorSetStorageBuffers
= 256,
558 .maxDescriptorSetStorageBuffersDynamic
= 256,
559 .maxDescriptorSetSampledImages
= 256,
560 .maxDescriptorSetStorageImages
= 256,
561 .maxDescriptorSetInputAttachments
= 256,
562 .maxVertexInputAttributes
= 32,
563 .maxVertexInputBindings
= 32,
564 .maxVertexInputAttributeOffset
= 2047,
565 .maxVertexInputBindingStride
= 2048,
566 .maxVertexOutputComponents
= 128,
567 .maxTessellationGenerationLevel
= 0,
568 .maxTessellationPatchSize
= 0,
569 .maxTessellationControlPerVertexInputComponents
= 0,
570 .maxTessellationControlPerVertexOutputComponents
= 0,
571 .maxTessellationControlPerPatchOutputComponents
= 0,
572 .maxTessellationControlTotalOutputComponents
= 0,
573 .maxTessellationEvaluationInputComponents
= 0,
574 .maxTessellationEvaluationOutputComponents
= 0,
575 .maxGeometryShaderInvocations
= 32,
576 .maxGeometryInputComponents
= 64,
577 .maxGeometryOutputComponents
= 128,
578 .maxGeometryOutputVertices
= 256,
579 .maxGeometryTotalOutputComponents
= 1024,
580 .maxFragmentInputComponents
= 128,
581 .maxFragmentOutputAttachments
= 8,
582 .maxFragmentDualSrcAttachments
= 1,
583 .maxFragmentCombinedOutputResources
= 8,
584 .maxComputeSharedMemorySize
= 32768,
585 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
586 .maxComputeWorkGroupInvocations
= 2048,
587 .maxComputeWorkGroupSize
= {
592 .subPixelPrecisionBits
= 4 /* FIXME */,
593 .subTexelPrecisionBits
= 4 /* FIXME */,
594 .mipmapPrecisionBits
= 4 /* FIXME */,
595 .maxDrawIndexedIndexValue
= UINT32_MAX
,
596 .maxDrawIndirectCount
= UINT32_MAX
,
597 .maxSamplerLodBias
= 16,
598 .maxSamplerAnisotropy
= 16,
599 .maxViewports
= MAX_VIEWPORTS
,
600 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
601 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
602 .viewportSubPixelBits
= 13, /* We take a float? */
603 .minMemoryMapAlignment
= 4096, /* A page */
604 .minTexelBufferOffsetAlignment
= 1,
605 .minUniformBufferOffsetAlignment
= 4,
606 .minStorageBufferOffsetAlignment
= 4,
607 .minTexelOffset
= -32,
608 .maxTexelOffset
= 31,
609 .minTexelGatherOffset
= -32,
610 .maxTexelGatherOffset
= 31,
611 .minInterpolationOffset
= -2,
612 .maxInterpolationOffset
= 2,
613 .subPixelInterpolationOffsetBits
= 8,
614 .maxFramebufferWidth
= (1 << 14),
615 .maxFramebufferHeight
= (1 << 14),
616 .maxFramebufferLayers
= (1 << 10),
617 .framebufferColorSampleCounts
= sample_counts
,
618 .framebufferDepthSampleCounts
= sample_counts
,
619 .framebufferStencilSampleCounts
= sample_counts
,
620 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
621 .maxColorAttachments
= MAX_RTS
,
622 .sampledImageColorSampleCounts
= sample_counts
,
623 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
624 .sampledImageDepthSampleCounts
= sample_counts
,
625 .sampledImageStencilSampleCounts
= sample_counts
,
626 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
627 .maxSampleMaskWords
= 1,
628 .timestampComputeAndGraphics
= false,
629 .timestampPeriod
= 100000.0 / pdevice
->rad_info
.clock_crystal_freq
,
630 .maxClipDistances
= 8,
631 .maxCullDistances
= 8,
632 .maxCombinedClipAndCullDistances
= 8,
633 .discreteQueuePriorities
= 1,
634 .pointSizeRange
= { 0.125, 255.875 },
635 .lineWidthRange
= { 0.0, 7.9921875 },
636 .pointSizeGranularity
= (1.0 / 8.0),
637 .lineWidthGranularity
= (1.0 / 128.0),
638 .strictLines
= false, /* FINISHME */
639 .standardSampleLocations
= true,
640 .optimalBufferCopyOffsetAlignment
= 128,
641 .optimalBufferCopyRowPitchAlignment
= 128,
642 .nonCoherentAtomSize
= 64,
645 *pProperties
= (VkPhysicalDeviceProperties
) {
646 .apiVersion
= VK_MAKE_VERSION(1, 0, 42),
647 .driverVersion
= radv_get_driver_version(),
649 .deviceID
= pdevice
->rad_info
.pci_id
,
650 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
,
652 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
655 strcpy(pProperties
->deviceName
, pdevice
->name
);
656 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->uuid
, VK_UUID_SIZE
);
659 void radv_GetPhysicalDeviceProperties2KHR(
660 VkPhysicalDevice physicalDevice
,
661 VkPhysicalDeviceProperties2KHR
*pProperties
)
663 return radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
666 static void radv_get_physical_device_queue_family_properties(
667 struct radv_physical_device
* pdevice
,
669 VkQueueFamilyProperties
** pQueueFamilyProperties
)
671 int num_queue_families
= 1;
673 if (pdevice
->rad_info
.compute_rings
> 0 &&
674 pdevice
->rad_info
.chip_class
>= CIK
&&
675 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
676 num_queue_families
++;
678 if (pQueueFamilyProperties
== NULL
) {
679 *pCount
= num_queue_families
;
688 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
689 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
690 VK_QUEUE_COMPUTE_BIT
|
691 VK_QUEUE_TRANSFER_BIT
,
693 .timestampValidBits
= 64,
694 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
699 if (pdevice
->rad_info
.compute_rings
> 0 &&
700 pdevice
->rad_info
.chip_class
>= CIK
&&
701 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
703 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
704 .queueFlags
= VK_QUEUE_COMPUTE_BIT
| VK_QUEUE_TRANSFER_BIT
,
705 .queueCount
= pdevice
->rad_info
.compute_rings
,
706 .timestampValidBits
= 64,
707 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
715 void radv_GetPhysicalDeviceQueueFamilyProperties(
716 VkPhysicalDevice physicalDevice
,
718 VkQueueFamilyProperties
* pQueueFamilyProperties
)
720 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
721 if (!pQueueFamilyProperties
) {
722 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
725 VkQueueFamilyProperties
*properties
[] = {
726 pQueueFamilyProperties
+ 0,
727 pQueueFamilyProperties
+ 1,
728 pQueueFamilyProperties
+ 2,
730 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
731 assert(*pCount
<= 3);
734 void radv_GetPhysicalDeviceQueueFamilyProperties2KHR(
735 VkPhysicalDevice physicalDevice
,
737 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
739 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
740 if (!pQueueFamilyProperties
) {
741 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
744 VkQueueFamilyProperties
*properties
[] = {
745 &pQueueFamilyProperties
[0].queueFamilyProperties
,
746 &pQueueFamilyProperties
[1].queueFamilyProperties
,
747 &pQueueFamilyProperties
[2].queueFamilyProperties
,
749 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
750 assert(*pCount
<= 3);
753 void radv_GetPhysicalDeviceMemoryProperties(
754 VkPhysicalDevice physicalDevice
,
755 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
757 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
759 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
761 pMemoryProperties
->memoryTypeCount
= RADV_MEM_TYPE_COUNT
;
762 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_VRAM
] = (VkMemoryType
) {
763 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
764 .heapIndex
= RADV_MEM_HEAP_VRAM
,
766 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_GTT_WRITE_COMBINE
] = (VkMemoryType
) {
767 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
768 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
769 .heapIndex
= RADV_MEM_HEAP_GTT
,
771 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_VRAM_CPU_ACCESS
] = (VkMemoryType
) {
772 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
773 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
774 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
775 .heapIndex
= RADV_MEM_HEAP_VRAM_CPU_ACCESS
,
777 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_GTT_CACHED
] = (VkMemoryType
) {
778 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
779 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
780 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
781 .heapIndex
= RADV_MEM_HEAP_GTT
,
784 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
786 pMemoryProperties
->memoryHeapCount
= RADV_MEM_HEAP_COUNT
;
787 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_VRAM
] = (VkMemoryHeap
) {
788 .size
= physical_device
->rad_info
.vram_size
-
789 physical_device
->rad_info
.visible_vram_size
,
790 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
792 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_VRAM_CPU_ACCESS
] = (VkMemoryHeap
) {
793 .size
= physical_device
->rad_info
.visible_vram_size
,
794 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
796 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_GTT
] = (VkMemoryHeap
) {
797 .size
= physical_device
->rad_info
.gart_size
,
802 void radv_GetPhysicalDeviceMemoryProperties2KHR(
803 VkPhysicalDevice physicalDevice
,
804 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
806 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
807 &pMemoryProperties
->memoryProperties
);
811 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
812 int queue_family_index
, int idx
)
814 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
815 queue
->device
= device
;
816 queue
->queue_family_index
= queue_family_index
;
817 queue
->queue_idx
= idx
;
819 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
);
821 return VK_ERROR_OUT_OF_HOST_MEMORY
;
827 radv_queue_finish(struct radv_queue
*queue
)
830 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
832 if (queue
->initial_preamble_cs
)
833 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
834 if (queue
->continue_preamble_cs
)
835 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
836 if (queue
->descriptor_bo
)
837 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
838 if (queue
->scratch_bo
)
839 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
840 if (queue
->esgs_ring_bo
)
841 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
842 if (queue
->gsvs_ring_bo
)
843 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
844 if (queue
->compute_scratch_bo
)
845 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
849 radv_device_init_gs_info(struct radv_device
*device
)
851 switch (device
->physical_device
->rad_info
.family
) {
860 device
->gs_table_depth
= 16;
871 device
->gs_table_depth
= 32;
874 unreachable("unknown GPU");
878 VkResult
radv_CreateDevice(
879 VkPhysicalDevice physicalDevice
,
880 const VkDeviceCreateInfo
* pCreateInfo
,
881 const VkAllocationCallbacks
* pAllocator
,
884 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
886 struct radv_device
*device
;
888 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
889 if (!is_extension_enabled(physical_device
->extensions
.ext_array
,
890 physical_device
->extensions
.num_ext
,
891 pCreateInfo
->ppEnabledExtensionNames
[i
]))
892 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
895 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
897 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
899 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
901 memset(device
, 0, sizeof(*device
));
903 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
904 device
->instance
= physical_device
->instance
;
905 device
->physical_device
= physical_device
;
907 device
->debug_flags
= device
->instance
->debug_flags
;
909 device
->ws
= physical_device
->ws
;
911 device
->alloc
= *pAllocator
;
913 device
->alloc
= physical_device
->instance
->alloc
;
915 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
916 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
917 uint32_t qfi
= queue_create
->queueFamilyIndex
;
919 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
920 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
921 if (!device
->queues
[qfi
]) {
922 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
926 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
928 device
->queue_count
[qfi
] = queue_create
->queueCount
;
930 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
931 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
], qfi
, q
);
932 if (result
!= VK_SUCCESS
)
937 #if HAVE_LLVM < 0x0400
938 device
->llvm_supports_spill
= false;
940 device
->llvm_supports_spill
= true;
943 /* The maximum number of scratch waves. Scratch space isn't divided
944 * evenly between CUs. The number is only a function of the number of CUs.
945 * We can decrease the constant to decrease the scratch buffer size.
947 * sctx->scratch_waves must be >= the maximum posible size of
948 * 1 threadgroup, so that the hw doesn't hang from being unable
951 * The recommended value is 4 per CU at most. Higher numbers don't
952 * bring much benefit, but they still occupy chip resources (think
953 * async compute). I've seen ~2% performance difference between 4 and 32.
955 uint32_t max_threads_per_block
= 2048;
956 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
957 max_threads_per_block
/ 64);
959 radv_device_init_gs_info(device
);
961 result
= radv_device_init_meta(device
);
962 if (result
!= VK_SUCCESS
)
965 radv_device_init_msaa(device
);
967 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
968 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
970 case RADV_QUEUE_GENERAL
:
971 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
972 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
973 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
975 case RADV_QUEUE_COMPUTE
:
976 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
977 radeon_emit(device
->empty_cs
[family
], 0);
980 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
982 device
->flush_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
984 case RADV_QUEUE_GENERAL
:
985 case RADV_QUEUE_COMPUTE
:
986 si_cs_emit_cache_flush(device
->flush_cs
[family
],
987 device
->physical_device
->rad_info
.chip_class
,
988 family
== RADV_QUEUE_COMPUTE
&& device
->physical_device
->rad_info
.chip_class
>= CIK
,
989 RADV_CMD_FLAG_INV_ICACHE
|
990 RADV_CMD_FLAG_INV_SMEM_L1
|
991 RADV_CMD_FLAG_INV_VMEM_L1
|
992 RADV_CMD_FLAG_INV_GLOBAL_L2
);
995 device
->ws
->cs_finalize(device
->flush_cs
[family
]);
998 if (getenv("RADV_TRACE_FILE")) {
999 device
->trace_bo
= device
->ws
->buffer_create(device
->ws
, 4096, 8,
1000 RADEON_DOMAIN_VRAM
, RADEON_FLAG_CPU_ACCESS
);
1001 if (!device
->trace_bo
)
1004 device
->trace_id_ptr
= device
->ws
->buffer_map(device
->trace_bo
);
1005 if (!device
->trace_id_ptr
)
1009 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1010 cik_create_gfx_config(device
);
1012 *pDevice
= radv_device_to_handle(device
);
1016 if (device
->trace_bo
)
1017 device
->ws
->buffer_destroy(device
->trace_bo
);
1019 if (device
->gfx_init
)
1020 device
->ws
->buffer_destroy(device
->gfx_init
);
1022 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1023 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1024 radv_queue_finish(&device
->queues
[i
][q
]);
1025 if (device
->queue_count
[i
])
1026 vk_free(&device
->alloc
, device
->queues
[i
]);
1029 vk_free(&device
->alloc
, device
);
1033 void radv_DestroyDevice(
1035 const VkAllocationCallbacks
* pAllocator
)
1037 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1042 if (device
->trace_bo
)
1043 device
->ws
->buffer_destroy(device
->trace_bo
);
1045 if (device
->gfx_init
)
1046 device
->ws
->buffer_destroy(device
->gfx_init
);
1048 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1049 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1050 radv_queue_finish(&device
->queues
[i
][q
]);
1051 if (device
->queue_count
[i
])
1052 vk_free(&device
->alloc
, device
->queues
[i
]);
1053 if (device
->empty_cs
[i
])
1054 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1055 if (device
->flush_cs
[i
])
1056 device
->ws
->cs_destroy(device
->flush_cs
[i
]);
1058 radv_device_finish_meta(device
);
1060 vk_free(&device
->alloc
, device
);
1063 VkResult
radv_EnumerateInstanceExtensionProperties(
1064 const char* pLayerName
,
1065 uint32_t* pPropertyCount
,
1066 VkExtensionProperties
* pProperties
)
1068 if (pProperties
== NULL
) {
1069 *pPropertyCount
= ARRAY_SIZE(instance_extensions
);
1073 *pPropertyCount
= MIN2(*pPropertyCount
, ARRAY_SIZE(instance_extensions
));
1074 typed_memcpy(pProperties
, instance_extensions
, *pPropertyCount
);
1076 if (*pPropertyCount
< ARRAY_SIZE(instance_extensions
))
1077 return VK_INCOMPLETE
;
1082 VkResult
radv_EnumerateDeviceExtensionProperties(
1083 VkPhysicalDevice physicalDevice
,
1084 const char* pLayerName
,
1085 uint32_t* pPropertyCount
,
1086 VkExtensionProperties
* pProperties
)
1088 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1090 if (pProperties
== NULL
) {
1091 *pPropertyCount
= pdevice
->extensions
.num_ext
;
1095 *pPropertyCount
= MIN2(*pPropertyCount
, pdevice
->extensions
.num_ext
);
1096 typed_memcpy(pProperties
, pdevice
->extensions
.ext_array
, *pPropertyCount
);
1098 if (*pPropertyCount
< pdevice
->extensions
.num_ext
)
1099 return VK_INCOMPLETE
;
1104 VkResult
radv_EnumerateInstanceLayerProperties(
1105 uint32_t* pPropertyCount
,
1106 VkLayerProperties
* pProperties
)
1108 if (pProperties
== NULL
) {
1109 *pPropertyCount
= 0;
1113 /* None supported at this time */
1114 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1117 VkResult
radv_EnumerateDeviceLayerProperties(
1118 VkPhysicalDevice physicalDevice
,
1119 uint32_t* pPropertyCount
,
1120 VkLayerProperties
* pProperties
)
1122 if (pProperties
== NULL
) {
1123 *pPropertyCount
= 0;
1127 /* None supported at this time */
1128 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1131 void radv_GetDeviceQueue(
1133 uint32_t queueFamilyIndex
,
1134 uint32_t queueIndex
,
1137 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1139 *pQueue
= radv_queue_to_handle(&device
->queues
[queueFamilyIndex
][queueIndex
]);
1142 static void radv_dump_trace(struct radv_device
*device
,
1143 struct radeon_winsys_cs
*cs
)
1145 const char *filename
= getenv("RADV_TRACE_FILE");
1146 FILE *f
= fopen(filename
, "w");
1148 fprintf(stderr
, "Failed to write trace dump to %s\n", filename
);
1152 fprintf(f
, "Trace ID: %x\n", *device
->trace_id_ptr
);
1153 device
->ws
->cs_dump(cs
, f
, *device
->trace_id_ptr
);
1158 fill_geom_rings(struct radv_queue
*queue
,
1160 uint32_t esgs_ring_size
,
1161 struct radeon_winsys_bo
*esgs_ring_bo
,
1162 uint32_t gsvs_ring_size
,
1163 struct radeon_winsys_bo
*gsvs_ring_bo
)
1165 uint64_t esgs_va
= 0, gsvs_va
= 0;
1166 uint32_t *desc
= &map
[4];
1169 esgs_va
= queue
->device
->ws
->buffer_get_va(esgs_ring_bo
);
1171 gsvs_va
= queue
->device
->ws
->buffer_get_va(gsvs_ring_bo
);
1173 /* stride 0, num records - size, add tid, swizzle, elsize4,
1176 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1177 S_008F04_STRIDE(0) |
1178 S_008F04_SWIZZLE_ENABLE(true);
1179 desc
[2] = esgs_ring_size
;
1180 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1181 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1182 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1183 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1184 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1185 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1186 S_008F0C_ELEMENT_SIZE(1) |
1187 S_008F0C_INDEX_STRIDE(3) |
1188 S_008F0C_ADD_TID_ENABLE(true);
1191 /* GS entry for ES->GS ring */
1192 /* stride 0, num records - size, elsize0,
1195 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1196 S_008F04_STRIDE(0) |
1197 S_008F04_SWIZZLE_ENABLE(false);
1198 desc
[2] = esgs_ring_size
;
1199 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1200 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1201 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1202 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1203 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1204 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1205 S_008F0C_ELEMENT_SIZE(0) |
1206 S_008F0C_INDEX_STRIDE(0) |
1207 S_008F0C_ADD_TID_ENABLE(false);
1210 /* VS entry for GS->VS ring */
1211 /* stride 0, num records - size, elsize0,
1214 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1215 S_008F04_STRIDE(0) |
1216 S_008F04_SWIZZLE_ENABLE(false);
1217 desc
[2] = gsvs_ring_size
;
1218 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1219 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1220 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1221 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1222 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1223 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1224 S_008F0C_ELEMENT_SIZE(0) |
1225 S_008F0C_INDEX_STRIDE(0) |
1226 S_008F0C_ADD_TID_ENABLE(false);
1229 /* stride gsvs_itemsize, num records 64
1230 elsize 4, index stride 16 */
1231 /* shader will patch stride and desc[2] */
1233 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1234 S_008F04_STRIDE(0) |
1235 S_008F04_SWIZZLE_ENABLE(true);
1237 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1238 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1239 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1240 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1241 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1242 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1243 S_008F0C_ELEMENT_SIZE(1) |
1244 S_008F0C_INDEX_STRIDE(1) |
1245 S_008F0C_ADD_TID_ENABLE(true);
1249 radv_get_preamble_cs(struct radv_queue
*queue
,
1250 uint32_t scratch_size
,
1251 uint32_t compute_scratch_size
,
1252 uint32_t esgs_ring_size
,
1253 uint32_t gsvs_ring_size
,
1254 struct radeon_winsys_cs
**initial_preamble_cs
,
1255 struct radeon_winsys_cs
**continue_preamble_cs
)
1257 struct radeon_winsys_bo
*scratch_bo
= NULL
;
1258 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
1259 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
1260 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
1261 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
1262 struct radeon_winsys_cs
*dest_cs
[2] = {0};
1264 if (scratch_size
<= queue
->scratch_size
&&
1265 compute_scratch_size
<= queue
->compute_scratch_size
&&
1266 esgs_ring_size
<= queue
->esgs_ring_size
&&
1267 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
1268 queue
->initial_preamble_cs
) {
1269 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1270 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1271 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1272 *continue_preamble_cs
= NULL
;
1276 if (scratch_size
> queue
->scratch_size
) {
1277 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1281 RADEON_FLAG_NO_CPU_ACCESS
);
1285 scratch_bo
= queue
->scratch_bo
;
1287 if (compute_scratch_size
> queue
->compute_scratch_size
) {
1288 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1289 compute_scratch_size
,
1292 RADEON_FLAG_NO_CPU_ACCESS
);
1293 if (!compute_scratch_bo
)
1297 compute_scratch_bo
= queue
->compute_scratch_bo
;
1299 if (esgs_ring_size
> queue
->esgs_ring_size
) {
1300 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1304 RADEON_FLAG_NO_CPU_ACCESS
);
1308 esgs_ring_bo
= queue
->esgs_ring_bo
;
1309 esgs_ring_size
= queue
->esgs_ring_size
;
1312 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
1313 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1317 RADEON_FLAG_NO_CPU_ACCESS
);
1321 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
1322 gsvs_ring_size
= queue
->gsvs_ring_size
;
1325 if (scratch_bo
!= queue
->scratch_bo
||
1326 esgs_ring_bo
!= queue
->esgs_ring_bo
||
1327 gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
1329 if (gsvs_ring_bo
|| esgs_ring_bo
)
1330 size
= 80; /* 2 dword + 2 padding + 4 dword * 4 */
1331 else if (scratch_bo
)
1332 size
= 8; /* 2 dword */
1334 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1338 RADEON_FLAG_CPU_ACCESS
);
1342 descriptor_bo
= queue
->descriptor_bo
;
1344 for(int i
= 0; i
< 2; ++i
) {
1345 struct radeon_winsys_cs
*cs
= NULL
;
1346 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
1347 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
1354 queue
->device
->ws
->cs_add_buffer(cs
, scratch_bo
, 8);
1357 queue
->device
->ws
->cs_add_buffer(cs
, esgs_ring_bo
, 8);
1360 queue
->device
->ws
->cs_add_buffer(cs
, gsvs_ring_bo
, 8);
1363 queue
->device
->ws
->cs_add_buffer(cs
, descriptor_bo
, 8);
1365 if (descriptor_bo
!= queue
->descriptor_bo
) {
1366 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
1369 uint64_t scratch_va
= queue
->device
->ws
->buffer_get_va(scratch_bo
);
1370 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1371 S_008F04_SWIZZLE_ENABLE(1);
1372 map
[0] = scratch_va
;
1376 if (esgs_ring_bo
|| gsvs_ring_bo
)
1377 fill_geom_rings(queue
, map
, esgs_ring_size
, esgs_ring_bo
, gsvs_ring_size
, gsvs_ring_bo
);
1379 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
1382 if (esgs_ring_bo
|| gsvs_ring_bo
) {
1383 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1384 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
1385 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1386 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
1388 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1389 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
1390 radeon_emit(cs
, esgs_ring_size
>> 8);
1391 radeon_emit(cs
, gsvs_ring_size
>> 8);
1393 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
1394 radeon_emit(cs
, esgs_ring_size
>> 8);
1395 radeon_emit(cs
, gsvs_ring_size
>> 8);
1399 if (descriptor_bo
) {
1400 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
1401 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
1402 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
1403 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
1404 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
1405 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
1407 uint64_t va
= queue
->device
->ws
->buffer_get_va(descriptor_bo
);
1409 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
1410 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
1411 radeon_emit(cs
, va
);
1412 radeon_emit(cs
, va
>> 32);
1416 if (compute_scratch_bo
) {
1417 uint64_t scratch_va
= queue
->device
->ws
->buffer_get_va(compute_scratch_bo
);
1418 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1419 S_008F04_SWIZZLE_ENABLE(1);
1421 queue
->device
->ws
->cs_add_buffer(cs
, compute_scratch_bo
, 8);
1423 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
1424 radeon_emit(cs
, scratch_va
);
1425 radeon_emit(cs
, rsrc1
);
1429 si_cs_emit_cache_flush(cs
,
1430 queue
->device
->physical_device
->rad_info
.chip_class
,
1431 queue
->queue_family_index
== RING_COMPUTE
&&
1432 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
1433 RADV_CMD_FLAG_INV_ICACHE
|
1434 RADV_CMD_FLAG_INV_SMEM_L1
|
1435 RADV_CMD_FLAG_INV_VMEM_L1
|
1436 RADV_CMD_FLAG_INV_GLOBAL_L2
);
1439 if (!queue
->device
->ws
->cs_finalize(cs
))
1443 if (queue
->initial_preamble_cs
)
1444 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1446 if (queue
->continue_preamble_cs
)
1447 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1449 queue
->initial_preamble_cs
= dest_cs
[0];
1450 queue
->continue_preamble_cs
= dest_cs
[1];
1452 if (scratch_bo
!= queue
->scratch_bo
) {
1453 if (queue
->scratch_bo
)
1454 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1455 queue
->scratch_bo
= scratch_bo
;
1456 queue
->scratch_size
= scratch_size
;
1459 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
1460 if (queue
->compute_scratch_bo
)
1461 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1462 queue
->compute_scratch_bo
= compute_scratch_bo
;
1463 queue
->compute_scratch_size
= compute_scratch_size
;
1466 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
1467 if (queue
->esgs_ring_bo
)
1468 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1469 queue
->esgs_ring_bo
= esgs_ring_bo
;
1470 queue
->esgs_ring_size
= esgs_ring_size
;
1473 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
1474 if (queue
->gsvs_ring_bo
)
1475 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1476 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
1477 queue
->gsvs_ring_size
= gsvs_ring_size
;
1480 if (descriptor_bo
!= queue
->descriptor_bo
) {
1481 if (queue
->descriptor_bo
)
1482 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1484 queue
->descriptor_bo
= descriptor_bo
;
1487 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1488 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1489 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1490 *continue_preamble_cs
= NULL
;
1493 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
1495 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
1496 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
1497 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
1498 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
1499 queue
->device
->ws
->buffer_destroy(scratch_bo
);
1500 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
1501 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
1502 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
1503 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
1504 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
1505 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
1506 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
1509 VkResult
radv_QueueSubmit(
1511 uint32_t submitCount
,
1512 const VkSubmitInfo
* pSubmits
,
1515 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
1516 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
1517 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
1518 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
1520 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
1521 uint32_t scratch_size
= 0;
1522 uint32_t compute_scratch_size
= 0;
1523 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
1524 struct radeon_winsys_cs
*initial_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
1526 bool fence_emitted
= false;
1528 /* Do this first so failing to allocate scratch buffers can't result in
1529 * partially executed submissions. */
1530 for (uint32_t i
= 0; i
< submitCount
; i
++) {
1531 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
1532 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
1533 pSubmits
[i
].pCommandBuffers
[j
]);
1535 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
1536 compute_scratch_size
= MAX2(compute_scratch_size
,
1537 cmd_buffer
->compute_scratch_size_needed
);
1538 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
1539 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
1543 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
1544 esgs_ring_size
, gsvs_ring_size
,
1545 &initial_preamble_cs
, &continue_preamble_cs
);
1546 if (result
!= VK_SUCCESS
)
1549 for (uint32_t i
= 0; i
< submitCount
; i
++) {
1550 struct radeon_winsys_cs
**cs_array
;
1551 bool has_flush
= !submitCount
;
1552 bool can_patch
= !has_flush
;
1555 if (!pSubmits
[i
].commandBufferCount
) {
1556 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
1557 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
1558 &queue
->device
->empty_cs
[queue
->queue_family_index
],
1560 (struct radeon_winsys_sem
**)pSubmits
[i
].pWaitSemaphores
,
1561 pSubmits
[i
].waitSemaphoreCount
,
1562 (struct radeon_winsys_sem
**)pSubmits
[i
].pSignalSemaphores
,
1563 pSubmits
[i
].signalSemaphoreCount
,
1566 radv_loge("failed to submit CS %d\n", i
);
1569 fence_emitted
= true;
1574 cs_array
= malloc(sizeof(struct radeon_winsys_cs
*) *
1575 (pSubmits
[i
].commandBufferCount
+ has_flush
));
1578 cs_array
[0] = queue
->device
->flush_cs
[queue
->queue_family_index
];
1580 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
1581 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
1582 pSubmits
[i
].pCommandBuffers
[j
]);
1583 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
1585 cs_array
[j
+ has_flush
] = cmd_buffer
->cs
;
1586 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
1590 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
+ has_flush
; j
+= advance
) {
1591 advance
= MIN2(max_cs_submission
,
1592 pSubmits
[i
].commandBufferCount
+ has_flush
- j
);
1594 bool e
= j
+ advance
== pSubmits
[i
].commandBufferCount
+ has_flush
;
1596 if (queue
->device
->trace_bo
)
1597 *queue
->device
->trace_id_ptr
= 0;
1599 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
1600 advance
, initial_preamble_cs
, continue_preamble_cs
,
1601 (struct radeon_winsys_sem
**)pSubmits
[i
].pWaitSemaphores
,
1602 b
? pSubmits
[i
].waitSemaphoreCount
: 0,
1603 (struct radeon_winsys_sem
**)pSubmits
[i
].pSignalSemaphores
,
1604 e
? pSubmits
[i
].signalSemaphoreCount
: 0,
1605 can_patch
, base_fence
);
1608 radv_loge("failed to submit CS %d\n", i
);
1611 fence_emitted
= true;
1612 if (queue
->device
->trace_bo
) {
1613 bool success
= queue
->device
->ws
->ctx_wait_idle(
1615 radv_queue_family_to_ring(
1616 queue
->queue_family_index
),
1619 if (!success
) { /* Hang */
1620 radv_dump_trace(queue
->device
, cs_array
[j
]);
1630 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
1631 &queue
->device
->empty_cs
[queue
->queue_family_index
],
1632 1, NULL
, NULL
, NULL
, 0, NULL
, 0,
1635 fence
->submitted
= true;
1641 VkResult
radv_QueueWaitIdle(
1644 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
1646 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
1647 radv_queue_family_to_ring(queue
->queue_family_index
),
1652 VkResult
radv_DeviceWaitIdle(
1655 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1657 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1658 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
1659 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
1665 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
1666 VkInstance instance
,
1669 return radv_lookup_entrypoint(pName
);
1672 /* The loader wants us to expose a second GetInstanceProcAddr function
1673 * to work around certain LD_PRELOAD issues seen in apps.
1676 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1677 VkInstance instance
,
1681 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1682 VkInstance instance
,
1685 return radv_GetInstanceProcAddr(instance
, pName
);
1688 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
1692 return radv_lookup_entrypoint(pName
);
1695 bool radv_get_memory_fd(struct radv_device
*device
,
1696 struct radv_device_memory
*memory
,
1699 struct radeon_bo_metadata metadata
;
1701 if (memory
->image
) {
1702 radv_init_metadata(device
, memory
->image
, &metadata
);
1703 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
1706 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
1710 VkResult
radv_AllocateMemory(
1712 const VkMemoryAllocateInfo
* pAllocateInfo
,
1713 const VkAllocationCallbacks
* pAllocator
,
1714 VkDeviceMemory
* pMem
)
1716 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1717 struct radv_device_memory
*mem
;
1719 enum radeon_bo_domain domain
;
1721 const VkDedicatedAllocationMemoryAllocateInfoNV
*dedicate_info
= NULL
;
1722 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1724 if (pAllocateInfo
->allocationSize
== 0) {
1725 /* Apparently, this is allowed */
1726 *pMem
= VK_NULL_HANDLE
;
1730 vk_foreach_struct(ext
, pAllocateInfo
->pNext
) {
1731 switch (ext
->sType
) {
1732 case VK_STRUCTURE_TYPE_DEDICATED_ALLOCATION_MEMORY_ALLOCATE_INFO_NV
:
1733 dedicate_info
= (const VkDedicatedAllocationMemoryAllocateInfoNV
*)ext
;
1740 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
1741 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1743 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1745 if (dedicate_info
) {
1746 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
1747 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
1753 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
1754 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
1755 pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_CACHED
)
1756 domain
= RADEON_DOMAIN_GTT
;
1758 domain
= RADEON_DOMAIN_VRAM
;
1760 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_VRAM
)
1761 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
1763 flags
|= RADEON_FLAG_CPU_ACCESS
;
1765 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
1766 flags
|= RADEON_FLAG_GTT_WC
;
1768 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, 65536,
1772 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
1775 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
1777 *pMem
= radv_device_memory_to_handle(mem
);
1782 vk_free2(&device
->alloc
, pAllocator
, mem
);
1787 void radv_FreeMemory(
1789 VkDeviceMemory _mem
,
1790 const VkAllocationCallbacks
* pAllocator
)
1792 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1793 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
1798 device
->ws
->buffer_destroy(mem
->bo
);
1801 vk_free2(&device
->alloc
, pAllocator
, mem
);
1804 VkResult
radv_MapMemory(
1806 VkDeviceMemory _memory
,
1807 VkDeviceSize offset
,
1809 VkMemoryMapFlags flags
,
1812 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1813 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
1820 *ppData
= device
->ws
->buffer_map(mem
->bo
);
1826 return VK_ERROR_MEMORY_MAP_FAILED
;
1829 void radv_UnmapMemory(
1831 VkDeviceMemory _memory
)
1833 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1834 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
1839 device
->ws
->buffer_unmap(mem
->bo
);
1842 VkResult
radv_FlushMappedMemoryRanges(
1844 uint32_t memoryRangeCount
,
1845 const VkMappedMemoryRange
* pMemoryRanges
)
1850 VkResult
radv_InvalidateMappedMemoryRanges(
1852 uint32_t memoryRangeCount
,
1853 const VkMappedMemoryRange
* pMemoryRanges
)
1858 void radv_GetBufferMemoryRequirements(
1861 VkMemoryRequirements
* pMemoryRequirements
)
1863 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
1865 pMemoryRequirements
->memoryTypeBits
= (1u << RADV_MEM_TYPE_COUNT
) - 1;
1867 pMemoryRequirements
->size
= buffer
->size
;
1868 pMemoryRequirements
->alignment
= 16;
1871 void radv_GetImageMemoryRequirements(
1874 VkMemoryRequirements
* pMemoryRequirements
)
1876 RADV_FROM_HANDLE(radv_image
, image
, _image
);
1878 pMemoryRequirements
->memoryTypeBits
= (1u << RADV_MEM_TYPE_COUNT
) - 1;
1880 pMemoryRequirements
->size
= image
->size
;
1881 pMemoryRequirements
->alignment
= image
->alignment
;
1884 void radv_GetImageSparseMemoryRequirements(
1887 uint32_t* pSparseMemoryRequirementCount
,
1888 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
1893 void radv_GetDeviceMemoryCommitment(
1895 VkDeviceMemory memory
,
1896 VkDeviceSize
* pCommittedMemoryInBytes
)
1898 *pCommittedMemoryInBytes
= 0;
1901 VkResult
radv_BindBufferMemory(
1904 VkDeviceMemory _memory
,
1905 VkDeviceSize memoryOffset
)
1907 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
1908 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
1911 buffer
->bo
= mem
->bo
;
1912 buffer
->offset
= memoryOffset
;
1921 VkResult
radv_BindImageMemory(
1924 VkDeviceMemory _memory
,
1925 VkDeviceSize memoryOffset
)
1927 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
1928 RADV_FROM_HANDLE(radv_image
, image
, _image
);
1931 image
->bo
= mem
->bo
;
1932 image
->offset
= memoryOffset
;
1941 VkResult
radv_QueueBindSparse(
1943 uint32_t bindInfoCount
,
1944 const VkBindSparseInfo
* pBindInfo
,
1947 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1950 VkResult
radv_CreateFence(
1952 const VkFenceCreateInfo
* pCreateInfo
,
1953 const VkAllocationCallbacks
* pAllocator
,
1956 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1957 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
1959 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1962 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1964 memset(fence
, 0, sizeof(*fence
));
1965 fence
->submitted
= false;
1966 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
1967 fence
->fence
= device
->ws
->create_fence();
1968 if (!fence
->fence
) {
1969 vk_free2(&device
->alloc
, pAllocator
, fence
);
1970 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1973 *pFence
= radv_fence_to_handle(fence
);
1978 void radv_DestroyFence(
1981 const VkAllocationCallbacks
* pAllocator
)
1983 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1984 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
1988 device
->ws
->destroy_fence(fence
->fence
);
1989 vk_free2(&device
->alloc
, pAllocator
, fence
);
1992 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
1994 uint64_t current_time
;
1997 clock_gettime(CLOCK_MONOTONIC
, &tv
);
1998 current_time
= tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
2000 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
2002 return current_time
+ timeout
;
2005 VkResult
radv_WaitForFences(
2007 uint32_t fenceCount
,
2008 const VkFence
* pFences
,
2012 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2013 timeout
= radv_get_absolute_timeout(timeout
);
2015 if (!waitAll
&& fenceCount
> 1) {
2016 fprintf(stderr
, "radv: WaitForFences without waitAll not implemented yet\n");
2019 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
2020 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
2021 bool expired
= false;
2023 if (fence
->signalled
)
2026 if (!fence
->submitted
)
2029 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
2033 fence
->signalled
= true;
2039 VkResult
radv_ResetFences(VkDevice device
,
2040 uint32_t fenceCount
,
2041 const VkFence
*pFences
)
2043 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
2044 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
2045 fence
->submitted
= fence
->signalled
= false;
2051 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
2053 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2054 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2056 if (fence
->signalled
)
2058 if (!fence
->submitted
)
2059 return VK_NOT_READY
;
2061 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
2062 return VK_NOT_READY
;
2068 // Queue semaphore functions
2070 VkResult
radv_CreateSemaphore(
2072 const VkSemaphoreCreateInfo
* pCreateInfo
,
2073 const VkAllocationCallbacks
* pAllocator
,
2074 VkSemaphore
* pSemaphore
)
2076 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2077 struct radeon_winsys_sem
*sem
;
2079 sem
= device
->ws
->create_sem(device
->ws
);
2081 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2083 *pSemaphore
= radeon_winsys_sem_to_handle(sem
);
2087 void radv_DestroySemaphore(
2089 VkSemaphore _semaphore
,
2090 const VkAllocationCallbacks
* pAllocator
)
2092 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2093 RADV_FROM_HANDLE(radeon_winsys_sem
, sem
, _semaphore
);
2097 device
->ws
->destroy_sem(sem
);
2100 VkResult
radv_CreateEvent(
2102 const VkEventCreateInfo
* pCreateInfo
,
2103 const VkAllocationCallbacks
* pAllocator
,
2106 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2107 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
2109 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2112 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2114 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
2116 RADEON_FLAG_CPU_ACCESS
);
2118 vk_free2(&device
->alloc
, pAllocator
, event
);
2119 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2122 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
2124 *pEvent
= radv_event_to_handle(event
);
2129 void radv_DestroyEvent(
2132 const VkAllocationCallbacks
* pAllocator
)
2134 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2135 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2139 device
->ws
->buffer_destroy(event
->bo
);
2140 vk_free2(&device
->alloc
, pAllocator
, event
);
2143 VkResult
radv_GetEventStatus(
2147 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2149 if (*event
->map
== 1)
2150 return VK_EVENT_SET
;
2151 return VK_EVENT_RESET
;
2154 VkResult
radv_SetEvent(
2158 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2164 VkResult
radv_ResetEvent(
2168 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2174 VkResult
radv_CreateBuffer(
2176 const VkBufferCreateInfo
* pCreateInfo
,
2177 const VkAllocationCallbacks
* pAllocator
,
2180 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2181 struct radv_buffer
*buffer
;
2183 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2185 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
2186 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2188 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2190 buffer
->size
= pCreateInfo
->size
;
2191 buffer
->usage
= pCreateInfo
->usage
;
2195 *pBuffer
= radv_buffer_to_handle(buffer
);
2200 void radv_DestroyBuffer(
2203 const VkAllocationCallbacks
* pAllocator
)
2205 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2206 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2211 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2214 static inline unsigned
2215 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
2218 return image
->surface
.stencil_tiling_index
[level
];
2220 return image
->surface
.tiling_index
[level
];
2223 static uint32_t radv_surface_layer_count(struct radv_image_view
*iview
)
2225 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: iview
->layer_count
;
2229 radv_initialise_color_surface(struct radv_device
*device
,
2230 struct radv_color_buffer_info
*cb
,
2231 struct radv_image_view
*iview
)
2233 const struct vk_format_description
*desc
;
2234 unsigned ntype
, format
, swap
, endian
;
2235 unsigned blend_clamp
= 0, blend_bypass
= 0;
2236 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
2238 const struct radeon_surf
*surf
= &iview
->image
->surface
;
2239 const struct radeon_surf_level
*level_info
= &surf
->level
[iview
->base_mip
];
2241 desc
= vk_format_description(iview
->vk_format
);
2243 memset(cb
, 0, sizeof(*cb
));
2245 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
2246 va
+= level_info
->offset
;
2247 cb
->cb_color_base
= va
>> 8;
2249 /* CMASK variables */
2250 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
2251 va
+= iview
->image
->cmask
.offset
;
2252 cb
->cb_color_cmask
= va
>> 8;
2253 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
2255 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
2256 va
+= iview
->image
->dcc_offset
;
2257 cb
->cb_dcc_base
= va
>> 8;
2259 uint32_t max_slice
= radv_surface_layer_count(iview
);
2260 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
2261 S_028C6C_SLICE_MAX(iview
->base_layer
+ max_slice
- 1);
2263 cb
->micro_tile_mode
= iview
->image
->surface
.micro_tile_mode
;
2264 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
2265 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
2266 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
2268 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
2269 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
2271 /* Intensity is implemented as Red, so treat it that way. */
2272 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
) |
2273 S_028C74_TILE_MODE_INDEX(tile_mode_index
);
2275 if (iview
->image
->samples
> 1) {
2276 unsigned log_samples
= util_logbase2(iview
->image
->samples
);
2278 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
2279 S_028C74_NUM_FRAGMENTS(log_samples
);
2282 if (iview
->image
->fmask
.size
) {
2283 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
2284 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
2285 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
2286 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
2287 cb
->cb_color_fmask
= va
>> 8;
2288 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
2290 /* This must be set for fast clear to work without FMASK. */
2291 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
2292 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
2293 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
2294 cb
->cb_color_fmask
= cb
->cb_color_base
;
2295 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
2298 ntype
= radv_translate_color_numformat(iview
->vk_format
,
2300 vk_format_get_first_non_void_channel(iview
->vk_format
));
2301 format
= radv_translate_colorformat(iview
->vk_format
);
2302 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
2303 radv_finishme("Illegal color\n");
2304 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
2305 endian
= radv_colorformat_endian_swap(format
);
2307 /* blend clamp should be set for all NORM/SRGB types */
2308 if (ntype
== V_028C70_NUMBER_UNORM
||
2309 ntype
== V_028C70_NUMBER_SNORM
||
2310 ntype
== V_028C70_NUMBER_SRGB
)
2313 /* set blend bypass according to docs if SINT/UINT or
2314 8/24 COLOR variants */
2315 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
2316 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
2317 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
2322 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
2323 (format
== V_028C70_COLOR_8
||
2324 format
== V_028C70_COLOR_8_8
||
2325 format
== V_028C70_COLOR_8_8_8_8
))
2326 ->color_is_int8
= true;
2328 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
2329 S_028C70_COMP_SWAP(swap
) |
2330 S_028C70_BLEND_CLAMP(blend_clamp
) |
2331 S_028C70_BLEND_BYPASS(blend_bypass
) |
2332 S_028C70_SIMPLE_FLOAT(1) |
2333 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
2334 ntype
!= V_028C70_NUMBER_SNORM
&&
2335 ntype
!= V_028C70_NUMBER_SRGB
&&
2336 format
!= V_028C70_COLOR_8_24
&&
2337 format
!= V_028C70_COLOR_24_8
) |
2338 S_028C70_NUMBER_TYPE(ntype
) |
2339 S_028C70_ENDIAN(endian
);
2340 if (iview
->image
->samples
> 1)
2341 if (iview
->image
->fmask
.size
)
2342 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
2344 if (iview
->image
->cmask
.size
&&
2345 !(device
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
2346 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
2348 if (iview
->image
->surface
.dcc_size
&& level_info
->dcc_enabled
)
2349 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
2351 if (device
->physical_device
->rad_info
.chip_class
>= VI
) {
2352 unsigned max_uncompressed_block_size
= 2;
2353 if (iview
->image
->samples
> 1) {
2354 if (iview
->image
->surface
.bpe
== 1)
2355 max_uncompressed_block_size
= 0;
2356 else if (iview
->image
->surface
.bpe
== 2)
2357 max_uncompressed_block_size
= 1;
2360 cb
->cb_dcc_control
= S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
2361 S_028C78_INDEPENDENT_64B_BLOCKS(1);
2364 /* This must be set for fast clear to work without FMASK. */
2365 if (!iview
->image
->fmask
.size
&&
2366 device
->physical_device
->rad_info
.chip_class
== SI
) {
2367 unsigned bankh
= util_logbase2(iview
->image
->surface
.bankh
);
2368 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
2373 radv_initialise_ds_surface(struct radv_device
*device
,
2374 struct radv_ds_buffer_info
*ds
,
2375 struct radv_image_view
*iview
)
2377 unsigned level
= iview
->base_mip
;
2379 uint64_t va
, s_offs
, z_offs
;
2380 const struct radeon_surf_level
*level_info
= &iview
->image
->surface
.level
[level
];
2381 memset(ds
, 0, sizeof(*ds
));
2382 switch (iview
->vk_format
) {
2383 case VK_FORMAT_D24_UNORM_S8_UINT
:
2384 case VK_FORMAT_X8_D24_UNORM_PACK32
:
2385 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
2386 ds
->offset_scale
= 2.0f
;
2388 case VK_FORMAT_D16_UNORM
:
2389 case VK_FORMAT_D16_UNORM_S8_UINT
:
2390 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
2391 ds
->offset_scale
= 4.0f
;
2393 case VK_FORMAT_D32_SFLOAT
:
2394 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
2395 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
2396 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
2397 ds
->offset_scale
= 1.0f
;
2403 format
= radv_translate_dbformat(iview
->vk_format
);
2404 if (format
== V_028040_Z_INVALID
) {
2405 fprintf(stderr
, "Invalid DB format: %d, disabling DB.\n", iview
->vk_format
);
2408 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
2409 s_offs
= z_offs
= va
;
2410 z_offs
+= iview
->image
->surface
.level
[level
].offset
;
2411 s_offs
+= iview
->image
->surface
.stencil_level
[level
].offset
;
2413 uint32_t max_slice
= radv_surface_layer_count(iview
);
2414 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
2415 S_028008_SLICE_MAX(iview
->base_layer
+ max_slice
- 1);
2416 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(1);
2417 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
2419 if (iview
->image
->samples
> 1)
2420 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->samples
));
2422 if (iview
->image
->surface
.flags
& RADEON_SURF_SBUFFER
)
2423 ds
->db_stencil_info
= S_028044_FORMAT(V_028044_STENCIL_8
);
2425 ds
->db_stencil_info
= S_028044_FORMAT(V_028044_STENCIL_INVALID
);
2427 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2428 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
2429 unsigned tiling_index
= iview
->image
->surface
.tiling_index
[level
];
2430 unsigned stencil_index
= iview
->image
->surface
.stencil_tiling_index
[level
];
2431 unsigned macro_index
= iview
->image
->surface
.macro_tile_index
;
2432 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
2433 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
2434 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
2436 ds
->db_depth_info
|=
2437 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
2438 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
2439 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
2440 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
2441 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
2442 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
2443 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
2444 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
2446 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
2447 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
2448 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
2449 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
2452 if (iview
->image
->surface
.htile_size
&& !level
) {
2453 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1) |
2454 S_028040_ALLOW_EXPCLEAR(1);
2456 if (iview
->image
->surface
.flags
& RADEON_SURF_SBUFFER
) {
2457 /* Workaround: For a not yet understood reason, the
2458 * combination of MSAA, fast stencil clear and stencil
2459 * decompress messes with subsequent stencil buffer
2460 * uses. Problem was reproduced on Verde, Bonaire,
2461 * Tonga, and Carrizo.
2463 * Disabling EXPCLEAR works around the problem.
2465 * Check piglit's arb_texture_multisample-stencil-clear
2466 * test if you want to try changing this.
2468 if (iview
->image
->samples
<= 1)
2469 ds
->db_stencil_info
|= S_028044_ALLOW_EXPCLEAR(1);
2471 /* Use all of the htile_buffer for depth if there's no stencil. */
2472 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
2474 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
+
2475 iview
->image
->htile_offset
;
2476 ds
->db_htile_data_base
= va
>> 8;
2477 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
2479 ds
->db_htile_data_base
= 0;
2480 ds
->db_htile_surface
= 0;
2483 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
2484 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
2486 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
2487 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
2488 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
2491 VkResult
radv_CreateFramebuffer(
2493 const VkFramebufferCreateInfo
* pCreateInfo
,
2494 const VkAllocationCallbacks
* pAllocator
,
2495 VkFramebuffer
* pFramebuffer
)
2497 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2498 struct radv_framebuffer
*framebuffer
;
2500 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
2502 size_t size
= sizeof(*framebuffer
) +
2503 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
2504 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
2505 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2506 if (framebuffer
== NULL
)
2507 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2509 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
2510 framebuffer
->width
= pCreateInfo
->width
;
2511 framebuffer
->height
= pCreateInfo
->height
;
2512 framebuffer
->layers
= pCreateInfo
->layers
;
2513 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
2514 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
2515 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
2516 framebuffer
->attachments
[i
].attachment
= iview
;
2517 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
2518 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
2519 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
2520 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
2522 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
2523 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
2524 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_layer_count(iview
));
2527 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
2531 void radv_DestroyFramebuffer(
2534 const VkAllocationCallbacks
* pAllocator
)
2536 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2537 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
2541 vk_free2(&device
->alloc
, pAllocator
, fb
);
2544 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
2546 switch (address_mode
) {
2547 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
2548 return V_008F30_SQ_TEX_WRAP
;
2549 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
2550 return V_008F30_SQ_TEX_MIRROR
;
2551 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
2552 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
2553 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
2554 return V_008F30_SQ_TEX_CLAMP_BORDER
;
2555 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
2556 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
2558 unreachable("illegal tex wrap mode");
2564 radv_tex_compare(VkCompareOp op
)
2567 case VK_COMPARE_OP_NEVER
:
2568 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
2569 case VK_COMPARE_OP_LESS
:
2570 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
2571 case VK_COMPARE_OP_EQUAL
:
2572 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
2573 case VK_COMPARE_OP_LESS_OR_EQUAL
:
2574 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
2575 case VK_COMPARE_OP_GREATER
:
2576 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
2577 case VK_COMPARE_OP_NOT_EQUAL
:
2578 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
2579 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
2580 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
2581 case VK_COMPARE_OP_ALWAYS
:
2582 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
2584 unreachable("illegal compare mode");
2590 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
2593 case VK_FILTER_NEAREST
:
2594 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
2595 V_008F38_SQ_TEX_XY_FILTER_POINT
);
2596 case VK_FILTER_LINEAR
:
2597 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
2598 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
2599 case VK_FILTER_CUBIC_IMG
:
2601 fprintf(stderr
, "illegal texture filter");
2607 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
2610 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
2611 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
2612 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
2613 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
2615 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
2620 radv_tex_bordercolor(VkBorderColor bcolor
)
2623 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
2624 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
2625 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
2626 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
2627 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
2628 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
2629 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
2630 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
2631 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
2639 radv_tex_aniso_filter(unsigned filter
)
2653 radv_init_sampler(struct radv_device
*device
,
2654 struct radv_sampler
*sampler
,
2655 const VkSamplerCreateInfo
*pCreateInfo
)
2657 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
2658 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
2659 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
2660 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
2662 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
2663 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
2664 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
2665 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
2666 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
2667 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
2668 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
2669 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
2670 S_008F30_DISABLE_CUBE_WRAP(0) |
2671 S_008F30_COMPAT_MODE(is_vi
));
2672 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
2673 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
2674 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
2675 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
2676 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
2677 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
2678 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
2679 S_008F38_MIP_POINT_PRECLAMP(0) |
2680 S_008F38_DISABLE_LSB_CEIL(1) |
2681 S_008F38_FILTER_PREC_FIX(1) |
2682 S_008F38_ANISO_OVERRIDE(is_vi
));
2683 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
2684 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
2687 VkResult
radv_CreateSampler(
2689 const VkSamplerCreateInfo
* pCreateInfo
,
2690 const VkAllocationCallbacks
* pAllocator
,
2691 VkSampler
* pSampler
)
2693 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2694 struct radv_sampler
*sampler
;
2696 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
2698 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
2699 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2701 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2703 radv_init_sampler(device
, sampler
, pCreateInfo
);
2704 *pSampler
= radv_sampler_to_handle(sampler
);
2709 void radv_DestroySampler(
2712 const VkAllocationCallbacks
* pAllocator
)
2714 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2715 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
2719 vk_free2(&device
->alloc
, pAllocator
, sampler
);
2723 /* vk_icd.h does not declare this function, so we declare it here to
2724 * suppress Wmissing-prototypes.
2726 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2727 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
2729 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2730 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
2732 /* For the full details on loader interface versioning, see
2733 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
2734 * What follows is a condensed summary, to help you navigate the large and
2735 * confusing official doc.
2737 * - Loader interface v0 is incompatible with later versions. We don't
2740 * - In loader interface v1:
2741 * - The first ICD entrypoint called by the loader is
2742 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
2744 * - The ICD must statically expose no other Vulkan symbol unless it is
2745 * linked with -Bsymbolic.
2746 * - Each dispatchable Vulkan handle created by the ICD must be
2747 * a pointer to a struct whose first member is VK_LOADER_DATA. The
2748 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
2749 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
2750 * vkDestroySurfaceKHR(). The ICD must be capable of working with
2751 * such loader-managed surfaces.
2753 * - Loader interface v2 differs from v1 in:
2754 * - The first ICD entrypoint called by the loader is
2755 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
2756 * statically expose this entrypoint.
2758 * - Loader interface v3 differs from v2 in:
2759 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
2760 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
2761 * because the loader no longer does so.
2763 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);