From 9531d2bb020bf278878368be580e2f816eea6027 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sat, 30 Jul 2016 18:45:28 -1000 Subject: [PATCH] Fixes for extended shaders --- hecl/extern/boo | 2 +- hecl/include/hecl/Backend/Backend.hpp | 20 +++++- hecl/include/hecl/Backend/GLSL.hpp | 2 +- .../hecl/Backend/ProgrammableCommon.hpp | 5 +- hecl/include/hecl/Runtime.hpp | 7 +- hecl/lib/Backend/GLSL.cpp | 67 +++++++++++-------- hecl/lib/Backend/ProgrammableCommon.cpp | 12 ++-- 7 files changed, 75 insertions(+), 40 deletions(-) diff --git a/hecl/extern/boo b/hecl/extern/boo index bec368dfe..0ee594438 160000 --- a/hecl/extern/boo +++ b/hecl/extern/boo @@ -1 +1 @@ -Subproject commit bec368dfe7722d348c6eb0411e349a3c731ffd58 +Subproject commit 0ee594438714f38e4de982a4d51fdeaf689dd5c6 diff --git a/hecl/include/hecl/Backend/Backend.hpp b/hecl/include/hecl/Backend/Backend.hpp index 2047b3374..7052c3f5f 100644 --- a/hecl/include/hecl/Backend/Backend.hpp +++ b/hecl/include/hecl/Backend/Backend.hpp @@ -20,11 +20,29 @@ enum class TexGenSrc UV }; +enum class BlendFactor +{ + Zero, + One, + SrcColor, + InvSrcColor, + DstColor, + InvDstColor, + SrcAlpha, + InvSrcAlpha, + DstAlpha, + InvDstAlpha, + SrcColor1, + InvSrcColor1, + Original = 0xff +}; + struct TextureInfo { TexGenSrc src; + int mapIdx; int uvIdx; - int mtx; + int mtxIdx; bool normalize; }; diff --git a/hecl/include/hecl/Backend/GLSL.hpp b/hecl/include/hecl/Backend/GLSL.hpp index 33e4743eb..1926a2abb 100644 --- a/hecl/include/hecl/Backend/GLSL.hpp +++ b/hecl/include/hecl/Backend/GLSL.hpp @@ -22,7 +22,7 @@ struct GLSL : ProgrammableCommon std::string makeFrag(const char* glslVer, const ShaderFunction& lighting, const ShaderFunction& post, - size_t extTexCount) const; + size_t extTexCount, const TextureInfo* extTexs) const; private: std::string GenerateVertInStruct(unsigned col, unsigned uv, unsigned w) const; diff --git a/hecl/include/hecl/Backend/ProgrammableCommon.hpp b/hecl/include/hecl/Backend/ProgrammableCommon.hpp index 362837a78..d5ea01d62 100644 --- a/hecl/include/hecl/Backend/ProgrammableCommon.hpp +++ b/hecl/include/hecl/Backend/ProgrammableCommon.hpp @@ -4,7 +4,6 @@ #include "Backend.hpp" #include "hecl/Runtime.hpp" #include -#include #include #include #include @@ -20,8 +19,8 @@ struct ProgrammableCommon : IBackend std::string m_colorExpr; std::string m_alphaExpr; - boo::BlendFactor m_blendSrc; - boo::BlendFactor m_blendDst; + BlendFactor m_blendSrc; + BlendFactor m_blendDst; bool m_lighting = false; struct TexSampling diff --git a/hecl/include/hecl/Runtime.hpp b/hecl/include/hecl/Runtime.hpp index d6ba5f06e..e5164a6e6 100644 --- a/hecl/include/hecl/Runtime.hpp +++ b/hecl/include/hecl/Runtime.hpp @@ -133,6 +133,8 @@ public: const char** blockNames = nullptr; size_t texCount = 0; const Backend::TextureInfo* texs = nullptr; + Backend::BlendFactor srcFactor = Backend::BlendFactor::Original; + Backend::BlendFactor dstFactor = Backend::BlendFactor::Original; }; std::vector m_extensionSlots; @@ -146,7 +148,8 @@ public: /* Strings must remain resident!! (intended to be stored static const) */ unsigned registerExtensionSlot(Function lighting, Function post, size_t blockCount, const char** blockNames, - size_t texCount, const Backend::TextureInfo* texs) + size_t texCount, const Backend::TextureInfo* texs, + Backend::BlendFactor srcFactor, Backend::BlendFactor dstFactor) { m_extensionSlots.emplace_back(); ExtensionSlot& slot = m_extensionSlots.back(); @@ -156,6 +159,8 @@ public: slot.blockNames = blockNames; slot.texCount = texCount; slot.texs = texs; + slot.srcFactor = srcFactor; + slot.dstFactor = dstFactor; return m_extensionSlots.size() - 1; } }; diff --git a/hecl/lib/Backend/GLSL.cpp b/hecl/lib/Backend/GLSL.cpp index 99ddb4326..6a5fe2939 100644 --- a/hecl/lib/Backend/GLSL.cpp +++ b/hecl/lib/Backend/GLSL.cpp @@ -169,14 +169,13 @@ std::string GLSL::makeVert(const char* glslVer, unsigned col, unsigned uv, unsig for (int i=0 ; i(ctx). newShaderPipeline(sources.back().first.c_str(), sources.back().second.c_str(), - m_backend.m_texMapEnd, STD_TEXNAMES, bc, bn, - m_backend.m_blendSrc, m_backend.m_blendDst, tag.getPrimType(), - tag.getDepthTest(), tag.getDepthWrite(), - tag.getBackfaceCulling()); + 8, STD_TEXNAMES, 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(), tag.getDepthTest(), + tag.getDepthWrite(), tag.getBackfaceCulling()); if (!ret) Log.report(logvisor::Fatal, "unable to build shader"); returnFunc(ret); @@ -434,8 +442,8 @@ struct GLSLBackendFactory : IShaderBackendFactory const ShaderTag& tag = data.m_tag; athena::io::MemoryReader r(data.m_data.get(), data.m_sz); atUint8 texMapEnd = r.readUByte(); - boo::BlendFactor blendSrc = boo::BlendFactor(r.readUByte()); - boo::BlendFactor blendDst = boo::BlendFactor(r.readUByte()); + hecl::Backend::BlendFactor blendSrc = hecl::Backend::BlendFactor(r.readUByte()); + hecl::Backend::BlendFactor blendDst = hecl::Backend::BlendFactor(r.readUByte()); if (texMapEnd > 8) Log.report(logvisor::Fatal, "maximum of 8 texture maps supported"); @@ -455,9 +463,10 @@ struct GLSLBackendFactory : IShaderBackendFactory boo::IShaderPipeline* ret = static_cast(ctx). newShaderPipeline(vertSource.c_str(), fragSource.c_str(), - texMapEnd, STD_TEXNAMES, bc, bn, - blendSrc, blendDst, tag.getPrimType(), - tag.getDepthTest(), tag.getDepthWrite(), + 8, STD_TEXNAMES, 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(), tag.getDepthTest(), tag.getDepthWrite(), tag.getBackfaceCulling()); if (!ret) Log.report(logvisor::Fatal, "unable to build shader"); @@ -500,8 +509,8 @@ struct SPIRVBackendFactory : IShaderBackendFactory static_cast(ctx). newShaderPipeline(vertSource.c_str(), fragSource.c_str(), vertBlob, fragBlob, pipelineBlob, tag.newVertexFormat(ctx), - m_backend.m_blendSrc, m_backend.m_blendDst, tag.getPrimType(), - tag.getDepthTest(), tag.getDepthWrite(), + boo::BlendFactor(m_backend.m_blendSrc), boo::BlendFactor(m_backend.m_blendDst), + tag.getPrimType(), tag.getDepthTest(), tag.getDepthWrite(), tag.getBackfaceCulling()); if (!objOut) Log.report(logvisor::Fatal, "unable to build shader"); @@ -609,7 +618,7 @@ struct SPIRVBackendFactory : IShaderBackendFactory tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(), tag.getSkinSlotCount(), tag.getTexMtxCount(), slot.texCount, slot.texs); - std::string fragSource = m_backend.makeFrag("#version 330", slot.lighting, slot.post, slot.texCount); + std::string fragSource = m_backend.makeFrag("#version 330", slot.lighting, slot.post, slot.texCount, slot.texs); pipeBlobs.emplace_back(); Blobs& pipeBlob = pipeBlobs.back(); boo::IShaderPipeline* ret = @@ -617,8 +626,11 @@ struct SPIRVBackendFactory : IShaderBackendFactory newShaderPipeline(vertSource.c_str(), fragSource.c_str(), pipeBlob.vert, pipeBlob.frag, pipeBlob.pipeline, tag.newVertexFormat(ctx), - m_backend.m_blendSrc, m_backend.m_blendDst, tag.getPrimType(), - tag.getDepthTest(), tag.getDepthWrite(), + 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(), tag.getDepthTest(), tag.getDepthWrite(), tag.getBackfaceCulling()); if (!ret) Log.report(logvisor::Fatal, "unable to build shader"); @@ -676,8 +688,8 @@ struct SPIRVBackendFactory : IShaderBackendFactory const ShaderTag& tag = data.m_tag; athena::io::MemoryReader r(data.m_data.get(), data.m_sz); size_t texCount = size_t(r.readByte()); - boo::BlendFactor blendSrc = boo::BlendFactor(r.readUByte()); - boo::BlendFactor blendDst = boo::BlendFactor(r.readUByte()); + hecl::Backend::BlendFactor blendSrc = hecl::Backend::BlendFactor(r.readUByte()); + hecl::Backend::BlendFactor blendDst = hecl::Backend::BlendFactor(r.readUByte()); for (const ShaderCacheExtensions::ExtensionSlot& slot : extensionSlots) { @@ -701,8 +713,9 @@ struct SPIRVBackendFactory : IShaderBackendFactory newShaderPipeline(nullptr, nullptr, vertBlob, fragBlob, pipelineBlob, tag.newVertexFormat(ctx), - blendSrc, blendDst, tag.getPrimType(), - tag.getDepthTest(), tag.getDepthWrite(), + boo::BlendFactor((slot.srcFactor == hecl::Backend::BlendFactor::Original) ? blendSrc : slot.srcFactor), + boo::BlendFactor((slot.dstFactor == hecl::Backend::BlendFactor::Original) ? blendDst : slot.dstFactor), + tag.getPrimType(), tag.getDepthTest(), tag.getDepthWrite(), tag.getBackfaceCulling()); if (!ret) Log.report(logvisor::Fatal, "unable to build shader"); diff --git a/hecl/lib/Backend/ProgrammableCommon.cpp b/hecl/lib/Backend/ProgrammableCommon.cpp index 78d8bcdd8..7cb556d76 100644 --- a/hecl/lib/Backend/ProgrammableCommon.cpp +++ b/hecl/lib/Backend/ProgrammableCommon.cpp @@ -267,19 +267,19 @@ void ProgrammableCommon::reset(const IR& ir, Diagnostics& diag, const char* back bool doAlpha = false; if (!rootCall.m_call.m_name.compare("HECLOpaque")) { - m_blendSrc = boo::BlendFactor::One; - m_blendDst = boo::BlendFactor::Zero; + m_blendSrc = BlendFactor::One; + m_blendDst = BlendFactor::Zero; } else if (!rootCall.m_call.m_name.compare("HECLAlpha")) { - m_blendSrc = boo::BlendFactor::SrcAlpha; - m_blendDst = boo::BlendFactor::InvSrcAlpha; + m_blendSrc = BlendFactor::SrcAlpha; + m_blendDst = BlendFactor::InvSrcAlpha; doAlpha = true; } else if (!rootCall.m_call.m_name.compare("HECLAdditive")) { - m_blendSrc = boo::BlendFactor::SrcAlpha; - m_blendDst = boo::BlendFactor::One; + m_blendSrc = BlendFactor::SrcAlpha; + m_blendDst = BlendFactor::One; doAlpha = true; } else