mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-07-01 23:33:33 +00:00
Update boo and Metal backend
This commit is contained in:
parent
3b757c9854
commit
54ca41f2ed
2
hecl/extern/boo
vendored
2
hecl/extern/boo
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 4c8e36f3e33582bca396b3b89e29178ebc2f1728
|
Subproject commit 843396095f8cbc160541edfcbf1a22c0030d397c
|
@ -1,12 +1,24 @@
|
|||||||
#ifndef HECLBACKEND_METAL_HPP
|
#ifndef HECLBACKEND_METAL_HPP
|
||||||
#define HECLBACKEND_METAL_HPP
|
#define HECLBACKEND_METAL_HPP
|
||||||
|
|
||||||
|
#if __APPLE__
|
||||||
|
#include <Availability.h>
|
||||||
|
#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
|
#if BOO_HAS_METAL
|
||||||
|
|
||||||
|
#include "ProgrammableCommon.hpp"
|
||||||
|
|
||||||
namespace hecl
|
namespace hecl
|
||||||
{
|
{
|
||||||
namespace Backend
|
namespace Backend
|
||||||
{
|
{
|
||||||
|
|
||||||
struct Metal : ProgrammableCommon
|
struct Metal : ProgrammableCommon
|
||||||
{
|
{
|
||||||
void reset(const IR& ir, Diagnostics& diag);
|
void reset(const IR& ir, Diagnostics& diag);
|
||||||
@ -15,21 +27,21 @@ struct Metal : ProgrammableCommon
|
|||||||
std::string makeFrag(const ShaderFunction& lighting=ShaderFunction()) const;
|
std::string makeFrag(const ShaderFunction& lighting=ShaderFunction()) const;
|
||||||
std::string makeFrag(const ShaderFunction& lighting,
|
std::string makeFrag(const ShaderFunction& lighting,
|
||||||
const ShaderFunction& post) const;
|
const ShaderFunction& post) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string GenerateVertInStruct(unsigned col, unsigned uv, unsigned w) const;
|
std::string GenerateVertInStruct(unsigned col, unsigned uv, unsigned w) const;
|
||||||
std::string GenerateVertToFragStruct() const;
|
std::string GenerateVertToFragStruct() const;
|
||||||
std::string GenerateVertUniformStruct(unsigned skinSlots, unsigned texMtxs) const;
|
std::string GenerateVertUniformStruct(unsigned skinSlots, unsigned texMtxs) const;
|
||||||
|
|
||||||
std::string EmitVec3(const atVec4f& vec) const
|
std::string EmitVec3(const atVec4f& vec) const
|
||||||
{
|
{
|
||||||
return hecl::Format("float3(%g,%g,%g)", vec.vec[0], vec.vec[1], vec.vec[2]);
|
return hecl::Format("float3(%g,%g,%g)", vec.vec[0], vec.vec[1], vec.vec[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string EmitTexGenSource2(TexGenSrc src, int uvIdx) const;
|
std::string EmitTexGenSource2(TexGenSrc src, int uvIdx) const;
|
||||||
std::string EmitTexGenSource4(TexGenSrc src, int uvIdx) const;
|
std::string EmitTexGenSource4(TexGenSrc src, int uvIdx) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -49,26 +49,26 @@ std::string Metal::GenerateVertInStruct(unsigned col, unsigned uv, unsigned w) c
|
|||||||
"{\n"
|
"{\n"
|
||||||
" float3 posIn [[ attribute(0) ]];\n"
|
" float3 posIn [[ attribute(0) ]];\n"
|
||||||
" float3 normIn [[ attribute(1) ]];\n";
|
" float3 normIn [[ attribute(1) ]];\n";
|
||||||
|
|
||||||
unsigned idx = 2;
|
unsigned idx = 2;
|
||||||
if (col)
|
if (col)
|
||||||
{
|
{
|
||||||
for (unsigned i=0 ; i<col ; ++i, ++idx)
|
for (unsigned i=0 ; i<col ; ++i, ++idx)
|
||||||
retval += hecl::Format(" float4 colIn%u [[ attribute(%u) ]];\n", i, idx);
|
retval += hecl::Format(" float4 colIn%u [[ attribute(%u) ]];\n", i, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uv)
|
if (uv)
|
||||||
{
|
{
|
||||||
for (unsigned i=0 ; i<uv ; ++i, ++idx)
|
for (unsigned i=0 ; i<uv ; ++i, ++idx)
|
||||||
retval += hecl::Format(" float2 uvIn%u [[ attribute(%u) ]];\n", i, idx);
|
retval += hecl::Format(" float2 uvIn%u [[ attribute(%u) ]];\n", i, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (w)
|
if (w)
|
||||||
{
|
{
|
||||||
for (unsigned i=0 ; i<w ; ++i, ++idx)
|
for (unsigned i=0 ; i<w ; ++i, ++idx)
|
||||||
retval += hecl::Format(" float4 weightIn%u [[ attribute(%u) ]];\n", i, idx);
|
retval += hecl::Format(" float4 weightIn%u [[ attribute(%u) ]];\n", i, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
return retval + "};\n";
|
return retval + "};\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,13 +80,13 @@ std::string Metal::GenerateVertToFragStruct() const
|
|||||||
" float4 mvpPos [[ position ]];\n"
|
" float4 mvpPos [[ position ]];\n"
|
||||||
" float4 mvPos;\n"
|
" float4 mvPos;\n"
|
||||||
" float4 mvNorm;\n";
|
" float4 mvNorm;\n";
|
||||||
|
|
||||||
if (m_tcgs.size())
|
if (m_tcgs.size())
|
||||||
{
|
{
|
||||||
for (size_t i=0 ; i<m_tcgs.size() ; ++i)
|
for (size_t i=0 ; i<m_tcgs.size() ; ++i)
|
||||||
retval += hecl::Format(" float2 tcgs%" PRISize ";\n", i);
|
retval += hecl::Format(" float2 tcgs%" PRISize ";\n", i);
|
||||||
}
|
}
|
||||||
|
|
||||||
return retval + "};\n";
|
return retval + "};\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ std::string Metal::makeVert(unsigned col, unsigned uv, unsigned w,
|
|||||||
GenerateVertUniformStruct(s, tm) +
|
GenerateVertUniformStruct(s, tm) +
|
||||||
"\nvertex VertToFrag vmain(VertData v [[ stage_in ]], constant HECLVertUniform& vu [[ buffer(2) ]])\n{\n"
|
"\nvertex VertToFrag vmain(VertData v [[ stage_in ]], constant HECLVertUniform& vu [[ buffer(2) ]])\n{\n"
|
||||||
" VertToFrag vtf;\n";
|
" VertToFrag vtf;\n";
|
||||||
|
|
||||||
if (s)
|
if (s)
|
||||||
{
|
{
|
||||||
/* skinned */
|
/* skinned */
|
||||||
@ -142,7 +142,7 @@ std::string Metal::makeVert(unsigned col, unsigned uv, unsigned w,
|
|||||||
" vtf.mvNorm = vu.mvInv[0] * float4(v.normIn, 0.0);\n"
|
" vtf.mvNorm = vu.mvInv[0] * float4(v.normIn, 0.0);\n"
|
||||||
" vtf.mvpPos = vu.proj * vtf.mvPos;\n";
|
" vtf.mvpPos = vu.proj * vtf.mvPos;\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
int tcgIdx = 0;
|
int tcgIdx = 0;
|
||||||
for (const TexCoordGen& tcg : m_tcgs)
|
for (const TexCoordGen& tcg : m_tcgs)
|
||||||
{
|
{
|
||||||
@ -154,7 +154,7 @@ std::string Metal::makeVert(unsigned col, unsigned uv, unsigned w,
|
|||||||
EmitTexGenSource4(tcg.m_src, tcg.m_uvIdx).c_str());
|
EmitTexGenSource4(tcg.m_src, tcg.m_uvIdx).c_str());
|
||||||
++tcgIdx;
|
++tcgIdx;
|
||||||
}
|
}
|
||||||
|
|
||||||
return retval + " return vtf;\n}\n";
|
return retval + " return vtf;\n}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,21 +163,21 @@ std::string Metal::makeFrag(const ShaderFunction& lighting) const
|
|||||||
std::string lightingSrc;
|
std::string lightingSrc;
|
||||||
if (lighting.m_source)
|
if (lighting.m_source)
|
||||||
lightingSrc = lighting.m_source;
|
lightingSrc = lighting.m_source;
|
||||||
|
|
||||||
std::string texMapDecl;
|
std::string texMapDecl;
|
||||||
if (m_texMapEnd)
|
if (m_texMapEnd)
|
||||||
{
|
{
|
||||||
for (int i=0 ; i<m_texMapEnd ; ++i)
|
for (int i=0 ; i<m_texMapEnd ; ++i)
|
||||||
texMapDecl += hecl::Format("\n, texture2d<float> tex%u [[ texture(%u) ]]", i, i);
|
texMapDecl += hecl::Format("\n, texture2d<float> tex%u [[ texture(%u) ]]", i, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string retval = "#include <metal_stdlib>\nusing namespace metal;\n"
|
std::string retval = "#include <metal_stdlib>\nusing namespace metal;\n"
|
||||||
"constexpr sampler samp(address::repeat);\n" +
|
"constexpr sampler samp(address::repeat, filter::linear, mip_filter::linear);\n" +
|
||||||
GenerateVertToFragStruct() + "\n" +
|
GenerateVertToFragStruct() + "\n" +
|
||||||
lightingSrc + "\n" +
|
lightingSrc + "\n" +
|
||||||
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]]" + texMapDecl + ")\n{\n";
|
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]]" + texMapDecl + ")\n{\n";
|
||||||
|
|
||||||
|
|
||||||
if (m_lighting)
|
if (m_lighting)
|
||||||
{
|
{
|
||||||
if (lighting.m_entry)
|
if (lighting.m_entry)
|
||||||
@ -185,17 +185,17 @@ std::string Metal::makeFrag(const ShaderFunction& lighting) const
|
|||||||
else
|
else
|
||||||
retval += " float4 lighting = float4(1.0,1.0,1.0,1.0);\n";
|
retval += " float4 lighting = float4(1.0,1.0,1.0,1.0);\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned sampIdx = 0;
|
unsigned sampIdx = 0;
|
||||||
for (const TexSampling& sampling : m_texSamplings)
|
for (const TexSampling& sampling : m_texSamplings)
|
||||||
retval += hecl::Format(" float4 sampling%u = tex%u.sample(samp, vtf.tcgs%u);\n",
|
retval += hecl::Format(" float4 sampling%u = tex%u.sample(samp, vtf.tcgs%u);\n",
|
||||||
sampIdx++, sampling.mapIdx, sampling.tcgIdx);
|
sampIdx++, sampling.mapIdx, sampling.tcgIdx);
|
||||||
|
|
||||||
if (m_alphaExpr.size())
|
if (m_alphaExpr.size())
|
||||||
retval += " return float4(" + m_colorExpr + ", " + m_alphaExpr + ");\n";
|
retval += " return float4(" + m_colorExpr + ", " + m_alphaExpr + ");\n";
|
||||||
else
|
else
|
||||||
retval += " return float4(" + m_colorExpr + ", 1.0);\n";
|
retval += " return float4(" + m_colorExpr + ", 1.0);\n";
|
||||||
|
|
||||||
return retval + "}\n";
|
return retval + "}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,28 +205,28 @@ std::string Metal::makeFrag(const ShaderFunction& lighting,
|
|||||||
std::string lightingSrc;
|
std::string lightingSrc;
|
||||||
if (lighting.m_source)
|
if (lighting.m_source)
|
||||||
lightingSrc = lighting.m_source;
|
lightingSrc = lighting.m_source;
|
||||||
|
|
||||||
std::string postSrc;
|
std::string postSrc;
|
||||||
if (post.m_source)
|
if (post.m_source)
|
||||||
postSrc = post.m_source;
|
postSrc = post.m_source;
|
||||||
|
|
||||||
std::string postEntry;
|
std::string postEntry;
|
||||||
if (post.m_entry)
|
if (post.m_entry)
|
||||||
postEntry = post.m_entry;
|
postEntry = post.m_entry;
|
||||||
|
|
||||||
std::string texMapDecl;
|
std::string texMapDecl;
|
||||||
if (m_texMapEnd)
|
if (m_texMapEnd)
|
||||||
{
|
{
|
||||||
for (int i=0 ; i<m_texMapEnd ; ++i)
|
for (int i=0 ; i<m_texMapEnd ; ++i)
|
||||||
texMapDecl += hecl::Format("texture2d<float> tex%u [[ texture(%u) ]],\n", i, i);
|
texMapDecl += hecl::Format("texture2d<float> tex%u [[ texture(%u) ]],\n", i, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string retval = "#include <metal_stdlib>\nusing namespace metal;\n"
|
std::string retval = "#include <metal_stdlib>\nusing namespace metal;\n"
|
||||||
"constexpr sampler samp(address::repeat);\n" +
|
"constexpr sampler samp(address::repeat, filter::linear, mip_filter::linear);\n" +
|
||||||
GenerateVertToFragStruct() + "\n" +
|
GenerateVertToFragStruct() + "\n" +
|
||||||
lightingSrc + "\n" +
|
lightingSrc + "\n" +
|
||||||
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" + texMapDecl + ")\n{\n";
|
"fragment float4 fmain(VertToFrag vtf [[ stage_in ]],\n" + texMapDecl + ")\n{\n";
|
||||||
|
|
||||||
if (m_lighting)
|
if (m_lighting)
|
||||||
{
|
{
|
||||||
if (lighting.m_entry)
|
if (lighting.m_entry)
|
||||||
@ -234,17 +234,17 @@ std::string Metal::makeFrag(const ShaderFunction& lighting,
|
|||||||
else
|
else
|
||||||
retval += " float4 lighting = float4(1.0,1.0,1.0,1.0);\n";
|
retval += " float4 lighting = float4(1.0,1.0,1.0,1.0);\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned sampIdx = 0;
|
unsigned sampIdx = 0;
|
||||||
for (const TexSampling& sampling : m_texSamplings)
|
for (const TexSampling& sampling : m_texSamplings)
|
||||||
retval += hecl::Format(" float4 sampling%u = tex%u.sample(samp, vtf.tcgs%u);\n",
|
retval += hecl::Format(" float4 sampling%u = tex%u.sample(samp, vtf.tcgs%u);\n",
|
||||||
sampIdx++, sampling.mapIdx, sampling.tcgIdx);
|
sampIdx++, sampling.mapIdx, sampling.tcgIdx);
|
||||||
|
|
||||||
if (m_alphaExpr.size())
|
if (m_alphaExpr.size())
|
||||||
retval += " return " + postEntry + "(float4(" + m_colorExpr + ", " + m_alphaExpr + "));\n";
|
retval += " return " + postEntry + "(float4(" + m_colorExpr + ", " + m_alphaExpr + "));\n";
|
||||||
else
|
else
|
||||||
retval += " return " + postEntry + "(float4(" + m_colorExpr + ", 1.0));\n";
|
retval += " return " + postEntry + "(float4(" + m_colorExpr + ", 1.0));\n";
|
||||||
|
|
||||||
return retval + "}\n";
|
return retval + "}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,55 +255,55 @@ namespace Runtime
|
|||||||
struct MetalBackendFactory : IShaderBackendFactory
|
struct MetalBackendFactory : IShaderBackendFactory
|
||||||
{
|
{
|
||||||
Backend::Metal m_backend;
|
Backend::Metal m_backend;
|
||||||
boo::MetalDataFactory* m_gfxFactory;
|
|
||||||
|
|
||||||
MetalBackendFactory(boo::IGraphicsDataFactory* gfxFactory)
|
|
||||||
: m_gfxFactory(dynamic_cast<boo::MetalDataFactory*>(gfxFactory)) {}
|
|
||||||
|
|
||||||
ShaderCachedData buildShaderFromIR(const ShaderTag& tag,
|
ShaderCachedData buildShaderFromIR(const ShaderTag& tag,
|
||||||
const hecl::Frontend::IR& ir,
|
const hecl::Frontend::IR& ir,
|
||||||
hecl::Frontend::Diagnostics& diag,
|
hecl::Frontend::Diagnostics& diag,
|
||||||
|
boo::IGraphicsDataFactory::Context& ctx,
|
||||||
boo::IShaderPipeline*& objOut)
|
boo::IShaderPipeline*& objOut)
|
||||||
{
|
{
|
||||||
if (!m_rtHint)
|
if (!m_rtHint)
|
||||||
Log.report(logvisor::Fatal,
|
Log.report(logvisor::Fatal,
|
||||||
"ShaderCacheManager::setRenderTargetHint must be called before making metal shaders");
|
"ShaderCacheManager::setRenderTargetHint must be called before making metal shaders");
|
||||||
|
|
||||||
m_backend.reset(ir, diag);
|
m_backend.reset(ir, diag);
|
||||||
size_t cachedSz = 2;
|
size_t cachedSz = 2;
|
||||||
|
|
||||||
std::string vertSource =
|
std::string vertSource =
|
||||||
m_backend.makeVert(tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(),
|
m_backend.makeVert(tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(),
|
||||||
tag.getSkinSlotCount(), tag.getTexMtxCount());
|
tag.getSkinSlotCount(), tag.getTexMtxCount());
|
||||||
cachedSz += vertSource.size() + 1;
|
cachedSz += vertSource.size() + 1;
|
||||||
|
|
||||||
std::string fragSource = m_backend.makeFrag();
|
std::string fragSource = m_backend.makeFrag();
|
||||||
cachedSz += fragSource.size() + 1;
|
cachedSz += fragSource.size() + 1;
|
||||||
objOut =
|
objOut =
|
||||||
m_gfxFactory->newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
|
static_cast<boo::MetalDataFactory::Context&>(ctx).
|
||||||
tag.newVertexFormat(m_gfxFactory), m_rtHint,
|
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
|
||||||
m_backend.m_blendSrc, m_backend.m_blendDst,
|
tag.newVertexFormat(ctx), m_rtHint,
|
||||||
tag.getDepthTest(), tag.getDepthWrite(),
|
m_backend.m_blendSrc, m_backend.m_blendDst,
|
||||||
tag.getBackfaceCulling());
|
tag.getPrimType(),
|
||||||
if (!*objOut)
|
tag.getDepthTest(), tag.getDepthWrite(),
|
||||||
|
tag.getBackfaceCulling());
|
||||||
|
if (!objOut)
|
||||||
Log.report(logvisor::Fatal, "unable to build shader");
|
Log.report(logvisor::Fatal, "unable to build shader");
|
||||||
|
|
||||||
ShaderCachedData dataOut(tag, cachedSz);
|
ShaderCachedData dataOut(tag, cachedSz);
|
||||||
athena::io::MemoryWriter w(dataOut.m_data.get(), dataOut.m_sz);
|
athena::io::MemoryWriter w(dataOut.m_data.get(), dataOut.m_sz);
|
||||||
w.writeUByte(atUint8(m_backend.m_blendSrc));
|
w.writeUByte(atUint8(m_backend.m_blendSrc));
|
||||||
w.writeUByte(atUint8(m_backend.m_blendDst));
|
w.writeUByte(atUint8(m_backend.m_blendDst));
|
||||||
w.writeString(vertSource);
|
w.writeString(vertSource);
|
||||||
w.writeString(fragSource);
|
w.writeString(fragSource);
|
||||||
|
|
||||||
return dataOut;
|
return dataOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
boo::IShaderPipeline* buildShaderFromCache(const ShaderCachedData& data)
|
boo::IShaderPipeline* buildShaderFromCache(const ShaderCachedData& data,
|
||||||
|
boo::IGraphicsDataFactory::Context& ctx)
|
||||||
{
|
{
|
||||||
if (!m_rtHint)
|
if (!m_rtHint)
|
||||||
Log.report(logvisor::Fatal,
|
Log.report(logvisor::Fatal,
|
||||||
"ShaderCacheManager::setRenderTargetHint must be called before making metal shaders");
|
"ShaderCacheManager::setRenderTargetHint must be called before making metal shaders");
|
||||||
|
|
||||||
const ShaderTag& tag = data.m_tag;
|
const ShaderTag& tag = data.m_tag;
|
||||||
athena::io::MemoryReader r(data.m_data.get(), data.m_sz);
|
athena::io::MemoryReader r(data.m_data.get(), data.m_sz);
|
||||||
boo::BlendFactor blendSrc = boo::BlendFactor(r.readUByte());
|
boo::BlendFactor blendSrc = boo::BlendFactor(r.readUByte());
|
||||||
@ -311,34 +311,36 @@ struct MetalBackendFactory : IShaderBackendFactory
|
|||||||
std::string vertSource = r.readString();
|
std::string vertSource = r.readString();
|
||||||
std::string fragSource = r.readString();
|
std::string fragSource = r.readString();
|
||||||
boo::IShaderPipeline* ret =
|
boo::IShaderPipeline* ret =
|
||||||
m_gfxFactory->newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
|
static_cast<boo::MetalDataFactory::Context&>(ctx).
|
||||||
tag.newVertexFormat(m_gfxFactory), m_rtHint,
|
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
|
||||||
blendSrc, blendDst,
|
tag.newVertexFormat(ctx), m_rtHint,
|
||||||
tag.getDepthTest(), tag.getDepthWrite(),
|
blendSrc, blendDst, tag.getPrimType(),
|
||||||
tag.getBackfaceCulling());
|
tag.getDepthTest(), tag.getDepthWrite(),
|
||||||
|
tag.getBackfaceCulling());
|
||||||
if (!ret)
|
if (!ret)
|
||||||
Log.report(logvisor::Fatal, "unable to build shader");
|
Log.report(logvisor::Fatal, "unable to build shader");
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderCachedData buildExtendedShaderFromIR(const ShaderTag& tag,
|
ShaderCachedData buildExtendedShaderFromIR(const ShaderTag& tag,
|
||||||
const hecl::Frontend::IR& ir,
|
const hecl::Frontend::IR& ir,
|
||||||
hecl::Frontend::Diagnostics& diag,
|
hecl::Frontend::Diagnostics& diag,
|
||||||
const std::vector<ShaderCacheExtensions::ExtensionSlot>& extensionSlots,
|
const std::vector<ShaderCacheExtensions::ExtensionSlot>& extensionSlots,
|
||||||
|
boo::IGraphicsDataFactory::Context& ctx,
|
||||||
FReturnExtensionShader returnFunc)
|
FReturnExtensionShader returnFunc)
|
||||||
{
|
{
|
||||||
if (!m_rtHint)
|
if (!m_rtHint)
|
||||||
Log.report(logvisor::Fatal,
|
Log.report(logvisor::Fatal,
|
||||||
"ShaderCacheManager::setRenderTargetHint must be called before making metal shaders");
|
"ShaderCacheManager::setRenderTargetHint must be called before making metal shaders");
|
||||||
|
|
||||||
m_backend.reset(ir, diag);
|
m_backend.reset(ir, diag);
|
||||||
size_t cachedSz = 2;
|
size_t cachedSz = 2;
|
||||||
|
|
||||||
std::string vertSource =
|
std::string vertSource =
|
||||||
m_backend.makeVert(tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(),
|
m_backend.makeVert(tag.getColorCount(), tag.getUvCount(), tag.getWeightCount(),
|
||||||
tag.getSkinSlotCount(), tag.getTexMtxCount());
|
tag.getSkinSlotCount(), tag.getTexMtxCount());
|
||||||
cachedSz += vertSource.size() + 1;
|
cachedSz += vertSource.size() + 1;
|
||||||
|
|
||||||
std::vector<std::string> fragSources;
|
std::vector<std::string> fragSources;
|
||||||
fragSources.reserve(extensionSlots.size());
|
fragSources.reserve(extensionSlots.size());
|
||||||
for (const ShaderCacheExtensions::ExtensionSlot& slot : extensionSlots)
|
for (const ShaderCacheExtensions::ExtensionSlot& slot : extensionSlots)
|
||||||
@ -346,16 +348,18 @@ struct MetalBackendFactory : IShaderBackendFactory
|
|||||||
fragSources.push_back(m_backend.makeFrag(slot.lighting, slot.post));
|
fragSources.push_back(m_backend.makeFrag(slot.lighting, slot.post));
|
||||||
cachedSz += fragSources.back().size() + 1;
|
cachedSz += fragSources.back().size() + 1;
|
||||||
boo::IShaderPipeline* ret =
|
boo::IShaderPipeline* ret =
|
||||||
m_gfxFactory->newShaderPipeline(vertSource.c_str(), fragSources.back().c_str(),
|
static_cast<boo::MetalDataFactory::Context&>(ctx).
|
||||||
tag.newVertexFormat(m_gfxFactory), m_rtHint,
|
newShaderPipeline(vertSource.c_str(), fragSources.back().c_str(),
|
||||||
m_backend.m_blendSrc, m_backend.m_blendDst,
|
tag.newVertexFormat(ctx), m_rtHint,
|
||||||
tag.getDepthTest(), tag.getDepthWrite(),
|
m_backend.m_blendSrc, m_backend.m_blendDst,
|
||||||
tag.getBackfaceCulling());
|
tag.getPrimType(),
|
||||||
|
tag.getDepthTest(), tag.getDepthWrite(),
|
||||||
|
tag.getBackfaceCulling());
|
||||||
if (!ret)
|
if (!ret)
|
||||||
Log.report(logvisor::Fatal, "unable to build shader");
|
Log.report(logvisor::Fatal, "unable to build shader");
|
||||||
returnFunc(ret);
|
returnFunc(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
ShaderCachedData dataOut(tag, cachedSz);
|
ShaderCachedData dataOut(tag, cachedSz);
|
||||||
athena::io::MemoryWriter w(dataOut.m_data.get(), dataOut.m_sz);
|
athena::io::MemoryWriter w(dataOut.m_data.get(), dataOut.m_sz);
|
||||||
w.writeUByte(atUint8(m_backend.m_blendSrc));
|
w.writeUByte(atUint8(m_backend.m_blendSrc));
|
||||||
@ -363,18 +367,19 @@ struct MetalBackendFactory : IShaderBackendFactory
|
|||||||
w.writeString(vertSource);
|
w.writeString(vertSource);
|
||||||
for (const std::string src : fragSources)
|
for (const std::string src : fragSources)
|
||||||
w.writeString(src);
|
w.writeString(src);
|
||||||
|
|
||||||
return dataOut;
|
return dataOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
void buildExtendedShaderFromCache(const ShaderCachedData& data,
|
void buildExtendedShaderFromCache(const ShaderCachedData& data,
|
||||||
const std::vector<ShaderCacheExtensions::ExtensionSlot>& extensionSlots,
|
const std::vector<ShaderCacheExtensions::ExtensionSlot>& extensionSlots,
|
||||||
|
boo::IGraphicsDataFactory::Context& ctx,
|
||||||
FReturnExtensionShader returnFunc)
|
FReturnExtensionShader returnFunc)
|
||||||
{
|
{
|
||||||
if (!m_rtHint)
|
if (!m_rtHint)
|
||||||
Log.report(logvisor::Fatal,
|
Log.report(logvisor::Fatal,
|
||||||
"ShaderCacheManager::setRenderTargetHint must be called before making metal shaders");
|
"ShaderCacheManager::setRenderTargetHint must be called before making metal shaders");
|
||||||
|
|
||||||
const ShaderTag& tag = data.m_tag;
|
const ShaderTag& tag = data.m_tag;
|
||||||
athena::io::MemoryReader r(data.m_data.get(), data.m_sz);
|
athena::io::MemoryReader r(data.m_data.get(), data.m_sz);
|
||||||
boo::BlendFactor blendSrc = boo::BlendFactor(r.readUByte());
|
boo::BlendFactor blendSrc = boo::BlendFactor(r.readUByte());
|
||||||
@ -384,11 +389,12 @@ struct MetalBackendFactory : IShaderBackendFactory
|
|||||||
{
|
{
|
||||||
std::string fragSource = r.readString();
|
std::string fragSource = r.readString();
|
||||||
boo::IShaderPipeline* ret =
|
boo::IShaderPipeline* ret =
|
||||||
m_gfxFactory->newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
|
static_cast<boo::MetalDataFactory::Context&>(ctx).
|
||||||
tag.newVertexFormat(m_gfxFactory), m_rtHint,
|
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
|
||||||
blendSrc, blendDst,
|
tag.newVertexFormat(ctx), m_rtHint,
|
||||||
tag.getDepthTest(), tag.getDepthWrite(),
|
blendSrc, blendDst, tag.getPrimType(),
|
||||||
tag.getBackfaceCulling());
|
tag.getDepthTest(), tag.getDepthWrite(),
|
||||||
|
tag.getBackfaceCulling());
|
||||||
if (!ret)
|
if (!ret)
|
||||||
Log.report(logvisor::Fatal, "unable to build shader");
|
Log.report(logvisor::Fatal, "unable to build shader");
|
||||||
returnFunc(ret);
|
returnFunc(ret);
|
||||||
@ -396,11 +402,11 @@ struct MetalBackendFactory : IShaderBackendFactory
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
IShaderBackendFactory* _NewMetalBackendFactory(boo::IGraphicsDataFactory* gfxFactory)
|
IShaderBackendFactory* _NewMetalBackendFactory()
|
||||||
{
|
{
|
||||||
return new struct MetalBackendFactory(gfxFactory);
|
return new struct MetalBackendFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user