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"
36 #include "util/strtod.h"
40 #include <amdgpu_drm.h>
41 #include "amdgpu_id.h"
42 #include "winsys/amdgpu/radv_amdgpu_winsys_public.h"
43 #include "ac_llvm_util.h"
44 #include "vk_format.h"
46 #include "util/debug.h"
47 struct radv_dispatch_table dtable
;
50 radv_get_function_timestamp(void *ptr
, uint32_t* timestamp
)
54 if (!dladdr(ptr
, &info
) || !info
.dli_fname
) {
57 if (stat(info
.dli_fname
, &st
)) {
60 *timestamp
= st
.st_mtim
.tv_sec
;
65 radv_device_get_cache_uuid(enum radeon_family family
, void *uuid
)
67 uint32_t mesa_timestamp
, llvm_timestamp
;
69 memset(uuid
, 0, VK_UUID_SIZE
);
70 if (radv_get_function_timestamp(radv_device_get_cache_uuid
, &mesa_timestamp
) ||
71 radv_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo
, &llvm_timestamp
))
74 memcpy(uuid
, &mesa_timestamp
, 4);
75 memcpy((char*)uuid
+ 4, &llvm_timestamp
, 4);
76 memcpy((char*)uuid
+ 8, &f
, 2);
77 snprintf((char*)uuid
+ 10, VK_UUID_SIZE
- 10, "radv");
81 static const VkExtensionProperties instance_extensions
[] = {
83 .extensionName
= VK_KHR_SURFACE_EXTENSION_NAME
,
86 #ifdef VK_USE_PLATFORM_XCB_KHR
88 .extensionName
= VK_KHR_XCB_SURFACE_EXTENSION_NAME
,
92 #ifdef VK_USE_PLATFORM_XLIB_KHR
94 .extensionName
= VK_KHR_XLIB_SURFACE_EXTENSION_NAME
,
98 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
100 .extensionName
= VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME
,
106 static const VkExtensionProperties common_device_extensions
[] = {
108 .extensionName
= VK_KHR_MAINTENANCE1_EXTENSION_NAME
,
112 .extensionName
= VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME
,
116 .extensionName
= VK_KHR_SWAPCHAIN_EXTENSION_NAME
,
120 .extensionName
= VK_AMD_DRAW_INDIRECT_COUNT_EXTENSION_NAME
,
124 .extensionName
= VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME
,
128 .extensionName
= VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME
,
134 radv_extensions_register(struct radv_instance
*instance
,
135 struct radv_extensions
*extensions
,
136 const VkExtensionProperties
*new_ext
,
140 VkExtensionProperties
*new_ptr
;
142 assert(new_ext
&& num_ext
> 0);
145 return VK_ERROR_INITIALIZATION_FAILED
;
147 new_size
= (extensions
->num_ext
+ num_ext
) * sizeof(VkExtensionProperties
);
148 new_ptr
= vk_realloc(&instance
->alloc
, extensions
->ext_array
,
149 new_size
, 8, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
151 /* Old array continues to be valid, update nothing */
153 return VK_ERROR_OUT_OF_HOST_MEMORY
;
155 memcpy(&new_ptr
[extensions
->num_ext
], new_ext
,
156 num_ext
* sizeof(VkExtensionProperties
));
157 extensions
->ext_array
= new_ptr
;
158 extensions
->num_ext
+= num_ext
;
164 radv_extensions_finish(struct radv_instance
*instance
,
165 struct radv_extensions
*extensions
)
170 radv_loge("Attemted to free invalid extension struct\n");
172 if (extensions
->ext_array
)
173 vk_free(&instance
->alloc
, extensions
->ext_array
);
177 is_extension_enabled(const VkExtensionProperties
*extensions
,
181 assert(extensions
&& name
);
183 for (uint32_t i
= 0; i
< num_ext
; i
++) {
184 if (strcmp(name
, extensions
[i
].extensionName
) == 0)
192 radv_physical_device_init(struct radv_physical_device
*device
,
193 struct radv_instance
*instance
,
197 drmVersionPtr version
;
200 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
202 return VK_ERROR_INCOMPATIBLE_DRIVER
;
204 version
= drmGetVersion(fd
);
207 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
208 "failed to get version %s: %m", path
);
211 if (strcmp(version
->name
, "amdgpu")) {
212 drmFreeVersion(version
);
214 return VK_ERROR_INCOMPATIBLE_DRIVER
;
216 drmFreeVersion(version
);
218 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
219 device
->instance
= instance
;
220 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
221 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
223 device
->ws
= radv_amdgpu_winsys_create(fd
);
225 result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
229 device
->local_fd
= fd
;
230 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
231 result
= radv_init_wsi(device
);
232 if (result
!= VK_SUCCESS
) {
233 device
->ws
->destroy(device
->ws
);
237 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->uuid
)) {
238 radv_finish_wsi(device
);
239 device
->ws
->destroy(device
->ws
);
240 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
241 "cannot generate UUID");
245 result
= radv_extensions_register(instance
,
247 common_device_extensions
,
248 ARRAY_SIZE(common_device_extensions
));
249 if (result
!= VK_SUCCESS
)
252 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
253 device
->name
= device
->rad_info
.name
;
263 radv_physical_device_finish(struct radv_physical_device
*device
)
265 radv_extensions_finish(device
->instance
, &device
->extensions
);
266 radv_finish_wsi(device
);
267 device
->ws
->destroy(device
->ws
);
268 close(device
->local_fd
);
273 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
274 VkSystemAllocationScope allocationScope
)
280 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
281 size_t align
, VkSystemAllocationScope allocationScope
)
283 return realloc(pOriginal
, size
);
287 default_free_func(void *pUserData
, void *pMemory
)
292 static const VkAllocationCallbacks default_alloc
= {
294 .pfnAllocation
= default_alloc_func
,
295 .pfnReallocation
= default_realloc_func
,
296 .pfnFree
= default_free_func
,
299 static const struct debug_control radv_debug_options
[] = {
300 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
301 {"nodcc", RADV_DEBUG_NO_DCC
},
302 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
303 {"nocache", RADV_DEBUG_NO_CACHE
},
304 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
305 {"nohiz", RADV_DEBUG_NO_HIZ
},
306 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
307 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
311 VkResult
radv_CreateInstance(
312 const VkInstanceCreateInfo
* pCreateInfo
,
313 const VkAllocationCallbacks
* pAllocator
,
314 VkInstance
* pInstance
)
316 struct radv_instance
*instance
;
318 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
320 uint32_t client_version
;
321 if (pCreateInfo
->pApplicationInfo
&&
322 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
323 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
325 client_version
= VK_MAKE_VERSION(1, 0, 0);
328 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
329 client_version
> VK_MAKE_VERSION(1, 0, 0xfff)) {
330 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
331 "Client requested version %d.%d.%d",
332 VK_VERSION_MAJOR(client_version
),
333 VK_VERSION_MINOR(client_version
),
334 VK_VERSION_PATCH(client_version
));
337 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
338 if (!is_extension_enabled(instance_extensions
,
339 ARRAY_SIZE(instance_extensions
),
340 pCreateInfo
->ppEnabledExtensionNames
[i
]))
341 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
344 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
345 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
347 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
349 memset(instance
, 0, sizeof(*instance
));
351 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
354 instance
->alloc
= *pAllocator
;
356 instance
->alloc
= default_alloc
;
358 instance
->apiVersion
= client_version
;
359 instance
->physicalDeviceCount
= -1;
363 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
365 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
368 *pInstance
= radv_instance_to_handle(instance
);
373 void radv_DestroyInstance(
374 VkInstance _instance
,
375 const VkAllocationCallbacks
* pAllocator
)
377 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
379 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
380 radv_physical_device_finish(instance
->physicalDevices
+ i
);
383 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
387 vk_free(&instance
->alloc
, instance
);
390 VkResult
radv_EnumeratePhysicalDevices(
391 VkInstance _instance
,
392 uint32_t* pPhysicalDeviceCount
,
393 VkPhysicalDevice
* pPhysicalDevices
)
395 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
398 if (instance
->physicalDeviceCount
< 0) {
400 instance
->physicalDeviceCount
= 0;
401 for (unsigned i
= 0; i
< RADV_MAX_DRM_DEVICES
; i
++) {
402 snprintf(path
, sizeof(path
), "/dev/dri/renderD%d", 128 + i
);
403 result
= radv_physical_device_init(instance
->physicalDevices
+
404 instance
->physicalDeviceCount
,
406 if (result
== VK_SUCCESS
)
407 ++instance
->physicalDeviceCount
;
408 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
413 if (!pPhysicalDevices
) {
414 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
416 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
417 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
418 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
421 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
425 void radv_GetPhysicalDeviceFeatures(
426 VkPhysicalDevice physicalDevice
,
427 VkPhysicalDeviceFeatures
* pFeatures
)
429 // RADV_FROM_HANDLE(radv_physical_device, pdevice, physicalDevice);
431 memset(pFeatures
, 0, sizeof(*pFeatures
));
433 *pFeatures
= (VkPhysicalDeviceFeatures
) {
434 .robustBufferAccess
= true,
435 .fullDrawIndexUint32
= true,
436 .imageCubeArray
= true,
437 .independentBlend
= true,
438 .geometryShader
= true,
439 .tessellationShader
= false,
440 .sampleRateShading
= false,
441 .dualSrcBlend
= true,
443 .multiDrawIndirect
= true,
444 .drawIndirectFirstInstance
= true,
446 .depthBiasClamp
= true,
447 .fillModeNonSolid
= true,
452 .multiViewport
= true,
453 .samplerAnisotropy
= true,
454 .textureCompressionETC2
= false,
455 .textureCompressionASTC_LDR
= false,
456 .textureCompressionBC
= true,
457 .occlusionQueryPrecise
= true,
458 .pipelineStatisticsQuery
= false,
459 .vertexPipelineStoresAndAtomics
= true,
460 .fragmentStoresAndAtomics
= true,
461 .shaderTessellationAndGeometryPointSize
= true,
462 .shaderImageGatherExtended
= true,
463 .shaderStorageImageExtendedFormats
= true,
464 .shaderStorageImageMultisample
= false,
465 .shaderUniformBufferArrayDynamicIndexing
= true,
466 .shaderSampledImageArrayDynamicIndexing
= true,
467 .shaderStorageBufferArrayDynamicIndexing
= true,
468 .shaderStorageImageArrayDynamicIndexing
= true,
469 .shaderStorageImageReadWithoutFormat
= true,
470 .shaderStorageImageWriteWithoutFormat
= true,
471 .shaderClipDistance
= true,
472 .shaderCullDistance
= true,
473 .shaderFloat64
= true,
474 .shaderInt64
= false,
475 .shaderInt16
= false,
477 .variableMultisampleRate
= false,
478 .inheritedQueries
= false,
482 void radv_GetPhysicalDeviceFeatures2KHR(
483 VkPhysicalDevice physicalDevice
,
484 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
486 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
489 void radv_GetPhysicalDeviceProperties(
490 VkPhysicalDevice physicalDevice
,
491 VkPhysicalDeviceProperties
* pProperties
)
493 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
494 VkSampleCountFlags sample_counts
= 0xf;
495 VkPhysicalDeviceLimits limits
= {
496 .maxImageDimension1D
= (1 << 14),
497 .maxImageDimension2D
= (1 << 14),
498 .maxImageDimension3D
= (1 << 11),
499 .maxImageDimensionCube
= (1 << 14),
500 .maxImageArrayLayers
= (1 << 11),
501 .maxTexelBufferElements
= 128 * 1024 * 1024,
502 .maxUniformBufferRange
= UINT32_MAX
,
503 .maxStorageBufferRange
= UINT32_MAX
,
504 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
505 .maxMemoryAllocationCount
= UINT32_MAX
,
506 .maxSamplerAllocationCount
= 64 * 1024,
507 .bufferImageGranularity
= 64, /* A cache line */
508 .sparseAddressSpaceSize
= 0,
509 .maxBoundDescriptorSets
= MAX_SETS
,
510 .maxPerStageDescriptorSamplers
= 64,
511 .maxPerStageDescriptorUniformBuffers
= 64,
512 .maxPerStageDescriptorStorageBuffers
= 64,
513 .maxPerStageDescriptorSampledImages
= 64,
514 .maxPerStageDescriptorStorageImages
= 64,
515 .maxPerStageDescriptorInputAttachments
= 64,
516 .maxPerStageResources
= 128,
517 .maxDescriptorSetSamplers
= 256,
518 .maxDescriptorSetUniformBuffers
= 256,
519 .maxDescriptorSetUniformBuffersDynamic
= 256,
520 .maxDescriptorSetStorageBuffers
= 256,
521 .maxDescriptorSetStorageBuffersDynamic
= 256,
522 .maxDescriptorSetSampledImages
= 256,
523 .maxDescriptorSetStorageImages
= 256,
524 .maxDescriptorSetInputAttachments
= 256,
525 .maxVertexInputAttributes
= 32,
526 .maxVertexInputBindings
= 32,
527 .maxVertexInputAttributeOffset
= 2047,
528 .maxVertexInputBindingStride
= 2048,
529 .maxVertexOutputComponents
= 128,
530 .maxTessellationGenerationLevel
= 0,
531 .maxTessellationPatchSize
= 0,
532 .maxTessellationControlPerVertexInputComponents
= 0,
533 .maxTessellationControlPerVertexOutputComponents
= 0,
534 .maxTessellationControlPerPatchOutputComponents
= 0,
535 .maxTessellationControlTotalOutputComponents
= 0,
536 .maxTessellationEvaluationInputComponents
= 0,
537 .maxTessellationEvaluationOutputComponents
= 0,
538 .maxGeometryShaderInvocations
= 32,
539 .maxGeometryInputComponents
= 64,
540 .maxGeometryOutputComponents
= 128,
541 .maxGeometryOutputVertices
= 256,
542 .maxGeometryTotalOutputComponents
= 1024,
543 .maxFragmentInputComponents
= 128,
544 .maxFragmentOutputAttachments
= 8,
545 .maxFragmentDualSrcAttachments
= 1,
546 .maxFragmentCombinedOutputResources
= 8,
547 .maxComputeSharedMemorySize
= 32768,
548 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
549 .maxComputeWorkGroupInvocations
= 2048,
550 .maxComputeWorkGroupSize
= {
555 .subPixelPrecisionBits
= 4 /* FIXME */,
556 .subTexelPrecisionBits
= 4 /* FIXME */,
557 .mipmapPrecisionBits
= 4 /* FIXME */,
558 .maxDrawIndexedIndexValue
= UINT32_MAX
,
559 .maxDrawIndirectCount
= UINT32_MAX
,
560 .maxSamplerLodBias
= 16,
561 .maxSamplerAnisotropy
= 16,
562 .maxViewports
= MAX_VIEWPORTS
,
563 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
564 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
565 .viewportSubPixelBits
= 13, /* We take a float? */
566 .minMemoryMapAlignment
= 4096, /* A page */
567 .minTexelBufferOffsetAlignment
= 1,
568 .minUniformBufferOffsetAlignment
= 4,
569 .minStorageBufferOffsetAlignment
= 4,
570 .minTexelOffset
= -32,
571 .maxTexelOffset
= 31,
572 .minTexelGatherOffset
= -32,
573 .maxTexelGatherOffset
= 31,
574 .minInterpolationOffset
= -2,
575 .maxInterpolationOffset
= 2,
576 .subPixelInterpolationOffsetBits
= 8,
577 .maxFramebufferWidth
= (1 << 14),
578 .maxFramebufferHeight
= (1 << 14),
579 .maxFramebufferLayers
= (1 << 10),
580 .framebufferColorSampleCounts
= sample_counts
,
581 .framebufferDepthSampleCounts
= sample_counts
,
582 .framebufferStencilSampleCounts
= sample_counts
,
583 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
584 .maxColorAttachments
= MAX_RTS
,
585 .sampledImageColorSampleCounts
= sample_counts
,
586 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
587 .sampledImageDepthSampleCounts
= sample_counts
,
588 .sampledImageStencilSampleCounts
= sample_counts
,
589 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
590 .maxSampleMaskWords
= 1,
591 .timestampComputeAndGraphics
= false,
592 .timestampPeriod
= 100000.0 / pdevice
->rad_info
.clock_crystal_freq
,
593 .maxClipDistances
= 8,
594 .maxCullDistances
= 8,
595 .maxCombinedClipAndCullDistances
= 8,
596 .discreteQueuePriorities
= 1,
597 .pointSizeRange
= { 0.125, 255.875 },
598 .lineWidthRange
= { 0.0, 7.9921875 },
599 .pointSizeGranularity
= (1.0 / 8.0),
600 .lineWidthGranularity
= (1.0 / 128.0),
601 .strictLines
= false, /* FINISHME */
602 .standardSampleLocations
= true,
603 .optimalBufferCopyOffsetAlignment
= 128,
604 .optimalBufferCopyRowPitchAlignment
= 128,
605 .nonCoherentAtomSize
= 64,
608 *pProperties
= (VkPhysicalDeviceProperties
) {
609 .apiVersion
= VK_MAKE_VERSION(1, 0, 5),
612 .deviceID
= pdevice
->rad_info
.pci_id
,
613 .deviceType
= VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
,
615 .sparseProperties
= {0}, /* Broadwell doesn't do sparse. */
618 strcpy(pProperties
->deviceName
, pdevice
->name
);
619 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->uuid
, VK_UUID_SIZE
);
622 void radv_GetPhysicalDeviceProperties2KHR(
623 VkPhysicalDevice physicalDevice
,
624 VkPhysicalDeviceProperties2KHR
*pProperties
)
626 return radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
629 static void radv_get_physical_device_queue_family_properties(
630 struct radv_physical_device
* pdevice
,
632 VkQueueFamilyProperties
** pQueueFamilyProperties
)
634 int num_queue_families
= 1;
636 if (pdevice
->rad_info
.compute_rings
> 0 &&
637 pdevice
->rad_info
.chip_class
>= CIK
&&
638 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
639 num_queue_families
++;
641 if (pQueueFamilyProperties
== NULL
) {
642 *pCount
= num_queue_families
;
651 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
652 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
653 VK_QUEUE_COMPUTE_BIT
|
654 VK_QUEUE_TRANSFER_BIT
,
656 .timestampValidBits
= 64,
657 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
662 if (pdevice
->rad_info
.compute_rings
> 0 &&
663 pdevice
->rad_info
.chip_class
>= CIK
&&
664 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
666 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
667 .queueFlags
= VK_QUEUE_COMPUTE_BIT
| VK_QUEUE_TRANSFER_BIT
,
668 .queueCount
= pdevice
->rad_info
.compute_rings
,
669 .timestampValidBits
= 64,
670 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
678 void radv_GetPhysicalDeviceQueueFamilyProperties(
679 VkPhysicalDevice physicalDevice
,
681 VkQueueFamilyProperties
* pQueueFamilyProperties
)
683 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
684 if (!pQueueFamilyProperties
) {
685 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
688 VkQueueFamilyProperties
*properties
[] = {
689 pQueueFamilyProperties
+ 0,
690 pQueueFamilyProperties
+ 1,
691 pQueueFamilyProperties
+ 2,
693 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
694 assert(*pCount
<= 3);
697 void radv_GetPhysicalDeviceQueueFamilyProperties2KHR(
698 VkPhysicalDevice physicalDevice
,
700 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
702 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
703 if (!pQueueFamilyProperties
) {
704 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
707 VkQueueFamilyProperties
*properties
[] = {
708 &pQueueFamilyProperties
[0].queueFamilyProperties
,
709 &pQueueFamilyProperties
[1].queueFamilyProperties
,
710 &pQueueFamilyProperties
[2].queueFamilyProperties
,
712 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
713 assert(*pCount
<= 3);
716 void radv_GetPhysicalDeviceMemoryProperties(
717 VkPhysicalDevice physicalDevice
,
718 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
720 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
722 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
724 pMemoryProperties
->memoryTypeCount
= RADV_MEM_TYPE_COUNT
;
725 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_VRAM
] = (VkMemoryType
) {
726 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
727 .heapIndex
= RADV_MEM_HEAP_VRAM
,
729 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_GTT_WRITE_COMBINE
] = (VkMemoryType
) {
730 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
731 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
732 .heapIndex
= RADV_MEM_HEAP_GTT
,
734 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_VRAM_CPU_ACCESS
] = (VkMemoryType
) {
735 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
736 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
737 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
738 .heapIndex
= RADV_MEM_HEAP_VRAM_CPU_ACCESS
,
740 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_GTT_CACHED
] = (VkMemoryType
) {
741 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
742 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
743 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
744 .heapIndex
= RADV_MEM_HEAP_GTT
,
747 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
749 pMemoryProperties
->memoryHeapCount
= RADV_MEM_HEAP_COUNT
;
750 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_VRAM
] = (VkMemoryHeap
) {
751 .size
= physical_device
->rad_info
.vram_size
-
752 physical_device
->rad_info
.visible_vram_size
,
753 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
755 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_VRAM_CPU_ACCESS
] = (VkMemoryHeap
) {
756 .size
= physical_device
->rad_info
.visible_vram_size
,
757 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
759 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_GTT
] = (VkMemoryHeap
) {
760 .size
= physical_device
->rad_info
.gart_size
,
765 void radv_GetPhysicalDeviceMemoryProperties2KHR(
766 VkPhysicalDevice physicalDevice
,
767 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
769 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
770 &pMemoryProperties
->memoryProperties
);
774 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
775 int queue_family_index
, int idx
)
777 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
778 queue
->device
= device
;
779 queue
->queue_family_index
= queue_family_index
;
780 queue
->queue_idx
= idx
;
782 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
);
784 return VK_ERROR_OUT_OF_HOST_MEMORY
;
790 radv_queue_finish(struct radv_queue
*queue
)
793 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
795 if (queue
->preamble_cs
)
796 queue
->device
->ws
->cs_destroy(queue
->preamble_cs
);
797 if (queue
->descriptor_bo
)
798 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
799 if (queue
->scratch_bo
)
800 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
801 if (queue
->esgs_ring_bo
)
802 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
803 if (queue
->gsvs_ring_bo
)
804 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
805 if (queue
->compute_scratch_bo
)
806 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
810 radv_device_init_gs_info(struct radv_device
*device
)
812 switch (device
->physical_device
->rad_info
.family
) {
821 device
->gs_table_depth
= 16;
832 device
->gs_table_depth
= 32;
835 unreachable("unknown GPU");
839 VkResult
radv_CreateDevice(
840 VkPhysicalDevice physicalDevice
,
841 const VkDeviceCreateInfo
* pCreateInfo
,
842 const VkAllocationCallbacks
* pAllocator
,
845 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
847 struct radv_device
*device
;
849 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
850 if (!is_extension_enabled(physical_device
->extensions
.ext_array
,
851 physical_device
->extensions
.num_ext
,
852 pCreateInfo
->ppEnabledExtensionNames
[i
]))
853 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
856 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
858 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
860 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
862 memset(device
, 0, sizeof(*device
));
864 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
865 device
->instance
= physical_device
->instance
;
866 device
->physical_device
= physical_device
;
868 device
->debug_flags
= device
->instance
->debug_flags
;
870 device
->ws
= physical_device
->ws
;
872 device
->alloc
= *pAllocator
;
874 device
->alloc
= physical_device
->instance
->alloc
;
876 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
877 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
878 uint32_t qfi
= queue_create
->queueFamilyIndex
;
880 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
881 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
882 if (!device
->queues
[qfi
]) {
883 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
887 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
889 device
->queue_count
[qfi
] = queue_create
->queueCount
;
891 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
892 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
], qfi
, q
);
893 if (result
!= VK_SUCCESS
)
898 #if HAVE_LLVM < 0x0400
899 device
->llvm_supports_spill
= false;
901 device
->llvm_supports_spill
= true;
904 /* The maximum number of scratch waves. Scratch space isn't divided
905 * evenly between CUs. The number is only a function of the number of CUs.
906 * We can decrease the constant to decrease the scratch buffer size.
908 * sctx->scratch_waves must be >= the maximum posible size of
909 * 1 threadgroup, so that the hw doesn't hang from being unable
912 * The recommended value is 4 per CU at most. Higher numbers don't
913 * bring much benefit, but they still occupy chip resources (think
914 * async compute). I've seen ~2% performance difference between 4 and 32.
916 uint32_t max_threads_per_block
= 2048;
917 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
918 max_threads_per_block
/ 64);
920 radv_device_init_gs_info(device
);
922 result
= radv_device_init_meta(device
);
923 if (result
!= VK_SUCCESS
)
926 radv_device_init_msaa(device
);
928 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
929 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
931 case RADV_QUEUE_GENERAL
:
932 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
933 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
934 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
936 case RADV_QUEUE_COMPUTE
:
937 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
938 radeon_emit(device
->empty_cs
[family
], 0);
941 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
944 if (getenv("RADV_TRACE_FILE")) {
945 device
->trace_bo
= device
->ws
->buffer_create(device
->ws
, 4096, 8,
946 RADEON_DOMAIN_VRAM
, RADEON_FLAG_CPU_ACCESS
);
947 if (!device
->trace_bo
)
950 device
->trace_id_ptr
= device
->ws
->buffer_map(device
->trace_bo
);
951 if (!device
->trace_id_ptr
)
955 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
956 cik_create_gfx_config(device
);
958 *pDevice
= radv_device_to_handle(device
);
962 if (device
->trace_bo
)
963 device
->ws
->buffer_destroy(device
->trace_bo
);
965 if (device
->gfx_init
)
966 device
->ws
->buffer_destroy(device
->gfx_init
);
968 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
969 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
970 radv_queue_finish(&device
->queues
[i
][q
]);
971 if (device
->queue_count
[i
])
972 vk_free(&device
->alloc
, device
->queues
[i
]);
975 vk_free(&device
->alloc
, device
);
979 void radv_DestroyDevice(
981 const VkAllocationCallbacks
* pAllocator
)
983 RADV_FROM_HANDLE(radv_device
, device
, _device
);
985 if (device
->trace_bo
)
986 device
->ws
->buffer_destroy(device
->trace_bo
);
988 if (device
->gfx_init
)
989 device
->ws
->buffer_destroy(device
->gfx_init
);
991 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
992 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
993 radv_queue_finish(&device
->queues
[i
][q
]);
994 if (device
->queue_count
[i
])
995 vk_free(&device
->alloc
, device
->queues
[i
]);
996 if (device
->empty_cs
[i
])
997 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
999 radv_device_finish_meta(device
);
1001 vk_free(&device
->alloc
, device
);
1004 VkResult
radv_EnumerateInstanceExtensionProperties(
1005 const char* pLayerName
,
1006 uint32_t* pPropertyCount
,
1007 VkExtensionProperties
* pProperties
)
1009 if (pProperties
== NULL
) {
1010 *pPropertyCount
= ARRAY_SIZE(instance_extensions
);
1014 *pPropertyCount
= MIN2(*pPropertyCount
, ARRAY_SIZE(instance_extensions
));
1015 typed_memcpy(pProperties
, instance_extensions
, *pPropertyCount
);
1017 if (*pPropertyCount
< ARRAY_SIZE(instance_extensions
))
1018 return VK_INCOMPLETE
;
1023 VkResult
radv_EnumerateDeviceExtensionProperties(
1024 VkPhysicalDevice physicalDevice
,
1025 const char* pLayerName
,
1026 uint32_t* pPropertyCount
,
1027 VkExtensionProperties
* pProperties
)
1029 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1031 if (pProperties
== NULL
) {
1032 *pPropertyCount
= pdevice
->extensions
.num_ext
;
1036 *pPropertyCount
= MIN2(*pPropertyCount
, pdevice
->extensions
.num_ext
);
1037 typed_memcpy(pProperties
, pdevice
->extensions
.ext_array
, *pPropertyCount
);
1039 if (*pPropertyCount
< pdevice
->extensions
.num_ext
)
1040 return VK_INCOMPLETE
;
1045 VkResult
radv_EnumerateInstanceLayerProperties(
1046 uint32_t* pPropertyCount
,
1047 VkLayerProperties
* pProperties
)
1049 if (pProperties
== NULL
) {
1050 *pPropertyCount
= 0;
1054 /* None supported at this time */
1055 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1058 VkResult
radv_EnumerateDeviceLayerProperties(
1059 VkPhysicalDevice physicalDevice
,
1060 uint32_t* pPropertyCount
,
1061 VkLayerProperties
* pProperties
)
1063 if (pProperties
== NULL
) {
1064 *pPropertyCount
= 0;
1068 /* None supported at this time */
1069 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1072 void radv_GetDeviceQueue(
1074 uint32_t queueFamilyIndex
,
1075 uint32_t queueIndex
,
1078 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1080 *pQueue
= radv_queue_to_handle(&device
->queues
[queueFamilyIndex
][queueIndex
]);
1083 static void radv_dump_trace(struct radv_device
*device
,
1084 struct radeon_winsys_cs
*cs
)
1086 const char *filename
= getenv("RADV_TRACE_FILE");
1087 FILE *f
= fopen(filename
, "w");
1089 fprintf(stderr
, "Failed to write trace dump to %s\n", filename
);
1093 fprintf(f
, "Trace ID: %x\n", *device
->trace_id_ptr
);
1094 device
->ws
->cs_dump(cs
, f
, *device
->trace_id_ptr
);
1099 fill_geom_rings(struct radv_queue
*queue
,
1101 uint32_t esgs_ring_size
,
1102 struct radeon_winsys_bo
*esgs_ring_bo
,
1103 uint32_t gsvs_ring_size
,
1104 struct radeon_winsys_bo
*gsvs_ring_bo
)
1106 uint64_t esgs_va
= 0, gsvs_va
= 0;
1107 uint32_t *desc
= &map
[4];
1110 esgs_va
= queue
->device
->ws
->buffer_get_va(esgs_ring_bo
);
1112 gsvs_va
= queue
->device
->ws
->buffer_get_va(gsvs_ring_bo
);
1114 /* stride 0, num records - size, add tid, swizzle, elsize4,
1117 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1118 S_008F04_STRIDE(0) |
1119 S_008F04_SWIZZLE_ENABLE(true);
1120 desc
[2] = esgs_ring_size
;
1121 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1122 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1123 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1124 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1125 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1126 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1127 S_008F0C_ELEMENT_SIZE(1) |
1128 S_008F0C_INDEX_STRIDE(3) |
1129 S_008F0C_ADD_TID_ENABLE(true);
1132 /* GS entry for ES->GS ring */
1133 /* stride 0, num records - size, elsize0,
1136 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1137 S_008F04_STRIDE(0) |
1138 S_008F04_SWIZZLE_ENABLE(false);
1139 desc
[2] = esgs_ring_size
;
1140 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1141 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1142 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1143 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1144 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1145 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1146 S_008F0C_ELEMENT_SIZE(0) |
1147 S_008F0C_INDEX_STRIDE(0) |
1148 S_008F0C_ADD_TID_ENABLE(false);
1151 /* VS entry for GS->VS ring */
1152 /* stride 0, num records - size, elsize0,
1155 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1156 S_008F04_STRIDE(0) |
1157 S_008F04_SWIZZLE_ENABLE(false);
1158 desc
[2] = gsvs_ring_size
;
1159 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1160 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1161 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1162 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1163 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1164 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1165 S_008F0C_ELEMENT_SIZE(0) |
1166 S_008F0C_INDEX_STRIDE(0) |
1167 S_008F0C_ADD_TID_ENABLE(false);
1170 /* stride gsvs_itemsize, num records 64
1171 elsize 4, index stride 16 */
1172 /* shader will patch stride and desc[2] */
1174 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1175 S_008F04_STRIDE(0) |
1176 S_008F04_SWIZZLE_ENABLE(true);
1178 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1179 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1180 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1181 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1182 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1183 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1184 S_008F0C_ELEMENT_SIZE(1) |
1185 S_008F0C_INDEX_STRIDE(1) |
1186 S_008F0C_ADD_TID_ENABLE(true);
1190 radv_get_preamble_cs(struct radv_queue
*queue
,
1191 uint32_t scratch_size
,
1192 uint32_t compute_scratch_size
,
1193 uint32_t esgs_ring_size
,
1194 uint32_t gsvs_ring_size
,
1195 struct radeon_winsys_cs
**preamble_cs
)
1197 struct radeon_winsys_bo
*scratch_bo
= NULL
;
1198 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
1199 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
1200 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
1201 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
1202 struct radeon_winsys_cs
*cs
= NULL
;
1204 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
) {
1205 *preamble_cs
= NULL
;
1209 if (scratch_size
<= queue
->scratch_size
&&
1210 compute_scratch_size
<= queue
->compute_scratch_size
&&
1211 esgs_ring_size
<= queue
->esgs_ring_size
&&
1212 gsvs_ring_size
<= queue
->gsvs_ring_size
) {
1213 *preamble_cs
= queue
->preamble_cs
;
1217 if (scratch_size
> queue
->scratch_size
) {
1218 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1222 RADEON_FLAG_NO_CPU_ACCESS
);
1226 scratch_bo
= queue
->scratch_bo
;
1228 if (compute_scratch_size
> queue
->compute_scratch_size
) {
1229 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1230 compute_scratch_size
,
1233 RADEON_FLAG_NO_CPU_ACCESS
);
1234 if (!compute_scratch_bo
)
1238 compute_scratch_bo
= queue
->compute_scratch_bo
;
1240 if (esgs_ring_size
> queue
->esgs_ring_size
) {
1241 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1245 RADEON_FLAG_NO_CPU_ACCESS
);
1249 esgs_ring_bo
= queue
->esgs_ring_bo
;
1250 esgs_ring_size
= queue
->esgs_ring_size
;
1253 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
1254 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1258 RADEON_FLAG_NO_CPU_ACCESS
);
1262 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
1263 gsvs_ring_size
= queue
->gsvs_ring_size
;
1266 if (scratch_bo
!= queue
->scratch_bo
||
1267 esgs_ring_bo
!= queue
->esgs_ring_bo
||
1268 gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
1270 if (gsvs_ring_bo
|| esgs_ring_bo
)
1271 size
= 80; /* 2 dword + 2 padding + 4 dword * 4 */
1272 else if (scratch_bo
)
1273 size
= 8; /* 2 dword */
1275 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1279 RADEON_FLAG_CPU_ACCESS
);
1283 descriptor_bo
= queue
->descriptor_bo
;
1285 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
1286 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
1292 queue
->device
->ws
->cs_add_buffer(cs
, scratch_bo
, 8);
1295 queue
->device
->ws
->cs_add_buffer(cs
, esgs_ring_bo
, 8);
1298 queue
->device
->ws
->cs_add_buffer(cs
, gsvs_ring_bo
, 8);
1301 queue
->device
->ws
->cs_add_buffer(cs
, descriptor_bo
, 8);
1303 if (descriptor_bo
!= queue
->descriptor_bo
) {
1304 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
1307 uint64_t scratch_va
= queue
->device
->ws
->buffer_get_va(scratch_bo
);
1308 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1309 S_008F04_SWIZZLE_ENABLE(1);
1310 map
[0] = scratch_va
;
1314 if (esgs_ring_bo
|| gsvs_ring_bo
)
1315 fill_geom_rings(queue
, map
, esgs_ring_size
, esgs_ring_bo
, gsvs_ring_size
, gsvs_ring_bo
);
1317 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
1320 if (esgs_ring_bo
|| gsvs_ring_bo
) {
1321 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1322 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
1323 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1324 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
1326 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1327 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
1328 radeon_emit(cs
, esgs_ring_size
>> 8);
1329 radeon_emit(cs
, gsvs_ring_size
>> 8);
1331 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
1332 radeon_emit(cs
, esgs_ring_size
>> 8);
1333 radeon_emit(cs
, gsvs_ring_size
>> 8);
1337 if (descriptor_bo
) {
1338 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
1339 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
1340 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
1341 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
1342 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
1343 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
1345 uint64_t va
= queue
->device
->ws
->buffer_get_va(descriptor_bo
);
1347 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
1348 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
1349 radeon_emit(cs
, va
);
1350 radeon_emit(cs
, va
>> 32);
1354 if (compute_scratch_bo
) {
1355 uint64_t scratch_va
= queue
->device
->ws
->buffer_get_va(compute_scratch_bo
);
1356 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1357 S_008F04_SWIZZLE_ENABLE(1);
1359 queue
->device
->ws
->cs_add_buffer(cs
, compute_scratch_bo
, 8);
1361 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
1362 radeon_emit(cs
, scratch_va
);
1363 radeon_emit(cs
, rsrc1
);
1366 if (!queue
->device
->ws
->cs_finalize(cs
))
1369 if (queue
->preamble_cs
)
1370 queue
->device
->ws
->cs_destroy(queue
->preamble_cs
);
1372 queue
->preamble_cs
= cs
;
1374 if (scratch_bo
!= queue
->scratch_bo
) {
1375 if (queue
->scratch_bo
)
1376 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1377 queue
->scratch_bo
= scratch_bo
;
1378 queue
->scratch_size
= scratch_size
;
1381 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
1382 if (queue
->compute_scratch_bo
)
1383 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1384 queue
->compute_scratch_bo
= compute_scratch_bo
;
1385 queue
->compute_scratch_size
= compute_scratch_size
;
1388 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
1389 if (queue
->esgs_ring_bo
)
1390 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1391 queue
->esgs_ring_bo
= esgs_ring_bo
;
1392 queue
->esgs_ring_size
= esgs_ring_size
;
1395 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
1396 if (queue
->gsvs_ring_bo
)
1397 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1398 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
1399 queue
->gsvs_ring_size
= gsvs_ring_size
;
1402 if (descriptor_bo
!= queue
->descriptor_bo
) {
1403 if (queue
->descriptor_bo
)
1404 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1406 queue
->descriptor_bo
= descriptor_bo
;
1413 queue
->device
->ws
->cs_destroy(cs
);
1414 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
1415 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
1416 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
1417 queue
->device
->ws
->buffer_destroy(scratch_bo
);
1418 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
1419 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
1420 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
1421 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
1422 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
1423 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
1424 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
1427 VkResult
radv_QueueSubmit(
1429 uint32_t submitCount
,
1430 const VkSubmitInfo
* pSubmits
,
1433 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
1434 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
1435 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
1436 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
1438 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
1439 uint32_t scratch_size
= 0;
1440 uint32_t compute_scratch_size
= 0;
1441 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
1442 struct radeon_winsys_cs
*preamble_cs
= NULL
;
1444 bool fence_emitted
= false;
1446 /* Do this first so failing to allocate scratch buffers can't result in
1447 * partially executed submissions. */
1448 for (uint32_t i
= 0; i
< submitCount
; i
++) {
1449 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
1450 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
1451 pSubmits
[i
].pCommandBuffers
[j
]);
1453 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
1454 compute_scratch_size
= MAX2(compute_scratch_size
,
1455 cmd_buffer
->compute_scratch_size_needed
);
1456 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
1457 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
1461 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
, esgs_ring_size
, gsvs_ring_size
, &preamble_cs
);
1462 if (result
!= VK_SUCCESS
)
1465 for (uint32_t i
= 0; i
< submitCount
; i
++) {
1466 struct radeon_winsys_cs
**cs_array
;
1467 bool can_patch
= true;
1470 if (!pSubmits
[i
].commandBufferCount
) {
1471 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
1472 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
1473 &queue
->device
->empty_cs
[queue
->queue_family_index
],
1475 (struct radeon_winsys_sem
**)pSubmits
[i
].pWaitSemaphores
,
1476 pSubmits
[i
].waitSemaphoreCount
,
1477 (struct radeon_winsys_sem
**)pSubmits
[i
].pSignalSemaphores
,
1478 pSubmits
[i
].signalSemaphoreCount
,
1481 radv_loge("failed to submit CS %d\n", i
);
1484 fence_emitted
= true;
1489 cs_array
= malloc(sizeof(struct radeon_winsys_cs
*) *
1490 pSubmits
[i
].commandBufferCount
);
1492 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
1493 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
1494 pSubmits
[i
].pCommandBuffers
[j
]);
1495 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
1497 cs_array
[j
] = cmd_buffer
->cs
;
1498 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
1502 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
1503 advance
= MIN2(max_cs_submission
,
1504 pSubmits
[i
].commandBufferCount
- j
);
1506 bool e
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
1508 if (queue
->device
->trace_bo
)
1509 *queue
->device
->trace_id_ptr
= 0;
1511 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
1512 advance
, preamble_cs
, preamble_cs
,
1513 (struct radeon_winsys_sem
**)pSubmits
[i
].pWaitSemaphores
,
1514 b
? pSubmits
[i
].waitSemaphoreCount
: 0,
1515 (struct radeon_winsys_sem
**)pSubmits
[i
].pSignalSemaphores
,
1516 e
? pSubmits
[i
].signalSemaphoreCount
: 0,
1517 can_patch
, base_fence
);
1520 radv_loge("failed to submit CS %d\n", i
);
1523 fence_emitted
= true;
1524 if (queue
->device
->trace_bo
) {
1525 bool success
= queue
->device
->ws
->ctx_wait_idle(
1527 radv_queue_family_to_ring(
1528 queue
->queue_family_index
),
1531 if (!success
) { /* Hang */
1532 radv_dump_trace(queue
->device
, cs_array
[j
]);
1542 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
1543 &queue
->device
->empty_cs
[queue
->queue_family_index
],
1544 1, NULL
, NULL
, NULL
, 0, NULL
, 0,
1547 fence
->submitted
= true;
1553 VkResult
radv_QueueWaitIdle(
1556 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
1558 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
1559 radv_queue_family_to_ring(queue
->queue_family_index
),
1564 VkResult
radv_DeviceWaitIdle(
1567 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1569 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1570 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
1571 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
1577 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
1578 VkInstance instance
,
1581 return radv_lookup_entrypoint(pName
);
1584 /* The loader wants us to expose a second GetInstanceProcAddr function
1585 * to work around certain LD_PRELOAD issues seen in apps.
1588 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1589 VkInstance instance
,
1593 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
1594 VkInstance instance
,
1597 return radv_GetInstanceProcAddr(instance
, pName
);
1600 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
1604 return radv_lookup_entrypoint(pName
);
1607 VkResult
radv_AllocateMemory(
1609 const VkMemoryAllocateInfo
* pAllocateInfo
,
1610 const VkAllocationCallbacks
* pAllocator
,
1611 VkDeviceMemory
* pMem
)
1613 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1614 struct radv_device_memory
*mem
;
1616 enum radeon_bo_domain domain
;
1618 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
1620 if (pAllocateInfo
->allocationSize
== 0) {
1621 /* Apparently, this is allowed */
1622 *pMem
= VK_NULL_HANDLE
;
1626 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
1627 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1629 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1631 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
1632 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
1633 pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_CACHED
)
1634 domain
= RADEON_DOMAIN_GTT
;
1636 domain
= RADEON_DOMAIN_VRAM
;
1638 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_VRAM
)
1639 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
1641 flags
|= RADEON_FLAG_CPU_ACCESS
;
1643 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
1644 flags
|= RADEON_FLAG_GTT_WC
;
1646 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, 65536,
1650 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
1653 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
1655 *pMem
= radv_device_memory_to_handle(mem
);
1660 vk_free2(&device
->alloc
, pAllocator
, mem
);
1665 void radv_FreeMemory(
1667 VkDeviceMemory _mem
,
1668 const VkAllocationCallbacks
* pAllocator
)
1670 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1671 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
1676 device
->ws
->buffer_destroy(mem
->bo
);
1679 vk_free2(&device
->alloc
, pAllocator
, mem
);
1682 VkResult
radv_MapMemory(
1684 VkDeviceMemory _memory
,
1685 VkDeviceSize offset
,
1687 VkMemoryMapFlags flags
,
1690 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1691 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
1698 *ppData
= device
->ws
->buffer_map(mem
->bo
);
1704 return VK_ERROR_MEMORY_MAP_FAILED
;
1707 void radv_UnmapMemory(
1709 VkDeviceMemory _memory
)
1711 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1712 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
1717 device
->ws
->buffer_unmap(mem
->bo
);
1720 VkResult
radv_FlushMappedMemoryRanges(
1722 uint32_t memoryRangeCount
,
1723 const VkMappedMemoryRange
* pMemoryRanges
)
1728 VkResult
radv_InvalidateMappedMemoryRanges(
1730 uint32_t memoryRangeCount
,
1731 const VkMappedMemoryRange
* pMemoryRanges
)
1736 void radv_GetBufferMemoryRequirements(
1739 VkMemoryRequirements
* pMemoryRequirements
)
1741 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
1743 pMemoryRequirements
->memoryTypeBits
= (1u << RADV_MEM_TYPE_COUNT
) - 1;
1745 pMemoryRequirements
->size
= buffer
->size
;
1746 pMemoryRequirements
->alignment
= 16;
1749 void radv_GetImageMemoryRequirements(
1752 VkMemoryRequirements
* pMemoryRequirements
)
1754 RADV_FROM_HANDLE(radv_image
, image
, _image
);
1756 pMemoryRequirements
->memoryTypeBits
= (1u << RADV_MEM_TYPE_COUNT
) - 1;
1758 pMemoryRequirements
->size
= image
->size
;
1759 pMemoryRequirements
->alignment
= image
->alignment
;
1762 void radv_GetImageSparseMemoryRequirements(
1765 uint32_t* pSparseMemoryRequirementCount
,
1766 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
1771 void radv_GetDeviceMemoryCommitment(
1773 VkDeviceMemory memory
,
1774 VkDeviceSize
* pCommittedMemoryInBytes
)
1776 *pCommittedMemoryInBytes
= 0;
1779 VkResult
radv_BindBufferMemory(
1782 VkDeviceMemory _memory
,
1783 VkDeviceSize memoryOffset
)
1785 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
1786 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
1789 buffer
->bo
= mem
->bo
;
1790 buffer
->offset
= memoryOffset
;
1799 VkResult
radv_BindImageMemory(
1802 VkDeviceMemory _memory
,
1803 VkDeviceSize memoryOffset
)
1805 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
1806 RADV_FROM_HANDLE(radv_image
, image
, _image
);
1809 image
->bo
= mem
->bo
;
1810 image
->offset
= memoryOffset
;
1819 VkResult
radv_QueueBindSparse(
1821 uint32_t bindInfoCount
,
1822 const VkBindSparseInfo
* pBindInfo
,
1825 stub_return(VK_ERROR_INCOMPATIBLE_DRIVER
);
1828 VkResult
radv_CreateFence(
1830 const VkFenceCreateInfo
* pCreateInfo
,
1831 const VkAllocationCallbacks
* pAllocator
,
1834 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1835 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
1837 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1840 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1842 memset(fence
, 0, sizeof(*fence
));
1843 fence
->submitted
= false;
1844 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
1845 fence
->fence
= device
->ws
->create_fence();
1846 if (!fence
->fence
) {
1847 vk_free2(&device
->alloc
, pAllocator
, fence
);
1848 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1851 *pFence
= radv_fence_to_handle(fence
);
1856 void radv_DestroyFence(
1859 const VkAllocationCallbacks
* pAllocator
)
1861 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1862 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
1866 device
->ws
->destroy_fence(fence
->fence
);
1867 vk_free2(&device
->alloc
, pAllocator
, fence
);
1870 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
1872 uint64_t current_time
;
1875 clock_gettime(CLOCK_MONOTONIC
, &tv
);
1876 current_time
= tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
1878 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
1880 return current_time
+ timeout
;
1883 VkResult
radv_WaitForFences(
1885 uint32_t fenceCount
,
1886 const VkFence
* pFences
,
1890 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1891 timeout
= radv_get_absolute_timeout(timeout
);
1893 if (!waitAll
&& fenceCount
> 1) {
1894 fprintf(stderr
, "radv: WaitForFences without waitAll not implemented yet\n");
1897 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
1898 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
1899 bool expired
= false;
1901 if (fence
->signalled
)
1904 if (!fence
->submitted
)
1907 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
1911 fence
->signalled
= true;
1917 VkResult
radv_ResetFences(VkDevice device
,
1918 uint32_t fenceCount
,
1919 const VkFence
*pFences
)
1921 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
1922 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
1923 fence
->submitted
= fence
->signalled
= false;
1929 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
1931 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1932 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
1934 if (fence
->signalled
)
1936 if (!fence
->submitted
)
1937 return VK_NOT_READY
;
1939 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
1940 return VK_NOT_READY
;
1946 // Queue semaphore functions
1948 VkResult
radv_CreateSemaphore(
1950 const VkSemaphoreCreateInfo
* pCreateInfo
,
1951 const VkAllocationCallbacks
* pAllocator
,
1952 VkSemaphore
* pSemaphore
)
1954 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1955 struct radeon_winsys_sem
*sem
;
1957 sem
= device
->ws
->create_sem(device
->ws
);
1959 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1961 *pSemaphore
= (VkSemaphore
)sem
;
1965 void radv_DestroySemaphore(
1967 VkSemaphore _semaphore
,
1968 const VkAllocationCallbacks
* pAllocator
)
1970 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1971 struct radeon_winsys_sem
*sem
;
1975 sem
= (struct radeon_winsys_sem
*)_semaphore
;
1976 device
->ws
->destroy_sem(sem
);
1979 VkResult
radv_CreateEvent(
1981 const VkEventCreateInfo
* pCreateInfo
,
1982 const VkAllocationCallbacks
* pAllocator
,
1985 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1986 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
1988 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1991 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1993 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
1995 RADEON_FLAG_CPU_ACCESS
);
1997 vk_free2(&device
->alloc
, pAllocator
, event
);
1998 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2001 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
2003 *pEvent
= radv_event_to_handle(event
);
2008 void radv_DestroyEvent(
2011 const VkAllocationCallbacks
* pAllocator
)
2013 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2014 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2018 device
->ws
->buffer_destroy(event
->bo
);
2019 vk_free2(&device
->alloc
, pAllocator
, event
);
2022 VkResult
radv_GetEventStatus(
2026 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2028 if (*event
->map
== 1)
2029 return VK_EVENT_SET
;
2030 return VK_EVENT_RESET
;
2033 VkResult
radv_SetEvent(
2037 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2043 VkResult
radv_ResetEvent(
2047 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2053 VkResult
radv_CreateBuffer(
2055 const VkBufferCreateInfo
* pCreateInfo
,
2056 const VkAllocationCallbacks
* pAllocator
,
2059 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2060 struct radv_buffer
*buffer
;
2062 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2064 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
2065 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2067 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2069 buffer
->size
= pCreateInfo
->size
;
2070 buffer
->usage
= pCreateInfo
->usage
;
2074 *pBuffer
= radv_buffer_to_handle(buffer
);
2079 void radv_DestroyBuffer(
2082 const VkAllocationCallbacks
* pAllocator
)
2084 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2085 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2090 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2093 static inline unsigned
2094 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
2097 return image
->surface
.stencil_tiling_index
[level
];
2099 return image
->surface
.tiling_index
[level
];
2102 static uint32_t radv_surface_layer_count(struct radv_image_view
*iview
)
2104 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: iview
->layer_count
;
2108 radv_initialise_color_surface(struct radv_device
*device
,
2109 struct radv_color_buffer_info
*cb
,
2110 struct radv_image_view
*iview
)
2112 const struct vk_format_description
*desc
;
2113 unsigned ntype
, format
, swap
, endian
;
2114 unsigned blend_clamp
= 0, blend_bypass
= 0;
2115 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
2117 const struct radeon_surf
*surf
= &iview
->image
->surface
;
2118 const struct radeon_surf_level
*level_info
= &surf
->level
[iview
->base_mip
];
2120 desc
= vk_format_description(iview
->vk_format
);
2122 memset(cb
, 0, sizeof(*cb
));
2124 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
2125 va
+= level_info
->offset
;
2126 cb
->cb_color_base
= va
>> 8;
2128 /* CMASK variables */
2129 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
2130 va
+= iview
->image
->cmask
.offset
;
2131 cb
->cb_color_cmask
= va
>> 8;
2132 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
2134 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
2135 va
+= iview
->image
->dcc_offset
;
2136 cb
->cb_dcc_base
= va
>> 8;
2138 uint32_t max_slice
= radv_surface_layer_count(iview
);
2139 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
2140 S_028C6C_SLICE_MAX(iview
->base_layer
+ max_slice
- 1);
2142 cb
->micro_tile_mode
= iview
->image
->surface
.micro_tile_mode
;
2143 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
2144 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
2145 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
2147 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
2148 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
2150 /* Intensity is implemented as Red, so treat it that way. */
2151 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
) |
2152 S_028C74_TILE_MODE_INDEX(tile_mode_index
);
2154 if (iview
->image
->samples
> 1) {
2155 unsigned log_samples
= util_logbase2(iview
->image
->samples
);
2157 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
2158 S_028C74_NUM_FRAGMENTS(log_samples
);
2161 if (iview
->image
->fmask
.size
) {
2162 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
2163 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
2164 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
2165 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
2166 cb
->cb_color_fmask
= va
>> 8;
2167 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
2169 /* This must be set for fast clear to work without FMASK. */
2170 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
2171 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
2172 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
2173 cb
->cb_color_fmask
= cb
->cb_color_base
;
2174 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
2177 ntype
= radv_translate_color_numformat(iview
->vk_format
,
2179 vk_format_get_first_non_void_channel(iview
->vk_format
));
2180 format
= radv_translate_colorformat(iview
->vk_format
);
2181 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
2182 radv_finishme("Illegal color\n");
2183 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
2184 endian
= radv_colorformat_endian_swap(format
);
2186 /* blend clamp should be set for all NORM/SRGB types */
2187 if (ntype
== V_028C70_NUMBER_UNORM
||
2188 ntype
== V_028C70_NUMBER_SNORM
||
2189 ntype
== V_028C70_NUMBER_SRGB
)
2192 /* set blend bypass according to docs if SINT/UINT or
2193 8/24 COLOR variants */
2194 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
2195 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
2196 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
2201 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
2202 (format
== V_028C70_COLOR_8
||
2203 format
== V_028C70_COLOR_8_8
||
2204 format
== V_028C70_COLOR_8_8_8_8
))
2205 ->color_is_int8
= true;
2207 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
2208 S_028C70_COMP_SWAP(swap
) |
2209 S_028C70_BLEND_CLAMP(blend_clamp
) |
2210 S_028C70_BLEND_BYPASS(blend_bypass
) |
2211 S_028C70_SIMPLE_FLOAT(1) |
2212 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
2213 ntype
!= V_028C70_NUMBER_SNORM
&&
2214 ntype
!= V_028C70_NUMBER_SRGB
&&
2215 format
!= V_028C70_COLOR_8_24
&&
2216 format
!= V_028C70_COLOR_24_8
) |
2217 S_028C70_NUMBER_TYPE(ntype
) |
2218 S_028C70_ENDIAN(endian
);
2219 if (iview
->image
->samples
> 1)
2220 if (iview
->image
->fmask
.size
)
2221 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
2223 if (iview
->image
->cmask
.size
&&
2224 !(device
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
2225 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
2227 if (iview
->image
->surface
.dcc_size
&& level_info
->dcc_enabled
)
2228 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
2230 if (device
->physical_device
->rad_info
.chip_class
>= VI
) {
2231 unsigned max_uncompressed_block_size
= 2;
2232 if (iview
->image
->samples
> 1) {
2233 if (iview
->image
->surface
.bpe
== 1)
2234 max_uncompressed_block_size
= 0;
2235 else if (iview
->image
->surface
.bpe
== 2)
2236 max_uncompressed_block_size
= 1;
2239 cb
->cb_dcc_control
= S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
2240 S_028C78_INDEPENDENT_64B_BLOCKS(1);
2243 /* This must be set for fast clear to work without FMASK. */
2244 if (!iview
->image
->fmask
.size
&&
2245 device
->physical_device
->rad_info
.chip_class
== SI
) {
2246 unsigned bankh
= util_logbase2(iview
->image
->surface
.bankh
);
2247 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
2252 radv_initialise_ds_surface(struct radv_device
*device
,
2253 struct radv_ds_buffer_info
*ds
,
2254 struct radv_image_view
*iview
)
2256 unsigned level
= iview
->base_mip
;
2258 uint64_t va
, s_offs
, z_offs
;
2259 const struct radeon_surf_level
*level_info
= &iview
->image
->surface
.level
[level
];
2260 memset(ds
, 0, sizeof(*ds
));
2261 switch (iview
->vk_format
) {
2262 case VK_FORMAT_D24_UNORM_S8_UINT
:
2263 case VK_FORMAT_X8_D24_UNORM_PACK32
:
2264 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
2265 ds
->offset_scale
= 2.0f
;
2267 case VK_FORMAT_D16_UNORM
:
2268 case VK_FORMAT_D16_UNORM_S8_UINT
:
2269 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
2270 ds
->offset_scale
= 4.0f
;
2272 case VK_FORMAT_D32_SFLOAT
:
2273 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
2274 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
2275 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
2276 ds
->offset_scale
= 1.0f
;
2282 format
= radv_translate_dbformat(iview
->vk_format
);
2283 if (format
== V_028040_Z_INVALID
) {
2284 fprintf(stderr
, "Invalid DB format: %d, disabling DB.\n", iview
->vk_format
);
2287 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
;
2288 s_offs
= z_offs
= va
;
2289 z_offs
+= iview
->image
->surface
.level
[level
].offset
;
2290 s_offs
+= iview
->image
->surface
.stencil_level
[level
].offset
;
2292 uint32_t max_slice
= radv_surface_layer_count(iview
);
2293 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
2294 S_028008_SLICE_MAX(iview
->base_layer
+ max_slice
- 1);
2295 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(1);
2296 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
2298 if (iview
->image
->samples
> 1)
2299 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->samples
));
2301 if (iview
->image
->surface
.flags
& RADEON_SURF_SBUFFER
)
2302 ds
->db_stencil_info
= S_028044_FORMAT(V_028044_STENCIL_8
);
2304 ds
->db_stencil_info
= S_028044_FORMAT(V_028044_STENCIL_INVALID
);
2306 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
2307 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
2308 unsigned tiling_index
= iview
->image
->surface
.tiling_index
[level
];
2309 unsigned stencil_index
= iview
->image
->surface
.stencil_tiling_index
[level
];
2310 unsigned macro_index
= iview
->image
->surface
.macro_tile_index
;
2311 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
2312 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
2313 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
2315 ds
->db_depth_info
|=
2316 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
2317 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
2318 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
2319 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
2320 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
2321 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
2322 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
2323 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
2325 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
2326 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
2327 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
2328 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
2331 if (iview
->image
->htile
.size
&& !level
) {
2332 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1) |
2333 S_028040_ALLOW_EXPCLEAR(1);
2335 if (iview
->image
->surface
.flags
& RADEON_SURF_SBUFFER
) {
2336 /* Workaround: For a not yet understood reason, the
2337 * combination of MSAA, fast stencil clear and stencil
2338 * decompress messes with subsequent stencil buffer
2339 * uses. Problem was reproduced on Verde, Bonaire,
2340 * Tonga, and Carrizo.
2342 * Disabling EXPCLEAR works around the problem.
2344 * Check piglit's arb_texture_multisample-stencil-clear
2345 * test if you want to try changing this.
2347 if (iview
->image
->samples
<= 1)
2348 ds
->db_stencil_info
|= S_028044_ALLOW_EXPCLEAR(1);
2350 /* Use all of the htile_buffer for depth if there's no stencil. */
2351 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
2353 va
= device
->ws
->buffer_get_va(iview
->bo
) + iview
->image
->offset
+
2354 iview
->image
->htile
.offset
;
2355 ds
->db_htile_data_base
= va
>> 8;
2356 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
2358 ds
->db_htile_data_base
= 0;
2359 ds
->db_htile_surface
= 0;
2362 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
2363 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
2365 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
2366 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
2367 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
2370 VkResult
radv_CreateFramebuffer(
2372 const VkFramebufferCreateInfo
* pCreateInfo
,
2373 const VkAllocationCallbacks
* pAllocator
,
2374 VkFramebuffer
* pFramebuffer
)
2376 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2377 struct radv_framebuffer
*framebuffer
;
2379 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
2381 size_t size
= sizeof(*framebuffer
) +
2382 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
2383 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
2384 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2385 if (framebuffer
== NULL
)
2386 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2388 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
2389 framebuffer
->width
= pCreateInfo
->width
;
2390 framebuffer
->height
= pCreateInfo
->height
;
2391 framebuffer
->layers
= pCreateInfo
->layers
;
2392 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
2393 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
2394 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
2395 framebuffer
->attachments
[i
].attachment
= iview
;
2396 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
2397 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
2398 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
2399 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
2401 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
2402 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
2403 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_layer_count(iview
));
2406 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
2410 void radv_DestroyFramebuffer(
2413 const VkAllocationCallbacks
* pAllocator
)
2415 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2416 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
2420 vk_free2(&device
->alloc
, pAllocator
, fb
);
2423 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
2425 switch (address_mode
) {
2426 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
2427 return V_008F30_SQ_TEX_WRAP
;
2428 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
2429 return V_008F30_SQ_TEX_MIRROR
;
2430 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
2431 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
2432 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
2433 return V_008F30_SQ_TEX_CLAMP_BORDER
;
2434 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
2435 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
2437 unreachable("illegal tex wrap mode");
2443 radv_tex_compare(VkCompareOp op
)
2446 case VK_COMPARE_OP_NEVER
:
2447 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
2448 case VK_COMPARE_OP_LESS
:
2449 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
2450 case VK_COMPARE_OP_EQUAL
:
2451 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
2452 case VK_COMPARE_OP_LESS_OR_EQUAL
:
2453 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
2454 case VK_COMPARE_OP_GREATER
:
2455 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
2456 case VK_COMPARE_OP_NOT_EQUAL
:
2457 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
2458 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
2459 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
2460 case VK_COMPARE_OP_ALWAYS
:
2461 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
2463 unreachable("illegal compare mode");
2469 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
2472 case VK_FILTER_NEAREST
:
2473 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
2474 V_008F38_SQ_TEX_XY_FILTER_POINT
);
2475 case VK_FILTER_LINEAR
:
2476 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
2477 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
2478 case VK_FILTER_CUBIC_IMG
:
2480 fprintf(stderr
, "illegal texture filter");
2486 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
2489 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
2490 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
2491 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
2492 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
2494 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
2499 radv_tex_bordercolor(VkBorderColor bcolor
)
2502 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
2503 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
2504 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
2505 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
2506 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
2507 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
2508 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
2509 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
2510 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
2518 radv_tex_aniso_filter(unsigned filter
)
2532 radv_init_sampler(struct radv_device
*device
,
2533 struct radv_sampler
*sampler
,
2534 const VkSamplerCreateInfo
*pCreateInfo
)
2536 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
2537 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
2538 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
2539 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
2541 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
2542 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
2543 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
2544 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
2545 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
2546 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
2547 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
2548 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
2549 S_008F30_DISABLE_CUBE_WRAP(0) |
2550 S_008F30_COMPAT_MODE(is_vi
));
2551 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
2552 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
2553 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
2554 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
2555 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
2556 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
2557 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
2558 S_008F38_MIP_POINT_PRECLAMP(1) |
2559 S_008F38_DISABLE_LSB_CEIL(1) |
2560 S_008F38_FILTER_PREC_FIX(1) |
2561 S_008F38_ANISO_OVERRIDE(is_vi
));
2562 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
2563 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
2566 VkResult
radv_CreateSampler(
2568 const VkSamplerCreateInfo
* pCreateInfo
,
2569 const VkAllocationCallbacks
* pAllocator
,
2570 VkSampler
* pSampler
)
2572 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2573 struct radv_sampler
*sampler
;
2575 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
2577 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
2578 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2580 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2582 radv_init_sampler(device
, sampler
, pCreateInfo
);
2583 *pSampler
= radv_sampler_to_handle(sampler
);
2588 void radv_DestroySampler(
2591 const VkAllocationCallbacks
* pAllocator
)
2593 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2594 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
2598 vk_free2(&device
->alloc
, pAllocator
, sampler
);
2602 /* vk_icd.h does not declare this function, so we declare it here to
2603 * suppress Wmissing-prototypes.
2605 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2606 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
2608 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
2609 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
2611 /* For the full details on loader interface versioning, see
2612 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
2613 * What follows is a condensed summary, to help you navigate the large and
2614 * confusing official doc.
2616 * - Loader interface v0 is incompatible with later versions. We don't
2619 * - In loader interface v1:
2620 * - The first ICD entrypoint called by the loader is
2621 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
2623 * - The ICD must statically expose no other Vulkan symbol unless it is
2624 * linked with -Bsymbolic.
2625 * - Each dispatchable Vulkan handle created by the ICD must be
2626 * a pointer to a struct whose first member is VK_LOADER_DATA. The
2627 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
2628 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
2629 * vkDestroySurfaceKHR(). The ICD must be capable of working with
2630 * such loader-managed surfaces.
2632 * - Loader interface v2 differs from v1 in:
2633 * - The first ICD entrypoint called by the loader is
2634 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
2635 * statically expose this entrypoint.
2637 * - Loader interface v3 differs from v2 in:
2638 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
2639 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
2640 * because the loader no longer does so.
2642 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);