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
;
412 radv_physical_device_finish(struct radv_physical_device
*device
)
414 radv_extensions_finish(device
->instance
, &device
->extensions
);
415 radv_finish_wsi(device
);
416 device
->ws
->destroy(device
->ws
);
417 disk_cache_destroy(device
->disk_cache
);
418 close(device
->local_fd
);
422 default_alloc_func(void *pUserData
, size_t size
, size_t align
,
423 VkSystemAllocationScope allocationScope
)
429 default_realloc_func(void *pUserData
, void *pOriginal
, size_t size
,
430 size_t align
, VkSystemAllocationScope allocationScope
)
432 return realloc(pOriginal
, size
);
436 default_free_func(void *pUserData
, void *pMemory
)
441 static const VkAllocationCallbacks default_alloc
= {
443 .pfnAllocation
= default_alloc_func
,
444 .pfnReallocation
= default_realloc_func
,
445 .pfnFree
= default_free_func
,
448 static const struct debug_control radv_debug_options
[] = {
449 {"nofastclears", RADV_DEBUG_NO_FAST_CLEARS
},
450 {"nodcc", RADV_DEBUG_NO_DCC
},
451 {"shaders", RADV_DEBUG_DUMP_SHADERS
},
452 {"nocache", RADV_DEBUG_NO_CACHE
},
453 {"shaderstats", RADV_DEBUG_DUMP_SHADER_STATS
},
454 {"nohiz", RADV_DEBUG_NO_HIZ
},
455 {"nocompute", RADV_DEBUG_NO_COMPUTE_QUEUE
},
456 {"unsafemath", RADV_DEBUG_UNSAFE_MATH
},
457 {"allbos", RADV_DEBUG_ALL_BOS
},
458 {"noibs", RADV_DEBUG_NO_IBS
},
459 {"spirv", RADV_DEBUG_DUMP_SPIRV
},
460 {"vmfaults", RADV_DEBUG_VM_FAULTS
},
461 {"zerovram", RADV_DEBUG_ZERO_VRAM
},
462 {"syncshaders", RADV_DEBUG_SYNC_SHADERS
},
467 radv_get_debug_option_name(int id
)
469 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
470 return radv_debug_options
[id
].string
;
473 static const struct debug_control radv_perftest_options
[] = {
474 {"nobatchchain", RADV_PERFTEST_NO_BATCHCHAIN
},
475 {"sisched", RADV_PERFTEST_SISCHED
},
480 radv_get_perftest_option_name(int id
)
482 assert(id
< ARRAY_SIZE(radv_debug_options
) - 1);
483 return radv_perftest_options
[id
].string
;
486 VkResult
radv_CreateInstance(
487 const VkInstanceCreateInfo
* pCreateInfo
,
488 const VkAllocationCallbacks
* pAllocator
,
489 VkInstance
* pInstance
)
491 struct radv_instance
*instance
;
493 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO
);
495 uint32_t client_version
;
496 if (pCreateInfo
->pApplicationInfo
&&
497 pCreateInfo
->pApplicationInfo
->apiVersion
!= 0) {
498 client_version
= pCreateInfo
->pApplicationInfo
->apiVersion
;
500 client_version
= VK_MAKE_VERSION(1, 0, 0);
503 if (VK_MAKE_VERSION(1, 0, 0) > client_version
||
504 client_version
> VK_MAKE_VERSION(1, 0, 0xfff)) {
505 return vk_errorf(VK_ERROR_INCOMPATIBLE_DRIVER
,
506 "Client requested version %d.%d.%d",
507 VK_VERSION_MAJOR(client_version
),
508 VK_VERSION_MINOR(client_version
),
509 VK_VERSION_PATCH(client_version
));
512 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
513 if (!is_extension_enabled(instance_extensions
,
514 ARRAY_SIZE(instance_extensions
),
515 pCreateInfo
->ppEnabledExtensionNames
[i
]))
516 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
519 instance
= vk_alloc2(&default_alloc
, pAllocator
, sizeof(*instance
), 8,
520 VK_SYSTEM_ALLOCATION_SCOPE_INSTANCE
);
522 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
524 memset(instance
, 0, sizeof(*instance
));
526 instance
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
529 instance
->alloc
= *pAllocator
;
531 instance
->alloc
= default_alloc
;
533 instance
->apiVersion
= client_version
;
534 instance
->physicalDeviceCount
= -1;
538 VG(VALGRIND_CREATE_MEMPOOL(instance
, 0, false));
540 instance
->debug_flags
= parse_debug_string(getenv("RADV_DEBUG"),
543 instance
->perftest_flags
= parse_debug_string(getenv("RADV_PERFTEST"),
544 radv_perftest_options
);
546 *pInstance
= radv_instance_to_handle(instance
);
551 void radv_DestroyInstance(
552 VkInstance _instance
,
553 const VkAllocationCallbacks
* pAllocator
)
555 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
560 for (int i
= 0; i
< instance
->physicalDeviceCount
; ++i
) {
561 radv_physical_device_finish(instance
->physicalDevices
+ i
);
564 VG(VALGRIND_DESTROY_MEMPOOL(instance
));
568 vk_free(&instance
->alloc
, instance
);
572 radv_enumerate_devices(struct radv_instance
*instance
)
574 /* TODO: Check for more devices ? */
575 drmDevicePtr devices
[8];
576 VkResult result
= VK_ERROR_INCOMPATIBLE_DRIVER
;
579 instance
->physicalDeviceCount
= 0;
581 max_devices
= drmGetDevices2(0, devices
, ARRAY_SIZE(devices
));
583 return VK_ERROR_INCOMPATIBLE_DRIVER
;
585 for (unsigned i
= 0; i
< (unsigned)max_devices
; i
++) {
586 if (devices
[i
]->available_nodes
& 1 << DRM_NODE_RENDER
&&
587 devices
[i
]->bustype
== DRM_BUS_PCI
&&
588 devices
[i
]->deviceinfo
.pci
->vendor_id
== ATI_VENDOR_ID
) {
590 result
= radv_physical_device_init(instance
->physicalDevices
+
591 instance
->physicalDeviceCount
,
594 if (result
== VK_SUCCESS
)
595 ++instance
->physicalDeviceCount
;
596 else if (result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
600 drmFreeDevices(devices
, max_devices
);
605 VkResult
radv_EnumeratePhysicalDevices(
606 VkInstance _instance
,
607 uint32_t* pPhysicalDeviceCount
,
608 VkPhysicalDevice
* pPhysicalDevices
)
610 RADV_FROM_HANDLE(radv_instance
, instance
, _instance
);
613 if (instance
->physicalDeviceCount
< 0) {
614 result
= radv_enumerate_devices(instance
);
615 if (result
!= VK_SUCCESS
&&
616 result
!= VK_ERROR_INCOMPATIBLE_DRIVER
)
620 if (!pPhysicalDevices
) {
621 *pPhysicalDeviceCount
= instance
->physicalDeviceCount
;
623 *pPhysicalDeviceCount
= MIN2(*pPhysicalDeviceCount
, instance
->physicalDeviceCount
);
624 for (unsigned i
= 0; i
< *pPhysicalDeviceCount
; ++i
)
625 pPhysicalDevices
[i
] = radv_physical_device_to_handle(instance
->physicalDevices
+ i
);
628 return *pPhysicalDeviceCount
< instance
->physicalDeviceCount
? VK_INCOMPLETE
632 void radv_GetPhysicalDeviceFeatures(
633 VkPhysicalDevice physicalDevice
,
634 VkPhysicalDeviceFeatures
* pFeatures
)
636 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
637 bool is_gfx9
= pdevice
->rad_info
.chip_class
>= GFX9
;
638 memset(pFeatures
, 0, sizeof(*pFeatures
));
640 *pFeatures
= (VkPhysicalDeviceFeatures
) {
641 .robustBufferAccess
= true,
642 .fullDrawIndexUint32
= true,
643 .imageCubeArray
= true,
644 .independentBlend
= true,
645 .geometryShader
= !is_gfx9
,
646 .tessellationShader
= !is_gfx9
,
647 .sampleRateShading
= true,
648 .dualSrcBlend
= true,
650 .multiDrawIndirect
= true,
651 .drawIndirectFirstInstance
= true,
653 .depthBiasClamp
= true,
654 .fillModeNonSolid
= true,
659 .multiViewport
= true,
660 .samplerAnisotropy
= true,
661 .textureCompressionETC2
= false,
662 .textureCompressionASTC_LDR
= false,
663 .textureCompressionBC
= true,
664 .occlusionQueryPrecise
= true,
665 .pipelineStatisticsQuery
= true,
666 .vertexPipelineStoresAndAtomics
= true,
667 .fragmentStoresAndAtomics
= true,
668 .shaderTessellationAndGeometryPointSize
= true,
669 .shaderImageGatherExtended
= true,
670 .shaderStorageImageExtendedFormats
= true,
671 .shaderStorageImageMultisample
= false,
672 .shaderUniformBufferArrayDynamicIndexing
= true,
673 .shaderSampledImageArrayDynamicIndexing
= true,
674 .shaderStorageBufferArrayDynamicIndexing
= true,
675 .shaderStorageImageArrayDynamicIndexing
= true,
676 .shaderStorageImageReadWithoutFormat
= true,
677 .shaderStorageImageWriteWithoutFormat
= true,
678 .shaderClipDistance
= true,
679 .shaderCullDistance
= true,
680 .shaderFloat64
= true,
682 .shaderInt16
= false,
683 .sparseBinding
= true,
684 .variableMultisampleRate
= true,
685 .inheritedQueries
= true,
689 void radv_GetPhysicalDeviceFeatures2KHR(
690 VkPhysicalDevice physicalDevice
,
691 VkPhysicalDeviceFeatures2KHR
*pFeatures
)
693 vk_foreach_struct(ext
, pFeatures
->pNext
) {
694 switch (ext
->sType
) {
695 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR
: {
696 VkPhysicalDeviceVariablePointerFeaturesKHR
*features
= (void *)ext
;
697 features
->variablePointersStorageBuffer
= true;
698 features
->variablePointers
= false;
701 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHX
: {
702 VkPhysicalDeviceMultiviewFeaturesKHX
*features
= (VkPhysicalDeviceMultiviewFeaturesKHX
*)ext
;
703 features
->multiview
= true;
704 features
->multiviewGeometryShader
= true;
705 features
->multiviewTessellationShader
= true;
712 return radv_GetPhysicalDeviceFeatures(physicalDevice
, &pFeatures
->features
);
715 void radv_GetPhysicalDeviceProperties(
716 VkPhysicalDevice physicalDevice
,
717 VkPhysicalDeviceProperties
* pProperties
)
719 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
720 VkSampleCountFlags sample_counts
= 0xf;
722 /* make sure that the entire descriptor set is addressable with a signed
723 * 32-bit int. So the sum of all limits scaled by descriptor size has to
724 * be at most 2 GiB. the combined image & samples object count as one of
725 * both. This limit is for the pipeline layout, not for the set layout, but
726 * there is no set limit, so we just set a pipeline limit. I don't think
727 * any app is going to hit this soon. */
728 size_t max_descriptor_set_size
= ((1ull << 31) - 16 * MAX_DYNAMIC_BUFFERS
) /
729 (32 /* uniform buffer, 32 due to potential space wasted on alignement */ +
730 32 /* storage buffer, 32 due to potential space wasted on alignement */ +
731 32 /* sampler, largest when combined with image */ +
732 64 /* sampled image */ +
733 64 /* storage image */);
735 VkPhysicalDeviceLimits limits
= {
736 .maxImageDimension1D
= (1 << 14),
737 .maxImageDimension2D
= (1 << 14),
738 .maxImageDimension3D
= (1 << 11),
739 .maxImageDimensionCube
= (1 << 14),
740 .maxImageArrayLayers
= (1 << 11),
741 .maxTexelBufferElements
= 128 * 1024 * 1024,
742 .maxUniformBufferRange
= UINT32_MAX
,
743 .maxStorageBufferRange
= UINT32_MAX
,
744 .maxPushConstantsSize
= MAX_PUSH_CONSTANTS_SIZE
,
745 .maxMemoryAllocationCount
= UINT32_MAX
,
746 .maxSamplerAllocationCount
= 64 * 1024,
747 .bufferImageGranularity
= 64, /* A cache line */
748 .sparseAddressSpaceSize
= 0xffffffffu
, /* buffer max size */
749 .maxBoundDescriptorSets
= MAX_SETS
,
750 .maxPerStageDescriptorSamplers
= max_descriptor_set_size
,
751 .maxPerStageDescriptorUniformBuffers
= max_descriptor_set_size
,
752 .maxPerStageDescriptorStorageBuffers
= max_descriptor_set_size
,
753 .maxPerStageDescriptorSampledImages
= max_descriptor_set_size
,
754 .maxPerStageDescriptorStorageImages
= max_descriptor_set_size
,
755 .maxPerStageDescriptorInputAttachments
= max_descriptor_set_size
,
756 .maxPerStageResources
= max_descriptor_set_size
,
757 .maxDescriptorSetSamplers
= max_descriptor_set_size
,
758 .maxDescriptorSetUniformBuffers
= max_descriptor_set_size
,
759 .maxDescriptorSetUniformBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
760 .maxDescriptorSetStorageBuffers
= max_descriptor_set_size
,
761 .maxDescriptorSetStorageBuffersDynamic
= MAX_DYNAMIC_BUFFERS
/ 2,
762 .maxDescriptorSetSampledImages
= max_descriptor_set_size
,
763 .maxDescriptorSetStorageImages
= max_descriptor_set_size
,
764 .maxDescriptorSetInputAttachments
= max_descriptor_set_size
,
765 .maxVertexInputAttributes
= 32,
766 .maxVertexInputBindings
= 32,
767 .maxVertexInputAttributeOffset
= 2047,
768 .maxVertexInputBindingStride
= 2048,
769 .maxVertexOutputComponents
= 128,
770 .maxTessellationGenerationLevel
= 64,
771 .maxTessellationPatchSize
= 32,
772 .maxTessellationControlPerVertexInputComponents
= 128,
773 .maxTessellationControlPerVertexOutputComponents
= 128,
774 .maxTessellationControlPerPatchOutputComponents
= 120,
775 .maxTessellationControlTotalOutputComponents
= 4096,
776 .maxTessellationEvaluationInputComponents
= 128,
777 .maxTessellationEvaluationOutputComponents
= 128,
778 .maxGeometryShaderInvocations
= 127,
779 .maxGeometryInputComponents
= 64,
780 .maxGeometryOutputComponents
= 128,
781 .maxGeometryOutputVertices
= 256,
782 .maxGeometryTotalOutputComponents
= 1024,
783 .maxFragmentInputComponents
= 128,
784 .maxFragmentOutputAttachments
= 8,
785 .maxFragmentDualSrcAttachments
= 1,
786 .maxFragmentCombinedOutputResources
= 8,
787 .maxComputeSharedMemorySize
= 32768,
788 .maxComputeWorkGroupCount
= { 65535, 65535, 65535 },
789 .maxComputeWorkGroupInvocations
= 2048,
790 .maxComputeWorkGroupSize
= {
795 .subPixelPrecisionBits
= 4 /* FIXME */,
796 .subTexelPrecisionBits
= 4 /* FIXME */,
797 .mipmapPrecisionBits
= 4 /* FIXME */,
798 .maxDrawIndexedIndexValue
= UINT32_MAX
,
799 .maxDrawIndirectCount
= UINT32_MAX
,
800 .maxSamplerLodBias
= 16,
801 .maxSamplerAnisotropy
= 16,
802 .maxViewports
= MAX_VIEWPORTS
,
803 .maxViewportDimensions
= { (1 << 14), (1 << 14) },
804 .viewportBoundsRange
= { INT16_MIN
, INT16_MAX
},
805 .viewportSubPixelBits
= 13, /* We take a float? */
806 .minMemoryMapAlignment
= 4096, /* A page */
807 .minTexelBufferOffsetAlignment
= 1,
808 .minUniformBufferOffsetAlignment
= 4,
809 .minStorageBufferOffsetAlignment
= 4,
810 .minTexelOffset
= -32,
811 .maxTexelOffset
= 31,
812 .minTexelGatherOffset
= -32,
813 .maxTexelGatherOffset
= 31,
814 .minInterpolationOffset
= -2,
815 .maxInterpolationOffset
= 2,
816 .subPixelInterpolationOffsetBits
= 8,
817 .maxFramebufferWidth
= (1 << 14),
818 .maxFramebufferHeight
= (1 << 14),
819 .maxFramebufferLayers
= (1 << 10),
820 .framebufferColorSampleCounts
= sample_counts
,
821 .framebufferDepthSampleCounts
= sample_counts
,
822 .framebufferStencilSampleCounts
= sample_counts
,
823 .framebufferNoAttachmentsSampleCounts
= sample_counts
,
824 .maxColorAttachments
= MAX_RTS
,
825 .sampledImageColorSampleCounts
= sample_counts
,
826 .sampledImageIntegerSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
827 .sampledImageDepthSampleCounts
= sample_counts
,
828 .sampledImageStencilSampleCounts
= sample_counts
,
829 .storageImageSampleCounts
= VK_SAMPLE_COUNT_1_BIT
,
830 .maxSampleMaskWords
= 1,
831 .timestampComputeAndGraphics
= true,
832 .timestampPeriod
= 1000000.0 / pdevice
->rad_info
.clock_crystal_freq
,
833 .maxClipDistances
= 8,
834 .maxCullDistances
= 8,
835 .maxCombinedClipAndCullDistances
= 8,
836 .discreteQueuePriorities
= 1,
837 .pointSizeRange
= { 0.125, 255.875 },
838 .lineWidthRange
= { 0.0, 7.9921875 },
839 .pointSizeGranularity
= (1.0 / 8.0),
840 .lineWidthGranularity
= (1.0 / 128.0),
841 .strictLines
= false, /* FINISHME */
842 .standardSampleLocations
= true,
843 .optimalBufferCopyOffsetAlignment
= 128,
844 .optimalBufferCopyRowPitchAlignment
= 128,
845 .nonCoherentAtomSize
= 64,
848 *pProperties
= (VkPhysicalDeviceProperties
) {
849 .apiVersion
= VK_MAKE_VERSION(1, 0, 42),
850 .driverVersion
= vk_get_driver_version(),
851 .vendorID
= ATI_VENDOR_ID
,
852 .deviceID
= pdevice
->rad_info
.pci_id
,
853 .deviceType
= pdevice
->rad_info
.has_dedicated_vram
? VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU
: VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU
,
855 .sparseProperties
= {0},
858 strcpy(pProperties
->deviceName
, pdevice
->name
);
859 memcpy(pProperties
->pipelineCacheUUID
, pdevice
->cache_uuid
, VK_UUID_SIZE
);
862 void radv_GetPhysicalDeviceProperties2KHR(
863 VkPhysicalDevice physicalDevice
,
864 VkPhysicalDeviceProperties2KHR
*pProperties
)
866 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
867 radv_GetPhysicalDeviceProperties(physicalDevice
, &pProperties
->properties
);
869 vk_foreach_struct(ext
, pProperties
->pNext
) {
870 switch (ext
->sType
) {
871 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR
: {
872 VkPhysicalDevicePushDescriptorPropertiesKHR
*properties
=
873 (VkPhysicalDevicePushDescriptorPropertiesKHR
*) ext
;
874 properties
->maxPushDescriptors
= MAX_PUSH_DESCRIPTORS
;
877 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR
: {
878 VkPhysicalDeviceIDPropertiesKHR
*properties
= (VkPhysicalDeviceIDPropertiesKHR
*)ext
;
879 memcpy(properties
->driverUUID
, pdevice
->driver_uuid
, VK_UUID_SIZE
);
880 memcpy(properties
->deviceUUID
, pdevice
->device_uuid
, VK_UUID_SIZE
);
881 properties
->deviceLUIDValid
= false;
884 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHX
: {
885 VkPhysicalDeviceMultiviewPropertiesKHX
*properties
= (VkPhysicalDeviceMultiviewPropertiesKHX
*)ext
;
886 properties
->maxMultiviewViewCount
= MAX_VIEWS
;
887 properties
->maxMultiviewInstanceIndex
= INT_MAX
;
890 case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR
: {
891 VkPhysicalDevicePointClippingPropertiesKHR
*properties
=
892 (VkPhysicalDevicePointClippingPropertiesKHR
*)ext
;
893 properties
->pointClippingBehavior
= VK_POINT_CLIPPING_BEHAVIOR_ALL_CLIP_PLANES_KHR
;
902 static void radv_get_physical_device_queue_family_properties(
903 struct radv_physical_device
* pdevice
,
905 VkQueueFamilyProperties
** pQueueFamilyProperties
)
907 int num_queue_families
= 1;
909 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
910 pdevice
->rad_info
.chip_class
>= CIK
&&
911 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
))
912 num_queue_families
++;
914 if (pQueueFamilyProperties
== NULL
) {
915 *pCount
= num_queue_families
;
924 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
925 .queueFlags
= VK_QUEUE_GRAPHICS_BIT
|
926 VK_QUEUE_COMPUTE_BIT
|
927 VK_QUEUE_TRANSFER_BIT
|
928 VK_QUEUE_SPARSE_BINDING_BIT
,
930 .timestampValidBits
= 64,
931 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
936 if (pdevice
->rad_info
.num_compute_rings
> 0 &&
937 pdevice
->rad_info
.chip_class
>= CIK
&&
938 !(pdevice
->instance
->debug_flags
& RADV_DEBUG_NO_COMPUTE_QUEUE
)) {
940 *pQueueFamilyProperties
[idx
] = (VkQueueFamilyProperties
) {
941 .queueFlags
= VK_QUEUE_COMPUTE_BIT
|
942 VK_QUEUE_TRANSFER_BIT
|
943 VK_QUEUE_SPARSE_BINDING_BIT
,
944 .queueCount
= pdevice
->rad_info
.num_compute_rings
,
945 .timestampValidBits
= 64,
946 .minImageTransferGranularity
= (VkExtent3D
) { 1, 1, 1 },
954 void radv_GetPhysicalDeviceQueueFamilyProperties(
955 VkPhysicalDevice physicalDevice
,
957 VkQueueFamilyProperties
* pQueueFamilyProperties
)
959 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
960 if (!pQueueFamilyProperties
) {
961 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
964 VkQueueFamilyProperties
*properties
[] = {
965 pQueueFamilyProperties
+ 0,
966 pQueueFamilyProperties
+ 1,
967 pQueueFamilyProperties
+ 2,
969 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
970 assert(*pCount
<= 3);
973 void radv_GetPhysicalDeviceQueueFamilyProperties2KHR(
974 VkPhysicalDevice physicalDevice
,
976 VkQueueFamilyProperties2KHR
*pQueueFamilyProperties
)
978 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
979 if (!pQueueFamilyProperties
) {
980 return radv_get_physical_device_queue_family_properties(pdevice
, pCount
, NULL
);
983 VkQueueFamilyProperties
*properties
[] = {
984 &pQueueFamilyProperties
[0].queueFamilyProperties
,
985 &pQueueFamilyProperties
[1].queueFamilyProperties
,
986 &pQueueFamilyProperties
[2].queueFamilyProperties
,
988 radv_get_physical_device_queue_family_properties(pdevice
, pCount
, properties
);
989 assert(*pCount
<= 3);
992 void radv_GetPhysicalDeviceMemoryProperties(
993 VkPhysicalDevice physicalDevice
,
994 VkPhysicalDeviceMemoryProperties
*pMemoryProperties
)
996 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
998 STATIC_ASSERT(RADV_MEM_TYPE_COUNT
<= VK_MAX_MEMORY_TYPES
);
1000 pMemoryProperties
->memoryTypeCount
= RADV_MEM_TYPE_COUNT
;
1001 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_VRAM
] = (VkMemoryType
) {
1002 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
,
1003 .heapIndex
= RADV_MEM_HEAP_VRAM
,
1005 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_GTT_WRITE_COMBINE
] = (VkMemoryType
) {
1006 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
1007 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
1008 .heapIndex
= RADV_MEM_HEAP_GTT
,
1010 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_VRAM_CPU_ACCESS
] = (VkMemoryType
) {
1011 .propertyFlags
= VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
1012 VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
1013 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
,
1014 .heapIndex
= RADV_MEM_HEAP_VRAM_CPU_ACCESS
,
1016 pMemoryProperties
->memoryTypes
[RADV_MEM_TYPE_GTT_CACHED
] = (VkMemoryType
) {
1017 .propertyFlags
= VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT
|
1018 VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
1019 VK_MEMORY_PROPERTY_HOST_CACHED_BIT
,
1020 .heapIndex
= RADV_MEM_HEAP_GTT
,
1023 STATIC_ASSERT(RADV_MEM_HEAP_COUNT
<= VK_MAX_MEMORY_HEAPS
);
1024 uint64_t visible_vram_size
= MIN2(physical_device
->rad_info
.vram_size
,
1025 physical_device
->rad_info
.vram_vis_size
);
1027 pMemoryProperties
->memoryHeapCount
= RADV_MEM_HEAP_COUNT
;
1028 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_VRAM
] = (VkMemoryHeap
) {
1029 .size
= physical_device
->rad_info
.vram_size
-
1031 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
1033 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_VRAM_CPU_ACCESS
] = (VkMemoryHeap
) {
1034 .size
= visible_vram_size
,
1035 .flags
= VK_MEMORY_HEAP_DEVICE_LOCAL_BIT
,
1037 pMemoryProperties
->memoryHeaps
[RADV_MEM_HEAP_GTT
] = (VkMemoryHeap
) {
1038 .size
= physical_device
->rad_info
.gart_size
,
1043 void radv_GetPhysicalDeviceMemoryProperties2KHR(
1044 VkPhysicalDevice physicalDevice
,
1045 VkPhysicalDeviceMemoryProperties2KHR
*pMemoryProperties
)
1047 return radv_GetPhysicalDeviceMemoryProperties(physicalDevice
,
1048 &pMemoryProperties
->memoryProperties
);
1052 radv_queue_init(struct radv_device
*device
, struct radv_queue
*queue
,
1053 int queue_family_index
, int idx
)
1055 queue
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1056 queue
->device
= device
;
1057 queue
->queue_family_index
= queue_family_index
;
1058 queue
->queue_idx
= idx
;
1060 queue
->hw_ctx
= device
->ws
->ctx_create(device
->ws
);
1062 return VK_ERROR_OUT_OF_HOST_MEMORY
;
1068 radv_queue_finish(struct radv_queue
*queue
)
1071 queue
->device
->ws
->ctx_destroy(queue
->hw_ctx
);
1073 if (queue
->initial_full_flush_preamble_cs
)
1074 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1075 if (queue
->initial_preamble_cs
)
1076 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1077 if (queue
->continue_preamble_cs
)
1078 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1079 if (queue
->descriptor_bo
)
1080 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1081 if (queue
->scratch_bo
)
1082 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1083 if (queue
->esgs_ring_bo
)
1084 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1085 if (queue
->gsvs_ring_bo
)
1086 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1087 if (queue
->tess_factor_ring_bo
)
1088 queue
->device
->ws
->buffer_destroy(queue
->tess_factor_ring_bo
);
1089 if (queue
->tess_offchip_ring_bo
)
1090 queue
->device
->ws
->buffer_destroy(queue
->tess_offchip_ring_bo
);
1091 if (queue
->compute_scratch_bo
)
1092 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1096 radv_device_init_gs_info(struct radv_device
*device
)
1098 switch (device
->physical_device
->rad_info
.family
) {
1107 device
->gs_table_depth
= 16;
1116 case CHIP_POLARIS10
:
1117 case CHIP_POLARIS11
:
1118 case CHIP_POLARIS12
:
1121 device
->gs_table_depth
= 32;
1124 unreachable("unknown GPU");
1128 VkResult
radv_CreateDevice(
1129 VkPhysicalDevice physicalDevice
,
1130 const VkDeviceCreateInfo
* pCreateInfo
,
1131 const VkAllocationCallbacks
* pAllocator
,
1134 RADV_FROM_HANDLE(radv_physical_device
, physical_device
, physicalDevice
);
1136 struct radv_device
*device
;
1138 for (uint32_t i
= 0; i
< pCreateInfo
->enabledExtensionCount
; i
++) {
1139 if (!is_extension_enabled(physical_device
->extensions
.ext_array
,
1140 physical_device
->extensions
.num_ext
,
1141 pCreateInfo
->ppEnabledExtensionNames
[i
]))
1142 return vk_error(VK_ERROR_EXTENSION_NOT_PRESENT
);
1145 /* Check enabled features */
1146 if (pCreateInfo
->pEnabledFeatures
) {
1147 VkPhysicalDeviceFeatures supported_features
;
1148 radv_GetPhysicalDeviceFeatures(physicalDevice
, &supported_features
);
1149 VkBool32
*supported_feature
= (VkBool32
*)&supported_features
;
1150 VkBool32
*enabled_feature
= (VkBool32
*)pCreateInfo
->pEnabledFeatures
;
1151 unsigned num_features
= sizeof(VkPhysicalDeviceFeatures
) / sizeof(VkBool32
);
1152 for (uint32_t i
= 0; i
< num_features
; i
++) {
1153 if (enabled_feature
[i
] && !supported_feature
[i
])
1154 return vk_error(VK_ERROR_FEATURE_NOT_PRESENT
);
1158 device
= vk_alloc2(&physical_device
->instance
->alloc
, pAllocator
,
1160 VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1162 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1164 memset(device
, 0, sizeof(*device
));
1166 device
->_loader_data
.loaderMagic
= ICD_LOADER_MAGIC
;
1167 device
->instance
= physical_device
->instance
;
1168 device
->physical_device
= physical_device
;
1170 device
->ws
= physical_device
->ws
;
1172 device
->alloc
= *pAllocator
;
1174 device
->alloc
= physical_device
->instance
->alloc
;
1176 mtx_init(&device
->shader_slab_mutex
, mtx_plain
);
1177 list_inithead(&device
->shader_slabs
);
1179 for (unsigned i
= 0; i
< pCreateInfo
->queueCreateInfoCount
; i
++) {
1180 const VkDeviceQueueCreateInfo
*queue_create
= &pCreateInfo
->pQueueCreateInfos
[i
];
1181 uint32_t qfi
= queue_create
->queueFamilyIndex
;
1183 device
->queues
[qfi
] = vk_alloc(&device
->alloc
,
1184 queue_create
->queueCount
* sizeof(struct radv_queue
), 8, VK_SYSTEM_ALLOCATION_SCOPE_DEVICE
);
1185 if (!device
->queues
[qfi
]) {
1186 result
= VK_ERROR_OUT_OF_HOST_MEMORY
;
1190 memset(device
->queues
[qfi
], 0, queue_create
->queueCount
* sizeof(struct radv_queue
));
1192 device
->queue_count
[qfi
] = queue_create
->queueCount
;
1194 for (unsigned q
= 0; q
< queue_create
->queueCount
; q
++) {
1195 result
= radv_queue_init(device
, &device
->queues
[qfi
][q
], qfi
, q
);
1196 if (result
!= VK_SUCCESS
)
1201 #if HAVE_LLVM < 0x0400
1202 device
->llvm_supports_spill
= false;
1204 device
->llvm_supports_spill
= true;
1207 /* The maximum number of scratch waves. Scratch space isn't divided
1208 * evenly between CUs. The number is only a function of the number of CUs.
1209 * We can decrease the constant to decrease the scratch buffer size.
1211 * sctx->scratch_waves must be >= the maximum posible size of
1212 * 1 threadgroup, so that the hw doesn't hang from being unable
1215 * The recommended value is 4 per CU at most. Higher numbers don't
1216 * bring much benefit, but they still occupy chip resources (think
1217 * async compute). I've seen ~2% performance difference between 4 and 32.
1219 uint32_t max_threads_per_block
= 2048;
1220 device
->scratch_waves
= MAX2(32 * physical_device
->rad_info
.num_good_compute_units
,
1221 max_threads_per_block
/ 64);
1223 radv_device_init_gs_info(device
);
1225 device
->tess_offchip_block_dw_size
=
1226 device
->physical_device
->rad_info
.family
== CHIP_HAWAII
? 4096 : 8192;
1227 device
->has_distributed_tess
=
1228 device
->physical_device
->rad_info
.chip_class
>= VI
&&
1229 device
->physical_device
->rad_info
.max_se
>= 2;
1231 if (getenv("RADV_TRACE_FILE")) {
1232 if (!radv_init_trace(device
))
1236 result
= radv_device_init_meta(device
);
1237 if (result
!= VK_SUCCESS
)
1240 radv_device_init_msaa(device
);
1242 for (int family
= 0; family
< RADV_MAX_QUEUE_FAMILIES
; ++family
) {
1243 device
->empty_cs
[family
] = device
->ws
->cs_create(device
->ws
, family
);
1245 case RADV_QUEUE_GENERAL
:
1246 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
1247 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_LOAD_ENABLE(1));
1248 radeon_emit(device
->empty_cs
[family
], CONTEXT_CONTROL_SHADOW_ENABLE(1));
1250 case RADV_QUEUE_COMPUTE
:
1251 radeon_emit(device
->empty_cs
[family
], PKT3(PKT3_NOP
, 0, 0));
1252 radeon_emit(device
->empty_cs
[family
], 0);
1255 device
->ws
->cs_finalize(device
->empty_cs
[family
]);
1258 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
1259 cik_create_gfx_config(device
);
1261 VkPipelineCacheCreateInfo ci
;
1262 ci
.sType
= VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO
;
1265 ci
.pInitialData
= NULL
;
1266 ci
.initialDataSize
= 0;
1268 result
= radv_CreatePipelineCache(radv_device_to_handle(device
),
1270 if (result
!= VK_SUCCESS
)
1273 device
->mem_cache
= radv_pipeline_cache_from_handle(pc
);
1275 *pDevice
= radv_device_to_handle(device
);
1279 if (device
->trace_bo
)
1280 device
->ws
->buffer_destroy(device
->trace_bo
);
1282 if (device
->gfx_init
)
1283 device
->ws
->buffer_destroy(device
->gfx_init
);
1285 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1286 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1287 radv_queue_finish(&device
->queues
[i
][q
]);
1288 if (device
->queue_count
[i
])
1289 vk_free(&device
->alloc
, device
->queues
[i
]);
1292 vk_free(&device
->alloc
, device
);
1296 void radv_DestroyDevice(
1298 const VkAllocationCallbacks
* pAllocator
)
1300 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1305 if (device
->trace_bo
)
1306 device
->ws
->buffer_destroy(device
->trace_bo
);
1308 if (device
->gfx_init
)
1309 device
->ws
->buffer_destroy(device
->gfx_init
);
1311 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
1312 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++)
1313 radv_queue_finish(&device
->queues
[i
][q
]);
1314 if (device
->queue_count
[i
])
1315 vk_free(&device
->alloc
, device
->queues
[i
]);
1316 if (device
->empty_cs
[i
])
1317 device
->ws
->cs_destroy(device
->empty_cs
[i
]);
1319 radv_device_finish_meta(device
);
1321 VkPipelineCache pc
= radv_pipeline_cache_to_handle(device
->mem_cache
);
1322 radv_DestroyPipelineCache(radv_device_to_handle(device
), pc
, NULL
);
1324 radv_destroy_shader_slabs(device
);
1326 vk_free(&device
->alloc
, device
);
1329 VkResult
radv_EnumerateInstanceExtensionProperties(
1330 const char* pLayerName
,
1331 uint32_t* pPropertyCount
,
1332 VkExtensionProperties
* pProperties
)
1334 if (pProperties
== NULL
) {
1335 *pPropertyCount
= ARRAY_SIZE(instance_extensions
);
1339 *pPropertyCount
= MIN2(*pPropertyCount
, ARRAY_SIZE(instance_extensions
));
1340 typed_memcpy(pProperties
, instance_extensions
, *pPropertyCount
);
1342 if (*pPropertyCount
< ARRAY_SIZE(instance_extensions
))
1343 return VK_INCOMPLETE
;
1348 VkResult
radv_EnumerateDeviceExtensionProperties(
1349 VkPhysicalDevice physicalDevice
,
1350 const char* pLayerName
,
1351 uint32_t* pPropertyCount
,
1352 VkExtensionProperties
* pProperties
)
1354 RADV_FROM_HANDLE(radv_physical_device
, pdevice
, physicalDevice
);
1356 if (pProperties
== NULL
) {
1357 *pPropertyCount
= pdevice
->extensions
.num_ext
;
1361 *pPropertyCount
= MIN2(*pPropertyCount
, pdevice
->extensions
.num_ext
);
1362 typed_memcpy(pProperties
, pdevice
->extensions
.ext_array
, *pPropertyCount
);
1364 if (*pPropertyCount
< pdevice
->extensions
.num_ext
)
1365 return VK_INCOMPLETE
;
1370 VkResult
radv_EnumerateInstanceLayerProperties(
1371 uint32_t* pPropertyCount
,
1372 VkLayerProperties
* pProperties
)
1374 if (pProperties
== NULL
) {
1375 *pPropertyCount
= 0;
1379 /* None supported at this time */
1380 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1383 VkResult
radv_EnumerateDeviceLayerProperties(
1384 VkPhysicalDevice physicalDevice
,
1385 uint32_t* pPropertyCount
,
1386 VkLayerProperties
* pProperties
)
1388 if (pProperties
== NULL
) {
1389 *pPropertyCount
= 0;
1393 /* None supported at this time */
1394 return vk_error(VK_ERROR_LAYER_NOT_PRESENT
);
1397 void radv_GetDeviceQueue(
1399 uint32_t queueFamilyIndex
,
1400 uint32_t queueIndex
,
1403 RADV_FROM_HANDLE(radv_device
, device
, _device
);
1405 *pQueue
= radv_queue_to_handle(&device
->queues
[queueFamilyIndex
][queueIndex
]);
1409 fill_geom_tess_rings(struct radv_queue
*queue
,
1411 bool add_sample_positions
,
1412 uint32_t esgs_ring_size
,
1413 struct radeon_winsys_bo
*esgs_ring_bo
,
1414 uint32_t gsvs_ring_size
,
1415 struct radeon_winsys_bo
*gsvs_ring_bo
,
1416 uint32_t tess_factor_ring_size
,
1417 struct radeon_winsys_bo
*tess_factor_ring_bo
,
1418 uint32_t tess_offchip_ring_size
,
1419 struct radeon_winsys_bo
*tess_offchip_ring_bo
)
1421 uint64_t esgs_va
= 0, gsvs_va
= 0;
1422 uint64_t tess_factor_va
= 0, tess_offchip_va
= 0;
1423 uint32_t *desc
= &map
[4];
1426 esgs_va
= radv_buffer_get_va(esgs_ring_bo
);
1428 gsvs_va
= radv_buffer_get_va(gsvs_ring_bo
);
1429 if (tess_factor_ring_bo
)
1430 tess_factor_va
= radv_buffer_get_va(tess_factor_ring_bo
);
1431 if (tess_offchip_ring_bo
)
1432 tess_offchip_va
= radv_buffer_get_va(tess_offchip_ring_bo
);
1434 /* stride 0, num records - size, add tid, swizzle, elsize4,
1437 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32) |
1438 S_008F04_STRIDE(0) |
1439 S_008F04_SWIZZLE_ENABLE(true);
1440 desc
[2] = esgs_ring_size
;
1441 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1442 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1443 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1444 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1445 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1446 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1447 S_008F0C_ELEMENT_SIZE(1) |
1448 S_008F0C_INDEX_STRIDE(3) |
1449 S_008F0C_ADD_TID_ENABLE(true);
1452 /* GS entry for ES->GS ring */
1453 /* stride 0, num records - size, elsize0,
1456 desc
[1] = S_008F04_BASE_ADDRESS_HI(esgs_va
>> 32)|
1457 S_008F04_STRIDE(0) |
1458 S_008F04_SWIZZLE_ENABLE(false);
1459 desc
[2] = esgs_ring_size
;
1460 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1461 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1462 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1463 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1464 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1465 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1466 S_008F0C_ELEMENT_SIZE(0) |
1467 S_008F0C_INDEX_STRIDE(0) |
1468 S_008F0C_ADD_TID_ENABLE(false);
1471 /* VS entry for GS->VS ring */
1472 /* stride 0, num records - size, elsize0,
1475 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1476 S_008F04_STRIDE(0) |
1477 S_008F04_SWIZZLE_ENABLE(false);
1478 desc
[2] = gsvs_ring_size
;
1479 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1480 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1481 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1482 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1483 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1484 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1485 S_008F0C_ELEMENT_SIZE(0) |
1486 S_008F0C_INDEX_STRIDE(0) |
1487 S_008F0C_ADD_TID_ENABLE(false);
1490 /* stride gsvs_itemsize, num records 64
1491 elsize 4, index stride 16 */
1492 /* shader will patch stride and desc[2] */
1494 desc
[1] = S_008F04_BASE_ADDRESS_HI(gsvs_va
>> 32)|
1495 S_008F04_STRIDE(0) |
1496 S_008F04_SWIZZLE_ENABLE(true);
1498 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1499 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1500 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1501 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1502 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1503 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1504 S_008F0C_ELEMENT_SIZE(1) |
1505 S_008F0C_INDEX_STRIDE(1) |
1506 S_008F0C_ADD_TID_ENABLE(true);
1509 desc
[0] = tess_factor_va
;
1510 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_factor_va
>> 32) |
1511 S_008F04_STRIDE(0) |
1512 S_008F04_SWIZZLE_ENABLE(false);
1513 desc
[2] = tess_factor_ring_size
;
1514 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1515 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1516 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1517 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1518 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1519 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1520 S_008F0C_ELEMENT_SIZE(0) |
1521 S_008F0C_INDEX_STRIDE(0) |
1522 S_008F0C_ADD_TID_ENABLE(false);
1525 desc
[0] = tess_offchip_va
;
1526 desc
[1] = S_008F04_BASE_ADDRESS_HI(tess_offchip_va
>> 32) |
1527 S_008F04_STRIDE(0) |
1528 S_008F04_SWIZZLE_ENABLE(false);
1529 desc
[2] = tess_offchip_ring_size
;
1530 desc
[3] = S_008F0C_DST_SEL_X(V_008F0C_SQ_SEL_X
) |
1531 S_008F0C_DST_SEL_Y(V_008F0C_SQ_SEL_Y
) |
1532 S_008F0C_DST_SEL_Z(V_008F0C_SQ_SEL_Z
) |
1533 S_008F0C_DST_SEL_W(V_008F0C_SQ_SEL_W
) |
1534 S_008F0C_NUM_FORMAT(V_008F0C_BUF_NUM_FORMAT_FLOAT
) |
1535 S_008F0C_DATA_FORMAT(V_008F0C_BUF_DATA_FORMAT_32
) |
1536 S_008F0C_ELEMENT_SIZE(0) |
1537 S_008F0C_INDEX_STRIDE(0) |
1538 S_008F0C_ADD_TID_ENABLE(false);
1541 /* add sample positions after all rings */
1542 memcpy(desc
, queue
->device
->sample_locations_1x
, 8);
1544 memcpy(desc
, queue
->device
->sample_locations_2x
, 16);
1546 memcpy(desc
, queue
->device
->sample_locations_4x
, 32);
1548 memcpy(desc
, queue
->device
->sample_locations_8x
, 64);
1550 memcpy(desc
, queue
->device
->sample_locations_16x
, 128);
1554 radv_get_hs_offchip_param(struct radv_device
*device
, uint32_t *max_offchip_buffers_p
)
1556 bool double_offchip_buffers
= device
->physical_device
->rad_info
.chip_class
>= CIK
&&
1557 device
->physical_device
->rad_info
.family
!= CHIP_CARRIZO
&&
1558 device
->physical_device
->rad_info
.family
!= CHIP_STONEY
;
1559 unsigned max_offchip_buffers_per_se
= double_offchip_buffers
? 128 : 64;
1560 unsigned max_offchip_buffers
= max_offchip_buffers_per_se
*
1561 device
->physical_device
->rad_info
.max_se
;
1562 unsigned offchip_granularity
;
1563 unsigned hs_offchip_param
;
1564 switch (device
->tess_offchip_block_dw_size
) {
1569 offchip_granularity
= V_03093C_X_8K_DWORDS
;
1572 offchip_granularity
= V_03093C_X_4K_DWORDS
;
1576 switch (device
->physical_device
->rad_info
.chip_class
) {
1578 max_offchip_buffers
= MIN2(max_offchip_buffers
, 126);
1584 max_offchip_buffers
= MIN2(max_offchip_buffers
, 508);
1588 *max_offchip_buffers_p
= max_offchip_buffers
;
1589 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1590 if (device
->physical_device
->rad_info
.chip_class
>= VI
)
1591 --max_offchip_buffers
;
1593 S_03093C_OFFCHIP_BUFFERING(max_offchip_buffers
) |
1594 S_03093C_OFFCHIP_GRANULARITY(offchip_granularity
);
1597 S_0089B0_OFFCHIP_BUFFERING(max_offchip_buffers
);
1599 return hs_offchip_param
;
1603 radv_get_preamble_cs(struct radv_queue
*queue
,
1604 uint32_t scratch_size
,
1605 uint32_t compute_scratch_size
,
1606 uint32_t esgs_ring_size
,
1607 uint32_t gsvs_ring_size
,
1608 bool needs_tess_rings
,
1609 bool needs_sample_positions
,
1610 struct radeon_winsys_cs
**initial_full_flush_preamble_cs
,
1611 struct radeon_winsys_cs
**initial_preamble_cs
,
1612 struct radeon_winsys_cs
**continue_preamble_cs
)
1614 struct radeon_winsys_bo
*scratch_bo
= NULL
;
1615 struct radeon_winsys_bo
*descriptor_bo
= NULL
;
1616 struct radeon_winsys_bo
*compute_scratch_bo
= NULL
;
1617 struct radeon_winsys_bo
*esgs_ring_bo
= NULL
;
1618 struct radeon_winsys_bo
*gsvs_ring_bo
= NULL
;
1619 struct radeon_winsys_bo
*tess_factor_ring_bo
= NULL
;
1620 struct radeon_winsys_bo
*tess_offchip_ring_bo
= NULL
;
1621 struct radeon_winsys_cs
*dest_cs
[3] = {0};
1622 bool add_tess_rings
= false, add_sample_positions
= false;
1623 unsigned tess_factor_ring_size
= 0, tess_offchip_ring_size
= 0;
1624 unsigned max_offchip_buffers
;
1625 unsigned hs_offchip_param
= 0;
1626 if (!queue
->has_tess_rings
) {
1627 if (needs_tess_rings
)
1628 add_tess_rings
= true;
1630 if (!queue
->has_sample_positions
) {
1631 if (needs_sample_positions
)
1632 add_sample_positions
= true;
1634 tess_factor_ring_size
= 32768 * queue
->device
->physical_device
->rad_info
.max_se
;
1635 hs_offchip_param
= radv_get_hs_offchip_param(queue
->device
,
1636 &max_offchip_buffers
);
1637 tess_offchip_ring_size
= max_offchip_buffers
*
1638 queue
->device
->tess_offchip_block_dw_size
* 4;
1640 if (scratch_size
<= queue
->scratch_size
&&
1641 compute_scratch_size
<= queue
->compute_scratch_size
&&
1642 esgs_ring_size
<= queue
->esgs_ring_size
&&
1643 gsvs_ring_size
<= queue
->gsvs_ring_size
&&
1644 !add_tess_rings
&& !add_sample_positions
&&
1645 queue
->initial_preamble_cs
) {
1646 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
1647 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1648 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1649 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1650 *continue_preamble_cs
= NULL
;
1654 if (scratch_size
> queue
->scratch_size
) {
1655 scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1659 RADEON_FLAG_NO_CPU_ACCESS
);
1663 scratch_bo
= queue
->scratch_bo
;
1665 if (compute_scratch_size
> queue
->compute_scratch_size
) {
1666 compute_scratch_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1667 compute_scratch_size
,
1670 RADEON_FLAG_NO_CPU_ACCESS
);
1671 if (!compute_scratch_bo
)
1675 compute_scratch_bo
= queue
->compute_scratch_bo
;
1677 if (esgs_ring_size
> queue
->esgs_ring_size
) {
1678 esgs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1682 RADEON_FLAG_NO_CPU_ACCESS
);
1686 esgs_ring_bo
= queue
->esgs_ring_bo
;
1687 esgs_ring_size
= queue
->esgs_ring_size
;
1690 if (gsvs_ring_size
> queue
->gsvs_ring_size
) {
1691 gsvs_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1695 RADEON_FLAG_NO_CPU_ACCESS
);
1699 gsvs_ring_bo
= queue
->gsvs_ring_bo
;
1700 gsvs_ring_size
= queue
->gsvs_ring_size
;
1703 if (add_tess_rings
) {
1704 tess_factor_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1705 tess_factor_ring_size
,
1708 RADEON_FLAG_NO_CPU_ACCESS
);
1709 if (!tess_factor_ring_bo
)
1711 tess_offchip_ring_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1712 tess_offchip_ring_size
,
1715 RADEON_FLAG_NO_CPU_ACCESS
);
1716 if (!tess_offchip_ring_bo
)
1719 tess_factor_ring_bo
= queue
->tess_factor_ring_bo
;
1720 tess_offchip_ring_bo
= queue
->tess_offchip_ring_bo
;
1723 if (scratch_bo
!= queue
->scratch_bo
||
1724 esgs_ring_bo
!= queue
->esgs_ring_bo
||
1725 gsvs_ring_bo
!= queue
->gsvs_ring_bo
||
1726 tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
||
1727 tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
|| add_sample_positions
) {
1729 if (gsvs_ring_bo
|| esgs_ring_bo
||
1730 tess_factor_ring_bo
|| tess_offchip_ring_bo
|| add_sample_positions
) {
1731 size
= 112; /* 2 dword + 2 padding + 4 dword * 6 */
1732 if (add_sample_positions
)
1733 size
+= 256; /* 32+16+8+4+2+1 samples * 4 * 2 = 248 bytes. */
1735 else if (scratch_bo
)
1736 size
= 8; /* 2 dword */
1738 descriptor_bo
= queue
->device
->ws
->buffer_create(queue
->device
->ws
,
1742 RADEON_FLAG_CPU_ACCESS
);
1746 descriptor_bo
= queue
->descriptor_bo
;
1748 for(int i
= 0; i
< 3; ++i
) {
1749 struct radeon_winsys_cs
*cs
= NULL
;
1750 cs
= queue
->device
->ws
->cs_create(queue
->device
->ws
,
1751 queue
->queue_family_index
? RING_COMPUTE
: RING_GFX
);
1758 queue
->device
->ws
->cs_add_buffer(cs
, scratch_bo
, 8);
1761 queue
->device
->ws
->cs_add_buffer(cs
, esgs_ring_bo
, 8);
1764 queue
->device
->ws
->cs_add_buffer(cs
, gsvs_ring_bo
, 8);
1766 if (tess_factor_ring_bo
)
1767 queue
->device
->ws
->cs_add_buffer(cs
, tess_factor_ring_bo
, 8);
1769 if (tess_offchip_ring_bo
)
1770 queue
->device
->ws
->cs_add_buffer(cs
, tess_offchip_ring_bo
, 8);
1773 queue
->device
->ws
->cs_add_buffer(cs
, descriptor_bo
, 8);
1775 if (descriptor_bo
!= queue
->descriptor_bo
) {
1776 uint32_t *map
= (uint32_t*)queue
->device
->ws
->buffer_map(descriptor_bo
);
1779 uint64_t scratch_va
= radv_buffer_get_va(scratch_bo
);
1780 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1781 S_008F04_SWIZZLE_ENABLE(1);
1782 map
[0] = scratch_va
;
1786 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_factor_ring_bo
|| tess_offchip_ring_bo
||
1787 add_sample_positions
)
1788 fill_geom_tess_rings(queue
, map
, add_sample_positions
,
1789 esgs_ring_size
, esgs_ring_bo
,
1790 gsvs_ring_size
, gsvs_ring_bo
,
1791 tess_factor_ring_size
, tess_factor_ring_bo
,
1792 tess_offchip_ring_size
, tess_offchip_ring_bo
);
1794 queue
->device
->ws
->buffer_unmap(descriptor_bo
);
1797 if (esgs_ring_bo
|| gsvs_ring_bo
|| tess_factor_ring_bo
|| tess_offchip_ring_bo
) {
1798 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1799 radeon_emit(cs
, EVENT_TYPE(V_028A90_VS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
1800 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
1801 radeon_emit(cs
, EVENT_TYPE(V_028A90_VGT_FLUSH
) | EVENT_INDEX(0));
1804 if (esgs_ring_bo
|| gsvs_ring_bo
) {
1805 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1806 radeon_set_uconfig_reg_seq(cs
, R_030900_VGT_ESGS_RING_SIZE
, 2);
1807 radeon_emit(cs
, esgs_ring_size
>> 8);
1808 radeon_emit(cs
, gsvs_ring_size
>> 8);
1810 radeon_set_config_reg_seq(cs
, R_0088C8_VGT_ESGS_RING_SIZE
, 2);
1811 radeon_emit(cs
, esgs_ring_size
>> 8);
1812 radeon_emit(cs
, gsvs_ring_size
>> 8);
1816 if (tess_factor_ring_bo
) {
1817 uint64_t tf_va
= radv_buffer_get_va(tess_factor_ring_bo
);
1818 if (queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
) {
1819 radeon_set_uconfig_reg(cs
, R_030938_VGT_TF_RING_SIZE
,
1820 S_030938_SIZE(tess_factor_ring_size
/ 4));
1821 radeon_set_uconfig_reg(cs
, R_030940_VGT_TF_MEMORY_BASE
,
1823 if (queue
->device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
1824 radeon_set_uconfig_reg(cs
, R_030944_VGT_TF_MEMORY_BASE_HI
,
1827 radeon_set_uconfig_reg(cs
, R_03093C_VGT_HS_OFFCHIP_PARAM
, hs_offchip_param
);
1829 radeon_set_config_reg(cs
, R_008988_VGT_TF_RING_SIZE
,
1830 S_008988_SIZE(tess_factor_ring_size
/ 4));
1831 radeon_set_config_reg(cs
, R_0089B8_VGT_TF_MEMORY_BASE
,
1833 radeon_set_config_reg(cs
, R_0089B0_VGT_HS_OFFCHIP_PARAM
,
1838 if (descriptor_bo
) {
1839 uint32_t regs
[] = {R_00B030_SPI_SHADER_USER_DATA_PS_0
,
1840 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
1841 R_00B230_SPI_SHADER_USER_DATA_GS_0
,
1842 R_00B330_SPI_SHADER_USER_DATA_ES_0
,
1843 R_00B430_SPI_SHADER_USER_DATA_HS_0
,
1844 R_00B530_SPI_SHADER_USER_DATA_LS_0
};
1846 uint64_t va
= radv_buffer_get_va(descriptor_bo
);
1848 for (int i
= 0; i
< ARRAY_SIZE(regs
); ++i
) {
1849 radeon_set_sh_reg_seq(cs
, regs
[i
], 2);
1850 radeon_emit(cs
, va
);
1851 radeon_emit(cs
, va
>> 32);
1855 if (compute_scratch_bo
) {
1856 uint64_t scratch_va
= radv_buffer_get_va(compute_scratch_bo
);
1857 uint32_t rsrc1
= S_008F04_BASE_ADDRESS_HI(scratch_va
>> 32) |
1858 S_008F04_SWIZZLE_ENABLE(1);
1860 queue
->device
->ws
->cs_add_buffer(cs
, compute_scratch_bo
, 8);
1862 radeon_set_sh_reg_seq(cs
, R_00B900_COMPUTE_USER_DATA_0
, 2);
1863 radeon_emit(cs
, scratch_va
);
1864 radeon_emit(cs
, rsrc1
);
1868 si_cs_emit_cache_flush(cs
,
1870 queue
->device
->physical_device
->rad_info
.chip_class
,
1872 queue
->queue_family_index
== RING_COMPUTE
&&
1873 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
1874 (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
)) |
1875 RADV_CMD_FLAG_INV_ICACHE
|
1876 RADV_CMD_FLAG_INV_SMEM_L1
|
1877 RADV_CMD_FLAG_INV_VMEM_L1
|
1878 RADV_CMD_FLAG_INV_GLOBAL_L2
);
1879 } else if (i
== 1) {
1880 si_cs_emit_cache_flush(cs
,
1882 queue
->device
->physical_device
->rad_info
.chip_class
,
1884 queue
->queue_family_index
== RING_COMPUTE
&&
1885 queue
->device
->physical_device
->rad_info
.chip_class
>= CIK
,
1886 RADV_CMD_FLAG_INV_ICACHE
|
1887 RADV_CMD_FLAG_INV_SMEM_L1
|
1888 RADV_CMD_FLAG_INV_VMEM_L1
|
1889 RADV_CMD_FLAG_INV_GLOBAL_L2
);
1892 if (!queue
->device
->ws
->cs_finalize(cs
))
1896 if (queue
->initial_full_flush_preamble_cs
)
1897 queue
->device
->ws
->cs_destroy(queue
->initial_full_flush_preamble_cs
);
1899 if (queue
->initial_preamble_cs
)
1900 queue
->device
->ws
->cs_destroy(queue
->initial_preamble_cs
);
1902 if (queue
->continue_preamble_cs
)
1903 queue
->device
->ws
->cs_destroy(queue
->continue_preamble_cs
);
1905 queue
->initial_full_flush_preamble_cs
= dest_cs
[0];
1906 queue
->initial_preamble_cs
= dest_cs
[1];
1907 queue
->continue_preamble_cs
= dest_cs
[2];
1909 if (scratch_bo
!= queue
->scratch_bo
) {
1910 if (queue
->scratch_bo
)
1911 queue
->device
->ws
->buffer_destroy(queue
->scratch_bo
);
1912 queue
->scratch_bo
= scratch_bo
;
1913 queue
->scratch_size
= scratch_size
;
1916 if (compute_scratch_bo
!= queue
->compute_scratch_bo
) {
1917 if (queue
->compute_scratch_bo
)
1918 queue
->device
->ws
->buffer_destroy(queue
->compute_scratch_bo
);
1919 queue
->compute_scratch_bo
= compute_scratch_bo
;
1920 queue
->compute_scratch_size
= compute_scratch_size
;
1923 if (esgs_ring_bo
!= queue
->esgs_ring_bo
) {
1924 if (queue
->esgs_ring_bo
)
1925 queue
->device
->ws
->buffer_destroy(queue
->esgs_ring_bo
);
1926 queue
->esgs_ring_bo
= esgs_ring_bo
;
1927 queue
->esgs_ring_size
= esgs_ring_size
;
1930 if (gsvs_ring_bo
!= queue
->gsvs_ring_bo
) {
1931 if (queue
->gsvs_ring_bo
)
1932 queue
->device
->ws
->buffer_destroy(queue
->gsvs_ring_bo
);
1933 queue
->gsvs_ring_bo
= gsvs_ring_bo
;
1934 queue
->gsvs_ring_size
= gsvs_ring_size
;
1937 if (tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
) {
1938 queue
->tess_factor_ring_bo
= tess_factor_ring_bo
;
1941 if (tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
) {
1942 queue
->tess_offchip_ring_bo
= tess_offchip_ring_bo
;
1943 queue
->has_tess_rings
= true;
1946 if (descriptor_bo
!= queue
->descriptor_bo
) {
1947 if (queue
->descriptor_bo
)
1948 queue
->device
->ws
->buffer_destroy(queue
->descriptor_bo
);
1950 queue
->descriptor_bo
= descriptor_bo
;
1953 if (add_sample_positions
)
1954 queue
->has_sample_positions
= true;
1956 *initial_full_flush_preamble_cs
= queue
->initial_full_flush_preamble_cs
;
1957 *initial_preamble_cs
= queue
->initial_preamble_cs
;
1958 *continue_preamble_cs
= queue
->continue_preamble_cs
;
1959 if (!scratch_size
&& !compute_scratch_size
&& !esgs_ring_size
&& !gsvs_ring_size
)
1960 *continue_preamble_cs
= NULL
;
1963 for (int i
= 0; i
< ARRAY_SIZE(dest_cs
); ++i
)
1965 queue
->device
->ws
->cs_destroy(dest_cs
[i
]);
1966 if (descriptor_bo
&& descriptor_bo
!= queue
->descriptor_bo
)
1967 queue
->device
->ws
->buffer_destroy(descriptor_bo
);
1968 if (scratch_bo
&& scratch_bo
!= queue
->scratch_bo
)
1969 queue
->device
->ws
->buffer_destroy(scratch_bo
);
1970 if (compute_scratch_bo
&& compute_scratch_bo
!= queue
->compute_scratch_bo
)
1971 queue
->device
->ws
->buffer_destroy(compute_scratch_bo
);
1972 if (esgs_ring_bo
&& esgs_ring_bo
!= queue
->esgs_ring_bo
)
1973 queue
->device
->ws
->buffer_destroy(esgs_ring_bo
);
1974 if (gsvs_ring_bo
&& gsvs_ring_bo
!= queue
->gsvs_ring_bo
)
1975 queue
->device
->ws
->buffer_destroy(gsvs_ring_bo
);
1976 if (tess_factor_ring_bo
&& tess_factor_ring_bo
!= queue
->tess_factor_ring_bo
)
1977 queue
->device
->ws
->buffer_destroy(tess_factor_ring_bo
);
1978 if (tess_offchip_ring_bo
&& tess_offchip_ring_bo
!= queue
->tess_offchip_ring_bo
)
1979 queue
->device
->ws
->buffer_destroy(tess_offchip_ring_bo
);
1980 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
1983 static VkResult
radv_alloc_sem_counts(struct radv_winsys_sem_counts
*counts
,
1985 const VkSemaphore
*sems
,
1988 int syncobj_idx
= 0, sem_idx
= 0;
1992 for (uint32_t i
= 0; i
< num_sems
; i
++) {
1993 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
1995 if (sem
->temp_syncobj
|| sem
->syncobj
)
1996 counts
->syncobj_count
++;
1998 counts
->sem_count
++;
2001 if (counts
->syncobj_count
) {
2002 counts
->syncobj
= (uint32_t *)malloc(sizeof(uint32_t) * counts
->syncobj_count
);
2003 if (!counts
->syncobj
)
2004 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2007 if (counts
->sem_count
) {
2008 counts
->sem
= (struct radeon_winsys_sem
**)malloc(sizeof(struct radeon_winsys_sem
*) * counts
->sem_count
);
2010 free(counts
->syncobj
);
2011 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2015 for (uint32_t i
= 0; i
< num_sems
; i
++) {
2016 RADV_FROM_HANDLE(radv_semaphore
, sem
, sems
[i
]);
2018 if (sem
->temp_syncobj
) {
2019 counts
->syncobj
[syncobj_idx
++] = sem
->temp_syncobj
;
2021 /* after we wait on a temp import - drop it */
2022 sem
->temp_syncobj
= 0;
2025 else if (sem
->syncobj
)
2026 counts
->syncobj
[syncobj_idx
++] = sem
->syncobj
;
2029 counts
->sem
[sem_idx
++] = sem
->sem
;
2036 void radv_free_sem_info(struct radv_winsys_sem_info
*sem_info
)
2038 free(sem_info
->wait
.syncobj
);
2039 free(sem_info
->wait
.sem
);
2040 free(sem_info
->signal
.syncobj
);
2041 free(sem_info
->signal
.sem
);
2044 VkResult
radv_alloc_sem_info(struct radv_winsys_sem_info
*sem_info
,
2046 const VkSemaphore
*wait_sems
,
2047 int num_signal_sems
,
2048 const VkSemaphore
*signal_sems
)
2051 memset(sem_info
, 0, sizeof(*sem_info
));
2053 ret
= radv_alloc_sem_counts(&sem_info
->wait
, num_wait_sems
, wait_sems
, true);
2056 ret
= radv_alloc_sem_counts(&sem_info
->signal
, num_signal_sems
, signal_sems
, false);
2058 radv_free_sem_info(sem_info
);
2060 /* caller can override these */
2061 sem_info
->cs_emit_wait
= true;
2062 sem_info
->cs_emit_signal
= true;
2066 VkResult
radv_QueueSubmit(
2068 uint32_t submitCount
,
2069 const VkSubmitInfo
* pSubmits
,
2072 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2073 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2074 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2075 struct radeon_winsys_ctx
*ctx
= queue
->hw_ctx
;
2077 uint32_t max_cs_submission
= queue
->device
->trace_bo
? 1 : UINT32_MAX
;
2078 uint32_t scratch_size
= 0;
2079 uint32_t compute_scratch_size
= 0;
2080 uint32_t esgs_ring_size
= 0, gsvs_ring_size
= 0;
2081 struct radeon_winsys_cs
*initial_preamble_cs
= NULL
, *initial_flush_preamble_cs
= NULL
, *continue_preamble_cs
= NULL
;
2083 bool fence_emitted
= false;
2084 bool tess_rings_needed
= false;
2085 bool sample_positions_needed
= false;
2087 /* Do this first so failing to allocate scratch buffers can't result in
2088 * partially executed submissions. */
2089 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2090 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2091 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2092 pSubmits
[i
].pCommandBuffers
[j
]);
2094 scratch_size
= MAX2(scratch_size
, cmd_buffer
->scratch_size_needed
);
2095 compute_scratch_size
= MAX2(compute_scratch_size
,
2096 cmd_buffer
->compute_scratch_size_needed
);
2097 esgs_ring_size
= MAX2(esgs_ring_size
, cmd_buffer
->esgs_ring_size_needed
);
2098 gsvs_ring_size
= MAX2(gsvs_ring_size
, cmd_buffer
->gsvs_ring_size_needed
);
2099 tess_rings_needed
|= cmd_buffer
->tess_rings_needed
;
2100 sample_positions_needed
|= cmd_buffer
->sample_positions_needed
;
2104 result
= radv_get_preamble_cs(queue
, scratch_size
, compute_scratch_size
,
2105 esgs_ring_size
, gsvs_ring_size
, tess_rings_needed
,
2106 sample_positions_needed
, &initial_flush_preamble_cs
,
2107 &initial_preamble_cs
, &continue_preamble_cs
);
2108 if (result
!= VK_SUCCESS
)
2111 for (uint32_t i
= 0; i
< submitCount
; i
++) {
2112 struct radeon_winsys_cs
**cs_array
;
2113 bool do_flush
= !i
|| pSubmits
[i
].pWaitDstStageMask
;
2114 bool can_patch
= true;
2116 struct radv_winsys_sem_info sem_info
;
2118 result
= radv_alloc_sem_info(&sem_info
,
2119 pSubmits
[i
].waitSemaphoreCount
,
2120 pSubmits
[i
].pWaitSemaphores
,
2121 pSubmits
[i
].signalSemaphoreCount
,
2122 pSubmits
[i
].pSignalSemaphores
);
2123 if (result
!= VK_SUCCESS
)
2126 if (!pSubmits
[i
].commandBufferCount
) {
2127 if (pSubmits
[i
].waitSemaphoreCount
|| pSubmits
[i
].signalSemaphoreCount
) {
2128 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2129 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2134 radv_loge("failed to submit CS %d\n", i
);
2137 fence_emitted
= true;
2139 radv_free_sem_info(&sem_info
);
2143 cs_array
= malloc(sizeof(struct radeon_winsys_cs
*) *
2144 (pSubmits
[i
].commandBufferCount
));
2146 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
++) {
2147 RADV_FROM_HANDLE(radv_cmd_buffer
, cmd_buffer
,
2148 pSubmits
[i
].pCommandBuffers
[j
]);
2149 assert(cmd_buffer
->level
== VK_COMMAND_BUFFER_LEVEL_PRIMARY
);
2151 cs_array
[j
] = cmd_buffer
->cs
;
2152 if ((cmd_buffer
->usage_flags
& VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT
))
2156 for (uint32_t j
= 0; j
< pSubmits
[i
].commandBufferCount
; j
+= advance
) {
2157 struct radeon_winsys_cs
*initial_preamble
= (do_flush
&& !j
) ? initial_flush_preamble_cs
: initial_preamble_cs
;
2158 advance
= MIN2(max_cs_submission
,
2159 pSubmits
[i
].commandBufferCount
- j
);
2161 if (queue
->device
->trace_bo
)
2162 *queue
->device
->trace_id_ptr
= 0;
2164 sem_info
.cs_emit_wait
= j
== 0;
2165 sem_info
.cs_emit_signal
= j
+ advance
== pSubmits
[i
].commandBufferCount
;
2167 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
, cs_array
+ j
,
2168 advance
, initial_preamble
, continue_preamble_cs
,
2170 can_patch
, base_fence
);
2173 radv_loge("failed to submit CS %d\n", i
);
2176 fence_emitted
= true;
2177 if (queue
->device
->trace_bo
) {
2178 radv_check_gpu_hangs(queue
, cs_array
[j
]);
2182 radv_free_sem_info(&sem_info
);
2187 if (!fence_emitted
) {
2188 struct radv_winsys_sem_info sem_info
= {0};
2189 ret
= queue
->device
->ws
->cs_submit(ctx
, queue
->queue_idx
,
2190 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2191 1, NULL
, NULL
, &sem_info
,
2194 fence
->submitted
= true;
2200 VkResult
radv_QueueWaitIdle(
2203 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2205 queue
->device
->ws
->ctx_wait_idle(queue
->hw_ctx
,
2206 radv_queue_family_to_ring(queue
->queue_family_index
),
2211 VkResult
radv_DeviceWaitIdle(
2214 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2216 for (unsigned i
= 0; i
< RADV_MAX_QUEUE_FAMILIES
; i
++) {
2217 for (unsigned q
= 0; q
< device
->queue_count
[i
]; q
++) {
2218 radv_QueueWaitIdle(radv_queue_to_handle(&device
->queues
[i
][q
]));
2224 PFN_vkVoidFunction
radv_GetInstanceProcAddr(
2225 VkInstance instance
,
2228 return radv_lookup_entrypoint(pName
);
2231 /* The loader wants us to expose a second GetInstanceProcAddr function
2232 * to work around certain LD_PRELOAD issues seen in apps.
2235 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2236 VkInstance instance
,
2240 VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL
vk_icdGetInstanceProcAddr(
2241 VkInstance instance
,
2244 return radv_GetInstanceProcAddr(instance
, pName
);
2247 PFN_vkVoidFunction
radv_GetDeviceProcAddr(
2251 return radv_lookup_entrypoint(pName
);
2254 bool radv_get_memory_fd(struct radv_device
*device
,
2255 struct radv_device_memory
*memory
,
2258 struct radeon_bo_metadata metadata
;
2260 if (memory
->image
) {
2261 radv_init_metadata(device
, memory
->image
, &metadata
);
2262 device
->ws
->buffer_set_metadata(memory
->bo
, &metadata
);
2265 return device
->ws
->buffer_get_fd(device
->ws
, memory
->bo
,
2269 VkResult
radv_AllocateMemory(
2271 const VkMemoryAllocateInfo
* pAllocateInfo
,
2272 const VkAllocationCallbacks
* pAllocator
,
2273 VkDeviceMemory
* pMem
)
2275 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2276 struct radv_device_memory
*mem
;
2278 enum radeon_bo_domain domain
;
2281 assert(pAllocateInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO
);
2283 if (pAllocateInfo
->allocationSize
== 0) {
2284 /* Apparently, this is allowed */
2285 *pMem
= VK_NULL_HANDLE
;
2289 const VkImportMemoryFdInfoKHR
*import_info
=
2290 vk_find_struct_const(pAllocateInfo
->pNext
, IMPORT_MEMORY_FD_INFO_KHR
);
2291 const VkMemoryDedicatedAllocateInfoKHR
*dedicate_info
=
2292 vk_find_struct_const(pAllocateInfo
->pNext
, MEMORY_DEDICATED_ALLOCATE_INFO_KHR
);
2294 mem
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*mem
), 8,
2295 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2297 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2299 if (dedicate_info
) {
2300 mem
->image
= radv_image_from_handle(dedicate_info
->image
);
2301 mem
->buffer
= radv_buffer_from_handle(dedicate_info
->buffer
);
2308 assert(import_info
->handleType
==
2309 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
2310 mem
->bo
= device
->ws
->buffer_from_fd(device
->ws
, import_info
->fd
,
2313 result
= VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
2316 close(import_info
->fd
);
2321 uint64_t alloc_size
= align_u64(pAllocateInfo
->allocationSize
, 4096);
2322 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
||
2323 pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_CACHED
)
2324 domain
= RADEON_DOMAIN_GTT
;
2326 domain
= RADEON_DOMAIN_VRAM
;
2328 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_VRAM
)
2329 flags
|= RADEON_FLAG_NO_CPU_ACCESS
;
2331 flags
|= RADEON_FLAG_CPU_ACCESS
;
2333 if (pAllocateInfo
->memoryTypeIndex
== RADV_MEM_TYPE_GTT_WRITE_COMBINE
)
2334 flags
|= RADEON_FLAG_GTT_WC
;
2336 mem
->bo
= device
->ws
->buffer_create(device
->ws
, alloc_size
, device
->physical_device
->rad_info
.max_alignment
,
2340 result
= VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2343 mem
->type_index
= pAllocateInfo
->memoryTypeIndex
;
2345 *pMem
= radv_device_memory_to_handle(mem
);
2350 vk_free2(&device
->alloc
, pAllocator
, mem
);
2355 void radv_FreeMemory(
2357 VkDeviceMemory _mem
,
2358 const VkAllocationCallbacks
* pAllocator
)
2360 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2361 RADV_FROM_HANDLE(radv_device_memory
, mem
, _mem
);
2366 device
->ws
->buffer_destroy(mem
->bo
);
2369 vk_free2(&device
->alloc
, pAllocator
, mem
);
2372 VkResult
radv_MapMemory(
2374 VkDeviceMemory _memory
,
2375 VkDeviceSize offset
,
2377 VkMemoryMapFlags flags
,
2380 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2381 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2388 *ppData
= device
->ws
->buffer_map(mem
->bo
);
2394 return VK_ERROR_MEMORY_MAP_FAILED
;
2397 void radv_UnmapMemory(
2399 VkDeviceMemory _memory
)
2401 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2402 RADV_FROM_HANDLE(radv_device_memory
, mem
, _memory
);
2407 device
->ws
->buffer_unmap(mem
->bo
);
2410 VkResult
radv_FlushMappedMemoryRanges(
2412 uint32_t memoryRangeCount
,
2413 const VkMappedMemoryRange
* pMemoryRanges
)
2418 VkResult
radv_InvalidateMappedMemoryRanges(
2420 uint32_t memoryRangeCount
,
2421 const VkMappedMemoryRange
* pMemoryRanges
)
2426 void radv_GetBufferMemoryRequirements(
2429 VkMemoryRequirements
* pMemoryRequirements
)
2431 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2433 pMemoryRequirements
->memoryTypeBits
= (1u << RADV_MEM_TYPE_COUNT
) - 1;
2435 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2436 pMemoryRequirements
->alignment
= 4096;
2438 pMemoryRequirements
->alignment
= 16;
2440 pMemoryRequirements
->size
= align64(buffer
->size
, pMemoryRequirements
->alignment
);
2443 void radv_GetBufferMemoryRequirements2KHR(
2445 const VkBufferMemoryRequirementsInfo2KHR
* pInfo
,
2446 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2448 radv_GetBufferMemoryRequirements(device
, pInfo
->buffer
,
2449 &pMemoryRequirements
->memoryRequirements
);
2451 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2452 switch (ext
->sType
) {
2453 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2454 VkMemoryDedicatedRequirementsKHR
*req
=
2455 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2456 req
->requiresDedicatedAllocation
= false;
2457 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2466 void radv_GetImageMemoryRequirements(
2469 VkMemoryRequirements
* pMemoryRequirements
)
2471 RADV_FROM_HANDLE(radv_image
, image
, _image
);
2473 pMemoryRequirements
->memoryTypeBits
= (1u << RADV_MEM_TYPE_COUNT
) - 1;
2475 pMemoryRequirements
->size
= image
->size
;
2476 pMemoryRequirements
->alignment
= image
->alignment
;
2479 void radv_GetImageMemoryRequirements2KHR(
2481 const VkImageMemoryRequirementsInfo2KHR
* pInfo
,
2482 VkMemoryRequirements2KHR
* pMemoryRequirements
)
2484 radv_GetImageMemoryRequirements(device
, pInfo
->image
,
2485 &pMemoryRequirements
->memoryRequirements
);
2487 RADV_FROM_HANDLE(radv_image
, image
, pInfo
->image
);
2489 vk_foreach_struct(ext
, pMemoryRequirements
->pNext
) {
2490 switch (ext
->sType
) {
2491 case VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS_KHR
: {
2492 VkMemoryDedicatedRequirementsKHR
*req
=
2493 (VkMemoryDedicatedRequirementsKHR
*) ext
;
2494 req
->requiresDedicatedAllocation
= image
->shareable
;
2495 req
->prefersDedicatedAllocation
= req
->requiresDedicatedAllocation
;
2504 void radv_GetImageSparseMemoryRequirements(
2507 uint32_t* pSparseMemoryRequirementCount
,
2508 VkSparseImageMemoryRequirements
* pSparseMemoryRequirements
)
2513 void radv_GetImageSparseMemoryRequirements2KHR(
2515 const VkImageSparseMemoryRequirementsInfo2KHR
* pInfo
,
2516 uint32_t* pSparseMemoryRequirementCount
,
2517 VkSparseImageMemoryRequirements2KHR
* pSparseMemoryRequirements
)
2522 void radv_GetDeviceMemoryCommitment(
2524 VkDeviceMemory memory
,
2525 VkDeviceSize
* pCommittedMemoryInBytes
)
2527 *pCommittedMemoryInBytes
= 0;
2530 VkResult
radv_BindBufferMemory2KHR(VkDevice device
,
2531 uint32_t bindInfoCount
,
2532 const VkBindBufferMemoryInfoKHR
*pBindInfos
)
2534 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2535 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2536 RADV_FROM_HANDLE(radv_buffer
, buffer
, pBindInfos
[i
].buffer
);
2539 buffer
->bo
= mem
->bo
;
2540 buffer
->offset
= pBindInfos
[i
].memoryOffset
;
2548 VkResult
radv_BindBufferMemory(
2551 VkDeviceMemory memory
,
2552 VkDeviceSize memoryOffset
)
2554 const VkBindBufferMemoryInfoKHR info
= {
2555 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2558 .memoryOffset
= memoryOffset
2561 return radv_BindBufferMemory2KHR(device
, 1, &info
);
2564 VkResult
radv_BindImageMemory2KHR(VkDevice device
,
2565 uint32_t bindInfoCount
,
2566 const VkBindImageMemoryInfoKHR
*pBindInfos
)
2568 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2569 RADV_FROM_HANDLE(radv_device_memory
, mem
, pBindInfos
[i
].memory
);
2570 RADV_FROM_HANDLE(radv_image
, image
, pBindInfos
[i
].image
);
2573 image
->bo
= mem
->bo
;
2574 image
->offset
= pBindInfos
[i
].memoryOffset
;
2584 VkResult
radv_BindImageMemory(
2587 VkDeviceMemory memory
,
2588 VkDeviceSize memoryOffset
)
2590 const VkBindImageMemoryInfoKHR info
= {
2591 .sType
= VK_STRUCTURE_TYPE_BIND_BUFFER_MEMORY_INFO_KHR
,
2594 .memoryOffset
= memoryOffset
2597 return radv_BindImageMemory2KHR(device
, 1, &info
);
2602 radv_sparse_buffer_bind_memory(struct radv_device
*device
,
2603 const VkSparseBufferMemoryBindInfo
*bind
)
2605 RADV_FROM_HANDLE(radv_buffer
, buffer
, bind
->buffer
);
2607 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
2608 struct radv_device_memory
*mem
= NULL
;
2610 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
2611 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
2613 device
->ws
->buffer_virtual_bind(buffer
->bo
,
2614 bind
->pBinds
[i
].resourceOffset
,
2615 bind
->pBinds
[i
].size
,
2616 mem
? mem
->bo
: NULL
,
2617 bind
->pBinds
[i
].memoryOffset
);
2622 radv_sparse_image_opaque_bind_memory(struct radv_device
*device
,
2623 const VkSparseImageOpaqueMemoryBindInfo
*bind
)
2625 RADV_FROM_HANDLE(radv_image
, image
, bind
->image
);
2627 for (uint32_t i
= 0; i
< bind
->bindCount
; ++i
) {
2628 struct radv_device_memory
*mem
= NULL
;
2630 if (bind
->pBinds
[i
].memory
!= VK_NULL_HANDLE
)
2631 mem
= radv_device_memory_from_handle(bind
->pBinds
[i
].memory
);
2633 device
->ws
->buffer_virtual_bind(image
->bo
,
2634 bind
->pBinds
[i
].resourceOffset
,
2635 bind
->pBinds
[i
].size
,
2636 mem
? mem
->bo
: NULL
,
2637 bind
->pBinds
[i
].memoryOffset
);
2641 VkResult
radv_QueueBindSparse(
2643 uint32_t bindInfoCount
,
2644 const VkBindSparseInfo
* pBindInfo
,
2647 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2648 RADV_FROM_HANDLE(radv_queue
, queue
, _queue
);
2649 struct radeon_winsys_fence
*base_fence
= fence
? fence
->fence
: NULL
;
2650 bool fence_emitted
= false;
2652 for (uint32_t i
= 0; i
< bindInfoCount
; ++i
) {
2653 struct radv_winsys_sem_info sem_info
;
2654 for (uint32_t j
= 0; j
< pBindInfo
[i
].bufferBindCount
; ++j
) {
2655 radv_sparse_buffer_bind_memory(queue
->device
,
2656 pBindInfo
[i
].pBufferBinds
+ j
);
2659 for (uint32_t j
= 0; j
< pBindInfo
[i
].imageOpaqueBindCount
; ++j
) {
2660 radv_sparse_image_opaque_bind_memory(queue
->device
,
2661 pBindInfo
[i
].pImageOpaqueBinds
+ j
);
2665 result
= radv_alloc_sem_info(&sem_info
,
2666 pBindInfo
[i
].waitSemaphoreCount
,
2667 pBindInfo
[i
].pWaitSemaphores
,
2668 pBindInfo
[i
].signalSemaphoreCount
,
2669 pBindInfo
[i
].pSignalSemaphores
);
2670 if (result
!= VK_SUCCESS
)
2673 if (pBindInfo
[i
].waitSemaphoreCount
|| pBindInfo
[i
].signalSemaphoreCount
) {
2674 queue
->device
->ws
->cs_submit(queue
->hw_ctx
, queue
->queue_idx
,
2675 &queue
->device
->empty_cs
[queue
->queue_family_index
],
2679 fence_emitted
= true;
2681 fence
->submitted
= true;
2684 radv_free_sem_info(&sem_info
);
2688 if (fence
&& !fence_emitted
) {
2689 fence
->signalled
= true;
2695 VkResult
radv_CreateFence(
2697 const VkFenceCreateInfo
* pCreateInfo
,
2698 const VkAllocationCallbacks
* pAllocator
,
2701 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2702 struct radv_fence
*fence
= vk_alloc2(&device
->alloc
, pAllocator
,
2704 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2707 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2709 memset(fence
, 0, sizeof(*fence
));
2710 fence
->submitted
= false;
2711 fence
->signalled
= !!(pCreateInfo
->flags
& VK_FENCE_CREATE_SIGNALED_BIT
);
2712 fence
->fence
= device
->ws
->create_fence();
2713 if (!fence
->fence
) {
2714 vk_free2(&device
->alloc
, pAllocator
, fence
);
2715 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2718 *pFence
= radv_fence_to_handle(fence
);
2723 void radv_DestroyFence(
2726 const VkAllocationCallbacks
* pAllocator
)
2728 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2729 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2733 device
->ws
->destroy_fence(fence
->fence
);
2734 vk_free2(&device
->alloc
, pAllocator
, fence
);
2737 static uint64_t radv_get_absolute_timeout(uint64_t timeout
)
2739 uint64_t current_time
;
2742 clock_gettime(CLOCK_MONOTONIC
, &tv
);
2743 current_time
= tv
.tv_nsec
+ tv
.tv_sec
*1000000000ull;
2745 timeout
= MIN2(UINT64_MAX
- current_time
, timeout
);
2747 return current_time
+ timeout
;
2750 VkResult
radv_WaitForFences(
2752 uint32_t fenceCount
,
2753 const VkFence
* pFences
,
2757 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2758 timeout
= radv_get_absolute_timeout(timeout
);
2760 if (!waitAll
&& fenceCount
> 1) {
2761 fprintf(stderr
, "radv: WaitForFences without waitAll not implemented yet\n");
2764 for (uint32_t i
= 0; i
< fenceCount
; ++i
) {
2765 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
2766 bool expired
= false;
2768 if (fence
->signalled
)
2771 if (!fence
->submitted
)
2774 expired
= device
->ws
->fence_wait(device
->ws
, fence
->fence
, true, timeout
);
2778 fence
->signalled
= true;
2784 VkResult
radv_ResetFences(VkDevice device
,
2785 uint32_t fenceCount
,
2786 const VkFence
*pFences
)
2788 for (unsigned i
= 0; i
< fenceCount
; ++i
) {
2789 RADV_FROM_HANDLE(radv_fence
, fence
, pFences
[i
]);
2790 fence
->submitted
= fence
->signalled
= false;
2796 VkResult
radv_GetFenceStatus(VkDevice _device
, VkFence _fence
)
2798 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2799 RADV_FROM_HANDLE(radv_fence
, fence
, _fence
);
2801 if (fence
->signalled
)
2803 if (!fence
->submitted
)
2804 return VK_NOT_READY
;
2806 if (!device
->ws
->fence_wait(device
->ws
, fence
->fence
, false, 0))
2807 return VK_NOT_READY
;
2813 // Queue semaphore functions
2815 VkResult
radv_CreateSemaphore(
2817 const VkSemaphoreCreateInfo
* pCreateInfo
,
2818 const VkAllocationCallbacks
* pAllocator
,
2819 VkSemaphore
* pSemaphore
)
2821 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2822 const VkExportSemaphoreCreateInfoKHR
*export
=
2823 vk_find_struct_const(pCreateInfo
->pNext
, EXPORT_SEMAPHORE_CREATE_INFO_KHR
);
2824 VkExternalSemaphoreHandleTypeFlagsKHR handleTypes
=
2825 export
? export
->handleTypes
: 0;
2827 struct radv_semaphore
*sem
= vk_alloc2(&device
->alloc
, pAllocator
,
2829 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2831 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2833 sem
->temp_syncobj
= 0;
2834 /* create a syncobject if we are going to export this semaphore */
2836 assert (device
->physical_device
->rad_info
.has_syncobj
);
2837 assert (handleTypes
== VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
2838 int ret
= device
->ws
->create_syncobj(device
->ws
, &sem
->syncobj
);
2840 vk_free2(&device
->alloc
, pAllocator
, sem
);
2841 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2845 sem
->sem
= device
->ws
->create_sem(device
->ws
);
2847 vk_free2(&device
->alloc
, pAllocator
, sem
);
2848 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2853 *pSemaphore
= radv_semaphore_to_handle(sem
);
2857 void radv_DestroySemaphore(
2859 VkSemaphore _semaphore
,
2860 const VkAllocationCallbacks
* pAllocator
)
2862 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2863 RADV_FROM_HANDLE(radv_semaphore
, sem
, _semaphore
);
2868 device
->ws
->destroy_syncobj(device
->ws
, sem
->syncobj
);
2870 device
->ws
->destroy_sem(sem
->sem
);
2871 vk_free2(&device
->alloc
, pAllocator
, sem
);
2874 VkResult
radv_CreateEvent(
2876 const VkEventCreateInfo
* pCreateInfo
,
2877 const VkAllocationCallbacks
* pAllocator
,
2880 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2881 struct radv_event
*event
= vk_alloc2(&device
->alloc
, pAllocator
,
2883 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2886 return VK_ERROR_OUT_OF_HOST_MEMORY
;
2888 event
->bo
= device
->ws
->buffer_create(device
->ws
, 8, 8,
2890 RADEON_FLAG_VA_UNCACHED
| RADEON_FLAG_CPU_ACCESS
);
2892 vk_free2(&device
->alloc
, pAllocator
, event
);
2893 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
2896 event
->map
= (uint64_t*)device
->ws
->buffer_map(event
->bo
);
2898 *pEvent
= radv_event_to_handle(event
);
2903 void radv_DestroyEvent(
2906 const VkAllocationCallbacks
* pAllocator
)
2908 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2909 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2913 device
->ws
->buffer_destroy(event
->bo
);
2914 vk_free2(&device
->alloc
, pAllocator
, event
);
2917 VkResult
radv_GetEventStatus(
2921 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2923 if (*event
->map
== 1)
2924 return VK_EVENT_SET
;
2925 return VK_EVENT_RESET
;
2928 VkResult
radv_SetEvent(
2932 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2938 VkResult
radv_ResetEvent(
2942 RADV_FROM_HANDLE(radv_event
, event
, _event
);
2948 VkResult
radv_CreateBuffer(
2950 const VkBufferCreateInfo
* pCreateInfo
,
2951 const VkAllocationCallbacks
* pAllocator
,
2954 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2955 struct radv_buffer
*buffer
;
2957 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO
);
2959 buffer
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*buffer
), 8,
2960 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2962 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2964 buffer
->size
= pCreateInfo
->size
;
2965 buffer
->usage
= pCreateInfo
->usage
;
2968 buffer
->flags
= pCreateInfo
->flags
;
2970 if (pCreateInfo
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
) {
2971 buffer
->bo
= device
->ws
->buffer_create(device
->ws
,
2972 align64(buffer
->size
, 4096),
2973 4096, 0, RADEON_FLAG_VIRTUAL
);
2975 vk_free2(&device
->alloc
, pAllocator
, buffer
);
2976 return vk_error(VK_ERROR_OUT_OF_DEVICE_MEMORY
);
2980 *pBuffer
= radv_buffer_to_handle(buffer
);
2985 void radv_DestroyBuffer(
2988 const VkAllocationCallbacks
* pAllocator
)
2990 RADV_FROM_HANDLE(radv_device
, device
, _device
);
2991 RADV_FROM_HANDLE(radv_buffer
, buffer
, _buffer
);
2996 if (buffer
->flags
& VK_BUFFER_CREATE_SPARSE_BINDING_BIT
)
2997 device
->ws
->buffer_destroy(buffer
->bo
);
2999 vk_free2(&device
->alloc
, pAllocator
, buffer
);
3002 static inline unsigned
3003 si_tile_mode_index(const struct radv_image
*image
, unsigned level
, bool stencil
)
3006 return image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3008 return image
->surface
.u
.legacy
.tiling_index
[level
];
3011 static uint32_t radv_surface_layer_count(struct radv_image_view
*iview
)
3013 return iview
->type
== VK_IMAGE_VIEW_TYPE_3D
? iview
->extent
.depth
: iview
->layer_count
;
3017 radv_initialise_color_surface(struct radv_device
*device
,
3018 struct radv_color_buffer_info
*cb
,
3019 struct radv_image_view
*iview
)
3021 const struct vk_format_description
*desc
;
3022 unsigned ntype
, format
, swap
, endian
;
3023 unsigned blend_clamp
= 0, blend_bypass
= 0;
3025 const struct radeon_surf
*surf
= &iview
->image
->surface
;
3027 desc
= vk_format_description(iview
->vk_format
);
3029 memset(cb
, 0, sizeof(*cb
));
3031 /* Intensity is implemented as Red, so treat it that way. */
3032 cb
->cb_color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == VK_SWIZZLE_1
);
3034 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3036 cb
->cb_color_base
= va
>> 8;
3038 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3039 struct gfx9_surf_meta_flags meta
;
3040 if (iview
->image
->dcc_offset
)
3041 meta
= iview
->image
->surface
.u
.gfx9
.dcc
;
3043 meta
= iview
->image
->surface
.u
.gfx9
.cmask
;
3045 cb
->cb_color_attrib
|= S_028C74_COLOR_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3046 S_028C74_FMASK_SW_MODE(iview
->image
->surface
.u
.gfx9
.fmask
.swizzle_mode
) |
3047 S_028C74_RB_ALIGNED(meta
.rb_aligned
) |
3048 S_028C74_PIPE_ALIGNED(meta
.pipe_aligned
);
3050 cb
->cb_color_base
+= iview
->image
->surface
.u
.gfx9
.surf_offset
>> 8;
3051 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3053 const struct legacy_surf_level
*level_info
= &surf
->u
.legacy
.level
[iview
->base_mip
];
3054 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
3056 cb
->cb_color_base
+= level_info
->offset
>> 8;
3057 if (level_info
->mode
== RADEON_SURF_MODE_2D
)
3058 cb
->cb_color_base
|= iview
->image
->surface
.tile_swizzle
;
3060 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
3061 slice_tile_max
= (level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1;
3062 tile_mode_index
= si_tile_mode_index(iview
->image
, iview
->base_mip
, false);
3064 cb
->cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
3065 cb
->cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
3066 cb
->cb_color_cmask_slice
= iview
->image
->cmask
.slice_tile_max
;
3068 cb
->cb_color_attrib
|= S_028C74_TILE_MODE_INDEX(tile_mode_index
);
3069 cb
->micro_tile_mode
= iview
->image
->surface
.micro_tile_mode
;
3071 if (iview
->image
->fmask
.size
) {
3072 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3073 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(iview
->image
->fmask
.pitch_in_pixels
/ 8 - 1);
3074 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(iview
->image
->fmask
.tile_mode_index
);
3075 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(iview
->image
->fmask
.slice_tile_max
);
3077 /* This must be set for fast clear to work without FMASK. */
3078 if (device
->physical_device
->rad_info
.chip_class
>= CIK
)
3079 cb
->cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
3080 cb
->cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
3081 cb
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
3085 /* CMASK variables */
3086 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3087 va
+= iview
->image
->cmask
.offset
;
3088 cb
->cb_color_cmask
= va
>> 8;
3090 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3091 va
+= iview
->image
->dcc_offset
;
3092 cb
->cb_dcc_base
= va
>> 8;
3093 cb
->cb_dcc_base
|= iview
->image
->surface
.tile_swizzle
;
3095 uint32_t max_slice
= radv_surface_layer_count(iview
);
3096 cb
->cb_color_view
= S_028C6C_SLICE_START(iview
->base_layer
) |
3097 S_028C6C_SLICE_MAX(iview
->base_layer
+ max_slice
- 1);
3099 if (iview
->image
->info
.samples
> 1) {
3100 unsigned log_samples
= util_logbase2(iview
->image
->info
.samples
);
3102 cb
->cb_color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
3103 S_028C74_NUM_FRAGMENTS(log_samples
);
3106 if (iview
->image
->fmask
.size
) {
3107 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+ iview
->image
->fmask
.offset
;
3108 cb
->cb_color_fmask
= va
>> 8;
3109 cb
->cb_color_fmask
|= iview
->image
->fmask
.tile_swizzle
;
3111 cb
->cb_color_fmask
= cb
->cb_color_base
;
3114 ntype
= radv_translate_color_numformat(iview
->vk_format
,
3116 vk_format_get_first_non_void_channel(iview
->vk_format
));
3117 format
= radv_translate_colorformat(iview
->vk_format
);
3118 if (format
== V_028C70_COLOR_INVALID
|| ntype
== ~0u)
3119 radv_finishme("Illegal color\n");
3120 swap
= radv_translate_colorswap(iview
->vk_format
, FALSE
);
3121 endian
= radv_colorformat_endian_swap(format
);
3123 /* blend clamp should be set for all NORM/SRGB types */
3124 if (ntype
== V_028C70_NUMBER_UNORM
||
3125 ntype
== V_028C70_NUMBER_SNORM
||
3126 ntype
== V_028C70_NUMBER_SRGB
)
3129 /* set blend bypass according to docs if SINT/UINT or
3130 8/24 COLOR variants */
3131 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
3132 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
3133 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
3138 if ((ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) &&
3139 (format
== V_028C70_COLOR_8
||
3140 format
== V_028C70_COLOR_8_8
||
3141 format
== V_028C70_COLOR_8_8_8_8
))
3142 ->color_is_int8
= true;
3144 cb
->cb_color_info
= S_028C70_FORMAT(format
) |
3145 S_028C70_COMP_SWAP(swap
) |
3146 S_028C70_BLEND_CLAMP(blend_clamp
) |
3147 S_028C70_BLEND_BYPASS(blend_bypass
) |
3148 S_028C70_SIMPLE_FLOAT(1) |
3149 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
3150 ntype
!= V_028C70_NUMBER_SNORM
&&
3151 ntype
!= V_028C70_NUMBER_SRGB
&&
3152 format
!= V_028C70_COLOR_8_24
&&
3153 format
!= V_028C70_COLOR_24_8
) |
3154 S_028C70_NUMBER_TYPE(ntype
) |
3155 S_028C70_ENDIAN(endian
);
3156 if ((iview
->image
->info
.samples
> 1) && iview
->image
->fmask
.size
) {
3157 cb
->cb_color_info
|= S_028C70_COMPRESSION(1);
3158 if (device
->physical_device
->rad_info
.chip_class
== SI
) {
3159 unsigned fmask_bankh
= util_logbase2(iview
->image
->fmask
.bank_height
);
3160 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
3164 if (iview
->image
->cmask
.size
&&
3165 !(device
->instance
->debug_flags
& RADV_DEBUG_NO_FAST_CLEARS
))
3166 cb
->cb_color_info
|= S_028C70_FAST_CLEAR(1);
3168 if (radv_vi_dcc_enabled(iview
->image
, iview
->base_mip
))
3169 cb
->cb_color_info
|= S_028C70_DCC_ENABLE(1);
3171 if (device
->physical_device
->rad_info
.chip_class
>= VI
) {
3172 unsigned max_uncompressed_block_size
= 2;
3173 if (iview
->image
->info
.samples
> 1) {
3174 if (iview
->image
->surface
.bpe
== 1)
3175 max_uncompressed_block_size
= 0;
3176 else if (iview
->image
->surface
.bpe
== 2)
3177 max_uncompressed_block_size
= 1;
3180 cb
->cb_dcc_control
= S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
3181 S_028C78_INDEPENDENT_64B_BLOCKS(1);
3184 /* This must be set for fast clear to work without FMASK. */
3185 if (!iview
->image
->fmask
.size
&&
3186 device
->physical_device
->rad_info
.chip_class
== SI
) {
3187 unsigned bankh
= util_logbase2(iview
->image
->surface
.u
.legacy
.bankh
);
3188 cb
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
3191 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3192 unsigned mip0_depth
= iview
->image
->type
== VK_IMAGE_TYPE_3D
?
3193 (iview
->extent
.depth
- 1) : (iview
->image
->info
.array_size
- 1);
3195 cb
->cb_color_view
|= S_028C6C_MIP_LEVEL(iview
->base_mip
);
3196 cb
->cb_color_attrib
|= S_028C74_MIP0_DEPTH(mip0_depth
) |
3197 S_028C74_RESOURCE_TYPE(iview
->image
->surface
.u
.gfx9
.resource_type
);
3198 cb
->cb_color_attrib2
= S_028C68_MIP0_WIDTH(iview
->extent
.width
- 1) |
3199 S_028C68_MIP0_HEIGHT(iview
->extent
.height
- 1) |
3200 S_028C68_MAX_MIP(iview
->image
->info
.levels
- 1);
3202 cb
->gfx9_epitch
= S_0287A0_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3208 radv_initialise_ds_surface(struct radv_device
*device
,
3209 struct radv_ds_buffer_info
*ds
,
3210 struct radv_image_view
*iview
)
3212 unsigned level
= iview
->base_mip
;
3213 unsigned format
, stencil_format
;
3214 uint64_t va
, s_offs
, z_offs
;
3215 bool stencil_only
= false;
3216 memset(ds
, 0, sizeof(*ds
));
3217 switch (iview
->image
->vk_format
) {
3218 case VK_FORMAT_D24_UNORM_S8_UINT
:
3219 case VK_FORMAT_X8_D24_UNORM_PACK32
:
3220 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
3221 ds
->offset_scale
= 2.0f
;
3223 case VK_FORMAT_D16_UNORM
:
3224 case VK_FORMAT_D16_UNORM_S8_UINT
:
3225 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
3226 ds
->offset_scale
= 4.0f
;
3228 case VK_FORMAT_D32_SFLOAT
:
3229 case VK_FORMAT_D32_SFLOAT_S8_UINT
:
3230 ds
->pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
3231 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
3232 ds
->offset_scale
= 1.0f
;
3234 case VK_FORMAT_S8_UINT
:
3235 stencil_only
= true;
3241 format
= radv_translate_dbformat(iview
->image
->vk_format
);
3242 stencil_format
= iview
->image
->surface
.has_stencil
?
3243 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
3245 uint32_t max_slice
= radv_surface_layer_count(iview
);
3246 ds
->db_depth_view
= S_028008_SLICE_START(iview
->base_layer
) |
3247 S_028008_SLICE_MAX(iview
->base_layer
+ max_slice
- 1);
3249 ds
->db_htile_data_base
= 0;
3250 ds
->db_htile_surface
= 0;
3252 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
;
3253 s_offs
= z_offs
= va
;
3255 if (device
->physical_device
->rad_info
.chip_class
>= GFX9
) {
3256 assert(iview
->image
->surface
.u
.gfx9
.surf_offset
== 0);
3257 s_offs
+= iview
->image
->surface
.u
.gfx9
.stencil_offset
;
3259 ds
->db_z_info
= S_028038_FORMAT(format
) |
3260 S_028038_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
)) |
3261 S_028038_SW_MODE(iview
->image
->surface
.u
.gfx9
.surf
.swizzle_mode
) |
3262 S_028038_MAXMIP(iview
->image
->info
.levels
- 1);
3263 ds
->db_stencil_info
= S_02803C_FORMAT(stencil_format
) |
3264 S_02803C_SW_MODE(iview
->image
->surface
.u
.gfx9
.stencil
.swizzle_mode
);
3266 ds
->db_z_info2
= S_028068_EPITCH(iview
->image
->surface
.u
.gfx9
.surf
.epitch
);
3267 ds
->db_stencil_info2
= S_02806C_EPITCH(iview
->image
->surface
.u
.gfx9
.stencil
.epitch
);
3268 ds
->db_depth_view
|= S_028008_MIPID(level
);
3270 ds
->db_depth_size
= S_02801C_X_MAX(iview
->image
->info
.width
- 1) |
3271 S_02801C_Y_MAX(iview
->image
->info
.height
- 1);
3273 if (radv_htile_enabled(iview
->image
, level
)) {
3274 ds
->db_z_info
|= S_028038_TILE_SURFACE_ENABLE(1);
3276 if (iview
->image
->tc_compatible_htile
) {
3277 unsigned max_zplanes
= 4;
3279 if (iview
->vk_format
== VK_FORMAT_D16_UNORM
&&
3280 iview
->image
->info
.samples
> 1)
3283 ds
->db_z_info
|= S_028038_DECOMPRESS_ON_N_ZPLANES(max_zplanes
+ 1) |
3284 S_028038_ITERATE_FLUSH(1);
3285 ds
->db_stencil_info
|= S_02803C_ITERATE_FLUSH(1);
3288 if (!iview
->image
->surface
.has_stencil
)
3289 /* Use all of the htile_buffer for depth if there's no stencil. */
3290 ds
->db_stencil_info
|= S_02803C_TILE_STENCIL_DISABLE(1);
3291 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3292 iview
->image
->htile_offset
;
3293 ds
->db_htile_data_base
= va
>> 8;
3294 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1) |
3295 S_028ABC_PIPE_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.pipe_aligned
) |
3296 S_028ABC_RB_ALIGNED(iview
->image
->surface
.u
.gfx9
.htile
.rb_aligned
);
3299 const struct legacy_surf_level
*level_info
= &iview
->image
->surface
.u
.legacy
.level
[level
];
3302 level_info
= &iview
->image
->surface
.u
.legacy
.stencil_level
[level
];
3304 z_offs
+= iview
->image
->surface
.u
.legacy
.level
[level
].offset
;
3305 s_offs
+= iview
->image
->surface
.u
.legacy
.stencil_level
[level
].offset
;
3307 ds
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!iview
->image
->tc_compatible_htile
);
3308 ds
->db_z_info
= S_028040_FORMAT(format
) | S_028040_ZRANGE_PRECISION(1);
3309 ds
->db_stencil_info
= S_028044_FORMAT(stencil_format
);
3311 if (iview
->image
->info
.samples
> 1)
3312 ds
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(iview
->image
->info
.samples
));
3314 if (device
->physical_device
->rad_info
.chip_class
>= CIK
) {
3315 struct radeon_info
*info
= &device
->physical_device
->rad_info
;
3316 unsigned tiling_index
= iview
->image
->surface
.u
.legacy
.tiling_index
[level
];
3317 unsigned stencil_index
= iview
->image
->surface
.u
.legacy
.stencil_tiling_index
[level
];
3318 unsigned macro_index
= iview
->image
->surface
.u
.legacy
.macro_tile_index
;
3319 unsigned tile_mode
= info
->si_tile_mode_array
[tiling_index
];
3320 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
3321 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
3324 tile_mode
= stencil_tile_mode
;
3326 ds
->db_depth_info
|=
3327 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
3328 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
3329 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
3330 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
3331 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
3332 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
3333 ds
->db_z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
3334 ds
->db_stencil_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
3336 unsigned tile_mode_index
= si_tile_mode_index(iview
->image
, level
, false);
3337 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3338 tile_mode_index
= si_tile_mode_index(iview
->image
, level
, true);
3339 ds
->db_stencil_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
3341 ds
->db_z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
3344 ds
->db_depth_size
= S_028058_PITCH_TILE_MAX((level_info
->nblk_x
/ 8) - 1) |
3345 S_028058_HEIGHT_TILE_MAX((level_info
->nblk_y
/ 8) - 1);
3346 ds
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((level_info
->nblk_x
* level_info
->nblk_y
) / 64 - 1);
3348 if (radv_htile_enabled(iview
->image
, level
)) {
3349 ds
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
3351 if (!iview
->image
->surface
.has_stencil
&&
3352 !iview
->image
->tc_compatible_htile
)
3353 /* Use all of the htile_buffer for depth if there's no stencil. */
3354 ds
->db_stencil_info
|= S_028044_TILE_STENCIL_DISABLE(1);
3356 va
= radv_buffer_get_va(iview
->bo
) + iview
->image
->offset
+
3357 iview
->image
->htile_offset
;
3358 ds
->db_htile_data_base
= va
>> 8;
3359 ds
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
3361 if (iview
->image
->tc_compatible_htile
) {
3362 ds
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
3364 if (iview
->image
->info
.samples
<= 1)
3365 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(5);
3366 else if (iview
->image
->info
.samples
<= 4)
3367 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(3);
3369 ds
->db_z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(2);
3374 ds
->db_z_read_base
= ds
->db_z_write_base
= z_offs
>> 8;
3375 ds
->db_stencil_read_base
= ds
->db_stencil_write_base
= s_offs
>> 8;
3378 VkResult
radv_CreateFramebuffer(
3380 const VkFramebufferCreateInfo
* pCreateInfo
,
3381 const VkAllocationCallbacks
* pAllocator
,
3382 VkFramebuffer
* pFramebuffer
)
3384 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3385 struct radv_framebuffer
*framebuffer
;
3387 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO
);
3389 size_t size
= sizeof(*framebuffer
) +
3390 sizeof(struct radv_attachment_info
) * pCreateInfo
->attachmentCount
;
3391 framebuffer
= vk_alloc2(&device
->alloc
, pAllocator
, size
, 8,
3392 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3393 if (framebuffer
== NULL
)
3394 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3396 framebuffer
->attachment_count
= pCreateInfo
->attachmentCount
;
3397 framebuffer
->width
= pCreateInfo
->width
;
3398 framebuffer
->height
= pCreateInfo
->height
;
3399 framebuffer
->layers
= pCreateInfo
->layers
;
3400 for (uint32_t i
= 0; i
< pCreateInfo
->attachmentCount
; i
++) {
3401 VkImageView _iview
= pCreateInfo
->pAttachments
[i
];
3402 struct radv_image_view
*iview
= radv_image_view_from_handle(_iview
);
3403 framebuffer
->attachments
[i
].attachment
= iview
;
3404 if (iview
->aspect_mask
& VK_IMAGE_ASPECT_COLOR_BIT
) {
3405 radv_initialise_color_surface(device
, &framebuffer
->attachments
[i
].cb
, iview
);
3406 } else if (iview
->aspect_mask
& (VK_IMAGE_ASPECT_DEPTH_BIT
| VK_IMAGE_ASPECT_STENCIL_BIT
)) {
3407 radv_initialise_ds_surface(device
, &framebuffer
->attachments
[i
].ds
, iview
);
3409 framebuffer
->width
= MIN2(framebuffer
->width
, iview
->extent
.width
);
3410 framebuffer
->height
= MIN2(framebuffer
->height
, iview
->extent
.height
);
3411 framebuffer
->layers
= MIN2(framebuffer
->layers
, radv_surface_layer_count(iview
));
3414 *pFramebuffer
= radv_framebuffer_to_handle(framebuffer
);
3418 void radv_DestroyFramebuffer(
3421 const VkAllocationCallbacks
* pAllocator
)
3423 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3424 RADV_FROM_HANDLE(radv_framebuffer
, fb
, _fb
);
3428 vk_free2(&device
->alloc
, pAllocator
, fb
);
3431 static unsigned radv_tex_wrap(VkSamplerAddressMode address_mode
)
3433 switch (address_mode
) {
3434 case VK_SAMPLER_ADDRESS_MODE_REPEAT
:
3435 return V_008F30_SQ_TEX_WRAP
;
3436 case VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT
:
3437 return V_008F30_SQ_TEX_MIRROR
;
3438 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE
:
3439 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
3440 case VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
:
3441 return V_008F30_SQ_TEX_CLAMP_BORDER
;
3442 case VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE
:
3443 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
3445 unreachable("illegal tex wrap mode");
3451 radv_tex_compare(VkCompareOp op
)
3454 case VK_COMPARE_OP_NEVER
:
3455 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
3456 case VK_COMPARE_OP_LESS
:
3457 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
3458 case VK_COMPARE_OP_EQUAL
:
3459 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
3460 case VK_COMPARE_OP_LESS_OR_EQUAL
:
3461 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
3462 case VK_COMPARE_OP_GREATER
:
3463 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
3464 case VK_COMPARE_OP_NOT_EQUAL
:
3465 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
3466 case VK_COMPARE_OP_GREATER_OR_EQUAL
:
3467 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
3468 case VK_COMPARE_OP_ALWAYS
:
3469 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
3471 unreachable("illegal compare mode");
3477 radv_tex_filter(VkFilter filter
, unsigned max_ansio
)
3480 case VK_FILTER_NEAREST
:
3481 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_POINT
:
3482 V_008F38_SQ_TEX_XY_FILTER_POINT
);
3483 case VK_FILTER_LINEAR
:
3484 return (max_ansio
> 1 ? V_008F38_SQ_TEX_XY_FILTER_ANISO_BILINEAR
:
3485 V_008F38_SQ_TEX_XY_FILTER_BILINEAR
);
3486 case VK_FILTER_CUBIC_IMG
:
3488 fprintf(stderr
, "illegal texture filter");
3494 radv_tex_mipfilter(VkSamplerMipmapMode mode
)
3497 case VK_SAMPLER_MIPMAP_MODE_NEAREST
:
3498 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
3499 case VK_SAMPLER_MIPMAP_MODE_LINEAR
:
3500 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
3502 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
3507 radv_tex_bordercolor(VkBorderColor bcolor
)
3510 case VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK
:
3511 case VK_BORDER_COLOR_INT_TRANSPARENT_BLACK
:
3512 return V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
3513 case VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK
:
3514 case VK_BORDER_COLOR_INT_OPAQUE_BLACK
:
3515 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
3516 case VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE
:
3517 case VK_BORDER_COLOR_INT_OPAQUE_WHITE
:
3518 return V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
3526 radv_tex_aniso_filter(unsigned filter
)
3540 radv_init_sampler(struct radv_device
*device
,
3541 struct radv_sampler
*sampler
,
3542 const VkSamplerCreateInfo
*pCreateInfo
)
3544 uint32_t max_aniso
= pCreateInfo
->anisotropyEnable
&& pCreateInfo
->maxAnisotropy
> 1.0 ?
3545 (uint32_t) pCreateInfo
->maxAnisotropy
: 0;
3546 uint32_t max_aniso_ratio
= radv_tex_aniso_filter(max_aniso
);
3547 bool is_vi
= (device
->physical_device
->rad_info
.chip_class
>= VI
);
3549 sampler
->state
[0] = (S_008F30_CLAMP_X(radv_tex_wrap(pCreateInfo
->addressModeU
)) |
3550 S_008F30_CLAMP_Y(radv_tex_wrap(pCreateInfo
->addressModeV
)) |
3551 S_008F30_CLAMP_Z(radv_tex_wrap(pCreateInfo
->addressModeW
)) |
3552 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
3553 S_008F30_DEPTH_COMPARE_FUNC(radv_tex_compare(pCreateInfo
->compareOp
)) |
3554 S_008F30_FORCE_UNNORMALIZED(pCreateInfo
->unnormalizedCoordinates
? 1 : 0) |
3555 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
3556 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
3557 S_008F30_DISABLE_CUBE_WRAP(0) |
3558 S_008F30_COMPAT_MODE(is_vi
));
3559 sampler
->state
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(pCreateInfo
->minLod
, 0, 15), 8)) |
3560 S_008F34_MAX_LOD(S_FIXED(CLAMP(pCreateInfo
->maxLod
, 0, 15), 8)) |
3561 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
3562 sampler
->state
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(pCreateInfo
->mipLodBias
, -16, 16), 8)) |
3563 S_008F38_XY_MAG_FILTER(radv_tex_filter(pCreateInfo
->magFilter
, max_aniso
)) |
3564 S_008F38_XY_MIN_FILTER(radv_tex_filter(pCreateInfo
->minFilter
, max_aniso
)) |
3565 S_008F38_MIP_FILTER(radv_tex_mipfilter(pCreateInfo
->mipmapMode
)) |
3566 S_008F38_MIP_POINT_PRECLAMP(0) |
3567 S_008F38_DISABLE_LSB_CEIL(1) |
3568 S_008F38_FILTER_PREC_FIX(1) |
3569 S_008F38_ANISO_OVERRIDE(is_vi
));
3570 sampler
->state
[3] = (S_008F3C_BORDER_COLOR_PTR(0) |
3571 S_008F3C_BORDER_COLOR_TYPE(radv_tex_bordercolor(pCreateInfo
->borderColor
)));
3574 VkResult
radv_CreateSampler(
3576 const VkSamplerCreateInfo
* pCreateInfo
,
3577 const VkAllocationCallbacks
* pAllocator
,
3578 VkSampler
* pSampler
)
3580 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3581 struct radv_sampler
*sampler
;
3583 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO
);
3585 sampler
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*sampler
), 8,
3586 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
3588 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
3590 radv_init_sampler(device
, sampler
, pCreateInfo
);
3591 *pSampler
= radv_sampler_to_handle(sampler
);
3596 void radv_DestroySampler(
3599 const VkAllocationCallbacks
* pAllocator
)
3601 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3602 RADV_FROM_HANDLE(radv_sampler
, sampler
, _sampler
);
3606 vk_free2(&device
->alloc
, pAllocator
, sampler
);
3609 /* vk_icd.h does not declare this function, so we declare it here to
3610 * suppress Wmissing-prototypes.
3612 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
3613 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
);
3615 PUBLIC VKAPI_ATTR VkResult VKAPI_CALL
3616 vk_icdNegotiateLoaderICDInterfaceVersion(uint32_t *pSupportedVersion
)
3618 /* For the full details on loader interface versioning, see
3619 * <https://github.com/KhronosGroup/Vulkan-LoaderAndValidationLayers/blob/master/loader/LoaderAndLayerInterface.md>.
3620 * What follows is a condensed summary, to help you navigate the large and
3621 * confusing official doc.
3623 * - Loader interface v0 is incompatible with later versions. We don't
3626 * - In loader interface v1:
3627 * - The first ICD entrypoint called by the loader is
3628 * vk_icdGetInstanceProcAddr(). The ICD must statically expose this
3630 * - The ICD must statically expose no other Vulkan symbol unless it is
3631 * linked with -Bsymbolic.
3632 * - Each dispatchable Vulkan handle created by the ICD must be
3633 * a pointer to a struct whose first member is VK_LOADER_DATA. The
3634 * ICD must initialize VK_LOADER_DATA.loadMagic to ICD_LOADER_MAGIC.
3635 * - The loader implements vkCreate{PLATFORM}SurfaceKHR() and
3636 * vkDestroySurfaceKHR(). The ICD must be capable of working with
3637 * such loader-managed surfaces.
3639 * - Loader interface v2 differs from v1 in:
3640 * - The first ICD entrypoint called by the loader is
3641 * vk_icdNegotiateLoaderICDInterfaceVersion(). The ICD must
3642 * statically expose this entrypoint.
3644 * - Loader interface v3 differs from v2 in:
3645 * - The ICD must implement vkCreate{PLATFORM}SurfaceKHR(),
3646 * vkDestroySurfaceKHR(), and other API which uses VKSurfaceKHR,
3647 * because the loader no longer does so.
3649 *pSupportedVersion
= MIN2(*pSupportedVersion
, 3u);
3653 VkResult
radv_GetMemoryFdKHR(VkDevice _device
,
3654 const VkMemoryGetFdInfoKHR
*pGetFdInfo
,
3657 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3658 RADV_FROM_HANDLE(radv_device_memory
, memory
, pGetFdInfo
->memory
);
3660 assert(pGetFdInfo
->sType
== VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR
);
3662 /* We support only one handle type. */
3663 assert(pGetFdInfo
->handleType
==
3664 VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
3666 bool ret
= radv_get_memory_fd(device
, memory
, pFD
);
3668 return VK_ERROR_OUT_OF_DEVICE_MEMORY
;
3672 VkResult
radv_GetMemoryFdPropertiesKHR(VkDevice _device
,
3673 VkExternalMemoryHandleTypeFlagBitsKHR handleType
,
3675 VkMemoryFdPropertiesKHR
*pMemoryFdProperties
)
3677 /* The valid usage section for this function says:
3679 * "handleType must not be one of the handle types defined as opaque."
3681 * Since we only handle opaque handles for now, there are no FD properties.
3683 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
3686 VkResult
radv_ImportSemaphoreFdKHR(VkDevice _device
,
3687 const VkImportSemaphoreFdInfoKHR
*pImportSemaphoreFdInfo
)
3689 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3690 RADV_FROM_HANDLE(radv_semaphore
, sem
, pImportSemaphoreFdInfo
->semaphore
);
3691 uint32_t syncobj_handle
= 0;
3692 assert(pImportSemaphoreFdInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
3694 int ret
= device
->ws
->import_syncobj(device
->ws
, pImportSemaphoreFdInfo
->fd
, &syncobj_handle
);
3696 return VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
;
3698 if (pImportSemaphoreFdInfo
->flags
& VK_SEMAPHORE_IMPORT_TEMPORARY_BIT_KHR
) {
3699 sem
->temp_syncobj
= syncobj_handle
;
3701 sem
->syncobj
= syncobj_handle
;
3703 close(pImportSemaphoreFdInfo
->fd
);
3707 VkResult
radv_GetSemaphoreFdKHR(VkDevice _device
,
3708 const VkSemaphoreGetFdInfoKHR
*pGetFdInfo
,
3711 RADV_FROM_HANDLE(radv_device
, device
, _device
);
3712 RADV_FROM_HANDLE(radv_semaphore
, sem
, pGetFdInfo
->semaphore
);
3714 uint32_t syncobj_handle
;
3716 assert(pGetFdInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
);
3717 if (sem
->temp_syncobj
)
3718 syncobj_handle
= sem
->temp_syncobj
;
3720 syncobj_handle
= sem
->syncobj
;
3721 ret
= device
->ws
->export_syncobj(device
->ws
, syncobj_handle
, pFd
);
3723 return vk_error(VK_ERROR_INVALID_EXTERNAL_HANDLE_KHR
);
3727 void radv_GetPhysicalDeviceExternalSemaphorePropertiesKHR(
3728 VkPhysicalDevice physicalDevice
,
3729 const VkPhysicalDeviceExternalSemaphoreInfoKHR
* pExternalSemaphoreInfo
,
3730 VkExternalSemaphorePropertiesKHR
* pExternalSemaphoreProperties
)
3732 if (pExternalSemaphoreInfo
->handleType
== VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
) {
3733 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
3734 pExternalSemaphoreProperties
->compatibleHandleTypes
= VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT_KHR
;
3735 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT_KHR
|
3736 VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT_KHR
;
3738 pExternalSemaphoreProperties
->exportFromImportedHandleTypes
= 0;
3739 pExternalSemaphoreProperties
->compatibleHandleTypes
= 0;
3740 pExternalSemaphoreProperties
->externalSemaphoreFeatures
= 0;