2
0
Эх сурвалжийг харах

DX11: Nicer way of checking and dealing with (un)supported pixel formats

BearishSun 9 жил өмнө
parent
commit
e62261bc1e

+ 9 - 0
Source/BansheeCore/Include/BsCommonTypes.h

@@ -331,6 +331,15 @@ namespace bs
 		GPDT_UNKNOWN = 0xffff
 		GPDT_UNKNOWN = 0xffff
 	};
 	};
 
 
+	/**	Available texture types. */
+	enum TextureType
+	{
+		TEX_TYPE_1D = 1, /**< One dimensional texture. Just a row of pixels. */
+		TEX_TYPE_2D = 2, /**< Two dimensional texture. */
+		TEX_TYPE_3D = 3, /**< Three dimensional texture. */
+		TEX_TYPE_CUBE_MAP = 4 /**< Texture consisting out of six 2D textures describing an inside of a cube. Allows special sampling. */
+	};
+
 	/**	Contains data about a type used for GPU data parameters. */
 	/**	Contains data about a type used for GPU data parameters. */
 	struct GpuParamDataTypeInfo
 	struct GpuParamDataTypeInfo
 	{
 	{

+ 19 - 0
Source/BansheeCore/Include/BsPixelUtil.h

@@ -128,6 +128,25 @@ namespace bs
 		/**	Checks is the provided format in native endian format. */
 		/**	Checks is the provided format in native endian format. */
         static bool isNativeEndian(PixelFormat format);
         static bool isNativeEndian(PixelFormat format);
 		
 		
+		/** 
+		 * Checks is the provided format valid for the texture type and usage. 
+		 * 
+		 * @param[in, out]	format	Format to check. If format is not valid the method will update this with the closest
+		 *							relevant format.
+		 * @param[in]		texType	Type of the texture the format will be used for.
+		 * @param[in]		usage	A set of TextureUsage flags that define how will a texture be used.
+		 * @return					True if the format is valid, false if not.
+		 * 
+		 * @note	This method checks only for obvious format mismatches:
+		 *			- Using depth format for anything but a depth-stencil buffer
+		 *			- Using anything but a depth format for a depth-stencil-buffer
+		 *			- Using compressed format for anything but normal textures
+		 *			- Using compressed format for 1D textures
+		 *			
+		 *			Caller should still check for platform-specific unsupported formats.
+		 */
+		static bool checkFormat(PixelFormat& format, TextureType texType, int usage);
+
 		/**
 		/**
 		 * Checks are the provided dimensions valid for the specified pixel format. Some formats (like BC) require 
 		 * Checks are the provided dimensions valid for the specified pixel format. Some formats (like BC) require 
 		 * width/height to be multiples of four and some formats dont allow depth larger than 1.
 		 * width/height to be multiples of four and some formats dont allow depth larger than 1.

+ 0 - 9
Source/BansheeCore/Include/BsTexture.h

@@ -28,15 +28,6 @@ namespace bs
 		TU_DEFAULT = TU_STATIC
 		TU_DEFAULT = TU_STATIC
     };
     };
 
 
-	/**	Available texture types. */
-    enum TextureType
-    {
-		TEX_TYPE_1D = 1, /**< One dimensional texture. Just a row of pixels. */
-		TEX_TYPE_2D = 2, /**< Two dimensional texture. */
-		TEX_TYPE_3D = 3, /**< Three dimensional texture. */
-		TEX_TYPE_CUBE_MAP = 4 /**< Texture consisting out of six 2D textures describing an inside of a cube. Allows special sampling. */
-    };
-
 	/**	Texture mipmap options. */
 	/**	Texture mipmap options. */
 	enum TextureMipmap
 	enum TextureMipmap
 	{
 	{

+ 68 - 0
Source/BansheeCore/Source/BsPixelUtil.cpp

@@ -5,6 +5,7 @@
 #include "BsColor.h"
 #include "BsColor.h"
 #include "BsMath.h"
 #include "BsMath.h"
 #include "BsException.h"
 #include "BsException.h"
+#include "BsTexture.h"
 #include <nvtt.h>
 #include <nvtt.h>
 
 
 namespace bs 
 namespace bs 
@@ -998,6 +999,73 @@ namespace bs
         return (PixelUtil::getFlags(format) & PFF_NATIVEENDIAN) > 0;
         return (PixelUtil::getFlags(format) & PFF_NATIVEENDIAN) > 0;
     }
     }
 
 
+	bool PixelUtil::checkFormat(PixelFormat& format, TextureType texType, int usage)
+	{
+		// First check just the usage since it's the most limiting factor
+
+		//// Depth-stencil only supports depth formats
+		if ((usage & TU_DEPTHSTENCIL) != 0)
+		{
+			if (isDepth(format))
+				return true;
+
+			format = PF_D32_S8X24;
+			return false;
+		}
+
+		//// Render targets support everything but compressed & depth-stencil formats
+		if ((usage & TU_RENDERTARGET) != 0)
+		{
+			if (!isDepth(format) && !isCompressed(format))
+				return true;
+
+			format = PF_R8G8B8A8;
+			return false;
+		}
+
+		//// Load-store textures support everything but compressed & depth-stencil formats
+		if ((usage & TU_LOADSTORE) != 0)
+		{
+			if (!isDepth(format) && !isCompressed(format))
+				return true;
+
+			format = PF_R8G8B8A8;
+			return false;
+		}
+
+		//// Sampled texture support depends on texture type
+		switch (texType)
+		{
+		case TEX_TYPE_1D:
+		{
+			// 1D textures support anything but depth & compressed formats
+			if (!isDepth(format) && !isCompressed(format))
+				return true;
+
+			format = PF_R8G8B8A8;
+			return false;
+		}
+		case TEX_TYPE_3D:
+		{
+			// 3D textures support anything but depth & compressed formats
+			if (!isDepth(format))
+				return true;
+
+			format = PF_R8G8B8A8;
+			return false;
+		}
+		default: // 2D & cube
+		{
+			// 2D/cube textures support anything but depth formats
+			if (!isDepth(format))
+				return true;
+
+			format = PF_R8G8B8A8;
+			return false;
+		}
+		}
+	}
+
 	bool PixelUtil::isValidExtent(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format)
 	bool PixelUtil::isValidExtent(UINT32 width, UINT32 height, UINT32 depth, PixelFormat format)
 	{
 	{
 		if(isCompressed(format))
 		if(isCompressed(format))

+ 3 - 4
Source/BansheeD3D11RenderAPI/Include/BsD3D11Mappings.h

@@ -90,10 +90,9 @@ namespace bs
 
 
 		/**
 		/**
 		 * Converts engine pixel format to DX11 pixel format. Some formats depend on whether hardware gamma is used or not,
 		 * Converts engine pixel format to DX11 pixel format. Some formats depend on whether hardware gamma is used or not,
-		 * in which case set the @p hwGamma parameter as needed. Most formats also depend on @p usage, as specified by
-		 * TextureUsage flags.
+		 * in which case set the @p hwGamma parameter as needed. 
 		 */
 		 */
-		static DXGI_FORMAT getPF(PixelFormat format, bool hwGamma, int usage);
+		static DXGI_FORMAT getPF(PixelFormat format, bool hwGamma);
 		
 		
 		/** Converts engine GPU buffer format to DX11 GPU buffer format. */
 		/** Converts engine GPU buffer format to DX11 GPU buffer format. */
 		static DXGI_FORMAT getBF(GpuBufferFormat format);
 		static DXGI_FORMAT getBF(GpuBufferFormat format);
@@ -120,7 +119,7 @@ namespace bs
 		static bool isDynamic(GpuBufferUsage mUsage);
 		static bool isDynamic(GpuBufferUsage mUsage);
 
 
 		/**	Finds the closest pixel format that DX11 supports. */
 		/**	Finds the closest pixel format that DX11 supports. */
-		static PixelFormat getClosestSupportedPF(PixelFormat format, bool hwGamma, int usage);
+		static PixelFormat getClosestSupportedPF(PixelFormat format, TextureType texType, int usage);
 
 
 		/**
 		/**
 		 * Returns size in bytes of a pixel surface of the specified size and format, while using DX11 allocation rules for
 		 * Returns size in bytes of a pixel surface of the specified size and format, while using DX11 allocation rules for

+ 1 - 0
Source/BansheeD3D11RenderAPI/Include/BsD3D11Texture.h

@@ -134,6 +134,7 @@ namespace bs
 
 
 		SPtr<D3D11TextureView> mShaderResourceView;
 		SPtr<D3D11TextureView> mShaderResourceView;
 		
 		
+		PixelFormat mInternalFormat;
 		DXGI_FORMAT mDXGIFormat;
 		DXGI_FORMAT mDXGIFormat;
 		DXGI_FORMAT mDXGIColorFormat;
 		DXGI_FORMAT mDXGIColorFormat;
 		DXGI_FORMAT mDXGIDepthStencilFormat;
 		DXGI_FORMAT mDXGIDepthStencilFormat;

+ 30 - 73
Source/BansheeD3D11RenderAPI/Source/BsD3D11Mappings.cpp

@@ -597,11 +597,8 @@ namespace bs
 		}
 		}
 	}
 	}
 
 
-	DXGI_FORMAT D3D11Mappings::getPF(PixelFormat pf, bool gamma, int usage)
+	DXGI_FORMAT D3D11Mappings::getPF(PixelFormat pf, bool gamma)
 	{
 	{
-		int isSampledTexture = ((usage & TU_RENDERTARGET) != 0) && ((usage & TU_DEPTHSTENCIL) != 0) &&
-			((usage & TU_LOADSTORE) != 0);
-
 		switch(pf)
 		switch(pf)
 		{
 		{
 		case PF_R8:
 		case PF_R8:
@@ -609,15 +606,13 @@ namespace bs
 		case PF_R8G8:
 		case PF_R8G8:
 			return DXGI_FORMAT_R8G8_UNORM; 
 			return DXGI_FORMAT_R8G8_UNORM; 
 		case PF_R8G8B8:
 		case PF_R8G8B8:
+		case PF_B8G8R8:
 			return DXGI_FORMAT_UNKNOWN;
 			return DXGI_FORMAT_UNKNOWN;
 		case PF_R8G8B8A8:
 		case PF_R8G8B8A8:
 			if (gamma)
 			if (gamma)
 				return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
 				return DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
 			return DXGI_FORMAT_R8G8B8A8_UNORM;
 			return DXGI_FORMAT_R8G8B8A8_UNORM;
 		case PF_B8G8R8A8:
 		case PF_B8G8R8A8:
-			if (!isSampledTexture)
-				return DXGI_FORMAT_UNKNOWN;
-
 			if (gamma)
 			if (gamma)
 				return DXGI_FORMAT_B8G8R8A8_UNORM_SRGB;
 				return DXGI_FORMAT_B8G8R8A8_UNORM_SRGB;
 			return DXGI_FORMAT_B8G8R8A8_UNORM;
 			return DXGI_FORMAT_B8G8R8A8_UNORM;
@@ -634,76 +629,39 @@ namespace bs
 		case PF_FLOAT32_RG:
 		case PF_FLOAT32_RG:
 			return DXGI_FORMAT_R32G32_FLOAT;
 			return DXGI_FORMAT_R32G32_FLOAT;
 		case PF_FLOAT32_RGB:
 		case PF_FLOAT32_RGB:
-			if (!isSampledTexture)
-				return DXGI_FORMAT_UNKNOWN;
-
 			return DXGI_FORMAT_R32G32B32_FLOAT;
 			return DXGI_FORMAT_R32G32B32_FLOAT;
 		case PF_FLOAT32_RGBA:
 		case PF_FLOAT32_RGBA:
 			return DXGI_FORMAT_R32G32B32A32_FLOAT;
 			return DXGI_FORMAT_R32G32B32A32_FLOAT;
 		case PF_BC1:
 		case PF_BC1:
 		case PF_BC1a:
 		case PF_BC1a:
-			if (!isSampledTexture)
-				return DXGI_FORMAT_UNKNOWN;
-
 			if(gamma)
 			if(gamma)
 				return DXGI_FORMAT_BC1_UNORM_SRGB;
 				return DXGI_FORMAT_BC1_UNORM_SRGB;
 			return DXGI_FORMAT_BC1_UNORM;
 			return DXGI_FORMAT_BC1_UNORM;
 		case PF_BC2:
 		case PF_BC2:
-			if (!isSampledTexture)
-				return DXGI_FORMAT_UNKNOWN;
-
 			if (gamma)
 			if (gamma)
 				return DXGI_FORMAT_BC2_UNORM_SRGB;
 				return DXGI_FORMAT_BC2_UNORM_SRGB;
 			return DXGI_FORMAT_BC2_UNORM;
 			return DXGI_FORMAT_BC2_UNORM;
 		case PF_BC3:
 		case PF_BC3:
-			if (!isSampledTexture)
-				return DXGI_FORMAT_UNKNOWN;
-
 			if (gamma)
 			if (gamma)
 				return DXGI_FORMAT_BC3_UNORM_SRGB;
 				return DXGI_FORMAT_BC3_UNORM_SRGB;
 			return DXGI_FORMAT_BC3_UNORM;
 			return DXGI_FORMAT_BC3_UNORM;
 		case PF_BC4:
 		case PF_BC4:
-			if (!isSampledTexture)
-				return DXGI_FORMAT_UNKNOWN;
-
 			return DXGI_FORMAT_BC4_UNORM;
 			return DXGI_FORMAT_BC4_UNORM;
 		case PF_BC5:
 		case PF_BC5:
-			if (!isSampledTexture)
-				return DXGI_FORMAT_UNKNOWN;
-
 			return DXGI_FORMAT_BC5_UNORM;
 			return DXGI_FORMAT_BC5_UNORM;
 		case PF_BC6H:
 		case PF_BC6H:
-			if (!isSampledTexture)
-				return DXGI_FORMAT_UNKNOWN;
-
 			return DXGI_FORMAT_BC6H_UF16;
 			return DXGI_FORMAT_BC6H_UF16;
 		case PF_BC7:
 		case PF_BC7:
-			if (!isSampledTexture)
-				return DXGI_FORMAT_UNKNOWN;
-
 			if (gamma)
 			if (gamma)
 				return DXGI_FORMAT_BC7_UNORM_SRGB;
 				return DXGI_FORMAT_BC7_UNORM_SRGB;
-			else
-				return DXGI_FORMAT_BC7_UNORM;
+			return DXGI_FORMAT_BC7_UNORM;
 		case PF_D32_S8X24:
 		case PF_D32_S8X24:
-			if ((usage & TU_DEPTHSTENCIL) == 0)
-				return DXGI_FORMAT_UNKNOWN;
-
 			return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
 			return DXGI_FORMAT_D32_FLOAT_S8X24_UINT;
 		case PF_D24S8:
 		case PF_D24S8:
-			if ((usage & TU_DEPTHSTENCIL) == 0)
-				return DXGI_FORMAT_UNKNOWN;
-
 			return DXGI_FORMAT_D24_UNORM_S8_UINT;
 			return DXGI_FORMAT_D24_UNORM_S8_UINT;
 		case PF_D32:
 		case PF_D32:
-			if ((usage & TU_DEPTHSTENCIL) == 0)
-				return DXGI_FORMAT_UNKNOWN;
-
 			return DXGI_FORMAT_D32_FLOAT;
 			return DXGI_FORMAT_D32_FLOAT;
 		case PF_D16:
 		case PF_D16:
-			if ((usage & TU_DEPTHSTENCIL) == 0)
-				return DXGI_FORMAT_UNKNOWN;
-
 			return DXGI_FORMAT_D16_UNORM;
 			return DXGI_FORMAT_D16_UNORM;
 		case PF_FLOAT_R11G11B10:
 		case PF_FLOAT_R11G11B10:
 			return DXGI_FORMAT_R11G11B10_FLOAT;
 			return DXGI_FORMAT_R11G11B10_FLOAT;
@@ -799,42 +757,41 @@ namespace bs
 		}
 		}
 	}
 	}
 
 
-	PixelFormat D3D11Mappings::getClosestSupportedPF(PixelFormat pf, bool hwGamma, int usage)
+	PixelFormat D3D11Mappings::getClosestSupportedPF(PixelFormat pf, TextureType texType, int usage)
 	{
 	{
-		if (getPF(pf, hwGamma, usage) != DXGI_FORMAT_UNKNOWN)
-		{
-			return pf;
-		}
+		// Check for any obvious issues first
+		PixelUtil::checkFormat(pf, texType, usage);
 
 
+		// Check for formats that are not supported at all by DX11
 		switch(pf)
 		switch(pf)
 		{
 		{
-		case PF_BC4:
-			return PF_R8;
-		case PF_BC5:
-			return PF_R8G8;
-		case PF_FLOAT16_RGB:
-		case PF_BC6H:
-			return PF_FLOAT16_RGBA;
-		case PF_FLOAT32_RGB:
-			return PF_FLOAT32_RGBA;
 		case PF_R8G8B8:
 		case PF_R8G8B8:
+			pf = PF_R8G8B8A8;
+			break;
 		case PF_B8G8R8:
 		case PF_B8G8R8:
-		case PF_BC1:
-		case PF_BC1a:
-		case PF_BC2:
-		case PF_BC3:
-		case PF_UNKNOWN:
-			return PF_R8G8B8A8;
-		case PF_D32_S8X24:
-			return PF_FLOAT32_RG;
-		case PF_D24S8:
-		case PF_D32:
-			return PF_FLOAT32_R;
-		case PF_D16:
-			return PF_FLOAT16_R;
+			pf = PF_B8G8R8A8;
+			break;
+		case PF_FLOAT16_RGB:
+			pf = PF_FLOAT16_RGBA;
+			break;
 		default:
 		default:
-			return PF_R8G8B8A8;
+			break;
 		}
 		}
+
+		// Check for usage specific format restrictions
+		if((usage & TU_LOADSTORE) != 0)
+		{
+			switch (pf)
+			{
+			case PF_B8G8R8A8:
+				pf = PF_R8G8B8A8;
+				break;
+			default:
+				break;
+			}
+		}
+
+		return pf;
 	}
 	}
 
 
 	D3D11_USAGE D3D11Mappings::getUsage(GpuBufferUsage usage)
 	D3D11_USAGE D3D11Mappings::getUsage(GpuBufferUsage usage)

+ 17 - 24
Source/BansheeD3D11RenderAPI/Source/BsD3D11Texture.cpp

@@ -17,7 +17,7 @@ namespace bs
 		GpuDeviceFlags deviceMask)
 		GpuDeviceFlags deviceMask)
 		: TextureCore(desc, initialData, deviceMask),
 		: TextureCore(desc, initialData, deviceMask),
 		m1DTex(nullptr), m2DTex(nullptr), m3DTex(nullptr), mDXGIFormat(DXGI_FORMAT_UNKNOWN), mDXGIColorFormat(DXGI_FORMAT_UNKNOWN),
 		m1DTex(nullptr), m2DTex(nullptr), m3DTex(nullptr), mDXGIFormat(DXGI_FORMAT_UNKNOWN), mDXGIColorFormat(DXGI_FORMAT_UNKNOWN),
-		mTex(nullptr), mStagingBuffer(nullptr), mDXGIDepthStencilFormat(DXGI_FORMAT_UNKNOWN),
+		mTex(nullptr), mInternalFormat(PF_UNKNOWN), mStagingBuffer(nullptr), mDXGIDepthStencilFormat(DXGI_FORMAT_UNKNOWN),
 		mLockedSubresourceIdx(-1), mLockedForReading(false), mStaticBuffer(nullptr)
 		mLockedSubresourceIdx(-1), mLockedForReading(false), mStaticBuffer(nullptr)
 	{
 	{
 		assert((deviceMask == GDF_DEFAULT || deviceMask == GDF_PRIMARY) && "Multiple GPUs not supported natively on DirectX 11.");
 		assert((deviceMask == GDF_DEFAULT || deviceMask == GDF_PRIMARY) && "Multiple GPUs not supported natively on DirectX 11.");
@@ -116,12 +116,10 @@ namespace bs
 		UINT32 mipHeight = std::max(1u, mProperties.getHeight() >> mipLevel);
 		UINT32 mipHeight = std::max(1u, mProperties.getHeight() >> mipLevel);
 		UINT32 mipDepth = std::max(1u, mProperties.getDepth() >> mipLevel);
 		UINT32 mipDepth = std::max(1u, mProperties.getDepth() >> mipLevel);
 
 
-		PixelData lockedArea(mipWidth, mipHeight, mipDepth, mProperties.getFormat());
+		PixelData lockedArea(mipWidth, mipHeight, mipDepth, mInternalFormat);
 
 
 		D3D11_MAP flags = D3D11Mappings::getLockOptions(options);
 		D3D11_MAP flags = D3D11Mappings::getLockOptions(options);
-
 		UINT32 rowPitch, slicePitch;
 		UINT32 rowPitch, slicePitch;
-
 		if(flags == D3D11_MAP_READ || flags == D3D11_MAP_READ_WRITE)
 		if(flags == D3D11_MAP_READ || flags == D3D11_MAP_READ_WRITE)
 		{
 		{
 			UINT8* data = (UINT8*)mapstagingbuffer(flags, face, mipLevel, rowPitch, slicePitch);
 			UINT8* data = (UINT8*)mapstagingbuffer(flags, face, mipLevel, rowPitch, slicePitch);
@@ -170,17 +168,7 @@ namespace bs
 		}
 		}
 
 
 		PixelData myData = lock(GBL_READ_ONLY, mipLevel, face, deviceIdx, queueIdx);
 		PixelData myData = lock(GBL_READ_ONLY, mipLevel, face, deviceIdx, queueIdx);
-
-#if BS_DEBUG_MODE
-		if(dest.getConsecutiveSize() != myData.getConsecutiveSize())
-		{
-			unlock();
-			BS_EXCEPT(InternalErrorException, "Buffer sizes don't match");
-		}
-#endif
-
 		PixelUtil::bulkPixelConversion(myData, dest);
 		PixelUtil::bulkPixelConversion(myData, dest);
-
 		unlock();
 		unlock();
 	}
 	}
 
 
@@ -242,7 +230,7 @@ namespace bs
 		UINT32 numMips = mProperties.getNumMipmaps();
 		UINT32 numMips = mProperties.getNumMipmaps();
 		PixelFormat format = mProperties.getFormat();
 		PixelFormat format = mProperties.getFormat();
 		bool hwGamma = mProperties.isHardwareGammaEnabled();
 		bool hwGamma = mProperties.isHardwareGammaEnabled();
-		PixelFormat closestFormat = D3D11Mappings::getClosestSupportedPF(format, hwGamma, usage);
+		PixelFormat closestFormat = D3D11Mappings::getClosestSupportedPF(format, TEX_TYPE_1D, usage);
 		UINT32 numFaces = mProperties.getNumFaces();
 		UINT32 numFaces = mProperties.getNumFaces();
 
 
 		// We must have those defined here
 		// We must have those defined here
@@ -250,13 +238,15 @@ namespace bs
 
 
 		// Determine which D3D11 pixel format we'll use
 		// Determine which D3D11 pixel format we'll use
 		HRESULT hr;
 		HRESULT hr;
-		DXGI_FORMAT d3dPF = D3D11Mappings::getPF(closestFormat, hwGamma, usage);
+		DXGI_FORMAT d3dPF = D3D11Mappings::getPF(closestFormat, hwGamma);
 
 
 		if (format != D3D11Mappings::getPF(d3dPF))
 		if (format != D3D11Mappings::getPF(d3dPF))
 		{
 		{
-			BS_EXCEPT(RenderingAPIException, "Provided pixel format is not supported by the driver: " + toString(format));
+			LOGWRN(StringUtil::format("Provided pixel format is not supported by the driver: {0}. Falling back on: {1}.",
+									  format, closestFormat));
 		}
 		}
 
 
+		mInternalFormat = closestFormat;
 		mDXGIColorFormat = d3dPF;
 		mDXGIColorFormat = d3dPF;
 		mDXGIDepthStencilFormat = d3dPF;
 		mDXGIDepthStencilFormat = d3dPF;
 
 
@@ -360,7 +350,7 @@ namespace bs
 		bool hwGamma = mProperties.isHardwareGammaEnabled();
 		bool hwGamma = mProperties.isHardwareGammaEnabled();
 		UINT32 sampleCount = mProperties.getNumSamples();
 		UINT32 sampleCount = mProperties.getNumSamples();
 		TextureType texType = mProperties.getTextureType();
 		TextureType texType = mProperties.getTextureType();
-		PixelFormat closestFormat = D3D11Mappings::getClosestSupportedPF(format, hwGamma, usage);
+		PixelFormat closestFormat = D3D11Mappings::getClosestSupportedPF(format, texType, usage);
 		UINT32 numFaces = mProperties.getNumFaces();
 		UINT32 numFaces = mProperties.getNumFaces();
 
 
 		// TODO - Consider making this a parameter eventually
 		// TODO - Consider making this a parameter eventually
@@ -371,14 +361,15 @@ namespace bs
 
 
 		// Determine which D3D11 pixel format we'll use
 		// Determine which D3D11 pixel format we'll use
 		HRESULT hr;
 		HRESULT hr;
-		DXGI_FORMAT d3dPF = D3D11Mappings::getPF(closestFormat, hwGamma, usage);
+		DXGI_FORMAT d3dPF = D3D11Mappings::getPF(closestFormat, hwGamma);
 
 
 		if (format != D3D11Mappings::getPF(d3dPF))
 		if (format != D3D11Mappings::getPF(d3dPF))
 		{
 		{
-			LOGWRN("Provided pixel format is not supported by the driver: " + toString(format) + ". Using " +
-				toString(closestFormat) + " instead.");
+			LOGWRN(StringUtil::format("Provided pixel format is not supported by the driver: {0}. Falling back on: {1}.",
+									  format, closestFormat));
 		}
 		}
 
 
+		mInternalFormat = closestFormat;
 		mDXGIColorFormat = d3dPF;
 		mDXGIColorFormat = d3dPF;
 		mDXGIDepthStencilFormat = d3dPF;
 		mDXGIDepthStencilFormat = d3dPF;
 
 
@@ -506,7 +497,7 @@ namespace bs
 		UINT32 numMips = mProperties.getNumMipmaps();
 		UINT32 numMips = mProperties.getNumMipmaps();
 		PixelFormat format = mProperties.getFormat();
 		PixelFormat format = mProperties.getFormat();
 		bool hwGamma = mProperties.isHardwareGammaEnabled();
 		bool hwGamma = mProperties.isHardwareGammaEnabled();
-		PixelFormat closestFormat = D3D11Mappings::getClosestSupportedPF(format, hwGamma, usage);
+		PixelFormat closestFormat = D3D11Mappings::getClosestSupportedPF(format, TEX_TYPE_3D, usage);
 
 
 		// TODO - Consider making this a parameter eventually
 		// TODO - Consider making this a parameter eventually
 		bool readableDepth = true;
 		bool readableDepth = true;
@@ -516,13 +507,15 @@ namespace bs
 
 
 		// Determine which D3D11 pixel format we'll use
 		// Determine which D3D11 pixel format we'll use
 		HRESULT hr;
 		HRESULT hr;
-		DXGI_FORMAT d3dPF = D3D11Mappings::getPF(closestFormat, hwGamma, usage);
+		DXGI_FORMAT d3dPF = D3D11Mappings::getPF(closestFormat, hwGamma);
 		
 		
 		if (format != D3D11Mappings::getPF(d3dPF))
 		if (format != D3D11Mappings::getPF(d3dPF))
 		{
 		{
-			BS_EXCEPT(RenderingAPIException, "Provided pixel format is not supported by the driver: " + toString(format));
+			LOGWRN(StringUtil::format("Provided pixel format is not supported by the driver: {0}. Falling back on: {1}.",
+									  format, closestFormat));
 		}
 		}
 
 
+		mInternalFormat = closestFormat;
 		mDXGIColorFormat = d3dPF;
 		mDXGIColorFormat = d3dPF;
 		mDXGIDepthStencilFormat = d3dPF;
 		mDXGIDepthStencilFormat = d3dPF;
 
 

+ 1 - 3
Source/BansheeD3D11RenderAPI/Source/BsD3D11TextureManager.cpp

@@ -17,9 +17,7 @@ namespace bs
 
 
 	PixelFormat D3D11TextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage, bool hwGamma)
 	PixelFormat D3D11TextureManager::getNativeFormat(TextureType ttype, PixelFormat format, int usage, bool hwGamma)
 	{
 	{
-		// Basic filtering
-		DXGI_FORMAT d3dPF = D3D11Mappings::getPF(D3D11Mappings::getClosestSupportedPF(format, hwGamma, usage), 
-			hwGamma, usage);
+		DXGI_FORMAT d3dPF = D3D11Mappings::getPF(D3D11Mappings::getClosestSupportedPF(format, ttype, usage), hwGamma);
 
 
 		return D3D11Mappings::getPF(d3dPF);
 		return D3D11Mappings::getPF(d3dPF);
 	}
 	}