diff --git a/configure.py b/configure.py index cae80350a..cdf5dc90d 100755 --- a/configure.py +++ b/configure.py @@ -1004,7 +1004,7 @@ config.libs = [ Object(Matching, "JSystem/J3DGraphBase/J3DShapeMtx.cpp", extra_cflags=['-pragma "nosyminline on"']), # TODO: nosyminline may be a fakematch. jsystem pch? Object(Matching, "JSystem/J3DGraphBase/J3DShape.cpp"), Object(Matching, "JSystem/J3DGraphBase/J3DMaterial.cpp"), - Object(NonMatching, "JSystem/J3DGraphBase/J3DMatBlock.cpp"), + Object(Equivalent, "JSystem/J3DGraphBase/J3DMatBlock.cpp"), # regalloc Object(Matching, "JSystem/J3DGraphBase/J3DTevs.cpp"), Object(Matching, "JSystem/J3DGraphBase/J3DDrawBuffer.cpp"), ], diff --git a/include/JSystem/J3DGraphBase/J3DMatBlock.h b/include/JSystem/J3DGraphBase/J3DMatBlock.h index c8eaef865..979cf465d 100644 --- a/include/JSystem/J3DGraphBase/J3DMatBlock.h +++ b/include/JSystem/J3DGraphBase/J3DMatBlock.h @@ -854,8 +854,8 @@ struct J3DIndTexMtx : public J3DIndTexMtxInfo { explicit J3DIndTexMtx(const J3DIndTexMtxInfo& info) { *(J3DIndTexMtxInfo*)this = info; } ~J3DIndTexMtx() {} - void load(u32 id) { - J3DGDSetIndTexMtx(GXIndTexMtxID(id + GX_ITM_0), getOffsetMtx(), getScaleExp()); + void load(u32 id) const { + J3DGDSetIndTexMtx(GXIndTexMtxID(id + GX_ITM_0), (Mtx3P)mOffsetMtx, mScaleExp); } Mtx3P getOffsetMtx() { @@ -960,17 +960,11 @@ inline u16 calcColorChanID(u16 enable, u8 matSrc, u8 lightMask, u8 diffuseFn, u8 return reg; } -inline u32 setChanCtrlMacro(u8 enable, GXColorSrc ambSrc, GXColorSrc matSrc, u32 lightMask, GXDiffuseFn diffuseFn, GXAttnFn attnFn) { - u32 ret = matSrc << 0; // Putting this as a separate statement fixes codegen, but regalloc is still wrong - return - ret | - enable << 1 | - (lightMask & 0x0F) << 2 | - ambSrc << 6 | - ((attnFn == GX_AF_SPEC) ? GX_DF_NONE : diffuseFn) << 7 | - (attnFn != GX_AF_NONE) << 9 | - (attnFn != GX_AF_SPEC) << 10 | - (lightMask >> 4 & 0x0F) << 11; +static inline u32 setChanCtrlMacro(u8 enable, GXColorSrc ambSrc, GXColorSrc matSrc, u32 lightMask, + GXDiffuseFn diffuseFn, GXAttnFn attnFn) { + return matSrc << 0 | enable << 1 | (lightMask & 0x0F) << 2 | ambSrc << 6 | + ((attnFn == GX_AF_SPEC) ? GX_DF_NONE : diffuseFn) << 7 | (attnFn != GX_AF_NONE) << 9 | + (attnFn != GX_AF_SPEC) << 10 | (lightMask >> 4 & 0x0F) << 11; } struct J3DColorChan { @@ -992,21 +986,22 @@ struct J3DColorChan { info.mDiffuseFn, info.mAttnFn, ambSrc); } J3DColorChan(u16 id) : mChanCtrl(id) {} - GXAttnFn getAttnFn() { + u8 getAttnFn() const { u8 attnFnTbl[] = { GX_AF_NONE, GX_AF_SPEC, GX_AF_NONE, GX_AF_SPOT }; - return GXAttnFn(attnFnTbl[mChanCtrl >> 9 & 0x03]); + return attnFnTbl[(u32)(mChanCtrl & (3 << 9)) >> 9]; } - GXDiffuseFn getDiffuseFn() { return GXDiffuseFn(mChanCtrl >> 7 & 3); } - u8 getLightMask() { return ((mChanCtrl >> 2 & 0x0f) | (mChanCtrl >> 11 & 0x0f) << 4); } + u8 getDiffuseFn() const { return ((u32)(mChanCtrl & (3 << 7)) >> 7); } + u8 getLightMask() const { return ((mChanCtrl >> 2) & 0x0f) | ((mChanCtrl >> 11) & 0x0f) << 4; } void setLightMask(u8 mask) { mChanCtrl = (mChanCtrl & ~0x003c) | ((mask & 0x0F) << 2); mChanCtrl = (mChanCtrl & ~0x7800) | ((mask & 0xF0) << 7); } - GXColorSrc getMatSrc() { return GXColorSrc(mChanCtrl >> 0 & 0x01); } - GXColorSrc getAmbSrc() { return GXColorSrc(mChanCtrl >> 6 & 0x01); } - u8 getEnable() { return !!(mChanCtrl & 0x02); } - void load() { - J3DGDWrite_u32(setChanCtrlMacro(getEnable(), getAmbSrc(), getMatSrc(), getLightMask(), getDiffuseFn(), getAttnFn())); + u8 getMatSrc() const { return (GXColorSrc)(mChanCtrl & 1); } + u8 getAmbSrc() const { return (GXColorSrc)((u32)(mChanCtrl & (1 << 6)) >> 6); } + u8 getEnable() const { return (u32)(mChanCtrl & 0x2) >> 1; } + void load() const { + J3DGDWrite_u32(setChanCtrlMacro(getEnable(), (GXColorSrc)getAmbSrc(), (GXColorSrc)getMatSrc(), getLightMask(), + (GXDiffuseFn)getDiffuseFn(), (GXAttnFn)getAttnFn())); } /* 0x0 */ u16 mChanCtrl; diff --git a/src/JSystem/J3DGraphBase/J3DMatBlock.cpp b/src/JSystem/J3DGraphBase/J3DMatBlock.cpp index adf20758d..0fe80d3eb 100644 --- a/src/JSystem/J3DGraphBase/J3DMatBlock.cpp +++ b/src/JSystem/J3DGraphBase/J3DMatBlock.cpp @@ -341,7 +341,6 @@ void J3DColorBlockLightOff::load() { mColorChan[2].load(); mColorChan[1].load(); mColorChan[3].load(); - /* Nonmatching */ } /* 802E0438-802E0AC0 .text load__22J3DColorBlockAmbientOnFv */ @@ -356,7 +355,6 @@ void J3DColorBlockAmbientOn::load() { mColorChan[2].load(); mColorChan[1].load(); mColorChan[3].load(); - /* Nonmatching */ } /* 802E0AC0-802E1180 .text load__20J3DColorBlockLightOnFv */ @@ -376,7 +374,6 @@ void J3DColorBlockLightOn::load() { mLight[i]->load(i); } } - /* Nonmatching */ } /* 802E1180-802E11CC .text patch__21J3DColorBlockLightOffFv */ @@ -407,7 +404,6 @@ void J3DColorBlockLightOff::patchLight() { mColorChan[3].load(); u8* end = GDGetCurrPointer(); DCFlushRange(start, end - start); - /* Nonmatching */ } /* 802E17B4-802E1800 .text patch__20J3DColorBlockLightOnFv */ @@ -428,7 +424,6 @@ void J3DColorBlockLightOn::patchMatColor() { /* 802E19AC-802E1E18 .text patchLight__20J3DColorBlockLightOnFv */ void J3DColorBlockLightOn::patchLight() { - /* Nonmatching */ GDSetCurrOffset(mColorChanOffset); u8* start = GDGetCurrPointer(); GDOverflowCheck(SizeOfLoadColorChans); @@ -444,7 +439,6 @@ void J3DColorBlockLightOn::patchLight() { } u8* end = GDGetCurrPointer(); DCFlushRange(start, end - start); - /* Nonmatching */ } /* 802E1E18-802E1E80 .text diff__21J3DColorBlockLightOffFUl */ @@ -469,7 +463,6 @@ void J3DColorBlockLightOff::diffLight() { mColorChan[2].load(); mColorChan[1].load(); mColorChan[3].load(); - /* Nonmatching */ } /* 802E2408-802E2478 .text diff__20J3DColorBlockLightOnFUl */ @@ -1414,7 +1407,7 @@ void J3DTevBlock::indexToPtr_private(u32 offs) { /* 802E6298-802E6494 .text load__15J3DIndBlockFullFv */ void J3DIndBlockFull::load() { - /* Nonmatching */ + /* Nonmatching - regalloc */ u8 indTexStageNum = mIndTexStageNum; for (u32 i = 0; i < indTexStageNum; i++) { mIndTexMtx[i].load(i); @@ -1447,7 +1440,7 @@ void J3DIndBlockFull::load() { /* 802E6494-802E657C .text diff__15J3DIndBlockFullFUl */ void J3DIndBlockFull::diff(u32 flag) { - /* Nonmatching */ + /* Nonmatching - regalloc */ if ((flag & 0x08000000) == 0) { return; } @@ -1455,7 +1448,7 @@ void J3DIndBlockFull::diff(u32 flag) { J3DGDSetIndTexStageNum(indTexStageNum); mIndTexMtx[0].load(0); J3DGDSetIndTexCoordScale( - GXIndTexStageID(0), + GX_INDTEXSTAGE0, GXIndTexScale(mIndTexCoordScale[0].getScaleS()), GXIndTexScale(mIndTexCoordScale[0].getScaleT()), GXIndTexScale(mIndTexCoordScale[1].getScaleS()), @@ -1509,7 +1502,6 @@ void J3DPEBlockFogOff::load() { mBlend.load(mDither); mZMode.load(); loadZCompLoc(mZCompLoc); - /* Nonmatching */ } /* 802E7250-802E7538 .text diffBlend__16J3DPEBlockFogOffFv */ @@ -1517,7 +1509,6 @@ void J3DPEBlockFogOff::diffBlend() { GDOverflowCheck(0xf); mBlend.load(mDither); mZMode.load(); - /* Nonmatching */ } /* 802E7538-802E7A1C .text load__14J3DPEBlockFullFv */ @@ -1531,7 +1522,6 @@ void J3DPEBlockFull::load() { mBlend.load(mDither); mZMode.load(); loadZCompLoc(mZCompLoc); - /* Nonmatching */ } /* 802E7A1C-802E7AD8 .text patch__14J3DPEBlockFullFv */ @@ -1544,7 +1534,6 @@ void J3DPEBlockFull::patch() { } u8* end = GDGetCurrPointer(); DCFlushRange(start, end - start); - /* Nonmatching */ } /* 802E7AD8-802E7B5C .text diffFog__14J3DPEBlockFullFv */ @@ -1560,7 +1549,6 @@ void J3DPEBlockFull::diffBlend() { GDOverflowCheck(0xf); mBlend.load(mDither); mZMode.load(); - /* Nonmatching */ } /* 802E7E44-802E7EAC .text diff__14J3DPEBlockFullFUl */