From 237f469baa3f8d33b5dfedd333f06ba0e53f7f73 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Thu, 21 May 2020 12:04:53 +1000 Subject: [PATCH] GPU: Mask variable sprite/rectangle sizes Fixes broken sprites in Gradius Deluxe Pack (Gradius II). --- src/core/gpu_hw.cpp | 17 +++++++++-------- src/core/gpu_sw.cpp | 13 +++++++++++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp index 7ca2fb3ae..7417dc20e 100644 --- a/src/core/gpu_hw.cpp +++ b/src/core/gpu_hw.cpp @@ -304,18 +304,19 @@ void GPU_HW::LoadVertices() default: { const u32 width_and_height = m_fifo.Pop(); - rectangle_width = static_cast(width_and_height & 0xFFFF); - rectangle_height = static_cast(width_and_height >> 16); + rectangle_width = static_cast(width_and_height & VRAM_WIDTH_MASK); + rectangle_height = static_cast((width_and_height >> 16) & VRAM_HEIGHT_MASK); + + if (rectangle_width >= MAX_PRIMITIVE_WIDTH || rectangle_height >= MAX_PRIMITIVE_HEIGHT) + { + Log_DebugPrintf("Culling too-large rectangle: %d,%d %dx%d", pos_x, pos_y, rectangle_width, + rectangle_height); + return; + } } break; } - if (rectangle_width >= MAX_PRIMITIVE_WIDTH || rectangle_height >= MAX_PRIMITIVE_HEIGHT) - { - Log_DebugPrintf("Culling too-large rectangle: %d,%d %dx%d", pos_x, pos_y, rectangle_width, rectangle_height); - return; - } - // we can split the rectangle up into potentially 8 quads DebugAssert(GetBatchVertexSpace() >= MAX_VERTICES_FOR_RECTANGLE); diff --git a/src/core/gpu_sw.cpp b/src/core/gpu_sw.cpp index e8f3359d7..de7a50640 100644 --- a/src/core/gpu_sw.cpp +++ b/src/core/gpu_sw.cpp @@ -1,8 +1,10 @@ #include "gpu_sw.h" #include "common/assert.h" +#include "common/log.h" #include "host_display.h" #include "system.h" #include +Log_SetChannel(GPU_SW); GPU_SW::GPU_SW() { @@ -277,8 +279,15 @@ void GPU_SW::DispatchRenderCommand() default: { const u32 width_and_height = m_fifo.Pop(); - width = static_cast(width_and_height & UINT32_C(0xFFFF)); - height = static_cast(width_and_height >> 16); + width = static_cast(width_and_height & VRAM_WIDTH_MASK); + height = static_cast((width_and_height >> 16) & VRAM_HEIGHT_MASK); + + if (width >= MAX_PRIMITIVE_WIDTH || height >= MAX_PRIMITIVE_HEIGHT) + { + Log_DebugPrintf("Culling too-large rectangle: %d,%d %dx%d", vp.x.GetValue(), vp.y.GetValue(), width, + height); + return; + } } break; }