diff --git a/hecl/extern/boo b/hecl/extern/boo index db82ba674..1dc69c346 160000 --- a/hecl/extern/boo +++ b/hecl/extern/boo @@ -1 +1 @@ -Subproject commit db82ba674ba3fc94f6cc18d33f9de62dc52080d5 +Subproject commit 1dc69c3468abfe599afb0677c2fb8cea1c99e8a4 diff --git a/hecl/include/hecl/CVarManager.hpp b/hecl/include/hecl/CVarManager.hpp index 2133e31cd..b4f6d39d4 100755 --- a/hecl/include/hecl/CVarManager.hpp +++ b/hecl/include/hecl/CVarManager.hpp @@ -55,6 +55,13 @@ public: bool registerCVar(CVar* cvar); CVar* findCVar(std::string_view name); + template + CVar* findOrMakeCVar(std::string_view name, _Args&&... args) + { + if (CVar* cv = findCVar(name)) + return cv; + return newCVar(name, std::forward<_Args>(args)...); + } std::vector archivedCVars() const; std::vector cvars() const; diff --git a/hecl/include/hecl/Runtime.hpp b/hecl/include/hecl/Runtime.hpp index 9d98eaa9d..25f1d5b70 100644 --- a/hecl/include/hecl/Runtime.hpp +++ b/hecl/include/hecl/Runtime.hpp @@ -195,7 +195,6 @@ class IShaderBackendFactory { friend class ShaderCacheManager; protected: - unsigned m_rtHint = 1; using FReturnExtensionShader = std::function&)>; virtual ShaderCachedData buildShaderFromIR(const ShaderTag& tag, const hecl::Frontend::IR& ir, @@ -269,10 +268,6 @@ public: void reload(); void clearCachedPipelines() { m_pipelineLookup.clear(); } - /* Some platforms (like Metal) require information about the render target - * for encoding the pipeline state. This must be called before building shaders */ - void setRenderTargetSamples(unsigned samps) {m_factory->m_rtHint = samps;} - std::shared_ptr buildShader(const ShaderTag& tag, std::string_view source, std::string_view diagName, boo::IGraphicsDataFactory& factory); diff --git a/hecl/lib/Backend/Metal.cpp b/hecl/lib/Backend/Metal.cpp index e667a214d..a578dcb7d 100644 --- a/hecl/lib/Backend/Metal.cpp +++ b/hecl/lib/Backend/Metal.cpp @@ -252,13 +252,12 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp blockCall += hecl::Format("block%" PRISize, i); } - std::string retval = "#include \nusing namespace metal;\n" - "constexpr sampler samp(address::repeat, filter::linear, mip_filter::linear);\n" - "constexpr sampler clampSamp(address::clamp_to_border, border_color::opaque_white, filter::linear, mip_filter::linear);\n" + + std::string retval = "#include \nusing namespace metal;\n" + GenerateVertToFragStruct(0, reflectionType != ReflectionType::None) + "\n" + GenerateFragOutStruct() + "\n" + lightingSrc + "\n" + - "fragment FragOut fmain(VertToFrag vtf [[ stage_in ]]" + texMapDecl + ")\n" + "fragment FragOut fmain(VertToFrag vtf [[ stage_in ]],\n" + "sampler samp [[ sampler(0) ]], sampler clampSamp [[ sampler(1) ]]" + texMapDecl + ")\n" "{\n" " FragOut out;\n"; @@ -364,14 +363,13 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp blockCall += hecl::Format("block%" PRISize, i); } - std::string retval = "#include \nusing namespace metal;\n" - "constexpr sampler samp(address::repeat, filter::linear, mip_filter::linear);\n" - "constexpr sampler clampSamp(address::clamp_to_border, border_color::opaque_white, filter::linear, mip_filter::linear);\n" + + std::string retval = "#include \nusing namespace metal;\n" + GenerateVertToFragStruct(extTexCount, reflectionType != ReflectionType::None) + "\n" + GenerateFragOutStruct() + "\n" + lightingSrc + "\n" + postSrc + "\n" + - "fragment FragOut fmain(VertToFrag vtf [[ stage_in ]]" + texMapDecl + ")\n" + "fragment FragOut fmain(VertToFrag vtf [[ stage_in ]],\n" + "sampler samp [[ sampler(0) ]], sampler clampSamp [[ sampler(1) ]]" + texMapDecl + ")\n" "{\n" " FragOut out;\n"; @@ -395,7 +393,7 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp if (lighting.m_entry) { retval += " float4 lighting = " + lightingEntry + "(" + blockCall + ", vtf.mvPos, vtf.mvNorm, vtf" + - (!strncmp(lighting.m_entry, "EXT", 3) ? (extTexCall.size() ? (", " + extTexCall) : "") : "") + ");\n"; + (!strncmp(lighting.m_entry, "EXT", 3) ? (extTexCall.size() ? (", samp, clampSamp," + extTexCall) : "") : "") + ");\n"; } else retval += " float4 lighting = float4(1.0,1.0,1.0,1.0);\n"; @@ -412,14 +410,14 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp { retval += " out.color = " + postEntry + "(" + (postEntry.size() ? ("vtf, " + (blockCall.size() ? (blockCall + ", ") : "") + - (!strncmp(post.m_entry, "EXT", 3) ? (extTexCall.size() ? (extTexCall + ", ") : "") : "")) : "") + + (!strncmp(post.m_entry, "EXT", 3) ? (extTexCall.size() ? ("samp, clampSamp," + extTexCall + ", ") : "") : "")) : "") + "float4(" + m_colorExpr + " + " + reflectionExpr + ", " + m_alphaExpr + ")) * mulColor;\n"; } else { retval += " out.color = " + postEntry + "(" + (postEntry.size() ? ("vtf, " + (blockCall.size() ? (blockCall + ", ") : "") + - (!strncmp(post.m_entry, "EXT", 3) ? (extTexCall.size() ? (extTexCall + ", ") : "") : "")) : "") + + (!strncmp(post.m_entry, "EXT", 3) ? (extTexCall.size() ? ("samp, clampSamp," + extTexCall + ", ") : "") : "")) : "") + "float4(" + m_colorExpr + " + " + reflectionExpr + ", 1.0)) * mulColor;\n"; } @@ -444,10 +442,6 @@ struct MetalBackendFactory : IShaderBackendFactory boo::IGraphicsDataFactory::Context& ctx, boo::ObjToken& objOut) { - if (!m_rtHint) - Log.report(logvisor::Fatal, - "ShaderCacheManager::setRenderTargetHint must be called before making metal shaders"); - m_backend.reset(ir, diag); size_t cachedSz = 2; @@ -465,7 +459,7 @@ struct MetalBackendFactory : IShaderBackendFactory static_cast(ctx). newShaderPipeline(vertSource.c_str(), fragSource.c_str(), &vertBlob, &fragBlob, - tag.newVertexFormat(ctx), m_rtHint, + tag.newVertexFormat(ctx), boo::BlendFactor(m_backend.m_blendSrc), boo::BlendFactor(m_backend.m_blendDst), tag.getPrimType(), @@ -492,10 +486,6 @@ struct MetalBackendFactory : IShaderBackendFactory boo::ObjToken buildShaderFromCache(const ShaderCachedData& data, boo::IGraphicsDataFactory::Context& ctx) { - if (!m_rtHint) - Log.report(logvisor::Fatal, - "ShaderCacheManager::setRenderTargetHint must be called before making metal shaders"); - const ShaderTag& tag = data.m_tag; athena::io::MemoryReader r(data.m_data.get(), data.m_sz, false, false); boo::BlendFactor blendSrc = boo::BlendFactor(r.readUByte()); @@ -522,7 +512,7 @@ struct MetalBackendFactory : IShaderBackendFactory static_cast(ctx). newShaderPipeline(nullptr, nullptr, &vertBlob, &fragBlob, - tag.newVertexFormat(ctx), m_rtHint, + tag.newVertexFormat(ctx), blendSrc, blendDst, tag.getPrimType(), tag.getDepthTest() ? boo::ZTest::LEqual : boo::ZTest::None, tag.getDepthWrite(), true, true, tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None); @@ -538,10 +528,6 @@ struct MetalBackendFactory : IShaderBackendFactory boo::IGraphicsDataFactory::Context& ctx, FReturnExtensionShader returnFunc) { - if (!m_rtHint) - Log.report(logvisor::Fatal, - "ShaderCacheManager::setRenderTargetHint must be called before making metal shaders"); - m_backend.reset(ir, diag); size_t cachedSz = 2; @@ -585,7 +571,7 @@ struct MetalBackendFactory : IShaderBackendFactory static_cast(ctx). newShaderPipeline(vertSource.c_str(), fragSource.c_str(), &blobs.back().first, &blobs.back().second, - tag.newVertexFormat(ctx), m_rtHint, + 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(), zTest, slot.noDepthWrite ? false : tag.getDepthWrite(), @@ -621,10 +607,6 @@ struct MetalBackendFactory : IShaderBackendFactory boo::IGraphicsDataFactory::Context& ctx, FReturnExtensionShader returnFunc) { - if (!m_rtHint) - Log.report(logvisor::Fatal, - "ShaderCacheManager::setRenderTargetHint must be called before making metal shaders"); - const ShaderTag& tag = data.m_tag; athena::io::MemoryReader r(data.m_data.get(), data.m_sz, false, false); hecl::Backend::BlendFactor blendSrc = hecl::Backend::BlendFactor(r.readUByte()); @@ -678,7 +660,7 @@ struct MetalBackendFactory : IShaderBackendFactory static_cast(ctx). newShaderPipeline(nullptr, nullptr, &vertBlob, &fragBlob, - tag.newVertexFormat(ctx), m_rtHint, + 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(), zTest, slot.noDepthWrite ? false : tag.getDepthWrite(),