From 7c6839fee7b05105b1a4863081717a2c4b722093 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Fri, 2 Dec 2022 12:33:10 -0500 Subject: [PATCH] CTevCombiners: Fix CTevPass (un)inlining Former-commit-id: 205947ebdfef71c0f54fc47f36eb155a658c0370 --- asm/Kyoto/Graphics/CTevCombiners.s | 11 ++---- asm/Kyoto/Graphics/CTevPass.s | 48 ------------------------ configure.py | 1 - include/Kyoto/Graphics/CGraphics.hpp | 2 +- include/Kyoto/Graphics/CTevCombiners.hpp | 29 ++++++++++++-- src/Kyoto/Graphics/CTevCombiners.cpp | 2 +- src/Kyoto/Graphics/CTevPass.cpp | 10 ----- src/Kyoto/Graphics/DolphinCGraphics.cpp | 2 +- 8 files changed, 32 insertions(+), 73 deletions(-) delete mode 100644 asm/Kyoto/Graphics/CTevPass.s delete mode 100644 src/Kyoto/Graphics/CTevPass.cpp diff --git a/asm/Kyoto/Graphics/CTevCombiners.s b/asm/Kyoto/Graphics/CTevCombiners.s index 5d2918ec..7b3319da 100644 --- a/asm/Kyoto/Graphics/CTevCombiners.s +++ b/asm/Kyoto/Graphics/CTevCombiners.s @@ -23,8 +23,8 @@ sNumEnabledPasses__13CTevCombiners: .section .sbss, "wa" .balign 8 -.global sUniquePass__13CTevCombiners -sUniquePass__13CTevCombiners: +.global sNextUniquePass__13CTevCombiners +sNextUniquePass__13CTevCombiners: .skip 0x4 .global skAlphaOne__13CTevCombiners skAlphaOne__13CTevCombiners: @@ -303,13 +303,11 @@ __sinit_CTevCombiners_cpp: /* 8030924C 003061AC 38 21 00 70 */ addi r1, r1, 0x70 /* 80309250 003061B0 4E 80 00 20 */ blr -.if 0 -# TODO: Figure out why this doesn't inline and get rid of the fake TU .global __ct__Q213CTevCombiners8CTevPassFRCQ213CTevCombiners9ColorPassRCQ213CTevCombiners9AlphaPassRCQ213CTevCombiners6CTevOpRCQ213CTevCombiners6CTevOp __ct__Q213CTevCombiners8CTevPassFRCQ213CTevCombiners9ColorPassRCQ213CTevCombiners9AlphaPassRCQ213CTevCombiners6CTevOpRCQ213CTevCombiners6CTevOp: -/* 80309254 003061B4 81 0D A7 98 */ lwz r8, sUniquePass__13CTevCombiners@sda21(r13) +/* 80309254 003061B4 81 0D A7 98 */ lwz r8, sNextUniquePass__13CTevCombiners@sda21(r13) /* 80309258 003061B8 38 08 00 01 */ addi r0, r8, 1 -/* 8030925C 003061BC 90 0D A7 98 */ stw r0, sUniquePass__13CTevCombiners@sda21(r13) +/* 8030925C 003061BC 90 0D A7 98 */ stw r0, sNextUniquePass__13CTevCombiners@sda21(r13) /* 80309260 003061C0 91 03 00 00 */ stw r8, 0(r3) /* 80309264 003061C4 80 04 00 00 */ lwz r0, 0(r4) /* 80309268 003061C8 90 03 00 04 */ stw r0, 4(r3) @@ -348,4 +346,3 @@ __ct__Q213CTevCombiners8CTevPassFRCQ213CTevCombiners9ColorPassRCQ213CTevCombiner /* 803092EC 0030624C 80 07 00 10 */ lwz r0, 0x10(r7) /* 803092F0 00306250 90 03 00 48 */ stw r0, 0x48(r3) /* 803092F4 00306254 4E 80 00 20 */ blr -.endif diff --git a/asm/Kyoto/Graphics/CTevPass.s b/asm/Kyoto/Graphics/CTevPass.s deleted file mode 100644 index deb750a8..00000000 --- a/asm/Kyoto/Graphics/CTevPass.s +++ /dev/null @@ -1,48 +0,0 @@ -.include "macros.inc" - -.section .text, "ax" - -# TODO: Figure out why this doesn't inline and get rid of this fake TU -.global __ct__Q213CTevCombiners8CTevPassFRCQ213CTevCombiners9ColorPassRCQ213CTevCombiners9AlphaPassRCQ213CTevCombiners6CTevOpRCQ213CTevCombiners6CTevOp -__ct__Q213CTevCombiners8CTevPassFRCQ213CTevCombiners9ColorPassRCQ213CTevCombiners9AlphaPassRCQ213CTevCombiners6CTevOpRCQ213CTevCombiners6CTevOp: -/* 80309254 003061B4 81 0D A7 98 */ lwz r8, sUniquePass__13CTevCombiners@sda21(r13) -/* 80309258 003061B8 38 08 00 01 */ addi r0, r8, 1 -/* 8030925C 003061BC 90 0D A7 98 */ stw r0, sUniquePass__13CTevCombiners@sda21(r13) -/* 80309260 003061C0 91 03 00 00 */ stw r8, 0(r3) -/* 80309264 003061C4 80 04 00 00 */ lwz r0, 0(r4) -/* 80309268 003061C8 90 03 00 04 */ stw r0, 4(r3) -/* 8030926C 003061CC 80 04 00 04 */ lwz r0, 4(r4) -/* 80309270 003061D0 90 03 00 08 */ stw r0, 8(r3) -/* 80309274 003061D4 80 04 00 08 */ lwz r0, 8(r4) -/* 80309278 003061D8 90 03 00 0C */ stw r0, 0xc(r3) -/* 8030927C 003061DC 80 04 00 0C */ lwz r0, 0xc(r4) -/* 80309280 003061E0 90 03 00 10 */ stw r0, 0x10(r3) -/* 80309284 003061E4 80 05 00 00 */ lwz r0, 0(r5) -/* 80309288 003061E8 90 03 00 14 */ stw r0, 0x14(r3) -/* 8030928C 003061EC 80 05 00 04 */ lwz r0, 4(r5) -/* 80309290 003061F0 90 03 00 18 */ stw r0, 0x18(r3) -/* 80309294 003061F4 80 05 00 08 */ lwz r0, 8(r5) -/* 80309298 003061F8 90 03 00 1C */ stw r0, 0x1c(r3) -/* 8030929C 003061FC 80 05 00 0C */ lwz r0, 0xc(r5) -/* 803092A0 00306200 90 03 00 20 */ stw r0, 0x20(r3) -/* 803092A4 00306204 88 06 00 00 */ lbz r0, 0(r6) -/* 803092A8 00306208 98 03 00 24 */ stb r0, 0x24(r3) -/* 803092AC 0030620C 80 06 00 04 */ lwz r0, 4(r6) -/* 803092B0 00306210 90 03 00 28 */ stw r0, 0x28(r3) -/* 803092B4 00306214 80 06 00 08 */ lwz r0, 8(r6) -/* 803092B8 00306218 90 03 00 2C */ stw r0, 0x2c(r3) -/* 803092BC 0030621C 80 06 00 0C */ lwz r0, 0xc(r6) -/* 803092C0 00306220 90 03 00 30 */ stw r0, 0x30(r3) -/* 803092C4 00306224 80 06 00 10 */ lwz r0, 0x10(r6) -/* 803092C8 00306228 90 03 00 34 */ stw r0, 0x34(r3) -/* 803092CC 0030622C 88 07 00 00 */ lbz r0, 0(r7) -/* 803092D0 00306230 98 03 00 38 */ stb r0, 0x38(r3) -/* 803092D4 00306234 80 07 00 04 */ lwz r0, 4(r7) -/* 803092D8 00306238 90 03 00 3C */ stw r0, 0x3c(r3) -/* 803092DC 0030623C 80 07 00 08 */ lwz r0, 8(r7) -/* 803092E0 00306240 90 03 00 40 */ stw r0, 0x40(r3) -/* 803092E4 00306244 80 07 00 0C */ lwz r0, 0xc(r7) -/* 803092E8 00306248 90 03 00 44 */ stw r0, 0x44(r3) -/* 803092EC 0030624C 80 07 00 10 */ lwz r0, 0x10(r7) -/* 803092F0 00306250 90 03 00 48 */ stw r0, 0x48(r3) -/* 803092F4 00306254 4E 80 00 20 */ blr diff --git a/configure.py b/configure.py index ad43d2d8..67a53c30 100755 --- a/configure.py +++ b/configure.py @@ -558,7 +558,6 @@ LIBS = [ "Kyoto/Graphics/CCubeModel", ["Kyoto/Graphics/CGX", True], ["Kyoto/Graphics/CTevCombiners", True], - ["Kyoto/Graphics/CTevPass", True], "Kyoto/Graphics/DolphinCGraphics", "Kyoto/Graphics/DolphinCPalette", "Kyoto/Graphics/DolphinCTexture", diff --git a/include/Kyoto/Graphics/CGraphics.hpp b/include/Kyoto/Graphics/CGraphics.hpp index 4e8485bb..61704e25 100644 --- a/include/Kyoto/Graphics/CGraphics.hpp +++ b/include/Kyoto/Graphics/CGraphics.hpp @@ -300,7 +300,7 @@ public: static void sub_80309564(uint* stretch, uint* xOffset, uint* yOffset); static void sub_803094b0(uint stretch, uint xOffset, uint yOffset); - static CTevCombiners::CTevPass& kEnvPassthru; + static const CTevCombiners::CTevPass& kEnvPassthru; static CTevCombiners::CTevPass kEnvModulateConstColor; static CTevCombiners::CTevPass kEnvConstColor; static CTevCombiners::CTevPass kEnvModulate; diff --git a/include/Kyoto/Graphics/CTevCombiners.hpp b/include/Kyoto/Graphics/CTevCombiners.hpp index 4b4c9efe..201a8550 100644 --- a/include/Kyoto/Graphics/CTevCombiners.hpp +++ b/include/Kyoto/Graphics/CTevCombiners.hpp @@ -25,19 +25,25 @@ public: kCS_Konst, kCS_Zero, }; + class ColorVar { public: ColorVar(EColorSrc src); + ColorVar(const ColorVar& other) : x0_src(other.GetSource()) {} EColorSrc GetSource() const { return x0_src; } private: EColorSrc x0_src; }; + class ColorPass { public: ColorPass(const ColorVar& a, const ColorVar& b, const ColorVar& c, const ColorVar& d) : x0_a(a), x4_b(b), x8_c(c), xc_d(d) {} + ColorPass(const ColorPass& other) + : x0_a(other.GetA()), x4_b(other.GetB()), x8_c(other.GetC()), xc_d(other.GetD()) {} + ColorVar GetA() const { return x0_a; } ColorVar GetB() const { return x4_b; } ColorVar GetC() const { return x8_c; } @@ -60,18 +66,24 @@ public: kAS_Konst, kAS_Zero, }; + class AlphaVar { public: AlphaVar(EAlphaSrc src); + AlphaVar(const AlphaVar& other) : x0_src(other.GetSource()) {} + EAlphaSrc GetSource() const { return x0_src; } private: EAlphaSrc x0_src; }; + class AlphaPass { public: AlphaPass(const AlphaVar& a, const AlphaVar& b, const AlphaVar& c, const AlphaVar& d) : x0_a(a), x4_b(b), x8_c(c), xc_d(d) {} + AlphaPass(const AlphaPass& other) + : x0_a(other.GetA()), x4_b(other.GetB()), x8_c(other.GetC()), xc_d(other.GetD()) {} AlphaVar GetA() const { return x0_a; } AlphaVar GetB() const { return x4_b; } @@ -89,28 +101,38 @@ public: kTO_Add, kTO_Subtract, }; + enum ETevBias { kTB_Zero, kTB_AddHalf, kTB_SubHalf, }; + enum ETevScale { kTS_Scale1, kTS_Scale2, kTS_Scale4, kTS_Divide2, }; + enum ETevOutput { kTO_Previous, kTO_Register0, kTO_Register1, kTO_Register2, }; + class CTevOp { public: CTevOp(ETevOp op = kTO_Add, ETevBias bias = kTB_Zero, ETevScale scale = kTS_Scale1, bool clamp = true, ETevOutput output = kTO_Previous) : x0_clamp(clamp), x4_op(op), x8_bias(bias), xc_scale(scale), x10_output(output) {} + CTevOp(const CTevOp& other) + : x0_clamp(other.GetClamp()) + , x4_op(other.GetOp()) + , x8_bias(other.GetBias()) + , xc_scale(other.GetScale()) + , x10_output(other.GetOutput()) {} bool GetClamp() const { return x0_clamp; } ETevOp GetOp() const { return x4_op; } @@ -129,13 +151,12 @@ public: class CTevPass { public: CTevPass(const ColorPass& colorPass, const AlphaPass& alphaPass, - const CTevOp& colorOp = CTevOp(), const CTevOp& alphaOp = CTevOp());/* - : x0_id(sUniquePass++) + const CTevOp& colorOp = CTevOp(), const CTevOp& alphaOp = CTevOp()) + : x0_id(sNextUniquePass++) , x4_colorPass(colorPass) , x14_alphaPass(alphaPass) , x24_colorOp(colorOp) , x38_alphaOp(alphaOp) {} - */ void Execute(int) const; @@ -154,7 +175,7 @@ public: static bool SetPassCombiners(int stage, const CTevPass& pass); static void ResetStates(); - static int sUniquePass; + static int sNextUniquePass; static const CTevPass kEnvPassthru; static const AlphaVar skAlphaOne; static const ColorVar skColorOne; diff --git a/src/Kyoto/Graphics/CTevCombiners.cpp b/src/Kyoto/Graphics/CTevCombiners.cpp index 92afe794..b50b2150 100644 --- a/src/Kyoto/Graphics/CTevCombiners.cpp +++ b/src/Kyoto/Graphics/CTevCombiners.cpp @@ -5,7 +5,7 @@ #define TEV_MAX_PASSES 2 -int CTevCombiners::sUniquePass = 0; +int CTevCombiners::sNextUniquePass = 0; const CTevCombiners::AlphaVar CTevCombiners::skAlphaOne(CTevCombiners::kAS_Konst); const CTevCombiners::ColorVar CTevCombiners::skColorOne(CTevCombiners::kCS_One); diff --git a/src/Kyoto/Graphics/CTevPass.cpp b/src/Kyoto/Graphics/CTevPass.cpp deleted file mode 100644 index 5d421ee5..00000000 --- a/src/Kyoto/Graphics/CTevPass.cpp +++ /dev/null @@ -1,10 +0,0 @@ -#include "Kyoto/Graphics/CTevCombiners.hpp" - -// TODO: Figure out why this doesn't inline and get rid of this fake TU -CTevCombiners::CTevPass::CTevPass(const ColorPass& colorPass, const AlphaPass& alphaPass, const CTevOp& colorOp, - const CTevOp& alphaOp) -: x0_id(sUniquePass++) -, x4_colorPass(colorPass) -, x14_alphaPass(alphaPass) -, x24_colorOp(colorOp) -, x38_alphaOp(alphaOp) {} diff --git a/src/Kyoto/Graphics/DolphinCGraphics.cpp b/src/Kyoto/Graphics/DolphinCGraphics.cpp index fcc458c2..09670e5c 100644 --- a/src/Kyoto/Graphics/DolphinCGraphics.cpp +++ b/src/Kyoto/Graphics/DolphinCGraphics.cpp @@ -244,7 +244,7 @@ ELightType CGraphics::mLightTypes[8] = { kLT_Directional, kLT_Directional, kLT_Directional, kLT_Directional, }; -CTevCombiners::CTevPass& CGraphics::kEnvPassthru = CTevCombiners::kEnvPassthru; +const CTevCombiners::CTevPass& CGraphics::kEnvPassthru = CTevCombiners::kEnvPassthru; bool CGraphics::mIsBeginSceneClearFb = true; ERglEnum CGraphics::mDepthFunc = kE_LEqual; ERglPrimitive CGraphics::mCurrentPrimitive = kP_Points;