diff --git a/src/core/gpu.cpp b/src/core/gpu.cpp index 4719bb989..224f65c7a 100644 --- a/src/core/gpu.cpp +++ b/src/core/gpu.cpp @@ -193,12 +193,16 @@ bool GPU::DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_displ sw.Do(&m_GPUSTAT.bits); sw.Do(&m_draw_mode.mode_reg.bits); - sw.Do(&m_draw_mode.palette_reg); + sw.Do(&m_draw_mode.palette_reg.bits); sw.Do(&m_draw_mode.texture_window_value); - sw.Do(&m_draw_mode.texture_page_x); - sw.Do(&m_draw_mode.texture_page_y); - sw.Do(&m_draw_mode.texture_palette_x); - sw.Do(&m_draw_mode.texture_palette_y); + + if (sw.GetVersion() < 62) + { + // texture_page_x, texture_page_y, texture_palette_x, texture_palette_y + DebugAssert(sw.IsReading()); + sw.SkipBytes(sizeof(u32) * 4); + } + sw.Do(&m_draw_mode.texture_window.and_x); sw.Do(&m_draw_mode.texture_window.and_y); sw.Do(&m_draw_mode.texture_window.or_x); @@ -1514,14 +1518,8 @@ void GPU::SetDrawMode(u16 value) if (new_mode_reg.bits == m_draw_mode.mode_reg.bits) return; - if ((new_mode_reg.bits & GPUDrawModeReg::TEXTURE_PAGE_MASK) != - (m_draw_mode.mode_reg.bits & GPUDrawModeReg::TEXTURE_PAGE_MASK)) - { - m_draw_mode.texture_page_x = new_mode_reg.GetTexturePageBaseX(); - m_draw_mode.texture_page_y = new_mode_reg.GetTexturePageBaseY(); - m_draw_mode.texture_page_changed = true; - } - + m_draw_mode.texture_page_changed |= ((new_mode_reg.bits & GPUDrawModeReg::TEXTURE_PAGE_MASK) != + (m_draw_mode.mode_reg.bits & GPUDrawModeReg::TEXTURE_PAGE_MASK)); m_draw_mode.mode_reg.bits = new_mode_reg.bits; if (m_GPUSTAT.draw_to_displayed_field != new_mode_reg.draw_to_displayed_field) @@ -1536,12 +1534,10 @@ void GPU::SetDrawMode(u16 value) void GPU::SetTexturePalette(u16 value) { value &= DrawMode::PALETTE_MASK; - if (m_draw_mode.palette_reg == value) + if (m_draw_mode.palette_reg.bits == value) return; - m_draw_mode.texture_palette_x = ZeroExtend32(value & 0x3F) * 16; - m_draw_mode.texture_palette_y = ZeroExtend32(value >> 6); - m_draw_mode.palette_reg = value; + m_draw_mode.palette_reg.bits = value; m_draw_mode.texture_page_changed = true; } diff --git a/src/core/gpu.h b/src/core/gpu.h index 8864705c7..360aee00c 100644 --- a/src/core/gpu.h +++ b/src/core/gpu.h @@ -422,28 +422,16 @@ protected: // original values GPUDrawModeReg mode_reg; - u16 palette_reg; // from vertex + GPUTexturePaletteReg palette_reg; // from vertex u32 texture_window_value; // decoded values - u32 texture_page_x; - u32 texture_page_y; - u32 texture_palette_x; - u32 texture_palette_y; GPUTextureWindow texture_window; bool texture_x_flip; bool texture_y_flip; bool texture_page_changed; bool texture_window_changed; - /// Returns a rectangle comprising the texture palette area. - ALWAYS_INLINE_RELEASE Common::Rectangle GetTexturePaletteRectangle() const - { - static constexpr std::array palette_widths = {{16, 256, 0, 0}}; - return Common::Rectangle::FromExtents(texture_palette_x, texture_palette_y, - palette_widths[static_cast(mode_reg.texture_mode.GetValue())], 1); - } - ALWAYS_INLINE bool IsTexturePageChanged() const { return texture_page_changed; } ALWAYS_INLINE void SetTexturePageChanged() { texture_page_changed = true; } ALWAYS_INLINE void ClearTexturePageChangedFlag() { texture_page_changed = false; } diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp index c294a027d..905bfd9eb 100644 --- a/src/core/gpu_hw.cpp +++ b/src/core/gpu_hw.cpp @@ -1623,7 +1623,7 @@ void GPU_HW::LoadVertices() m_current_depth++; const GPURenderCommand rc{m_render_command.bits}; - const u32 texpage = ZeroExtend32(m_draw_mode.mode_reg.bits) | (ZeroExtend32(m_draw_mode.palette_reg) << 16); + const u32 texpage = ZeroExtend32(m_draw_mode.mode_reg.bits) | (ZeroExtend32(m_draw_mode.palette_reg.bits) << 16); const float depth = GetCurrentNormalizedVertexDepth(); switch (rc.primitive) @@ -2067,7 +2067,8 @@ void GPU_HW::IncludeVRAMDirtyRectangle(Common::Rectangle& rect, const Commo // shadow texture is updated if (!m_draw_mode.IsTexturePageChanged() && (m_draw_mode.mode_reg.GetTexturePageRectangle().Intersects(new_rect) || - (m_draw_mode.mode_reg.IsUsingPalette() && m_draw_mode.GetTexturePaletteRectangle().Intersects(new_rect)))) + (m_draw_mode.mode_reg.IsUsingPalette() && + m_draw_mode.palette_reg.GetRectangle(m_draw_mode.mode_reg.texture_mode).Intersects(new_rect)))) { m_draw_mode.SetTexturePageChanged(); } @@ -2300,7 +2301,7 @@ void GPU_HW::FillDrawCommand(GPUBackendDrawCommand* cmd, GPURenderCommand rc) co FillBackendCommandParameters(cmd); cmd->rc.bits = rc.bits; cmd->draw_mode.bits = m_draw_mode.mode_reg.bits; - cmd->palette.bits = m_draw_mode.palette_reg; + cmd->palette.bits = m_draw_mode.palette_reg.bits; cmd->window = m_draw_mode.texture_window; } @@ -2604,7 +2605,8 @@ void GPU_HW::DispatchRenderCommand() if (m_draw_mode.mode_reg.IsUsingPalette()) { - const Common::Rectangle palette_rect = m_draw_mode.GetTexturePaletteRectangle(); + const Common::Rectangle palette_rect = + m_draw_mode.palette_reg.GetRectangle(m_draw_mode.mode_reg.texture_mode); const bool update_drawn = palette_rect.Intersects(m_vram_dirty_draw_rect); const bool update_written = palette_rect.Intersects(m_vram_dirty_write_rect); if (update_drawn || update_written) diff --git a/src/core/gpu_sw.cpp b/src/core/gpu_sw.cpp index 6ab034f30..1e55bbcc4 100644 --- a/src/core/gpu_sw.cpp +++ b/src/core/gpu_sw.cpp @@ -554,7 +554,7 @@ void GPU_SW::FillDrawCommand(GPUBackendDrawCommand* cmd, GPURenderCommand rc) co FillBackendCommandParameters(cmd); cmd->rc.bits = rc.bits; cmd->draw_mode.bits = m_draw_mode.mode_reg.bits; - cmd->palette.bits = m_draw_mode.palette_reg; + cmd->palette.bits = m_draw_mode.palette_reg.bits; cmd->window = m_draw_mode.texture_window; } diff --git a/src/core/gpu_types.h b/src/core/gpu_types.h index d9b8fc6a3..44eeb266d 100644 --- a/src/core/gpu_types.h +++ b/src/core/gpu_types.h @@ -208,6 +208,13 @@ union GPUTexturePaletteReg ALWAYS_INLINE u32 GetXBase() const { return static_cast(x) * 16u; } ALWAYS_INLINE u32 GetYBase() const { return static_cast(y); } + + /// Returns a rectangle comprising the texture palette area. + ALWAYS_INLINE_RELEASE Common::Rectangle GetRectangle(GPUTextureMode mode) const + { + static constexpr std::array palette_widths = {{16, 256, 0, 0}}; + return Common::Rectangle::FromExtents(GetXBase(), GetYBase(), palette_widths[static_cast(mode)], 1); + } }; struct GPUTextureWindow diff --git a/src/core/save_state_version.h b/src/core/save_state_version.h index 526763f87..4ac3e7137 100644 --- a/src/core/save_state_version.h +++ b/src/core/save_state_version.h @@ -5,7 +5,7 @@ #include "types.h" static constexpr u32 SAVE_STATE_MAGIC = 0x43435544; -static constexpr u32 SAVE_STATE_VERSION = 61; +static constexpr u32 SAVE_STATE_VERSION = 62; static constexpr u32 SAVE_STATE_MINIMUM_VERSION = 42; static_assert(SAVE_STATE_VERSION >= SAVE_STATE_MINIMUM_VERSION);