Cache the Vulkan resource copy's storage format query

This commit is contained in:
cdozdil committed 2026-11-14 01:58:59 +03:00
1 parent 78643b6b83
commit 992f4e1984
2 files changed
+14 -5

No files matched your search

+9 -4
View File
@@ -65,20 +65,25 @@ ResourceCopy_Vk::ResourceCopy_Vk(std::string InName, VkDevice InDevice, VkPhysic
std::ranges::none_of(_descriptorSets, [](VkDescriptorSet set) { return set == VK_NULL_HANDLE; });
}
VkFormat ResourceCopy_Vk::BufferFormat(VkFormat InFormat, bool InDepth) const
VkFormat ResourceCopy_Vk::BufferFormat(VkFormat InFormat, bool InDepth)
{
// Depth formats can't be storage images, the shader reads the depth aspect as float
if (InDepth)
return VK_FORMAT_R32_SFLOAT;
if (InFormat == _querySource)
return _queryResult;
// sRGB, BGRA and others without storage support, float keeps the precision of what the shader reads
VkFormatProperties properties {};
vkGetPhysicalDeviceFormatProperties(_physicalDevice, InFormat, &properties);
if (!(properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT))
return VK_FORMAT_R16G16B16A16_SFLOAT;
_querySource = InFormat;
_queryResult = (properties.optimalTilingFeatures & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT)
? InFormat
: VK_FORMAT_R16G16B16A16_SFLOAT;
return InFormat;
return _queryResult;
}
bool ResourceCopy_Vk::IsInteger(VkFormat InFormat)
+5 -1
View File
@@ -8,6 +8,10 @@ class ResourceCopy_Vk : public Shader_Vk
uint32_t InNumThreadsX = 16;
uint32_t InNumThreadsY = 16;
// Last BufferFormat query, the source format rarely changes
VkFormat _querySource = VK_FORMAT_MAX_ENUM;
VkFormat _queryResult = VK_FORMAT_UNDEFINED;
public:
ResourceCopy_Vk(std::string InName, VkDevice InDevice, VkPhysicalDevice InPhysicalDevice);
~ResourceCopy_Vk() = default;
@@ -17,7 +21,7 @@ class ResourceCopy_Vk : public Shader_Vk
VkExtent2D OutExtent, VkOffset2D InSrc = {}, VkOffset2D InDst = {});
// Storage image format for a copy of InFormat, depth is copied to R32_SFLOAT
VkFormat BufferFormat(VkFormat InFormat, bool InDepth) const;
VkFormat BufferFormat(VkFormat InFormat, bool InDepth);
// Integer formats can't be read as float
static bool IsInteger(VkFormat InFormat);