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
34 #include "radv_private.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"
45 #include "util/debug.h"
46 struct radv_dispatch_table dtable
;
49 radv_get_function_timestamp(void *ptr
, uint32_t* timestamp
)
53 if (!dladdr(ptr
, &info
) || !info
.dli_fname
) {
56 if (stat(info
.dli_fname
, &st
)) {
59 *timestamp
= st
.st_mtim
.tv_sec
;
64 radv_device_get_cache_uuid(enum radeon_family family
, void *uuid
)
66 uint32_t mesa_timestamp
, llvm_timestamp
;
68 memset(uuid
, 0, VK_UUID_SIZE
);
69 if (radv_get_function_timestamp(radv_device_get_cache_uuid
, &mesa_timestamp
) ||
70 radv_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo
, &llvm_timestamp
))
73 memcpy(uuid
, &mesa_timestamp
, 4);
74 memcpy((char*)uuid
+ 4, &llvm_timestamp
, 4);
75 memcpy((char*)uuid
+ 8, &f
, 2);
76 snprintf((char*)uuid
+ 10, VK_UUID_SIZE
- 10, "radv");
80 static const VkExtensionProperties instance_extensions
[] = {
82 .extensionName
= VK_KHR_SURFACE_EXTENSION_NAME
,
85 #ifdef VK_USE_PLATFORM_XCB_KHR
87 .extensionName
= VK_KHR_XCB_SURFACE_EXTENSION_NAME
,
91 #ifdef VK_USE_PLATFORM_XLIB_KHR
93 .extensionName
= VK_KHR_XLIB_SURFACE_EXTENSION_NAME
,
97 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
99 .extensionName
= VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME
,
105 static const VkExtensionProperties common_device_extensions
[] = {
107 .extensionName
= VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME
,
111 .extensionName
= VK_KHR_SWAPCHAIN_EXTENSION_NAME
,
115 .extensionName
= VK_AMD_DRAW_INDIRECT_COUNT_EXTENSION_NAME
,
119 .extensionName
= VK_AMD_NEGATIVE_VIEWPORT_HEIGHT_EXTENSION_NAME
,
125 radv_extensions_register(struct radv_instance
*instance
,
126 struct radv_extensions
*extensions
,
127 const VkExtensionProperties
*new_ext
,
131 VkExtensionProperties
*new_ptr
;
133 assert(new_ext
&& num_ext
> 0);
136 return VK_ERROR_INITIALIZATION_FAILED
;
138 new_size
= (extensions
->num_ext
+ num_ext
) * sizeof(VkExtensionProperties
);
139 new_ptr
= vk_realloc(&instance
->alloc
, extensions
->ext_array
,
140 new_size
, 8, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
142 /* Old array continues to be valid, update nothing */
144 return VK_ERROR_OUT_OF_HOST_MEMORY
;
146 memcpy(&new_ptr
[extensions
->num_ext
], new_ext
,
147 num_ext
* sizeof(VkExtensionProperties
));
148 extensions
->ext_array
= new_ptr
;
149 extensions
->num_ext
+= num_ext
;
155 radv_extensions_finish(struct radv_instance
*instance
,
156 struct radv_extensions
*extensions
)
161 radv_loge("Attemted to free invalid extension struct\n");
163 if (extensions
->ext_array
)
164 vk_free(&instance
->alloc
, extensions
->ext_array
);
168 is_extension_enabled(const VkExtensionProperties
*extensions
,
172 assert(extensions
&& name
);
174 for (uint32_t i
= 0; i
< num_ext
; i
++) {
175 if (strcmp(name
, extensions
[i
].extensionName
) == 0)
183 radv_physical_device_init(struct radv_physical_device
*device
,
184 struct radv_instance
*instance
,
188 drmVersionPtr version
;
191 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
193 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
194 "failed to open %s: %m", path
);
196 version
= drmGetVersion(fd
);
199 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
200 "failed to get version %s: %m", path
);
203 if (strcmp(version
->name
, "amdgpu")) {
204 drmFreeVersion(version
);
206 return VK_ERROR_INCOMPATIBLE_DRIVER
;
208 drmFreeVersion(version
);
210 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
211 device
->instance
= instance
;
212 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
213 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
215 device
->ws
= radv_amdgpu_winsys_create(fd
);
217 result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
220 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
221 result
= radv_init_wsi(device
);
222 if (result
!= VK_SUCCESS
) {
223 device
->ws
->destroy(device
->ws
);
227 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->uuid
)) {
228 radv_finish_wsi(device
);
229 device
->ws
->destroy(device
->ws
);
230 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
231 "cannot generate UUID");
235 result
= radv_extensions_register(instance
,
237 common_device_extensions
,
238 ARRAY_SIZE(common_device_extensions
));
239 if (result
!= VK_SUCCESS
)
242 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
243 device
->name
= device
->rad_info
.name
;
253 radv_physical_device_finish(struct radv_physical_device
*device
)
255 radv_extensions_finish(device
->instance
, &device
->extensions
);
256 radv_finish_wsi(device
);
257 device
->ws
->destroy(device
->ws
);
262 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
263 VkSystemAllocationScope allocationScope
)
269 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
270 size_t align
, VkSystemAllocationScope allocationScope
)
272 return realloc(pOriginal
, size
);
276 default_free_func(void *pUserData
, void *pMemory
)
281 static const VkAllocationCallbacks default_alloc
= {
283 .pfnAllocation
= default_alloc_func
,
284 .pfnReallocation
= default_realloc_func
,
285 .pfnFree
= default_free_func
,
288 static const struct debug_control radv_debug_options
[] = {
289 {"fastclears", RADV_DEBUG_FAST_CLEARS
},
290 {"nodcc", RADV_DEBUG_NO_DCC
},
291 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
292 {"nocache", RADV_DEBUG_NO_CACHE
},
293 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
294 {"nohiz", RADV_DEBUG_NO_HIZ
},
295 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
296 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
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
);
368 if (instance
->physicalDeviceCount
> 0) {
369 /* We support at most one physical device. */
370 assert(instance
->physicalDeviceCount
== 1);
371 radv_physical_device_finish(&instance
->physicalDevice
);
374 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
378 vk_free(&instance
->alloc
, instance
);
381 VkResult
radv_EnumeratePhysicalDevices(
382 VkInstance _instance
,
383 uint32_t* pPhysicalDeviceCount
,
384 VkPhysicalDevice
* pPhysicalDevices
)
386 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
389 if (instance
->physicalDeviceCount
< 0) {
391 for (unsigned i
= 0; i
< 8; i
++) {
392 snprintf(path
, sizeof(path
), "/dev/dri/renderD%d", 128 + i
);
393 result
= radv_physical_device_init(&instance
->physicalDevice
,
395 if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
399 if (result
== VK_ERROR_INCOMPATIBLE_DRIVER
) {
400 instance
->physicalDeviceCount
= 0;
401 } else if (result
== VK_SUCCESS
) {
402 instance
->physicalDeviceCount
= 1;
408 /* pPhysicalDeviceCount is an out parameter if pPhysicalDevices is NULL;
409 * otherwise it's an inout parameter.
411 * The Vulkan spec (git aaed022) says:
413 * pPhysicalDeviceCount is a pointer to an unsigned integer variable
414 * that is initialized with the number of devices the application is
415 * prepared to receive handles to. pname:pPhysicalDevices is pointer to
416 * an array of at least this many VkPhysicalDevice handles [...].
418 * Upon success, if pPhysicalDevices is NULL, vkEnumeratePhysicalDevices
419 * overwrites the contents of the variable pointed to by
420 * pPhysicalDeviceCount with the number of physical devices in in the
421 * instance; otherwise, vkEnumeratePhysicalDevices overwrites
422 * pPhysicalDeviceCount with the number of physical handles written to
425 if (!pPhysicalDevices
) {
426 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
427 } else if (*pPhysicalDeviceCount
>= 1) {
428 pPhysicalDevices
[0] = radv_physical_device_to_handle(&instance
->physicalDevice
);
429 *pPhysicalDeviceCount
= 1;
430 } else if (*pPhysicalDeviceCount
< instance
->physicalDeviceCount
) {
431 return VK_INCOMPLETE
;
433 *pPhysicalDeviceCount
= 0;
439 void radv_GetPhysicalDeviceFeatures(
440 VkPhysicalDevice physicalDevice
,
441 VkPhysicalDeviceFeatures
* pFeatures
)
443 // RADV_FROM_HANDLE(radv_physical_device, pdevice, physicalDevice);
445 memset(pFeatures
, 0, sizeof(*pFeatures
));
447 *pFeatures
= (VkPhysicalDeviceFeatures
) {
448 .robustBufferAccess
= true,
449 .fullDrawIndexUint32
= true,
450 .imageCubeArray
= true,
451 .independentBlend
= true,
452 .geometryShader
= false,
453 .tessellationShader
= false,
454 .sampleRateShading
= false,
455 .dualSrcBlend
= true,
457 .multiDrawIndirect
= true,
458 .drawIndirectFirstInstance
= true,
460 .depthBiasClamp
= true,
461 .fillModeNonSolid
= true,
466 .multiViewport
= false,
467 .samplerAnisotropy
= true,
468 .textureCompressionETC2
= false,
469 .textureCompressionASTC_LDR
= false,
470 .textureCompressionBC
= true,
471 .occlusionQueryPrecise
= true,
472 .pipelineStatisticsQuery
= false,
473 .vertexPipelineStoresAndAtomics
= true,
474 .fragmentStoresAndAtomics
= true,
475 .shaderTessellationAndGeometryPointSize
= true,
476 .shaderImageGatherExtended
= true,
477 .shaderStorageImageExtendedFormats
= true,
478 .shaderStorageImageMultisample
= false,
479 .shaderUniformBufferArrayDynamicIndexing
= true,
480 .shaderSampledImageArrayDynamicIndexing
= true,
481 .shaderStorageBufferArrayDynamicIndexing
= true,
482 .shaderStorageImageArrayDynamicIndexing
= true,
483 .shaderStorageImageReadWithoutFormat
= false,
484 .shaderStorageImageWriteWithoutFormat
= false,
485 .shaderClipDistance
= true,
486 .shaderCullDistance
= true,
487 .shaderFloat64
= false,
488 .shaderInt64
= false,
489 .shaderInt16
= false,
491 .variableMultisampleRate
= false,
492 .inheritedQueries
= false,
496 void radv_GetPhysicalDeviceProperties(
497 VkPhysicalDevice physicalDevice
,
498 VkPhysicalDeviceProperties
* pProperties
)
500 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
501 VkSampleCountFlags sample_counts
= 0xf;
502 VkPhysicalDeviceLimits limits
= {
503 .maxImageDimension1D
= (1 << 14),
504 .maxImageDimension2D
= (1 << 14),
505 .maxImageDimension3D
= (1 << 11),
506 .maxImageDimensionCube
= (1 << 14),
507 .maxImageArrayLayers
= (1 << 11),
508 .maxTexelBufferElements
= 128 * 1024 * 1024,
509 .maxUniformBufferRange
= UINT32_MAX
,
510 .maxStorageBufferRange
= UINT32_MAX
,
511 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
512 .maxMemoryAllocationCount
= UINT32_MAX
,
513 .maxSamplerAllocationCount
= 64 * 1024,
514 .bufferImageGranularity
= 64, /* A cache line */
515 .sparseAddressSpaceSize
= 0,
516 .maxBoundDescriptorSets
= MAX_SETS
,
517 .maxPerStageDescriptorSamplers
= 64,
518 .maxPerStageDescriptorUniformBuffers
= 64,
519 .maxPerStageDescriptorStorageBuffers
= 64,
520 .maxPerStageDescriptorSampledImages
= 64,
521 .maxPerStageDescriptorStorageImages
= 64,
522 .maxPerStageDescriptorInputAttachments
= 64,
523 .maxPerStageResources
= 128,
524 .maxDescriptorSetSamplers
= 256,
525 .maxDescriptorSetUniformBuffers
= 256,
526 .maxDescriptorSetUniformBuffersDynamic
= 256,
527 .maxDescriptorSetStorageBuffers
= 256,
528 .maxDescriptorSetStorageBuffersDynamic
= 256,
529 .maxDescriptorSetSampledImages
= 256,
530 .maxDescriptorSetStorageImages
= 256,
531 .maxDescriptorSetInputAttachments
= 256,
532 .maxVertexInputAttributes
= 32,
533 .maxVertexInputBindings
= 32,
534 .maxVertexInputAttributeOffset
= 2047,
535 .maxVertexInputBindingStride
= 2048,
536 .maxVertexOutputComponents
= 128,
537 .maxTessellationGenerationLevel
= 0,
538 .maxTessellationPatchSize
= 0,
539 .maxTessellationControlPerVertexInputComponents
= 0,
540 .maxTessellationControlPerVertexOutputComponents
= 0,
541 .maxTessellationControlPerPatchOutputComponents
= 0,
542 .maxTessellationControlTotalOutputComponents
= 0,
543 .maxTessellationEvaluationInputComponents
= 0,
544 .maxTessellationEvaluationOutputComponents
= 0,
545 .maxGeometryShaderInvocations
= 32,
546 .maxGeometryInputComponents
= 64,
547 .maxGeometryOutputComponents
= 128,
548 .maxGeometryOutputVertices
= 256,
549 .maxGeometryTotalOutputComponents
= 1024,
550 .maxFragmentInputComponents
= 128,
551 .maxFragmentOutputAttachments
= 8,
552 .maxFragmentDualSrcAttachments
= 1,
553 .maxFragmentCombinedOutputResources
= 8,
554 .maxComputeSharedMemorySize
= 32768,
555 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
556 .maxComputeWorkGroupInvocations
= 2048,
557 .maxComputeWorkGroupSize
= {
562 .subPixelPrecisionBits
= 4 /* FIXME */,
563 .subTexelPrecisionBits
= 4 /* FIXME */,
564 .mipmapPrecisionBits
= 4 /* FIXME */,
565 .maxDrawIndexedIndexValue
= UINT32_MAX
,
566 .maxDrawIndirectCount
= UINT32_MAX
,
567 .maxSamplerLodBias
= 16,
568 .maxSamplerAnisotropy
= 16,
569 .maxViewports
= MAX_VIEWPORTS
,
570 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
571 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
572 .viewportSubPixelBits
= 13, /* We take a float? */
573 .minMemoryMapAlignment
= 4096, /* A page */
574 .minTexelBufferOffsetAlignment
= 1,
575 .minUniformBufferOffsetAlignment
= 4,
576 .minStorageBufferOffsetAlignment
= 4,
577 .minTexelOffset
= -32,
578 .maxTexelOffset
= 31,
579 .minTexelGatherOffset
= -32,
580 .maxTexelGatherOffset
= 31,
581 .minInterpolationOffset
= -2,
582 .maxInterpolationOffset
= 2,
583 .subPixelInterpolationOffsetBits
= 8,
584 .maxFramebufferWidth
= (1 << 14),
585 .maxFramebufferHeight
= (1 << 14),
586 .maxFramebufferLayers
= (1 << 10),
587 .framebufferColorSampleCounts
= sample_counts
,
588 .framebufferDepthSampleCounts
= sample_counts
,
589 .framebufferStencilSampleCounts
= sample_counts
,
590 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
591 .maxColorAttachments
= MAX_RTS
,
592 .sampledImageColorSampleCounts
= sample_counts
,
593 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
594 .sampledImageDepthSampleCounts
= sample_counts
,
595 .sampledImageStencilSampleCounts
= sample_counts
,
596 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
597 .maxSampleMaskWords
= 1,
598 .timestampComputeAndGraphics
= false,
599 .timestampPeriod
= 100000.0 / pdevice
->rad_info
.clock_crystal_freq
,
600 .maxClipDistances
= 8,
601 .maxCullDistances
= 8,
602 .maxCombinedClipAndCullDistances
= 8,
603 .discreteQueuePriorities
= 1,
604 .pointSizeRange
= { 0.125, 255.875 },
605 .lineWidthRange
= { 0.0, 7.9921875 },
606 .pointSizeGranularity
= (1.0 / 8.0),
607 .lineWidthGranularity
= (1.0 / 128.0),
608 .strictLines
= false, /* FINISHME */
609 .standardSampleLocations
= true,
610 .optimalBufferCopyOffsetAlignment
= 128,
611 .optimalBufferCopyRowPitchAlignment
= 128,
612 .nonCoherentAtomSize
= 64,
615 *pProperties
= (VkPhysicalDeviceProperties
) {
616 .apiVersion
= VK_MAKE_VERSION(1, 0, 5),
619 .deviceID
= pdevice
->rad_info
.pci_id
,
620 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
,
622 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
625 strcpy(pProperties
->deviceName
, pdevice
->name
);
626 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->uuid
, VK_UUID_SIZE
);
629 void radv_GetPhysicalDeviceQueueFamilyProperties(
630 VkPhysicalDevice physicalDevice
,
632 VkQueueFamilyProperties
* pQueueFamilyProperties
)
634 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
635 int num_queue_families
= 1;
637 if (pdevice
->rad_info
.compute_rings
> 0 &&
638 pdevice
->rad_info
.chip_class
>= CIK
&&
639 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
640 num_queue_families
++;
642 if (pQueueFamilyProperties
== NULL
) {
643 *pCount
= num_queue_families
;
652 pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
653 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
654 VK_QUEUE_COMPUTE_BIT
|
655 VK_QUEUE_TRANSFER_BIT
,
657 .timestampValidBits
= 64,
658 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
663 if (pdevice
->rad_info
.compute_rings
> 0 &&
664 pdevice
->rad_info
.chip_class
>= CIK
&&
665 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
667 pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
668 .queueFlags
= VK_QUEUE_COMPUTE_BIT
| VK_QUEUE_TRANSFER_BIT
,
669 .queueCount
= pdevice
->rad_info
.compute_rings
,
670 .timestampValidBits
= 64,
671 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
679 void radv_GetPhysicalDeviceMemoryProperties(
680 VkPhysicalDevice physicalDevice
,
681 VkPhysicalDeviceMemoryProperties
* pMemoryProperties
)
683 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
685 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
687 pMemoryProperties
->memoryTypeCount
= RADV_MEM_TYPE_COUNT
;
688 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_VRAM
] = (VkMemoryType
) {
689 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
690 .heapIndex
= RADV_MEM_HEAP_VRAM
,
692 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_GTT_WRITE_COMBINE
] = (VkMemoryType
) {
693 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
694 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
695 .heapIndex
= RADV_MEM_HEAP_GTT
,
697 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_VRAM_CPU_ACCESS
] = (VkMemoryType
) {
698 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
699 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
700 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
701 .heapIndex
= RADV_MEM_HEAP_VRAM_CPU_ACCESS
,
703 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_GTT_CACHED
] = (VkMemoryType
) {
704 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
705 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
706 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
707 .heapIndex
= RADV_MEM_HEAP_GTT
,
710 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
712 pMemoryProperties
->memoryHeapCount
= RADV_MEM_HEAP_COUNT
;
713 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_VRAM
] = (VkMemoryHeap
) {
714 .size
= physical_device
->rad_info
.vram_size
-
715 physical_device
->rad_info
.visible_vram_size
,
716 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
718 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_VRAM_CPU_ACCESS
] = (VkMemoryHeap
) {
719 .size
= physical_device
->rad_info
.visible_vram_size
,
720 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
722 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_GTT
] = (VkMemoryHeap
) {
723 .size
= physical_device
->rad_info
.gart_size
,
729 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
730 int queue_family_index
, int idx
)
732 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
733 queue
->device
= device
;
734 queue
->queue_family_index
= queue_family_index
;
735 queue
->queue_idx
= idx
;
737 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
);
739 return VK_ERROR_OUT_OF_HOST_MEMORY
;
745 radv_queue_finish(struct radv_queue
*queue
)
748 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
751 VkResult
radv_CreateDevice(
752 VkPhysicalDevice physicalDevice
,
753 const VkDeviceCreateInfo
* pCreateInfo
,
754 const VkAllocationCallbacks
* pAllocator
,
757 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
759 struct radv_device
*device
;
761 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
762 if (!is_extension_enabled(physical_device
->extensions
.ext_array
,
763 physical_device
->extensions
.num_ext
,
764 pCreateInfo
->ppEnabledExtensionNames
[i
]))
765 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
768 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
770 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
772 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
774 memset(device
, 0, sizeof(*device
));
776 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
777 device
->instance
= physical_device
->instance
;
778 device
->physical_device
= physical_device
;
780 device
->debug_flags
= device
->instance
->debug_flags
;
782 device
->ws
= physical_device
->ws
;
784 device
->alloc
= *pAllocator
;
786 device
->alloc
= physical_device
->instance
->alloc
;
788 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
789 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
790 uint32_t qfi
= queue_create
->queueFamilyIndex
;
792 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
793 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
794 if (!device
->queues
[qfi
]) {
795 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
799 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
801 device
->queue_count
[qfi
] = queue_create
->queueCount
;
803 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
804 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
], qfi
, q
);
805 if (result
!= VK_SUCCESS
)
810 result
= radv_device_init_meta(device
);
811 if (result
!= VK_SUCCESS
)
814 radv_device_init_msaa(device
);
816 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
817 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
819 case RADV_QUEUE_GENERAL
:
820 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
821 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
822 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
824 case RADV_QUEUE_COMPUTE
:
825 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
826 radeon_emit(device
->empty_cs
[family
], 0);
829 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
832 if (getenv("RADV_TRACE_FILE")) {
833 device
->trace_bo
= device
->ws
->buffer_create(device
->ws
, 4096, 8,
834 RADEON_DOMAIN_VRAM
, RADEON_FLAG_CPU_ACCESS
);
835 if (!device
->trace_bo
)
838 device
->trace_id_ptr
= device
->ws
->buffer_map(device
->trace_bo
);
839 if (!device
->trace_id_ptr
)
843 *pDevice
= radv_device_to_handle(device
);
847 if (device
->trace_bo
)
848 device
->ws
->buffer_destroy(device
->trace_bo
);
850 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
851 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
852 radv_queue_finish(&device
->queues
[i
][q
]);
853 if (device
->queue_count
[i
])
854 vk_free(&device
->alloc
, device
->queues
[i
]);
857 vk_free(&device
->alloc
, device
);
861 void radv_DestroyDevice(
863 const VkAllocationCallbacks
* pAllocator
)
865 RADV_FROM_HANDLE(radv_device
, device
, _device
);
867 if (device
->trace_bo
)
868 device
->ws
->buffer_destroy(device
->trace_bo
);
870 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
871 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
872 radv_queue_finish(&device
->queues
[i
][q
]);
873 if (device
->queue_count
[i
])
874 vk_free(&device
->alloc
, device
->queues
[i
]);
876 radv_device_finish_meta(device
);
878 vk_free(&device
->alloc
, device
);
881 VkResult
radv_EnumerateInstanceExtensionProperties(
882 const char* pLayerName
,
883 uint32_t* pPropertyCount
,
884 VkExtensionProperties
* pProperties
)
886 if (pProperties
== NULL
) {
887 *pPropertyCount
= ARRAY_SIZE(instance_extensions
);
891 *pPropertyCount
= MIN2(*pPropertyCount
, ARRAY_SIZE(instance_extensions
));
892 typed_memcpy(pProperties
, instance_extensions
, *pPropertyCount
);
894 if (*pPropertyCount
< ARRAY_SIZE(instance_extensions
))
895 return VK_INCOMPLETE
;
900 VkResult
radv_EnumerateDeviceExtensionProperties(
901 VkPhysicalDevice physicalDevice
,
902 const char* pLayerName
,
903 uint32_t* pPropertyCount
,
904 VkExtensionProperties
* pProperties
)
906 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
908 if (pProperties
== NULL
) {
909 *pPropertyCount
= pdevice
->extensions
.num_ext
;
913 *pPropertyCount
= MIN2(*pPropertyCount
, pdevice
->extensions
.num_ext
);
914 typed_memcpy(pProperties
, pdevice
->extensions
.ext_array
, *pPropertyCount
);
916 if (*pPropertyCount
< pdevice
->extensions
.num_ext
)
917 return VK_INCOMPLETE
;
922 VkResult
radv_EnumerateInstanceLayerProperties(
923 uint32_t* pPropertyCount
,
924 VkLayerProperties
* pProperties
)
926 if (pProperties
== NULL
) {
931 /* None supported at this time */
932 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
935 VkResult
radv_EnumerateDeviceLayerProperties(
936 VkPhysicalDevice physicalDevice
,
937 uint32_t* pPropertyCount
,
938 VkLayerProperties
* pProperties
)
940 if (pProperties
== NULL
) {
945 /* None supported at this time */
946 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
949 void radv_GetDeviceQueue(
951 uint32_t queueFamilyIndex
,
955 RADV_FROM_HANDLE(radv_device
, device
, _device
);
957 *pQueue
= radv_queue_to_handle(&device
->queues
[queueFamilyIndex
][queueIndex
]);
960 static void radv_dump_trace(struct radv_device
*device
,
961 struct radeon_winsys_cs
*cs
)
963 const char *filename
= getenv("RADV_TRACE_FILE");
964 FILE *f
= fopen(filename
, "w");
966 fprintf(stderr
, "Failed to write trace dump to %s\n", filename
);
970 fprintf(f
, "Trace ID: %x\n", *device
->trace_id_ptr
);
971 device
->ws
->cs_dump(cs
, f
, *device
->trace_id_ptr
);
975 VkResult
radv_QueueSubmit(
977 uint32_t submitCount
,
978 const VkSubmitInfo
* pSubmits
,
981 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
982 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
983 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
984 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
986 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
988 for (uint32_t i
= 0; i
< submitCount
; i
++) {
989 struct radeon_winsys_cs
**cs_array
;
990 bool can_patch
= true;
993 if (!pSubmits
[i
].commandBufferCount
)
996 cs_array
= malloc(sizeof(struct radeon_winsys_cs
*) *
997 pSubmits
[i
].commandBufferCount
);
999 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
1000 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
1001 pSubmits
[i
].pCommandBuffers
[j
]);
1002 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
1004 cs_array
[j
] = cmd_buffer
->cs
;
1005 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
1009 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
1010 advance
= MIN2(max_cs_submission
,
1011 pSubmits
[i
].commandBufferCount
- j
);
1013 bool e
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
1015 if (queue
->device
->trace_bo
)
1016 *queue
->device
->trace_id_ptr
= 0;
1018 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
,
1019 pSubmits
[i
].commandBufferCount
,
1020 (struct radeon_winsys_sem
**)pSubmits
[i
].pWaitSemaphores
,
1021 b
? pSubmits
[i
].waitSemaphoreCount
: 0,
1022 (struct radeon_winsys_sem
**)pSubmits
[i
].pSignalSemaphores
,
1023 e
? pSubmits
[i
].signalSemaphoreCount
: 0,
1024 can_patch
, base_fence
);
1027 radv_loge("failed to submit CS %d\n", i
);
1030 if (queue
->device
->trace_bo
) {
1031 bool success
= queue
->device
->ws
->ctx_wait_idle(
1033 radv_queue_family_to_ring(
1034 queue
->queue_family_index
),
1037 if (!success
) { /* Hang */
1038 radv_dump_trace(queue
->device
, cs_array
[j
]);
1048 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
1049 &queue
->device
->empty_cs
[queue
->queue_family_index
],
1050 1, NULL
, 0, NULL
, 0, false, base_fence
);
1052 fence
->submitted
= true;
1058 VkResult
radv_QueueWaitIdle(
1061 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
1063 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
1064 radv_queue_family_to_ring(queue
->queue_family_index
),
1069 VkResult
radv_DeviceWaitIdle(
1072 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1074 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1075 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
1076 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
1082 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
1083 VkInstance instance
,
1086 return radv_lookup_entrypoint(pName
);
1089 /* The loader wants us to expose a second GetInstanceProcAddr function
1090 * to work around certain LD_PRELOAD issues seen in apps.
1093 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1094 VkInstance instance
,
1098 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1099 VkInstance instance
,
1102 return radv_GetInstanceProcAddr(instance
, pName
);
1105 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
1109 return radv_lookup_entrypoint(pName
);
1112 VkResult
radv_AllocateMemory(
1114 const VkMemoryAllocateInfo
* pAllocateInfo
,
1115 const VkAllocationCallbacks
* pAllocator
,
1116 VkDeviceMemory
* pMem
)
1118 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1119 struct radv_device_memory
*mem
;
1121 enum radeon_bo_domain domain
;
1123 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1125 if (pAllocateInfo
->allocationSize
== 0) {
1126 /* Apparently, this is allowed */
1127 *pMem
= VK_NULL_HANDLE
;
1131 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
1132 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1134 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1136 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
1137 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
1138 pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_CACHED
)
1139 domain
= RADEON_DOMAIN_GTT
;
1141 domain
= RADEON_DOMAIN_VRAM
;
1143 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_VRAM
)
1144 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
1146 flags
|= RADEON_FLAG_CPU_ACCESS
;
1148 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
1149 flags
|= RADEON_FLAG_GTT_WC
;
1151 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, 32768,
1155 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
1158 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
1160 *pMem
= radv_device_memory_to_handle(mem
);
1165 vk_free2(&device
->alloc
, pAllocator
, mem
);
1170 void radv_FreeMemory(
1172 VkDeviceMemory _mem
,
1173 const VkAllocationCallbacks
* pAllocator
)
1175 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1176 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
1181 device
->ws
->buffer_destroy(mem
->bo
);
1184 vk_free2(&device
->alloc
, pAllocator
, mem
);
1187 VkResult
radv_MapMemory(
1189 VkDeviceMemory _memory
,
1190 VkDeviceSize offset
,
1192 VkMemoryMapFlags flags
,
1195 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1196 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
1203 *ppData
= device
->ws
->buffer_map(mem
->bo
);
1209 return VK_ERROR_MEMORY_MAP_FAILED
;
1212 void radv_UnmapMemory(
1214 VkDeviceMemory _memory
)
1216 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1217 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
1222 device
->ws
->buffer_unmap(mem
->bo
);
1225 VkResult
radv_FlushMappedMemoryRanges(
1227 uint32_t memoryRangeCount
,
1228 const VkMappedMemoryRange
* pMemoryRanges
)
1233 VkResult
radv_InvalidateMappedMemoryRanges(
1235 uint32_t memoryRangeCount
,
1236 const VkMappedMemoryRange
* pMemoryRanges
)
1241 void radv_GetBufferMemoryRequirements(
1244 VkMemoryRequirements
* pMemoryRequirements
)
1246 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
1248 pMemoryRequirements
->memoryTypeBits
= (1u << RADV_MEM_TYPE_COUNT
) - 1;
1250 pMemoryRequirements
->size
= buffer
->size
;
1251 pMemoryRequirements
->alignment
= 16;
1254 void radv_GetImageMemoryRequirements(
1257 VkMemoryRequirements
* pMemoryRequirements
)
1259 RADV_FROM_HANDLE(radv_image
, image
, _image
);
1261 pMemoryRequirements
->memoryTypeBits
= (1u << RADV_MEM_TYPE_COUNT
) - 1;
1263 pMemoryRequirements
->size
= image
->size
;
1264 pMemoryRequirements
->alignment
= image
->alignment
;
1267 void radv_GetImageSparseMemoryRequirements(
1270 uint32_t* pSparseMemoryRequirementCount
,
1271 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
1276 void radv_GetDeviceMemoryCommitment(
1278 VkDeviceMemory memory
,
1279 VkDeviceSize
* pCommittedMemoryInBytes
)
1281 *pCommittedMemoryInBytes
= 0;
1284 VkResult
radv_BindBufferMemory(
1287 VkDeviceMemory _memory
,
1288 VkDeviceSize memoryOffset
)
1290 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
1291 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
1294 buffer
->bo
= mem
->bo
;
1295 buffer
->offset
= memoryOffset
;
1304 VkResult
radv_BindImageMemory(
1307 VkDeviceMemory _memory
,
1308 VkDeviceSize memoryOffset
)
1310 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
1311 RADV_FROM_HANDLE(radv_image
, image
, _image
);
1314 image
->bo
= mem
->bo
;
1315 image
->offset
= memoryOffset
;
1324 VkResult
radv_QueueBindSparse(
1326 uint32_t bindInfoCount
,
1327 const VkBindSparseInfo
* pBindInfo
,
1330 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1333 VkResult
radv_CreateFence(
1335 const VkFenceCreateInfo
* pCreateInfo
,
1336 const VkAllocationCallbacks
* pAllocator
,
1339 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1340 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
1342 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1345 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1347 memset(fence
, 0, sizeof(*fence
));
1348 fence
->submitted
= false;
1349 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
1350 fence
->fence
= device
->ws
->create_fence();
1351 if (!fence
->fence
) {
1352 vk_free2(&device
->alloc
, pAllocator
, fence
);
1353 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1356 *pFence
= radv_fence_to_handle(fence
);
1361 void radv_DestroyFence(
1364 const VkAllocationCallbacks
* pAllocator
)
1366 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1367 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
1371 device
->ws
->destroy_fence(fence
->fence
);
1372 vk_free2(&device
->alloc
, pAllocator
, fence
);
1375 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
1377 uint64_t current_time
;
1380 clock_gettime(CLOCK_MONOTONIC
, &tv
);
1381 current_time
= tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
1383 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
1385 return current_time
+ timeout
;
1388 VkResult
radv_WaitForFences(
1390 uint32_t fenceCount
,
1391 const VkFence
* pFences
,
1395 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1396 timeout
= radv_get_absolute_timeout(timeout
);
1398 if (!waitAll
&& fenceCount
> 1) {
1399 fprintf(stderr
, "radv: WaitForFences without waitAll not implemented yet\n");
1402 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
1403 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
1404 bool expired
= false;
1406 if (fence
->signalled
)
1409 if (!fence
->submitted
)
1412 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
1416 fence
->signalled
= true;
1422 VkResult
radv_ResetFences(VkDevice device
,
1423 uint32_t fenceCount
,
1424 const VkFence
*pFences
)
1426 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
1427 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
1428 fence
->submitted
= fence
->signalled
= false;
1434 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
1436 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1437 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
1439 if (fence
->signalled
)
1441 if (!fence
->submitted
)
1442 return VK_NOT_READY
;
1444 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
1445 return VK_NOT_READY
;
1451 // Queue semaphore functions
1453 VkResult
radv_CreateSemaphore(
1455 const VkSemaphoreCreateInfo
* pCreateInfo
,
1456 const VkAllocationCallbacks
* pAllocator
,
1457 VkSemaphore
* pSemaphore
)
1459 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1460 struct radeon_winsys_sem
*sem
;
1462 sem
= device
->ws
->create_sem(device
->ws
);
1464 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1466 *pSemaphore
= (VkSemaphore
)sem
;
1470 void radv_DestroySemaphore(
1472 VkSemaphore _semaphore
,
1473 const VkAllocationCallbacks
* pAllocator
)
1475 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1476 struct radeon_winsys_sem
*sem
;
1480 sem
= (struct radeon_winsys_sem
*)_semaphore
;
1481 device
->ws
->destroy_sem(sem
);
1484 VkResult
radv_CreateEvent(
1486 const VkEventCreateInfo
* pCreateInfo
,
1487 const VkAllocationCallbacks
* pAllocator
,
1490 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1491 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
1493 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1496 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1498 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
1500 RADEON_FLAG_CPU_ACCESS
);
1502 vk_free2(&device
->alloc
, pAllocator
, event
);
1503 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
1506 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
1508 *pEvent
= radv_event_to_handle(event
);
1513 void radv_DestroyEvent(
1516 const VkAllocationCallbacks
* pAllocator
)
1518 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1519 RADV_FROM_HANDLE(radv_event
, event
, _event
);
1523 device
->ws
->buffer_destroy(event
->bo
);
1524 vk_free2(&device
->alloc
, pAllocator
, event
);
1527 VkResult
radv_GetEventStatus(
1531 RADV_FROM_HANDLE(radv_event
, event
, _event
);
1533 if (*event
->map
== 1)
1534 return VK_EVENT_SET
;
1535 return VK_EVENT_RESET
;
1538 VkResult
radv_SetEvent(
1542 RADV_FROM_HANDLE(radv_event
, event
, _event
);
1548 VkResult
radv_ResetEvent(
1552 RADV_FROM_HANDLE(radv_event
, event
, _event
);
1558 VkResult
radv_CreateBuffer(
1560 const VkBufferCreateInfo
* pCreateInfo
,
1561 const VkAllocationCallbacks
* pAllocator
,
1564 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1565 struct radv_buffer
*buffer
;
1567 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
1569 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
1570 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1572 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1574 buffer
->size
= pCreateInfo
->size
;
1575 buffer
->usage
= pCreateInfo
->usage
;
1579 *pBuffer
= radv_buffer_to_handle(buffer
);
1584 void radv_DestroyBuffer(
1587 const VkAllocationCallbacks
* pAllocator
)
1589 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1590 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
1595 vk_free2(&device
->alloc
, pAllocator
, buffer
);
1598 static inline unsigned
1599 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
1602 return image
->surface
.stencil_tiling_index
[level
];
1604 return image
->surface
.tiling_index
[level
];
1608 radv_initialise_color_surface(struct radv_device
*device
,
1609 struct radv_color_buffer_info
*cb
,
1610 struct radv_image_view
*iview
)
1612 const struct vk_format_description
*desc
;
1613 unsigned ntype
, format
, swap
, endian
;
1614 unsigned blend_clamp
= 0, blend_bypass
= 0;
1615 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
1617 const struct radeon_surf
*surf
= &iview
->image
->surface
;
1618 const struct radeon_surf_level
*level_info
= &surf
->level
[iview
->base_mip
];
1620 desc
= vk_format_description(iview
->vk_format
);
1622 memset(cb
, 0, sizeof(*cb
));
1624 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
1625 va
+= level_info
->offset
;
1626 cb
->cb_color_base
= va
>> 8;
1628 /* CMASK variables */
1629 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
1630 va
+= iview
->image
->cmask
.offset
;
1631 cb
->cb_color_cmask
= va
>> 8;
1632 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
1634 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
1635 va
+= iview
->image
->dcc_offset
;
1636 cb
->cb_dcc_base
= va
>> 8;
1638 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
1639 S_028C6C_SLICE_MAX(iview
->base_layer
+ iview
->extent
.depth
- 1);
1641 cb
->micro_tile_mode
= iview
->image
->surface
.micro_tile_mode
;
1642 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
1643 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
1644 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
1646 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
1647 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
1649 /* Intensity is implemented as Red, so treat it that way. */
1650 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
) |
1651 S_028C74_TILE_MODE_INDEX(tile_mode_index
);
1653 if (iview
->image
->samples
> 1) {
1654 unsigned log_samples
= util_logbase2(iview
->image
->samples
);
1656 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
1657 S_028C74_NUM_FRAGMENTS(log_samples
);
1660 if (iview
->image
->fmask
.size
) {
1661 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
1662 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1663 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
1664 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
1665 cb
->cb_color_fmask
= va
>> 8;
1666 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
1668 /* This must be set for fast clear to work without FMASK. */
1669 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1670 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
1671 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
1672 cb
->cb_color_fmask
= cb
->cb_color_base
;
1673 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
1676 ntype
= radv_translate_color_numformat(iview
->vk_format
,
1678 vk_format_get_first_non_void_channel(iview
->vk_format
));
1679 format
= radv_translate_colorformat(iview
->vk_format
);
1680 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
1681 radv_finishme("Illegal color\n");
1682 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
1683 endian
= radv_colorformat_endian_swap(format
);
1685 /* blend clamp should be set for all NORM/SRGB types */
1686 if (ntype
== V_028C70_NUMBER_UNORM
||
1687 ntype
== V_028C70_NUMBER_SNORM
||
1688 ntype
== V_028C70_NUMBER_SRGB
)
1691 /* set blend bypass according to docs if SINT/UINT or
1692 8/24 COLOR variants */
1693 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
1694 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
1695 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
1700 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
1701 (format
== V_028C70_COLOR_8
||
1702 format
== V_028C70_COLOR_8_8
||
1703 format
== V_028C70_COLOR_8_8_8_8
))
1704 ->color_is_int8
= true;
1706 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
1707 S_028C70_COMP_SWAP(swap
) |
1708 S_028C70_BLEND_CLAMP(blend_clamp
) |
1709 S_028C70_BLEND_BYPASS(blend_bypass
) |
1710 S_028C70_SIMPLE_FLOAT(1) |
1711 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
1712 ntype
!= V_028C70_NUMBER_SNORM
&&
1713 ntype
!= V_028C70_NUMBER_SRGB
&&
1714 format
!= V_028C70_COLOR_8_24
&&
1715 format
!= V_028C70_COLOR_24_8
) |
1716 S_028C70_NUMBER_TYPE(ntype
) |
1717 S_028C70_ENDIAN(endian
);
1718 if (iview
->image
->samples
> 1)
1719 if (iview
->image
->fmask
.size
)
1720 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
1722 if (iview
->image
->cmask
.size
&&
1723 (device
->debug_flags
& RADV_DEBUG_FAST_CLEARS
))
1724 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
1726 if (iview
->image
->surface
.dcc_size
&& level_info
->dcc_enabled
)
1727 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
1729 if (device
->physical_device
->rad_info
.chip_class
>= VI
) {
1730 unsigned max_uncompressed_block_size
= 2;
1731 if (iview
->image
->samples
> 1) {
1732 if (iview
->image
->surface
.bpe
== 1)
1733 max_uncompressed_block_size
= 0;
1734 else if (iview
->image
->surface
.bpe
== 2)
1735 max_uncompressed_block_size
= 1;
1738 cb
->cb_dcc_control
= S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
1739 S_028C78_INDEPENDENT_64B_BLOCKS(1);
1742 /* This must be set for fast clear to work without FMASK. */
1743 if (!iview
->image
->fmask
.size
&&
1744 device
->physical_device
->rad_info
.chip_class
== SI
) {
1745 unsigned bankh
= util_logbase2(iview
->image
->surface
.bankh
);
1746 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
1751 radv_initialise_ds_surface(struct radv_device
*device
,
1752 struct radv_ds_buffer_info
*ds
,
1753 struct radv_image_view
*iview
)
1755 unsigned level
= iview
->base_mip
;
1757 uint64_t va
, s_offs
, z_offs
;
1758 const struct radeon_surf_level
*level_info
= &iview
->image
->surface
.level
[level
];
1759 memset(ds
, 0, sizeof(*ds
));
1760 switch (iview
->vk_format
) {
1761 case VK_FORMAT_D24_UNORM_S8_UINT
:
1762 case VK_FORMAT_X8_D24_UNORM_PACK32
:
1763 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
1764 ds
->offset_scale
= 2.0f
;
1766 case VK_FORMAT_D16_UNORM
:
1767 case VK_FORMAT_D16_UNORM_S8_UINT
:
1768 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
1769 ds
->offset_scale
= 4.0f
;
1771 case VK_FORMAT_D32_SFLOAT
:
1772 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
1773 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
1774 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
1775 ds
->offset_scale
= 1.0f
;
1781 format
= radv_translate_dbformat(iview
->vk_format
);
1782 if (format
== V_028040_Z_INVALID
) {
1783 fprintf(stderr
, "Invalid DB format: %d, disabling DB.\n", iview
->vk_format
);
1786 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
1787 s_offs
= z_offs
= va
;
1788 z_offs
+= iview
->image
->surface
.level
[level
].offset
;
1789 s_offs
+= iview
->image
->surface
.stencil_level
[level
].offset
;
1791 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
1792 S_028008_SLICE_MAX(iview
->base_layer
+ iview
->extent
.depth
- 1);
1793 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(1);
1794 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
1796 if (iview
->image
->samples
> 1)
1797 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->samples
));
1799 if (iview
->image
->surface
.flags
& RADEON_SURF_SBUFFER
)
1800 ds
->db_stencil_info
= S_028044_FORMAT(V_028044_STENCIL_8
);
1802 ds
->db_stencil_info
= S_028044_FORMAT(V_028044_STENCIL_INVALID
);
1804 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1805 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
1806 unsigned tiling_index
= iview
->image
->surface
.tiling_index
[level
];
1807 unsigned stencil_index
= iview
->image
->surface
.stencil_tiling_index
[level
];
1808 unsigned macro_index
= iview
->image
->surface
.macro_tile_index
;
1809 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
1810 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
1811 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
1813 ds
->db_depth_info
|=
1814 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
1815 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
1816 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
1817 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
1818 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
1819 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
1820 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
1821 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
1823 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
1824 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
1825 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
1826 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
1829 if (iview
->image
->htile
.size
&& !level
) {
1830 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1) |
1831 S_028040_ALLOW_EXPCLEAR(1);
1833 if (iview
->image
->surface
.flags
& RADEON_SURF_SBUFFER
) {
1834 /* Workaround: For a not yet understood reason, the
1835 * combination of MSAA, fast stencil clear and stencil
1836 * decompress messes with subsequent stencil buffer
1837 * uses. Problem was reproduced on Verde, Bonaire,
1838 * Tonga, and Carrizo.
1840 * Disabling EXPCLEAR works around the problem.
1842 * Check piglit's arb_texture_multisample-stencil-clear
1843 * test if you want to try changing this.
1845 if (iview
->image
->samples
<= 1)
1846 ds
->db_stencil_info
|= S_028044_ALLOW_EXPCLEAR(1);
1848 /* Use all of the htile_buffer for depth if there's no stencil. */
1849 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
1851 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
+
1852 iview
->image
->htile
.offset
;
1853 ds
->db_htile_data_base
= va
>> 8;
1854 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
1856 ds
->db_htile_data_base
= 0;
1857 ds
->db_htile_surface
= 0;
1860 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
1861 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
1863 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
1864 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
1865 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
1868 VkResult
radv_CreateFramebuffer(
1870 const VkFramebufferCreateInfo
* pCreateInfo
,
1871 const VkAllocationCallbacks
* pAllocator
,
1872 VkFramebuffer
* pFramebuffer
)
1874 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1875 struct radv_framebuffer
*framebuffer
;
1877 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
1879 size_t size
= sizeof(*framebuffer
) +
1880 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
1881 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
1882 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1883 if (framebuffer
== NULL
)
1884 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1886 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
1887 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
1888 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
1889 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
1890 framebuffer
->attachments
[i
].attachment
= iview
;
1891 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
1892 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
1893 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
1894 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
1898 framebuffer
->width
= pCreateInfo
->width
;
1899 framebuffer
->height
= pCreateInfo
->height
;
1900 framebuffer
->layers
= pCreateInfo
->layers
;
1902 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
1906 void radv_DestroyFramebuffer(
1909 const VkAllocationCallbacks
* pAllocator
)
1911 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1912 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
1916 vk_free2(&device
->alloc
, pAllocator
, fb
);
1919 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
1921 switch (address_mode
) {
1922 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
1923 return V_008F30_SQ_TEX_WRAP
;
1924 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
1925 return V_008F30_SQ_TEX_MIRROR
;
1926 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
1927 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
1928 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
1929 return V_008F30_SQ_TEX_CLAMP_BORDER
;
1930 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
1931 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
1933 unreachable("illegal tex wrap mode");
1939 radv_tex_compare(VkCompareOp op
)
1942 case VK_COMPARE_OP_NEVER
:
1943 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
1944 case VK_COMPARE_OP_LESS
:
1945 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
1946 case VK_COMPARE_OP_EQUAL
:
1947 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
1948 case VK_COMPARE_OP_LESS_OR_EQUAL
:
1949 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
1950 case VK_COMPARE_OP_GREATER
:
1951 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
1952 case VK_COMPARE_OP_NOT_EQUAL
:
1953 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
1954 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
1955 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
1956 case VK_COMPARE_OP_ALWAYS
:
1957 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
1959 unreachable("illegal compare mode");
1965 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
1968 case VK_FILTER_NEAREST
:
1969 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
1970 V_008F38_SQ_TEX_XY_FILTER_POINT
);
1971 case VK_FILTER_LINEAR
:
1972 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
1973 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
1974 case VK_FILTER_CUBIC_IMG
:
1976 fprintf(stderr
, "illegal texture filter");
1982 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
1985 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
1986 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
1987 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
1988 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
1990 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
1995 radv_tex_bordercolor(VkBorderColor bcolor
)
1998 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
1999 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
2000 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
2001 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
2002 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
2003 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
2004 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
2005 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
2006 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
2014 radv_tex_aniso_filter(unsigned filter
)
2028 radv_init_sampler(struct radv_device
*device
,
2029 struct radv_sampler
*sampler
,
2030 const VkSamplerCreateInfo
*pCreateInfo
)
2032 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
2033 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
2034 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
2035 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
2037 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
2038 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
2039 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
2040 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
2041 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
2042 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
2043 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
2044 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
2045 S_008F30_DISABLE_CUBE_WRAP(0) |
2046 S_008F30_COMPAT_MODE(is_vi
));
2047 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
2048 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
2049 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
2050 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
2051 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
2052 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
2053 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
2054 S_008F38_MIP_POINT_PRECLAMP(1) |
2055 S_008F38_DISABLE_LSB_CEIL(1) |
2056 S_008F38_FILTER_PREC_FIX(1) |
2057 S_008F38_ANISO_OVERRIDE(is_vi
));
2058 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
2059 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
2062 VkResult
radv_CreateSampler(
2064 const VkSamplerCreateInfo
* pCreateInfo
,
2065 const VkAllocationCallbacks
* pAllocator
,
2066 VkSampler
* pSampler
)
2068 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2069 struct radv_sampler
*sampler
;
2071 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
2073 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
2074 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2076 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2078 radv_init_sampler(device
, sampler
, pCreateInfo
);
2079 *pSampler
= radv_sampler_to_handle(sampler
);
2084 void radv_DestroySampler(
2087 const VkAllocationCallbacks
* pAllocator
)
2089 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2090 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
2094 vk_free2(&device
->alloc
, pAllocator
, sampler
);
2098 /* vk_icd.h does not declare this function, so we declare it here to
2099 * suppress Wmissing-prototypes.
2101 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2102 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
2104 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2105 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
2107 /* For the full details on loader interface versioning, see
2108 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
2109 * What follows is a condensed summary, to help you navigate the large and
2110 * confusing official doc.
2112 * - Loader interface v0 is incompatible with later versions. We don't
2115 * - In loader interface v1:
2116 * - The first ICD entrypoint called by the loader is
2117 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
2119 * - The ICD must statically expose no other Vulkan symbol unless it is
2120 * linked with -Bsymbolic.
2121 * - Each dispatchable Vulkan handle created by the ICD must be
2122 * a pointer to a struct whose first member is VK_LOADER_DATA. The
2123 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
2124 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
2125 * vkDestroySurfaceKHR(). The ICD must be capable of working with
2126 * such loader-managed surfaces.
2128 * - Loader interface v2 differs from v1 in:
2129 * - The first ICD entrypoint called by the loader is
2130 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
2131 * statically expose this entrypoint.
2133 * - Loader interface v3 differs from v2 in:
2134 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
2135 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
2136 * because the loader no longer does so.
2138 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);