Deep color CVar and GLSL backend bug fixes

This commit is contained in:
Jack Andersen 2018-01-15 20:30:37 -10:00
parent da5ba6cdf3
commit ac29a724ba
9 changed files with 93 additions and 60 deletions

2
hecl/extern/boo vendored

@ -1 +1 @@
Subproject commit 41cfb56c36d2b67e8da95106eac22a1fda1bcb9a
Subproject commit 3d987b6dc9e2c06072a5a09832e85bbd4279c2a4

View File

@ -13,7 +13,7 @@ struct GLSL : ProgrammableCommon
{
void reset(const IR& ir, Diagnostics& diag);
std::string makeVert(const char* glslVer, unsigned col, unsigned uv, unsigned w,
unsigned skinSlots, unsigned texMtxs, size_t extTexCount,
unsigned skinSlots, size_t extTexCount,
const TextureInfo* extTexs, ReflectionType reflectionType) const;
std::string makeFrag(const char* glslVer, bool alphaTest, ReflectionType reflectionType,
const ShaderFunction& lighting=ShaderFunction()) const;
@ -26,7 +26,7 @@ struct GLSL : ProgrammableCommon
private:
std::string GenerateVertInStruct(unsigned col, unsigned uv, unsigned w) const;
std::string GenerateVertToFragStruct(size_t extTexCount, bool reflectionCoords) const;
std::string GenerateVertUniformStruct(unsigned skinSlots, unsigned texMtxs, bool reflectionCoords) const;
std::string GenerateVertUniformStruct(unsigned skinSlots, bool reflectionCoords) const;
std::string GenerateAlphaTest() const;
std::string GenerateReflectionExpr(ReflectionType type) const;

View File

@ -10,7 +10,7 @@ struct HLSL : ProgrammableCommon
{
void reset(const IR& ir, Diagnostics& diag);
std::string makeVert(unsigned col, unsigned uv, unsigned w,
unsigned skinSlots, unsigned texMtxs, size_t extTexCount,
unsigned skinSlots, size_t extTexCount,
const TextureInfo* extTexs, ReflectionType reflectionType) const;
std::string makeFrag(bool alphaTest, ReflectionType reflectionType,
const ShaderFunction& lighting=ShaderFunction()) const;
@ -22,7 +22,7 @@ struct HLSL : ProgrammableCommon
private:
std::string GenerateVertInStruct(unsigned col, unsigned uv, unsigned w) const;
std::string GenerateVertToFragStruct(size_t extTexCount, bool reflectionCoords) const;
std::string GenerateVertUniformStruct(unsigned skinSlots, unsigned texMtxs, bool reflectionCoords) const;
std::string GenerateVertUniformStruct(unsigned skinSlots, bool reflectionCoords) const;
std::string GenerateAlphaTest() const;
std::string GenerateReflectionExpr(ReflectionType type) const;

View File

@ -12,7 +12,7 @@ struct Metal : ProgrammableCommon
{
void reset(const IR& ir, Diagnostics& diag);
std::string makeVert(unsigned col, unsigned uv, unsigned w,
unsigned skinSlots, unsigned texMtxs, size_t extTexCount,
unsigned skinSlots, size_t extTexCount,
const TextureInfo* extTexs, ReflectionType reflectionType) const;
std::string makeFrag(size_t blockCount, const char** blockNames, bool alphaTest,
ReflectionType reflectionType,

View File

@ -25,18 +25,22 @@ class CVarCommons
std::string m_graphicsApi = DEFAULT_GRAPHICS_API;
uint32_t m_drawSamples = 1;
uint32_t m_texAnisotropy = 1;
bool m_deepColor = false;
public:
CVarCommons(CVarManager& manager) : m_mgr(manager)
{
m_mgr.findOrMakeCVar("graphicsApi"sv,
"API to use for rendering graphics"sv,
m_graphicsApi, hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ModifyRestart);
"API to use for rendering graphics"sv,
m_graphicsApi, hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ModifyRestart);
m_mgr.findOrMakeCVar("drawSamples"sv,
"Number of MSAA samples to use for render targets"sv,
m_drawSamples, hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ModifyRestart);
"Number of MSAA samples to use for render targets"sv,
m_drawSamples, hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ModifyRestart);
m_mgr.findOrMakeCVar("texAnisotropy"sv,
"Number of anisotropic samples to use for sampling textures"sv,
m_texAnisotropy, hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ModifyRestart);
"Number of anisotropic samples to use for sampling textures"sv,
m_texAnisotropy, hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ModifyRestart);
m_mgr.findOrMakeCVar("deepColor"sv,
"Allow framebuffer with color depth greater-then 24-bits"sv,
m_deepColor, hecl::CVar::EFlags::System | hecl::CVar::EFlags::Archive | hecl::CVar::EFlags::ModifyRestart);
}
std::string getGraphicsApi() const
@ -69,6 +73,16 @@ public:
m_texAnisotropy = std::max(uint32_t(1), v);
}
bool getDeepColor() const
{
return m_deepColor;
}
void setDeepColor(bool b)
{
m_deepColor = b;
}
void serialize()
{
m_mgr.serialize();

View File

@ -47,7 +47,6 @@ class ShaderTag : public Hash
uint8_t m_uvCount;
uint8_t m_weightCount;
uint8_t m_skinSlotCount;
uint8_t m_texMtxCount;
uint8_t m_primitiveType;
uint8_t m_reflectionType;
bool m_depthTest:1;
@ -57,21 +56,21 @@ class ShaderTag : public Hash
};
public:
ShaderTag() = default;
ShaderTag(std::string_view source, uint8_t c, uint8_t u, uint8_t w, uint8_t s, uint8_t t, boo::Primitive pt,
ShaderTag(std::string_view source, uint8_t c, uint8_t u, uint8_t w, uint8_t s, boo::Primitive pt,
Backend::ReflectionType reflectionType, bool depthTest, bool depthWrite, bool backfaceCulling)
: Hash(source), m_colorCount(c), m_uvCount(u), m_weightCount(w), m_skinSlotCount(s), m_texMtxCount(t),
: Hash(source), m_colorCount(c), m_uvCount(u), m_weightCount(w), m_skinSlotCount(s),
m_primitiveType(uint8_t(pt)), m_reflectionType(uint8_t(reflectionType)),
m_depthTest(depthTest), m_depthWrite(depthWrite), m_backfaceCulling(backfaceCulling)
{hash ^= m_meta;}
ShaderTag(const hecl::Frontend::IR& ir, uint8_t c, uint8_t u, uint8_t w, uint8_t s, uint8_t t, boo::Primitive pt,
ShaderTag(const hecl::Frontend::IR& ir, uint8_t c, uint8_t u, uint8_t w, uint8_t s, boo::Primitive pt,
Backend::ReflectionType reflectionType, bool depthTest, bool depthWrite, bool backfaceCulling)
: Hash(ir.m_hash), m_colorCount(c), m_uvCount(u), m_weightCount(w), m_skinSlotCount(s), m_texMtxCount(t),
: Hash(ir.m_hash), m_colorCount(c), m_uvCount(u), m_weightCount(w), m_skinSlotCount(s),
m_primitiveType(uint8_t(pt)), m_reflectionType(uint8_t(reflectionType)),
m_depthTest(depthTest), m_depthWrite(depthWrite), m_backfaceCulling(backfaceCulling)
{hash ^= m_meta;}
ShaderTag(uint64_t hashin, uint8_t c, uint8_t u, uint8_t w, uint8_t s, uint8_t t, boo::Primitive pt,
ShaderTag(uint64_t hashin, uint8_t c, uint8_t u, uint8_t w, uint8_t s, boo::Primitive pt,
Backend::ReflectionType reflectionType, bool depthTest, bool depthWrite, bool backfaceCulling)
: Hash(hashin), m_colorCount(c), m_uvCount(u), m_weightCount(w), m_skinSlotCount(s), m_texMtxCount(t),
: Hash(hashin), m_colorCount(c), m_uvCount(u), m_weightCount(w), m_skinSlotCount(s),
m_primitiveType(uint8_t(pt)), m_reflectionType(uint8_t(reflectionType)),
m_depthTest(depthTest), m_depthWrite(depthWrite), m_backfaceCulling(backfaceCulling)
{hash ^= m_meta;}
@ -82,7 +81,6 @@ public:
uint8_t getUvCount() const {return m_uvCount;}
uint8_t getWeightCount() const {return m_weightCount;}
uint8_t getSkinSlotCount() const {return m_skinSlotCount;}
uint8_t getTexMtxCount() const {return m_texMtxCount;}
boo::Primitive getPrimType() const {return boo::Primitive(m_primitiveType);}
Backend::ReflectionType getReflectionType() const {return Backend::ReflectionType(m_reflectionType);}
bool getDepthTest() const {return m_depthTest;}

View File

@ -87,7 +87,7 @@ std::string GLSL::GenerateVertToFragStruct(size_t extTexCount, bool reflectionCo
return retval + "};\n";
}
std::string GLSL::GenerateVertUniformStruct(unsigned skinSlots, unsigned texMtxs, bool reflectionCoords) const
std::string GLSL::GenerateVertUniformStruct(unsigned skinSlots, bool reflectionCoords) const
{
if (skinSlots == 0)
skinSlots = 1;
@ -98,16 +98,16 @@ std::string GLSL::GenerateVertUniformStruct(unsigned skinSlots, unsigned texMtxs
" mat4 proj;\n"
"};\n",
skinSlots, skinSlots);
if (texMtxs)
retval += hecl::Format("struct HECLTCGMatrix\n"
"{\n"
" mat4 mtx;\n"
" mat4 postMtx;\n"
"};\n"
"UBINDING1 uniform HECLTexMtxUniform\n"
"{\n"
" HECLTCGMatrix texMtxs[%u];\n"
"};\n", texMtxs);
retval += "struct HECLTCGMatrix\n"
"{\n"
" mat4 mtx;\n"
" mat4 postMtx;\n"
"};\n"
"UBINDING1 uniform HECLTexMtxUniform\n"
"{\n"
" HECLTCGMatrix texMtxs[8];\n"
"};\n";
if (reflectionCoords)
retval += "UBINDING3 uniform HECLReflectMtx\n"
@ -151,14 +151,14 @@ void GLSL::reset(const IR& ir, Diagnostics& diag)
}
std::string GLSL::makeVert(const char* glslVer, unsigned col, unsigned uv, unsigned w,
unsigned s, unsigned tm, size_t extTexCount,
unsigned s, size_t extTexCount,
const TextureInfo* extTexs, ReflectionType reflectionType) const
{
extTexCount = std::min(int(extTexCount), BOO_GLSL_MAX_TEXTURE_COUNT - int(m_tcgs.size()));
std::string retval = std::string(glslVer) + "\n" BOO_GLSL_BINDING_HEAD +
GenerateVertInStruct(col, uv, w) + "\n" +
GenerateVertToFragStruct(extTexCount, reflectionType != ReflectionType::None) + "\n" +
GenerateVertUniformStruct(s, tm, reflectionType != ReflectionType::None) +
GenerateVertUniformStruct(s, reflectionType != ReflectionType::None) +
"SBINDING(0) out VertToFrag vtf;\n\n"
"void main()\n{\n";
@ -381,6 +381,18 @@ static const char* STD_TEXNAMES[] =
"tex7"
};
static const char* EXT_TEXNAMES[] =
{
"extTex0",
"extTex1",
"extTex2",
"extTex3",
"extTex4",
"extTex5",
"extTex6",
"extTex7"
};
struct GLSLBackendFactory : IShaderBackendFactory
{
Backend::GLSL m_backend;
@ -397,7 +409,7 @@ struct GLSLBackendFactory : IShaderBackendFactory
std::string vertSource =
m_backend.makeVert("#version 330",
tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(),
tag.getSkinSlotCount(), tag.getTexMtxCount(), 0, nullptr, tag.getReflectionType());
tag.getSkinSlotCount(), 0, nullptr, tag.getReflectionType());
cachedSz += vertSource.size() + 1;
std::string fragSource = m_backend.makeFrag("#version 330",
@ -490,7 +502,7 @@ struct GLSLBackendFactory : IShaderBackendFactory
sources.emplace_back(m_backend.makeVert("#version 330",
tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(),
tag.getSkinSlotCount(), tag.getTexMtxCount(), slot.texCount,
tag.getSkinSlotCount(), slot.texCount,
slot.texs, tag.getReflectionType()),
m_backend.makeFrag("#version 330",
tag.getDepthWrite() && m_backend.m_blendDst == hecl::Backend::BlendFactor::InvSrcAlpha,
@ -519,10 +531,16 @@ struct GLSLBackendFactory : IShaderBackendFactory
break;
}
const char* ExtTexnames[8];
for (int i=0 ; i<8 ; ++i)
ExtTexnames[i] = STD_TEXNAMES[i];
for (int i=0 ; i<slot.texCount ; ++i)
ExtTexnames[slot.texs[i].mapIdx] = EXT_TEXNAMES[slot.texs[i].mapIdx];
auto ret =
static_cast<boo::GLDataFactory::Context&>(ctx).
newShaderPipeline(sources.back().first.c_str(), sources.back().second.c_str(),
8, STD_TEXNAMES, bc, bn,
8, ExtTexnames, bc, bn,
boo::BlendFactor((slot.srcFactor == hecl::Backend::BlendFactor::Original) ? m_backend.m_blendSrc : slot.srcFactor),
boo::BlendFactor((slot.dstFactor == hecl::Backend::BlendFactor::Original) ? m_backend.m_blendDst : slot.dstFactor),
tag.getPrimType(), zTest, slot.noDepthWrite ? false : tag.getDepthWrite(), !slot.noColorWrite, !slot.noAlphaWrite,
@ -602,10 +620,16 @@ struct GLSLBackendFactory : IShaderBackendFactory
break;
}
const char* ExtTexnames[8];
for (int i=0 ; i<8 ; ++i)
ExtTexnames[i] = STD_TEXNAMES[i];
for (int i=0 ; i<slot.texCount ; ++i)
ExtTexnames[slot.texs[i].mapIdx] = EXT_TEXNAMES[slot.texs[i].mapIdx];
auto ret =
static_cast<boo::GLDataFactory::Context&>(ctx).
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
8, STD_TEXNAMES, bc, bn,
8, ExtTexnames, bc, bn,
boo::BlendFactor((slot.srcFactor == hecl::Backend::BlendFactor::Original) ? blendSrc : slot.srcFactor),
boo::BlendFactor((slot.dstFactor == hecl::Backend::BlendFactor::Original) ? blendDst : slot.dstFactor),
tag.getPrimType(), zTest, slot.noDepthWrite ? false : tag.getDepthWrite(), !slot.noColorWrite, !slot.noAlphaWrite,
@ -643,7 +667,7 @@ struct SPIRVBackendFactory : IShaderBackendFactory
std::string vertSource =
m_backend.makeVert("#version 330",
tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(),
tag.getSkinSlotCount(), tag.getTexMtxCount(), 0, nullptr,
tag.getSkinSlotCount(), 0, nullptr,
tag.getReflectionType());
std::string fragSource = m_backend.makeFrag("#version 330",
@ -771,7 +795,7 @@ struct SPIRVBackendFactory : IShaderBackendFactory
std::string vertSource =
m_backend.makeVert("#version 330",
tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(),
tag.getSkinSlotCount(), tag.getTexMtxCount(), slot.texCount, slot.texs,
tag.getSkinSlotCount(), slot.texCount, slot.texs,
tag.getReflectionType());
std::string fragSource = m_backend.makeFrag("#version 330",

View File

@ -80,7 +80,7 @@ std::string HLSL::GenerateVertToFragStruct(size_t extTexCount, bool reflectionCo
return retval + "};\n";
}
std::string HLSL::GenerateVertUniformStruct(unsigned skinSlots, unsigned texMtxs, bool reflectionCoords) const
std::string HLSL::GenerateVertUniformStruct(unsigned skinSlots, bool reflectionCoords) const
{
if (skinSlots == 0)
skinSlots = 1;
@ -91,16 +91,15 @@ std::string HLSL::GenerateVertUniformStruct(unsigned skinSlots, unsigned texMtxs
" float4x4 proj;\n"
"};\n",
skinSlots, skinSlots);
if (texMtxs)
retval += hecl::Format("struct TCGMtx\n"
"{\n"
" float4x4 mtx;\n"
" float4x4 postMtx;\n"
"};\n"
"cbuffer HECLTCGMatrix : register(b1)\n"
"{\n"
" TCGMtx texMtxs[%u];\n"
"};\n", texMtxs);
retval += "struct TCGMtx\n"
"{\n"
" float4x4 mtx;\n"
" float4x4 postMtx;\n"
"};\n"
"cbuffer HECLTCGMatrix : register(b1)\n"
"{\n"
" TCGMtx texMtxs[8];\n"
"};\n";
if (reflectionCoords)
retval += "cbuffer HECLReflectMtx : register(b3)\n"
@ -144,13 +143,13 @@ void HLSL::reset(const IR& ir, Diagnostics& diag)
}
std::string HLSL::makeVert(unsigned col, unsigned uv, unsigned w,
unsigned s, unsigned tm, size_t extTexCount,
unsigned s, size_t extTexCount,
const TextureInfo* extTexs, ReflectionType reflectionType) const
{
std::string retval =
GenerateVertInStruct(col, uv, w) + "\n" +
GenerateVertToFragStruct(extTexCount, reflectionType != ReflectionType::None) + "\n" +
GenerateVertUniformStruct(s, tm, reflectionType != ReflectionType::None) + "\n" +
GenerateVertUniformStruct(s, reflectionType != ReflectionType::None) + "\n" +
"VertToFrag main(in VertData v)\n"
"{\n"
" VertToFrag vtf;\n";
@ -365,7 +364,7 @@ struct HLSLBackendFactory : IShaderBackendFactory
std::string vertSource =
m_backend.makeVert(tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(),
tag.getSkinSlotCount(), tag.getTexMtxCount(), 0, nullptr,
tag.getSkinSlotCount(), 0, nullptr,
tag.getReflectionType());
std::string fragSource = m_backend.makeFrag(tag.getDepthWrite() && m_backend.m_blendDst == hecl::Backend::BlendFactor::InvSrcAlpha,
@ -505,7 +504,7 @@ struct HLSLBackendFactory : IShaderBackendFactory
{
std::string vertSource =
m_backend.makeVert(tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(),
tag.getSkinSlotCount(), tag.getTexMtxCount(), slot.texCount, slot.texs,
tag.getSkinSlotCount(), slot.texCount, slot.texs,
tag.getReflectionType());
std::string fragSource = m_backend.makeFrag(tag.getDepthWrite() && m_backend.m_blendDst == hecl::Backend::BlendFactor::InvSrcAlpha,

View File

@ -148,12 +148,10 @@ void Metal::reset(const IR& ir, Diagnostics& diag)
}
std::string Metal::makeVert(unsigned col, unsigned uv, unsigned w,
unsigned s, unsigned tm, size_t extTexCount,
unsigned s, size_t extTexCount,
const TextureInfo* extTexs, ReflectionType reflectionType) const
{
std::string tmStr;
if (tm)
tmStr = hecl::Format(",\nconstant TexMtxs* texMtxs [[ buffer(3) ]]");
std::string tmStr = ",\nconstant TexMtxs* texMtxs [[ buffer(3) ]]";
if (reflectionType != ReflectionType::None)
tmStr += ",\nconstant ReflectTexMtxs& reflectMtxs [[ buffer(5) ]]";
std::string retval = "#include <metal_stdlib>\nusing namespace metal;\n" +
@ -447,7 +445,7 @@ struct MetalBackendFactory : IShaderBackendFactory
std::string vertSource =
m_backend.makeVert(tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(),
tag.getSkinSlotCount(), tag.getTexMtxCount(), 0, nullptr, tag.getReflectionType());
tag.getSkinSlotCount(), 0, nullptr, tag.getReflectionType());
std::string fragSource = m_backend.makeFrag(0, nullptr,
tag.getDepthWrite() && m_backend.m_blendDst == hecl::Backend::BlendFactor::InvSrcAlpha,
@ -537,7 +535,7 @@ struct MetalBackendFactory : IShaderBackendFactory
{
std::string vertSource =
m_backend.makeVert(tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(),
tag.getSkinSlotCount(), tag.getTexMtxCount(), slot.texCount, slot.texs,
tag.getSkinSlotCount(), slot.texCount, slot.texs,
slot.noReflection ? Backend::ReflectionType::None : tag.getReflectionType());
std::string fragSource =
m_backend.makeFrag(slot.blockCount, slot.blockNames,