From aab318b4f7d60d762f49ae1ac6909baf4fe4d059 Mon Sep 17 00:00:00 2001 From: Sergey Lipskiy Date: Wed, 17 Oct 2018 19:29:00 +0700 Subject: [PATCH] Fix tile load for BG commands. --- src/Textures.cpp | 9 +++++++++ src/gDP.cpp | 31 ++++++++++++++++++++++++++++--- src/gDP.h | 2 ++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/Textures.cpp b/src/Textures.cpp index d14e25f3..0d233154 100644 --- a/src/Textures.cpp +++ b/src/Textures.cpp @@ -614,6 +614,15 @@ void _calcTileSizes(u32 _t, TileSizes & _sizes, gDPTile * _pLoadTile) const u32 tMemMask = gDP.otherMode.textureLUT == G_TT_NONE ? 0x1FF : 0xFF; gDPLoadTileInfo &info = gDP.loadInfo[pTile->tmem & tMemMask]; + if (pTile->tmem == gDP.loadTile->tmem) { + if (gDP.loadTile->loadWidth != 0 && gDP.loadTile->masks == 0) + info.width = gDP.loadTile->loadWidth; + if (gDP.loadTile->loadHeight != 0 && gDP.loadTile->maskt == 0) { + info.height = gDP.loadTile->loadHeight; + info.bytes = info.height * (gDP.loadTile->line << 3); + } + gDP.loadTile->loadWidth = gDP.loadTile->loadHeight = 0; + } _sizes.bytes = info.bytes; if (info.loadType == LOADTYPE_TILE) { if (pTile->masks && ((maskWidth * maskHeight) <= maxTexels)) diff --git a/src/gDP.cpp b/src/gDP.cpp index db4ec5ef..f8e98f8a 100644 --- a/src/gDP.cpp +++ b/src/gDP.cpp @@ -440,6 +440,23 @@ void gDPLoadTile(u32 tile, u32 uls, u32 ult, u32 lrs, u32 lrt) const u32 height = (gDP.loadTile->lrt - gDP.loadTile->ult + 1) & 0x03FF; const u32 bpl = gDP.loadTile->line << 3; + u32 alignedWidth = width; + u32 wmask = 0; + switch (gDP.textureImage.size) { + case G_IM_SIZ_8b: + wmask = 7; + break; + case G_IM_SIZ_16b: + wmask = 3; + break; + case G_IM_SIZ_32b: + wmask = 1; + break; + } + if ((width & wmask) != 0) + alignedWidth = (width & (~wmask)) + wmask + 1; + const u32 bpr = alignedWidth << gDP.loadTile->size >> 1; + gDPLoadTileInfo &info = gDP.loadInfo[gDP.loadTile->tmem]; info.texAddress = gDP.loadTile->imageAddress; info.uls = gDP.loadTile->uls; @@ -447,7 +464,7 @@ void gDPLoadTile(u32 tile, u32 uls, u32 ult, u32 lrs, u32 lrt) info.lrs = gDP.loadTile->lrs; info.lrt = gDP.loadTile->lrt; info.width = gDP.loadTile->masks != 0 ? (u16)min(width, 1U << gDP.loadTile->masks) : (u16)width; - info.height = gDP.loadTile->maskt != 0 ? (u16)min(height, 1U<maskt) : (u16)height; + info.height = gDP.loadTile->maskt != 0 ? (u16)min(height, 1U << gDP.loadTile->maskt) : (u16)height; info.texWidth = gDP.textureImage.width; info.size = gDP.textureImage.size; info.loadType = LOADTYPE_TILE; @@ -459,6 +476,13 @@ void gDPLoadTile(u32 tile, u32 uls, u32 ult, u32 lrs, u32 lrt) if (gDP.loadTile->line == 0) return; + if (gDP.loadTile->masks == 0) + gDP.loadTile->loadWidth = max(gDP.loadTile->loadWidth, info.width); + if (gDP.loadTile->maskt == 0 && gDP.loadTile->tmem % gDP.loadTile->line == 0) { + const u16 theight = info.height + gDP.loadTile->tmem / gDP.loadTile->line; + gDP.loadTile->loadHeight = max(gDP.loadTile->loadHeight, theight); + } + u32 address = gDP.textureImage.address + gDP.loadTile->ult * gDP.textureImage.bpl + (gDP.loadTile->uls << gDP.textureImage.size >> 1); u32 bpl2 = bpl; if (gDP.loadTile->lrs > gDP.textureImage.width) @@ -475,13 +499,14 @@ void gDPLoadTile(u32 tile, u32 uls, u32 ult, u32 lrs, u32 lrt) else { u32 tmemAddr = gDP.loadTile->tmem; const u32 line = gDP.loadTile->line; + const u32 qwpr = bpr >> 3; for (u32 y = 0; y < height; ++y) { if (address + bpl > RDRAMSize) UnswapCopyWrap(RDRAM, address, (u8*)TMEM, tmemAddr << 3, 0xFFF, RDRAMSize - address); else - UnswapCopyWrap(RDRAM, address, (u8*)TMEM, tmemAddr << 3, 0xFFF, bpl); + UnswapCopyWrap(RDRAM, address, (u8*)TMEM, tmemAddr << 3, 0xFFF, bpr); if (y & 1) - DWordInterleaveWrap((u32*)TMEM, tmemAddr << 1, 0x3FF, line); + DWordInterleaveWrap((u32*)TMEM, tmemAddr << 1, 0x3FF, qwpr); address += gDP.textureImage.bpl; if (address >= RDRAMSize) diff --git a/src/gDP.h b/src/gDP.h index 03348485..f2d843dd 100644 --- a/src/gDP.h +++ b/src/gDP.h @@ -94,6 +94,8 @@ struct gDPTile u32 textureMode; u32 loadType; + u16 loadWidth; + u16 loadHeight; u32 imageAddress; u32 frameBufferAddress; };