From 23f52a1eadd44bedcb74bf38cf9c2b752e412cf2 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Mon, 18 Jul 2016 17:41:55 -1000 Subject: [PATCH] Add support for normalizing TCG configs --- hecl/include/hecl/Backend/GX.hpp | 10 +++++-- .../hecl/Backend/ProgrammableCommon.hpp | 5 ++-- hecl/lib/Backend/GX.cpp | 28 +++++++++++-------- hecl/lib/Backend/ProgrammableCommon.cpp | 26 +++++++++-------- 4 files changed, 43 insertions(+), 26 deletions(-) diff --git a/hecl/include/hecl/Backend/GX.hpp b/hecl/include/hecl/Backend/GX.hpp index 29cccaa4a..44f89721e 100644 --- a/hecl/include/hecl/Backend/GX.hpp +++ b/hecl/include/hecl/Backend/GX.hpp @@ -281,6 +281,8 @@ struct GX : IBackend { TexGenSrc m_src = TG_TEX0; TexMtx m_mtx = IDENTITY; + bool m_norm = false; + PTTexMtx m_pmtx = PTIDENTITY; /* Not actually part of GX, but a way to relate out-of-band * texmtx animation parameters */ @@ -477,6 +479,10 @@ struct GX : IBackend return false; if (a.m_mtx != b.m_mtx) return false; + if (a.m_norm != b.m_norm) + return false; + if (a.m_pmtx != b.m_pmtx) + return false; } for (unsigned i=0 ; i m_gameArgs; }; @@ -53,7 +54,7 @@ struct ProgrammableCommon : IBackend void reset(const IR& ir, Diagnostics& diag, const char* backendName); private: - unsigned addTexCoordGen(TexGenSrc src, int uvIdx, int mtx); + unsigned addTexCoordGen(TexGenSrc src, int uvIdx, int mtx, bool normalize); unsigned addTexSampling(unsigned mapIdx, unsigned tcgIdx); std::string RecursiveTraceColor(const IR& ir, Diagnostics& diag, const IR::Instruction& inst, bool toSwizzle); @@ -61,7 +62,7 @@ private: const IR::Instruction& inst, bool toSwizzle); unsigned RecursiveTraceTexGen(const IR& ir, Diagnostics& diag, const IR::Instruction& inst, - int mtx); + int mtx, bool normalize); std::string EmitSamplingUseRaw(unsigned samplingIdx) const { diff --git a/hecl/lib/Backend/GX.cpp b/hecl/lib/Backend/GX.cpp index 0cf4d336c..d40218357 100644 --- a/hecl/lib/Backend/GX.cpp +++ b/hecl/lib/Backend/GX.cpp @@ -38,12 +38,12 @@ unsigned GX::addKAlpha(Diagnostics& diag, const SourceLocation& loc, float alpha } unsigned GX::addTexCoordGen(Diagnostics& diag, const SourceLocation& loc, - TexGenSrc src, TexMtx mtx) + TexGenSrc src, TexMtx mtx, bool norm, PTTexMtx pmtx) { for (unsigned i=0 ; i= 8) @@ -51,6 +51,8 @@ unsigned GX::addTexCoordGen(Diagnostics& diag, const SourceLocation& loc, GX::TexCoordGen& newTcg = m_tcgs[m_tcgCount]; newTcg.m_src = src; newTcg.m_mtx = mtx; + newTcg.m_norm = norm; + newTcg.m_pmtx = pmtx; return m_tcgCount++; } @@ -69,7 +71,8 @@ GX::TEVStage& GX::addTEVStage(Diagnostics& diag, const SourceLocation& loc) return newTEV; } -unsigned GX::RecursiveTraceTexGen(const IR& ir, Diagnostics& diag, const IR::Instruction& inst, TexMtx mtx) +unsigned GX::RecursiveTraceTexGen(const IR& ir, Diagnostics& diag, const IR::Instruction& inst, TexMtx mtx, + bool normalize, PTTexMtx pmtx) { if (inst.m_op != IR::OpType::Call) diag.reportBackendErr(inst.m_loc, "TexCoordGen resolution requires function"); @@ -81,16 +84,17 @@ unsigned GX::RecursiveTraceTexGen(const IR& ir, Diagnostics& diag, const IR::Ins diag.reportBackendErr(inst.m_loc, "TexCoordGen UV(layerIdx) requires one argument"); const IR::Instruction& idxInst = inst.getChildInst(ir, 0); const atVec4f& idxImm = idxInst.getImmVec(); - return addTexCoordGen(diag, inst.m_loc, TexGenSrc(TG_TEX0 + unsigned(idxImm.vec[0])), mtx); + return addTexCoordGen(diag, inst.m_loc, TexGenSrc(TG_TEX0 + unsigned(idxImm.vec[0])), mtx, normalize, pmtx); } else if (!tcgName.compare("Normal")) - return addTexCoordGen(diag, inst.m_loc, TG_NRM, mtx); + return addTexCoordGen(diag, inst.m_loc, TG_NRM, mtx, normalize, pmtx); else if (!tcgName.compare("View")) - return addTexCoordGen(diag, inst.m_loc, TG_POS, mtx); + return addTexCoordGen(diag, inst.m_loc, TG_POS, mtx, normalize, pmtx); /* Otherwise treat as game-specific function */ const IR::Instruction& tcgSrcInst = inst.getChildInst(ir, 0); - unsigned idx = RecursiveTraceTexGen(ir, diag, tcgSrcInst, TexMtx(TEXMTX0 + m_texMtxCount * 3)); + unsigned idx = RecursiveTraceTexGen(ir, diag, tcgSrcInst, TexMtx(TEXMTX0 + m_texMtxCount * 3), + normalize || tcgName.back() == 'N', PTTexMtx(PTTEXMTX0 + m_texMtxCount * 3)); GX::TexCoordGen& tcg = m_tcgs[idx]; m_texMtxRefs[m_texMtxCount] = &tcg; ++m_texMtxCount; @@ -112,7 +116,8 @@ GX::TraceResult GX::RecursiveTraceColor(const IR& ir, Diagnostics& diag, const I case IR::OpType::Call: { const std::string& name = inst.m_call.m_name; - if (!name.compare("Texture")) + bool normalize = false; + if (!name.compare("Texture") || (normalize = true && !name.compare("TextureN"))) { TEVStage& newStage = addTEVStage(diag, inst.m_loc); @@ -125,7 +130,7 @@ GX::TraceResult GX::RecursiveTraceColor(const IR& ir, Diagnostics& diag, const I newStage.m_color[0] = swizzleAlpha ? CC_TEXA : CC_TEXC; const IR::Instruction& tcgInst = inst.getChildInst(ir, 1); - newStage.m_texGenIdx = RecursiveTraceTexGen(ir, diag, tcgInst, IDENTITY); + newStage.m_texGenIdx = RecursiveTraceTexGen(ir, diag, tcgInst, IDENTITY, normalize, PTIDENTITY); return TraceResult(&newStage); } @@ -389,7 +394,8 @@ GX::TraceResult GX::RecursiveTraceAlpha(const IR& ir, Diagnostics& diag, const I case IR::OpType::Call: { const std::string& name = inst.m_call.m_name; - if (!name.compare("Texture")) + bool normalize = false; + if (!name.compare("Texture") || (normalize = true && !name.compare("TextureN"))) { if (inst.getChildCount() < 2) diag.reportBackendErr(inst.m_loc, "Texture(map, texgen) requires 2 arguments"); @@ -424,7 +430,7 @@ GX::TraceResult GX::RecursiveTraceAlpha(const IR& ir, Diagnostics& diag, const I newStage.m_alpha[0] = CA_TEXA; const IR::Instruction& tcgInst = inst.getChildInst(ir, 1); - newStage.m_texGenIdx = RecursiveTraceTexGen(ir, diag, tcgInst, IDENTITY); + newStage.m_texGenIdx = RecursiveTraceTexGen(ir, diag, tcgInst, IDENTITY, normalize, PTIDENTITY); return TraceResult(&newStage); } diff --git a/hecl/lib/Backend/ProgrammableCommon.cpp b/hecl/lib/Backend/ProgrammableCommon.cpp index ee40b3c11..78d8bcdd8 100644 --- a/hecl/lib/Backend/ProgrammableCommon.cpp +++ b/hecl/lib/Backend/ProgrammableCommon.cpp @@ -6,12 +6,12 @@ namespace hecl namespace Backend { -unsigned ProgrammableCommon::addTexCoordGen(TexGenSrc src, int uvIdx, int mtx) +unsigned ProgrammableCommon::addTexCoordGen(TexGenSrc src, int uvIdx, int mtx, bool normalize) { for (unsigned i=0 ; i