AbstractTexture: Support BGRA8 formats

Used for some driver's swap chains, and EFB to RAM.
This commit is contained in:
Stenzek 2017-09-09 15:24:41 +10:00
parent 49a9c33bd7
commit a584ccc7d8
5 changed files with 36 additions and 5 deletions

View File

@ -40,7 +40,11 @@ DXGI_FORMAT GetDXGIFormatForHostFormat(AbstractTextureFormat format)
case AbstractTextureFormat::BPTC: case AbstractTextureFormat::BPTC:
return DXGI_FORMAT_BC7_UNORM; return DXGI_FORMAT_BC7_UNORM;
case AbstractTextureFormat::RGBA8: case AbstractTextureFormat::RGBA8:
return DXGI_FORMAT_R8G8B8A8_UNORM;
case AbstractTextureFormat::BGRA8:
return DXGI_FORMAT_B8G8R8A8_UNORM;
default: default:
PanicAlert("Unhandled texture format.");
return DXGI_FORMAT_R8G8B8A8_UNORM; return DXGI_FORMAT_R8G8B8A8_UNORM;
} }
} }

View File

@ -35,7 +35,11 @@ GLenum GetGLInternalFormatForTextureFormat(AbstractTextureFormat format, bool st
case AbstractTextureFormat::BPTC: case AbstractTextureFormat::BPTC:
return GL_COMPRESSED_RGBA_BPTC_UNORM_ARB; return GL_COMPRESSED_RGBA_BPTC_UNORM_ARB;
case AbstractTextureFormat::RGBA8: case AbstractTextureFormat::RGBA8:
return storage ? GL_RGBA8 : GL_RGBA;
case AbstractTextureFormat::BGRA8:
return GL_BGRA;
default: default:
PanicAlert("Unhandled texture format.");
return storage ? GL_RGBA8 : GL_RGBA; return storage ? GL_RGBA8 : GL_RGBA;
} }
} }
@ -46,6 +50,8 @@ GLenum GetGLFormatForTextureFormat(AbstractTextureFormat format)
{ {
case AbstractTextureFormat::RGBA8: case AbstractTextureFormat::RGBA8:
return GL_RGBA; return GL_RGBA;
case AbstractTextureFormat::BGRA8:
return GL_BGRA;
// Compressed texture formats don't use this parameter. // Compressed texture formats don't use this parameter.
default: default:
return GL_UNSIGNED_BYTE; return GL_UNSIGNED_BYTE;
@ -57,6 +63,7 @@ GLenum GetGLTypeForTextureFormat(AbstractTextureFormat format)
switch (format) switch (format)
{ {
case AbstractTextureFormat::RGBA8: case AbstractTextureFormat::RGBA8:
case AbstractTextureFormat::BGRA8:
return GL_UNSIGNED_BYTE; return GL_UNSIGNED_BYTE;
// Compressed texture formats don't use this parameter. // Compressed texture formats don't use this parameter.
default: default:

View File

@ -107,7 +107,13 @@ VkFormat GetVkFormatForHostTextureFormat(AbstractTextureFormat format)
return VK_FORMAT_BC7_UNORM_BLOCK; return VK_FORMAT_BC7_UNORM_BLOCK;
case AbstractTextureFormat::RGBA8: case AbstractTextureFormat::RGBA8:
return VK_FORMAT_R8G8B8A8_UNORM;
case AbstractTextureFormat::BGRA8:
return VK_FORMAT_B8G8R8A8_UNORM;
default: default:
PanicAlert("Unhandled texture format.");
return VK_FORMAT_R8G8B8A8_UNORM; return VK_FORMAT_R8G8B8A8_UNORM;
} }
} }

View File

@ -5,7 +5,7 @@
#include <algorithm> #include <algorithm>
#include "Common/Assert.h" #include "Common/Assert.h"
#include "Common/MsgHandler.h"
#include "VideoCommon/AbstractTexture.h" #include "VideoCommon/AbstractTexture.h"
#include "VideoCommon/ImageWrite.h" #include "VideoCommon/ImageWrite.h"
@ -102,8 +102,17 @@ AbstractTexture::MapRegionImpl(u32 level, u32 x, u32 y, u32 width, u32 height)
bool AbstractTexture::IsCompressedHostTextureFormat(AbstractTextureFormat format) bool AbstractTexture::IsCompressedHostTextureFormat(AbstractTextureFormat format)
{ {
// This will need to be changed if we add any other uncompressed formats. switch (format)
return format != AbstractTextureFormat::RGBA8; {
case AbstractTextureFormat::DXT1:
case AbstractTextureFormat::DXT3:
case AbstractTextureFormat::DXT5:
case AbstractTextureFormat::BPTC:
return true;
default:
return false;
}
} }
size_t AbstractTexture::CalculateHostTextureLevelPitch(AbstractTextureFormat format, u32 row_length) size_t AbstractTexture::CalculateHostTextureLevelPitch(AbstractTextureFormat format, u32 row_length)
@ -117,8 +126,11 @@ size_t AbstractTexture::CalculateHostTextureLevelPitch(AbstractTextureFormat for
case AbstractTextureFormat::BPTC: case AbstractTextureFormat::BPTC:
return static_cast<size_t>(std::max(1u, row_length / 4)) * 16; return static_cast<size_t>(std::max(1u, row_length / 4)) * 16;
case AbstractTextureFormat::RGBA8: case AbstractTextureFormat::RGBA8:
default: case AbstractTextureFormat::BGRA8:
return static_cast<size_t>(row_length) * 4; return static_cast<size_t>(row_length) * 4;
default:
PanicAlert("Unhandled texture format.");
return 0;
} }
} }

View File

@ -13,10 +13,12 @@
enum class AbstractTextureFormat : u32 enum class AbstractTextureFormat : u32
{ {
RGBA8, RGBA8,
BGRA8,
DXT1, DXT1,
DXT3, DXT3,
DXT5, DXT5,
BPTC BPTC,
Undefined
}; };
struct TextureConfig struct TextureConfig