mirror of https://github.com/AxioDL/metaforce.git
Changes to support MSAA rendering
This commit is contained in:
parent
61f6c6fc73
commit
b3ca5b1e1e
|
@ -1 +1 @@
|
||||||
Subproject commit db82ba674ba3fc94f6cc18d33f9de62dc52080d5
|
Subproject commit 1dc69c3468abfe599afb0677c2fb8cea1c99e8a4
|
|
@ -55,6 +55,13 @@ public:
|
||||||
bool registerCVar(CVar* cvar);
|
bool registerCVar(CVar* cvar);
|
||||||
|
|
||||||
CVar* findCVar(std::string_view name);
|
CVar* findCVar(std::string_view name);
|
||||||
|
template<class... _Args>
|
||||||
|
CVar* findOrMakeCVar(std::string_view name, _Args&&... args)
|
||||||
|
{
|
||||||
|
if (CVar* cv = findCVar(name))
|
||||||
|
return cv;
|
||||||
|
return newCVar(name, std::forward<_Args>(args)...);
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<CVar*> archivedCVars() const;
|
std::vector<CVar*> archivedCVars() const;
|
||||||
std::vector<CVar*> cvars() const;
|
std::vector<CVar*> cvars() const;
|
||||||
|
|
|
@ -195,7 +195,6 @@ class IShaderBackendFactory
|
||||||
{
|
{
|
||||||
friend class ShaderCacheManager;
|
friend class ShaderCacheManager;
|
||||||
protected:
|
protected:
|
||||||
unsigned m_rtHint = 1;
|
|
||||||
using FReturnExtensionShader = std::function<void(const boo::ObjToken<boo::IShaderPipeline>&)>;
|
using FReturnExtensionShader = std::function<void(const boo::ObjToken<boo::IShaderPipeline>&)>;
|
||||||
virtual ShaderCachedData buildShaderFromIR(const ShaderTag& tag,
|
virtual ShaderCachedData buildShaderFromIR(const ShaderTag& tag,
|
||||||
const hecl::Frontend::IR& ir,
|
const hecl::Frontend::IR& ir,
|
||||||
|
@ -269,10 +268,6 @@ public:
|
||||||
void reload();
|
void reload();
|
||||||
void clearCachedPipelines() { m_pipelineLookup.clear(); }
|
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<ShaderPipelines> buildShader(const ShaderTag& tag, std::string_view source,
|
std::shared_ptr<ShaderPipelines> buildShader(const ShaderTag& tag, std::string_view source,
|
||||||
std::string_view diagName,
|
std::string_view diagName,
|
||||||
boo::IGraphicsDataFactory& factory);
|
boo::IGraphicsDataFactory& factory);
|
||||||
|
|
|
@ -252,13 +252,12 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp
|
||||||
blockCall += hecl::Format("block%" PRISize, i);
|
blockCall += hecl::Format("block%" PRISize, 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, filter::linear, mip_filter::linear);\n"
|
|
||||||
"constexpr sampler clampSamp(address::clamp_to_border, border_color::opaque_white, filter::linear, mip_filter::linear);\n" +
|
|
||||||
GenerateVertToFragStruct(0, reflectionType != ReflectionType::None) + "\n" +
|
GenerateVertToFragStruct(0, reflectionType != ReflectionType::None) + "\n" +
|
||||||
GenerateFragOutStruct() + "\n" +
|
GenerateFragOutStruct() + "\n" +
|
||||||
lightingSrc + "\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"
|
"{\n"
|
||||||
" FragOut out;\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);
|
blockCall += hecl::Format("block%" PRISize, 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, filter::linear, mip_filter::linear);\n"
|
|
||||||
"constexpr sampler clampSamp(address::clamp_to_border, border_color::opaque_white, filter::linear, mip_filter::linear);\n" +
|
|
||||||
GenerateVertToFragStruct(extTexCount, reflectionType != ReflectionType::None) + "\n" +
|
GenerateVertToFragStruct(extTexCount, reflectionType != ReflectionType::None) + "\n" +
|
||||||
GenerateFragOutStruct() + "\n" +
|
GenerateFragOutStruct() + "\n" +
|
||||||
lightingSrc + "\n" +
|
lightingSrc + "\n" +
|
||||||
postSrc + "\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"
|
"{\n"
|
||||||
" FragOut out;\n";
|
" FragOut out;\n";
|
||||||
|
|
||||||
|
@ -395,7 +393,7 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp
|
||||||
if (lighting.m_entry)
|
if (lighting.m_entry)
|
||||||
{
|
{
|
||||||
retval += " float4 lighting = " + lightingEntry + "(" + blockCall + ", vtf.mvPos, vtf.mvNorm, vtf" +
|
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
|
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";
|
||||||
|
@ -412,14 +410,14 @@ std::string Metal::makeFrag(size_t blockCount, const char** blockNames, bool alp
|
||||||
{
|
{
|
||||||
retval += " out.color = " + postEntry + "(" +
|
retval += " out.color = " + postEntry + "(" +
|
||||||
(postEntry.size() ? ("vtf, " + (blockCall.size() ? (blockCall + ", ") : "") +
|
(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";
|
"float4(" + m_colorExpr + " + " + reflectionExpr + ", " + m_alphaExpr + ")) * mulColor;\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
retval += " out.color = " + postEntry + "(" +
|
retval += " out.color = " + postEntry + "(" +
|
||||||
(postEntry.size() ? ("vtf, " + (blockCall.size() ? (blockCall + ", ") : "") +
|
(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";
|
"float4(" + m_colorExpr + " + " + reflectionExpr + ", 1.0)) * mulColor;\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,10 +442,6 @@ struct MetalBackendFactory : IShaderBackendFactory
|
||||||
boo::IGraphicsDataFactory::Context& ctx,
|
boo::IGraphicsDataFactory::Context& ctx,
|
||||||
boo::ObjToken<boo::IShaderPipeline>& objOut)
|
boo::ObjToken<boo::IShaderPipeline>& objOut)
|
||||||
{
|
{
|
||||||
if (!m_rtHint)
|
|
||||||
Log.report(logvisor::Fatal,
|
|
||||||
"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;
|
||||||
|
|
||||||
|
@ -465,7 +459,7 @@ struct MetalBackendFactory : IShaderBackendFactory
|
||||||
static_cast<boo::MetalDataFactory::Context&>(ctx).
|
static_cast<boo::MetalDataFactory::Context&>(ctx).
|
||||||
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
|
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
|
||||||
&vertBlob, &fragBlob,
|
&vertBlob, &fragBlob,
|
||||||
tag.newVertexFormat(ctx), m_rtHint,
|
tag.newVertexFormat(ctx),
|
||||||
boo::BlendFactor(m_backend.m_blendSrc),
|
boo::BlendFactor(m_backend.m_blendSrc),
|
||||||
boo::BlendFactor(m_backend.m_blendDst),
|
boo::BlendFactor(m_backend.m_blendDst),
|
||||||
tag.getPrimType(),
|
tag.getPrimType(),
|
||||||
|
@ -492,10 +486,6 @@ struct MetalBackendFactory : IShaderBackendFactory
|
||||||
boo::ObjToken<boo::IShaderPipeline> buildShaderFromCache(const ShaderCachedData& data,
|
boo::ObjToken<boo::IShaderPipeline> buildShaderFromCache(const ShaderCachedData& data,
|
||||||
boo::IGraphicsDataFactory::Context& ctx)
|
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;
|
const ShaderTag& tag = data.m_tag;
|
||||||
athena::io::MemoryReader r(data.m_data.get(), data.m_sz, false, false);
|
athena::io::MemoryReader r(data.m_data.get(), data.m_sz, false, false);
|
||||||
boo::BlendFactor blendSrc = boo::BlendFactor(r.readUByte());
|
boo::BlendFactor blendSrc = boo::BlendFactor(r.readUByte());
|
||||||
|
@ -522,7 +512,7 @@ struct MetalBackendFactory : IShaderBackendFactory
|
||||||
static_cast<boo::MetalDataFactory::Context&>(ctx).
|
static_cast<boo::MetalDataFactory::Context&>(ctx).
|
||||||
newShaderPipeline(nullptr, nullptr,
|
newShaderPipeline(nullptr, nullptr,
|
||||||
&vertBlob, &fragBlob,
|
&vertBlob, &fragBlob,
|
||||||
tag.newVertexFormat(ctx), m_rtHint,
|
tag.newVertexFormat(ctx),
|
||||||
blendSrc, blendDst, tag.getPrimType(),
|
blendSrc, blendDst, tag.getPrimType(),
|
||||||
tag.getDepthTest() ? boo::ZTest::LEqual : boo::ZTest::None, tag.getDepthWrite(), true, true,
|
tag.getDepthTest() ? boo::ZTest::LEqual : boo::ZTest::None, tag.getDepthWrite(), true, true,
|
||||||
tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None);
|
tag.getBackfaceCulling() ? boo::CullMode::Backface : boo::CullMode::None);
|
||||||
|
@ -538,10 +528,6 @@ struct MetalBackendFactory : IShaderBackendFactory
|
||||||
boo::IGraphicsDataFactory::Context& ctx,
|
boo::IGraphicsDataFactory::Context& ctx,
|
||||||
FReturnExtensionShader returnFunc)
|
FReturnExtensionShader returnFunc)
|
||||||
{
|
{
|
||||||
if (!m_rtHint)
|
|
||||||
Log.report(logvisor::Fatal,
|
|
||||||
"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;
|
||||||
|
|
||||||
|
@ -585,7 +571,7 @@ struct MetalBackendFactory : IShaderBackendFactory
|
||||||
static_cast<boo::MetalDataFactory::Context&>(ctx).
|
static_cast<boo::MetalDataFactory::Context&>(ctx).
|
||||||
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
|
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
|
||||||
&blobs.back().first, &blobs.back().second,
|
&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.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),
|
boo::BlendFactor((slot.dstFactor == hecl::Backend::BlendFactor::Original) ? m_backend.m_blendDst : slot.dstFactor),
|
||||||
tag.getPrimType(), zTest, slot.noDepthWrite ? false : tag.getDepthWrite(),
|
tag.getPrimType(), zTest, slot.noDepthWrite ? false : tag.getDepthWrite(),
|
||||||
|
@ -621,10 +607,6 @@ struct MetalBackendFactory : IShaderBackendFactory
|
||||||
boo::IGraphicsDataFactory::Context& ctx,
|
boo::IGraphicsDataFactory::Context& ctx,
|
||||||
FReturnExtensionShader returnFunc)
|
FReturnExtensionShader returnFunc)
|
||||||
{
|
{
|
||||||
if (!m_rtHint)
|
|
||||||
Log.report(logvisor::Fatal,
|
|
||||||
"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, false, false);
|
athena::io::MemoryReader r(data.m_data.get(), data.m_sz, false, false);
|
||||||
hecl::Backend::BlendFactor blendSrc = hecl::Backend::BlendFactor(r.readUByte());
|
hecl::Backend::BlendFactor blendSrc = hecl::Backend::BlendFactor(r.readUByte());
|
||||||
|
@ -678,7 +660,7 @@ struct MetalBackendFactory : IShaderBackendFactory
|
||||||
static_cast<boo::MetalDataFactory::Context&>(ctx).
|
static_cast<boo::MetalDataFactory::Context&>(ctx).
|
||||||
newShaderPipeline(nullptr, nullptr,
|
newShaderPipeline(nullptr, nullptr,
|
||||||
&vertBlob, &fragBlob,
|
&vertBlob, &fragBlob,
|
||||||
tag.newVertexFormat(ctx), m_rtHint,
|
tag.newVertexFormat(ctx),
|
||||||
boo::BlendFactor((slot.srcFactor == hecl::Backend::BlendFactor::Original) ? blendSrc : slot.srcFactor),
|
boo::BlendFactor((slot.srcFactor == hecl::Backend::BlendFactor::Original) ? blendSrc : slot.srcFactor),
|
||||||
boo::BlendFactor((slot.dstFactor == hecl::Backend::BlendFactor::Original) ? blendDst : slot.dstFactor),
|
boo::BlendFactor((slot.dstFactor == hecl::Backend::BlendFactor::Original) ? blendDst : slot.dstFactor),
|
||||||
tag.getPrimType(), zTest, slot.noDepthWrite ? false : tag.getDepthWrite(),
|
tag.getPrimType(), zTest, slot.noDepthWrite ? false : tag.getDepthWrite(),
|
||||||
|
|
Loading…
Reference in New Issue