Browse Source

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.
slime 2 years ago
parent
commit
b9da6d6ddc

+ 6 - 6
src/modules/graphics/Texture.h

@@ -59,12 +59,12 @@ enum TextureType
 
 
 enum PixelFormatUsage
 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
 	PIXELFORMATUSAGE_MAX_ENUM
 };
 };
 
 

+ 11 - 14
src/modules/graphics/vulkan/Graphics.cpp

@@ -965,21 +965,9 @@ bool Graphics::isPixelFormatSupported(PixelFormat format, uint32 usage, bool sRG
 	VkFormatProperties formatProperties;
 	VkFormatProperties formatProperties;
 	vkGetPhysicalDeviceFormatProperties(physicalDevice, vulkanFormat.internalFormat, &formatProperties);
 	vkGetPhysicalDeviceFormatProperties(physicalDevice, vulkanFormat.internalFormat, &formatProperties);
 
 
-	VkFormatFeatureFlags featureFlags;
-	VkImageTiling tiling;
+	VkFormatFeatureFlags featureFlags = formatProperties.optimalTilingFeatures;
 	VkImageUsageFlags usageFlags = 0;
 	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)
 	if (!featureFlags)
 		return false;
 		return false;
 
 
@@ -990,6 +978,12 @@ bool Graphics::isPixelFormatSupported(PixelFormat format, uint32 usage, bool sRG
 			return false;
 			return false;
 	}
 	}
 
 
+	if (usage & PIXELFORMATUSAGE_LINEAR)
+	{
+		if (!(featureFlags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT))
+			return false;
+	}
+
 	if (usage & PIXELFORMATUSAGEFLAGS_RENDERTARGET)
 	if (usage & PIXELFORMATUSAGEFLAGS_RENDERTARGET)
 	{
 	{
 		if (isPixelFormatDepth(format) || isPixelFormatDepthStencil(format))
 		if (isPixelFormatDepth(format) || isPixelFormatDepthStencil(format))
@@ -1007,8 +1001,10 @@ bool Graphics::isPixelFormatSupported(PixelFormat format, uint32 usage, bool sRG
 	}
 	}
 
 
 	if (usage & PIXELFORMATUSAGEFLAGS_BLEND)
 	if (usage & PIXELFORMATUSAGEFLAGS_BLEND)
+	{
 		if (!(featureFlags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT))
 		if (!(featureFlags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT))
 			return false;
 			return false;
+	}
 
 
 	if (usage & PIXELFORMATUSAGEFLAGS_COMPUTEWRITE)
 	if (usage & PIXELFORMATUSAGEFLAGS_COMPUTEWRITE)
 	{
 	{
@@ -1021,7 +1017,8 @@ bool Graphics::isPixelFormatSupported(PixelFormat format, uint32 usage, bool sRG
 	{
 	{
 		VkImageFormatProperties properties;
 		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<uint32_t>(properties.sampleCounts) == 1)
 		if (static_cast<uint32_t>(properties.sampleCounts) == 1)
 			return false;
 			return false;

+ 1 - 4
src/modules/graphics/vulkan/Texture.cpp

@@ -99,10 +99,7 @@ bool Texture::loadVolatile()
 	imageInfo.arrayLayers = static_cast<uint32_t>(layerCount);
 	imageInfo.arrayLayers = static_cast<uint32_t>(layerCount);
 	imageInfo.mipLevels = static_cast<uint32_t>(mipmapCount);
 	imageInfo.mipLevels = static_cast<uint32_t>(mipmapCount);
 	imageInfo.format = vulkanFormat.internalFormat;
 	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.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
 	imageInfo.usage = usageFlags;
 	imageInfo.usage = usageFlags;
 	imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
 	imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;