diff --git a/hecl/extern/boo b/hecl/extern/boo index 73891af56..05c26a535 160000 --- a/hecl/extern/boo +++ b/hecl/extern/boo @@ -1 +1 @@ -Subproject commit 73891af56a633cf2b4e047b6422f34c80230eb29 +Subproject commit 05c26a535b23b1b787523e896853c3641cb888c8 diff --git a/hecl/include/hecl/Backend/Backend.hpp b/hecl/include/hecl/Backend/Backend.hpp index 7052c3f5f..fddcb816e 100644 --- a/hecl/include/hecl/Backend/Backend.hpp +++ b/hecl/include/hecl/Backend/Backend.hpp @@ -13,14 +13,14 @@ using Diagnostics = Frontend::Diagnostics; using SourceLocation = Frontend::SourceLocation; using ArithmeticOp = IR::Instruction::ArithmeticOpType; -enum class TexGenSrc +enum class TexGenSrc : uint8_t { Position, Normal, UV }; -enum class BlendFactor +enum class BlendFactor : uint8_t { Zero, One, @@ -37,6 +37,15 @@ enum class BlendFactor Original = 0xff }; +enum class ZTest : uint8_t +{ + None, + LEqual, + Greater, + Equal, + Original = 0xff +}; + struct TextureInfo { TexGenSrc src; diff --git a/hecl/include/hecl/Runtime.hpp b/hecl/include/hecl/Runtime.hpp index 563367305..d034eb0f7 100644 --- a/hecl/include/hecl/Runtime.hpp +++ b/hecl/include/hecl/Runtime.hpp @@ -135,6 +135,11 @@ public: const Backend::TextureInfo* texs = nullptr; Backend::BlendFactor srcFactor = Backend::BlendFactor::Original; Backend::BlendFactor dstFactor = Backend::BlendFactor::Original; + Backend::ZTest depthTest = Backend::ZTest::Original; + bool frontfaceCull = false; + bool noDepthWrite = false; + bool noColorWrite = false; + bool noAlphaWrite = false; }; std::vector m_extensionSlots; @@ -149,7 +154,12 @@ public: unsigned registerExtensionSlot(Function lighting, Function post, size_t blockCount, const char** blockNames, size_t texCount, const Backend::TextureInfo* texs, - Backend::BlendFactor srcFactor, Backend::BlendFactor dstFactor) + Backend::BlendFactor srcFactor, Backend::BlendFactor dstFactor, + Backend::ZTest depthTest = Backend::ZTest::Original, + bool frontfaceCull = false, + bool noDepthWrite = false, + bool noColorWrite = false, + bool noAlphaWrite = false) { m_extensionSlots.emplace_back(); ExtensionSlot& slot = m_extensionSlots.back(); @@ -161,6 +171,11 @@ public: slot.texs = texs; slot.srcFactor = srcFactor; slot.dstFactor = dstFactor; + slot.depthTest = depthTest; + slot.frontfaceCull = frontfaceCull; + slot.noDepthWrite = noDepthWrite; + slot.noColorWrite = noColorWrite; + slot.noAlphaWrite = noAlphaWrite; return m_extensionSlots.size() - 1; } }; @@ -286,7 +301,8 @@ struct HMDLData const boo::PipelineStage* ubufStages, size_t texCount, boo::ITexture** texs) {return ctx.newShaderDataBinding(shader, m_vtxFmt, m_vbo, nullptr, m_ibo, - ubufCount, ubufs, ubufStages, nullptr, nullptr, texCount, texs);} + ubufCount, ubufs, ubufStages, nullptr, nullptr, + texCount, texs, nullptr, nullptr);} }; } diff --git a/hecl/lib/Backend/GLSL.cpp b/hecl/lib/Backend/GLSL.cpp index 58c7e35db..66ab91db0 100644 --- a/hecl/lib/Backend/GLSL.cpp +++ b/hecl/lib/Backend/GLSL.cpp @@ -361,8 +361,8 @@ struct GLSLBackendFactory : IShaderBackendFactory 2, STD_BLOCKNAMES, boo::BlendFactor(m_backend.m_blendSrc), boo::BlendFactor(m_backend.m_blendDst), - tag.getPrimType(), tag.getDepthTest(), - tag.getDepthWrite(), + tag.getPrimType(), tag.getDepthTest() ? boo::ZTest::LEqual : boo::ZTest::None, + tag.getDepthWrite(), true, false, tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None); if (!objOut) Log.report(logvisor::Fatal, "unable to build shader"); @@ -401,7 +401,8 @@ struct GLSLBackendFactory : IShaderBackendFactory texMapEnd, STD_TEXNAMES, 2, STD_BLOCKNAMES, blendSrc, blendDst, tag.getPrimType(), - tag.getDepthTest(), tag.getDepthWrite(), + tag.getDepthTest() ? boo::ZTest::LEqual : boo::ZTest::None, + tag.getDepthWrite(), true, false, tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None); if (!ret) Log.report(logvisor::Fatal, "unable to build shader"); @@ -442,15 +443,37 @@ struct GLSLBackendFactory : IShaderBackendFactory slot.lighting, slot.post, slot.texCount, slot.texs)); cachedSz += sources.back().first.size() + 1; cachedSz += sources.back().second.size() + 1; + + boo::ZTest zTest; + switch (slot.depthTest) + { + case hecl::Backend::ZTest::Original: + default: + zTest = tag.getDepthTest() ? boo::ZTest::LEqual : boo::ZTest::None; + break; + case hecl::Backend::ZTest::None: + zTest = boo::ZTest::None; + break; + case hecl::Backend::ZTest::LEqual: + zTest = boo::ZTest::LEqual; + break; + case hecl::Backend::ZTest::Greater: + zTest = boo::ZTest::Greater; + break; + case hecl::Backend::ZTest::Equal: + zTest = boo::ZTest::Equal; + break; + } + boo::IShaderPipeline* ret = static_cast(ctx). newShaderPipeline(sources.back().first.c_str(), sources.back().second.c_str(), 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() ? boo::CullMode::Backface : boo::CullMode::None); + tag.getPrimType(), zTest, slot.noDepthWrite ? false : tag.getDepthWrite(), !slot.noColorWrite, !slot.noAlphaWrite, + slot.frontfaceCull ? boo::CullMode::Frontface : + (tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None)); if (!ret) Log.report(logvisor::Fatal, "unable to build shader"); returnFunc(ret); @@ -503,14 +526,36 @@ struct GLSLBackendFactory : IShaderBackendFactory if (r.hasError()) return false; + boo::ZTest zTest; + switch (slot.depthTest) + { + case hecl::Backend::ZTest::Original: + default: + zTest = tag.getDepthTest() ? boo::ZTest::LEqual : boo::ZTest::None; + break; + case hecl::Backend::ZTest::None: + zTest = boo::ZTest::None; + break; + case hecl::Backend::ZTest::LEqual: + zTest = boo::ZTest::LEqual; + break; + case hecl::Backend::ZTest::Greater: + zTest = boo::ZTest::Greater; + break; + case hecl::Backend::ZTest::Equal: + zTest = boo::ZTest::Equal; + break; + } + boo::IShaderPipeline* ret = static_cast(ctx). newShaderPipeline(vertSource.c_str(), fragSource.c_str(), 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() ? boo::CullMode::Backface : boo::CullMode::None); + tag.getPrimType(), zTest, slot.noDepthWrite ? false : tag.getDepthWrite(), !slot.noColorWrite, !slot.noAlphaWrite, + slot.frontfaceCull ? boo::CullMode::Frontface : + (tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None)); if (!ret) Log.report(logvisor::Fatal, "unable to build shader"); returnFunc(ret); @@ -681,7 +726,8 @@ struct SPIRVBackendFactory : IShaderBackendFactory 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.getPrimType(), tag.getDepthTest(), slot.noDepthWrite ? false : tag.getDepthWrite(), + !slot.noColorWrite, !slot.noAlphaWrite, tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None); if (!ret) Log.report(logvisor::Fatal, "unable to build shader"); @@ -772,7 +818,8 @@ struct SPIRVBackendFactory : IShaderBackendFactory tag.newVertexFormat(ctx), 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.getPrimType(), tag.getDepthTest(), slot.noDepthWrite ? false : tag.getDepthWrite(), + !slot.noColorWrite, !slot.noAlphaWrite, tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None); if (!ret) Log.report(logvisor::Fatal, "unable to build shader"); diff --git a/hecl/lib/Backend/HLSL.cpp b/hecl/lib/Backend/HLSL.cpp index b6b904780..ff067ba48 100644 --- a/hecl/lib/Backend/HLSL.cpp +++ b/hecl/lib/Backend/HLSL.cpp @@ -451,6 +451,28 @@ struct HLSLBackendFactory : IShaderBackendFactory slot.lighting, slot.post, slot.texCount, slot.texs); pipeBlobs.emplace_back(); Blobs& thisPipeBlobs = pipeBlobs.back(); + + boo::ZTest zTest; + switch (slot.depthTest) + { + case hecl::Backend::ZTest::Original: + default: + zTest = tag.getDepthTest() ? boo::ZTest::LEqual : boo::ZTest::None; + break; + case hecl::Backend::ZTest::None: + zTest = boo::ZTest::None; + break; + case hecl::Backend::ZTest::LEqual: + zTest = boo::ZTest::LEqual; + break; + case hecl::Backend::ZTest::Greater: + zTest = boo::ZTest::Greater; + break; + case hecl::Backend::ZTest::Equal: + zTest = boo::ZTest::Equal; + break; + } + boo::IShaderPipeline* ret = static_cast(ctx). newShaderPipeline(vertSource.c_str(), fragSource.c_str(), @@ -458,9 +480,9 @@ struct HLSLBackendFactory : IShaderBackendFactory tag.newVertexFormat(ctx), 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() ? boo::CullMode::Backface : boo::CullMode::None); + tag.getPrimType(), zTest, slot.noDepthWrite ? false : tag.getDepthWrite(), + slot.frontfaceCull ? boo::CullMode::Frontface : + (tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None)); if (!ret) Log.report(logvisor::Fatal, "unable to build shader"); if (thisPipeBlobs.vert) @@ -549,6 +571,27 @@ struct HLSLBackendFactory : IShaderBackendFactory if (r.hasError()) return false; + boo::ZTest zTest; + switch (slot.depthTest) + { + case hecl::Backend::ZTest::Original: + default: + zTest = tag.getDepthTest() ? boo::ZTest::LEqual : boo::ZTest::None; + break; + case hecl::Backend::ZTest::None: + zTest = boo::ZTest::None; + break; + case hecl::Backend::ZTest::LEqual: + zTest = boo::ZTest::LEqual; + break; + case hecl::Backend::ZTest::Greater: + zTest = boo::ZTest::Greater; + break; + case hecl::Backend::ZTest::Equal: + zTest = boo::ZTest::Equal; + break; + } + boo::IShaderPipeline* ret = static_cast(ctx). newShaderPipeline(nullptr, nullptr, @@ -556,9 +599,9 @@ struct HLSLBackendFactory : IShaderBackendFactory tag.newVertexFormat(ctx), 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() ? boo::CullMode::Backface : boo::CullMode::None); + tag.getPrimType(), zTest, slot.noDepthWrite ? false : tag.getDepthWrite(), + slot.frontfaceCull ? boo::CullMode::Frontface : + (tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None)); if (!ret) Log.report(logvisor::Fatal, "unable to build shader"); returnFunc(ret); diff --git a/hecl/lib/Backend/Metal.cpp b/hecl/lib/Backend/Metal.cpp index a6300aa3d..f18abd1d4 100644 --- a/hecl/lib/Backend/Metal.cpp +++ b/hecl/lib/Backend/Metal.cpp @@ -66,7 +66,7 @@ std::string Metal::GenerateVertInStruct(unsigned col, unsigned uv, unsigned w) c if (w) { for (unsigned i=0 ; i(ctx). newShaderPipeline(sources.back().first.c_str(), sources.back().second.c_str(), tag.newVertexFormat(ctx), m_rtHint, 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() ? boo::CullMode::Backface : boo::CullMode::None); + tag.getPrimType(), zTest, slot.noDepthWrite ? false : tag.getDepthWrite(), + !slot.noColorWrite, !slot.noAlphaWrite, + slot.frontfaceCull ? boo::CullMode::Frontface : + (tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None)); if (!ret) Log.report(logvisor::Fatal, "unable to build shader"); returnFunc(ret); @@ -528,15 +551,37 @@ struct MetalBackendFactory : IShaderBackendFactory if (r.hasError()) return false; + boo::ZTest zTest; + switch (slot.depthTest) + { + case hecl::Backend::ZTest::Original: + default: + zTest = tag.getDepthTest() ? boo::ZTest::LEqual : boo::ZTest::None; + break; + case hecl::Backend::ZTest::None: + zTest = boo::ZTest::None; + break; + case hecl::Backend::ZTest::LEqual: + zTest = boo::ZTest::LEqual; + break; + case hecl::Backend::ZTest::Greater: + zTest = boo::ZTest::Greater; + break; + case hecl::Backend::ZTest::Equal: + zTest = boo::ZTest::Equal; + break; + } + boo::IShaderPipeline* ret = static_cast(ctx). newShaderPipeline(vertSource.c_str(), fragSource.c_str(), tag.newVertexFormat(ctx), m_rtHint, 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() ? boo::CullMode::Backface : boo::CullMode::None); + tag.getPrimType(), zTest, slot.noDepthWrite ? false : tag.getDepthWrite(), + !slot.noColorWrite, !slot.noAlphaWrite, + slot.frontfaceCull ? boo::CullMode::Frontface : + (tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None)); if (!ret) Log.report(logvisor::Fatal, "unable to build shader"); returnFunc(ret);