From ac29a724baccf8389ac1fe903557e0995e846b59 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Mon, 15 Jan 2018 20:30:37 -1000 Subject: [PATCH] Deep color CVar and GLSL backend bug fixes --- hecl/extern/boo | 2 +- hecl/include/hecl/Backend/GLSL.hpp | 4 +- hecl/include/hecl/Backend/HLSL.hpp | 4 +- hecl/include/hecl/Backend/Metal.hpp | 2 +- hecl/include/hecl/CVarCommons.hpp | 26 +++++++++--- hecl/include/hecl/Runtime.hpp | 14 +++---- hecl/lib/Backend/GLSL.cpp | 62 ++++++++++++++++++++--------- hecl/lib/Backend/HLSL.cpp | 29 +++++++------- hecl/lib/Backend/Metal.cpp | 10 ++--- 9 files changed, 93 insertions(+), 60 deletions(-) diff --git a/hecl/extern/boo b/hecl/extern/boo index 41cfb56c3..3d987b6dc 160000 --- a/hecl/extern/boo +++ b/hecl/extern/boo @@ -1 +1 @@ -Subproject commit 41cfb56c36d2b67e8da95106eac22a1fda1bcb9a +Subproject commit 3d987b6dc9e2c06072a5a09832e85bbd4279c2a4 diff --git a/hecl/include/hecl/Backend/GLSL.hpp b/hecl/include/hecl/Backend/GLSL.hpp index 4367a6d64..8c7f9db57 100644 --- a/hecl/include/hecl/Backend/GLSL.hpp +++ b/hecl/include/hecl/Backend/GLSL.hpp @@ -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; diff --git a/hecl/include/hecl/Backend/HLSL.hpp b/hecl/include/hecl/Backend/HLSL.hpp index f4ac0a7fb..ab9570f41 100644 --- a/hecl/include/hecl/Backend/HLSL.hpp +++ b/hecl/include/hecl/Backend/HLSL.hpp @@ -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; diff --git a/hecl/include/hecl/Backend/Metal.hpp b/hecl/include/hecl/Backend/Metal.hpp index dd644d25f..ed51b3532 100644 --- a/hecl/include/hecl/Backend/Metal.hpp +++ b/hecl/include/hecl/Backend/Metal.hpp @@ -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, diff --git a/hecl/include/hecl/CVarCommons.hpp b/hecl/include/hecl/CVarCommons.hpp index bdaf0fa43..331825cca 100644 --- a/hecl/include/hecl/CVarCommons.hpp +++ b/hecl/include/hecl/CVarCommons.hpp @@ -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(); diff --git a/hecl/include/hecl/Runtime.hpp b/hecl/include/hecl/Runtime.hpp index 25f1d5b70..f72b2f800 100644 --- a/hecl/include/hecl/Runtime.hpp +++ b/hecl/include/hecl/Runtime.hpp @@ -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;} diff --git a/hecl/lib/Backend/GLSL.cpp b/hecl/lib/Backend/GLSL.cpp index 0655a8afe..528fe3b08 100644 --- a/hecl/lib/Backend/GLSL.cpp +++ b/hecl/lib/Backend/GLSL.cpp @@ -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(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(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", diff --git a/hecl/lib/Backend/HLSL.cpp b/hecl/lib/Backend/HLSL.cpp index f8337fd70..2ca2eecd9 100644 --- a/hecl/lib/Backend/HLSL.cpp +++ b/hecl/lib/Backend/HLSL.cpp @@ -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, diff --git a/hecl/lib/Backend/Metal.cpp b/hecl/lib/Backend/Metal.cpp index a578dcb7d..c0feb5c86 100644 --- a/hecl/lib/Backend/Metal.cpp +++ b/hecl/lib/Backend/Metal.cpp @@ -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 \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,