From 27bc65fc2ada7d5c34ce7d4f8219f0c9dcddcc8f Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 4 Oct 2019 23:21:20 +1000 Subject: [PATCH] GPU: Use BitField sign extending for position --- src/core/gpu.cpp | 4 ++-- src/core/gpu.h | 15 ++------------- src/core/gpu_hw.cpp | 10 +++++----- 3 files changed, 9 insertions(+), 20 deletions(-) diff --git a/src/core/gpu.cpp b/src/core/gpu.cpp index 8f9bf4460..e28614bb8 100644 --- a/src/core/gpu.cpp +++ b/src/core/gpu.cpp @@ -477,8 +477,8 @@ void GPU::WriteGP0(u32 value) case 0xE5: // Set drawing offset { - m_drawing_offset.x = S11ToS32(param & UINT32_C(0x7FF)); - m_drawing_offset.y = S11ToS32((param >> 11) & UINT32_C(0x7FF)); + m_drawing_offset.x = SignExtendN<11, u32>(param & UINT32_C(0x7FF)); + m_drawing_offset.y = SignExtendN<11, u32>((param >> 11) & UINT32_C(0x7FF)); Log_DebugPrintf("Set drawing offset (%d, %d)", m_drawing_offset.x, m_drawing_offset.y); } break; diff --git a/src/core/gpu.h b/src/core/gpu.h index 94288be60..4f10ba848 100644 --- a/src/core/gpu.h +++ b/src/core/gpu.h @@ -61,14 +61,6 @@ public: void Execute(TickCount ticks); protected: - static constexpr s32 S11ToS32(u32 value) - { - if (value & (UINT16_C(1) << 10)) - return static_cast(UINT32_C(0xFFFFF800) | value); - else - return value; - } - // Helper/format conversion functions. static constexpr u32 RGBA5551ToRGBA8888(u16 color) { @@ -164,11 +156,8 @@ protected: { u32 bits; - BitField x_s11; - BitField y_s11; - - s32 x() const { return S11ToS32(x_s11); } - s32 y() const { return S11ToS32(y_s11); } + BitField x; + BitField y; }; struct DebugOptions diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp index 1f8bcb287..6e0310a16 100644 --- a/src/core/gpu_hw.cpp +++ b/src/core/gpu_hw.cpp @@ -41,8 +41,8 @@ void GPU_HW::LoadVertices(RenderCommand rc, u32 num_vertices) hw_vert.color = (shaded && i > 0) ? (m_GP0_command[buffer_pos++] & UINT32_C(0x00FFFFFF)) : first_color; const VertexPosition vp{m_GP0_command[buffer_pos++]}; - hw_vert.x = vp.x(); - hw_vert.y = vp.y(); + hw_vert.x = vp.x; + hw_vert.y = vp.y; hw_vert.texpage = texpage; if (textured) @@ -73,8 +73,8 @@ void GPU_HW::LoadVertices(RenderCommand rc, u32 num_vertices) const bool textured = rc.texture_enable; const u32 color = rc.color_for_first_vertex; const VertexPosition vp{m_GP0_command[buffer_pos++]}; - const s32 pos_left = vp.x(); - const s32 pos_top = vp.y(); + const s32 pos_left = vp.x; + const s32 pos_top = vp.y; const auto [tex_left, tex_top] = HWVertex::DecodeTexcoord(rc.texture_enable ? Truncate16(m_GP0_command[buffer_pos++]) : 0); s32 rectangle_width; @@ -128,7 +128,7 @@ void GPU_HW::LoadVertices(RenderCommand rc, u32 num_vertices) { const u32 color = (shaded && i > 0) ? (m_GP0_command[buffer_pos++] & UINT32_C(0x00FFFFFF)) : first_color; const VertexPosition vp{m_GP0_command[buffer_pos++]}; - m_batch.vertices.push_back(HWVertex{vp.x(), vp.y(), color}); + m_batch.vertices.push_back(HWVertex{vp.x.GetValue(), vp.y.GetValue(), color}); } } break;