From b9da6d6ddcd8549c98f21d71a6131d29ffebccb8 Mon Sep 17 00:00:00 2001 From: slime Date: Sun, 25 Sep 2022 22:05:18 -0300 Subject: [PATCH] vulkan: always use optimal image tiling. Linear is useful for intermediate texture copy steps between the CPU and GPU, but we use buffers instead of textures for that. --- src/modules/graphics/Texture.h | 12 ++++++------ src/modules/graphics/vulkan/Graphics.cpp | 25 +++++++++++------------- src/modules/graphics/vulkan/Texture.cpp | 5 +---- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/modules/graphics/Texture.h b/src/modules/graphics/Texture.h index 17402ac57..fc8dfb118 100644 --- a/src/modules/graphics/Texture.h +++ b/src/modules/graphics/Texture.h @@ -59,12 +59,12 @@ enum TextureType enum PixelFormatUsage { - PIXELFORMATUSAGE_SAMPLE, - PIXELFORMATUSAGE_LINEAR, - PIXELFORMATUSAGE_RENDERTARGET, - PIXELFORMATUSAGE_BLEND, - PIXELFORMATUSAGE_MSAA, - PIXELFORMATUSAGE_COMPUTEWRITE, + PIXELFORMATUSAGE_SAMPLE, // Any sampling in shaders. + PIXELFORMATUSAGE_LINEAR, // Linear filtering. + PIXELFORMATUSAGE_RENDERTARGET, // Usable as a render target. + PIXELFORMATUSAGE_BLEND, // Blend support when used as a render target. + PIXELFORMATUSAGE_MSAA, // MSAA support when used as a render target. + PIXELFORMATUSAGE_COMPUTEWRITE, // Writable in compute shaders via imageStore. PIXELFORMATUSAGE_MAX_ENUM }; diff --git a/src/modules/graphics/vulkan/Graphics.cpp b/src/modules/graphics/vulkan/Graphics.cpp index 873d97f8a..3bde5b03b 100644 --- a/src/modules/graphics/vulkan/Graphics.cpp +++ b/src/modules/graphics/vulkan/Graphics.cpp @@ -965,21 +965,9 @@ bool Graphics::isPixelFormatSupported(PixelFormat format, uint32 usage, bool sRG VkFormatProperties formatProperties; vkGetPhysicalDeviceFormatProperties(physicalDevice, vulkanFormat.internalFormat, &formatProperties); - VkFormatFeatureFlags featureFlags; - VkImageTiling tiling; + VkFormatFeatureFlags featureFlags = formatProperties.optimalTilingFeatures; VkImageUsageFlags usageFlags = 0; - if (usage & PIXELFORMATUSAGEFLAGS_LINEAR) - { - tiling = VK_IMAGE_TILING_LINEAR; - featureFlags = formatProperties.linearTilingFeatures; - } - else - { - tiling = VK_IMAGE_TILING_OPTIMAL; - featureFlags = formatProperties.optimalTilingFeatures; - } - if (!featureFlags) return false; @@ -990,6 +978,12 @@ bool Graphics::isPixelFormatSupported(PixelFormat format, uint32 usage, bool sRG return false; } + if (usage & PIXELFORMATUSAGE_LINEAR) + { + if (!(featureFlags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT)) + return false; + } + if (usage & PIXELFORMATUSAGEFLAGS_RENDERTARGET) { if (isPixelFormatDepth(format) || isPixelFormatDepthStencil(format)) @@ -1007,8 +1001,10 @@ bool Graphics::isPixelFormatSupported(PixelFormat format, uint32 usage, bool sRG } if (usage & PIXELFORMATUSAGEFLAGS_BLEND) + { if (!(featureFlags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT)) return false; + } if (usage & PIXELFORMATUSAGEFLAGS_COMPUTEWRITE) { @@ -1021,7 +1017,8 @@ bool Graphics::isPixelFormatSupported(PixelFormat format, uint32 usage, bool sRG { VkImageFormatProperties properties; - vkGetPhysicalDeviceImageFormatProperties(physicalDevice, vulkanFormat.internalFormat, VK_IMAGE_TYPE_2D, tiling, usageFlags, 0, &properties); + if (vkGetPhysicalDeviceImageFormatProperties(physicalDevice, vulkanFormat.internalFormat, VK_IMAGE_TYPE_2D, VK_IMAGE_TILING_OPTIMAL, usageFlags, 0, &properties) != VK_SUCCESS) + return false; if (static_cast(properties.sampleCounts) == 1) return false; diff --git a/src/modules/graphics/vulkan/Texture.cpp b/src/modules/graphics/vulkan/Texture.cpp index fbcb44d05..015e351af 100644 --- a/src/modules/graphics/vulkan/Texture.cpp +++ b/src/modules/graphics/vulkan/Texture.cpp @@ -99,10 +99,7 @@ bool Texture::loadVolatile() imageInfo.arrayLayers = static_cast(layerCount); imageInfo.mipLevels = static_cast(mipmapCount); imageInfo.format = vulkanFormat.internalFormat; - if (isPixelFormatCompressed(format)) - imageInfo.tiling = VK_IMAGE_TILING_LINEAR; - else - imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; + imageInfo.tiling = VK_IMAGE_TILING_OPTIMAL; imageInfo.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED; imageInfo.usage = usageFlags; imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;