GS: Add Swap() to GSTexture

This commit is contained in:
Connor McLaughlin 2022-02-20 22:30:56 +10:00 committed by refractionpcsx2
parent ed9f34de5f
commit 69a500d657
12 changed files with 76 additions and 0 deletions

View File

@ -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)

View File

@ -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; }

View File

@ -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<GSTexture11*>(tex)->m_texture);
std::swap(m_srv, static_cast<GSTexture11*>(tex)->m_srv);
std::swap(m_rtv, static_cast<GSTexture11*>(tex)->m_rtv);
std::swap(m_desc, static_cast<GSTexture11*>(tex)->m_desc);
std::swap(m_mapped_subresource, static_cast<GSTexture11*>(tex)->m_mapped_subresource);
}
GSTexture11::operator ID3D11Texture2D*()
{
return m_texture.get();

View File

@ -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*();

View File

@ -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<GSTextureNull*>(tex)->m_desc);
}
void* GSTextureNull::GetNativeHandle() const
{
return nullptr;

View File

@ -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;
};

View File

@ -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<GSTextureOGL*>(tex)->m_texture_id);
std::swap(m_fbo_read, static_cast<GSTextureOGL*>(tex)->m_fbo_read);
std::swap(m_clean, static_cast<GSTextureOGL*>(tex)->m_clean);
std::swap(m_r_x, static_cast<GSTextureOGL*>(tex)->m_r_x);
std::swap(m_r_x, static_cast<GSTextureOGL*>(tex)->m_r_y);
std::swap(m_r_w, static_cast<GSTextureOGL*>(tex)->m_r_w);
std::swap(m_r_h, static_cast<GSTextureOGL*>(tex)->m_r_h);
std::swap(m_layer, static_cast<GSTextureOGL*>(tex)->m_layer);
std::swap(m_int_format, static_cast<GSTextureOGL*>(tex)->m_int_format);
std::swap(m_int_type, static_cast<GSTextureOGL*>(tex)->m_int_type);
std::swap(m_int_shift, static_cast<GSTextureOGL*>(tex)->m_int_shift);
std::swap(m_mem_usage, static_cast<GSTextureOGL*>(tex)->m_mem_usage);
}
u32 GSTextureOGL::GetMemUsage()
{
return m_mem_usage;

View File

@ -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<u8, 32>& buffer);
bool IsDss() { return (m_type == Type::DepthStencil || m_type == Type::SparseDepthStencil); }

View File

@ -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<u8*>(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<GSTextureSW*>(tex)->m_pitch);
std::swap(m_data, static_cast<GSTextureSW*>(tex)->m_data);
// std::swap(m_mapped, static_cast<GSTextureSW*>(tex)->m_mapped);
}

View File

@ -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;
};

View File

@ -361,6 +361,17 @@ void GSTextureVK::GenerateMipmap()
}
}
void GSTextureVK::Swap(GSTexture* tex)
{
GSTexture::Swap(tex);
std::swap(m_texture, static_cast<GSTextureVK*>(tex)->m_texture);
std::swap(m_use_fence_counter, static_cast<GSTextureVK*>(tex)->m_use_fence_counter);
std::swap(m_clear_value, static_cast<GSTextureVK*>(tex)->m_clear_value);
std::swap(m_map_area, static_cast<GSTextureVK*>(tex)->m_map_area);
std::swap(m_map_level, static_cast<GSTextureVK*>(tex)->m_map_level);
std::swap(m_framebuffers, static_cast<GSTextureVK*>(tex)->m_framebuffers);
}
void GSTextureVK::TransitionToLayout(VkImageLayout layout)
{
m_texture.TransitionToLayout(g_vulkan_context->GetCurrentCommandBuffer(), layout);

View File

@ -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();