2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
32 #include "radv_debug.h"
33 #include "radv_private.h"
34 #include "radv_shader.h"
36 #include "util/disk_cache.h"
37 #include "util/strtod.h"
41 #include <amdgpu_drm.h>
42 #include "amdgpu_id.h"
43 #include "winsys/amdgpu/radv_amdgpu_winsys_public.h"
44 #include "ac_llvm_util.h"
45 #include "vk_format.h"
48 #include "util/debug.h"
51 radv_device_get_cache_uuid(enum radeon_family family
, void *uuid
)
53 uint32_t mesa_timestamp
, llvm_timestamp
;
55 memset(uuid
, 0, VK_UUID_SIZE
);
56 if (!disk_cache_get_function_timestamp(radv_device_get_cache_uuid
, &mesa_timestamp
) ||
57 !disk_cache_get_function_timestamp(LLVMInitializeAMDGPUTargetInfo
, &llvm_timestamp
))
60 memcpy(uuid
, &mesa_timestamp
, 4);
61 memcpy((char*)uuid
+ 4, &llvm_timestamp
, 4);
62 memcpy((char*)uuid
+ 8, &f
, 2);
63 snprintf((char*)uuid
+ 10, VK_UUID_SIZE
- 10, "radv");
68 radv_get_driver_uuid(void *uuid
)
70 ac_compute_driver_uuid(uuid
, VK_UUID_SIZE
);
74 radv_get_device_uuid(struct radeon_info
*info
, void *uuid
)
76 ac_compute_device_uuid(info
, uuid
, VK_UUID_SIZE
);
79 static const VkExtensionProperties instance_extensions
[] = {
81 .extensionName
= VK_KHR_SURFACE_EXTENSION_NAME
,
84 #ifdef VK_USE_PLATFORM_XCB_KHR
86 .extensionName
= VK_KHR_XCB_SURFACE_EXTENSION_NAME
,
90 #ifdef VK_USE_PLATFORM_XLIB_KHR
92 .extensionName
= VK_KHR_XLIB_SURFACE_EXTENSION_NAME
,
96 #ifdef VK_USE_PLATFORM_WAYLAND_KHR
98 .extensionName
= VK_KHR_WAYLAND_SURFACE_EXTENSION_NAME
,
103 .extensionName
= VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME
,
107 .extensionName
= VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME
,
111 .extensionName
= VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME
,
116 static const VkExtensionProperties common_device_extensions
[] = {
118 .extensionName
= VK_KHR_DESCRIPTOR_UPDATE_TEMPLATE_EXTENSION_NAME
,
122 .extensionName
= VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME
,
126 .extensionName
= VK_KHR_MAINTENANCE1_EXTENSION_NAME
,
130 .extensionName
= VK_KHR_PUSH_DESCRIPTOR_EXTENSION_NAME
,
134 .extensionName
= VK_KHR_SAMPLER_MIRROR_CLAMP_TO_EDGE_EXTENSION_NAME
,
138 .extensionName
= VK_KHR_SWAPCHAIN_EXTENSION_NAME
,
142 .extensionName
= VK_AMD_DRAW_INDIRECT_COUNT_EXTENSION_NAME
,
146 .extensionName
= VK_KHR_SHADER_DRAW_PARAMETERS_EXTENSION_NAME
,
150 .extensionName
= VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME
,
154 .extensionName
= VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME
,
158 .extensionName
= VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME
,
162 .extensionName
= VK_KHR_EXTERNAL_MEMORY_FD_EXTENSION_NAME
,
166 .extensionName
= VK_KHR_STORAGE_BUFFER_STORAGE_CLASS_EXTENSION_NAME
,
170 .extensionName
= VK_KHR_VARIABLE_POINTERS_EXTENSION_NAME
,
174 .extensionName
= VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME
,
178 .extensionName
= VK_KHR_BIND_MEMORY_2_EXTENSION_NAME
,
182 .extensionName
= VK_KHR_MAINTENANCE2_EXTENSION_NAME
,
186 .extensionName
= VK_KHR_RELAXED_BLOCK_LAYOUT_EXTENSION_NAME
,
191 static const VkExtensionProperties rasterization_order_extension
[] ={
193 .extensionName
= VK_AMD_RASTERIZATION_ORDER_EXTENSION_NAME
,
198 static const VkExtensionProperties ext_sema_device_extensions
[] = {
200 .extensionName
= VK_KHR_EXTERNAL_SEMAPHORE_EXTENSION_NAME
,
204 .extensionName
= VK_KHR_EXTERNAL_SEMAPHORE_FD_EXTENSION_NAME
,
208 .extensionName
= VK_KHX_MULTIVIEW_EXTENSION_NAME
,
214 radv_extensions_register(struct radv_instance
*instance
,
215 struct radv_extensions
*extensions
,
216 const VkExtensionProperties
*new_ext
,
220 VkExtensionProperties
*new_ptr
;
222 assert(new_ext
&& num_ext
> 0);
225 return VK_ERROR_INITIALIZATION_FAILED
;
227 new_size
= (extensions
->num_ext
+ num_ext
) * sizeof(VkExtensionProperties
);
228 new_ptr
= vk_realloc(&instance
->alloc
, extensions
->ext_array
,
229 new_size
, 8, VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
231 /* Old array continues to be valid, update nothing */
233 return VK_ERROR_OUT_OF_HOST_MEMORY
;
235 memcpy(&new_ptr
[extensions
->num_ext
], new_ext
,
236 num_ext
* sizeof(VkExtensionProperties
));
237 extensions
->ext_array
= new_ptr
;
238 extensions
->num_ext
+= num_ext
;
244 radv_extensions_finish(struct radv_instance
*instance
,
245 struct radv_extensions
*extensions
)
250 radv_loge("Attemted to free invalid extension struct\n");
252 if (extensions
->ext_array
)
253 vk_free(&instance
->alloc
, extensions
->ext_array
);
257 is_extension_enabled(const VkExtensionProperties
*extensions
,
261 assert(extensions
&& name
);
263 for (uint32_t i
= 0; i
< num_ext
; i
++) {
264 if (strcmp(name
, extensions
[i
].extensionName
) == 0)
272 get_chip_name(enum radeon_family family
)
275 case CHIP_TAHITI
: return "AMD RADV TAHITI";
276 case CHIP_PITCAIRN
: return "AMD RADV PITCAIRN";
277 case CHIP_VERDE
: return "AMD RADV CAPE VERDE";
278 case CHIP_OLAND
: return "AMD RADV OLAND";
279 case CHIP_HAINAN
: return "AMD RADV HAINAN";
280 case CHIP_BONAIRE
: return "AMD RADV BONAIRE";
281 case CHIP_KAVERI
: return "AMD RADV KAVERI";
282 case CHIP_KABINI
: return "AMD RADV KABINI";
283 case CHIP_HAWAII
: return "AMD RADV HAWAII";
284 case CHIP_MULLINS
: return "AMD RADV MULLINS";
285 case CHIP_TONGA
: return "AMD RADV TONGA";
286 case CHIP_ICELAND
: return "AMD RADV ICELAND";
287 case CHIP_CARRIZO
: return "AMD RADV CARRIZO";
288 case CHIP_FIJI
: return "AMD RADV FIJI";
289 case CHIP_POLARIS10
: return "AMD RADV POLARIS10";
290 case CHIP_POLARIS11
: return "AMD RADV POLARIS11";
291 case CHIP_POLARIS12
: return "AMD RADV POLARIS12";
292 case CHIP_STONEY
: return "AMD RADV STONEY";
293 case CHIP_VEGA10
: return "AMD RADV VEGA";
294 case CHIP_RAVEN
: return "AMD RADV RAVEN";
295 default: return "AMD RADV unknown";
300 radv_physical_device_init(struct radv_physical_device
*device
,
301 struct radv_instance
*instance
,
302 drmDevicePtr drm_device
)
304 const char *path
= drm_device
->nodes
[DRM_NODE_RENDER
];
306 drmVersionPtr version
;
309 fd
= open(path
, O_RDWR
| O_CLOEXEC
);
311 return VK_ERROR_INCOMPATIBLE_DRIVER
;
313 version
= drmGetVersion(fd
);
316 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
317 "failed to get version %s: %m", path
);
320 if (strcmp(version
->name
, "amdgpu")) {
321 drmFreeVersion(version
);
323 return VK_ERROR_INCOMPATIBLE_DRIVER
;
325 drmFreeVersion(version
);
327 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
328 device
->instance
= instance
;
329 assert(strlen(path
) < ARRAY_SIZE(device
->path
));
330 strncpy(device
->path
, path
, ARRAY_SIZE(device
->path
));
332 device
->ws
= radv_amdgpu_winsys_create(fd
, instance
->debug_flags
,
333 instance
->perftest_flags
);
335 result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
339 device
->local_fd
= fd
;
340 device
->ws
->query_info(device
->ws
, &device
->rad_info
);
341 result
= radv_init_wsi(device
);
342 if (result
!= VK_SUCCESS
) {
343 device
->ws
->destroy(device
->ws
);
347 if (radv_device_get_cache_uuid(device
->rad_info
.family
, device
->cache_uuid
)) {
348 radv_finish_wsi(device
);
349 device
->ws
->destroy(device
->ws
);
350 result
= vk_errorf(VK_ERROR_INITIALIZATION_FAILED
,
351 "cannot generate UUID");
355 /* These flags affect shader compilation. */
356 uint64_t shader_env_flags
=
357 (device
->instance
->perftest_flags
& RADV_PERFTEST_SISCHED
? 0x1 : 0) |
358 (device
->instance
->debug_flags
& RADV_DEBUG_UNSAFE_MATH
? 0x2 : 0);
360 /* The gpu id is already embeded in the uuid so we just pass "radv"
361 * when creating the cache.
363 char buf
[VK_UUID_SIZE
+ 1];
364 disk_cache_format_hex_id(buf
, device
->cache_uuid
, VK_UUID_SIZE
);
365 device
->disk_cache
= disk_cache_create("radv", buf
, shader_env_flags
);
367 result
= radv_extensions_register(instance
,
369 common_device_extensions
,
370 ARRAY_SIZE(common_device_extensions
));
371 if (result
!= VK_SUCCESS
)
374 if (device
->rad_info
.chip_class
>= VI
&& device
->rad_info
.max_se
>= 2) {
375 result
= radv_extensions_register(instance
,
377 rasterization_order_extension
,
378 ARRAY_SIZE(rasterization_order_extension
));
379 if (result
!= VK_SUCCESS
)
383 if (device
->rad_info
.has_syncobj
) {
384 result
= radv_extensions_register(instance
,
386 ext_sema_device_extensions
,
387 ARRAY_SIZE(ext_sema_device_extensions
));
388 if (result
!= VK_SUCCESS
)
392 fprintf(stderr
, "WARNING: radv is not a conformant vulkan implementation, testing use only.\n");
393 device
->name
= get_chip_name(device
->rad_info
.family
);
395 radv_get_driver_uuid(&device
->device_uuid
);
396 radv_get_device_uuid(&device
->rad_info
, &device
->device_uuid
);
398 if (device
->rad_info
.family
== CHIP_STONEY
||
399 device
->rad_info
.chip_class
>= GFX9
) {
400 device
->has_rbplus
= true;
401 device
->rbplus_allowed
= device
->rad_info
.family
== CHIP_STONEY
;
404 /* The mere presense of CLEAR_STATE in the IB causes random GPU hangs
407 device
->has_clear_state
= device
->rad_info
.chip_class
>= CIK
;
417 radv_physical_device_finish(struct radv_physical_device
*device
)
419 radv_extensions_finish(device
->instance
, &device
->extensions
);
420 radv_finish_wsi(device
);
421 device
->ws
->destroy(device
->ws
);
422 disk_cache_destroy(device
->disk_cache
);
423 close(device
->local_fd
);
427 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
428 VkSystemAllocationScope allocationScope
)
434 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
435 size_t align
, VkSystemAllocationScope allocationScope
)
437 return realloc(pOriginal
, size
);
441 default_free_func(void *pUserData
, void *pMemory
)
446 static const VkAllocationCallbacks default_alloc
= {
448 .pfnAllocation
= default_alloc_func
,
449 .pfnReallocation
= default_realloc_func
,
450 .pfnFree
= default_free_func
,
453 static const struct debug_control radv_debug_options
[] = {
454 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
455 {"nodcc", RADV_DEBUG_NO_DCC
},
456 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
457 {"nocache", RADV_DEBUG_NO_CACHE
},
458 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
459 {"nohiz", RADV_DEBUG_NO_HIZ
},
460 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
461 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
462 {"allbos", RADV_DEBUG_ALL_BOS
},
463 {"noibs", RADV_DEBUG_NO_IBS
},
464 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
465 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
466 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
467 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
472 radv_get_debug_option_name(int id
)
474 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
475 return radv_debug_options
[id
].string
;
478 static const struct debug_control radv_perftest_options
[] = {
479 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
480 {"sisched", RADV_PERFTEST_SISCHED
},
485 radv_get_perftest_option_name(int id
)
487 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
488 return radv_perftest_options
[id
].string
;
491 VkResult
radv_CreateInstance(
492 const VkInstanceCreateInfo
* pCreateInfo
,
493 const VkAllocationCallbacks
* pAllocator
,
494 VkInstance
* pInstance
)
496 struct radv_instance
*instance
;
498 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
500 uint32_t client_version
;
501 if (pCreateInfo
->pApplicationInfo
&&
502 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
503 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
505 client_version
= VK_MAKE_VERSION(1, 0, 0);
508 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
509 client_version
> VK_MAKE_VERSION(1, 0, 0xfff)) {
510 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
511 "Client requested version %d.%d.%d",
512 VK_VERSION_MAJOR(client_version
),
513 VK_VERSION_MINOR(client_version
),
514 VK_VERSION_PATCH(client_version
));
517 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
518 if (!is_extension_enabled(instance_extensions
,
519 ARRAY_SIZE(instance_extensions
),
520 pCreateInfo
->ppEnabledExtensionNames
[i
]))
521 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
524 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
525 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
527 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
529 memset(instance
, 0, sizeof(*instance
));
531 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
534 instance
->alloc
= *pAllocator
;
536 instance
->alloc
= default_alloc
;
538 instance
->apiVersion
= client_version
;
539 instance
->physicalDeviceCount
= -1;
543 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
545 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
548 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
549 radv_perftest_options
);
551 *pInstance
= radv_instance_to_handle(instance
);
556 void radv_DestroyInstance(
557 VkInstance _instance
,
558 const VkAllocationCallbacks
* pAllocator
)
560 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
565 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
566 radv_physical_device_finish(instance
->physicalDevices
+ i
);
569 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
573 vk_free(&instance
->alloc
, instance
);
577 radv_enumerate_devices(struct radv_instance
*instance
)
579 /* TODO: Check for more devices ? */
580 drmDevicePtr devices
[8];
581 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
584 instance
->physicalDeviceCount
= 0;
586 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
588 return VK_ERROR_INCOMPATIBLE_DRIVER
;
590 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
591 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
592 devices
[i
]->bustype
== DRM_BUS_PCI
&&
593 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
595 result
= radv_physical_device_init(instance
->physicalDevices
+
596 instance
->physicalDeviceCount
,
599 if (result
== VK_SUCCESS
)
600 ++instance
->physicalDeviceCount
;
601 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
605 drmFreeDevices(devices
, max_devices
);
610 VkResult
radv_EnumeratePhysicalDevices(
611 VkInstance _instance
,
612 uint32_t* pPhysicalDeviceCount
,
613 VkPhysicalDevice
* pPhysicalDevices
)
615 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
618 if (instance
->physicalDeviceCount
< 0) {
619 result
= radv_enumerate_devices(instance
);
620 if (result
!= VK_SUCCESS
&&
621 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
625 if (!pPhysicalDevices
) {
626 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
628 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
629 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
630 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
633 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
637 void radv_GetPhysicalDeviceFeatures(
638 VkPhysicalDevice physicalDevice
,
639 VkPhysicalDeviceFeatures
* pFeatures
)
641 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
642 bool is_gfx9
= pdevice
->rad_info
.chip_class
>= GFX9
;
643 memset(pFeatures
, 0, sizeof(*pFeatures
));
645 *pFeatures
= (VkPhysicalDeviceFeatures
) {
646 .robustBufferAccess
= true,
647 .fullDrawIndexUint32
= true,
648 .imageCubeArray
= true,
649 .independentBlend
= true,
650 .geometryShader
= !is_gfx9
,
651 .tessellationShader
= !is_gfx9
,
652 .sampleRateShading
= true,
653 .dualSrcBlend
= true,
655 .multiDrawIndirect
= true,
656 .drawIndirectFirstInstance
= true,
658 .depthBiasClamp
= true,
659 .fillModeNonSolid
= true,
664 .multiViewport
= true,
665 .samplerAnisotropy
= true,
666 .textureCompressionETC2
= false,
667 .textureCompressionASTC_LDR
= false,
668 .textureCompressionBC
= true,
669 .occlusionQueryPrecise
= true,
670 .pipelineStatisticsQuery
= true,
671 .vertexPipelineStoresAndAtomics
= true,
672 .fragmentStoresAndAtomics
= true,
673 .shaderTessellationAndGeometryPointSize
= true,
674 .shaderImageGatherExtended
= true,
675 .shaderStorageImageExtendedFormats
= true,
676 .shaderStorageImageMultisample
= false,
677 .shaderUniformBufferArrayDynamicIndexing
= true,
678 .shaderSampledImageArrayDynamicIndexing
= true,
679 .shaderStorageBufferArrayDynamicIndexing
= true,
680 .shaderStorageImageArrayDynamicIndexing
= true,
681 .shaderStorageImageReadWithoutFormat
= true,
682 .shaderStorageImageWriteWithoutFormat
= true,
683 .shaderClipDistance
= true,
684 .shaderCullDistance
= true,
685 .shaderFloat64
= true,
687 .shaderInt16
= false,
688 .sparseBinding
= true,
689 .variableMultisampleRate
= true,
690 .inheritedQueries
= true,
694 void radv_GetPhysicalDeviceFeatures2KHR(
695 VkPhysicalDevice physicalDevice
,
696 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
698 vk_foreach_struct(ext
, pFeatures
->pNext
) {
699 switch (ext
->sType
) {
700 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
701 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
702 features
->variablePointersStorageBuffer
= true;
703 features
->variablePointers
= false;
706 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHX
: {
707 VkPhysicalDeviceMultiviewFeaturesKHX
*features
= (VkPhysicalDeviceMultiviewFeaturesKHX
*)ext
;
708 features
->multiview
= true;
709 features
->multiviewGeometryShader
= true;
710 features
->multiviewTessellationShader
= true;
717 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
720 void radv_GetPhysicalDeviceProperties(
721 VkPhysicalDevice physicalDevice
,
722 VkPhysicalDeviceProperties
* pProperties
)
724 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
725 VkSampleCountFlags sample_counts
= 0xf;
727 /* make sure that the entire descriptor set is addressable with a signed
728 * 32-bit int. So the sum of all limits scaled by descriptor size has to
729 * be at most 2 GiB. the combined image & samples object count as one of
730 * both. This limit is for the pipeline layout, not for the set layout, but
731 * there is no set limit, so we just set a pipeline limit. I don't think
732 * any app is going to hit this soon. */
733 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
734 (32 /* uniform buffer, 32 due to potential space wasted on alignement */ +
735 32 /* storage buffer, 32 due to potential space wasted on alignement */ +
736 32 /* sampler, largest when combined with image */ +
737 64 /* sampled image */ +
738 64 /* storage image */);
740 VkPhysicalDeviceLimits limits
= {
741 .maxImageDimension1D
= (1 << 14),
742 .maxImageDimension2D
= (1 << 14),
743 .maxImageDimension3D
= (1 << 11),
744 .maxImageDimensionCube
= (1 << 14),
745 .maxImageArrayLayers
= (1 << 11),
746 .maxTexelBufferElements
= 128 * 1024 * 1024,
747 .maxUniformBufferRange
= UINT32_MAX
,
748 .maxStorageBufferRange
= UINT32_MAX
,
749 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
750 .maxMemoryAllocationCount
= UINT32_MAX
,
751 .maxSamplerAllocationCount
= 64 * 1024,
752 .bufferImageGranularity
= 64, /* A cache line */
753 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
754 .maxBoundDescriptorSets
= MAX_SETS
,
755 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
756 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
757 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
758 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
759 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
760 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
761 .maxPerStageResources
= max_descriptor_set_size
,
762 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
763 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
764 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
765 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
766 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
767 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
768 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
769 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
770 .maxVertexInputAttributes
= 32,
771 .maxVertexInputBindings
= 32,
772 .maxVertexInputAttributeOffset
= 2047,
773 .maxVertexInputBindingStride
= 2048,
774 .maxVertexOutputComponents
= 128,
775 .maxTessellationGenerationLevel
= 64,
776 .maxTessellationPatchSize
= 32,
777 .maxTessellationControlPerVertexInputComponents
= 128,
778 .maxTessellationControlPerVertexOutputComponents
= 128,
779 .maxTessellationControlPerPatchOutputComponents
= 120,
780 .maxTessellationControlTotalOutputComponents
= 4096,
781 .maxTessellationEvaluationInputComponents
= 128,
782 .maxTessellationEvaluationOutputComponents
= 128,
783 .maxGeometryShaderInvocations
= 127,
784 .maxGeometryInputComponents
= 64,
785 .maxGeometryOutputComponents
= 128,
786 .maxGeometryOutputVertices
= 256,
787 .maxGeometryTotalOutputComponents
= 1024,
788 .maxFragmentInputComponents
= 128,
789 .maxFragmentOutputAttachments
= 8,
790 .maxFragmentDualSrcAttachments
= 1,
791 .maxFragmentCombinedOutputResources
= 8,
792 .maxComputeSharedMemorySize
= 32768,
793 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
794 .maxComputeWorkGroupInvocations
= 2048,
795 .maxComputeWorkGroupSize
= {
800 .subPixelPrecisionBits
= 4 /* FIXME */,
801 .subTexelPrecisionBits
= 4 /* FIXME */,
802 .mipmapPrecisionBits
= 4 /* FIXME */,
803 .maxDrawIndexedIndexValue
= UINT32_MAX
,
804 .maxDrawIndirectCount
= UINT32_MAX
,
805 .maxSamplerLodBias
= 16,
806 .maxSamplerAnisotropy
= 16,
807 .maxViewports
= MAX_VIEWPORTS
,
808 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
809 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
810 .viewportSubPixelBits
= 13, /* We take a float? */
811 .minMemoryMapAlignment
= 4096, /* A page */
812 .minTexelBufferOffsetAlignment
= 1,
813 .minUniformBufferOffsetAlignment
= 4,
814 .minStorageBufferOffsetAlignment
= 4,
815 .minTexelOffset
= -32,
816 .maxTexelOffset
= 31,
817 .minTexelGatherOffset
= -32,
818 .maxTexelGatherOffset
= 31,
819 .minInterpolationOffset
= -2,
820 .maxInterpolationOffset
= 2,
821 .subPixelInterpolationOffsetBits
= 8,
822 .maxFramebufferWidth
= (1 << 14),
823 .maxFramebufferHeight
= (1 << 14),
824 .maxFramebufferLayers
= (1 << 10),
825 .framebufferColorSampleCounts
= sample_counts
,
826 .framebufferDepthSampleCounts
= sample_counts
,
827 .framebufferStencilSampleCounts
= sample_counts
,
828 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
829 .maxColorAttachments
= MAX_RTS
,
830 .sampledImageColorSampleCounts
= sample_counts
,
831 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
832 .sampledImageDepthSampleCounts
= sample_counts
,
833 .sampledImageStencilSampleCounts
= sample_counts
,
834 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
835 .maxSampleMaskWords
= 1,
836 .timestampComputeAndGraphics
= true,
837 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
838 .maxClipDistances
= 8,
839 .maxCullDistances
= 8,
840 .maxCombinedClipAndCullDistances
= 8,
841 .discreteQueuePriorities
= 1,
842 .pointSizeRange
= { 0.125, 255.875 },
843 .lineWidthRange
= { 0.0, 7.9921875 },
844 .pointSizeGranularity
= (1.0 / 8.0),
845 .lineWidthGranularity
= (1.0 / 128.0),
846 .strictLines
= false, /* FINISHME */
847 .standardSampleLocations
= true,
848 .optimalBufferCopyOffsetAlignment
= 128,
849 .optimalBufferCopyRowPitchAlignment
= 128,
850 .nonCoherentAtomSize
= 64,
853 *pProperties
= (VkPhysicalDeviceProperties
) {
854 .apiVersion
= VK_MAKE_VERSION(1, 0, 42),
855 .driverVersion
= vk_get_driver_version(),
856 .vendorID
= ATI_VENDOR_ID
,
857 .deviceID
= pdevice
->rad_info
.pci_id
,
858 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
860 .sparseProperties
= {0},
863 strcpy(pProperties
->deviceName
, pdevice
->name
);
864 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
867 void radv_GetPhysicalDeviceProperties2KHR(
868 VkPhysicalDevice physicalDevice
,
869 VkPhysicalDeviceProperties2KHR
*pProperties
)
871 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
872 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
874 vk_foreach_struct(ext
, pProperties
->pNext
) {
875 switch (ext
->sType
) {
876 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
877 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
878 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
879 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
882 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
883 VkPhysicalDeviceIDPropertiesKHR
*properties
= (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
884 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
885 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
886 properties
->deviceLUIDValid
= false;
889 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHX
: {
890 VkPhysicalDeviceMultiviewPropertiesKHX
*properties
= (VkPhysicalDeviceMultiviewPropertiesKHX
*)ext
;
891 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
892 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
895 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR
: {
896 VkPhysicalDevicePointClippingPropertiesKHR
*properties
=
897 (VkPhysicalDevicePointClippingPropertiesKHR
*)ext
;
898 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR
;
907 static void radv_get_physical_device_queue_family_properties(
908 struct radv_physical_device
* pdevice
,
910 VkQueueFamilyProperties
** pQueueFamilyProperties
)
912 int num_queue_families
= 1;
914 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
915 pdevice
->rad_info
.chip_class
>= CIK
&&
916 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
917 num_queue_families
++;
919 if (pQueueFamilyProperties
== NULL
) {
920 *pCount
= num_queue_families
;
929 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
930 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
931 VK_QUEUE_COMPUTE_BIT
|
932 VK_QUEUE_TRANSFER_BIT
|
933 VK_QUEUE_SPARSE_BINDING_BIT
,
935 .timestampValidBits
= 64,
936 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
941 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
942 pdevice
->rad_info
.chip_class
>= CIK
&&
943 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
945 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
946 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
947 VK_QUEUE_TRANSFER_BIT
|
948 VK_QUEUE_SPARSE_BINDING_BIT
,
949 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
950 .timestampValidBits
= 64,
951 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
959 void radv_GetPhysicalDeviceQueueFamilyProperties(
960 VkPhysicalDevice physicalDevice
,
962 VkQueueFamilyProperties
* pQueueFamilyProperties
)
964 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
965 if (!pQueueFamilyProperties
) {
966 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
969 VkQueueFamilyProperties
*properties
[] = {
970 pQueueFamilyProperties
+ 0,
971 pQueueFamilyProperties
+ 1,
972 pQueueFamilyProperties
+ 2,
974 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
975 assert(*pCount
<= 3);
978 void radv_GetPhysicalDeviceQueueFamilyProperties2KHR(
979 VkPhysicalDevice physicalDevice
,
981 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
983 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
984 if (!pQueueFamilyProperties
) {
985 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
988 VkQueueFamilyProperties
*properties
[] = {
989 &pQueueFamilyProperties
[0].queueFamilyProperties
,
990 &pQueueFamilyProperties
[1].queueFamilyProperties
,
991 &pQueueFamilyProperties
[2].queueFamilyProperties
,
993 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
994 assert(*pCount
<= 3);
997 void radv_GetPhysicalDeviceMemoryProperties(
998 VkPhysicalDevice physicalDevice
,
999 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
1001 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1003 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
1005 pMemoryProperties
->memoryTypeCount
= RADV_MEM_TYPE_COUNT
;
1006 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_VRAM
] = (VkMemoryType
) {
1007 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
1008 .heapIndex
= RADV_MEM_HEAP_VRAM
,
1010 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_GTT_WRITE_COMBINE
] = (VkMemoryType
) {
1011 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
1012 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
1013 .heapIndex
= RADV_MEM_HEAP_GTT
,
1015 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_VRAM_CPU_ACCESS
] = (VkMemoryType
) {
1016 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
1017 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
1018 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
1019 .heapIndex
= RADV_MEM_HEAP_VRAM_CPU_ACCESS
,
1021 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_GTT_CACHED
] = (VkMemoryType
) {
1022 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
1023 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
1024 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
1025 .heapIndex
= RADV_MEM_HEAP_GTT
,
1028 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
1029 uint64_t visible_vram_size
= MIN2(physical_device
->rad_info
.vram_size
,
1030 physical_device
->rad_info
.vram_vis_size
);
1032 pMemoryProperties
->memoryHeapCount
= RADV_MEM_HEAP_COUNT
;
1033 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_VRAM
] = (VkMemoryHeap
) {
1034 .size
= physical_device
->rad_info
.vram_size
-
1036 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
1038 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_VRAM_CPU_ACCESS
] = (VkMemoryHeap
) {
1039 .size
= visible_vram_size
,
1040 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
1042 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_GTT
] = (VkMemoryHeap
) {
1043 .size
= physical_device
->rad_info
.gart_size
,
1048 void radv_GetPhysicalDeviceMemoryProperties2KHR(
1049 VkPhysicalDevice physicalDevice
,
1050 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
1052 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1053 &pMemoryProperties
->memoryProperties
);
1057 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1058 int queue_family_index
, int idx
)
1060 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1061 queue
->device
= device
;
1062 queue
->queue_family_index
= queue_family_index
;
1063 queue
->queue_idx
= idx
;
1065 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
);
1067 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1073 radv_queue_finish(struct radv_queue
*queue
)
1076 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1078 if (queue
->initial_full_flush_preamble_cs
)
1079 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1080 if (queue
->initial_preamble_cs
)
1081 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1082 if (queue
->continue_preamble_cs
)
1083 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1084 if (queue
->descriptor_bo
)
1085 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1086 if (queue
->scratch_bo
)
1087 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1088 if (queue
->esgs_ring_bo
)
1089 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1090 if (queue
->gsvs_ring_bo
)
1091 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1092 if (queue
->tess_factor_ring_bo
)
1093 queue
->device
->ws
->buffer_destroy(queue
->tess_factor_ring_bo
);
1094 if (queue
->tess_offchip_ring_bo
)
1095 queue
->device
->ws
->buffer_destroy(queue
->tess_offchip_ring_bo
);
1096 if (queue
->compute_scratch_bo
)
1097 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1101 radv_device_init_gs_info(struct radv_device
*device
)
1103 switch (device
->physical_device
->rad_info
.family
) {
1112 device
->gs_table_depth
= 16;
1121 case CHIP_POLARIS10
:
1122 case CHIP_POLARIS11
:
1123 case CHIP_POLARIS12
:
1126 device
->gs_table_depth
= 32;
1129 unreachable("unknown GPU");
1133 VkResult
radv_CreateDevice(
1134 VkPhysicalDevice physicalDevice
,
1135 const VkDeviceCreateInfo
* pCreateInfo
,
1136 const VkAllocationCallbacks
* pAllocator
,
1139 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1141 struct radv_device
*device
;
1143 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1144 if (!is_extension_enabled(physical_device
->extensions
.ext_array
,
1145 physical_device
->extensions
.num_ext
,
1146 pCreateInfo
->ppEnabledExtensionNames
[i
]))
1147 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1150 /* Check enabled features */
1151 if (pCreateInfo
->pEnabledFeatures
) {
1152 VkPhysicalDeviceFeatures supported_features
;
1153 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1154 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1155 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1156 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1157 for (uint32_t i
= 0; i
< num_features
; i
++) {
1158 if (enabled_feature
[i
] && !supported_feature
[i
])
1159 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1163 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
1165 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1167 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1169 memset(device
, 0, sizeof(*device
));
1171 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1172 device
->instance
= physical_device
->instance
;
1173 device
->physical_device
= physical_device
;
1175 device
->ws
= physical_device
->ws
;
1177 device
->alloc
= *pAllocator
;
1179 device
->alloc
= physical_device
->instance
->alloc
;
1181 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1182 list_inithead(&device
->shader_slabs
);
1184 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1185 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1186 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1188 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1189 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1190 if (!device
->queues
[qfi
]) {
1191 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1195 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1197 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1199 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1200 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
], qfi
, q
);
1201 if (result
!= VK_SUCCESS
)
1206 #if HAVE_LLVM < 0x0400
1207 device
->llvm_supports_spill
= false;
1209 device
->llvm_supports_spill
= true;
1212 /* The maximum number of scratch waves. Scratch space isn't divided
1213 * evenly between CUs. The number is only a function of the number of CUs.
1214 * We can decrease the constant to decrease the scratch buffer size.
1216 * sctx->scratch_waves must be >= the maximum posible size of
1217 * 1 threadgroup, so that the hw doesn't hang from being unable
1220 * The recommended value is 4 per CU at most. Higher numbers don't
1221 * bring much benefit, but they still occupy chip resources (think
1222 * async compute). I've seen ~2% performance difference between 4 and 32.
1224 uint32_t max_threads_per_block
= 2048;
1225 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1226 max_threads_per_block
/ 64);
1228 radv_device_init_gs_info(device
);
1230 device
->tess_offchip_block_dw_size
=
1231 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1232 device
->has_distributed_tess
=
1233 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1234 device
->physical_device
->rad_info
.max_se
>= 2;
1236 if (getenv("RADV_TRACE_FILE")) {
1237 if (!radv_init_trace(device
))
1241 result
= radv_device_init_meta(device
);
1242 if (result
!= VK_SUCCESS
)
1245 radv_device_init_msaa(device
);
1247 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1248 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1250 case RADV_QUEUE_GENERAL
:
1251 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1252 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1253 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1255 case RADV_QUEUE_COMPUTE
:
1256 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1257 radeon_emit(device
->empty_cs
[family
], 0);
1260 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1263 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1264 cik_create_gfx_config(device
);
1266 VkPipelineCacheCreateInfo ci
;
1267 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1270 ci
.pInitialData
= NULL
;
1271 ci
.initialDataSize
= 0;
1273 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1275 if (result
!= VK_SUCCESS
)
1278 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1280 *pDevice
= radv_device_to_handle(device
);
1284 if (device
->trace_bo
)
1285 device
->ws
->buffer_destroy(device
->trace_bo
);
1287 if (device
->gfx_init
)
1288 device
->ws
->buffer_destroy(device
->gfx_init
);
1290 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1291 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1292 radv_queue_finish(&device
->queues
[i
][q
]);
1293 if (device
->queue_count
[i
])
1294 vk_free(&device
->alloc
, device
->queues
[i
]);
1297 vk_free(&device
->alloc
, device
);
1301 void radv_DestroyDevice(
1303 const VkAllocationCallbacks
* pAllocator
)
1305 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1310 if (device
->trace_bo
)
1311 device
->ws
->buffer_destroy(device
->trace_bo
);
1313 if (device
->gfx_init
)
1314 device
->ws
->buffer_destroy(device
->gfx_init
);
1316 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1317 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1318 radv_queue_finish(&device
->queues
[i
][q
]);
1319 if (device
->queue_count
[i
])
1320 vk_free(&device
->alloc
, device
->queues
[i
]);
1321 if (device
->empty_cs
[i
])
1322 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1324 radv_device_finish_meta(device
);
1326 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1327 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1329 radv_destroy_shader_slabs(device
);
1331 vk_free(&device
->alloc
, device
);
1334 VkResult
radv_EnumerateInstanceExtensionProperties(
1335 const char* pLayerName
,
1336 uint32_t* pPropertyCount
,
1337 VkExtensionProperties
* pProperties
)
1339 if (pProperties
== NULL
) {
1340 *pPropertyCount
= ARRAY_SIZE(instance_extensions
);
1344 *pPropertyCount
= MIN2(*pPropertyCount
, ARRAY_SIZE(instance_extensions
));
1345 typed_memcpy(pProperties
, instance_extensions
, *pPropertyCount
);
1347 if (*pPropertyCount
< ARRAY_SIZE(instance_extensions
))
1348 return VK_INCOMPLETE
;
1353 VkResult
radv_EnumerateDeviceExtensionProperties(
1354 VkPhysicalDevice physicalDevice
,
1355 const char* pLayerName
,
1356 uint32_t* pPropertyCount
,
1357 VkExtensionProperties
* pProperties
)
1359 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1361 if (pProperties
== NULL
) {
1362 *pPropertyCount
= pdevice
->extensions
.num_ext
;
1366 *pPropertyCount
= MIN2(*pPropertyCount
, pdevice
->extensions
.num_ext
);
1367 typed_memcpy(pProperties
, pdevice
->extensions
.ext_array
, *pPropertyCount
);
1369 if (*pPropertyCount
< pdevice
->extensions
.num_ext
)
1370 return VK_INCOMPLETE
;
1375 VkResult
radv_EnumerateInstanceLayerProperties(
1376 uint32_t* pPropertyCount
,
1377 VkLayerProperties
* pProperties
)
1379 if (pProperties
== NULL
) {
1380 *pPropertyCount
= 0;
1384 /* None supported at this time */
1385 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1388 VkResult
radv_EnumerateDeviceLayerProperties(
1389 VkPhysicalDevice physicalDevice
,
1390 uint32_t* pPropertyCount
,
1391 VkLayerProperties
* pProperties
)
1393 if (pProperties
== NULL
) {
1394 *pPropertyCount
= 0;
1398 /* None supported at this time */
1399 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1402 void radv_GetDeviceQueue(
1404 uint32_t queueFamilyIndex
,
1405 uint32_t queueIndex
,
1408 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1410 *pQueue
= radv_queue_to_handle(&device
->queues
[queueFamilyIndex
][queueIndex
]);
1414 fill_geom_tess_rings(struct radv_queue
*queue
,
1416 bool add_sample_positions
,
1417 uint32_t esgs_ring_size
,
1418 struct radeon_winsys_bo
*esgs_ring_bo
,
1419 uint32_t gsvs_ring_size
,
1420 struct radeon_winsys_bo
*gsvs_ring_bo
,
1421 uint32_t tess_factor_ring_size
,
1422 struct radeon_winsys_bo
*tess_factor_ring_bo
,
1423 uint32_t tess_offchip_ring_size
,
1424 struct radeon_winsys_bo
*tess_offchip_ring_bo
)
1426 uint64_t esgs_va
= 0, gsvs_va
= 0;
1427 uint64_t tess_factor_va
= 0, tess_offchip_va
= 0;
1428 uint32_t *desc
= &map
[4];
1431 esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
1433 gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
1434 if (tess_factor_ring_bo
)
1435 tess_factor_va
= radv_buffer_get_va(tess_factor_ring_bo
);
1436 if (tess_offchip_ring_bo
)
1437 tess_offchip_va
= radv_buffer_get_va(tess_offchip_ring_bo
);
1439 /* stride 0, num records - size, add tid, swizzle, elsize4,
1442 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1443 S_008F04_STRIDE(0) |
1444 S_008F04_SWIZZLE_ENABLE(true);
1445 desc
[2] = esgs_ring_size
;
1446 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1447 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1448 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1449 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1450 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1451 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1452 S_008F0C_ELEMENT_SIZE(1) |
1453 S_008F0C_INDEX_STRIDE(3) |
1454 S_008F0C_ADD_TID_ENABLE(true);
1457 /* GS entry for ES->GS ring */
1458 /* stride 0, num records - size, elsize0,
1461 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1462 S_008F04_STRIDE(0) |
1463 S_008F04_SWIZZLE_ENABLE(false);
1464 desc
[2] = esgs_ring_size
;
1465 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1466 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1467 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1468 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1469 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1470 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1471 S_008F0C_ELEMENT_SIZE(0) |
1472 S_008F0C_INDEX_STRIDE(0) |
1473 S_008F0C_ADD_TID_ENABLE(false);
1476 /* VS entry for GS->VS ring */
1477 /* stride 0, num records - size, elsize0,
1480 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1481 S_008F04_STRIDE(0) |
1482 S_008F04_SWIZZLE_ENABLE(false);
1483 desc
[2] = gsvs_ring_size
;
1484 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1485 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1486 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1487 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1488 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1489 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1490 S_008F0C_ELEMENT_SIZE(0) |
1491 S_008F0C_INDEX_STRIDE(0) |
1492 S_008F0C_ADD_TID_ENABLE(false);
1495 /* stride gsvs_itemsize, num records 64
1496 elsize 4, index stride 16 */
1497 /* shader will patch stride and desc[2] */
1499 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1500 S_008F04_STRIDE(0) |
1501 S_008F04_SWIZZLE_ENABLE(true);
1503 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1504 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1505 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1506 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1507 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1508 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1509 S_008F0C_ELEMENT_SIZE(1) |
1510 S_008F0C_INDEX_STRIDE(1) |
1511 S_008F0C_ADD_TID_ENABLE(true);
1514 desc
[0] = tess_factor_va
;
1515 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_factor_va
>> 32) |
1516 S_008F04_STRIDE(0) |
1517 S_008F04_SWIZZLE_ENABLE(false);
1518 desc
[2] = tess_factor_ring_size
;
1519 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1520 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1521 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1522 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1523 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1524 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1525 S_008F0C_ELEMENT_SIZE(0) |
1526 S_008F0C_INDEX_STRIDE(0) |
1527 S_008F0C_ADD_TID_ENABLE(false);
1530 desc
[0] = tess_offchip_va
;
1531 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
1532 S_008F04_STRIDE(0) |
1533 S_008F04_SWIZZLE_ENABLE(false);
1534 desc
[2] = tess_offchip_ring_size
;
1535 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1536 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1537 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1538 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1539 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1540 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1541 S_008F0C_ELEMENT_SIZE(0) |
1542 S_008F0C_INDEX_STRIDE(0) |
1543 S_008F0C_ADD_TID_ENABLE(false);
1546 /* add sample positions after all rings */
1547 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
1549 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
1551 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
1553 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
1555 memcpy(desc
, queue
->device
->sample_locations_16x
, 128);
1559 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
1561 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
1562 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
1563 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
1564 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1565 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1566 device
->physical_device
->rad_info
.max_se
;
1567 unsigned offchip_granularity
;
1568 unsigned hs_offchip_param
;
1569 switch (device
->tess_offchip_block_dw_size
) {
1574 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1577 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1581 switch (device
->physical_device
->rad_info
.chip_class
) {
1583 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
1589 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
1593 *max_offchip_buffers_p
= max_offchip_buffers
;
1594 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1595 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
1596 --max_offchip_buffers
;
1598 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1599 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1602 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1604 return hs_offchip_param
;
1608 radv_get_preamble_cs(struct radv_queue
*queue
,
1609 uint32_t scratch_size
,
1610 uint32_t compute_scratch_size
,
1611 uint32_t esgs_ring_size
,
1612 uint32_t gsvs_ring_size
,
1613 bool needs_tess_rings
,
1614 bool needs_sample_positions
,
1615 struct radeon_winsys_cs
**initial_full_flush_preamble_cs
,
1616 struct radeon_winsys_cs
**initial_preamble_cs
,
1617 struct radeon_winsys_cs
**continue_preamble_cs
)
1619 struct radeon_winsys_bo
*scratch_bo
= NULL
;
1620 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
1621 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
1622 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
1623 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
1624 struct radeon_winsys_bo
*tess_factor_ring_bo
= NULL
;
1625 struct radeon_winsys_bo
*tess_offchip_ring_bo
= NULL
;
1626 struct radeon_winsys_cs
*dest_cs
[3] = {0};
1627 bool add_tess_rings
= false, add_sample_positions
= false;
1628 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
1629 unsigned max_offchip_buffers
;
1630 unsigned hs_offchip_param
= 0;
1631 if (!queue
->has_tess_rings
) {
1632 if (needs_tess_rings
)
1633 add_tess_rings
= true;
1635 if (!queue
->has_sample_positions
) {
1636 if (needs_sample_positions
)
1637 add_sample_positions
= true;
1639 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
1640 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
1641 &max_offchip_buffers
);
1642 tess_offchip_ring_size
= max_offchip_buffers
*
1643 queue
->device
->tess_offchip_block_dw_size
* 4;
1645 if (scratch_size
<= queue
->scratch_size
&&
1646 compute_scratch_size
<= queue
->compute_scratch_size
&&
1647 esgs_ring_size
<= queue
->esgs_ring_size
&&
1648 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
1649 !add_tess_rings
&& !add_sample_positions
&&
1650 queue
->initial_preamble_cs
) {
1651 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
1652 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1653 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1654 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1655 *continue_preamble_cs
= NULL
;
1659 if (scratch_size
> queue
->scratch_size
) {
1660 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1664 RADEON_FLAG_NO_CPU_ACCESS
);
1668 scratch_bo
= queue
->scratch_bo
;
1670 if (compute_scratch_size
> queue
->compute_scratch_size
) {
1671 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1672 compute_scratch_size
,
1675 RADEON_FLAG_NO_CPU_ACCESS
);
1676 if (!compute_scratch_bo
)
1680 compute_scratch_bo
= queue
->compute_scratch_bo
;
1682 if (esgs_ring_size
> queue
->esgs_ring_size
) {
1683 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1687 RADEON_FLAG_NO_CPU_ACCESS
);
1691 esgs_ring_bo
= queue
->esgs_ring_bo
;
1692 esgs_ring_size
= queue
->esgs_ring_size
;
1695 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
1696 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1700 RADEON_FLAG_NO_CPU_ACCESS
);
1704 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
1705 gsvs_ring_size
= queue
->gsvs_ring_size
;
1708 if (add_tess_rings
) {
1709 tess_factor_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1710 tess_factor_ring_size
,
1713 RADEON_FLAG_NO_CPU_ACCESS
);
1714 if (!tess_factor_ring_bo
)
1716 tess_offchip_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1717 tess_offchip_ring_size
,
1720 RADEON_FLAG_NO_CPU_ACCESS
);
1721 if (!tess_offchip_ring_bo
)
1724 tess_factor_ring_bo
= queue
->tess_factor_ring_bo
;
1725 tess_offchip_ring_bo
= queue
->tess_offchip_ring_bo
;
1728 if (scratch_bo
!= queue
->scratch_bo
||
1729 esgs_ring_bo
!= queue
->esgs_ring_bo
||
1730 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
1731 tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
||
1732 tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
|| add_sample_positions
) {
1734 if (gsvs_ring_bo
|| esgs_ring_bo
||
1735 tess_factor_ring_bo
|| tess_offchip_ring_bo
|| add_sample_positions
) {
1736 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
1737 if (add_sample_positions
)
1738 size
+= 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
1740 else if (scratch_bo
)
1741 size
= 8; /* 2 dword */
1743 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1747 RADEON_FLAG_CPU_ACCESS
);
1751 descriptor_bo
= queue
->descriptor_bo
;
1753 for(int i
= 0; i
< 3; ++i
) {
1754 struct radeon_winsys_cs
*cs
= NULL
;
1755 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
1756 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
1763 queue
->device
->ws
->cs_add_buffer(cs
, scratch_bo
, 8);
1766 queue
->device
->ws
->cs_add_buffer(cs
, esgs_ring_bo
, 8);
1769 queue
->device
->ws
->cs_add_buffer(cs
, gsvs_ring_bo
, 8);
1771 if (tess_factor_ring_bo
)
1772 queue
->device
->ws
->cs_add_buffer(cs
, tess_factor_ring_bo
, 8);
1774 if (tess_offchip_ring_bo
)
1775 queue
->device
->ws
->cs_add_buffer(cs
, tess_offchip_ring_bo
, 8);
1778 queue
->device
->ws
->cs_add_buffer(cs
, descriptor_bo
, 8);
1780 if (descriptor_bo
!= queue
->descriptor_bo
) {
1781 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
1784 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
1785 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1786 S_008F04_SWIZZLE_ENABLE(1);
1787 map
[0] = scratch_va
;
1791 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_factor_ring_bo
|| tess_offchip_ring_bo
||
1792 add_sample_positions
)
1793 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
1794 esgs_ring_size
, esgs_ring_bo
,
1795 gsvs_ring_size
, gsvs_ring_bo
,
1796 tess_factor_ring_size
, tess_factor_ring_bo
,
1797 tess_offchip_ring_size
, tess_offchip_ring_bo
);
1799 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
1802 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_factor_ring_bo
|| tess_offchip_ring_bo
) {
1803 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1804 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
1805 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1806 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
1809 if (esgs_ring_bo
|| gsvs_ring_bo
) {
1810 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1811 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
1812 radeon_emit(cs
, esgs_ring_size
>> 8);
1813 radeon_emit(cs
, gsvs_ring_size
>> 8);
1815 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
1816 radeon_emit(cs
, esgs_ring_size
>> 8);
1817 radeon_emit(cs
, gsvs_ring_size
>> 8);
1821 if (tess_factor_ring_bo
) {
1822 uint64_t tf_va
= radv_buffer_get_va(tess_factor_ring_bo
);
1823 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1824 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
1825 S_030938_SIZE(tess_factor_ring_size
/ 4));
1826 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
1828 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
1829 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
1832 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
, hs_offchip_param
);
1834 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
1835 S_008988_SIZE(tess_factor_ring_size
/ 4));
1836 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
1838 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
1843 if (descriptor_bo
) {
1844 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
1845 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
1846 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
1847 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
1848 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
1849 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
1851 uint64_t va
= radv_buffer_get_va(descriptor_bo
);
1853 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
1854 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
1855 radeon_emit(cs
, va
);
1856 radeon_emit(cs
, va
>> 32);
1860 if (compute_scratch_bo
) {
1861 uint64_t scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
1862 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1863 S_008F04_SWIZZLE_ENABLE(1);
1865 queue
->device
->ws
->cs_add_buffer(cs
, compute_scratch_bo
, 8);
1867 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
1868 radeon_emit(cs
, scratch_va
);
1869 radeon_emit(cs
, rsrc1
);
1873 si_cs_emit_cache_flush(cs
,
1875 queue
->device
->physical_device
->rad_info
.chip_class
,
1877 queue
->queue_family_index
== RING_COMPUTE
&&
1878 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
1879 (queue
->queue_family_index
== RADV_QUEUE_COMPUTE
? RADV_CMD_FLAG_CS_PARTIAL_FLUSH
: (RADV_CMD_FLAG_CS_PARTIAL_FLUSH
| RADV_CMD_FLAG_PS_PARTIAL_FLUSH
)) |
1880 RADV_CMD_FLAG_INV_ICACHE
|
1881 RADV_CMD_FLAG_INV_SMEM_L1
|
1882 RADV_CMD_FLAG_INV_VMEM_L1
|
1883 RADV_CMD_FLAG_INV_GLOBAL_L2
);
1884 } else if (i
== 1) {
1885 si_cs_emit_cache_flush(cs
,
1887 queue
->device
->physical_device
->rad_info
.chip_class
,
1889 queue
->queue_family_index
== RING_COMPUTE
&&
1890 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
1891 RADV_CMD_FLAG_INV_ICACHE
|
1892 RADV_CMD_FLAG_INV_SMEM_L1
|
1893 RADV_CMD_FLAG_INV_VMEM_L1
|
1894 RADV_CMD_FLAG_INV_GLOBAL_L2
);
1897 if (!queue
->device
->ws
->cs_finalize(cs
))
1901 if (queue
->initial_full_flush_preamble_cs
)
1902 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1904 if (queue
->initial_preamble_cs
)
1905 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1907 if (queue
->continue_preamble_cs
)
1908 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1910 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
1911 queue
->initial_preamble_cs
= dest_cs
[1];
1912 queue
->continue_preamble_cs
= dest_cs
[2];
1914 if (scratch_bo
!= queue
->scratch_bo
) {
1915 if (queue
->scratch_bo
)
1916 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1917 queue
->scratch_bo
= scratch_bo
;
1918 queue
->scratch_size
= scratch_size
;
1921 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
1922 if (queue
->compute_scratch_bo
)
1923 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1924 queue
->compute_scratch_bo
= compute_scratch_bo
;
1925 queue
->compute_scratch_size
= compute_scratch_size
;
1928 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
1929 if (queue
->esgs_ring_bo
)
1930 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1931 queue
->esgs_ring_bo
= esgs_ring_bo
;
1932 queue
->esgs_ring_size
= esgs_ring_size
;
1935 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
1936 if (queue
->gsvs_ring_bo
)
1937 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1938 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
1939 queue
->gsvs_ring_size
= gsvs_ring_size
;
1942 if (tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
) {
1943 queue
->tess_factor_ring_bo
= tess_factor_ring_bo
;
1946 if (tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
) {
1947 queue
->tess_offchip_ring_bo
= tess_offchip_ring_bo
;
1948 queue
->has_tess_rings
= true;
1951 if (descriptor_bo
!= queue
->descriptor_bo
) {
1952 if (queue
->descriptor_bo
)
1953 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1955 queue
->descriptor_bo
= descriptor_bo
;
1958 if (add_sample_positions
)
1959 queue
->has_sample_positions
= true;
1961 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
1962 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1963 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1964 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1965 *continue_preamble_cs
= NULL
;
1968 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
1970 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
1971 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
1972 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
1973 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
1974 queue
->device
->ws
->buffer_destroy(scratch_bo
);
1975 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
1976 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
1977 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
1978 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
1979 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
1980 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
1981 if (tess_factor_ring_bo
&& tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
)
1982 queue
->device
->ws
->buffer_destroy(tess_factor_ring_bo
);
1983 if (tess_offchip_ring_bo
&& tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
)
1984 queue
->device
->ws
->buffer_destroy(tess_offchip_ring_bo
);
1985 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
1988 static VkResult
radv_alloc_sem_counts(struct radv_winsys_sem_counts
*counts
,
1990 const VkSemaphore
*sems
,
1993 int syncobj_idx
= 0, sem_idx
= 0;
1997 for (uint32_t i
= 0; i
< num_sems
; i
++) {
1998 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2000 if (sem
->temp_syncobj
|| sem
->syncobj
)
2001 counts
->syncobj_count
++;
2003 counts
->sem_count
++;
2006 if (counts
->syncobj_count
) {
2007 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2008 if (!counts
->syncobj
)
2009 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2012 if (counts
->sem_count
) {
2013 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2015 free(counts
->syncobj
);
2016 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2020 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2021 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2023 if (sem
->temp_syncobj
) {
2024 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2026 /* after we wait on a temp import - drop it */
2027 sem
->temp_syncobj
= 0;
2030 else if (sem
->syncobj
)
2031 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2034 counts
->sem
[sem_idx
++] = sem
->sem
;
2041 void radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2043 free(sem_info
->wait
.syncobj
);
2044 free(sem_info
->wait
.sem
);
2045 free(sem_info
->signal
.syncobj
);
2046 free(sem_info
->signal
.sem
);
2049 VkResult
radv_alloc_sem_info(struct radv_winsys_sem_info
*sem_info
,
2051 const VkSemaphore
*wait_sems
,
2052 int num_signal_sems
,
2053 const VkSemaphore
*signal_sems
)
2056 memset(sem_info
, 0, sizeof(*sem_info
));
2058 ret
= radv_alloc_sem_counts(&sem_info
->wait
, num_wait_sems
, wait_sems
, true);
2061 ret
= radv_alloc_sem_counts(&sem_info
->signal
, num_signal_sems
, signal_sems
, false);
2063 radv_free_sem_info(sem_info
);
2065 /* caller can override these */
2066 sem_info
->cs_emit_wait
= true;
2067 sem_info
->cs_emit_signal
= true;
2071 VkResult
radv_QueueSubmit(
2073 uint32_t submitCount
,
2074 const VkSubmitInfo
* pSubmits
,
2077 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2078 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2079 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2080 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2082 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
2083 uint32_t scratch_size
= 0;
2084 uint32_t compute_scratch_size
= 0;
2085 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2086 struct radeon_winsys_cs
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2088 bool fence_emitted
= false;
2089 bool tess_rings_needed
= false;
2090 bool sample_positions_needed
= false;
2092 /* Do this first so failing to allocate scratch buffers can't result in
2093 * partially executed submissions. */
2094 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2095 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2096 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2097 pSubmits
[i
].pCommandBuffers
[j
]);
2099 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2100 compute_scratch_size
= MAX2(compute_scratch_size
,
2101 cmd_buffer
->compute_scratch_size_needed
);
2102 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2103 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2104 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2105 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2109 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2110 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2111 sample_positions_needed
, &initial_flush_preamble_cs
,
2112 &initial_preamble_cs
, &continue_preamble_cs
);
2113 if (result
!= VK_SUCCESS
)
2116 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2117 struct radeon_winsys_cs
**cs_array
;
2118 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2119 bool can_patch
= true;
2121 struct radv_winsys_sem_info sem_info
;
2123 result
= radv_alloc_sem_info(&sem_info
,
2124 pSubmits
[i
].waitSemaphoreCount
,
2125 pSubmits
[i
].pWaitSemaphores
,
2126 pSubmits
[i
].signalSemaphoreCount
,
2127 pSubmits
[i
].pSignalSemaphores
);
2128 if (result
!= VK_SUCCESS
)
2131 if (!pSubmits
[i
].commandBufferCount
) {
2132 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2133 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2134 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2139 radv_loge("failed to submit CS %d\n", i
);
2142 fence_emitted
= true;
2144 radv_free_sem_info(&sem_info
);
2148 cs_array
= malloc(sizeof(struct radeon_winsys_cs
*) *
2149 (pSubmits
[i
].commandBufferCount
));
2151 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2152 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2153 pSubmits
[i
].pCommandBuffers
[j
]);
2154 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2156 cs_array
[j
] = cmd_buffer
->cs
;
2157 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2161 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2162 struct radeon_winsys_cs
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2163 advance
= MIN2(max_cs_submission
,
2164 pSubmits
[i
].commandBufferCount
- j
);
2166 if (queue
->device
->trace_bo
)
2167 *queue
->device
->trace_id_ptr
= 0;
2169 sem_info
.cs_emit_wait
= j
== 0;
2170 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2172 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2173 advance
, initial_preamble
, continue_preamble_cs
,
2175 can_patch
, base_fence
);
2178 radv_loge("failed to submit CS %d\n", i
);
2181 fence_emitted
= true;
2182 if (queue
->device
->trace_bo
) {
2183 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2187 radv_free_sem_info(&sem_info
);
2192 if (!fence_emitted
) {
2193 struct radv_winsys_sem_info sem_info
= {0};
2194 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2195 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2196 1, NULL
, NULL
, &sem_info
,
2199 fence
->submitted
= true;
2205 VkResult
radv_QueueWaitIdle(
2208 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2210 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2211 radv_queue_family_to_ring(queue
->queue_family_index
),
2216 VkResult
radv_DeviceWaitIdle(
2219 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2221 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2222 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2223 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2229 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
2230 VkInstance instance
,
2233 return radv_lookup_entrypoint(pName
);
2236 /* The loader wants us to expose a second GetInstanceProcAddr function
2237 * to work around certain LD_PRELOAD issues seen in apps.
2240 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2241 VkInstance instance
,
2245 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2246 VkInstance instance
,
2249 return radv_GetInstanceProcAddr(instance
, pName
);
2252 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
2256 return radv_lookup_entrypoint(pName
);
2259 bool radv_get_memory_fd(struct radv_device
*device
,
2260 struct radv_device_memory
*memory
,
2263 struct radeon_bo_metadata metadata
;
2265 if (memory
->image
) {
2266 radv_init_metadata(device
, memory
->image
, &metadata
);
2267 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
2270 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
2274 VkResult
radv_AllocateMemory(
2276 const VkMemoryAllocateInfo
* pAllocateInfo
,
2277 const VkAllocationCallbacks
* pAllocator
,
2278 VkDeviceMemory
* pMem
)
2280 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2281 struct radv_device_memory
*mem
;
2283 enum radeon_bo_domain domain
;
2286 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2288 if (pAllocateInfo
->allocationSize
== 0) {
2289 /* Apparently, this is allowed */
2290 *pMem
= VK_NULL_HANDLE
;
2294 const VkImportMemoryFdInfoKHR
*import_info
=
2295 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2296 const VkMemoryDedicatedAllocateInfoKHR
*dedicate_info
=
2297 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2299 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2300 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2302 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2304 if (dedicate_info
) {
2305 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
2306 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
2313 assert(import_info
->handleType
==
2314 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
2315 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
2318 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2321 close(import_info
->fd
);
2326 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
2327 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
2328 pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_CACHED
)
2329 domain
= RADEON_DOMAIN_GTT
;
2331 domain
= RADEON_DOMAIN_VRAM
;
2333 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_VRAM
)
2334 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
2336 flags
|= RADEON_FLAG_CPU_ACCESS
;
2338 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
2339 flags
|= RADEON_FLAG_GTT_WC
;
2341 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
2345 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2348 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
2350 *pMem
= radv_device_memory_to_handle(mem
);
2355 vk_free2(&device
->alloc
, pAllocator
, mem
);
2360 void radv_FreeMemory(
2362 VkDeviceMemory _mem
,
2363 const VkAllocationCallbacks
* pAllocator
)
2365 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2366 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
2371 device
->ws
->buffer_destroy(mem
->bo
);
2374 vk_free2(&device
->alloc
, pAllocator
, mem
);
2377 VkResult
radv_MapMemory(
2379 VkDeviceMemory _memory
,
2380 VkDeviceSize offset
,
2382 VkMemoryMapFlags flags
,
2385 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2386 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2393 *ppData
= device
->ws
->buffer_map(mem
->bo
);
2399 return VK_ERROR_MEMORY_MAP_FAILED
;
2402 void radv_UnmapMemory(
2404 VkDeviceMemory _memory
)
2406 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2407 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2412 device
->ws
->buffer_unmap(mem
->bo
);
2415 VkResult
radv_FlushMappedMemoryRanges(
2417 uint32_t memoryRangeCount
,
2418 const VkMappedMemoryRange
* pMemoryRanges
)
2423 VkResult
radv_InvalidateMappedMemoryRanges(
2425 uint32_t memoryRangeCount
,
2426 const VkMappedMemoryRange
* pMemoryRanges
)
2431 void radv_GetBufferMemoryRequirements(
2434 VkMemoryRequirements
* pMemoryRequirements
)
2436 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2438 pMemoryRequirements
->memoryTypeBits
= (1u << RADV_MEM_TYPE_COUNT
) - 1;
2440 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2441 pMemoryRequirements
->alignment
= 4096;
2443 pMemoryRequirements
->alignment
= 16;
2445 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
2448 void radv_GetBufferMemoryRequirements2KHR(
2450 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
2451 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2453 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
2454 &pMemoryRequirements
->memoryRequirements
);
2456 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2457 switch (ext
->sType
) {
2458 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2459 VkMemoryDedicatedRequirementsKHR
*req
=
2460 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2461 req
->requiresDedicatedAllocation
= false;
2462 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2471 void radv_GetImageMemoryRequirements(
2474 VkMemoryRequirements
* pMemoryRequirements
)
2476 RADV_FROM_HANDLE(radv_image
, image
, _image
);
2478 pMemoryRequirements
->memoryTypeBits
= (1u << RADV_MEM_TYPE_COUNT
) - 1;
2480 pMemoryRequirements
->size
= image
->size
;
2481 pMemoryRequirements
->alignment
= image
->alignment
;
2484 void radv_GetImageMemoryRequirements2KHR(
2486 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
2487 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2489 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
2490 &pMemoryRequirements
->memoryRequirements
);
2492 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
2494 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2495 switch (ext
->sType
) {
2496 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2497 VkMemoryDedicatedRequirementsKHR
*req
=
2498 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2499 req
->requiresDedicatedAllocation
= image
->shareable
;
2500 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2509 void radv_GetImageSparseMemoryRequirements(
2512 uint32_t* pSparseMemoryRequirementCount
,
2513 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
2518 void radv_GetImageSparseMemoryRequirements2KHR(
2520 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
2521 uint32_t* pSparseMemoryRequirementCount
,
2522 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
2527 void radv_GetDeviceMemoryCommitment(
2529 VkDeviceMemory memory
,
2530 VkDeviceSize
* pCommittedMemoryInBytes
)
2532 *pCommittedMemoryInBytes
= 0;
2535 VkResult
radv_BindBufferMemory2KHR(VkDevice device
,
2536 uint32_t bindInfoCount
,
2537 const VkBindBufferMemoryInfoKHR
*pBindInfos
)
2539 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2540 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2541 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
2544 buffer
->bo
= mem
->bo
;
2545 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
2553 VkResult
radv_BindBufferMemory(
2556 VkDeviceMemory memory
,
2557 VkDeviceSize memoryOffset
)
2559 const VkBindBufferMemoryInfoKHR info
= {
2560 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2563 .memoryOffset
= memoryOffset
2566 return radv_BindBufferMemory2KHR(device
, 1, &info
);
2569 VkResult
radv_BindImageMemory2KHR(VkDevice device
,
2570 uint32_t bindInfoCount
,
2571 const VkBindImageMemoryInfoKHR
*pBindInfos
)
2573 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2574 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2575 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
2578 image
->bo
= mem
->bo
;
2579 image
->offset
= pBindInfos
[i
].memoryOffset
;
2589 VkResult
radv_BindImageMemory(
2592 VkDeviceMemory memory
,
2593 VkDeviceSize memoryOffset
)
2595 const VkBindImageMemoryInfoKHR info
= {
2596 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2599 .memoryOffset
= memoryOffset
2602 return radv_BindImageMemory2KHR(device
, 1, &info
);
2607 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
2608 const VkSparseBufferMemoryBindInfo
*bind
)
2610 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
2612 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
2613 struct radv_device_memory
*mem
= NULL
;
2615 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
2616 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
2618 device
->ws
->buffer_virtual_bind(buffer
->bo
,
2619 bind
->pBinds
[i
].resourceOffset
,
2620 bind
->pBinds
[i
].size
,
2621 mem
? mem
->bo
: NULL
,
2622 bind
->pBinds
[i
].memoryOffset
);
2627 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
2628 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
2630 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
2632 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
2633 struct radv_device_memory
*mem
= NULL
;
2635 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
2636 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
2638 device
->ws
->buffer_virtual_bind(image
->bo
,
2639 bind
->pBinds
[i
].resourceOffset
,
2640 bind
->pBinds
[i
].size
,
2641 mem
? mem
->bo
: NULL
,
2642 bind
->pBinds
[i
].memoryOffset
);
2646 VkResult
radv_QueueBindSparse(
2648 uint32_t bindInfoCount
,
2649 const VkBindSparseInfo
* pBindInfo
,
2652 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2653 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2654 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2655 bool fence_emitted
= false;
2657 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2658 struct radv_winsys_sem_info sem_info
;
2659 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
2660 radv_sparse_buffer_bind_memory(queue
->device
,
2661 pBindInfo
[i
].pBufferBinds
+ j
);
2664 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
2665 radv_sparse_image_opaque_bind_memory(queue
->device
,
2666 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
2670 result
= radv_alloc_sem_info(&sem_info
,
2671 pBindInfo
[i
].waitSemaphoreCount
,
2672 pBindInfo
[i
].pWaitSemaphores
,
2673 pBindInfo
[i
].signalSemaphoreCount
,
2674 pBindInfo
[i
].pSignalSemaphores
);
2675 if (result
!= VK_SUCCESS
)
2678 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
2679 queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2680 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2684 fence_emitted
= true;
2686 fence
->submitted
= true;
2689 radv_free_sem_info(&sem_info
);
2693 if (fence
&& !fence_emitted
) {
2694 fence
->signalled
= true;
2700 VkResult
radv_CreateFence(
2702 const VkFenceCreateInfo
* pCreateInfo
,
2703 const VkAllocationCallbacks
* pAllocator
,
2706 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2707 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
2709 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2712 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2714 memset(fence
, 0, sizeof(*fence
));
2715 fence
->submitted
= false;
2716 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
2717 fence
->fence
= device
->ws
->create_fence();
2718 if (!fence
->fence
) {
2719 vk_free2(&device
->alloc
, pAllocator
, fence
);
2720 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2723 *pFence
= radv_fence_to_handle(fence
);
2728 void radv_DestroyFence(
2731 const VkAllocationCallbacks
* pAllocator
)
2733 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2734 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2738 device
->ws
->destroy_fence(fence
->fence
);
2739 vk_free2(&device
->alloc
, pAllocator
, fence
);
2742 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
2744 uint64_t current_time
;
2747 clock_gettime(CLOCK_MONOTONIC
, &tv
);
2748 current_time
= tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
2750 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
2752 return current_time
+ timeout
;
2755 VkResult
radv_WaitForFences(
2757 uint32_t fenceCount
,
2758 const VkFence
* pFences
,
2762 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2763 timeout
= radv_get_absolute_timeout(timeout
);
2765 if (!waitAll
&& fenceCount
> 1) {
2766 fprintf(stderr
, "radv: WaitForFences without waitAll not implemented yet\n");
2769 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
2770 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
2771 bool expired
= false;
2773 if (fence
->signalled
)
2776 if (!fence
->submitted
)
2779 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
2783 fence
->signalled
= true;
2789 VkResult
radv_ResetFences(VkDevice device
,
2790 uint32_t fenceCount
,
2791 const VkFence
*pFences
)
2793 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
2794 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
2795 fence
->submitted
= fence
->signalled
= false;
2801 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
2803 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2804 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2806 if (fence
->signalled
)
2808 if (!fence
->submitted
)
2809 return VK_NOT_READY
;
2811 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
2812 return VK_NOT_READY
;
2818 // Queue semaphore functions
2820 VkResult
radv_CreateSemaphore(
2822 const VkSemaphoreCreateInfo
* pCreateInfo
,
2823 const VkAllocationCallbacks
* pAllocator
,
2824 VkSemaphore
* pSemaphore
)
2826 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2827 const VkExportSemaphoreCreateInfoKHR
*export
=
2828 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO_KHR
);
2829 VkExternalSemaphoreHandleTypeFlagsKHR handleTypes
=
2830 export
? export
->handleTypes
: 0;
2832 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
2834 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2836 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2838 sem
->temp_syncobj
= 0;
2839 /* create a syncobject if we are going to export this semaphore */
2841 assert (device
->physical_device
->rad_info
.has_syncobj
);
2842 assert (handleTypes
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
2843 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
2845 vk_free2(&device
->alloc
, pAllocator
, sem
);
2846 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2850 sem
->sem
= device
->ws
->create_sem(device
->ws
);
2852 vk_free2(&device
->alloc
, pAllocator
, sem
);
2853 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2858 *pSemaphore
= radv_semaphore_to_handle(sem
);
2862 void radv_DestroySemaphore(
2864 VkSemaphore _semaphore
,
2865 const VkAllocationCallbacks
* pAllocator
)
2867 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2868 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
2873 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
2875 device
->ws
->destroy_sem(sem
->sem
);
2876 vk_free2(&device
->alloc
, pAllocator
, sem
);
2879 VkResult
radv_CreateEvent(
2881 const VkEventCreateInfo
* pCreateInfo
,
2882 const VkAllocationCallbacks
* pAllocator
,
2885 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2886 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
2888 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2891 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2893 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
2895 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
);
2897 vk_free2(&device
->alloc
, pAllocator
, event
);
2898 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2901 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
2903 *pEvent
= radv_event_to_handle(event
);
2908 void radv_DestroyEvent(
2911 const VkAllocationCallbacks
* pAllocator
)
2913 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2914 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2918 device
->ws
->buffer_destroy(event
->bo
);
2919 vk_free2(&device
->alloc
, pAllocator
, event
);
2922 VkResult
radv_GetEventStatus(
2926 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2928 if (*event
->map
== 1)
2929 return VK_EVENT_SET
;
2930 return VK_EVENT_RESET
;
2933 VkResult
radv_SetEvent(
2937 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2943 VkResult
radv_ResetEvent(
2947 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2953 VkResult
radv_CreateBuffer(
2955 const VkBufferCreateInfo
* pCreateInfo
,
2956 const VkAllocationCallbacks
* pAllocator
,
2959 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2960 struct radv_buffer
*buffer
;
2962 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2964 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
2965 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2967 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2969 buffer
->size
= pCreateInfo
->size
;
2970 buffer
->usage
= pCreateInfo
->usage
;
2973 buffer
->flags
= pCreateInfo
->flags
;
2975 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
2976 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
2977 align64(buffer
->size
, 4096),
2978 4096, 0, RADEON_FLAG_VIRTUAL
);
2980 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2981 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2985 *pBuffer
= radv_buffer_to_handle(buffer
);
2990 void radv_DestroyBuffer(
2993 const VkAllocationCallbacks
* pAllocator
)
2995 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2996 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
3001 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
3002 device
->ws
->buffer_destroy(buffer
->bo
);
3004 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3007 static inline unsigned
3008 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
3011 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3013 return image
->surface
.u
.legacy
.tiling_index
[level
];
3016 static uint32_t radv_surface_layer_count(struct radv_image_view
*iview
)
3018 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: iview
->layer_count
;
3022 radv_initialise_color_surface(struct radv_device
*device
,
3023 struct radv_color_buffer_info
*cb
,
3024 struct radv_image_view
*iview
)
3026 const struct vk_format_description
*desc
;
3027 unsigned ntype
, format
, swap
, endian
;
3028 unsigned blend_clamp
= 0, blend_bypass
= 0;
3030 const struct radeon_surf
*surf
= &iview
->image
->surface
;
3032 desc
= vk_format_description(iview
->vk_format
);
3034 memset(cb
, 0, sizeof(*cb
));
3036 /* Intensity is implemented as Red, so treat it that way. */
3037 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
3039 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3041 cb
->cb_color_base
= va
>> 8;
3043 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3044 struct gfx9_surf_meta_flags meta
;
3045 if (iview
->image
->dcc_offset
)
3046 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
3048 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
3050 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3051 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
3052 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
3053 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
3055 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
3056 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3058 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
3059 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
3061 cb
->cb_color_base
+= level_info
->offset
>> 8;
3062 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
3063 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3065 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
3066 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
3067 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
3069 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
3070 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
3071 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
3073 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
3074 cb
->micro_tile_mode
= iview
->image
->surface
.micro_tile_mode
;
3076 if (iview
->image
->fmask
.size
) {
3077 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3078 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
3079 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
3080 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
3082 /* This must be set for fast clear to work without FMASK. */
3083 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3084 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
3085 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
3086 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
3090 /* CMASK variables */
3091 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3092 va
+= iview
->image
->cmask
.offset
;
3093 cb
->cb_color_cmask
= va
>> 8;
3095 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3096 va
+= iview
->image
->dcc_offset
;
3097 cb
->cb_dcc_base
= va
>> 8;
3098 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
3100 uint32_t max_slice
= radv_surface_layer_count(iview
);
3101 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
3102 S_028C6C_SLICE_MAX(iview
->base_layer
+ max_slice
- 1);
3104 if (iview
->image
->info
.samples
> 1) {
3105 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
3107 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
3108 S_028C74_NUM_FRAGMENTS(log_samples
);
3111 if (iview
->image
->fmask
.size
) {
3112 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
3113 cb
->cb_color_fmask
= va
>> 8;
3114 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
3116 cb
->cb_color_fmask
= cb
->cb_color_base
;
3119 ntype
= radv_translate_color_numformat(iview
->vk_format
,
3121 vk_format_get_first_non_void_channel(iview
->vk_format
));
3122 format
= radv_translate_colorformat(iview
->vk_format
);
3123 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
3124 radv_finishme("Illegal color\n");
3125 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
3126 endian
= radv_colorformat_endian_swap(format
);
3128 /* blend clamp should be set for all NORM/SRGB types */
3129 if (ntype
== V_028C70_NUMBER_UNORM
||
3130 ntype
== V_028C70_NUMBER_SNORM
||
3131 ntype
== V_028C70_NUMBER_SRGB
)
3134 /* set blend bypass according to docs if SINT/UINT or
3135 8/24 COLOR variants */
3136 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
3137 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
3138 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
3143 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
3144 (format
== V_028C70_COLOR_8
||
3145 format
== V_028C70_COLOR_8_8
||
3146 format
== V_028C70_COLOR_8_8_8_8
))
3147 ->color_is_int8
= true;
3149 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
3150 S_028C70_COMP_SWAP(swap
) |
3151 S_028C70_BLEND_CLAMP(blend_clamp
) |
3152 S_028C70_BLEND_BYPASS(blend_bypass
) |
3153 S_028C70_SIMPLE_FLOAT(1) |
3154 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
3155 ntype
!= V_028C70_NUMBER_SNORM
&&
3156 ntype
!= V_028C70_NUMBER_SRGB
&&
3157 format
!= V_028C70_COLOR_8_24
&&
3158 format
!= V_028C70_COLOR_24_8
) |
3159 S_028C70_NUMBER_TYPE(ntype
) |
3160 S_028C70_ENDIAN(endian
);
3161 if ((iview
->image
->info
.samples
> 1) && iview
->image
->fmask
.size
) {
3162 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
3163 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
3164 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
3165 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
3169 if (iview
->image
->cmask
.size
&&
3170 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
3171 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
3173 if (radv_vi_dcc_enabled(iview
->image
, iview
->base_mip
))
3174 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
3176 if (device
->physical_device
->rad_info
.chip_class
>= VI
) {
3177 unsigned max_uncompressed_block_size
= 2;
3178 if (iview
->image
->info
.samples
> 1) {
3179 if (iview
->image
->surface
.bpe
== 1)
3180 max_uncompressed_block_size
= 0;
3181 else if (iview
->image
->surface
.bpe
== 2)
3182 max_uncompressed_block_size
= 1;
3185 cb
->cb_dcc_control
= S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
3186 S_028C78_INDEPENDENT_64B_BLOCKS(1);
3189 /* This must be set for fast clear to work without FMASK. */
3190 if (!iview
->image
->fmask
.size
&&
3191 device
->physical_device
->rad_info
.chip_class
== SI
) {
3192 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
3193 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
3196 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3197 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
3198 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
3200 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
3201 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
3202 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
3203 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
3204 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
3205 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
3207 cb
->gfx9_epitch
= S_0287A0_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3213 radv_initialise_ds_surface(struct radv_device
*device
,
3214 struct radv_ds_buffer_info
*ds
,
3215 struct radv_image_view
*iview
)
3217 unsigned level
= iview
->base_mip
;
3218 unsigned format
, stencil_format
;
3219 uint64_t va
, s_offs
, z_offs
;
3220 bool stencil_only
= false;
3221 memset(ds
, 0, sizeof(*ds
));
3222 switch (iview
->image
->vk_format
) {
3223 case VK_FORMAT_D24_UNORM_S8_UINT
:
3224 case VK_FORMAT_X8_D24_UNORM_PACK32
:
3225 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
3226 ds
->offset_scale
= 2.0f
;
3228 case VK_FORMAT_D16_UNORM
:
3229 case VK_FORMAT_D16_UNORM_S8_UINT
:
3230 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
3231 ds
->offset_scale
= 4.0f
;
3233 case VK_FORMAT_D32_SFLOAT
:
3234 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
3235 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
3236 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
3237 ds
->offset_scale
= 1.0f
;
3239 case VK_FORMAT_S8_UINT
:
3240 stencil_only
= true;
3246 format
= radv_translate_dbformat(iview
->image
->vk_format
);
3247 stencil_format
= iview
->image
->surface
.has_stencil
?
3248 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
3250 uint32_t max_slice
= radv_surface_layer_count(iview
);
3251 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
3252 S_028008_SLICE_MAX(iview
->base_layer
+ max_slice
- 1);
3254 ds
->db_htile_data_base
= 0;
3255 ds
->db_htile_surface
= 0;
3257 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3258 s_offs
= z_offs
= va
;
3260 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3261 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
3262 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
3264 ds
->db_z_info
= S_028038_FORMAT(format
) |
3265 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
3266 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3267 S_028038_MAXMIP(iview
->image
->info
.levels
- 1);
3268 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
3269 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
3271 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3272 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
3273 ds
->db_depth_view
|= S_028008_MIPID(level
);
3275 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
3276 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
3278 if (radv_htile_enabled(iview
->image
, level
)) {
3279 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
3281 if (iview
->image
->tc_compatible_htile
) {
3282 unsigned max_zplanes
= 4;
3284 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
3285 iview
->image
->info
.samples
> 1)
3288 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
+ 1) |
3289 S_028038_ITERATE_FLUSH(1);
3290 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
3293 if (!iview
->image
->surface
.has_stencil
)
3294 /* Use all of the htile_buffer for depth if there's no stencil. */
3295 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
3296 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3297 iview
->image
->htile_offset
;
3298 ds
->db_htile_data_base
= va
>> 8;
3299 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
3300 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
3301 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
3304 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
3307 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
3309 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
3310 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
3312 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!iview
->image
->tc_compatible_htile
);
3313 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
3314 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
3316 if (iview
->image
->info
.samples
> 1)
3317 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
3319 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
3320 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
3321 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
3322 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3323 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
3324 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
3325 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
3326 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
3329 tile_mode
= stencil_tile_mode
;
3331 ds
->db_depth_info
|=
3332 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
3333 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
3334 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
3335 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
3336 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
3337 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
3338 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
3339 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
3341 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
3342 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3343 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
3344 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
3346 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3349 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
3350 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
3351 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
3353 if (radv_htile_enabled(iview
->image
, level
)) {
3354 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
3356 if (!iview
->image
->surface
.has_stencil
&&
3357 !iview
->image
->tc_compatible_htile
)
3358 /* Use all of the htile_buffer for depth if there's no stencil. */
3359 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
3361 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3362 iview
->image
->htile_offset
;
3363 ds
->db_htile_data_base
= va
>> 8;
3364 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
3366 if (iview
->image
->tc_compatible_htile
) {
3367 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
3369 if (iview
->image
->info
.samples
<= 1)
3370 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(5);
3371 else if (iview
->image
->info
.samples
<= 4)
3372 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(3);
3374 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(2);
3379 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
3380 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
3383 VkResult
radv_CreateFramebuffer(
3385 const VkFramebufferCreateInfo
* pCreateInfo
,
3386 const VkAllocationCallbacks
* pAllocator
,
3387 VkFramebuffer
* pFramebuffer
)
3389 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3390 struct radv_framebuffer
*framebuffer
;
3392 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
3394 size_t size
= sizeof(*framebuffer
) +
3395 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
3396 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
3397 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3398 if (framebuffer
== NULL
)
3399 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3401 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
3402 framebuffer
->width
= pCreateInfo
->width
;
3403 framebuffer
->height
= pCreateInfo
->height
;
3404 framebuffer
->layers
= pCreateInfo
->layers
;
3405 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
3406 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
3407 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
3408 framebuffer
->attachments
[i
].attachment
= iview
;
3409 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
3410 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
3411 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
3412 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
3414 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
3415 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
3416 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_layer_count(iview
));
3419 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
3423 void radv_DestroyFramebuffer(
3426 const VkAllocationCallbacks
* pAllocator
)
3428 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3429 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
3433 vk_free2(&device
->alloc
, pAllocator
, fb
);
3436 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
3438 switch (address_mode
) {
3439 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
3440 return V_008F30_SQ_TEX_WRAP
;
3441 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
3442 return V_008F30_SQ_TEX_MIRROR
;
3443 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
3444 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
3445 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
3446 return V_008F30_SQ_TEX_CLAMP_BORDER
;
3447 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
3448 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
3450 unreachable("illegal tex wrap mode");
3456 radv_tex_compare(VkCompareOp op
)
3459 case VK_COMPARE_OP_NEVER
:
3460 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
3461 case VK_COMPARE_OP_LESS
:
3462 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
3463 case VK_COMPARE_OP_EQUAL
:
3464 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
3465 case VK_COMPARE_OP_LESS_OR_EQUAL
:
3466 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
3467 case VK_COMPARE_OP_GREATER
:
3468 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
3469 case VK_COMPARE_OP_NOT_EQUAL
:
3470 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
3471 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
3472 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
3473 case VK_COMPARE_OP_ALWAYS
:
3474 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
3476 unreachable("illegal compare mode");
3482 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
3485 case VK_FILTER_NEAREST
:
3486 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
3487 V_008F38_SQ_TEX_XY_FILTER_POINT
);
3488 case VK_FILTER_LINEAR
:
3489 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
3490 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
3491 case VK_FILTER_CUBIC_IMG
:
3493 fprintf(stderr
, "illegal texture filter");
3499 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
3502 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
3503 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
3504 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
3505 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
3507 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
3512 radv_tex_bordercolor(VkBorderColor bcolor
)
3515 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
3516 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
3517 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
3518 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
3519 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
3520 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
3521 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
3522 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
3523 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
3531 radv_tex_aniso_filter(unsigned filter
)
3545 radv_init_sampler(struct radv_device
*device
,
3546 struct radv_sampler
*sampler
,
3547 const VkSamplerCreateInfo
*pCreateInfo
)
3549 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
3550 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
3551 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
3552 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
3554 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
3555 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
3556 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
3557 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
3558 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
3559 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
3560 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
3561 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
3562 S_008F30_DISABLE_CUBE_WRAP(0) |
3563 S_008F30_COMPAT_MODE(is_vi
));
3564 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
3565 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
3566 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
3567 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
3568 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
3569 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
3570 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
3571 S_008F38_MIP_POINT_PRECLAMP(0) |
3572 S_008F38_DISABLE_LSB_CEIL(1) |
3573 S_008F38_FILTER_PREC_FIX(1) |
3574 S_008F38_ANISO_OVERRIDE(is_vi
));
3575 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
3576 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
3579 VkResult
radv_CreateSampler(
3581 const VkSamplerCreateInfo
* pCreateInfo
,
3582 const VkAllocationCallbacks
* pAllocator
,
3583 VkSampler
* pSampler
)
3585 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3586 struct radv_sampler
*sampler
;
3588 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
3590 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
3591 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3593 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3595 radv_init_sampler(device
, sampler
, pCreateInfo
);
3596 *pSampler
= radv_sampler_to_handle(sampler
);
3601 void radv_DestroySampler(
3604 const VkAllocationCallbacks
* pAllocator
)
3606 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3607 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
3611 vk_free2(&device
->alloc
, pAllocator
, sampler
);
3614 /* vk_icd.h does not declare this function, so we declare it here to
3615 * suppress Wmissing-prototypes.
3617 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
3618 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
3620 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
3621 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
3623 /* For the full details on loader interface versioning, see
3624 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
3625 * What follows is a condensed summary, to help you navigate the large and
3626 * confusing official doc.
3628 * - Loader interface v0 is incompatible with later versions. We don't
3631 * - In loader interface v1:
3632 * - The first ICD entrypoint called by the loader is
3633 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
3635 * - The ICD must statically expose no other Vulkan symbol unless it is
3636 * linked with -Bsymbolic.
3637 * - Each dispatchable Vulkan handle created by the ICD must be
3638 * a pointer to a struct whose first member is VK_LOADER_DATA. The
3639 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
3640 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
3641 * vkDestroySurfaceKHR(). The ICD must be capable of working with
3642 * such loader-managed surfaces.
3644 * - Loader interface v2 differs from v1 in:
3645 * - The first ICD entrypoint called by the loader is
3646 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
3647 * statically expose this entrypoint.
3649 * - Loader interface v3 differs from v2 in:
3650 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
3651 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
3652 * because the loader no longer does so.
3654 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
3658 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
3659 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
3662 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3663 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
3665 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
3667 /* We support only one handle type. */
3668 assert(pGetFdInfo
->handleType
==
3669 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
3671 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
3673 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
3677 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
3678 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
3680 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
3682 /* The valid usage section for this function says:
3684 * "handleType must not be one of the handle types defined as opaque."
3686 * Since we only handle opaque handles for now, there are no FD properties.
3688 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
3691 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
3692 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
3694 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3695 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
3696 uint32_t syncobj_handle
= 0;
3697 assert(pImportSemaphoreFdInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
3699 int ret
= device
->ws
->import_syncobj(device
->ws
, pImportSemaphoreFdInfo
->fd
, &syncobj_handle
);
3701 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
3703 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR
) {
3704 sem
->temp_syncobj
= syncobj_handle
;
3706 sem
->syncobj
= syncobj_handle
;
3708 close(pImportSemaphoreFdInfo
->fd
);
3712 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
3713 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
3716 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3717 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
3719 uint32_t syncobj_handle
;
3721 assert(pGetFdInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
3722 if (sem
->temp_syncobj
)
3723 syncobj_handle
= sem
->temp_syncobj
;
3725 syncobj_handle
= sem
->syncobj
;
3726 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
3728 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
3732 void radv_GetPhysicalDeviceExternalSemaphorePropertiesKHR(
3733 VkPhysicalDevice physicalDevice
,
3734 const VkPhysicalDeviceExternalSemaphoreInfoKHR
* pExternalSemaphoreInfo
,
3735 VkExternalSemaphorePropertiesKHR
* pExternalSemaphoreProperties
)
3737 if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
) {
3738 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
3739 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
3740 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
3741 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
3743 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
3744 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
3745 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;