diff --git a/pcsx2/GS/Renderers/Common/GSTexture.cpp b/pcsx2/GS/Renderers/Common/GSTexture.cpp index 65fdf99b35..ecb099a3ac 100644 --- a/pcsx2/GS/Renderers/Common/GSTexture.cpp +++ b/pcsx2/GS/Renderers/Common/GSTexture.cpp @@ -71,6 +71,23 @@ bool GSTexture::Save(const std::string& fn) return success; } +void GSTexture::Swap(GSTexture* tex) +{ + std::swap(m_scale, tex->m_scale); + std::swap(m_size, tex->m_size); + std::swap(m_committed_size, tex->m_committed_size); + std::swap(m_mipmap_levels, tex->m_mipmap_levels); + std::swap(m_type, tex->m_type); + std::swap(m_format, tex->m_format); + std::swap(m_state, tex->m_state); + std::swap(m_sparse, tex->m_sparse); + std::swap(m_needs_mipmaps_generated, tex->m_needs_mipmaps_generated); + std::swap(last_frame_used, tex->last_frame_used); + std::swap(LikelyOffset, tex->LikelyOffset); + std::swap(OffsetHack_modx, tex->OffsetHack_modx); + std::swap(OffsetHack_mody, tex->OffsetHack_mody); +} + void GSTexture::GenerateMipmapsIfNeeded() { if (!m_needs_mipmaps_generated || m_mipmap_levels <= 1) diff --git a/pcsx2/GS/Renderers/Common/GSTexture.h b/pcsx2/GS/Renderers/Common/GSTexture.h index 1d2ccbd966..5137c8af67 100644 --- a/pcsx2/GS/Renderers/Common/GSTexture.h +++ b/pcsx2/GS/Renderers/Common/GSTexture.h @@ -86,6 +86,7 @@ public: virtual void Unmap() = 0; virtual void GenerateMipmap() {} virtual bool Save(const std::string& fn); + virtual void Swap(GSTexture* tex); virtual u32 GetID() { return 0; } GSVector2 GetScale() const { return m_scale; } diff --git a/pcsx2/GS/Renderers/DX11/GSTexture11.cpp b/pcsx2/GS/Renderers/DX11/GSTexture11.cpp index e583294957..811c44792a 100644 --- a/pcsx2/GS/Renderers/DX11/GSTexture11.cpp +++ b/pcsx2/GS/Renderers/DX11/GSTexture11.cpp @@ -188,6 +188,16 @@ void GSTexture11::GenerateMipmap() GSDevice11::GetInstance()->GetD3DContext()->GenerateMips(operator ID3D11ShaderResourceView*()); } +void GSTexture11::Swap(GSTexture* tex) +{ + GSTexture::Swap(tex); + std::swap(m_texture, static_cast(tex)->m_texture); + std::swap(m_srv, static_cast(tex)->m_srv); + std::swap(m_rtv, static_cast(tex)->m_rtv); + std::swap(m_desc, static_cast(tex)->m_desc); + std::swap(m_mapped_subresource, static_cast(tex)->m_mapped_subresource); +} + GSTexture11::operator ID3D11Texture2D*() { return m_texture.get(); diff --git a/pcsx2/GS/Renderers/DX11/GSTexture11.h b/pcsx2/GS/Renderers/DX11/GSTexture11.h index 87445d6e7b..3bb2211ca6 100644 --- a/pcsx2/GS/Renderers/DX11/GSTexture11.h +++ b/pcsx2/GS/Renderers/DX11/GSTexture11.h @@ -40,6 +40,7 @@ public: void Unmap() override; bool Save(const std::string& fn) override; void GenerateMipmap() override; + void Swap(GSTexture* tex) override; bool Equal(GSTexture11* tex); operator ID3D11Texture2D*(); diff --git a/pcsx2/GS/Renderers/Null/GSTextureNull.cpp b/pcsx2/GS/Renderers/Null/GSTextureNull.cpp index ba1e2cd229..06f18ea0ce 100644 --- a/pcsx2/GS/Renderers/Null/GSTextureNull.cpp +++ b/pcsx2/GS/Renderers/Null/GSTextureNull.cpp @@ -29,6 +29,12 @@ GSTextureNull::GSTextureNull(Type type, int w, int h, GSTexture::Format format) m_desc.format = format; } +void GSTextureNull::Swap(GSTexture* tex) +{ + GSTexture::Swap(tex); + std::swap(m_desc, static_cast(tex)->m_desc); +} + void* GSTextureNull::GetNativeHandle() const { return nullptr; diff --git a/pcsx2/GS/Renderers/Null/GSTextureNull.h b/pcsx2/GS/Renderers/Null/GSTextureNull.h index 6eeb50b392..255eab935f 100644 --- a/pcsx2/GS/Renderers/Null/GSTextureNull.h +++ b/pcsx2/GS/Renderers/Null/GSTextureNull.h @@ -37,5 +37,6 @@ public: bool Map(GSMap& m, const GSVector4i* r = NULL, int layer = 0) override { return false; } void Unmap() override {} bool Save(const std::string& fn) override { return false; } + void Swap(GSTexture* tex) override; void* GetNativeHandle() const override; }; diff --git a/pcsx2/GS/Renderers/OpenGL/GSTextureOGL.cpp b/pcsx2/GS/Renderers/OpenGL/GSTextureOGL.cpp index d22b7bb93d..0d15c42b84 100644 --- a/pcsx2/GS/Renderers/OpenGL/GSTextureOGL.cpp +++ b/pcsx2/GS/Renderers/OpenGL/GSTextureOGL.cpp @@ -625,6 +625,24 @@ bool GSTextureOGL::Save(const std::string& fn) return GSPng::Save(fmt, fn, image.get(), m_committed_size.x, m_committed_size.y, pitch, compression); } +void GSTextureOGL::Swap(GSTexture* tex) +{ + GSTexture::Swap(tex); + + std::swap(m_texture_id, static_cast(tex)->m_texture_id); + std::swap(m_fbo_read, static_cast(tex)->m_fbo_read); + std::swap(m_clean, static_cast(tex)->m_clean); + std::swap(m_r_x, static_cast(tex)->m_r_x); + std::swap(m_r_x, static_cast(tex)->m_r_y); + std::swap(m_r_w, static_cast(tex)->m_r_w); + std::swap(m_r_h, static_cast(tex)->m_r_h); + std::swap(m_layer, static_cast(tex)->m_layer); + std::swap(m_int_format, static_cast(tex)->m_int_format); + std::swap(m_int_type, static_cast(tex)->m_int_type); + std::swap(m_int_shift, static_cast(tex)->m_int_shift); + std::swap(m_mem_usage, static_cast(tex)->m_mem_usage); +} + u32 GSTextureOGL::GetMemUsage() { return m_mem_usage; diff --git a/pcsx2/GS/Renderers/OpenGL/GSTextureOGL.h b/pcsx2/GS/Renderers/OpenGL/GSTextureOGL.h index 181e939d5e..63df1fdf59 100644 --- a/pcsx2/GS/Renderers/OpenGL/GSTextureOGL.h +++ b/pcsx2/GS/Renderers/OpenGL/GSTextureOGL.h @@ -68,6 +68,7 @@ public: void Unmap() final; void GenerateMipmap() final; bool Save(const std::string& fn) final; + void Swap(GSTexture* tex) final; GSMap Read(const GSVector4i& r, AlignedBuffer& buffer); bool IsDss() { return (m_type == Type::DepthStencil || m_type == Type::SparseDepthStencil); } diff --git a/pcsx2/GS/Renderers/SW/GSTextureSW.cpp b/pcsx2/GS/Renderers/SW/GSTextureSW.cpp index d713ddf41d..9abf94c11b 100644 --- a/pcsx2/GS/Renderers/SW/GSTextureSW.cpp +++ b/pcsx2/GS/Renderers/SW/GSTextureSW.cpp @@ -94,3 +94,11 @@ bool GSTextureSW::Save(const std::string& fn) int compression = theApp.GetConfigI("png_compression_level"); return GSPng::Save(fmt, fn, static_cast(m_data), m_size.x, m_size.y, m_pitch, compression); } + +void GSTextureSW::Swap(GSTexture* tex) +{ + GSTexture::Swap(tex); + std::swap(m_pitch, static_cast(tex)->m_pitch); + std::swap(m_data, static_cast(tex)->m_data); + // std::swap(m_mapped, static_cast(tex)->m_mapped); +} diff --git a/pcsx2/GS/Renderers/SW/GSTextureSW.h b/pcsx2/GS/Renderers/SW/GSTextureSW.h index a90616728e..32ca3fc260 100644 --- a/pcsx2/GS/Renderers/SW/GSTextureSW.h +++ b/pcsx2/GS/Renderers/SW/GSTextureSW.h @@ -33,5 +33,6 @@ public: bool Map(GSMap& m, const GSVector4i* r = NULL, int layer = 0) override; void Unmap() override; bool Save(const std::string& fn) override; + void Swap(GSTexture* tex) override; void* GetNativeHandle() const override; }; diff --git a/pcsx2/GS/Renderers/Vulkan/GSTextureVK.cpp b/pcsx2/GS/Renderers/Vulkan/GSTextureVK.cpp index b04361eb66..6403b65916 100644 --- a/pcsx2/GS/Renderers/Vulkan/GSTextureVK.cpp +++ b/pcsx2/GS/Renderers/Vulkan/GSTextureVK.cpp @@ -361,6 +361,17 @@ void GSTextureVK::GenerateMipmap() } } +void GSTextureVK::Swap(GSTexture* tex) +{ + GSTexture::Swap(tex); + std::swap(m_texture, static_cast(tex)->m_texture); + std::swap(m_use_fence_counter, static_cast(tex)->m_use_fence_counter); + std::swap(m_clear_value, static_cast(tex)->m_clear_value); + std::swap(m_map_area, static_cast(tex)->m_map_area); + std::swap(m_map_level, static_cast(tex)->m_map_level); + std::swap(m_framebuffers, static_cast(tex)->m_framebuffers); +} + void GSTextureVK::TransitionToLayout(VkImageLayout layout) { m_texture.TransitionToLayout(g_vulkan_context->GetCurrentCommandBuffer(), layout); diff --git a/pcsx2/GS/Renderers/Vulkan/GSTextureVK.h b/pcsx2/GS/Renderers/Vulkan/GSTextureVK.h index bf21375a59..905cb20e9a 100644 --- a/pcsx2/GS/Renderers/Vulkan/GSTextureVK.h +++ b/pcsx2/GS/Renderers/Vulkan/GSTextureVK.h @@ -50,6 +50,7 @@ public: bool Map(GSMap& m, const GSVector4i* r = NULL, int layer = 0) override; void Unmap() override; void GenerateMipmap() override; + void Swap(GSTexture* tex) override; void TransitionToLayout(VkImageLayout layout); void CommitClear();