From 66b6dfd0a5618a4cd11f1c05dca26fbaecef9882 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Thu, 22 Sep 2022 20:21:44 -0700 Subject: [PATCH] softgpu: Fix self-render detect in Ridge Racer. When we flush we mark all pending writes zero, but we rely on this being set to detect self-render. TRANSFORM_ALL was wrong as well, sometimes clearing BINNER_RANGE. --- GPU/Software/BinManager.cpp | 23 +++++++++++++++++------ GPU/Software/BinManager.h | 1 + GPU/Software/SoftGpu.h | 10 +++++----- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/GPU/Software/BinManager.cpp b/GPU/Software/BinManager.cpp index 42eef12eda40..fa7c78f21ea6 100644 --- a/GPU/Software/BinManager.cpp +++ b/GPU/Software/BinManager.cpp @@ -197,16 +197,16 @@ void BinManager::UpdateState(bool throughMode) { Flush("tex"); // Okay, now update what's pending. - constexpr uint32_t mirrorMask = 0x0FFFFFFF & ~0x00600000; - const uint32_t bpp = state.pixelID.FBFormat() == GE_FORMAT_8888 ? 4 : 2; - pendingWrites_[0].Expand(gstate.getFrameBufAddress() & mirrorMask, bpp, gstate.FrameBufStride(), scissorTL, scissorBR); - if (state.pixelID.depthWrite) - pendingWrites_[1].Expand(gstate.getDepthBufAddress() & mirrorMask, 2, gstate.DepthBufStride(), scissorTL, scissorBR); + MarkPendingWrites(state); ClearDirty(SoftDirty::BINNER_RANGE); } else if (pendingOverlap_) { - if (HasTextureWrite(state)) + if (HasTextureWrite(state)) { Flush("tex"); + + // We need the pending writes set, which flushing cleared. Set them again. + MarkPendingWrites(state); + } } if (HasDirty(SoftDirty::BINNER_OVERLAP)) { @@ -282,6 +282,17 @@ void BinManager::MarkPendingReads(const Rasterizer::RasterizerState &state) { } } +void BinManager::MarkPendingWrites(const Rasterizer::RasterizerState &state) { + DrawingCoords scissorTL(gstate.getScissorX1(), gstate.getScissorY1()); + DrawingCoords scissorBR(std::min(gstate.getScissorX2(), gstate.getRegionX2()), std::min(gstate.getScissorY2(), gstate.getRegionY2())); + + constexpr uint32_t mirrorMask = 0x0FFFFFFF & ~0x00600000; + const uint32_t bpp = state.pixelID.FBFormat() == GE_FORMAT_8888 ? 4 : 2; + pendingWrites_[0].Expand(gstate.getFrameBufAddress() & mirrorMask, bpp, gstate.FrameBufStride(), scissorTL, scissorBR); + if (state.pixelID.depthWrite) + pendingWrites_[1].Expand(gstate.getDepthBufAddress() & mirrorMask, 2, gstate.DepthBufStride(), scissorTL, scissorBR); +} + inline void BinDirtyRange::Expand(uint32_t newBase, uint32_t bpp, uint32_t stride, DrawingCoords &tl, DrawingCoords &br) { const uint32_t w = br.x - tl.x + 1; const uint32_t h = br.y - tl.y + 1; diff --git a/GPU/Software/BinManager.h b/GPU/Software/BinManager.h index 79146eae1df0..e74f6faac2a6 100644 --- a/GPU/Software/BinManager.h +++ b/GPU/Software/BinManager.h @@ -267,6 +267,7 @@ class BinManager { int mostThreads_ = 0; void MarkPendingReads(const Rasterizer::RasterizerState &state); + void MarkPendingWrites(const Rasterizer::RasterizerState &state); bool HasTextureWrite(const Rasterizer::RasterizerState &state); BinCoords Scissor(BinCoords range); BinCoords Range(const VertexData &v0, const VertexData &v1, const VertexData &v2); diff --git a/GPU/Software/SoftGpu.h b/GPU/Software/SoftGpu.h index 18fa23118ddc..9944f2b78952 100644 --- a/GPU/Software/SoftGpu.h +++ b/GPU/Software/SoftGpu.h @@ -64,17 +64,17 @@ enum class SoftDirty : uint64_t { PIXEL_DITHER = 1ULL << 3, PIXEL_WRITEMASK = 1ULL << 4, PIXEL_CACHED = 1ULL << 5, - PIXEL_ALL = 63ULL << 0, + PIXEL_ALL = 0b111111ULL << 0, SAMPLER_BASIC = 1ULL << 6, SAMPLER_TEXLIST = 1ULL << 7, SAMPLER_CLUT = 1ULL << 8, - SAMPLER_ALL = 7ULL << 6, + SAMPLER_ALL = 0b111ULL << 6, RAST_BASIC = 1ULL << 9, RAST_TEX = 1ULL << 10, RAST_OFFSET = 1ULL << 11, - RAST_ALL = 7ULL << 9, + RAST_ALL = 0b111ULL << 9, LIGHT_BASIC = 1ULL << 12, LIGHT_MATERIAL = 1ULL << 13, @@ -82,13 +82,13 @@ enum class SoftDirty : uint64_t { LIGHT_1 = 1ULL << 15, LIGHT_2 = 1ULL << 16, LIGHT_3 = 1ULL << 17, - LIGHT_ALL = 63ULL << 12, + LIGHT_ALL = 0b111111ULL << 12, TRANSFORM_BASIC = 1ULL << 18, TRANSFORM_MATRIX = 1ULL << 19, TRANSFORM_VIEWPORT = 1ULL << 20, TRANSFORM_FOG = 1ULL << 21, - TRANSFORM_ALL = 31ULL << 18, + TRANSFORM_ALL = 0b1111ULL << 18, BINNER_RANGE = 1ULL << 22, BINNER_OVERLAP = 1ULL << 23,