From 4d4523dc04c7c1007eb5c08aa5e129b92f00f2c2 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Mon, 30 Dec 2024 16:45:59 +1000 Subject: [PATCH] GPU: Use same early culling rules for lines as polygons --- src/core/gpu.cpp | 2 +- src/core/gpu.h | 7 ++++++- src/core/gpu_commands.cpp | 33 +++++++++++++-------------------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/core/gpu.cpp b/src/core/gpu.cpp index e8a1f7794..356bc099a 100644 --- a/src/core/gpu.cpp +++ b/src/core/gpu.cpp @@ -462,7 +462,7 @@ void GPU::UpdateDMARequest() case BlitterState::ReadingVRAM: m_GPUSTAT.ready_to_send_vram = true; - m_GPUSTAT.ready_to_recieve_dma = m_fifo.IsEmpty(); + m_GPUSTAT.ready_to_recieve_dma = false; break; case BlitterState::DrawingPolyLine: diff --git a/src/core/gpu.h b/src/core/gpu.h index d177a4454..595d9012a 100644 --- a/src/core/gpu.h +++ b/src/core/gpu.h @@ -378,7 +378,12 @@ private: ALWAYS_INLINE_RELEASE void AddDrawLineTicks(const GSVector4i rect, bool shaded) { const GSVector4i clamped_rect = rect.rintersect(m_clamped_drawing_area); - u32 drawn_width = clamped_rect.width(); + + // Needed because we're not multiplying either dimension. + if (clamped_rect.rempty()) + return; + + const u32 drawn_width = clamped_rect.width(); u32 drawn_height = clamped_rect.height(); if (m_GPUSTAT.SkipDrawingToActiveField()) diff --git a/src/core/gpu_commands.cpp b/src/core/gpu_commands.cpp index 09a50bbd7..20e8c2aa9 100644 --- a/src/core/gpu_commands.cpp +++ b/src/core/gpu_commands.cpp @@ -724,21 +724,17 @@ bool GPU::HandleRenderLineCommand() cmd->vertices[i].w = 1.0f; } - const GSVector2 v0f = GSVector2::load(&cmd->vertices[0].x); - const GSVector2 v1f = GSVector2::load(&cmd->vertices[1].x); - const GSVector4i rect = - GSVector4i(GSVector4(v0f.min(v1f)).upld(GSVector4(v0f.max(v1f)))).add32(GSVector4i::cxpr(0, 0, 1, 1)); - const GSVector4i clamped_rect = rect.rintersect(m_clamped_drawing_area); - - if (rect.width() > MAX_PRIMITIVE_WIDTH || rect.height() > MAX_PRIMITIVE_HEIGHT || clamped_rect.rempty()) + const GSVector2i v0 = GSVector2i::load(&cmd->vertices[0].native_x); + const GSVector2i v1 = GSVector2i::load(&cmd->vertices[1].native_x); + const GSVector4i rect = GSVector4i::xyxy(v0.min_s32(v1), v0.max_s32(v1)).add32(GSVector4i::cxpr(0, 0, 1, 1)); + if (rect.width() > MAX_PRIMITIVE_WIDTH || rect.height() > MAX_PRIMITIVE_HEIGHT) { - DEBUG_LOG("Culling too-large/off-screen line: {},{} - {},{}", cmd->vertices[0].y, cmd->vertices[0].y, - cmd->vertices[1].x, cmd->vertices[1].y); + DEBUG_LOG("Culling too-large line: {} - {}", v0, v1); EndCommand(); return true; } - AddDrawLineTicks(clamped_rect, rc.shading_enable); + AddDrawLineTicks(rect, rc.shading_enable); GPUBackend::PushCommand(cmd); } else @@ -776,17 +772,14 @@ bool GPU::HandleRenderLineCommand() const GSVector2i v0 = GSVector2i::load(&cmd->vertices[0].x); const GSVector2i v1 = GSVector2i::load(&cmd->vertices[1].x); const GSVector4i rect = GSVector4i::xyxy(v0.min_s32(v1), v0.max_s32(v1)).add32(GSVector4i::cxpr(0, 0, 1, 1)); - const GSVector4i clamped_rect = rect.rintersect(m_clamped_drawing_area); - - if (rect.width() > MAX_PRIMITIVE_WIDTH || rect.height() > MAX_PRIMITIVE_HEIGHT || clamped_rect.rempty()) + if (rect.width() > MAX_PRIMITIVE_WIDTH || rect.height() > MAX_PRIMITIVE_HEIGHT) { - DEBUG_LOG("Culling too-large/off-screen line: {},{} - {},{}", cmd->vertices[0].y, cmd->vertices[0].y, - cmd->vertices[1].x, cmd->vertices[1].y); + DEBUG_LOG("Culling too-large line: {} - {}", v0, v1); EndCommand(); return true; } - AddDrawLineTicks(clamped_rect, rc.shading_enable); + AddDrawLineTicks(rect, rc.shading_enable); GPUBackend::PushCommand(cmd); } @@ -864,13 +857,13 @@ void GPU::FinishPolyline() (shaded ? Truncate32(m_polyline_buffer[buffer_pos++]) : m_render_command.bits) & UINT32_C(0x00FFFFFF); read_vertex(end, color); - const GSVector2 start_pos = GSVector2::load(&start.x); - const GSVector2 end_pos = GSVector2::load(&end.x); + const GSVector2i start_pos = GSVector2i::load(&start.native_x); + const GSVector2i end_pos = GSVector2i::load(&end.native_x); const GSVector4i rect = - GSVector4i(GSVector4::xyxy(start_pos.min(end_pos), start_pos.max(end_pos))).add32(GSVector4i::cxpr(0, 0, 1, 1)); + GSVector4i::xyxy(start_pos.min_s32(end_pos), start_pos.max_s32(end_pos)).add32(GSVector4i::cxpr(0, 0, 1, 1)); if (rect.width() > MAX_PRIMITIVE_WIDTH || rect.height() > MAX_PRIMITIVE_HEIGHT) { - DEBUG_LOG("Culling too-large/off-screen line: {},{} - {},{}", start_pos.x, start_pos.y, end_pos.x, end_pos.y); + DEBUG_LOG("Culling too-large line: {} - {}", start_pos, end_pos); } else {