diff --git a/hecl/extern/athena b/hecl/extern/athena index c4db28821..cf3dfcddf 160000 --- a/hecl/extern/athena +++ b/hecl/extern/athena @@ -1 +1 @@ -Subproject commit c4db28821e112bd60dcde4caff79b3fd4634b238 +Subproject commit cf3dfcddffde70b54e38f18665cc3c4dbb0f5132 diff --git a/hecl/extern/boo b/hecl/extern/boo index 0ee594438..2ec943f0b 160000 --- a/hecl/extern/boo +++ b/hecl/extern/boo @@ -1 +1 @@ -Subproject commit 0ee594438714f38e4de982a4d51fdeaf689dd5c6 +Subproject commit 2ec943f0b2f5af6c74c0b8a2f852c484c3235d8e diff --git a/hecl/include/hecl/Backend/Metal.hpp b/hecl/include/hecl/Backend/Metal.hpp index 508c8cafa..4c7602536 100644 --- a/hecl/include/hecl/Backend/Metal.hpp +++ b/hecl/include/hecl/Backend/Metal.hpp @@ -1,15 +1,6 @@ #ifndef HECLBACKEND_METAL_HPP #define HECLBACKEND_METAL_HPP -#if __APPLE__ -#include -#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 101100 -#define BOO_HAS_METAL 1 -#else -#define BOO_HAS_METAL 0 -#endif -#endif - #if BOO_HAS_METAL #include "ProgrammableCommon.hpp" @@ -23,16 +14,18 @@ struct Metal : ProgrammableCommon { void reset(const IR& ir, Diagnostics& diag); std::string makeVert(unsigned col, unsigned uv, unsigned w, - unsigned skinSlots, unsigned texMtxs) const; + unsigned skinSlots, unsigned texMtxs, size_t extTexCount, + const TextureInfo* extTexs) const; std::string makeFrag(size_t blockCount, const char** blockNames, const ShaderFunction& lighting=ShaderFunction()) const; std::string makeFrag(size_t blockCount, const char** blockNames, const ShaderFunction& lighting, - const ShaderFunction& post) const; + const ShaderFunction& post, size_t extTexCount, + const TextureInfo* extTexs) const; private: std::string GenerateVertInStruct(unsigned col, unsigned uv, unsigned w) const; - std::string GenerateVertToFragStruct() const; + std::string GenerateVertToFragStruct(size_t extTexCount) const; std::string GenerateVertUniformStruct(unsigned skinSlots) const; std::string EmitVec3(const atVec4f& vec) const diff --git a/hecl/lib/Backend/Metal.cpp b/hecl/lib/Backend/Metal.cpp index 5eedc58f8..97f5931c5 100644 --- a/hecl/lib/Backend/Metal.cpp +++ b/hecl/lib/Backend/Metal.cpp @@ -72,7 +72,7 @@ std::string Metal::GenerateVertInStruct(unsigned col, unsigned uv, unsigned w) c return retval + "};\n"; } -std::string Metal::GenerateVertToFragStruct() const +std::string Metal::GenerateVertToFragStruct(size_t extTexCount) const { std::string retval = "struct VertToFrag\n" @@ -86,6 +86,11 @@ std::string Metal::GenerateVertToFragStruct() const for (size_t i=0 ; i tex%u [[ texture(%u) ]]", i, i); } + std::string extTexCall; + for (int i=0 ; i tex%u [[ texture(%u) ]]", extTex.mapIdx, extTex.mapIdx); + } + std::string blockCall; for (size_t i=0 ; i(ctx). newShaderPipeline(vertSource.c_str(), fragSource.c_str(), tag.newVertexFormat(ctx), m_rtHint, - m_backend.m_blendSrc, m_backend.m_blendDst, + boo::BlendFactor(m_backend.m_blendSrc), + boo::BlendFactor(m_backend.m_blendDst), tag.getPrimType(), tag.getDepthTest(), tag.getDepthWrite(), tag.getBackfaceCulling()); @@ -361,22 +393,21 @@ struct MetalBackendFactory : IShaderBackendFactory m_backend.reset(ir, diag); size_t cachedSz = 2; - std::string vertSource = - m_backend.makeVert(tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(), - tag.getSkinSlotCount(), tag.getTexMtxCount()); - cachedSz += vertSource.size() + 1; - - std::vector fragSources; - fragSources.reserve(extensionSlots.size()); + std::vector> sources; + sources.reserve(extensionSlots.size()); for (const ShaderCacheExtensions::ExtensionSlot& slot : extensionSlots) { - fragSources.push_back(m_backend.makeFrag(slot.blockCount, slot.blockNames, slot.lighting, slot.post)); - cachedSz += fragSources.back().size() + 1; + sources.emplace_back(m_backend.makeVert(tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(), + tag.getSkinSlotCount(), tag.getTexMtxCount(), slot.texCount, slot.texs), + m_backend.makeFrag(slot.blockCount, slot.blockNames, slot.lighting, slot.post, slot.texCount, slot.texs)); + cachedSz += sources.back().first.size() + 1; + cachedSz += sources.back().second.size() + 1; boo::IShaderPipeline* ret = static_cast(ctx). - newShaderPipeline(vertSource.c_str(), fragSources.back().c_str(), + newShaderPipeline(sources.back().first.c_str(), sources.back().second.c_str(), tag.newVertexFormat(ctx), m_rtHint, - m_backend.m_blendSrc, m_backend.m_blendDst, + 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()); @@ -389,9 +420,11 @@ struct MetalBackendFactory : IShaderBackendFactory athena::io::MemoryWriter w(dataOut.m_data.get(), dataOut.m_sz); w.writeUByte(atUint8(m_backend.m_blendSrc)); w.writeUByte(atUint8(m_backend.m_blendDst)); - w.writeString(vertSource); - for (const std::string src : fragSources) - w.writeString(src); + for (auto& src : sources) + { + w.writeString(src.first); + w.writeString(src.second); + } return dataOut; } @@ -407,17 +440,19 @@ struct MetalBackendFactory : IShaderBackendFactory const ShaderTag& tag = data.m_tag; athena::io::MemoryReader r(data.m_data.get(), data.m_sz); - boo::BlendFactor blendSrc = boo::BlendFactor(r.readUByte()); - boo::BlendFactor blendDst = boo::BlendFactor(r.readUByte()); - std::string vertSource = r.readString(); + hecl::Backend::BlendFactor blendSrc = hecl::Backend::BlendFactor(r.readUByte()); + hecl::Backend::BlendFactor blendDst = hecl::Backend::BlendFactor(r.readUByte()); for (const ShaderCacheExtensions::ExtensionSlot& slot : extensionSlots) { + std::string vertSource = r.readString(); std::string fragSource = r.readString(); boo::IShaderPipeline* ret = static_cast(ctx). newShaderPipeline(vertSource.c_str(), fragSource.c_str(), tag.newVertexFormat(ctx), m_rtHint, - blendSrc, blendDst, tag.getPrimType(), + 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)