Add DXT5/BPTC (BC3/BC7) texture formats

This commit is contained in:
Luke Street 2020-02-27 03:59:41 -05:00
parent 56a6b06210
commit 217031ebb9
5 changed files with 50 additions and 4 deletions

View File

@ -48,7 +48,7 @@ protected:
enum class TextureType { Static, StaticArray, Dynamic, Render, CubeRender };
/** Supported texture formats */
enum class TextureFormat { RGBA8, I8, I16, DXT1, DXT3, PVRTC4 };
enum class TextureFormat { RGBA8, I8, I16, DXT1, DXT3, DXT5, BPTC };
/** Supported texture clamp modes */
enum class TextureClampMode { Invalid = -1, Repeat, ClampToWhite, ClampToBlack, ClampToEdge, ClampToEdgeNearest };

View File

@ -179,6 +179,20 @@ class D3D11TextureS : public GraphicsDataNode<ITextureS> {
pxPitchDenom = 1;
pxTilePitch = 4;
break;
case TextureFormat::DXT5:
pfmt = DXGI_FORMAT_BC3_UNORM;
compressed = true;
pxPitchNum = 1;
pxPitchDenom = 1;
pxTilePitch = 4;
break;
case TextureFormat::BPTC:
pfmt = DXGI_FORMAT_BC7_UNORM;
compressed = true;
pxPitchNum = 1;
pxPitchDenom = 1;
pxTilePitch = 4;
break;
default:
Log.report(logvisor::Fatal, fmt("unsupported tex format"));
}

View File

@ -335,6 +335,16 @@ class GLTextureS : public GraphicsDataNode<ITextureS> {
compressed = true;
pxPitch = 1;
break;
case TextureFormat::DXT5:
intFormat = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
compressed = true;
pxPitch = 1;
break;
case TextureFormat::BPTC:
intFormat = GL_COMPRESSED_RGBA_BPTC_UNORM_ARB;
compressed = true;
pxPitch = 1;
break;
default:
Log.report(logvisor::Fatal, fmt("unsupported tex format"));
}

View File

@ -85,7 +85,7 @@ class MetalDataFactoryImpl : public MetalDataFactory, public GraphicsDataFactory
ObjToken<ITextureD> m_gammaLUT;
ObjToken<IGraphicsBufferS> m_gammaVBO;
ObjToken<IShaderDataBinding> m_gammaBinding;
void SetupGammaResources();
public:
@ -232,6 +232,18 @@ class MetalTextureS : public GraphicsDataNode<ITextureS> {
ppitchDenom = 1;
bytesPerRow = width * 16 / 4; // Metal wants this in blocks, not bytes
break;
case TextureFormat::DXT5:
pfmt = MTLPixelFormatBC3_RGBA;
ppitchNum = 1;
ppitchDenom = 1;
bytesPerRow = width * 16 / 4; // Metal wants this in blocks, not bytes
break;
case TextureFormat::BPTC:
pfmt = MTLPixelFormatBC7_RGBAUnorm;
ppitchNum = 1;
ppitchDenom = 1;
bytesPerRow = width * 16 / 4; // Metal wants this in blocks, not bytes
break;
default:
break;
}
@ -1977,10 +1989,10 @@ std::vector<uint8_t> MetalDataFactory::CompileMetal(const char* source, Pipeline
memcpy(ret.data() + 1, source, strSz);
return ret;
}
void MetalDataFactoryImpl::SetupGammaResources() {
m_hasTessellation = [m_ctx->m_dev supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v2];
commitTransaction([this](IGraphicsDataFactory::Context& ctx) {
auto vertexMetal = MetalDataFactory::CompileMetal(GammaVS, PipelineStage::Vertex);
auto vertexShader = ctx.newShaderStage(vertexMetal, PipelineStage::Vertex);

View File

@ -1383,6 +1383,16 @@ class VulkanTextureS : public GraphicsDataNode<ITextureS> {
m_pixelPitchNum = 1;
m_pixelPitchDenom = 1;
break;
case TextureFormat::DXT5:
pfmt = VK_FORMAT_BC3_UNORM_BLOCK;
m_pixelPitchNum = 1;
m_pixelPitchDenom = 1;
break;
case TextureFormat::BPTC:
pfmt = VK_FORMAT_BC7_UNORM_BLOCK;
m_pixelPitchNum = 1;
m_pixelPitchDenom = 1;
break;
default:
Log.report(logvisor::Fatal, fmt("unsupported tex format"));
}