From 192dc5b3453a0e88534b3a33763f6fcf9708fc0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 1 Oct 2026 12:56:20 -0600 Subject: [PATCH] SoftGPU: Fix black screenshots with the DarkStalkers present hack The hack skips the game's stretch blit, so the display framebuffer stays black and savestate thumbnails and screenshots came out empty. Do the stretch from the source image when reading back the display framebuffer. AGENTS.md: Commit finished work without asking, push only when asked Co-Authored-By: Claude Opus 5.5 (1M context) --- AGENTS.md | 4 ++- GPU/Software/SoftGpu.cpp | 58 ++++++++++++++++++++++++++++++++++++++-- GPU/Software/SoftGpu.h | 2 ++ 3 files changed, 61 insertions(+), 3 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index e686ac305e..e2b0565c71 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -35,7 +35,9 @@ for it: 1. Keep style changes minimal unless requested. Follow existing code patterns and conventions. 2. Keep cross-platform parity in mind when changing shared code. See below for more multiplatform tips -3. Never `git push` (to any remote) without asking the user first. Committing locally is fine when asked; pushing requires explicit approval. +3. **Commit freely, push only when asked.** Once a change is done and tested, commit it on its + branch without waiting to be told. Never `git push` (to any remote) without the user's explicit + approval. 4. **Don't write code on `master`.** When asked to make a code change while on `master`, create an appropriately named branch first (`git checkout -b some-descriptive-name`) and do the work there. If you're already on a topic branch, just keep working on it. diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index 4b597d3409..2921d01104 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -495,6 +495,55 @@ void SoftGPU::SetDisplayFramebuffer(u32 framebuf, u32 stride, GEBufferFormat for DSStretch g_DarkStalkerStretch; +// With the DarkStalkers hack, the game's stretch blit is skipped and we present its 384x224 source image directly. +static const u32 DS_SOURCE_ADDR = 0x04088000; + +bool SoftGPU::DarkStalkersStretchActive() const { + return PSP_CoreParameter().compat.flags().DarkStalkersPresentHack && displayFormat_ == GE_FORMAT_5551 && g_DarkStalkerStretch != DSStretch::Off; +} + +// Does the stretch blit we skipped, so screenshots see what the game would have displayed. +void SoftGPU::GetDarkStalkersDisplay(GPUDebugBuffer &buffer) { + const u16 *src = (const u16 *)Memory::GetPointerOrException(DS_SOURCE_ADDR); + const int srcStride = displayStride_ == 0 ? 512 : displayStride_; + const int srcX = 64, srcY = 16, srcW = 384, srcH = 224; + // Same rectangles as the game's own blits (see RectangleFastPath). + const int dstX = g_DarkStalkerStretch == DSStretch::Normal ? 48 : 0; + const int dstW = g_DarkStalkerStretch == DSStretch::Normal ? 384 : 480; + + buffer.Allocate(480, 272, GE_FORMAT_8888); + u32 *dst = (u32 *)buffer.GetData(); + for (int y = 0; y < 272; ++y) { + float sy = std::clamp((y + 0.5f) * srcH / 272.0f - 0.5f, 0.0f, (float)(srcH - 1)); + int y0 = (int)sy; + int y1 = std::min(y0 + 1, srcH - 1); + float fy = sy - y0; + const u16 *row0 = src + (srcY + y0) * srcStride + srcX; + const u16 *row1 = src + (srcY + y1) * srcStride + srcX; + for (int x = 0; x < 480; ++x) { + if (x < dstX || x >= dstX + dstW) { + dst[y * 480 + x] = 0xFF000000; + continue; + } + float sx = std::clamp((x - dstX + 0.5f) * srcW / dstW - 0.5f, 0.0f, (float)(srcW - 1)); + int x0 = (int)sx; + int x1 = std::min(x0 + 1, srcW - 1); + float fx = sx - x0; + const u32 c00 = RGBA5551ToRGBA8888(row0[x0]); + const u32 c01 = RGBA5551ToRGBA8888(row0[x1]); + const u32 c10 = RGBA5551ToRGBA8888(row1[x0]); + const u32 c11 = RGBA5551ToRGBA8888(row1[x1]); + u32 result = 0xFF000000; + for (int shift = 0; shift < 24; shift += 8) { + float top = ((c00 >> shift) & 0xFF) * (1.0f - fx) + ((c01 >> shift) & 0xFF) * fx; + float bottom = ((c10 >> shift) & 0xFF) * (1.0f - fx) + ((c11 >> shift) & 0xFF) * fx; + result |= (u32)(top * (1.0f - fy) + bottom * fy + 0.5f) << shift; + } + dst[y * 480 + x] = result; + } + } +} + void SoftGPU::ConvertTextureDescFrom16(Draw::TextureDesc &desc, int srcwidth, int srcheight, const uint16_t *overrideData) { // TODO: This should probably be converted in a shader instead.. fbTexBuffer_.resize(srcwidth * srcheight); @@ -563,8 +612,8 @@ void SoftGPU::CopyToCurrentFboFromDisplayRam(const DisplayLayoutConfig &config, OutputFlags outputFlags = config.iDisplayFilter == SCALE_NEAREST ? OutputFlags::NEAREST : OutputFlags::LINEAR; bool hasPostShader = presentation_ && presentation_->HasPostShader(); - if (PSP_CoreParameter().compat.flags().DarkStalkersPresentHack && displayFormat_ == GE_FORMAT_5551 && g_DarkStalkerStretch != DSStretch::Off) { - const u8 *data = Memory::GetPointerWriteOrException(0x04088000); + if (DarkStalkersStretchActive()) { + const u8 *data = Memory::GetPointerWriteOrException(DS_SOURCE_ADDR); bool fillDesc = true; if (draw_->GetDataFormatSupport(Draw::DataFormat::A1B5G5R5_UNORM_PACK16) & Draw::FMT_TEXTURE) { // The perfect one. @@ -1364,6 +1413,11 @@ bool SoftGPU::GetCurrentFramebuffer(GPUDebugBuffer &buffer, GPUDebugFramebufferT if (!Memory::IsValidAddress(displayFramebuf_)) return false; + if (type == GPU_DBG_FRAMEBUF_DISPLAY && DarkStalkersStretchActive()) { + GetDarkStalkersDisplay(buffer); + return true; + } + if (type == GPU_DBG_FRAMEBUF_DISPLAY) { size.x = 480; size.y = 272; diff --git a/GPU/Software/SoftGpu.h b/GPU/Software/SoftGpu.h index 367c0023a3..b236542390 100644 --- a/GPU/Software/SoftGpu.h +++ b/GPU/Software/SoftGpu.h @@ -214,6 +214,8 @@ protected: void FastRunLoop(DisplayList &list) override; void CopyToCurrentFboFromDisplayRam(const DisplayLayoutConfig &config, int srcwidth, int srcheight); void ConvertTextureDescFrom16(Draw::TextureDesc &desc, int srcwidth, int srcheight, const uint16_t *overrideData = nullptr); + bool DarkStalkersStretchActive() const; + void GetDarkStalkersDisplay(GPUDebugBuffer &buffer); void BuildReportingInfo() override {}