mirror of https://github.com/AxioDL/metaforce.git
Shader variable emit fixes
This commit is contained in:
parent
c47ae9f3b6
commit
c544d99f98
|
@ -1 +1 @@
|
|||
Subproject commit 5c91ba8da7951b2b039da5fb07cf5dcd49be2790
|
||||
Subproject commit 44e8317d49cd5be5776a48ebc9715495cb47552a
|
|
@ -56,13 +56,18 @@ private:
|
|||
unsigned addTexCoordGen(TexGenSrc src, int uvIdx, int mtx);
|
||||
unsigned addTexSampling(unsigned mapIdx, unsigned tcgIdx);
|
||||
std::string RecursiveTraceColor(const IR& ir, Diagnostics& diag,
|
||||
const IR::Instruction& inst);
|
||||
const IR::Instruction& inst, bool toSwizzle);
|
||||
std::string RecursiveTraceAlpha(const IR& ir, Diagnostics& diag,
|
||||
const IR::Instruction& inst);
|
||||
const IR::Instruction& inst, bool toSwizzle);
|
||||
unsigned RecursiveTraceTexGen(const IR& ir, Diagnostics& diag,
|
||||
const IR::Instruction& inst,
|
||||
int mtx);
|
||||
|
||||
std::string EmitSamplingUseRaw(unsigned samplingIdx) const
|
||||
{
|
||||
return hecl::Format("sampling%u", samplingIdx);
|
||||
}
|
||||
|
||||
std::string EmitSamplingUseRGB(unsigned samplingIdx) const
|
||||
{
|
||||
return hecl::Format("sampling%u.rgb", samplingIdx);
|
||||
|
@ -78,6 +83,11 @@ private:
|
|||
return hecl::Format("colorReg%u", idx);
|
||||
}
|
||||
|
||||
std::string EmitLightingRaw() const
|
||||
{
|
||||
return std::string("lighting");
|
||||
}
|
||||
|
||||
std::string EmitLightingRGB() const
|
||||
{
|
||||
return std::string("lighting.rgb");
|
||||
|
|
|
@ -17,9 +17,9 @@ std::string GLSL::EmitTexGenSource2(TexGenSrc src, int uvIdx) const
|
|||
switch (src)
|
||||
{
|
||||
case TexGenSrc::Position:
|
||||
return "posIn.xy\n";
|
||||
return "posIn.xy";
|
||||
case TexGenSrc::Normal:
|
||||
return "normIn.xy\n";
|
||||
return "normIn.xy";
|
||||
case TexGenSrc::UV:
|
||||
return hecl::Format("uvIn[%u]", uvIdx);
|
||||
default: break;
|
||||
|
@ -32,9 +32,9 @@ std::string GLSL::EmitTexGenSource4(TexGenSrc src, int uvIdx) const
|
|||
switch (src)
|
||||
{
|
||||
case TexGenSrc::Position:
|
||||
return "vec4(posIn, 1.0)\n";
|
||||
return "vec4(posIn, 1.0)";
|
||||
case TexGenSrc::Normal:
|
||||
return "vec4(normIn, 1.0)\n";
|
||||
return "vec4(normIn, 1.0)";
|
||||
case TexGenSrc::UV:
|
||||
return hecl::Format("vec4(uvIn[%u], 0.0, 1.0)", uvIdx);
|
||||
default: break;
|
||||
|
@ -166,8 +166,8 @@ std::string GLSL::makeFrag(const char* glslVer,
|
|||
lightingSrc = lighting.m_source;
|
||||
|
||||
std::string texMapDecl;
|
||||
if (m_texMapEnd)
|
||||
texMapDecl = hecl::Format("TBINDING0 uniform sampler2D texs[%u];\n", m_texMapEnd);
|
||||
for (int i=0 ; i<m_texMapEnd ; ++i)
|
||||
texMapDecl += hecl::Format("TBINDING%u uniform sampler2D tex%u;\n", i, i);
|
||||
|
||||
std::string retval = std::string(glslVer) + "\n" BOO_GLSL_BINDING_HEAD +
|
||||
GenerateVertToFragStruct() +
|
||||
|
@ -188,7 +188,7 @@ std::string GLSL::makeFrag(const char* glslVer,
|
|||
|
||||
unsigned sampIdx = 0;
|
||||
for (const TexSampling& sampling : m_texSamplings)
|
||||
retval += hecl::Format(" vec4 sampling%u = texture(texs[%u], vtf.tcgs[%u]);\n",
|
||||
retval += hecl::Format(" vec4 sampling%u = texture(tex%u, vtf.tcgs[%u]);\n",
|
||||
sampIdx++, sampling.mapIdx, sampling.tcgIdx);
|
||||
|
||||
if (m_alphaExpr.size())
|
||||
|
@ -216,8 +216,8 @@ std::string GLSL::makeFrag(const char* glslVer,
|
|||
postEntry = post.m_entry;
|
||||
|
||||
std::string texMapDecl;
|
||||
if (m_texMapEnd)
|
||||
texMapDecl = hecl::Format("TBINDING0 uniform sampler2D texs[%u];\n", m_texMapEnd);
|
||||
for (int i=0 ; i<m_texMapEnd ; ++i)
|
||||
texMapDecl += hecl::Format("TBINDING%u uniform sampler2D tex%u;\n", i, i);
|
||||
|
||||
std::string retval = std::string(glslVer) + "\n" BOO_GLSL_BINDING_HEAD +
|
||||
GenerateVertToFragStruct() +
|
||||
|
@ -238,7 +238,7 @@ std::string GLSL::makeFrag(const char* glslVer,
|
|||
|
||||
unsigned sampIdx = 0;
|
||||
for (const TexSampling& sampling : m_texSamplings)
|
||||
retval += hecl::Format(" vec4 sampling%u = texture(texs[%u], vtf.tcgs[%u]);\n",
|
||||
retval += hecl::Format(" vec4 sampling%u = texture(tex%u, vtf.tcgs[%u]);\n",
|
||||
sampIdx++, sampling.mapIdx, sampling.tcgIdx);
|
||||
|
||||
if (m_alphaExpr.size())
|
||||
|
@ -256,6 +256,18 @@ namespace Runtime
|
|||
static const char* STD_BLOCKNAMES[] = {HECL_GLSL_VERT_UNIFORM_BLOCK_NAME,
|
||||
HECL_GLSL_TEXMTX_UNIFORM_BLOCK_NAME};
|
||||
|
||||
static const char* STD_TEXNAMES[] =
|
||||
{
|
||||
"tex0",
|
||||
"tex1",
|
||||
"tex2",
|
||||
"tex3",
|
||||
"tex4",
|
||||
"tex5",
|
||||
"tex6",
|
||||
"tex7"
|
||||
};
|
||||
|
||||
struct GLSLBackendFactory : IShaderBackendFactory
|
||||
{
|
||||
Backend::GLSL m_backend;
|
||||
|
@ -277,10 +289,14 @@ struct GLSLBackendFactory : IShaderBackendFactory
|
|||
|
||||
std::string fragSource = m_backend.makeFrag("#version 330");
|
||||
cachedSz += fragSource.size() + 1;
|
||||
|
||||
if (m_backend.m_texMapEnd > 8)
|
||||
Log.report(logvisor::Fatal, "maximum of 8 texture maps supported");
|
||||
|
||||
objOut =
|
||||
static_cast<boo::GLDataFactory::Context&>(ctx).
|
||||
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
|
||||
m_backend.m_texMapEnd, "texs",
|
||||
m_backend.m_texMapEnd, STD_TEXNAMES,
|
||||
2, STD_BLOCKNAMES,
|
||||
m_backend.m_blendSrc, m_backend.m_blendDst, tag.getPrimType(),
|
||||
tag.getDepthTest(), tag.getDepthWrite(),
|
||||
|
@ -309,10 +325,14 @@ struct GLSLBackendFactory : IShaderBackendFactory
|
|||
boo::BlendFactor blendDst = boo::BlendFactor(r.readUByte());
|
||||
std::string vertSource = r.readString();
|
||||
std::string fragSource = r.readString();
|
||||
|
||||
if (texMapEnd > 8)
|
||||
Log.report(logvisor::Fatal, "maximum of 8 texture maps supported");
|
||||
|
||||
boo::IShaderPipeline* ret =
|
||||
static_cast<boo::GLDataFactory::Context&>(ctx).
|
||||
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
|
||||
texMapEnd, "texs",
|
||||
texMapEnd, STD_TEXNAMES,
|
||||
2, STD_BLOCKNAMES,
|
||||
blendSrc, blendDst, tag.getPrimType(),
|
||||
tag.getDepthTest(), tag.getDepthWrite(),
|
||||
|
@ -338,6 +358,9 @@ struct GLSLBackendFactory : IShaderBackendFactory
|
|||
tag.getSkinSlotCount(), tag.getTexMtxCount());
|
||||
cachedSz += vertSource.size() + 1;
|
||||
|
||||
if (m_backend.m_texMapEnd > 8)
|
||||
Log.report(logvisor::Fatal, "maximum of 8 texture maps supported");
|
||||
|
||||
std::vector<std::string> fragSources;
|
||||
fragSources.reserve(extensionSlots.size());
|
||||
for (const ShaderCacheExtensions::ExtensionSlot& slot : extensionSlots)
|
||||
|
@ -355,7 +378,7 @@ struct GLSLBackendFactory : IShaderBackendFactory
|
|||
boo::IShaderPipeline* ret =
|
||||
static_cast<boo::GLDataFactory::Context&>(ctx).
|
||||
newShaderPipeline(vertSource.c_str(), fragSources.back().c_str(),
|
||||
m_backend.m_texMapEnd, "texs", bc, bn,
|
||||
m_backend.m_texMapEnd, STD_TEXNAMES, bc, bn,
|
||||
m_backend.m_blendSrc, m_backend.m_blendDst, tag.getPrimType(),
|
||||
tag.getDepthTest(), tag.getDepthWrite(),
|
||||
tag.getBackfaceCulling());
|
||||
|
@ -387,6 +410,10 @@ struct GLSLBackendFactory : IShaderBackendFactory
|
|||
boo::BlendFactor blendSrc = boo::BlendFactor(r.readUByte());
|
||||
boo::BlendFactor blendDst = boo::BlendFactor(r.readUByte());
|
||||
std::string vertSource = r.readString();
|
||||
|
||||
if (texMapEnd > 8)
|
||||
Log.report(logvisor::Fatal, "maximum of 8 texture maps supported");
|
||||
|
||||
for (const ShaderCacheExtensions::ExtensionSlot& slot : extensionSlots)
|
||||
{
|
||||
size_t bc = 2;
|
||||
|
@ -401,7 +428,7 @@ struct GLSLBackendFactory : IShaderBackendFactory
|
|||
boo::IShaderPipeline* ret =
|
||||
static_cast<boo::GLDataFactory::Context&>(ctx).
|
||||
newShaderPipeline(vertSource.c_str(), fragSource.c_str(),
|
||||
texMapEnd, "texs", bc, bn,
|
||||
texMapEnd, STD_TEXNAMES, bc, bn,
|
||||
blendSrc, blendDst, tag.getPrimType(),
|
||||
tag.getDepthTest(), tag.getDepthWrite(),
|
||||
tag.getBackfaceCulling());
|
||||
|
|
|
@ -75,7 +75,7 @@ unsigned ProgrammableCommon::RecursiveTraceTexGen(const IR& ir, Diagnostics& dia
|
|||
}
|
||||
|
||||
std::string ProgrammableCommon::RecursiveTraceColor(const IR& ir, Diagnostics& diag,
|
||||
const IR::Instruction& inst)
|
||||
const IR::Instruction& inst, bool toSwizzle)
|
||||
{
|
||||
switch (inst.m_op)
|
||||
{
|
||||
|
@ -94,7 +94,8 @@ std::string ProgrammableCommon::RecursiveTraceColor(const IR& ir, Diagnostics& d
|
|||
const IR::Instruction& tcgInst = inst.getChildInst(ir, 1);
|
||||
unsigned texGenIdx = RecursiveTraceTexGen(ir, diag, tcgInst, -1);
|
||||
|
||||
return EmitSamplingUseRGB(addTexSampling(mapIdx, texGenIdx));
|
||||
return toSwizzle ? EmitSamplingUseRaw(addTexSampling(mapIdx, texGenIdx)) :
|
||||
EmitSamplingUseRGB(addTexSampling(mapIdx, texGenIdx));
|
||||
}
|
||||
else if (!name.compare("ColorReg"))
|
||||
{
|
||||
|
@ -105,7 +106,7 @@ std::string ProgrammableCommon::RecursiveTraceColor(const IR& ir, Diagnostics& d
|
|||
else if (!name.compare("Lighting"))
|
||||
{
|
||||
m_lighting = true;
|
||||
return EmitLightingRGB();
|
||||
return toSwizzle ? EmitLightingRaw() : EmitLightingRGB();
|
||||
}
|
||||
else
|
||||
diag.reportBackendErr(inst.m_loc, "unable to interpret '%s'", name.c_str());
|
||||
|
@ -121,8 +122,8 @@ std::string ProgrammableCommon::RecursiveTraceColor(const IR& ir, Diagnostics& d
|
|||
ArithmeticOp op = inst.m_arithmetic.m_op;
|
||||
const IR::Instruction& aInst = inst.getChildInst(ir, 0);
|
||||
const IR::Instruction& bInst = inst.getChildInst(ir, 1);
|
||||
std::string aTrace = RecursiveTraceColor(ir, diag, aInst);
|
||||
std::string bTrace = RecursiveTraceColor(ir, diag, bInst);
|
||||
std::string aTrace = RecursiveTraceColor(ir, diag, aInst, false);
|
||||
std::string bTrace = RecursiveTraceColor(ir, diag, bInst, false);
|
||||
|
||||
switch (op)
|
||||
{
|
||||
|
@ -149,7 +150,7 @@ std::string ProgrammableCommon::RecursiveTraceColor(const IR& ir, Diagnostics& d
|
|||
case IR::OpType::Swizzle:
|
||||
{
|
||||
const IR::Instruction& aInst = inst.getChildInst(ir, 0);
|
||||
std::string aTrace = RecursiveTraceColor(ir, diag, aInst);
|
||||
std::string aTrace = RecursiveTraceColor(ir, diag, aInst, true);
|
||||
return EmitSwizzle3(diag, inst.m_loc, aTrace, inst.m_swizzle.m_idxs);
|
||||
}
|
||||
default:
|
||||
|
@ -160,7 +161,7 @@ std::string ProgrammableCommon::RecursiveTraceColor(const IR& ir, Diagnostics& d
|
|||
}
|
||||
|
||||
std::string ProgrammableCommon::RecursiveTraceAlpha(const IR& ir, Diagnostics& diag,
|
||||
const IR::Instruction& inst)
|
||||
const IR::Instruction& inst, bool toSwizzle)
|
||||
{
|
||||
switch (inst.m_op)
|
||||
{
|
||||
|
@ -179,7 +180,8 @@ std::string ProgrammableCommon::RecursiveTraceAlpha(const IR& ir, Diagnostics& d
|
|||
const IR::Instruction& tcgInst = inst.getChildInst(ir, 1);
|
||||
unsigned texGenIdx = RecursiveTraceTexGen(ir, diag, tcgInst, -1);
|
||||
|
||||
return EmitSamplingUseAlpha(addTexSampling(mapIdx, texGenIdx));
|
||||
return toSwizzle ? EmitSamplingUseRaw(addTexSampling(mapIdx, texGenIdx)) :
|
||||
EmitSamplingUseAlpha(addTexSampling(mapIdx, texGenIdx));
|
||||
}
|
||||
else if (!name.compare("ColorReg"))
|
||||
{
|
||||
|
@ -190,7 +192,7 @@ std::string ProgrammableCommon::RecursiveTraceAlpha(const IR& ir, Diagnostics& d
|
|||
else if (!name.compare("Lighting"))
|
||||
{
|
||||
m_lighting = true;
|
||||
return EmitLightingAlpha();
|
||||
return toSwizzle ? EmitLightingRaw() : EmitLightingAlpha();
|
||||
}
|
||||
else
|
||||
diag.reportBackendErr(inst.m_loc, "unable to interpret '%s'", name.c_str());
|
||||
|
@ -206,8 +208,8 @@ std::string ProgrammableCommon::RecursiveTraceAlpha(const IR& ir, Diagnostics& d
|
|||
ArithmeticOp op = inst.m_arithmetic.m_op;
|
||||
const IR::Instruction& aInst = inst.getChildInst(ir, 0);
|
||||
const IR::Instruction& bInst = inst.getChildInst(ir, 1);
|
||||
std::string aTrace = RecursiveTraceAlpha(ir, diag, aInst);
|
||||
std::string bTrace = RecursiveTraceAlpha(ir, diag, bInst);
|
||||
std::string aTrace = RecursiveTraceAlpha(ir, diag, aInst, false);
|
||||
std::string bTrace = RecursiveTraceAlpha(ir, diag, bInst, false);
|
||||
|
||||
switch (op)
|
||||
{
|
||||
|
@ -234,7 +236,7 @@ std::string ProgrammableCommon::RecursiveTraceAlpha(const IR& ir, Diagnostics& d
|
|||
case IR::OpType::Swizzle:
|
||||
{
|
||||
const IR::Instruction& aInst = inst.getChildInst(ir, 0);
|
||||
std::string aTrace = RecursiveTraceAlpha(ir, diag, aInst);
|
||||
std::string aTrace = RecursiveTraceAlpha(ir, diag, aInst, true);
|
||||
return EmitSwizzle1(diag, inst.m_loc, aTrace, inst.m_swizzle.m_idxs);
|
||||
}
|
||||
default:
|
||||
|
@ -246,6 +248,14 @@ std::string ProgrammableCommon::RecursiveTraceAlpha(const IR& ir, Diagnostics& d
|
|||
|
||||
void ProgrammableCommon::reset(const IR& ir, Diagnostics& diag, const char* backendName)
|
||||
{
|
||||
m_lighting = false;
|
||||
m_texSamplings.clear();
|
||||
m_texMapEnd = 0;
|
||||
m_tcgs.clear();
|
||||
m_texMtxRefs.clear();
|
||||
m_colorExpr.clear();
|
||||
m_alphaExpr.clear();
|
||||
|
||||
diag.setBackend(backendName);
|
||||
|
||||
/* Final instruction is the root call by hecl convention */
|
||||
|
@ -278,14 +288,14 @@ void ProgrammableCommon::reset(const IR& ir, Diagnostics& diag, const char* back
|
|||
/* Follow Color Chain */
|
||||
const IR::Instruction& colorRoot =
|
||||
ir.m_instructions.at(rootCall.m_call.m_argInstIdxs.at(0));
|
||||
m_colorExpr = RecursiveTraceColor(ir, diag, colorRoot);
|
||||
m_colorExpr = RecursiveTraceColor(ir, diag, colorRoot, false);
|
||||
|
||||
/* Follow Alpha Chain */
|
||||
if (doAlpha)
|
||||
{
|
||||
const IR::Instruction& alphaRoot =
|
||||
ir.m_instructions.at(rootCall.m_call.m_argInstIdxs.at(1));
|
||||
m_alphaExpr = RecursiveTraceAlpha(ir, diag, alphaRoot);
|
||||
m_alphaExpr = RecursiveTraceAlpha(ir, diag, alphaRoot, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue