Browse Source

Vulkan: Workaround an unsupported format

Panagiotis Christopoulos Charitos 9 years ago
parent
commit
a72d3094cf

+ 1 - 0
src/anki/gr/Enums.h

@@ -145,6 +145,7 @@ enum class ComponentFormat : U8
 	D16,
 	D16,
 	D24S8,
 	D24S8,
 	D32,
 	D32,
+	D32S8,
 	S8,
 	S8,
 
 
 	// Limits
 	// Limits

+ 1 - 1
src/anki/gr/vulkan/Common.cpp

@@ -200,7 +200,7 @@ static const ConvertFormat CONVERT_FORMAT_TABLE[] = {ANKI_FMT(NONE, NONE, VK_FOR
 	ANKI_FMT(S8, UINT, VK_FORMAT_S8_UINT, S),
 	ANKI_FMT(S8, UINT, VK_FORMAT_S8_UINT, S),
 	ANKI_FMT(NONE, NONE, VK_FORMAT_D16_UNORM_S8_UINT, DS),
 	ANKI_FMT(NONE, NONE, VK_FORMAT_D16_UNORM_S8_UINT, DS),
 	ANKI_FMT(D24S8, UNORM, VK_FORMAT_D24_UNORM_S8_UINT, DS),
 	ANKI_FMT(D24S8, UNORM, VK_FORMAT_D24_UNORM_S8_UINT, DS),
-	ANKI_FMT(NONE, NONE, VK_FORMAT_D32_SFLOAT_S8_UINT, C),
+	ANKI_FMT(D32S8, UNORM, VK_FORMAT_D32_SFLOAT_S8_UINT, DS),
 	ANKI_FMT(R8G8B8_S3TC, UNORM, VK_FORMAT_BC1_RGB_UNORM_BLOCK, C),
 	ANKI_FMT(R8G8B8_S3TC, UNORM, VK_FORMAT_BC1_RGB_UNORM_BLOCK, C),
 	ANKI_FMT(NONE, NONE, VK_FORMAT_BC1_RGB_SRGB_BLOCK, C),
 	ANKI_FMT(NONE, NONE, VK_FORMAT_BC1_RGB_SRGB_BLOCK, C),
 	ANKI_FMT(NONE, NONE, VK_FORMAT_BC1_RGBA_UNORM_BLOCK, C),
 	ANKI_FMT(NONE, NONE, VK_FORMAT_BC1_RGBA_UNORM_BLOCK, C),

+ 24 - 0
src/anki/gr/vulkan/GrManagerImpl.cpp

@@ -189,6 +189,30 @@ Error GrManagerImpl::initInternal(const GrManagerInitInfo& init)
 		}
 		}
 	}
 	}
 
 
+	// Set m_d24S8ImagesSupported
+	{
+		VkImageFormatProperties props = {};
+		VkResult res = vkGetPhysicalDeviceImageFormatProperties(m_physicalDevice,
+			VK_FORMAT_D24_UNORM_S8_UINT,
+			VK_IMAGE_TYPE_2D,
+			VK_IMAGE_TILING_OPTIMAL,
+			VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
+			0,
+			&props);
+
+		if(res == VK_ERROR_FORMAT_NOT_SUPPORTED)
+		{
+			ANKI_LOGI("D24S8 Images are not supported. Will workaround this");
+			m_d24S8ImagesSupported = false;
+		}
+		else
+		{
+			ANKI_ASSERT(res == VK_SUCCESS);
+			ANKI_LOGI("D24S8 Images are supported");
+			m_d24S8ImagesSupported = true;
+		}
+	}
+
 	return ErrorCode::NONE;
 	return ErrorCode::NONE;
 }
 }
 
 

+ 6 - 0
src/anki/gr/vulkan/GrManagerImpl.h

@@ -161,6 +161,11 @@ public:
 		return m_s8ImagesSupported;
 		return m_s8ImagesSupported;
 	}
 	}
 
 
+	Bool getD24S8ImagesSupported() const
+	{
+		return m_d24S8ImagesSupported;
+	}
+
 	CompatibleRenderPassCreator& getCompatibleRenderPassCreator()
 	CompatibleRenderPassCreator& getCompatibleRenderPassCreator()
 	{
 	{
 		return m_rpCreator;
 		return m_rpCreator;
@@ -292,6 +297,7 @@ private:
 
 
 	Bool8 m_r8g8b8ImagesSupported = false;
 	Bool8 m_r8g8b8ImagesSupported = false;
 	Bool8 m_s8ImagesSupported = false;
 	Bool8 m_s8ImagesSupported = false;
+	Bool8 m_d24S8ImagesSupported = false;
 
 
 	GrObjectCache* m_samplerCache = nullptr;
 	GrObjectCache* m_samplerCache = nullptr;
 
 

+ 6 - 0
src/anki/gr/vulkan/PipelineExtra.cpp

@@ -116,6 +116,12 @@ VkRenderPass CompatibleRenderPassCreator::createNewRenderPass(const PipelineInit
 			PixelFormat newFmt = PixelFormat(ComponentFormat::D24S8, TransformFormat::UNORM);
 			PixelFormat newFmt = PixelFormat(ComponentFormat::D24S8, TransformFormat::UNORM);
 			fmt = convertFormat(newFmt);
 			fmt = convertFormat(newFmt);
 		}
 		}
+		else if(init.m_depthStencil.m_format.m_components == ComponentFormat::D24S8
+			&& !m_manager->getD24S8ImagesSupported())
+		{
+			PixelFormat newFmt = PixelFormat(ComponentFormat::D32S8, TransformFormat::UNORM);
+			fmt = convertFormat(newFmt);
+		}
 		else
 		else
 		{
 		{
 			fmt = convertFormat(init.m_depthStencil.m_format);
 			fmt = convertFormat(init.m_depthStencil.m_format);

+ 12 - 0
src/anki/gr/vulkan/TextureImpl.cpp

@@ -228,6 +228,17 @@ Error TextureImpl::initImage(const TextureInitInfo& init_)
 			m_aspect = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
 			m_aspect = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
 			m_akAspect = DepthStencilAspectMask::DEPTH | DepthStencilAspectMask::STENCIL;
 			m_akAspect = DepthStencilAspectMask::DEPTH | DepthStencilAspectMask::STENCIL;
 		}
 		}
+		else if(init.m_format.m_components == ComponentFormat::D24S8)
+		{
+			ANKI_ASSERT(
+				!(init.m_usage & (TextureUsageBit::IMAGE_ALL | TextureUsageBit::UPLOAD)) && "Can't do that ATM");
+			init.m_format = PixelFormat(ComponentFormat::D32S8, TransformFormat::UNORM);
+			m_format = init.m_format;
+			m_vkFormat = convertFormat(m_format);
+			m_workarounds = TextureImplWorkaround::D24S8_TO_D32S8;
+			m_aspect = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
+			m_akAspect = DepthStencilAspectMask::DEPTH | DepthStencilAspectMask::STENCIL;
+		}
 		else
 		else
 		{
 		{
 			break;
 			break;
@@ -237,6 +248,7 @@ Error TextureImpl::initImage(const TextureInitInfo& init_)
 	if(!supported)
 	if(!supported)
 	{
 	{
 		ANKI_LOGE("Unsupported texture format: %u %u", U(init.m_format.m_components), U(init.m_format.m_transform));
 		ANKI_LOGE("Unsupported texture format: %u %u", U(init.m_format.m_components), U(init.m_format.m_transform));
+		return ErrorCode::FUNCTION_FAILED;
 	}
 	}
 
 
 	// Contunue with the creation
 	// Contunue with the creation

+ 1 - 0
src/anki/gr/vulkan/TextureImpl.h

@@ -22,6 +22,7 @@ enum class TextureImplWorkaround : U8
 	NONE,
 	NONE,
 	R8G8B8_TO_R8G8B8A8 = 1 << 0,
 	R8G8B8_TO_R8G8B8A8 = 1 << 0,
 	S8_TO_D24S8 = 1 << 1,
 	S8_TO_D24S8 = 1 << 1,
+	D24S8_TO_D32S8 = 1 << 2,
 };
 };
 ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(TextureImplWorkaround, inline)
 ANKI_ENUM_ALLOW_NUMERIC_OPERATIONS(TextureImplWorkaround, inline)