From 3e7dd3283af2fda9fb4fc67768d5b6c08325fc18 Mon Sep 17 00:00:00 2001 From: robojumper Date: Mon, 24 Mar 2025 23:40:14 +0100 Subject: [PATCH] Start StateEfb --- config/SOUE01/splits.txt | 1 + config/SOUE01/symbols.txt | 9 ++++--- include/egg/gfx/eggStateEfb.h | 27 +++++++++++++++++++++ include/egg/gfx/eggStateGX.h | 2 +- src/egg/gfx/eggStateEfb.cpp | 44 ++++++++++++++++++++++++++++++++++- src/egg/gfx/eggStateGX.cpp | 2 +- 6 files changed, 77 insertions(+), 8 deletions(-) diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index 9c7b55a7..84c47baf 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -2347,6 +2347,7 @@ egg/gfx/eggStateEfb.cpp: .text start:0x804B3DA0 end:0x804B460C .sdata start:0x80574F60 end:0x80574F68 .sbss start:0x80576898 end:0x805768A0 + .sdata2 start:0x8057F868 end:0x8057F890 .bss start:0x80675010 end:0x806750A0 egg/gfx/eggStateGX.cpp: diff --git a/config/SOUE01/symbols.txt b/config/SOUE01/symbols.txt index d99e2921..2b094dbd 100644 --- a/config/SOUE01/symbols.txt +++ b/config/SOUE01/symbols.txt @@ -49806,11 +49806,10 @@ sMtx__3EGG = .bss:0x80674EC0; // type:object size:0x30 data:float lbl_80674EF0 = .bss:0x80674EF0; // type:object size:0xC data:float @LOCAL@Initialize__Q23EGG6ScreenFPCUsPCUsPQ23EGG6Screen@defaultRoot = .bss:0x80674F00; // type:object size:0x88 data:4byte sScreen__Q23EGG16ScreenEffectBase = .bss:0x80674F88; // type:object size:0x88 -lbl_80675010 = .bss:0x80675010; // type:object size:0x30 -lbl_80675040 = .bss:0x80675040; // type:object size:0x14 data:float -lbl_80675054 = .bss:0x80675054; // type:object size:0x4 data:float -lbl_80675058 = .bss:0x80675058; // type:object size:0x18 data:float -lbl_80675070 = .bss:0x80675070; // type:object size:0x30 data:float +spBufferSet__Q23EGG8StateEfb = .bss:0x80675010; // type:object size:0x30 +sWorkSpaceV__Q23EGG8StateEfb = .bss:0x80675040; // type:object size:0x18 data:float +sWorkSpaceHideV__Q23EGG8StateEfb = .bss:0x80675058; // type:object size:0x18 data:float +sUnkBuffer__Q23EGG8StateEfb = .bss:0x80675070; // type:object size:0x18 data:float sDefaultTexObj__Q23EGG7StateGX = .bss:0x806750A0; // type:object size:0x20 s_tmem_layout__Q23EGG7StateGX = .bss:0x806750C0; // type:object size:0xA8 data:4byte s_cacheGX__Q23EGG7StateGX = .bss:0x80675168; // type:object size:0x18 diff --git a/include/egg/gfx/eggStateEfb.h b/include/egg/gfx/eggStateEfb.h index fdecd35a..97e82605 100644 --- a/include/egg/gfx/eggStateEfb.h +++ b/include/egg/gfx/eggStateEfb.h @@ -1,11 +1,38 @@ #ifndef EGG_STATE_EFB_H #define EGG_STATE_EFB_H +#include "common.h" +#include "egg/egg_types.h" + namespace EGG { class StateEfb { + enum BufferType { + BUFFER_0, + BUFFER_1, + BUFFER_2, + BUFFER_3, + + BUFFER_MAX, + }; + + struct Buffer { + TextureBuffer *buf; + u32 userData; + u32 field_0x08; + }; + + static Buffer spBufferSet[BUFFER_MAX]; + static f32 sWorkSpaceV[6]; + static f32 sWorkSpaceHideV[6]; + static f32 sUnkBuffer[6]; // unk name + static s32 sWorkBuffer; + static s32 sPushCount; + static u32 sFlag; + public: static void Clean(); + static bool releaseEfb(BufferType type, u32 userData); }; } // namespace EGG diff --git a/include/egg/gfx/eggStateGX.h b/include/egg/gfx/eggStateGX.h index 9dcdf342..251d864e 100644 --- a/include/egg/gfx/eggStateGX.h +++ b/include/egg/gfx/eggStateGX.h @@ -89,7 +89,7 @@ public: static CacheGX &GXSetDstAlpha_(bool, u8); static void GXSetProjection_(Mtx44, GXProjectionType); static void GXSetProjectionv_(const f32 *); - static void GXSetViewport_(f32, f32, f32, f32, f32, f32); + static void GXSetViewport_(f32 ox, f32 oy, f32 sx, f32 sy, f32 near, f32 far); static void GXSetScissor_(u32, u32, u32, u32); static void GXSetScissorBoxOffset_(s32, s32); diff --git a/src/egg/gfx/eggStateEfb.cpp b/src/egg/gfx/eggStateEfb.cpp index 25f2dbbb..39a4a588 100644 --- a/src/egg/gfx/eggStateEfb.cpp +++ b/src/egg/gfx/eggStateEfb.cpp @@ -1,3 +1,45 @@ #include "egg/gfx/eggStateEfb.h" -namespace EGG {} // namespace EGG +#include "common.h" +#include "egg/gfx/eggTextureBuffer.h" + +namespace EGG { + +StateEfb::Buffer StateEfb::spBufferSet[BUFFER_MAX]; +f32 StateEfb::sWorkSpaceV[6]; +f32 StateEfb::sWorkSpaceHideV[6]; +f32 StateEfb::sUnkBuffer[6]; + +u32 StateEfb::sFlag = 4; +s32 StateEfb::sWorkBuffer = -1; + +s32 StateEfb::sPushCount; + +void StateEfb::Clean() { + sFlag &= ~(1 | 2); + sWorkBuffer = -1; + sPushCount = 0; + + for (u32 i = 0; i < ARRAY_LENGTH(spBufferSet); i++) { + spBufferSet[i].field_0x08 = 0; + } + + for (u32 i = 0; i < ARRAY_LENGTH(sWorkSpaceV); i++) { + sWorkSpaceV[i] = 0.0f; + sWorkSpaceHideV[i] = 0.0f; + } +} + +bool StateEfb::releaseEfb(BufferType type, u32 userData) { + if (spBufferSet[type].buf != nullptr && spBufferSet[type].userData == userData) { + spBufferSet[type].buf->free(); + spBufferSet[type].buf = nullptr; + spBufferSet[type].userData = 0; + spBufferSet[type].field_0x08 = 0; + return true; + } else { + return false; + } +} + +} // namespace EGG diff --git a/src/egg/gfx/eggStateGX.cpp b/src/egg/gfx/eggStateGX.cpp index f364b81a..fc56e29e 100644 --- a/src/egg/gfx/eggStateGX.cpp +++ b/src/egg/gfx/eggStateGX.cpp @@ -34,7 +34,7 @@ static const f32 identity[3][4] = { namespace EGG { -GXTexObj StateGX::sDefaultTexObj; +GXTexObj ALIGN_DECL(32) StateGX::sDefaultTexObj; StateGX::MemLayout StateGX::s_tmem_layout; StateGX::CacheGX StateGX::s_cacheGX;