diff --git a/GPU/Software/Rasterizer.cpp b/GPU/Software/Rasterizer.cpp index 9f46945fac..2a4df59987 100644 --- a/GPU/Software/Rasterizer.cpp +++ b/GPU/Software/Rasterizer.cpp @@ -208,19 +208,6 @@ static inline void SetPixelDepth(int x, int y, int stride, u16 value) { depthbuf.Set16(x, y, stride, value); } -static inline u8 GetPixelStencil(GEBufferFormat fmt, int fbStride, int x, int y) { - if (fmt == GE_FORMAT_565) { - // Always treated as 0 for comparison purposes. - return 0; - } else if (fmt == GE_FORMAT_5551) { - return ((fb.Get16(x, y, fbStride) & 0x8000) != 0) ? 0xFF : 0; - } else if (fmt == GE_FORMAT_4444) { - return Convert4To8(fb.Get16(x, y, fbStride) >> 12); - } else { - return fb.Get32(x, y, fbStride) >> 24; - } -} - static inline bool IsRightSideOrFlatBottomLine(const Vec2& vertex, const Vec2& line1, const Vec2& line2) { if (line1.y == line2.y) { @@ -1247,21 +1234,6 @@ void DrawLine(const VertexData &v0, const VertexData &v1, const BinCoords &range } } -bool GetCurrentStencilbuffer(GPUDebugBuffer &buffer) { - int w = gstate.getRegionX2() + 1; - int h = gstate.getRegionY2() + 1; - buffer.Allocate(w, h, GPU_DBG_FORMAT_8BIT); - - u8 *row = buffer.GetData(); - for (int y = 0; y < w; ++y) { - for (int x = 0; x < h; ++x) { - row[x] = GetPixelStencil(gstate.FrameBufFormat(), gstate.FrameBufStride(), x, y); - } - row += w; - } - return true; -} - bool GetCurrentTexture(GPUDebugBuffer &buffer, int level) { if (!gstate.isTextureMapEnabled()) { diff --git a/GPU/Software/Rasterizer.h b/GPU/Software/Rasterizer.h index 0e6d289163..e160e199f2 100644 --- a/GPU/Software/Rasterizer.h +++ b/GPU/Software/Rasterizer.h @@ -75,7 +75,6 @@ void DrawPoint(const VertexData &v0, const BinCoords &range, const RasterizerSta void DrawLine(const VertexData &v0, const VertexData &v1, const BinCoords &range, const RasterizerState &state); void ClearRectangle(const VertexData &v0, const VertexData &v1, const BinCoords &range, const RasterizerState &state); -bool GetCurrentStencilbuffer(GPUDebugBuffer &buffer); bool GetCurrentTexture(GPUDebugBuffer &buffer, int level); // Shared functions with RasterizerRectangle.cpp diff --git a/GPU/Software/SoftGpu.cpp b/GPU/Software/SoftGpu.cpp index dcba967393..3e22b7b7f0 100644 --- a/GPU/Software/SoftGpu.cpp +++ b/GPU/Software/SoftGpu.cpp @@ -1167,26 +1167,38 @@ bool SoftGPU::FramebufferReallyDirty() { return true; } +static DrawingCoords GetTargetSize(int stride) { + int w = std::min(stride, std::max(gstate.getRegionX2(), gstate.getScissorX2()) + 1); + int h = std::max(gstate.getRegionY2(), gstate.getScissorY2()) + 1; + if (gstate.getRegionX2() == 1023 && gstate.getRegionY2() == 1023) { + // Some games max out region, but always scissor to an appropriate size. + // Both values always scissor, we just prefer region as it's usually a more stable size. + w = std::max(stride, gstate.getScissorX2() + 1); + h = std::max(272, gstate.getScissorY2() + 1); + } + + return DrawingCoords((s16)w, (s16)h); +} + bool SoftGPU::GetCurrentFramebuffer(GPUDebugBuffer &buffer, GPUDebugFramebufferType type, int maxRes) { - int w = gstate.getRegionX2() + 1; - int h = gstate.getRegionY2() + 1; int stride = gstate.FrameBufStride(); + DrawingCoords size = GetTargetSize(stride); GEBufferFormat fmt = gstate.FrameBufFormat(); if (type == GPU_DBG_FRAMEBUF_DISPLAY) { - w = 480; - h = 272; + size.x = 480; + size.y = 272; stride = displayStride_; fmt = displayFormat_; } - buffer.Allocate(w, h, fmt); + buffer.Allocate(size.x, size.y, fmt); const int depth = fmt == GE_FORMAT_8888 ? 4 : 2; const u8 *src = fb.data; u8 *dst = buffer.GetData(); - const int byteWidth = w * depth; - for (int y = 0; y < h; ++y) { + const int byteWidth = size.x * depth; + for (int16_t y = 0; y < size.y; ++y) { memcpy(dst, src, byteWidth); dst += byteWidth; src += stride * depth; @@ -1199,24 +1211,45 @@ bool SoftGPU::GetOutputFramebuffer(GPUDebugBuffer &buffer) { } bool SoftGPU::GetCurrentDepthbuffer(GPUDebugBuffer &buffer) { - const int w = gstate.getRegionX2() + 1; - const int h = gstate.getRegionY2() + 1; - buffer.Allocate(w, h, GPU_DBG_FORMAT_16BIT); + DrawingCoords size = GetTargetSize(gstate.DepthBufStride()); + buffer.Allocate(size.x, size.y, GPU_DBG_FORMAT_16BIT); const int depth = 2; const u8 *src = depthbuf.data; u8 *dst = buffer.GetData(); - for (int y = 0; y < h; ++y) { - memcpy(dst, src, w * depth); - dst += w * depth; + for (int16_t y = 0; y < size.y; ++y) { + memcpy(dst, src, size.x * depth); + dst += size.x * depth; src += gstate.DepthBufStride() * depth; } return true; } -bool SoftGPU::GetCurrentStencilbuffer(GPUDebugBuffer &buffer) -{ - return Rasterizer::GetCurrentStencilbuffer(buffer); +static inline u8 GetPixelStencil(GEBufferFormat fmt, int fbStride, int x, int y) { + if (fmt == GE_FORMAT_565) { + // Always treated as 0 for comparison purposes. + return 0; + } else if (fmt == GE_FORMAT_5551) { + return ((fb.Get16(x, y, fbStride) & 0x8000) != 0) ? 0xFF : 0; + } else if (fmt == GE_FORMAT_4444) { + return Convert4To8(fb.Get16(x, y, fbStride) >> 12); + } else { + return fb.Get32(x, y, fbStride) >> 24; + } +} + +bool SoftGPU::GetCurrentStencilbuffer(GPUDebugBuffer &buffer) { + DrawingCoords size = GetTargetSize(gstate.FrameBufStride()); + buffer.Allocate(size.x, size.y, GPU_DBG_FORMAT_8BIT); + + u8 *row = buffer.GetData(); + for (int16_t y = 0; y < size.x; ++y) { + for (int16_t x = 0; x < size.y; ++x) { + row[x] = GetPixelStencil(gstate.FrameBufFormat(), gstate.FrameBufStride(), x, y); + } + row += size.x; + } + return true; } bool SoftGPU::GetCurrentTexture(GPUDebugBuffer &buffer, int level)