From c76d87d900d5732253b014444b240b51c7254a6b Mon Sep 17 00:00:00 2001 From: XProger Date: Wed, 9 Mar 2022 05:07:56 +0300 Subject: [PATCH] #407 32X use 2px texturing, aligned gLightmap address optimization --- src/fixed/common.h | 2 + src/fixed/level.h | 8 +++- src/platform/32x/crt0.s | 3 ++ src/platform/32x/rasterizer.h | 78 ++++++++++++++++++++++++++++++++--- 4 files changed, 83 insertions(+), 8 deletions(-) diff --git a/src/fixed/common.h b/src/fixed/common.h index 6d709a2..3e826d8 100644 --- a/src/fixed/common.h +++ b/src/fixed/common.h @@ -91,6 +91,8 @@ #define USE_DIV_TABLE #define CPU_BIG_ENDIAN #define ROM_READ + #define TEX_2PX + #define ALIGNED_LIGHTMAP #define MODE13 #define FRAME_WIDTH 320 diff --git a/src/fixed/level.h b/src/fixed/level.h index 2f87e3a..0769749 100644 --- a/src/fixed/level.h +++ b/src/fixed/level.h @@ -6,8 +6,12 @@ Level level; -#ifndef MODEHW -IWRAM_DATA uint8 gLightmap[256 * 32]; // IWRAM 8k +#ifdef __32X__ + extern uint8 gLightmap[256 * 32]; // SDRAM 8k at 0x6000000 +#else + #ifndef MODEHW + IWRAM_DATA uint8 gLightmap[256 * 32]; // IWRAM 8k + #endif #endif EWRAM_DATA ItemObj items[MAX_ITEMS]; diff --git a/src/platform/32x/crt0.s b/src/platform/32x/crt0.s index e71422f..206c94d 100644 --- a/src/platform/32x/crt0.s +++ b/src/platform/32x/crt0.s @@ -192,6 +192,9 @@ .incbin "src-md/m68k.bin" /* all 68000 code & data, compiled to 0x880800/0xFF0000 */ .data + .global _gLightmap +_gLightmap: + .space 256 * 32 !----------------------------------------------------------------------- ! Primary Vector Base Table diff --git a/src/platform/32x/rasterizer.h b/src/platform/32x/rasterizer.h index 5d8e3c0..f56e9d0 100644 --- a/src/platform/32x/rasterizer.h +++ b/src/platform/32x/rasterizer.h @@ -340,6 +340,21 @@ extern "C" void rasterizeFT_c(uint16* pixel, const VertexLink* L, const VertexLi } width >>= 1; + + #ifdef TEX_2PX + dtdx <<= 1; + + while (width--) + { + uint8 indexA = ft_lightmap[gTile[(t & 0xFF00) | (t >> 24)]]; + t += dtdx; + + *(uint16*)ptr = indexA | (indexA << 8); + + ptr += 2; + } + #else + width >>= 1; while (width--) { uint8 indexA = ft_lightmap[gTile[(t & 0xFF00) | (t >> 24)]]; @@ -355,6 +370,7 @@ extern "C" void rasterizeFT_c(uint16* pixel, const VertexLink* L, const VertexLi ptr += 2; } + #endif } pixel += VRAM_WIDTH; @@ -445,6 +461,11 @@ extern "C" void rasterizeGT_c(uint16* pixel, const VertexLink* L, const VertexLi Lh -= h; Rh -= h; + #ifdef ALIGNED_LIGHTMAP + Lg |= intptr_t(gLightmap); + Rg |= intptr_t(gLightmap); + #endif + while (h--) { int32 x1 = Lx >> 16; @@ -470,7 +491,13 @@ extern "C" void rasterizeGT_c(uint16* pixel, const VertexLink* L, const VertexLi if (intptr_t(ptr) & 1) { - *ptr++ = gLightmap[(g >> 8 << 8) | gTile[(t & 0xFF00) | (t >> 24)]]; + #ifdef ALIGNED_LIGHTMAP + const uint8* LMAP = (uint8*)(g >> 8 << 8); + uint8 indexA = LMAP[gTile[(t & 0xFF00) | (t >> 24)]]; + #else + uint8 indexA = gLightmap[(g >> 8 << 8) | gTile[(t & 0xFF00) | (t >> 24)]]; + #endif + *ptr++ = indexA; t += dtdx; g += dgdx >> 1; width--; @@ -479,15 +506,34 @@ extern "C" void rasterizeGT_c(uint16* pixel, const VertexLink* L, const VertexLi if (width & 1) { uint32 tmp = Rt - dtdx; - ptr[width - 1] = gLightmap[(Rg >> 8 << 8) | gTile[(tmp & 0xFF00) | (tmp >> 24)]]; + #ifdef ALIGNED_LIGHTMAP + const uint8* LMAP = (uint8*)(Rg >> 8 << 8); + uint8 indexA = LMAP[gTile[(tmp & 0xFF00) | (tmp >> 24)]]; + #else + uint8 indexA = gLightmap[(Rg >> 8 << 8) | gTile[(tmp & 0xFF00) | (tmp >> 24)]]; + #endif + ptr[width - 1] = indexA; } - #ifdef ALIGNED_LIGHTMAP - g += intptr_t(gLightmap); - #endif - width >>= 1; + #ifdef TEX_2PX + dtdx <<= 1; + + while (width--) + { + #ifdef ALIGNED_LIGHTMAP + const uint8* LMAP = (uint8*)(g >> 8 << 8); + uint8 indexA = LMAP[gTile[(t & 0xFF00) | (t >> 24)]]; + #else + uint8 indexA = gLightmap[(g >> 8 << 8) | gTile[(t & 0xFF00) | (t >> 24)]]; + #endif + *(uint16*)ptr = indexA | (indexA << 8); + ptr += 2; + t += dtdx; + g += dgdx; + } + #else while (width--) { #ifdef ALIGNED_LIGHTMAP @@ -514,6 +560,7 @@ extern "C" void rasterizeGT_c(uint16* pixel, const VertexLink* L, const VertexLi ptr += 2; } + #endif } pixel += VRAM_WIDTH; @@ -635,6 +682,24 @@ extern "C" void rasterizeFTA_c(uint16* pixel, const VertexLink* L, const VertexL } width >>= 1; + + #ifdef TEX_2PX + dtdx <<= 1; + + while (width--) + { + uint8 indexA = gTile[(t & 0xFF00) | (t >> 24)]; + t += dtdx; + + if (indexA) + { + indexA = ft_lightmap[indexA]; + *(uint16*)ptr = indexA | (indexA << 8); + } + + ptr += 2; + } + #else while (width--) { uint8 indexA = gTile[(t & 0xFF00) | (t >> 24)]; @@ -662,6 +727,7 @@ extern "C" void rasterizeFTA_c(uint16* pixel, const VertexLink* L, const VertexL ptr += 2; } + #endif } pixel += VRAM_WIDTH;