From 3e42b1a9a4882f73f521d2b87f2b811107a908dc Mon Sep 17 00:00:00 2001 From: fincs Date: Sun, 6 Sep 2015 22:08:28 +0200 Subject: [PATCH] Adapt to the great-refactor libctru branch --- Makefile | 1 + examples/gputest/Makefile | 2 +- source/base.c | 37 ++++++++++--------------------------- source/context.h | 2 -- source/effect.c | 4 ++-- source/ibo.c | 2 +- source/renderbuffer.c | 6 +++--- source/texture.c | 2 +- source/uniforms.c | 3 ++- source/vbo.c | 2 +- 10 files changed, 22 insertions(+), 39 deletions(-) diff --git a/Makefile b/Makefile index 727b9b8..eb3abb4 100644 --- a/Makefile +++ b/Makefile @@ -28,6 +28,7 @@ INCLUDES := include ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard CFLAGS := -g -Wall -O2 -mword-relocations \ + -ffunction-sections \ -fomit-frame-pointer -ffast-math \ $(ARCH) diff --git a/examples/gputest/Makefile b/examples/gputest/Makefile index f5aeabf..61e2ca4 100644 --- a/examples/gputest/Makefile +++ b/examples/gputest/Makefile @@ -46,7 +46,7 @@ CFLAGS += $(INCLUDE) -DARM11 -D_3DS CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions -std=gnu++11 ASFLAGS := -g $(ARCH) -LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) +LDFLAGS = -specs=3dsx.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) -Wl,--gc-sections LIBS := -lcitro3d -lctru -lm diff --git a/source/base.c b/source/base.c index abc24cc..e6fb7f4 100644 --- a/source/base.c +++ b/source/base.c @@ -2,25 +2,6 @@ C3D_Context __C3D_Context; -u32 C3Di_Float24(float f) -{ - if (!f) return 0; - union { float t; u32 v; } u; - u.t = f; - u32 s = u.v >> 31; - u32 exp = ((u.v >> 23) & 0xFF) - 0x40; - u32 man = (u.v >> 7) & 0xFFFF; - - return (exp >= 0) ? (man | (exp << 16) | (s << 23)) : (s << 23); -} - -u32 C3Di_FloatInv24(u32 val) -{ - // Too lazy to copy & paste & cleanup the libctru function - extern u32 computeInvValue(u32 val); - return computeInvValue(val); -} - static void C3Di_SetTex(GPU_TEXUNIT unit, C3D_Tex* tex) { u32 reg[4]; @@ -86,7 +67,6 @@ bool C3D_Init(size_t cmdBufSize) ctx->cmdBuf = linearAlloc(cmdBufSize); if (!ctx->cmdBuf) return false; - GPU_Reset(NULL, ctx->cmdBuf, ctx->cmdBufSize); GPUCMD_SetBuffer(ctx->cmdBuf, ctx->cmdBufSize, 0); ctx->flags = C3DiF_Active | C3DiF_TexEnvAll | C3DiF_Effect | C3DiF_TexAll; @@ -116,10 +96,10 @@ void C3D_SetViewport(u32 x, u32 y, u32 w, u32 h) { C3D_Context* ctx = C3Di_GetContext(); ctx->flags |= C3DiF_Viewport | C3DiF_Scissor; - ctx->viewport[0] = C3Di_Float24((float)w/2); - ctx->viewport[1] = C3Di_FloatInv24(w); - ctx->viewport[2] = C3Di_Float24((float)h/2); - ctx->viewport[3] = C3Di_FloatInv24(h); + ctx->viewport[0] = f32tof24(w / 2.0f); + ctx->viewport[1] = f32tof31(2.0f / w) << 1; + ctx->viewport[2] = f32tof24(h / 2.0f); + ctx->viewport[3] = f32tof31(2.0f / h) << 1; ctx->viewport[4] = (y << 16) | (x & 0xFFFF); ctx->scissor[0] = GPU_SCISSOR_DISABLE; } @@ -199,7 +179,8 @@ void C3Di_UpdateContext(void) } ctx->flags &= ~C3DiF_TexAll; - GPU_SetTextureEnable(units); + GPUCMD_AddMaskedWrite(GPUREG_006F, 0x2, units<<8); // enables texcoord outputs + GPUCMD_AddWrite(GPUREG_TEXUNITS_CONFIG, 0x00011000|units); // enables texture units } if (ctx->flags & C3DiF_TexEnvAll) @@ -226,11 +207,13 @@ void C3D_FlushAsync(void) if (ctx->flags & C3DiF_NeedFinishDrawing) { ctx->flags &= ~C3DiF_NeedFinishDrawing; - GPU_FinishDrawing(); + GPUCMD_AddWrite(GPUREG_0111, 0x00000001); + GPUCMD_AddWrite(GPUREG_0110, 0x00000001); + GPUCMD_AddWrite(GPUREG_0063, 0x00000001); } GPUCMD_Finalize(); - GPUCMD_FlushAndRun(NULL); + GPUCMD_FlushAndRun(); GPUCMD_SetBuffer(ctx->cmdBuf, ctx->cmdBufSize, 0); } diff --git a/source/context.h b/source/context.h index 7d33630..9bb72d4 100644 --- a/source/context.h +++ b/source/context.h @@ -65,8 +65,6 @@ static inline C3D_Context* C3Di_GetContext(void) return &__C3D_Context; } -u32 C3Di_Float24(float f); -u32 C3Di_FloatInv24(u32 val); void C3Di_UpdateContext(void); void C3Di_IBOBind(C3D_IBO* ibo); void C3Di_AttrInfoBind(C3D_AttrInfo* info); diff --git a/source/effect.c b/source/effect.c index 3bb09ef..78463cc 100644 --- a/source/effect.c +++ b/source/effect.c @@ -10,8 +10,8 @@ static inline C3D_Effect* getEffect() void C3D_DepthMap(float zScale, float zOffset) { C3D_Effect* e = getEffect(); - e->zScale = C3Di_Float24(zScale); - e->zOffset = C3Di_Float24(zOffset); + e->zScale = f32tof24(zScale); + e->zOffset = f32tof24(zOffset); } void C3D_CullFace(GPU_CULLMODE mode) diff --git a/source/ibo.c b/source/ibo.c index 593c5bd..761e1bc 100644 --- a/source/ibo.c +++ b/source/ibo.c @@ -27,7 +27,7 @@ bool C3D_IBOAddData(C3D_IBO* ibo, const void* data, int indexCount) void C3D_IBOFlush(C3D_IBO* ibo) { int stride = ibo->format+1; - GSPGPU_FlushDataCache(NULL, ibo->data, ibo->indexCount*stride); + GSPGPU_FlushDataCache(ibo->data, ibo->indexCount*stride); } void C3Di_IBOBind(C3D_IBO* ibo) diff --git a/source/renderbuffer.c b/source/renderbuffer.c index 3f2375e..8b5b15a 100644 --- a/source/renderbuffer.c +++ b/source/renderbuffer.c @@ -41,15 +41,15 @@ void C3D_RenderBufClearAsync(C3D_RenderBuf* rb) { u32 colorBufSize = calcColorBufSize(rb->width, rb->height, rb->colorFmt); u32 depthBufSize = calcDepthBufSize(rb->width, rb->height, rb->depthFmt); - GX_SetMemoryFill(NULL, + GX_SetMemoryFill( (u32*)rb->colorBuf, rb->clearColor, (u32*)((u8*)rb->colorBuf+colorBufSize), BIT(0) | ((u32)colorFmtSizes[rb->colorFmt] << 8), - (u32*)rb->depthBuf, rb->clearDepth, (u32*)((u8*)rb->depthBuf+depthBufSize), BIT(0) | ((u32)colorFmtSizes[rb->depthFmt] << 8)); + (u32*)rb->depthBuf, rb->clearDepth, (u32*)((u8*)rb->depthBuf+depthBufSize), BIT(0) | ((u32)depthFmtSizes[rb->depthFmt] << 8)); } void C3D_RenderBufTransferAsync(C3D_RenderBuf* rb, u32* frameBuf, u32 flags) { u32 dim = GX_BUFFER_DIM((u32)rb->width, (u32)rb->height); - GX_SetDisplayTransfer(NULL, (u32*)rb->colorBuf, dim, frameBuf, dim, flags); + GX_SetDisplayTransfer((u32*)rb->colorBuf, dim, frameBuf, dim, flags); } void C3D_RenderBufBind(C3D_RenderBuf* rb) diff --git a/source/texture.c b/source/texture.c index 348cd9a..b25afae 100644 --- a/source/texture.c +++ b/source/texture.c @@ -69,7 +69,7 @@ void C3D_TexBind(int unitId, C3D_Tex* tex) void C3D_TexFlush(C3D_Tex* tex) { if (tex->data) - GSPGPU_FlushDataCache(NULL, tex->data, tex->size); + GSPGPU_FlushDataCache(tex->data, tex->size); } void C3D_TexDelete(C3D_Tex* tex) diff --git a/source/uniforms.c b/source/uniforms.c index d0c3101..825938f 100644 --- a/source/uniforms.c +++ b/source/uniforms.c @@ -36,7 +36,8 @@ void C3D_UpdateUniforms(GPU_SHADER_TYPE type) */ // Upload the uniforms - GPU_SetFloatUniform(type, i, (u32*)&C3D_FVUnif[i], j-i); + GPUCMD_AddWrite(GPUREG_VSH_FLOATUNIFORM_CONFIG+offset, 0x80000000|i); + GPUCMD_AddWrites(GPUREG_VSH_FLOATUNIFORM_DATA+offset, (u32*)&C3D_FVUnif[i], (j-i)*4); // Clear the dirty flag int k; diff --git a/source/vbo.c b/source/vbo.c index d2affa2..717a655 100644 --- a/source/vbo.c +++ b/source/vbo.c @@ -27,7 +27,7 @@ bool C3D_VBOAddData(C3D_VBO* vbo, const void* data, size_t size, int vertexCount void C3D_VBOFlush(C3D_VBO* vbo) { if (vbo->data) - GSPGPU_FlushDataCache(NULL, vbo->data, vbo->size); + GSPGPU_FlushDataCache(vbo->data, vbo->size); } void C3D_VBOBind(C3D_VBO* vbo)