Fix missing srgb for compressed textures

This commit is contained in:
Benau 2023-04-13 12:56:06 +08:00
parent f9d10fe9ff
commit 8c90d7b3d0
2 changed files with 17 additions and 3 deletions

View File

@ -291,7 +291,7 @@ bool GEVulkanTexture::createImage(VkImageUsageFlags usage)
if (m_image_view_type == VK_IMAGE_VIEW_TYPE_CUBE ||
m_image_view_type == VK_IMAGE_VIEW_TYPE_CUBE_ARRAY)
image_info.flags = VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT;
if (m_internal_format == VK_FORMAT_R8G8B8A8_UNORM)
if (m_internal_format != getSRGBformat(m_internal_format))
image_info.flags |= VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT;
m_vma_info = {};
@ -449,10 +449,11 @@ bool GEVulkanTexture::createImageView(VkImageAspectFlags aspect_flags)
{
image_view.get()->store(view_ptr);
m_image_view = image_view;
if (m_internal_format == VK_FORMAT_R8G8B8A8_UNORM)
VkFormat srgb_format = getSRGBformat(m_internal_format);
if (m_internal_format != srgb_format)
{
image_view = std::make_shared<std::atomic<VkImageView> >();
view_info.format = VK_FORMAT_R8G8B8A8_SRGB;
view_info.format = srgb_format;
view_ptr = VK_NULL_HANDLE;
if (vkCreateImageView(m_vulkan_device, &view_info,
NULL, &view_ptr) == VK_SUCCESS)

View File

@ -67,6 +67,19 @@ protected:
GEVulkanDriver* m_vk;
// ------------------------------------------------------------------------
VkFormat getSRGBformat(VkFormat format)
{
if (format == VK_FORMAT_R8G8B8A8_UNORM)
return VK_FORMAT_R8G8B8A8_SRGB;
else if (format == VK_FORMAT_ASTC_4x4_UNORM_BLOCK)
return VK_FORMAT_ASTC_4x4_SRGB_BLOCK;
else if (format == VK_FORMAT_BC7_UNORM_BLOCK)
return VK_FORMAT_BC7_SRGB_BLOCK;
else if (format == VK_FORMAT_BC3_UNORM_BLOCK)
return VK_FORMAT_BC3_SRGB_BLOCK;
return format;
}
// ------------------------------------------------------------------------
bool createTextureImage(uint8_t* texture_data, bool generate_hq_mipmap);
// ------------------------------------------------------------------------