diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 998b30cd0..43cd717bf 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -15,6 +15,8 @@ add_library(common
fifo_queue.h
file_system.cpp
file_system.h
+ gpu_texture.cpp
+ gpu_texture.h
image.cpp
image.h
hash_combine.h
diff --git a/src/common/common.vcxproj b/src/common/common.vcxproj
index 0fdb9eb11..50773b429 100644
--- a/src/common/common.vcxproj
+++ b/src/common/common.vcxproj
@@ -46,6 +46,7 @@
true
+
@@ -142,6 +143,7 @@
true
+
diff --git a/src/common/common.vcxproj.filters b/src/common/common.vcxproj.filters
index 14449df6a..30df8cc14 100644
--- a/src/common/common.vcxproj.filters
+++ b/src/common/common.vcxproj.filters
@@ -129,6 +129,7 @@
+
@@ -233,6 +234,7 @@
+
diff --git a/src/common/d3d11/texture.cpp b/src/common/d3d11/texture.cpp
index ab4af3dca..f68347958 100644
--- a/src/common/d3d11/texture.cpp
+++ b/src/common/d3d11/texture.cpp
@@ -1,38 +1,63 @@
#include "texture.h"
#include "../log.h"
+#include
Log_SetChannel(D3D11);
-namespace D3D11 {
+static constexpr std::array(GPUTexture::Format::Count)> s_dxgi_mapping = {
+ {DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B5G6R5_UNORM,
+ DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_D16_UNORM}};
-Texture::Texture() : m_width(0), m_height(0), m_samples(0) {}
+D3D11::Texture::Texture() = default;
-Texture::Texture(ComPtr texture, ComPtr srv,
- ComPtr rtv)
+D3D11::Texture::Texture(ComPtr texture, ComPtr srv,
+ ComPtr rtv)
: m_texture(std::move(texture)), m_srv(std::move(srv)), m_rtv(std::move(rtv))
{
const D3D11_TEXTURE2D_DESC desc = GetDesc();
m_width = static_cast(desc.Width);
m_height = static_cast(desc.Height);
- m_layers = static_cast(desc.ArraySize);
+ m_layers = static_cast(desc.ArraySize);
m_levels = static_cast(desc.MipLevels);
m_samples = static_cast(desc.SampleDesc.Count);
+ m_format = LookupBaseFormat(desc.Format);
+ m_dynamic = (desc.Usage == D3D11_USAGE_DYNAMIC);
}
-Texture::~Texture()
+D3D11::Texture::~Texture()
{
Destroy();
}
-D3D11_TEXTURE2D_DESC Texture::GetDesc() const
+DXGI_FORMAT D3D11::Texture::GetDXGIFormat(Format format)
+{
+ return s_dxgi_mapping[static_cast(format)];
+}
+
+GPUTexture::Format D3D11::Texture::LookupBaseFormat(DXGI_FORMAT dformat)
+{
+ for (u32 i = 0; i < static_cast(s_dxgi_mapping.size()); i++)
+ {
+ if (s_dxgi_mapping[i] == dformat)
+ return static_cast(i);
+ }
+ return GPUTexture::Format::Unknown;
+}
+
+D3D11_TEXTURE2D_DESC D3D11::Texture::GetDesc() const
{
D3D11_TEXTURE2D_DESC desc;
m_texture->GetDesc(&desc);
return desc;
}
-bool Texture::Create(ID3D11Device* device, u32 width, u32 height, u32 layers, u32 levels, u32 samples,
- DXGI_FORMAT format, u32 bind_flags, const void* initial_data /* = nullptr */,
- u32 initial_data_stride /* = 0 */, bool dynamic /* = false */)
+bool D3D11::Texture::IsValid() const
+{
+ return static_cast(m_texture);
+}
+
+bool D3D11::Texture::Create(ID3D11Device* device, u32 width, u32 height, u32 layers, u32 levels, u32 samples,
+ Format format, u32 bind_flags, const void* initial_data /* = nullptr */,
+ u32 initial_data_stride /* = 0 */, bool dynamic /* = false */)
{
if (width > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION || height > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION ||
layers > D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION || (layers > 1 && samples > 1))
@@ -42,7 +67,7 @@ bool Texture::Create(ID3D11Device* device, u32 width, u32 height, u32 layers, u3
return false;
}
- CD3D11_TEXTURE2D_DESC desc(format, width, height, layers, levels, bind_flags,
+ CD3D11_TEXTURE2D_DESC desc(GetDXGIFormat(format), width, height, layers, levels, bind_flags,
dynamic ? D3D11_USAGE_DYNAMIC : D3D11_USAGE_DEFAULT, dynamic ? D3D11_CPU_ACCESS_WRITE : 0,
samples, 0, 0);
@@ -96,13 +121,15 @@ bool Texture::Create(ID3D11Device* device, u32 width, u32 height, u32 layers, u3
m_rtv = std::move(rtv);
m_width = static_cast(width);
m_height = static_cast(height);
- m_layers = static_cast(layers);
+ m_layers = static_cast(layers);
m_levels = static_cast(levels);
m_samples = static_cast(samples);
+ m_format = format;
+ m_dynamic = dynamic;
return true;
}
-bool Texture::Adopt(ID3D11Device* device, ComPtr texture)
+bool D3D11::Texture::Adopt(ID3D11Device* device, ComPtr texture)
{
D3D11_TEXTURE2D_DESC desc;
texture->GetDesc(&desc);
@@ -140,22 +167,18 @@ bool Texture::Adopt(ID3D11Device* device, ComPtr texture)
m_rtv = std::move(rtv);
m_width = static_cast(desc.Width);
m_height = static_cast(desc.Height);
- m_layers = static_cast(desc.ArraySize);
+ m_layers = static_cast(desc.ArraySize);
m_levels = static_cast(desc.MipLevels);
m_samples = static_cast(desc.SampleDesc.Count);
+ m_dynamic = (desc.Usage == D3D11_USAGE_DYNAMIC);
return true;
}
-void Texture::Destroy()
+void D3D11::Texture::Destroy()
{
m_rtv.Reset();
m_srv.Reset();
m_texture.Reset();
- m_width = 0;
- m_height = 0;
- m_layers = 0;
- m_levels = 0;
- m_samples = 0;
+ m_dynamic = false;
+ ClearBaseProperties();
}
-
-} // namespace D3D11
diff --git a/src/common/d3d11/texture.h b/src/common/d3d11/texture.h
index 402fee2de..8c5d602f7 100644
--- a/src/common/d3d11/texture.h
+++ b/src/common/d3d11/texture.h
@@ -1,11 +1,12 @@
#pragma once
-#include "../types.h"
+#include "../gpu_texture.h"
#include "../windows_headers.h"
#include
#include
namespace D3D11 {
-class Texture
+
+class Texture final : public GPUTexture
{
public:
template
@@ -15,27 +16,27 @@ public:
Texture(ComPtr texture, ComPtr srv, ComPtr rtv);
~Texture();
+ static DXGI_FORMAT GetDXGIFormat(Format format);
+ static Format LookupBaseFormat(DXGI_FORMAT dformat);
+
ALWAYS_INLINE ID3D11Texture2D* GetD3DTexture() const { return m_texture.Get(); }
ALWAYS_INLINE ID3D11ShaderResourceView* GetD3DSRV() const { return m_srv.Get(); }
ALWAYS_INLINE ID3D11RenderTargetView* GetD3DRTV() const { return m_rtv.Get(); }
ALWAYS_INLINE ID3D11ShaderResourceView* const* GetD3DSRVArray() const { return m_srv.GetAddressOf(); }
ALWAYS_INLINE ID3D11RenderTargetView* const* GetD3DRTVArray() const { return m_rtv.GetAddressOf(); }
-
- ALWAYS_INLINE u16 GetWidth() const { return m_width; }
- ALWAYS_INLINE u16 GetHeight() const { return m_height; }
- ALWAYS_INLINE u16 GetLayers() const { return m_layers; }
- ALWAYS_INLINE u8 GetLevels() const { return m_levels; }
- ALWAYS_INLINE u8 GetSamples() const { return m_samples; }
- ALWAYS_INLINE bool IsMultisampled() const { return m_samples > 1; }
- ALWAYS_INLINE DXGI_FORMAT GetFormat() const { return GetDesc().Format; }
- D3D11_TEXTURE2D_DESC GetDesc() const;
+ ALWAYS_INLINE DXGI_FORMAT GetDXGIFormat() const { return GetDXGIFormat(m_format); }
+ ALWAYS_INLINE bool IsDynamic() const { return m_dynamic; }
ALWAYS_INLINE operator ID3D11Texture2D*() const { return m_texture.Get(); }
ALWAYS_INLINE operator ID3D11ShaderResourceView*() const { return m_srv.Get(); }
ALWAYS_INLINE operator ID3D11RenderTargetView*() const { return m_rtv.Get(); }
ALWAYS_INLINE operator bool() const { return static_cast(m_texture); }
- bool Create(ID3D11Device* device, u32 width, u32 height, u32 layers, u32 levels, u32 samples, DXGI_FORMAT format,
+ D3D11_TEXTURE2D_DESC GetDesc() const;
+
+ bool IsValid() const override;
+
+ bool Create(ID3D11Device* device, u32 width, u32 height, u32 layers, u32 levels, u32 samples, Format format,
u32 bind_flags, const void* initial_data = nullptr, u32 initial_data_stride = 0, bool dynamic = false);
bool Adopt(ID3D11Device* device, ComPtr texture);
@@ -45,10 +46,7 @@ private:
ComPtr m_texture;
ComPtr m_srv;
ComPtr m_rtv;
- u16 m_width;
- u16 m_height;
- u16 m_layers;
- u8 m_levels;
- u8 m_samples;
+ bool m_dynamic = false;
};
+
} // namespace D3D11
\ No newline at end of file
diff --git a/src/common/d3d12/texture.cpp b/src/common/d3d12/texture.cpp
index 4ceab3644..a9b7bb4a4 100644
--- a/src/common/d3d12/texture.cpp
+++ b/src/common/d3d12/texture.cpp
@@ -8,79 +8,111 @@
#include "util.h"
Log_SetChannel(D3D12);
-namespace D3D12 {
+static constexpr std::array(GPUTexture::Format::Count)> s_dxgi_mapping = {
+ {DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_B8G8R8A8_UNORM, DXGI_FORMAT_B5G6R5_UNORM,
+ DXGI_FORMAT_B5G5R5A1_UNORM, DXGI_FORMAT_R8_UNORM, DXGI_FORMAT_D16_UNORM}};
-Texture::Texture() = default;
+D3D12::Texture::Texture() = default;
-Texture::Texture(ID3D12Resource* resource, D3D12_RESOURCE_STATES state) : m_resource(std::move(resource))
+D3D12::Texture::Texture(ID3D12Resource* resource, D3D12_RESOURCE_STATES state) : m_resource(std::move(resource))
{
const D3D12_RESOURCE_DESC desc = GetDesc();
- m_width = static_cast(desc.Width);
- m_height = desc.Height;
- m_samples = desc.SampleDesc.Count;
- m_format = desc.Format;
+ m_width = static_cast(desc.Width);
+ m_height = static_cast(desc.Height);
+ m_layers = static_cast(desc.DepthOrArraySize);
+ m_levels = static_cast(desc.MipLevels);
+ m_samples = static_cast(desc.SampleDesc.Count);
+ m_format = LookupBaseFormat(desc.Format);
}
-Texture::Texture(Texture&& texture)
+D3D12::Texture::Texture(Texture&& texture)
: m_resource(std::move(texture.m_resource)), m_srv_descriptor(texture.m_srv_descriptor),
- m_rtv_or_dsv_descriptor(texture.m_rtv_or_dsv_descriptor), m_width(texture.m_width), m_height(texture.m_height),
- m_samples(texture.m_samples), m_format(texture.m_format), m_state(texture.m_state),
- m_is_depth_view(texture.m_is_depth_view)
+ m_rtv_or_dsv_descriptor(texture.m_rtv_or_dsv_descriptor), m_is_depth_view(texture.m_is_depth_view)
{
+ m_width = texture.m_width;
+ m_height = texture.m_height;
+ m_layers = texture.m_layers;
+ m_levels = texture.m_levels;
+ m_samples = texture.m_samples;
texture.m_srv_descriptor = {};
texture.m_rtv_or_dsv_descriptor = {};
- texture.m_width = 0;
- texture.m_height = 0;
- texture.m_samples = 0;
- texture.m_format = DXGI_FORMAT_UNKNOWN;
texture.m_state = D3D12_RESOURCE_STATE_COMMON;
texture.m_is_depth_view = false;
+ texture.ClearBaseProperties();
}
-Texture::~Texture()
+DXGI_FORMAT D3D12::Texture::GetDXGIFormat(Format format)
+{
+ return s_dxgi_mapping[static_cast(format)];
+}
+
+GPUTexture::Format D3D12::Texture::LookupBaseFormat(DXGI_FORMAT dformat)
+{
+ for (u32 i = 0; i < static_cast(s_dxgi_mapping.size()); i++)
+ {
+ if (s_dxgi_mapping[i] == dformat)
+ return static_cast(i);
+ }
+ return GPUTexture::Format::Unknown;
+}
+
+D3D12::Texture::~Texture()
{
Destroy();
}
-Texture& Texture::operator=(Texture&& texture)
+D3D12::Texture& D3D12::Texture::operator=(Texture&& texture)
{
Destroy();
+
+ m_width = texture.m_width;
+ m_height = texture.m_height;
+ m_layers = texture.m_layers;
+ m_levels = texture.m_levels;
+ m_samples = texture.m_samples;
+
m_resource = std::move(texture.m_resource);
m_srv_descriptor = texture.m_srv_descriptor;
m_rtv_or_dsv_descriptor = texture.m_rtv_or_dsv_descriptor;
- m_width = texture.m_width;
- m_height = texture.m_height;
- m_samples = texture.m_samples;
- m_format = texture.m_format;
m_state = texture.m_state;
m_is_depth_view = texture.m_is_depth_view;
+
+ texture.ClearBaseProperties();
texture.m_srv_descriptor = {};
texture.m_rtv_or_dsv_descriptor = {};
- texture.m_width = 0;
- texture.m_height = 0;
- texture.m_samples = 0;
- texture.m_format = DXGI_FORMAT_UNKNOWN;
texture.m_state = D3D12_RESOURCE_STATE_COMMON;
texture.m_is_depth_view = false;
return *this;
}
-D3D12_RESOURCE_DESC Texture::GetDesc() const
+D3D12_RESOURCE_DESC D3D12::Texture::GetDesc() const
{
return m_resource->GetDesc();
}
-bool Texture::Create(u32 width, u32 height, u32 samples, DXGI_FORMAT format, DXGI_FORMAT srv_format,
- DXGI_FORMAT rtv_format, DXGI_FORMAT dsv_format, D3D12_RESOURCE_FLAGS flags)
+bool D3D12::Texture::IsValid() const
+{
+ return static_cast(m_resource);
+}
+
+bool D3D12::Texture::Create(u32 width, u32 height, u32 layers, u32 levels, u32 samples, DXGI_FORMAT format,
+ DXGI_FORMAT srv_format, DXGI_FORMAT rtv_format, DXGI_FORMAT dsv_format,
+ D3D12_RESOURCE_FLAGS flags)
{
constexpr D3D12_HEAP_PROPERTIES heap_properties = {D3D12_HEAP_TYPE_DEFAULT};
+ if (width > MAX_WIDTH || height > MAX_HEIGHT || layers > MAX_LAYERS || levels > MAX_LEVELS || samples > MAX_SAMPLES)
+ {
+ Log_ErrorPrintf("Invalid dimensions: %ux%ux%u %u %u", width, height, layers, levels, samples);
+ return false;
+ }
+
D3D12_RESOURCE_DESC desc = {};
desc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
desc.Width = width;
- desc.Height = height;
- desc.DepthOrArraySize = 1;
- desc.MipLevels = 1;
+ desc.Height = static_cast(height);
+ desc.DepthOrArraySize = static_cast(layers);
+ desc.MipLevels = static_cast(levels);
desc.Format = format;
desc.SampleDesc.Count = samples;
desc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
@@ -147,17 +179,19 @@ bool Texture::Create(u32 width, u32 height, u32 samples, DXGI_FORMAT format, DXG
m_resource = std::move(resource);
m_srv_descriptor = std::move(srv_descriptor);
m_rtv_or_dsv_descriptor = std::move(rtv_descriptor);
- m_width = width;
- m_height = height;
- m_samples = samples;
- m_format = format;
+ m_width = static_cast(width);
+ m_height = static_cast(height);
+ m_layers = static_cast(layers);
+ m_levels = static_cast(levels);
+ m_samples = static_cast(samples);
+ m_format = LookupBaseFormat(format);
m_state = state;
m_is_depth_view = is_depth_view;
return true;
}
-bool Texture::Adopt(ComPtr texture, DXGI_FORMAT srv_format, DXGI_FORMAT rtv_format,
- DXGI_FORMAT dsv_format, D3D12_RESOURCE_STATES state)
+bool D3D12::Texture::Adopt(ComPtr texture, DXGI_FORMAT srv_format, DXGI_FORMAT rtv_format,
+ DXGI_FORMAT dsv_format, D3D12_RESOURCE_STATES state)
{
const D3D12_RESOURCE_DESC desc(texture->GetDesc());
@@ -168,6 +202,8 @@ bool Texture::Adopt(ComPtr texture, DXGI_FORMAT srv_format, DXGI
return false;
}
+ m_is_depth_view = false;
+
if (rtv_format != DXGI_FORMAT_UNKNOWN)
{
Assert(dsv_format == DXGI_FORMAT_UNKNOWN);
@@ -184,20 +220,24 @@ bool Texture::Adopt(ComPtr texture, DXGI_FORMAT srv_format, DXGI
g_d3d12_context->GetDescriptorHeapManager().Free(&srv_descriptor);
return false;
}
+
+ m_is_depth_view = true;
}
m_resource = std::move(texture);
m_srv_descriptor = std::move(srv_descriptor);
m_rtv_or_dsv_descriptor = std::move(rtv_descriptor);
- m_width = static_cast(desc.Width);
- m_height = desc.Height;
- m_samples = desc.SampleDesc.Count;
- m_format = desc.Format;
+ m_width = static_cast(desc.Width);
+ m_height = static_cast(desc.Height);
+ m_layers = static_cast(desc.DepthOrArraySize);
+ m_levels = static_cast(desc.MipLevels);
+ m_samples = static_cast(desc.SampleDesc.Count);
+ m_format = LookupBaseFormat(desc.Format);
m_state = state;
return true;
}
-void Texture::Destroy(bool defer /* = true */)
+void D3D12::Texture::Destroy(bool defer /* = true */)
{
if (defer)
{
@@ -220,14 +260,11 @@ void Texture::Destroy(bool defer /* = true */)
m_resource.Reset();
}
- m_width = 0;
- m_height = 0;
- m_samples = 0;
- m_format = DXGI_FORMAT_UNKNOWN;
+ ClearBaseProperties();
m_is_depth_view = false;
}
-void Texture::TransitionToState(D3D12_RESOURCE_STATES state) const
+void D3D12::Texture::TransitionToState(D3D12_RESOURCE_STATES state) const
{
if (m_state == state)
return;
@@ -236,9 +273,9 @@ void Texture::TransitionToState(D3D12_RESOURCE_STATES state) const
m_state = state;
}
-bool Texture::BeginStreamUpdate(u32 x, u32 y, u32 width, u32 height, void** out_data, u32* out_data_pitch)
+bool D3D12::Texture::BeginStreamUpdate(u32 x, u32 y, u32 width, u32 height, void** out_data, u32* out_data_pitch)
{
- const u32 copy_pitch = Common::AlignUpPow2(width * GetTexelSize(m_format), D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
+ const u32 copy_pitch = Common::AlignUpPow2(width * GetPixelSize(), D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
const u32 upload_size = copy_pitch * height;
if (!g_d3d12_context->GetTextureStreamBuffer().ReserveMemory(upload_size, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT))
@@ -258,9 +295,9 @@ bool Texture::BeginStreamUpdate(u32 x, u32 y, u32 width, u32 height, void** out_
return true;
}
-void Texture::EndStreamUpdate(u32 x, u32 y, u32 width, u32 height)
+void D3D12::Texture::EndStreamUpdate(u32 x, u32 y, u32 width, u32 height)
{
- const u32 copy_pitch = Common::AlignUpPow2(width * GetTexelSize(m_format), D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
+ const u32 copy_pitch = Common::AlignUpPow2(width * GetPixelSize(), D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
const u32 upload_size = copy_pitch * height;
StreamBuffer& sb = g_d3d12_context->GetTextureStreamBuffer();
@@ -270,7 +307,8 @@ void Texture::EndStreamUpdate(u32 x, u32 y, u32 width, u32 height)
CopyFromBuffer(x, y, width, height, copy_pitch, sb.GetBuffer(), sb_offset);
}
-void Texture::CopyFromBuffer(u32 x, u32 y, u32 width, u32 height, u32 pitch, ID3D12Resource* buffer, u32 buffer_offset)
+void D3D12::Texture::CopyFromBuffer(u32 x, u32 y, u32 width, u32 height, u32 pitch, ID3D12Resource* buffer,
+ u32 buffer_offset)
{
D3D12_TEXTURE_COPY_LOCATION src;
src.pResource = buffer;
@@ -281,7 +319,7 @@ void Texture::CopyFromBuffer(u32 x, u32 y, u32 width, u32 height, u32 pitch, ID3
src.PlacedFootprint.Footprint.Height = height;
src.PlacedFootprint.Footprint.Depth = 1;
src.PlacedFootprint.Footprint.RowPitch = pitch;
- src.PlacedFootprint.Footprint.Format = m_format;
+ src.PlacedFootprint.Footprint.Format = GetDXGIFormat();
D3D12_TEXTURE_COPY_LOCATION dst;
dst.pResource = m_resource.Get();
@@ -295,15 +333,15 @@ void Texture::CopyFromBuffer(u32 x, u32 y, u32 width, u32 height, u32 pitch, ID3
TransitionToState(old_state);
}
-bool Texture::LoadData(u32 x, u32 y, u32 width, u32 height, const void* data, u32 pitch)
+bool D3D12::Texture::LoadData(u32 x, u32 y, u32 width, u32 height, const void* data, u32 pitch)
{
- const u32 texel_size = GetTexelSize(m_format);
+ const u32 texel_size = GetPixelSize();
const u32 upload_pitch = Common::AlignUpPow2(width * texel_size, D3D12_TEXTURE_DATA_PITCH_ALIGNMENT);
const u32 upload_size = upload_pitch * height;
if (upload_size >= g_d3d12_context->GetTextureStreamBuffer().GetSize())
{
StagingTexture st;
- if (!st.Create(width, height, m_format, true) || !st.WritePixels(0, 0, width, height, data, pitch))
+ if (!st.Create(width, height, GetDXGIFormat(), true) || !st.WritePixels(0, 0, width, height, data, pitch))
return false;
D3D12_RESOURCE_STATES old_state = m_state;
@@ -324,7 +362,7 @@ bool Texture::LoadData(u32 x, u32 y, u32 width, u32 height, const void* data, u3
return true;
}
-void Texture::CopyToUploadBuffer(const void* src_data, u32 src_pitch, u32 height, void* dst_data, u32 dst_pitch)
+void D3D12::Texture::CopyToUploadBuffer(const void* src_data, u32 src_pitch, u32 height, void* dst_data, u32 dst_pitch)
{
const u8* src_ptr = static_cast(src_data);
u8* dst_ptr = static_cast(dst_data);
@@ -344,7 +382,8 @@ void Texture::CopyToUploadBuffer(const void* src_data, u32 src_pitch, u32 height
}
}
-bool Texture::CreateSRVDescriptor(ID3D12Resource* resource, DXGI_FORMAT format, bool multisampled, DescriptorHandle* dh)
+bool D3D12::Texture::CreateSRVDescriptor(ID3D12Resource* resource, DXGI_FORMAT format, bool multisampled,
+ DescriptorHandle* dh)
{
if (!g_d3d12_context->GetDescriptorHeapManager().Allocate(dh))
{
@@ -362,7 +401,8 @@ bool Texture::CreateSRVDescriptor(ID3D12Resource* resource, DXGI_FORMAT format,
return true;
}
-bool Texture::CreateRTVDescriptor(ID3D12Resource* resource, DXGI_FORMAT format, bool multisampled, DescriptorHandle* dh)
+bool D3D12::Texture::CreateRTVDescriptor(ID3D12Resource* resource, DXGI_FORMAT format, bool multisampled,
+ DescriptorHandle* dh)
{
if (!g_d3d12_context->GetRTVHeapManager().Allocate(dh))
{
@@ -377,7 +417,8 @@ bool Texture::CreateRTVDescriptor(ID3D12Resource* resource, DXGI_FORMAT format,
return true;
}
-bool Texture::CreateDSVDescriptor(ID3D12Resource* resource, DXGI_FORMAT format, bool multisampled, DescriptorHandle* dh)
+bool D3D12::Texture::CreateDSVDescriptor(ID3D12Resource* resource, DXGI_FORMAT format, bool multisampled,
+ DescriptorHandle* dh)
{
if (!g_d3d12_context->GetDSVHeapManager().Allocate(dh))
{
@@ -391,5 +432,3 @@ bool Texture::CreateDSVDescriptor(ID3D12Resource* resource, DXGI_FORMAT format,
g_d3d12_context->GetDevice()->CreateDepthStencilView(resource, &desc, dh->cpu_handle);
return true;
}
-
-} // namespace D3D12
\ No newline at end of file
diff --git a/src/common/d3d12/texture.h b/src/common/d3d12/texture.h
index 50b60aa18..ec47f15b1 100644
--- a/src/common/d3d12/texture.h
+++ b/src/common/d3d12/texture.h
@@ -1,5 +1,5 @@
#pragma once
-#include "../types.h"
+#include "../gpu_texture.h"
#include "../windows_headers.h"
#include "descriptor_heap_manager.h"
#include
@@ -9,7 +9,7 @@ namespace D3D12 {
class StreamBuffer;
-class Texture final
+class Texture final : public GPUTexture
{
public:
template
@@ -21,21 +21,21 @@ public:
Texture(const Texture&) = delete;
~Texture();
+ static DXGI_FORMAT GetDXGIFormat(Format format);
+ static Format LookupBaseFormat(DXGI_FORMAT dformat);
+
ALWAYS_INLINE ID3D12Resource* GetResource() const { return m_resource.Get(); }
ALWAYS_INLINE const DescriptorHandle& GetSRVDescriptor() const { return m_srv_descriptor; }
ALWAYS_INLINE const DescriptorHandle& GetRTVOrDSVDescriptor() const { return m_rtv_or_dsv_descriptor; }
ALWAYS_INLINE D3D12_RESOURCE_STATES GetState() const { return m_state; }
-
- ALWAYS_INLINE u32 GetWidth() const { return m_width; }
- ALWAYS_INLINE u32 GetHeight() const { return m_height; }
- ALWAYS_INLINE u32 GetSamples() const { return m_samples; }
- ALWAYS_INLINE DXGI_FORMAT GetFormat() const { return m_format; }
- ALWAYS_INLINE bool IsMultisampled() const { return m_samples > 1; }
+ ALWAYS_INLINE DXGI_FORMAT GetDXGIFormat() const { return GetDXGIFormat(m_format); }
ALWAYS_INLINE operator ID3D12Resource*() const { return m_resource.Get(); }
ALWAYS_INLINE operator bool() const { return static_cast(m_resource); }
- bool Create(u32 width, u32 height, u32 samples, DXGI_FORMAT format, DXGI_FORMAT srv_format, DXGI_FORMAT rtv_format,
+ bool IsValid() const override;
+
+ bool Create(u32 width, u32 height, u32 layers, u32 levels, u32 samples, DXGI_FORMAT format, DXGI_FORMAT srv_format, DXGI_FORMAT rtv_format,
DXGI_FORMAT dsv_format, D3D12_RESOURCE_FLAGS flags);
bool Adopt(ComPtr texture, DXGI_FORMAT srv_format, DXGI_FORMAT rtv_format, DXGI_FORMAT dsv_format,
D3D12_RESOURCE_STATES state);
@@ -68,10 +68,6 @@ private:
ComPtr m_resource;
DescriptorHandle m_srv_descriptor = {};
DescriptorHandle m_rtv_or_dsv_descriptor = {};
- u32 m_width = 0;
- u32 m_height = 0;
- u32 m_samples = 0;
- DXGI_FORMAT m_format = DXGI_FORMAT_UNKNOWN;
mutable D3D12_RESOURCE_STATES m_state = D3D12_RESOURCE_STATE_COMMON;
diff --git a/src/common/gl/texture.cpp b/src/common/gl/texture.cpp
index 2d821e66a..9a0034073 100644
--- a/src/common/gl/texture.cpp
+++ b/src/common/gl/texture.cpp
@@ -1,51 +1,78 @@
#include "texture.h"
#include "../assert.h"
#include "../log.h"
+#include
#include
+#include
Log_SetChannel(GL);
-namespace GL {
-
-static constexpr u32 MAX_DIMENSIONS = std::numeric_limits::max();
-static constexpr u8 MAX_LEVELS = std::numeric_limits::max();
-static constexpr u8 MAX_SAMPLES = std::numeric_limits::max();
-
-Texture::Texture() = default;
-
-Texture::Texture(Texture&& moved)
- : m_id(moved.m_id), m_width(moved.m_width), m_height(moved.m_height), m_samples(moved.m_samples),
- m_fbo_id(moved.m_fbo_id)
+const std::tuple& GL::Texture::GetPixelFormatMapping(GPUTexture::Format format)
{
- moved.m_id = 0;
- moved.m_width = 0;
- moved.m_height = 0;
- moved.m_samples = 0;
- moved.m_fbo_id = 0;
+ static constexpr std::array, static_cast(GPUTexture::Format::Count)> mapping =
+ {{
+ {}, // Unknown
+ {GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE}, // RGBA8
+ {GL_RGBA8, GL_BGRA, GL_UNSIGNED_BYTE}, // BGRA8
+ {GL_RGB565, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}, // RGB565
+ {GL_RGB5_A1, GL_BGRA, GL_UNSIGNED_SHORT_1_5_5_5_REV}, // RGBA5551
+ {GL_R8, GL_RED, GL_UNSIGNED_BYTE}, // R8
+ {GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT, GL_SHORT}, // D16
+ }};
+
+ static constexpr std::array, static_cast(GPUTexture::Format::Count)>
+ mapping_gles2 = {{
+ {}, // Unknown
+ {GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE}, // RGBA8
+ {}, // BGRA8
+ {GL_RGB, GL_RGB, GL_UNSIGNED_SHORT_5_6_5}, // RGB565
+ {}, // RGBA5551
+ {}, // R8
+ {}, // D16
+ }};
+
+ if (!GLAD_GL_ES_VERSION_2_0 || GLAD_GL_ES_VERSION_3_0)
+ return mapping[static_cast(format)];
+ else
+ return mapping_gles2[static_cast(format)];
}
-Texture::~Texture()
+GL::Texture::Texture() = default;
+
+GL::Texture::Texture(Texture&& moved) : m_id(moved.m_id), m_fbo_id(moved.m_fbo_id)
+{
+ m_width = moved.m_width;
+ m_height = moved.m_height;
+ m_levels = moved.m_levels;
+ m_layers = moved.m_layers;
+ m_samples = moved.m_samples;
+ m_format = moved.m_format;
+ moved.m_id = 0;
+ moved.m_fbo_id = 0;
+ moved.ClearBaseProperties();
+}
+
+GL::Texture::~Texture()
{
Destroy();
}
-bool Texture::UseTextureStorage(bool multisampled)
+bool GL::Texture::UseTextureStorage(bool multisampled)
{
return GLAD_GL_ARB_texture_storage || (multisampled ? GLAD_GL_ES_VERSION_3_1 : GLAD_GL_ES_VERSION_3_0);
}
-bool Texture::UseTextureStorage() const
+bool GL::Texture::UseTextureStorage() const
{
return UseTextureStorage(IsMultisampled());
}
-bool Texture::Create(u32 width, u32 height, u32 layers, u32 levels, u32 samples, GLenum internal_format, GLenum format,
- GLenum type, const void* data /* = nullptr */, bool linear_filter /* = false */,
- bool wrap /* = false */)
+bool GL::Texture::Create(u32 width, u32 height, u32 layers, u32 levels, u32 samples, Format format,
+ const void* data /* = nullptr */, u32 data_pitch /* = 0 */, bool linear /* = true */,
+ bool wrap /* = true */)
{
glGetError();
- if (width > MAX_DIMENSIONS || height > MAX_DIMENSIONS || layers > MAX_DIMENSIONS || levels > MAX_DIMENSIONS ||
- samples > MAX_SAMPLES)
+ if (width > MAX_WIDTH || height > MAX_HEIGHT || layers > MAX_LAYERS || levels > MAX_LEVELS || samples > MAX_SAMPLES)
{
Log_ErrorPrintf("Invalid dimensions: %ux%ux%u %u %u", width, height, layers, levels, samples);
return false;
@@ -65,6 +92,7 @@ bool Texture::Create(u32 width, u32 height, u32 layers, u32 levels, u32 samples,
const GLenum target = ((samples > 1) ? ((layers > 1) ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D_MULTISAMPLE_ARRAY) :
((layers > 1) ? GL_TEXTURE_2D_ARRAY : GL_TEXTURE_2D));
+ const auto [gl_internal_format, gl_format, gl_type] = GetPixelFormatMapping(format);
GLuint id;
glGenTextures(1, &id);
@@ -76,16 +104,16 @@ bool Texture::Create(u32 width, u32 height, u32 layers, u32 levels, u32 samples,
if (UseTextureStorage(true))
{
if (layers > 1)
- glTexStorage3DMultisample(target, samples, internal_format, width, height, layers, GL_FALSE);
+ glTexStorage3DMultisample(target, samples, gl_internal_format, width, height, layers, GL_FALSE);
else
- glTexStorage2DMultisample(target, samples, internal_format, width, height, GL_FALSE);
+ glTexStorage2DMultisample(target, samples, gl_internal_format, width, height, GL_FALSE);
}
else
{
if (layers > 1)
- glTexImage3DMultisample(target, samples, internal_format, width, height, layers, GL_FALSE);
+ glTexImage3DMultisample(target, samples, gl_internal_format, width, height, layers, GL_FALSE);
else
- glTexImage2DMultisample(target, samples, internal_format, width, height, GL_FALSE);
+ glTexImage2DMultisample(target, samples, gl_internal_format, width, height, GL_FALSE);
}
}
else
@@ -93,17 +121,17 @@ bool Texture::Create(u32 width, u32 height, u32 layers, u32 levels, u32 samples,
if (UseTextureStorage(false))
{
if (layers > 1)
- glTexStorage3D(target, levels, internal_format, width, height, layers);
+ glTexStorage3D(target, levels, gl_internal_format, width, height, layers);
else
- glTexStorage2D(target, levels, internal_format, width, height);
+ glTexStorage2D(target, levels, gl_internal_format, width, height);
if (data)
{
// TODO: Fix data for mipmaps here.
if (layers > 1)
- glTexSubImage3D(target, 0, 0, 0, 0, width, height, layers, format, type, data);
+ glTexSubImage3D(target, 0, 0, 0, 0, width, height, layers, gl_format, gl_type, data);
else
- glTexSubImage2D(target, 0, 0, 0, width, height, format, type, data);
+ glTexSubImage2D(target, 0, 0, 0, width, height, gl_format, gl_type, data);
}
}
else
@@ -112,17 +140,17 @@ bool Texture::Create(u32 width, u32 height, u32 layers, u32 levels, u32 samples,
{
// TODO: Fix data pointer here.
if (layers > 1)
- glTexImage3D(target, i, internal_format, width, height, layers, 0, format, type, data);
+ glTexImage3D(target, i, gl_internal_format, width, height, layers, 0, gl_format, gl_type, data);
else
- glTexImage2D(target, i, internal_format, width, height, 0, format, type, data);
+ glTexImage2D(target, i, gl_internal_format, width, height, 0, gl_format, gl_type, data);
}
glTexParameteri(target, GL_TEXTURE_BASE_LEVEL, 0);
glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, levels);
}
- glTexParameteri(target, GL_TEXTURE_MIN_FILTER, linear_filter ? GL_LINEAR : GL_NEAREST);
- glTexParameteri(target, GL_TEXTURE_MAG_FILTER, linear_filter ? GL_LINEAR : GL_NEAREST);
+ glTexParameteri(target, GL_TEXTURE_MIN_FILTER, linear ? GL_LINEAR : GL_NEAREST);
+ glTexParameteri(target, GL_TEXTURE_MAG_FILTER, linear ? GL_LINEAR : GL_NEAREST);
glTexParameteri(target, GL_TEXTURE_WRAP_S, wrap ? GL_REPEAT : GL_CLAMP_TO_EDGE);
glTexParameteri(target, GL_TEXTURE_WRAP_T, wrap ? GL_REPEAT : GL_CLAMP_TO_EDGE);
@@ -148,16 +176,16 @@ bool Texture::Create(u32 width, u32 height, u32 layers, u32 levels, u32 samples,
m_id = id;
m_width = static_cast(width);
m_height = static_cast(height);
- m_layers = static_cast(layers);
+ m_layers = static_cast(layers);
m_levels = static_cast(levels);
m_samples = static_cast(samples);
+ m_format = format;
return true;
}
-void Texture::Replace(u32 width, u32 height, GLenum internal_format, GLenum format, GLenum type, const void* data)
+void GL::Texture::Replace(u32 width, u32 height, GLenum internal_format, GLenum format, GLenum type, const void* data)
{
- Assert(IsValid() && width < MAX_DIMENSIONS && height < MAX_DIMENSIONS && m_layers == 1 && m_samples == 1 &&
- m_levels == 1);
+ Assert(IsValid() && width < MAX_WIDTH && height < MAX_HEIGHT && m_layers == 1 && m_samples == 1 && m_levels == 1);
const bool size_changed = (width != m_width || height != m_height);
@@ -186,7 +214,7 @@ void Texture::Replace(u32 width, u32 height, GLenum internal_format, GLenum form
}
}
-void Texture::ReplaceImage(u32 layer, u32 level, GLenum format, GLenum type, const void* data)
+void GL::Texture::ReplaceImage(u32 layer, u32 level, GLenum format, GLenum type, const void* data)
{
Assert(IsValid() && !IsMultisampled());
@@ -197,8 +225,8 @@ void Texture::ReplaceImage(u32 layer, u32 level, GLenum format, GLenum type, con
glTexSubImage2D(target, level, 0, 0, m_width, m_height, format, type, data);
}
-void Texture::ReplaceSubImage(u32 layer, u32 level, u32 x, u32 y, u32 width, u32 height, GLenum format, GLenum type,
- const void* data)
+void GL::Texture::ReplaceSubImage(u32 layer, u32 level, u32 x, u32 y, u32 width, u32 height, GLenum format, GLenum type,
+ const void* data)
{
Assert(IsValid() && !IsMultisampled());
@@ -209,7 +237,7 @@ void Texture::ReplaceSubImage(u32 layer, u32 level, u32 x, u32 y, u32 width, u32
glTexSubImage2D(target, level, x, y, width, height, format, type, data);
}
-void Texture::SetLinearFilter(bool enabled) const
+void GL::Texture::SetLinearFilter(bool enabled) const
{
Assert(!IsMultisampled());
@@ -220,7 +248,17 @@ void Texture::SetLinearFilter(bool enabled) const
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, enabled ? GL_LINEAR : GL_NEAREST);
}
-bool Texture::CreateFramebuffer()
+void GL::Texture::SetWrap(bool enabled) const
+{
+ const GLenum target = GetGLTarget();
+ glTexParameteri(target, GL_TEXTURE_WRAP_S, enabled ? GL_REPEAT : GL_CLAMP_TO_EDGE);
+ glTexParameteri(target, GL_TEXTURE_WRAP_T, enabled ? GL_REPEAT : GL_CLAMP_TO_EDGE);
+
+ if (m_layers > 1)
+ glTexParameteri(target, GL_TEXTURE_WRAP_R, enabled ? GL_REPEAT : GL_CLAMP_TO_EDGE);
+}
+
+bool GL::Texture::CreateFramebuffer()
{
if (!IsValid())
return false;
@@ -244,7 +282,7 @@ bool Texture::CreateFramebuffer()
return true;
}
-void Texture::Destroy()
+void GL::Texture::Destroy()
{
if (m_fbo_id != 0)
{
@@ -257,54 +295,46 @@ void Texture::Destroy()
m_id = 0;
}
- m_width = 0;
- m_height = 0;
- m_layers = 0;
- m_levels = 0;
- m_samples = 0;
+ ClearBaseProperties();
}
-void Texture::Bind() const
+void GL::Texture::Bind() const
{
glBindTexture(GetGLTarget(), m_id);
}
-void Texture::BindFramebuffer(GLenum target /*= GL_DRAW_FRAMEBUFFER*/) const
+void GL::Texture::BindFramebuffer(GLenum target /*= GL_DRAW_FRAMEBUFFER*/) const
{
DebugAssert(m_fbo_id != 0);
glBindFramebuffer(target, m_fbo_id);
}
-void Texture::Unbind() const
+void GL::Texture::Unbind() const
{
glBindTexture(GetGLTarget(), 0);
}
-Texture& Texture::operator=(Texture&& moved)
+GL::Texture& GL::Texture::operator=(Texture&& moved)
{
Destroy();
m_id = moved.m_id;
+ m_fbo_id = moved.m_fbo_id;
m_width = moved.m_width;
m_height = moved.m_height;
m_layers = moved.m_layers;
m_levels = moved.m_levels;
m_samples = moved.m_samples;
- m_fbo_id = moved.m_fbo_id;
moved.m_id = 0;
- moved.m_width = 0;
- moved.m_height = 0;
- moved.m_layers = 0;
- moved.m_levels = 0;
- moved.m_samples = 0;
moved.m_fbo_id = 0;
+ moved.ClearBaseProperties();
return *this;
}
-void Texture::GetTextureSubImage(GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
- GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type,
- GLsizei bufSize, void* pixels)
+void GL::Texture::GetTextureSubImage(GLuint texture, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
+ GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type,
+ GLsizei bufSize, void* pixels)
{
if (GLAD_GL_VERSION_4_5 || GLAD_GL_ARB_get_texture_sub_image)
{
@@ -341,5 +371,3 @@ void Texture::GetTextureSubImage(GLuint texture, GLint level, GLint xoffset, GLi
glBindFramebuffer(target, old_read_fbo);
glDeleteFramebuffers(1, &temp_fbo);
}
-
-} // namespace GL
diff --git a/src/common/gl/texture.h b/src/common/gl/texture.h
index f5fc25b06..2979ec2a3 100644
--- a/src/common/gl/texture.h
+++ b/src/common/gl/texture.h
@@ -1,9 +1,11 @@
#pragma once
-#include "../types.h"
+#include "../gpu_texture.h"
#include "loader.h"
+#include
namespace GL {
-class Texture
+
+class Texture final : public GPUTexture
{
public:
Texture();
@@ -11,29 +13,25 @@ public:
~Texture();
static bool UseTextureStorage(bool multisampled);
+ static const std::tuple& GetPixelFormatMapping(Format format);
+
+ ALWAYS_INLINE GLuint GetGLId() const { return m_id; }
+ bool IsValid() const override { return m_id != 0; }
+
+ bool Create(u32 width, u32 height, u32 layers, u32 levels, u32 samples, Format format, const void* data = nullptr,
+ u32 data_pitch = 0, bool linear = true, bool wrap = true);
+ void Destroy();
- bool Create(u32 width, u32 height, u32 layers, u32 levels, u32 samples, GLenum internal_format, GLenum format,
- GLenum type, const void* data = nullptr, bool linear_filter = false, bool wrap = false);
void Replace(u32 width, u32 height, GLenum internal_format, GLenum format, GLenum type, const void* data);
void ReplaceImage(u32 layer, u32 level, GLenum format, GLenum type, const void* data);
void ReplaceSubImage(u32 layer, u32 level, u32 x, u32 y, u32 width, u32 height, GLenum format, GLenum type,
const void* data);
bool CreateFramebuffer();
- void Destroy();
-
bool UseTextureStorage() const;
- void SetLinearFilter(bool enabled) const;
- ALWAYS_INLINE bool IsValid() const { return m_id != 0; }
- ALWAYS_INLINE bool IsTextureArray() const { return m_layers > 1; }
- ALWAYS_INLINE bool IsMultisampled() const { return m_samples > 1; }
- ALWAYS_INLINE GLuint GetGLId() const { return m_id; }
- ALWAYS_INLINE u16 GetWidth() const { return m_width; }
- ALWAYS_INLINE u16 GetHeight() const { return m_height; }
- ALWAYS_INLINE u16 GetLayers() const { return m_layers; }
- ALWAYS_INLINE u8 GetLevels() const { return m_levels; }
- ALWAYS_INLINE u8 GetSamples() const { return m_samples; }
+ void SetLinearFilter(bool enabled) const;
+ void SetWrap(bool enabled) const;
ALWAYS_INLINE GLuint GetGLFramebufferID() const { return m_fbo_id; }
ALWAYS_INLINE GLenum GetGLTarget() const
@@ -56,12 +54,6 @@ public:
private:
GLuint m_id = 0;
- u16 m_width = 0;
- u16 m_height = 0;
- u16 m_layers = 0;
- u8 m_levels = 0;
- u8 m_samples = 0;
-
GLuint m_fbo_id = 0;
};
diff --git a/src/common/gpu_texture.cpp b/src/common/gpu_texture.cpp
new file mode 100644
index 000000000..5eb4a3688
--- /dev/null
+++ b/src/common/gpu_texture.cpp
@@ -0,0 +1,145 @@
+#include "gpu_texture.h"
+#include "log.h"
+#include "string_util.h"
+Log_SetChannel(GPUTexture);
+
+GPUTexture::GPUTexture() = default;
+
+GPUTexture::GPUTexture(u16 width, u16 height, u8 layers, u8 levels, u8 samples, GPUTexture::Format format)
+ : m_width(width), m_height(height), m_layers(layers), m_levels(levels), m_samples(samples), m_format(format)
+{
+}
+
+GPUTexture::~GPUTexture() = default;
+
+void GPUTexture::ClearBaseProperties()
+{
+ m_width = 0;
+ m_height = 0;
+ m_layers = 0;
+ m_levels = 0;
+ m_samples = 0;
+ m_format = GPUTexture::Format::Unknown;
+}
+
+u32 GPUTexture::GPUTexture::GetPixelSize(GPUTexture::Format format)
+{
+ switch (format)
+ {
+ case Format::RGBA8:
+ case Format::BGRA8:
+ return 4;
+
+ case Format::RGBA5551:
+ case Format::RGB565:
+ case Format::D16:
+ return 2;
+
+ case Format::R8:
+ return 1;
+
+ default:
+ return 0;
+ }
+}
+
+bool GPUTexture::IsDepthFormat(Format format)
+{
+ return (format == Format::D16);
+}
+
+bool GPUTexture::ConvertTextureDataToRGBA8(u32 width, u32 height, std::vector& texture_data,
+ u32& texture_data_stride, GPUTexture::Format format)
+{
+ switch (format)
+ {
+ case GPUTexture::Format::BGRA8:
+ {
+ for (u32 y = 0; y < height; y++)
+ {
+ u32* pixels = reinterpret_cast(reinterpret_cast(texture_data.data()) + (y * texture_data_stride));
+ for (u32 x = 0; x < width; x++)
+ pixels[x] = (pixels[x] & 0xFF00FF00) | ((pixels[x] & 0xFF) << 16) | ((pixels[x] >> 16) & 0xFF);
+ }
+
+ return true;
+ }
+
+ case GPUTexture::Format::RGBA8:
+ return true;
+
+ case GPUTexture::Format::RGB565:
+ {
+ std::vector temp(width * height);
+
+ for (u32 y = 0; y < height; y++)
+ {
+ const u8* pixels_in = reinterpret_cast(texture_data.data()) + (y * texture_data_stride);
+ u32* pixels_out = &temp[y * width];
+
+ for (u32 x = 0; x < width; x++)
+ {
+ // RGB565 -> RGBA8
+ u16 pixel_in;
+ std::memcpy(&pixel_in, pixels_in, sizeof(u16));
+ pixels_in += sizeof(u16);
+ const u8 r5 = Truncate8(pixel_in >> 11);
+ const u8 g6 = Truncate8((pixel_in >> 5) & 0x3F);
+ const u8 b5 = Truncate8(pixel_in & 0x1F);
+ *(pixels_out++) = ZeroExtend32((r5 << 3) | (r5 & 7)) | (ZeroExtend32((g6 << 2) | (g6 & 3)) << 8) |
+ (ZeroExtend32((b5 << 3) | (b5 & 7)) << 16) | (0xFF000000u);
+ }
+ }
+
+ texture_data = std::move(temp);
+ texture_data_stride = sizeof(u32) * width;
+ return true;
+ }
+
+ case GPUTexture::Format::RGBA5551:
+ {
+ std::vector temp(width * height);
+
+ for (u32 y = 0; y < height; y++)
+ {
+ const u8* pixels_in = reinterpret_cast(texture_data.data()) + (y * texture_data_stride);
+ u32* pixels_out = &temp[y * width];
+
+ for (u32 x = 0; x < width; x++)
+ {
+ // RGBA5551 -> RGBA8
+ u16 pixel_in;
+ std::memcpy(&pixel_in, pixels_in, sizeof(u16));
+ pixels_in += sizeof(u16);
+ const u8 a1 = Truncate8(pixel_in >> 15);
+ const u8 r5 = Truncate8((pixel_in >> 10) & 0x1F);
+ const u8 g6 = Truncate8((pixel_in >> 5) & 0x1F);
+ const u8 b5 = Truncate8(pixel_in & 0x1F);
+ *(pixels_out++) = ZeroExtend32((r5 << 3) | (r5 & 7)) | (ZeroExtend32((g6 << 3) | (g6 & 7)) << 8) |
+ (ZeroExtend32((b5 << 3) | (b5 & 7)) << 16) | (a1 ? 0xFF000000u : 0u);
+ }
+ }
+
+ texture_data = std::move(temp);
+ texture_data_stride = sizeof(u32) * width;
+ return true;
+ }
+
+ default:
+ Log_ErrorPrintf("Unknown pixel format %u", static_cast(format));
+ return false;
+ }
+}
+
+void GPUTexture::FlipTextureDataRGBA8(u32 width, u32 height, std::vector& texture_data, u32 texture_data_stride)
+{
+ std::vector temp(width);
+ for (u32 flip_row = 0; flip_row < (height / 2); flip_row++)
+ {
+ u32* top_ptr = &texture_data[flip_row * width];
+ u32* bottom_ptr = &texture_data[((height - 1) - flip_row) * width];
+ std::memcpy(temp.data(), top_ptr, texture_data_stride);
+ std::memcpy(top_ptr, bottom_ptr, texture_data_stride);
+ std::memcpy(bottom_ptr, temp.data(), texture_data_stride);
+ }
+}
\ No newline at end of file
diff --git a/src/common/gpu_texture.h b/src/common/gpu_texture.h
new file mode 100644
index 000000000..3ae3a6dcd
--- /dev/null
+++ b/src/common/gpu_texture.h
@@ -0,0 +1,68 @@
+#pragma once
+#include "types.h"
+#include
+#include
+
+class GPUTexture
+{
+public:
+ enum : u32
+ {
+ MAX_WIDTH = 65535,
+ MAX_HEIGHT = 65535,
+ MAX_LAYERS = 255,
+ MAX_LEVELS = 255,
+ MAX_SAMPLES = 255,
+ };
+
+ enum class Format : u8
+ {
+ Unknown,
+ RGBA8,
+ BGRA8,
+ RGB565,
+ RGBA5551,
+ R8,
+ D16,
+ Count
+ };
+
+public:
+ virtual ~GPUTexture();
+
+ ALWAYS_INLINE u32 GetWidth() const { return m_width; }
+ ALWAYS_INLINE u32 GetHeight() const { return m_height; }
+ ALWAYS_INLINE u32 GetLayers() const { return m_layers; }
+ ALWAYS_INLINE u32 GetLevels() const { return m_levels; }
+ ALWAYS_INLINE u32 GetSamples() const { return m_samples; }
+ ALWAYS_INLINE GPUTexture::Format GetFormat() const { return m_format; }
+
+ ALWAYS_INLINE bool IsTextureArray() const { return m_layers > 1; }
+ ALWAYS_INLINE bool IsMultisampled() const { return m_samples > 1; }
+
+ ALWAYS_INLINE u32 GetPixelSize() const { return GetPixelSize(m_format); }
+ ALWAYS_INLINE u32 GetMipWidth(u32 level) const { return std::max(m_width >> level, 1u); }
+ ALWAYS_INLINE u32 GetMipHeight(u32 level) const { return std::max(m_height >> level, 1u); }
+
+ virtual bool IsValid() const = 0;
+
+ static u32 GetPixelSize(GPUTexture::Format format);
+ static bool IsDepthFormat(GPUTexture::Format format);
+
+ static bool ConvertTextureDataToRGBA8(u32 width, u32 height, std::vector& texture_data, u32& texture_data_stride,
+ GPUTexture::Format format);
+ static void FlipTextureDataRGBA8(u32 width, u32 height, std::vector& texture_data, u32 texture_data_stride);
+
+protected:
+ GPUTexture();
+ GPUTexture(u16 width, u16 height, u8 layers, u8 levels, u8 samples, Format format);
+
+ void ClearBaseProperties();
+
+ u16 m_width = 0;
+ u16 m_height = 0;
+ u8 m_layers = 0;
+ u8 m_levels = 0;
+ u8 m_samples = 0;
+ Format m_format = Format::Unknown;
+};
diff --git a/src/common/vulkan/texture.cpp b/src/common/vulkan/texture.cpp
index f3db36ae7..2419380f0 100644
--- a/src/common/vulkan/texture.cpp
+++ b/src/common/vulkan/texture.cpp
@@ -8,22 +8,26 @@
#include
Log_SetChannel(Texture);
+static constexpr std::array(GPUTexture::Format::Count)> s_vk_mapping = {
+ {VK_FORMAT_UNDEFINED, VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_B8G8R8A8_UNORM, VK_FORMAT_R5G6B5_UNORM_PACK16,
+ VK_FORMAT_A1R5G5B5_UNORM_PACK16, VK_FORMAT_R8_UNORM, VK_FORMAT_D16_UNORM}};
+
static constexpr VkComponentMapping s_identity_swizzle{VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY};
Vulkan::Texture::Texture() = default;
Vulkan::Texture::Texture(Texture&& move)
- : m_width(move.m_width), m_height(move.m_height), m_levels(move.m_levels), m_layers(move.m_layers),
- m_format(move.m_format), m_samples(move.m_samples), m_view_type(move.m_view_type), m_layout(move.m_layout),
- m_image(move.m_image), m_allocation(move.m_allocation), m_view(move.m_view)
+ : m_view_type(move.m_view_type), m_layout(move.m_layout), m_image(move.m_image), m_allocation(move.m_allocation),
+ m_view(move.m_view)
{
- move.m_width = 0;
- move.m_height = 0;
- move.m_levels = 0;
- move.m_layers = 0;
- move.m_format = VK_FORMAT_UNDEFINED;
- move.m_samples = VK_SAMPLE_COUNT_1_BIT;
+ m_width = move.m_width;
+ m_height = move.m_height;
+ m_layers = move.m_layers;
+ m_levels = move.m_levels;
+ m_samples = move.m_samples;
+
+ move.ClearBaseProperties();
move.m_view_type = VK_IMAGE_VIEW_TYPE_2D;
move.m_layout = VK_IMAGE_LAYOUT_UNDEFINED;
move.m_image = VK_NULL_HANDLE;
@@ -37,6 +41,26 @@ Vulkan::Texture::~Texture()
Destroy(true);
}
+VkFormat Vulkan::Texture::GetVkFormat(Format format)
+{
+ return s_vk_mapping[static_cast(format)];
+}
+
+GPUTexture::Format Vulkan::Texture::LookupBaseFormat(VkFormat vformat)
+{
+ for (u32 i = 0; i < static_cast(s_vk_mapping.size()); i++)
+ {
+ if (s_vk_mapping[i] == vformat)
+ return static_cast(i);
+ }
+ return GPUTexture::Format::Unknown;
+}
+
+bool Vulkan::Texture::IsValid() const
+{
+ return (m_image != VK_NULL_HANDLE);
+}
+
Vulkan::Texture& Vulkan::Texture::operator=(Texture&& move)
{
if (IsValid())
@@ -129,12 +153,12 @@ bool Vulkan::Texture::Create(u32 width, u32 height, u32 levels, u32 layers, VkFo
if (IsValid())
Destroy(true);
- m_width = width;
- m_height = height;
- m_levels = levels;
- m_layers = layers;
- m_format = format;
- m_samples = samples;
+ m_width = static_cast(width);
+ m_height = static_cast(height);
+ m_levels = static_cast(levels);
+ m_layers = static_cast(layers);
+ m_samples = static_cast(samples);
+ m_format = LookupBaseFormat(format);
m_view_type = view_type;
m_image = image;
m_allocation = allocation;
@@ -171,12 +195,12 @@ bool Vulkan::Texture::Adopt(VkImage existing_image, VkImageViewType view_type, u
if (IsValid())
Destroy(true);
- m_width = width;
- m_height = height;
- m_levels = levels;
- m_layers = layers;
- m_format = format;
- m_samples = samples;
+ m_width = static_cast(width);
+ m_height = static_cast(height);
+ m_levels = static_cast(levels);
+ m_layers = static_cast(layers);
+ m_format = LookupBaseFormat(format);
+ m_samples = static_cast(samples);
m_view_type = view_type;
m_image = existing_image;
m_view = view;
@@ -206,11 +230,7 @@ void Vulkan::Texture::Destroy(bool defer /* = true */)
m_allocation = VK_NULL_HANDLE;
}
- m_width = 0;
- m_height = 0;
- m_levels = 0;
- m_layers = 0;
- m_format = VK_FORMAT_UNDEFINED;
+ ClearBaseProperties();
m_samples = VK_SAMPLE_COUNT_1_BIT;
m_view_type = VK_IMAGE_VIEW_TYPE_2D;
m_layout = VK_IMAGE_LAYOUT_UNDEFINED;
@@ -252,8 +272,7 @@ void Vulkan::Texture::TransitionSubresourcesToLayout(VkCommandBuffer command_buf
VK_QUEUE_FAMILY_IGNORED, // uint32_t srcQueueFamilyIndex
VK_QUEUE_FAMILY_IGNORED, // uint32_t dstQueueFamilyIndex
m_image, // VkImage image
- {static_cast(Util::IsDepthFormat(m_format) ? VK_IMAGE_ASPECT_DEPTH_BIT :
- VK_IMAGE_ASPECT_COLOR_BIT),
+ {static_cast(IsDepthFormat(m_format) ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT),
start_level, num_levels, start_layer, num_layers} // VkImageSubresourceRange subresourceRange
};
@@ -392,13 +411,12 @@ void Vulkan::Texture::UpdateFromBuffer(VkCommandBuffer cmdbuf, u32 level, u32 la
u32 Vulkan::Texture::CalcUpdatePitch(u32 width) const
{
- return Common::AlignUp(width * Vulkan::Util::GetTexelSize(m_format),
- g_vulkan_context->GetBufferCopyRowPitchAlignment());
+ return Common::AlignUp(width * GetPixelSize(), g_vulkan_context->GetBufferCopyRowPitchAlignment());
}
u32 Vulkan::Texture::CalcUpdateRowLength(u32 pitch) const
{
- return pitch / Vulkan::Util::GetTexelSize(m_format);
+ return pitch / GetPixelSize();
}
bool Vulkan::Texture::BeginUpdate(u32 width, u32 height, void** out_buffer, u32* out_pitch)
diff --git a/src/common/vulkan/texture.h b/src/common/vulkan/texture.h
index 5f72bd30a..8aea75e77 100644
--- a/src/common/vulkan/texture.h
+++ b/src/common/vulkan/texture.h
@@ -1,11 +1,12 @@
#pragma once
-#include "../types.h"
+#include "../gpu_texture.h"
#include "loader.h"
#include
#include
namespace Vulkan {
-class Texture
+
+class Texture final : public GPUTexture
{
public:
Texture();
@@ -16,7 +17,10 @@ public:
Texture& operator=(Texture&& move);
Texture& operator=(const Texture&) = delete;
- ALWAYS_INLINE bool IsValid() const { return (m_image != VK_NULL_HANDLE); }
+ static VkFormat GetVkFormat(Format format);
+ static Format LookupBaseFormat(VkFormat vformat);
+
+ bool IsValid() const override;
/// An image is considered owned/managed if we control the memory.
ALWAYS_INLINE bool IsOwned() const { return (m_allocation != VK_NULL_HANDLE); }
@@ -25,10 +29,9 @@ public:
ALWAYS_INLINE u32 GetHeight() const { return m_height; }
ALWAYS_INLINE u32 GetLevels() const { return m_levels; }
ALWAYS_INLINE u32 GetLayers() const { return m_layers; }
- ALWAYS_INLINE u32 GetMipWidth(u32 level) const { return std::max(m_width >> level, 1u); }
- ALWAYS_INLINE u32 GetMipHeight(u32 level) const { return std::max(m_height >> level, 1u); }
- ALWAYS_INLINE VkFormat GetFormat() const { return m_format; }
- ALWAYS_INLINE VkSampleCountFlagBits GetSamples() const { return m_samples; }
+
+ ALWAYS_INLINE VkFormat GetVkFormat() const { return GetVkFormat(m_format); }
+ ALWAYS_INLINE VkSampleCountFlagBits GetVkSamples() const { return static_cast(m_samples); }
ALWAYS_INLINE VkImageLayout GetLayout() const { return m_layout; }
ALWAYS_INLINE VkImageViewType GetViewType() const { return m_view_type; }
ALWAYS_INLINE VkImage GetImage() const { return m_image; }
@@ -65,12 +68,6 @@ public:
bool Update(u32 x, u32 y, u32 width, u32 height, u32 level, u32 layer, const void* data, u32 data_pitch);
private:
- u32 m_width = 0;
- u32 m_height = 0;
- u32 m_levels = 0;
- u32 m_layers = 0;
- VkFormat m_format = VK_FORMAT_UNDEFINED;
- VkSampleCountFlagBits m_samples = VK_SAMPLE_COUNT_1_BIT;
VkImageViewType m_view_type = VK_IMAGE_VIEW_TYPE_2D;
VkImageLayout m_layout = VK_IMAGE_LAYOUT_UNDEFINED;
diff --git a/src/core/gpu.cpp b/src/core/gpu.cpp
index 7c68d9ac1..84bd33271 100644
--- a/src/core/gpu.cpp
+++ b/src/core/gpu.cpp
@@ -163,7 +163,7 @@ void GPU::SoftReset()
UpdateGPUIdle();
}
-bool GPU::DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool update_display)
+bool GPU::DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_display)
{
if (sw.IsReading())
{
diff --git a/src/core/gpu.h b/src/core/gpu.h
index 69906598a..40b0ef460 100644
--- a/src/core/gpu.h
+++ b/src/core/gpu.h
@@ -15,7 +15,7 @@
class StateWrapper;
class HostDisplay;
-class HostDisplayTexture;
+class GPUTexture;
class TimingEvent;
class Timers;
@@ -83,7 +83,7 @@ public:
virtual bool Initialize();
virtual void Reset(bool clear_vram);
- virtual bool DoState(StateWrapper& sw, HostDisplayTexture** save_to_texture, bool update_display);
+ virtual bool DoState(StateWrapper& sw, GPUTexture** save_to_texture, bool update_display);
// Graphics API state reset/restore - call when drawing the UI etc.
virtual void ResetGraphicsAPIState();
diff --git a/src/core/gpu_hw.cpp b/src/core/gpu_hw.cpp
index 41b4d9833..1e2c34ae4 100644
--- a/src/core/gpu_hw.cpp
+++ b/src/core/gpu_hw.cpp
@@ -123,7 +123,7 @@ void GPU_HW::Reset(bool clear_vram)
SetFullVRAMDirtyRectangle();
}
-bool GPU_HW::DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool update_display)
+bool GPU_HW::DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_display)
{
if (!GPU::DoState(sw, host_texture, update_display))
return false;
diff --git a/src/core/gpu_hw.h b/src/core/gpu_hw.h
index 45d211557..8deebce53 100644
--- a/src/core/gpu_hw.h
+++ b/src/core/gpu_hw.h
@@ -37,7 +37,7 @@ public:
virtual bool Initialize() override;
virtual void Reset(bool clear_vram) override;
- virtual bool DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool update_display) override;
+ virtual bool DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_display) override;
void UpdateResolutionScale() override final;
std::tuple GetEffectiveDisplayResolution(bool scaled = true) override final;
diff --git a/src/core/gpu_hw_d3d11.cpp b/src/core/gpu_hw_d3d11.cpp
index 9007794e0..b6794b7b0 100644
--- a/src/core/gpu_hw_d3d11.cpp
+++ b/src/core/gpu_hw_d3d11.cpp
@@ -99,13 +99,13 @@ void GPU_HW_D3D11::Reset(bool clear_vram)
ClearFramebuffer();
}
-bool GPU_HW_D3D11::DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool update_display)
+bool GPU_HW_D3D11::DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_display)
{
if (host_texture)
{
ComPtr resource;
- HostDisplayTexture* tex = *host_texture;
+ D3D11::Texture* tex = static_cast(*host_texture);
if (sw.IsReading())
{
if (tex->GetWidth() != m_vram_texture.GetWidth() || tex->GetHeight() != m_vram_texture.GetHeight() ||
@@ -114,8 +114,7 @@ bool GPU_HW_D3D11::DoState(StateWrapper& sw, HostDisplayTexture** host_texture,
return false;
}
- static_cast(tex->GetHandle())->GetResource(resource.GetAddressOf());
- m_context->CopySubresourceRegion(m_vram_texture.GetD3DTexture(), 0, 0, 0, 0, resource.Get(), 0, nullptr);
+ m_context->CopySubresourceRegion(m_vram_texture.GetD3DTexture(), 0, 0, 0, 0, tex->GetD3DTexture(), 0, nullptr);
}
else
{
@@ -124,17 +123,17 @@ bool GPU_HW_D3D11::DoState(StateWrapper& sw, HostDisplayTexture** host_texture,
{
delete tex;
- tex = g_host_display
- ->CreateTexture(m_vram_texture.GetWidth(), m_vram_texture.GetHeight(), 1, 1,
- m_vram_texture.GetSamples(), HostDisplayPixelFormat::RGBA8, nullptr, 0, false)
- .release();
+ tex = static_cast(g_host_display
+ ->CreateTexture(m_vram_texture.GetWidth(), m_vram_texture.GetHeight(), 1,
+ 1, m_vram_texture.GetSamples(), GPUTexture::Format::RGBA8,
+ nullptr, 0, false)
+ .release());
*host_texture = tex;
if (!tex)
return false;
}
- static_cast(tex->GetHandle())->GetResource(resource.GetAddressOf());
- m_context->CopySubresourceRegion(resource.Get(), 0, 0, 0, 0, m_vram_texture.GetD3DTexture(), 0, nullptr);
+ m_context->CopySubresourceRegion(tex->GetD3DTexture(), 0, 0, 0, 0, m_vram_texture.GetD3DTexture(), 0, nullptr);
}
}
@@ -254,9 +253,9 @@ bool GPU_HW_D3D11::CreateFramebuffer()
// scale vram size to internal resolution
const u32 texture_width = VRAM_WIDTH * m_resolution_scale;
const u32 texture_height = VRAM_HEIGHT * m_resolution_scale;
- const u16 samples = static_cast(m_multisamples);
- const DXGI_FORMAT texture_format = DXGI_FORMAT_R8G8B8A8_UNORM;
- const DXGI_FORMAT depth_format = DXGI_FORMAT_D16_UNORM;
+ const u8 samples = static_cast(m_multisamples);
+ const GPUTexture::Format texture_format = GPUTexture::Format::RGBA8;
+ const GPUTexture::Format depth_format = GPUTexture::Format::D16;
if (!m_vram_texture.Create(m_device.Get(), texture_width, texture_height, 1, 1, samples, texture_format,
D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET) ||
@@ -275,8 +274,9 @@ bool GPU_HW_D3D11::CreateFramebuffer()
return false;
}
- const CD3D11_DEPTH_STENCIL_VIEW_DESC depth_view_desc(
- samples > 1 ? D3D11_DSV_DIMENSION_TEXTURE2DMS : D3D11_DSV_DIMENSION_TEXTURE2D, depth_format);
+ const CD3D11_DEPTH_STENCIL_VIEW_DESC depth_view_desc(samples > 1 ? D3D11_DSV_DIMENSION_TEXTURE2DMS :
+ D3D11_DSV_DIMENSION_TEXTURE2D,
+ D3D11::Texture::GetDXGIFormat(depth_format));
HRESULT hr =
m_device->CreateDepthStencilView(m_vram_depth_texture, &depth_view_desc, m_vram_depth_view.GetAddressOf());
if (FAILED(hr))
@@ -289,7 +289,7 @@ bool GPU_HW_D3D11::CreateFramebuffer()
if (!m_downsample_texture.Create(m_device.Get(), texture_width, texture_height, 1, static_cast(levels), 1,
texture_format, D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET) ||
!m_downsample_weight_texture.Create(m_device.Get(), texture_width >> (levels - 1),
- texture_height >> (levels - 1), 1, 1, 1, DXGI_FORMAT_R8_UNORM,
+ texture_height >> (levels - 1), 1, 1, 1, GPUTexture::Format::R8,
D3D11_BIND_SHADER_RESOURCE | D3D11_BIND_RENDER_TARGET))
{
return false;
@@ -299,9 +299,9 @@ bool GPU_HW_D3D11::CreateFramebuffer()
for (u32 i = 0; i < levels; i++)
{
const CD3D11_SHADER_RESOURCE_VIEW_DESC srv_desc(m_downsample_texture, D3D11_SRV_DIMENSION_TEXTURE2D,
- texture_format, i, 1);
- const CD3D11_RENDER_TARGET_VIEW_DESC rtv_desc(m_downsample_texture, D3D11_RTV_DIMENSION_TEXTURE2D, texture_format,
- i, 1);
+ m_downsample_texture.GetDXGIFormat(), i, 1);
+ const CD3D11_RENDER_TARGET_VIEW_DESC rtv_desc(m_downsample_texture, D3D11_RTV_DIMENSION_TEXTURE2D,
+ m_downsample_texture.GetDXGIFormat(), i, 1);
hr = m_device->CreateShaderResourceView(m_downsample_texture, &srv_desc,
m_downsample_mip_views[i].first.GetAddressOf());
@@ -749,7 +749,7 @@ bool GPU_HW_D3D11::BlitVRAMReplacementTexture(const TextureReplacementTexture* t
m_vram_replacement_texture.GetHeight() < tex->GetHeight())
{
if (!m_vram_replacement_texture.Create(m_device.Get(), tex->GetWidth(), tex->GetHeight(), 1, 1, 1,
- DXGI_FORMAT_R8G8B8A8_UNORM, D3D11_BIND_SHADER_RESOURCE, tex->GetPixels(),
+ GPUTexture::Format::RGBA8, D3D11_BIND_SHADER_RESOURCE, tex->GetPixels(),
tex->GetPitch(), true))
{
return false;
@@ -841,15 +841,12 @@ void GPU_HW_D3D11::UpdateDisplay()
if (IsUsingMultisampling())
{
UpdateVRAMReadTexture();
- g_host_display->SetDisplayTexture(&m_vram_read_texture, HostDisplayPixelFormat::RGBA8,
- m_vram_read_texture.GetWidth(), m_vram_read_texture.GetHeight(), 0, 0,
- m_vram_read_texture.GetWidth(), m_vram_read_texture.GetHeight());
+ g_host_display->SetDisplayTexture(&m_vram_read_texture, 0, 0, m_vram_read_texture.GetWidth(),
+ m_vram_read_texture.GetHeight());
}
else
{
- g_host_display->SetDisplayTexture(&m_vram_texture, HostDisplayPixelFormat::RGBA8, m_vram_texture.GetWidth(),
- m_vram_texture.GetHeight(), 0, 0, m_vram_texture.GetWidth(),
- m_vram_texture.GetHeight());
+ g_host_display->SetDisplayTexture(&m_vram_texture, 0, 0, m_vram_texture.GetWidth(), m_vram_texture.GetHeight());
}
g_host_display->SetDisplayParameters(VRAM_WIDTH, VRAM_HEIGHT, 0, 0, VRAM_WIDTH, VRAM_HEIGHT,
@@ -889,8 +886,7 @@ void GPU_HW_D3D11::UpdateDisplay()
}
else
{
- g_host_display->SetDisplayTexture(&m_vram_texture, HostDisplayPixelFormat::RGBA8, m_vram_texture.GetWidth(),
- m_vram_texture.GetHeight(), scaled_vram_offset_x, scaled_vram_offset_y,
+ g_host_display->SetDisplayTexture(&m_vram_texture, scaled_vram_offset_x, scaled_vram_offset_y,
scaled_display_width, scaled_display_height);
}
}
@@ -916,15 +912,9 @@ void GPU_HW_D3D11::UpdateDisplay()
DrawUtilityShader(display_pixel_shader, uniforms, sizeof(uniforms));
if (IsUsingDownsampling())
- {
DownsampleFramebuffer(m_display_texture, 0, 0, scaled_display_width, scaled_display_height);
- }
else
- {
- g_host_display->SetDisplayTexture(&m_display_texture, HostDisplayPixelFormat::RGBA8,
- m_display_texture.GetWidth(), m_display_texture.GetHeight(), 0, 0,
- scaled_display_width, scaled_display_height);
- }
+ g_host_display->SetDisplayTexture(&m_display_texture, 0, 0, scaled_display_width, scaled_display_height);
RestoreGraphicsAPIState();
}
@@ -954,9 +944,9 @@ void GPU_HW_D3D11::ReadVRAM(u32 x, u32 y, u32 width, u32 height)
DrawUtilityShader(m_vram_read_pixel_shader.Get(), uniforms, sizeof(uniforms));
// Stage the readback and copy it into our shadow buffer.
- g_host_display->DownloadTexture(
- &m_vram_encoding_texture, HostDisplayPixelFormat::RGBA8, 0, 0, encoded_width, encoded_height,
- reinterpret_cast(&m_vram_shadow[copy_rect.top * VRAM_WIDTH + copy_rect.left]), VRAM_WIDTH * sizeof(u16));
+ g_host_display->DownloadTexture(&m_vram_encoding_texture, 0, 0, encoded_width, encoded_height,
+ reinterpret_cast(&m_vram_shadow[copy_rect.top * VRAM_WIDTH + copy_rect.left]),
+ VRAM_WIDTH * sizeof(u16));
RestoreGraphicsAPIState();
}
@@ -1080,7 +1070,7 @@ void GPU_HW_D3D11::UpdateVRAMReadTexture()
if (m_vram_texture.IsMultisampled())
{
m_context->ResolveSubresource(m_vram_read_texture.GetD3DTexture(), 0, m_vram_texture.GetD3DTexture(), 0,
- m_vram_texture.GetFormat());
+ m_vram_texture.GetDXGIFormat());
}
else
{
@@ -1191,8 +1181,7 @@ void GPU_HW_D3D11::DownsampleFramebufferAdaptive(D3D11::Texture& source, u32 lef
RestoreGraphicsAPIState();
- g_host_display->SetDisplayTexture(&m_display_texture, HostDisplayPixelFormat::RGBA8, m_display_texture.GetWidth(),
- m_display_texture.GetHeight(), left, top, width, height);
+ g_host_display->SetDisplayTexture(&m_display_texture, left, top, width, height);
}
void GPU_HW_D3D11::DownsampleFramebufferBoxFilter(D3D11::Texture& source, u32 left, u32 top, u32 width, u32 height)
@@ -1215,9 +1204,7 @@ void GPU_HW_D3D11::DownsampleFramebufferBoxFilter(D3D11::Texture& source, u32 le
RestoreGraphicsAPIState();
- g_host_display->SetDisplayTexture(&m_downsample_texture, HostDisplayPixelFormat::RGBA8,
- m_downsample_texture.GetWidth(), m_downsample_texture.GetHeight(), ds_left, ds_top,
- ds_width, ds_height);
+ g_host_display->SetDisplayTexture(&m_downsample_texture, ds_left, ds_top, ds_width, ds_height);
}
std::unique_ptr GPU::CreateHardwareD3D11Renderer()
diff --git a/src/core/gpu_hw_d3d11.h b/src/core/gpu_hw_d3d11.h
index 78eec6316..0a427c474 100644
--- a/src/core/gpu_hw_d3d11.h
+++ b/src/core/gpu_hw_d3d11.h
@@ -23,7 +23,7 @@ public:
bool Initialize() override;
void Reset(bool clear_vram) override;
- bool DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool update_display) override;
+ bool DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_display) override;
void ResetGraphicsAPIState() override;
void RestoreGraphicsAPIState() override;
diff --git a/src/core/gpu_hw_d3d12.cpp b/src/core/gpu_hw_d3d12.cpp
index 296b92f7e..277e380b0 100644
--- a/src/core/gpu_hw_d3d12.cpp
+++ b/src/core/gpu_hw_d3d12.cpp
@@ -319,16 +319,16 @@ bool GPU_HW_D3D12::CreateFramebuffer()
const DXGI_FORMAT texture_format = DXGI_FORMAT_R8G8B8A8_UNORM;
const DXGI_FORMAT depth_format = DXGI_FORMAT_D16_UNORM;
- if (!m_vram_texture.Create(texture_width, texture_height, m_multisamples, texture_format, texture_format,
+ if (!m_vram_texture.Create(texture_width, texture_height, 1, 1, m_multisamples, texture_format, texture_format,
texture_format, DXGI_FORMAT_UNKNOWN, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET) ||
!m_vram_depth_texture.Create(
- texture_width, texture_height, m_multisamples, depth_format, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN,
+ texture_width, texture_height, 1, 1, m_multisamples, depth_format, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN,
depth_format, D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL | D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE) ||
- !m_vram_read_texture.Create(texture_width, texture_height, 1, texture_format, texture_format, DXGI_FORMAT_UNKNOWN,
- DXGI_FORMAT_UNKNOWN, D3D12_RESOURCE_FLAG_NONE) ||
- !m_display_texture.Create(texture_width, texture_height, 1, texture_format, texture_format, texture_format,
+ !m_vram_read_texture.Create(texture_width, texture_height, 1, 1, 1, texture_format, texture_format,
+ DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN, D3D12_RESOURCE_FLAG_NONE) ||
+ !m_display_texture.Create(texture_width, texture_height, 1, 1, 1, texture_format, texture_format, texture_format,
DXGI_FORMAT_UNKNOWN, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET) ||
- !m_vram_readback_texture.Create(VRAM_WIDTH, VRAM_HEIGHT, 1, texture_format, texture_format, texture_format,
+ !m_vram_readback_texture.Create(VRAM_WIDTH, VRAM_HEIGHT, 1, 1, 1, texture_format, texture_format, texture_format,
DXGI_FORMAT_UNKNOWN, D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET) ||
!m_vram_readback_staging_texture.Create(VRAM_WIDTH / 2, VRAM_HEIGHT, texture_format, false))
{
@@ -476,8 +476,8 @@ bool GPU_HW_D3D12::CompilePipelines()
const bool textured = (static_cast(texture_mode) != GPUTextureMode::Disabled);
gpbuilder.SetRootSignature(m_batch_root_signature.Get());
- gpbuilder.SetRenderTarget(0, m_vram_texture.GetFormat());
- gpbuilder.SetDepthStencilFormat(m_vram_depth_texture.GetFormat());
+ gpbuilder.SetRenderTarget(0, m_vram_texture.GetDXGIFormat());
+ gpbuilder.SetDepthStencilFormat(m_vram_depth_texture.GetDXGIFormat());
gpbuilder.AddVertexAttribute("ATTR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, offsetof(BatchVertex, x));
gpbuilder.AddVertexAttribute("ATTR", 1, DXGI_FORMAT_R8G8B8A8_UNORM, 0, offsetof(BatchVertex, color));
@@ -547,16 +547,16 @@ bool GPU_HW_D3D12::CompilePipelines()
// common state
gpbuilder.SetRootSignature(m_single_sampler_root_signature.Get());
- gpbuilder.SetRenderTarget(0, m_vram_texture.GetFormat());
- gpbuilder.SetDepthStencilFormat(m_vram_depth_texture.GetFormat());
+ gpbuilder.SetRenderTarget(0, m_vram_texture.GetDXGIFormat());
+ gpbuilder.SetDepthStencilFormat(m_vram_depth_texture.GetDXGIFormat());
gpbuilder.SetPrimitiveTopologyType(D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE);
gpbuilder.SetNoCullRasterizationState();
gpbuilder.SetNoDepthTestState();
gpbuilder.SetNoBlendingState();
gpbuilder.SetVertexShader(fullscreen_quad_vertex_shader.Get());
gpbuilder.SetMultisamples(m_multisamples);
- gpbuilder.SetRenderTarget(0, m_vram_texture.GetFormat());
- gpbuilder.SetDepthStencilFormat(m_vram_depth_texture.GetFormat());
+ gpbuilder.SetRenderTarget(0, m_vram_texture.GetDXGIFormat());
+ gpbuilder.SetDepthStencilFormat(m_vram_depth_texture.GetDXGIFormat());
// VRAM fill
for (u8 wrapped = 0; wrapped < 2; wrapped++)
@@ -663,7 +663,7 @@ bool GPU_HW_D3D12::CompilePipelines()
gpbuilder.SetNoCullRasterizationState();
gpbuilder.SetNoDepthTestState();
gpbuilder.SetNoBlendingState();
- gpbuilder.SetRenderTarget(0, m_vram_readback_texture.GetFormat());
+ gpbuilder.SetRenderTarget(0, m_vram_readback_texture.GetDXGIFormat());
gpbuilder.ClearDepthStencilFormat();
m_vram_readback_pipeline = gpbuilder.Create(g_d3d12_context->GetDevice(), shader_cache, false);
@@ -685,7 +685,7 @@ bool GPU_HW_D3D12::CompilePipelines()
gpbuilder.SetNoCullRasterizationState();
gpbuilder.SetNoDepthTestState();
gpbuilder.SetNoBlendingState();
- gpbuilder.SetRenderTarget(0, m_display_texture.GetFormat());
+ gpbuilder.SetRenderTarget(0, m_display_texture.GetDXGIFormat());
for (u8 depth_24 = 0; depth_24 < 2; depth_24++)
{
@@ -775,7 +775,7 @@ bool GPU_HW_D3D12::BlitVRAMReplacementTexture(const TextureReplacementTexture* t
if (m_vram_write_replacement_texture.GetWidth() < tex->GetWidth() ||
m_vram_write_replacement_texture.GetHeight() < tex->GetHeight())
{
- if (!m_vram_write_replacement_texture.Create(tex->GetWidth(), tex->GetHeight(), 1, DXGI_FORMAT_R8G8B8A8_UNORM,
+ if (!m_vram_write_replacement_texture.Create(tex->GetWidth(), tex->GetHeight(), 1, 1, 1, DXGI_FORMAT_R8G8B8A8_UNORM,
DXGI_FORMAT_R8G8B8A8_UNORM, DXGI_FORMAT_UNKNOWN, DXGI_FORMAT_UNKNOWN,
D3D12_RESOURCE_FLAG_NONE))
{
@@ -867,16 +867,13 @@ void GPU_HW_D3D12::UpdateDisplay()
if (IsUsingMultisampling())
{
UpdateVRAMReadTexture();
- g_host_display->SetDisplayTexture(&m_vram_read_texture, HostDisplayPixelFormat::RGBA8,
- m_vram_read_texture.GetWidth(), m_vram_read_texture.GetHeight(), 0, 0,
- m_vram_read_texture.GetWidth(), m_vram_read_texture.GetHeight());
+ g_host_display->SetDisplayTexture(&m_vram_read_texture, 0, 0, m_vram_read_texture.GetWidth(),
+ m_vram_read_texture.GetHeight());
}
else
{
m_vram_texture.TransitionToState(D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
- g_host_display->SetDisplayTexture(&m_vram_texture, HostDisplayPixelFormat::RGBA8, m_vram_texture.GetWidth(),
- m_vram_texture.GetHeight(), 0, 0, m_vram_texture.GetWidth(),
- m_vram_texture.GetHeight());
+ g_host_display->SetDisplayTexture(&m_vram_texture, 0, 0, m_vram_texture.GetWidth(), m_vram_texture.GetHeight());
}
g_host_display->SetDisplayParameters(VRAM_WIDTH, VRAM_HEIGHT, 0, 0, VRAM_WIDTH, VRAM_HEIGHT,
static_cast(VRAM_WIDTH) / static_cast(VRAM_HEIGHT));
@@ -908,8 +905,7 @@ void GPU_HW_D3D12::UpdateDisplay()
(scaled_vram_offset_y + scaled_display_height) <= m_vram_texture.GetHeight())
{
m_vram_texture.TransitionToState(D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
- g_host_display->SetDisplayTexture(&m_vram_texture, HostDisplayPixelFormat::RGBA8, m_vram_texture.GetWidth(),
- m_vram_texture.GetHeight(), scaled_vram_offset_x, scaled_vram_offset_y,
+ g_host_display->SetDisplayTexture(&m_vram_texture, scaled_vram_offset_x, scaled_vram_offset_y,
scaled_display_width, scaled_display_height);
}
else
@@ -936,9 +932,7 @@ void GPU_HW_D3D12::UpdateDisplay()
m_display_texture.TransitionToState(D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);
m_vram_texture.TransitionToState(D3D12_RESOURCE_STATE_RENDER_TARGET);
- g_host_display->SetDisplayTexture(&m_display_texture, HostDisplayPixelFormat::RGBA8, m_display_texture.GetWidth(),
- m_display_texture.GetHeight(), 0, 0, scaled_display_width,
- scaled_display_height);
+ g_host_display->SetDisplayTexture(&m_display_texture, 0, 0, scaled_display_width, scaled_display_height);
RestoreGraphicsAPIState();
}
@@ -1150,7 +1144,7 @@ void GPU_HW_D3D12::UpdateVRAMReadTexture()
{
m_vram_texture.TransitionToState(D3D12_RESOURCE_STATE_RESOLVE_SOURCE);
m_vram_read_texture.TransitionToState(D3D12_RESOURCE_STATE_RESOLVE_DEST);
- cmdlist->ResolveSubresource(m_vram_read_texture, 0, m_vram_texture, 0, m_vram_texture.GetFormat());
+ cmdlist->ResolveSubresource(m_vram_read_texture, 0, m_vram_texture, 0, m_vram_texture.GetDXGIFormat());
}
else
{
diff --git a/src/core/gpu_hw_opengl.cpp b/src/core/gpu_hw_opengl.cpp
index 0f2a6f5c3..2de16eae9 100644
--- a/src/core/gpu_hw_opengl.cpp
+++ b/src/core/gpu_hw_opengl.cpp
@@ -108,11 +108,11 @@ void GPU_HW_OpenGL::Reset(bool clear_vram)
ClearFramebuffer();
}
-bool GPU_HW_OpenGL::DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool update_display)
+bool GPU_HW_OpenGL::DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_display)
{
if (host_texture)
{
- HostDisplayTexture* tex = *host_texture;
+ GPUTexture* tex = *host_texture;
if (sw.IsReading())
{
if (tex->GetWidth() != m_vram_texture.GetWidth() || tex->GetHeight() != m_vram_texture.GetHeight() ||
@@ -121,9 +121,9 @@ bool GPU_HW_OpenGL::DoState(StateWrapper& sw, HostDisplayTexture** host_texture,
return false;
}
- CopyFramebufferForState(
- m_vram_texture.GetGLTarget(), static_cast(reinterpret_cast(tex->GetHandle())), 0, 0, 0,
- m_vram_texture.GetGLId(), m_vram_fbo_id, 0, 0, m_vram_texture.GetWidth(), m_vram_texture.GetHeight());
+ CopyFramebufferForState(m_vram_texture.GetGLTarget(), static_cast(tex)->GetGLId(), 0, 0, 0,
+ m_vram_texture.GetGLId(), m_vram_fbo_id, 0, 0, m_vram_texture.GetWidth(),
+ m_vram_texture.GetHeight());
}
else
{
@@ -134,7 +134,7 @@ bool GPU_HW_OpenGL::DoState(StateWrapper& sw, HostDisplayTexture** host_texture,
tex = g_host_display
->CreateTexture(m_vram_texture.GetWidth(), m_vram_texture.GetHeight(), 1, 1,
- m_vram_texture.GetSamples(), HostDisplayPixelFormat::RGBA8, nullptr, 0, false)
+ m_vram_texture.GetSamples(), GPUTexture::Format::RGBA8, nullptr, 0, false)
.release();
*host_texture = tex;
if (!tex)
@@ -142,8 +142,8 @@ bool GPU_HW_OpenGL::DoState(StateWrapper& sw, HostDisplayTexture** host_texture,
}
CopyFramebufferForState(m_vram_texture.GetGLTarget(), m_vram_texture.GetGLId(), m_vram_fbo_id, 0, 0,
- static_cast(reinterpret_cast(tex->GetHandle())), 0, 0, 0,
- m_vram_texture.GetWidth(), m_vram_texture.GetHeight());
+ static_cast(tex)->GetGLId(), 0, 0, 0, m_vram_texture.GetWidth(),
+ m_vram_texture.GetHeight());
}
}
@@ -285,17 +285,11 @@ void GPU_HW_OpenGL::UnmapBatchVertexPointer(u32 used_vertices)
DebugAssert(m_batch_start_vertex_ptr);
m_vertex_stream_buffer->Unmap(used_vertices * sizeof(BatchVertex));
- m_vertex_stream_buffer->Bind();
m_batch_start_vertex_ptr = nullptr;
m_batch_end_vertex_ptr = nullptr;
m_batch_current_vertex_ptr = nullptr;
}
-std::tuple GPU_HW_OpenGL::ConvertToFramebufferCoordinates(s32 x, s32 y)
-{
- return std::make_tuple(x, static_cast(static_cast(VRAM_HEIGHT) - y));
-}
-
void GPU_HW_OpenGL::SetCapabilities()
{
GLint max_texture_size = VRAM_WIDTH;
@@ -396,18 +390,18 @@ bool GPU_HW_OpenGL::CreateFramebuffer()
const u32 texture_height = VRAM_HEIGHT * m_resolution_scale;
const u32 multisamples = m_multisamples;
- if (!m_vram_texture.Create(texture_width, texture_height, 1, 1, multisamples, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE,
- nullptr, false, true) ||
- !m_vram_depth_texture.Create(texture_width, texture_height, 1, 1, multisamples, GL_DEPTH_COMPONENT16,
- GL_DEPTH_COMPONENT, GL_UNSIGNED_SHORT, nullptr, false) ||
- !m_vram_read_texture.Create(texture_width, texture_height, 1, 1, 1, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, nullptr,
- false, true) ||
+ if (!m_vram_texture.Create(texture_width, texture_height, 1, 1, multisamples, GPUTexture::Format::RGBA8, nullptr, 0,
+ true, true) ||
+ !m_vram_depth_texture.Create(texture_width, texture_height, 1, 1, multisamples, GPUTexture::Format::D16, nullptr,
+ 0, false, true) ||
+ !m_vram_read_texture.Create(texture_width, texture_height, 1, 1, 1, GPUTexture::Format::RGBA8, nullptr, 0, false,
+ true) ||
!m_vram_read_texture.CreateFramebuffer() ||
- !m_vram_encoding_texture.Create(VRAM_WIDTH, VRAM_HEIGHT, 1, 1, 1, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, nullptr,
- false) ||
+ !m_vram_encoding_texture.Create(VRAM_WIDTH, VRAM_HEIGHT, 1, 1, 1, GPUTexture::Format::RGBA8, nullptr, 0, false,
+ true) ||
!m_vram_encoding_texture.CreateFramebuffer() ||
!m_display_texture.Create(GPU_MAX_DISPLAY_WIDTH * m_resolution_scale, GPU_MAX_DISPLAY_HEIGHT * m_resolution_scale,
- 1, 1, 1, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE, nullptr, false) ||
+ 1, 1, 1, GPUTexture::Format::RGBA8, nullptr, 0, true, true) ||
!m_display_texture.CreateFramebuffer())
{
return false;
@@ -425,7 +419,7 @@ bool GPU_HW_OpenGL::CreateFramebuffer()
if (m_downsample_mode == GPUDownsampleMode::Box)
{
- if (!m_downsample_texture.Create(VRAM_WIDTH, VRAM_HEIGHT, 1, 1, 1, GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE) ||
+ if (!m_downsample_texture.Create(VRAM_WIDTH, VRAM_HEIGHT, 1, 1, 1, GPUTexture::Format::RGBA8) ||
!m_downsample_texture.CreateFramebuffer())
{
return false;
@@ -778,8 +772,8 @@ bool GPU_HW_OpenGL::BlitVRAMReplacementTexture(const TextureReplacementTexture*
{
if (!m_vram_write_replacement_texture.IsValid())
{
- if (!m_vram_write_replacement_texture.Create(tex->GetWidth(), tex->GetHeight(), 1, 1, 1, GL_RGBA8, GL_RGBA,
- GL_UNSIGNED_BYTE, tex->GetPixels(), true) ||
+ if (!m_vram_write_replacement_texture.Create(tex->GetWidth(), tex->GetHeight(), 1, 1, 1,
+ GPUTexture::Format::RGBA8) ||
!m_vram_write_replacement_texture.CreateFramebuffer())
{
m_vram_write_replacement_texture.Destroy();
@@ -795,7 +789,6 @@ bool GPU_HW_OpenGL::BlitVRAMReplacementTexture(const TextureReplacementTexture*
glDisable(GL_SCISSOR_TEST);
m_vram_write_replacement_texture.BindFramebuffer(GL_READ_FRAMEBUFFER);
- dst_y = m_vram_texture.GetHeight() - dst_y - height;
glBlitFramebuffer(0, tex->GetHeight(), tex->GetWidth(), 0, dst_x, dst_y, dst_x + width, dst_y + height,
GL_COLOR_BUFFER_BIT, GL_LINEAR);
@@ -826,7 +819,7 @@ void GPU_HW_OpenGL::SetScissorFromDrawingArea()
const int width = right - left;
const int height = bottom - top;
const int x = left;
- const int y = m_vram_texture.GetHeight() - bottom;
+ const int y = top;
Log_DebugPrintf("SetScissor: (%d-%d, %d-%d)", x, x + width, y, y + height);
glScissor(x, y, width, height);
@@ -867,16 +860,13 @@ void GPU_HW_OpenGL::UpdateDisplay()
{
UpdateVRAMReadTexture();
- g_host_display->SetDisplayTexture(
- &m_vram_read_texture, HostDisplayPixelFormat::RGBA8, m_vram_read_texture.GetWidth(),
- static_cast(m_vram_read_texture.GetHeight()), 0, m_vram_read_texture.GetHeight(),
- m_vram_read_texture.GetWidth(), -static_cast(m_vram_read_texture.GetHeight()));
+ g_host_display->SetDisplayTexture(&m_vram_read_texture, 0, m_vram_read_texture.GetHeight(),
+ m_vram_read_texture.GetWidth(), m_vram_read_texture.GetHeight());
}
else
{
- g_host_display->SetDisplayTexture(&m_vram_texture, HostDisplayPixelFormat::RGBA8, m_vram_texture.GetWidth(),
- static_cast(m_vram_texture.GetHeight()), 0, m_vram_texture.GetHeight(),
- m_vram_texture.GetWidth(), -static_cast(m_vram_texture.GetHeight()));
+ g_host_display->SetDisplayTexture(&m_vram_texture, 0, m_vram_texture.GetHeight(), m_vram_texture.GetWidth(),
+ m_vram_texture.GetHeight());
}
g_host_display->SetDisplayParameters(VRAM_WIDTH, VRAM_HEIGHT, 0, 0, VRAM_WIDTH, VRAM_HEIGHT,
static_cast(VRAM_WIDTH) / static_cast(VRAM_HEIGHT));
@@ -914,10 +904,8 @@ void GPU_HW_OpenGL::UpdateDisplay()
}
else
{
- g_host_display->SetDisplayTexture(&m_vram_texture, HostDisplayPixelFormat::RGBA8, m_vram_texture.GetWidth(),
- m_vram_texture.GetHeight(), scaled_vram_offset_x,
- m_vram_texture.GetHeight() - scaled_vram_offset_y, scaled_display_width,
- -static_cast(scaled_display_height));
+ g_host_display->SetDisplayTexture(&m_vram_texture, scaled_vram_offset_x, scaled_vram_offset_y,
+ scaled_display_width, scaled_display_height);
}
}
else
@@ -936,14 +924,11 @@ void GPU_HW_OpenGL::UpdateDisplay()
glInvalidateFramebuffer(GL_DRAW_FRAMEBUFFER, static_cast(attachments.size()), attachments.data());
}
- const u8 height_div2 = BoolToUInt8(interlaced == GPU_HW::InterlacedRenderMode::SeparateFields);
const u32 reinterpret_field_offset = (interlaced != InterlacedRenderMode::None) ? GetInterlacedDisplayField() : 0;
- const u32 scaled_flipped_vram_offset_y = m_vram_texture.GetHeight() - scaled_vram_offset_y -
- reinterpret_field_offset - (scaled_display_height >> height_div2);
const u32 reinterpret_start_x = m_crtc_state.regs.X * resolution_scale;
const u32 reinterpret_crop_left = (m_crtc_state.display_vram_left - m_crtc_state.regs.X) * resolution_scale;
- const u32 uniforms[4] = {reinterpret_start_x, scaled_flipped_vram_offset_y, reinterpret_crop_left,
- reinterpret_field_offset};
+ const u32 uniforms[4] = {reinterpret_start_x, scaled_vram_offset_y + reinterpret_field_offset,
+ reinterpret_crop_left, reinterpret_field_offset};
UploadUniformBuffer(uniforms, sizeof(uniforms));
m_batch_ubo_dirty = true;
@@ -960,10 +945,7 @@ void GPU_HW_OpenGL::UpdateDisplay()
}
else
{
- g_host_display->SetDisplayTexture(&m_display_texture, HostDisplayPixelFormat::RGBA8,
- m_display_texture.GetWidth(), m_display_texture.GetHeight(), 0,
- scaled_display_height, scaled_display_width,
- -static_cast(scaled_display_height));
+ g_host_display->SetDisplayTexture(&m_display_texture, 0, 0, scaled_display_width, scaled_display_height);
}
// restore state
@@ -993,8 +975,7 @@ void GPU_HW_OpenGL::ReadVRAM(u32 x, u32 y, u32 width, u32 height)
const u32 encoded_height = copy_rect.GetHeight();
// Encode the 24-bit texture as 16-bit.
- const u32 uniforms[4] = {copy_rect.left, VRAM_HEIGHT - copy_rect.top - copy_rect.GetHeight(), copy_rect.GetWidth(),
- copy_rect.GetHeight()};
+ const u32 uniforms[4] = {copy_rect.left, copy_rect.top, copy_rect.GetWidth(), copy_rect.GetHeight()};
m_vram_encoding_texture.BindFramebuffer(GL_DRAW_FRAMEBUFFER);
m_vram_texture.Bind();
m_vram_read_program.Bind();
@@ -1024,9 +1005,8 @@ void GPU_HW_OpenGL::FillVRAM(u32 x, u32 y, u32 width, u32 height, u32 color)
GPU_HW::FillVRAM(x, y, width, height, color);
const Common::Rectangle bounds(GetVRAMTransferBounds(x, y, width, height));
- glScissor(bounds.left * m_resolution_scale,
- m_vram_texture.GetHeight() - (bounds.top * m_resolution_scale) - (height * m_resolution_scale),
- width * m_resolution_scale, height * m_resolution_scale);
+ glScissor(bounds.left * m_resolution_scale, bounds.top * m_resolution_scale, width * m_resolution_scale,
+ height * m_resolution_scale);
// fast path when not using interlaced rendering
const bool wrapped = IsVRAMFillOversized(x, y, width, height);
@@ -1096,9 +1076,7 @@ void GPU_HW_OpenGL::UpdateVRAM(u32 x, u32 y, u32 width, u32 height, const void*
// the viewport should already be set to the full vram, so just adjust the scissor
const Common::Rectangle scaled_bounds = bounds * m_resolution_scale;
- glScissor(scaled_bounds.left, m_vram_texture.GetHeight() - scaled_bounds.top - scaled_bounds.GetHeight(),
- scaled_bounds.GetWidth(), scaled_bounds.GetHeight());
-
+ glScissor(scaled_bounds.left, scaled_bounds.top, scaled_bounds.GetWidth(), scaled_bounds.GetHeight());
glBindVertexArray(m_attributeless_vao_id);
glDrawArrays(GL_TRIANGLES, 0, 3);
@@ -1120,9 +1098,8 @@ void GPU_HW_OpenGL::UpdateVRAM(u32 x, u32 y, u32 width, u32 height, const void*
const auto map_result = m_texture_stream_buffer->Map(sizeof(u32), num_pixels * sizeof(u32));
- // reverse copy the rows so it matches opengl's lower-left origin
const u32 source_stride = width * sizeof(u16);
- const u8* source_ptr = static_cast(data) + (source_stride * (height - 1));
+ const u8* source_ptr = static_cast(data);
const u16 mask_or = set_mask ? 0x8000 : 0x0000;
u32* dest_ptr = static_cast(map_result.pointer);
for (u32 row = 0; row < height; row++)
@@ -1137,7 +1114,7 @@ void GPU_HW_OpenGL::UpdateVRAM(u32 x, u32 y, u32 width, u32 height, const void*
*(dest_ptr++) = VRAMRGBA5551ToRGBA8888(src_col | mask_or);
}
- source_ptr -= source_stride;
+ source_ptr += source_stride;
}
m_texture_stream_buffer->Unmap(num_pixels * sizeof(u32));
@@ -1149,11 +1126,8 @@ void GPU_HW_OpenGL::UpdateVRAM(u32 x, u32 y, u32 width, u32 height, const void*
else
m_vram_texture.Bind();
- // lower-left origin flip happens here
- const u32 flipped_y = VRAM_HEIGHT - y - height;
-
// update texture data
- glTexSubImage2D(m_vram_texture.GetGLTarget(), 0, x, flipped_y, width, height, GL_RGBA, GL_UNSIGNED_BYTE,
+ glTexSubImage2D(m_vram_texture.GetGLTarget(), 0, x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE,
reinterpret_cast(static_cast(map_result.buffer_offset)));
m_texture_stream_buffer->Unbind();
@@ -1164,11 +1138,10 @@ void GPU_HW_OpenGL::UpdateVRAM(u32 x, u32 y, u32 width, u32 height, const void*
const u32 scaled_height = height * m_resolution_scale;
const u32 scaled_x = x * m_resolution_scale;
const u32 scaled_y = y * m_resolution_scale;
- const u32 scaled_flipped_y = m_vram_texture.GetHeight() - scaled_y - scaled_height;
glDisable(GL_SCISSOR_TEST);
m_vram_encoding_texture.BindFramebuffer(GL_READ_FRAMEBUFFER);
- glBlitFramebuffer(x, flipped_y, x + width, flipped_y + height, scaled_x, scaled_flipped_y,
- scaled_x + scaled_width, scaled_flipped_y + scaled_height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
+ glBlitFramebuffer(x, y, x + width, y + height, scaled_x, scaled_y, scaled_x + scaled_width,
+ scaled_y + scaled_height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glEnable(GL_SCISSOR_TEST);
}
}
@@ -1189,9 +1162,7 @@ void GPU_HW_OpenGL::CopyVRAM(u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, u32 wid
UpdateVRAMReadTexture();
IncludeVRAMDirtyRectangle(dst_bounds);
- VRAMCopyUBOData uniforms = GetVRAMCopyUBOData(src_x, src_y, dst_x, dst_y, width, height);
- uniforms.u_src_y = m_vram_texture.GetHeight() - uniforms.u_src_y - uniforms.u_height;
- uniforms.u_dst_y = m_vram_texture.GetHeight() - uniforms.u_dst_y - uniforms.u_height;
+ const VRAMCopyUBOData uniforms = GetVRAMCopyUBOData(src_x, src_y, dst_x, dst_y, width, height);
UploadUniformBuffer(&uniforms, sizeof(uniforms));
glDisable(GL_SCISSOR_TEST);
@@ -1199,9 +1170,8 @@ void GPU_HW_OpenGL::CopyVRAM(u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, u32 wid
SetDepthFunc((m_GPUSTAT.check_mask_before_draw && !m_pgxp_depth_buffer) ? GL_GEQUAL : GL_ALWAYS);
const Common::Rectangle dst_bounds_scaled(dst_bounds * m_resolution_scale);
- glViewport(dst_bounds_scaled.left,
- m_vram_texture.GetHeight() - dst_bounds_scaled.top - dst_bounds_scaled.GetHeight(),
- dst_bounds_scaled.GetWidth(), dst_bounds_scaled.GetHeight());
+ glViewport(dst_bounds_scaled.left, dst_bounds_scaled.top, dst_bounds_scaled.GetWidth(),
+ dst_bounds_scaled.GetHeight());
m_vram_read_texture.Bind();
m_vram_copy_program.Bind();
glBindVertexArray(m_attributeless_vao_id);
@@ -1224,10 +1194,6 @@ void GPU_HW_OpenGL::CopyVRAM(u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, u32 wid
width *= m_resolution_scale;
height *= m_resolution_scale;
- // lower-left origin flip
- src_y = m_vram_texture.GetHeight() - src_y - height;
- dst_y = m_vram_texture.GetHeight() - dst_y - height;
-
if (GLAD_GL_VERSION_4_3)
{
glCopyImageSubData(m_vram_texture.GetGLId(), m_vram_texture.GetGLTarget(), 0, src_x, src_y, 0,
@@ -1266,7 +1232,7 @@ void GPU_HW_OpenGL::UpdateVRAMReadTexture()
const u32 width = scaled_rect.GetWidth();
const u32 height = scaled_rect.GetHeight();
const u32 x = scaled_rect.left;
- const u32 y = m_vram_texture.GetHeight() - scaled_rect.top - height;
+ const u32 y = scaled_rect.top;
const bool multisampled = m_vram_texture.IsMultisampled();
if (!multisampled && GLAD_GL_VERSION_4_3)
@@ -1344,7 +1310,7 @@ void GPU_HW_OpenGL::DownsampleFramebufferBoxFilter(GL::Texture& source, u32 left
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
glDisable(GL_SCISSOR_TEST);
- glViewport(ds_left, m_downsample_texture.GetHeight() - ds_top - ds_height, ds_width, ds_height);
+ glViewport(ds_left, ds_top, ds_width, ds_height);
glBindVertexArray(m_attributeless_vao_id);
source.Bind();
m_downsample_texture.BindFramebuffer(GL_DRAW_FRAMEBUFFER);
@@ -1353,9 +1319,7 @@ void GPU_HW_OpenGL::DownsampleFramebufferBoxFilter(GL::Texture& source, u32 left
RestoreGraphicsAPIState();
- g_host_display->SetDisplayTexture(&m_downsample_texture, HostDisplayPixelFormat::RGBA8,
- m_downsample_texture.GetWidth(), m_downsample_texture.GetHeight(), ds_left,
- m_downsample_texture.GetHeight() - ds_top, ds_width, -static_cast(ds_height));
+ g_host_display->SetDisplayTexture(&m_downsample_texture, ds_left, ds_top, ds_width, ds_height);
}
std::unique_ptr GPU::CreateHardwareOpenGLRenderer()
diff --git a/src/core/gpu_hw_opengl.h b/src/core/gpu_hw_opengl.h
index e50829370..8bb33aeda 100644
--- a/src/core/gpu_hw_opengl.h
+++ b/src/core/gpu_hw_opengl.h
@@ -20,7 +20,7 @@ public:
bool Initialize() override;
void Reset(bool clear_vram) override;
- bool DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool update_display) override;
+ bool DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_display) override;
void ResetGraphicsAPIState() override;
void RestoreGraphicsAPIState() override;
@@ -55,8 +55,6 @@ private:
ALWAYS_INLINE bool IsGLES() const { return (m_render_api == RenderAPI::OpenGLES); }
- std::tuple ConvertToFramebufferCoordinates(s32 x, s32 y);
-
void SetCapabilities();
bool CreateFramebuffer();
void ClearFramebuffer();
diff --git a/src/core/gpu_hw_shadergen.cpp b/src/core/gpu_hw_shadergen.cpp
index 7f5ad4ce9..8ced70087 100644
--- a/src/core/gpu_hw_shadergen.cpp
+++ b/src/core/gpu_hw_shadergen.cpp
@@ -25,25 +25,6 @@ void GPU_HW_ShaderGen::WriteCommonFunctions(std::stringstream& ss)
ss << "CONSTANT uint MULTISAMPLES = " << m_multisamples << "u;\n";
ss << "CONSTANT bool PER_SAMPLE_SHADING = " << (m_per_sample_shading ? "true" : "false") << ";\n";
ss << R"(
-
-float fixYCoord(float y)
-{
-#if API_OPENGL || API_OPENGL_ES
- return 1.0 - RCP_VRAM_SIZE.y - y;
-#else
- return y;
-#endif
-}
-
-uint fixYCoord(uint y)
-{
-#if API_OPENGL || API_OPENGL_ES
- return VRAM_SIZE.y - y - 1u;
-#else
- return y;
-#endif
-}
-
uint RGBA8ToRGBA5551(float4 v)
{
uint r = uint(roundEven(v.r * 31.0));
@@ -85,23 +66,6 @@ std::string GPU_HW_ShaderGen::GenerateBatchVertexShader(bool textured)
WriteCommonFunctions(ss);
WriteBatchUniformBuffer(ss);
- ss << R"(
-
-// OpenGL seems to be off by one pixel in the Y direction due to lower-left origin, but only on
-// Intel and NVIDIA drivers. AMD is fine. V3D requires coordinates to be slightly offset even further.
-#if API_OPENGL || API_OPENGL_ES
- #ifdef DRIVER_V3D
- CONSTANT float POS_EPSILON = 0.0001;
- #else
- #ifdef DRIVER_POWERVR
- CONSTANT float POS_EPSILON = 0.001;
- #else
- CONSTANT float POS_EPSILON = 0.00001;
- #endif
- #endif
-#endif
-)";
-
if (textured)
{
if (m_uv_limits)
@@ -145,14 +109,12 @@ std::string GPU_HW_ShaderGen::GenerateBatchVertexShader(bool textured)
#endif
#if API_OPENGL || API_OPENGL_ES
- pos_y += POS_EPSILON;
-
// 0..1 to -1..1 depth range.
pos_z = (pos_z * 2.0) - 1.0;
#endif
// NDC space Y flip in Vulkan.
-#if API_VULKAN
+#if API_OPENGL || API_OPENGL_ES || API_VULKAN
pos_y = -pos_y;
#endif
@@ -767,7 +729,7 @@ float4 SampleFromVRAM(uint4 texpage, float2 coords)
#endif
// fixup coords
- uint2 vicoord = uint2(texpage.x + index_coord.x * RESOLUTION_SCALE, fixYCoord(texpage.y + index_coord.y * RESOLUTION_SCALE));
+ uint2 vicoord = texpage.xy + (index_coord * uint2(RESOLUTION_SCALE, RESOLUTION_SCALE));
// load colour/palette
float4 texel = SAMPLE_TEXTURE(samp0, float2(vicoord) * RCP_VRAM_SIZE);
@@ -783,12 +745,12 @@ float4 SampleFromVRAM(uint4 texpage, float2 coords)
#endif
// sample palette
- uint2 palette_icoord = uint2(texpage.z + (palette_index * RESOLUTION_SCALE), fixYCoord(texpage.w));
+ uint2 palette_icoord = uint2(texpage.z + (palette_index * RESOLUTION_SCALE), texpage.w);
return SAMPLE_TEXTURE(samp0, float2(palette_icoord) * RCP_VRAM_SIZE);
#else
// Direct texturing. Render-to-texture effects. Use upscaled coordinates.
uint2 icoord = ApplyUpscaledTextureWindow(FloatToIntegerCoords(coords));
- uint2 direct_icoord = uint2(texpage.x + icoord.x, fixYCoord(texpage.y + icoord.y));
+ uint2 direct_icoord = texpage.xy + icoord;
return SAMPLE_TEXTURE(samp0, float2(direct_icoord) * RCP_VRAM_SIZE);
#endif
}
@@ -831,7 +793,7 @@ float4 SampleFromVRAM(uint4 texpage, float2 coords)
float oalpha;
#if INTERLACING
- if ((fixYCoord(uint(v_pos.y)) & 1u) == u_interlaced_displayed_field)
+ if ((uint(v_pos.y) & 1u) == u_interlaced_displayed_field)
discard;
#endif
@@ -1097,7 +1059,7 @@ float3 SampleVRAM24Smoothed(uint2 icoords)
uint2 icoords = uint2(v_pos.xy) + uint2(u_crop_left, 0u);
#if INTERLACED
- if ((fixYCoord(icoords.y) & 1u) != u_field_offset)
+ if ((icoords.y & 1u) != u_field_offset)
discard;
#if !INTERLEAVED
@@ -1167,13 +1129,6 @@ uint SampleVRAM(uint2 coords)
ss << R"(
{
uint2 sample_coords = uint2(uint(v_pos.x) * 2u, uint(v_pos.y));
-
- #if API_OPENGL || API_OPENGL_ES
- // Lower-left origin flip for OpenGL.
- // We want to write the image out upside-down so we can read it top-to-bottom.
- sample_coords.y = u_size.y - sample_coords.y - 1u;
- #endif
-
sample_coords += u_base_coords;
// We're encoding as 32-bit, so the output width is halved and we pack two 16-bit pixels in one 32-bit pixel.
@@ -1222,7 +1177,7 @@ std::string GPU_HW_ShaderGen::GenerateVRAMWriteFragmentShader(bool use_ssbo)
DeclareFragmentEntryPoint(ss, 0, 1, {}, true, 1, true);
ss << R"(
{
- uint2 coords = uint2(uint(v_pos.x) / RESOLUTION_SCALE, fixYCoord(uint(v_pos.y)) / RESOLUTION_SCALE);
+ uint2 coords = uint2(v_pos.xy) / uint2(RESOLUTION_SCALE, RESOLUTION_SCALE);
// make sure it's not oversized and out of range
if ((coords.x < u_base_coords.x && coords.x >= u_end_coords.x) ||
@@ -1320,7 +1275,7 @@ std::string GPU_HW_ShaderGen::GenerateVRAMFillFragmentShader(bool wrapped, bool
ss << R"(
{
#if INTERLACED || WRAPPED
- uint2 dst_coords = uint2(uint(v_pos.x), fixYCoord(uint(v_pos.y)));
+ uint2 dst_coords = uint2(v_pos.xy);
#endif
#if INTERLACED
diff --git a/src/core/gpu_hw_vulkan.cpp b/src/core/gpu_hw_vulkan.cpp
index 6d8baf8e7..02bdaaa3e 100644
--- a/src/core/gpu_hw_vulkan.cpp
+++ b/src/core/gpu_hw_vulkan.cpp
@@ -102,7 +102,7 @@ void GPU_HW_Vulkan::Reset(bool clear_vram)
ClearFramebuffer();
}
-bool GPU_HW_Vulkan::DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool update_display)
+bool GPU_HW_Vulkan::DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_display)
{
if (host_texture)
{
@@ -119,7 +119,7 @@ bool GPU_HW_Vulkan::DoState(StateWrapper& sw, HostDisplayTexture** host_texture,
if (sw.IsReading())
{
- Vulkan::Texture* tex = static_cast((*host_texture)->GetHandle());
+ Vulkan::Texture* tex = static_cast(*host_texture);
if (tex->GetWidth() != m_vram_texture.GetWidth() || tex->GetHeight() != m_vram_texture.GetHeight() ||
tex->GetSamples() != m_vram_texture.GetSamples())
{
@@ -137,22 +137,22 @@ bool GPU_HW_Vulkan::DoState(StateWrapper& sw, HostDisplayTexture** host_texture,
}
else
{
- HostDisplayTexture* htex = *host_texture;
- if (!htex || htex->GetWidth() != m_vram_texture.GetWidth() || htex->GetHeight() != m_vram_texture.GetHeight() ||
- htex->GetSamples() != static_cast(m_vram_texture.GetSamples()))
+ Vulkan::Texture* tex = static_cast(*host_texture);
+ if (!tex || tex->GetWidth() != m_vram_texture.GetWidth() || tex->GetHeight() != m_vram_texture.GetHeight() ||
+ tex->GetSamples() != static_cast(m_vram_texture.GetSamples()))
{
- delete htex;
+ delete tex;
- htex = g_host_display
- ->CreateTexture(m_vram_texture.GetWidth(), m_vram_texture.GetHeight(), 1, 1,
- m_vram_texture.GetSamples(), HostDisplayPixelFormat::RGBA8, nullptr, 0, false)
- .release();
- *host_texture = htex;
- if (!htex)
+ tex = static_cast(g_host_display
+ ->CreateTexture(m_vram_texture.GetWidth(), m_vram_texture.GetHeight(), 1,
+ 1, m_vram_texture.GetSamples(), GPUTexture::Format::RGBA8,
+ nullptr, 0, false)
+ .release());
+ *host_texture = tex;
+ if (!tex)
return false;
}
- Vulkan::Texture* tex = static_cast(htex->GetHandle());
if (tex->GetWidth() != m_vram_texture.GetWidth() || tex->GetHeight() != m_vram_texture.GetHeight() ||
tex->GetSamples() != m_vram_texture.GetSamples())
{
@@ -612,13 +612,13 @@ bool GPU_HW_Vulkan::CreateFramebuffer()
m_vram_update_depth_render_pass =
g_vulkan_context->GetRenderPass(VK_FORMAT_UNDEFINED, depth_format, samples, VK_ATTACHMENT_LOAD_OP_DONT_CARE);
m_display_load_render_pass = g_vulkan_context->GetRenderPass(
- m_display_texture.GetFormat(), VK_FORMAT_UNDEFINED, m_display_texture.GetSamples(), VK_ATTACHMENT_LOAD_OP_LOAD);
+ m_display_texture.GetVkFormat(), VK_FORMAT_UNDEFINED, m_display_texture.GetVkSamples(), VK_ATTACHMENT_LOAD_OP_LOAD);
m_display_discard_render_pass =
- g_vulkan_context->GetRenderPass(m_display_texture.GetFormat(), VK_FORMAT_UNDEFINED, m_display_texture.GetSamples(),
- VK_ATTACHMENT_LOAD_OP_DONT_CARE);
+ g_vulkan_context->GetRenderPass(m_display_texture.GetVkFormat(), VK_FORMAT_UNDEFINED,
+ m_display_texture.GetVkSamples(), VK_ATTACHMENT_LOAD_OP_DONT_CARE);
m_vram_readback_render_pass =
- g_vulkan_context->GetRenderPass(m_vram_readback_texture.GetFormat(), VK_FORMAT_UNDEFINED,
- m_vram_readback_texture.GetSamples(), VK_ATTACHMENT_LOAD_OP_DONT_CARE);
+ g_vulkan_context->GetRenderPass(m_vram_readback_texture.GetVkFormat(), VK_FORMAT_UNDEFINED,
+ m_vram_readback_texture.GetVkSamples(), VK_ATTACHMENT_LOAD_OP_DONT_CARE);
if (m_vram_render_pass == VK_NULL_HANDLE || m_vram_update_depth_render_pass == VK_NULL_HANDLE ||
m_display_load_render_pass == VK_NULL_HANDLE || m_vram_readback_render_pass == VK_NULL_HANDLE)
@@ -704,10 +704,11 @@ bool GPU_HW_Vulkan::CreateFramebuffer()
m_downsample_texture.TransitionToLayout(cmdbuf, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
- m_downsample_render_pass = g_vulkan_context->GetRenderPass(m_downsample_texture.GetFormat(), VK_FORMAT_UNDEFINED,
+ m_downsample_render_pass = g_vulkan_context->GetRenderPass(m_downsample_texture.GetVkFormat(), VK_FORMAT_UNDEFINED,
VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_CLEAR);
- m_downsample_weight_render_pass = g_vulkan_context->GetRenderPass(
- m_downsample_weight_texture.GetFormat(), VK_FORMAT_UNDEFINED, VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_CLEAR);
+ m_downsample_weight_render_pass =
+ g_vulkan_context->GetRenderPass(m_downsample_weight_texture.GetVkFormat(), VK_FORMAT_UNDEFINED,
+ VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_CLEAR);
if (m_downsample_render_pass == VK_NULL_HANDLE || m_downsample_weight_render_pass == VK_NULL_HANDLE)
return false;
@@ -725,7 +726,7 @@ bool GPU_HW_Vulkan::CreateFramebuffer()
0,
m_downsample_texture.GetImage(),
VK_IMAGE_VIEW_TYPE_2D,
- m_downsample_texture.GetFormat(),
+ m_downsample_texture.GetVkFormat(),
{VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY,
VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY},
{VK_IMAGE_ASPECT_COLOR_BIT, i, 1u, 0u, 1u}};
@@ -776,7 +777,7 @@ bool GPU_HW_Vulkan::CreateFramebuffer()
return false;
}
- m_downsample_render_pass = g_vulkan_context->GetRenderPass(m_downsample_texture.GetFormat(), VK_FORMAT_UNDEFINED,
+ m_downsample_render_pass = g_vulkan_context->GetRenderPass(m_downsample_texture.GetVkFormat(), VK_FORMAT_UNDEFINED,
VK_SAMPLE_COUNT_1_BIT, VK_ATTACHMENT_LOAD_OP_CLEAR);
m_downsample_mip_views.resize(1);
@@ -1433,15 +1434,12 @@ void GPU_HW_Vulkan::UpdateDisplay()
UpdateVRAMReadTexture();
}
- g_host_display->SetDisplayTexture(&m_vram_read_texture, HostDisplayPixelFormat::RGBA8,
- m_vram_read_texture.GetWidth(), m_vram_read_texture.GetHeight(), 0, 0,
- m_vram_read_texture.GetWidth(), m_vram_read_texture.GetHeight());
+ g_host_display->SetDisplayTexture(&m_vram_read_texture, 0, 0, m_vram_read_texture.GetWidth(),
+ m_vram_read_texture.GetHeight());
}
else
{
- g_host_display->SetDisplayTexture(&m_vram_texture, HostDisplayPixelFormat::RGBA8, m_vram_texture.GetWidth(),
- m_vram_texture.GetHeight(), 0, 0, m_vram_texture.GetWidth(),
- m_vram_texture.GetHeight());
+ g_host_display->SetDisplayTexture(&m_vram_texture, 0, 0, m_vram_texture.GetWidth(), m_vram_texture.GetHeight());
}
g_host_display->SetDisplayParameters(VRAM_WIDTH, VRAM_HEIGHT, 0, 0, VRAM_WIDTH, VRAM_HEIGHT,
static_cast(VRAM_WIDTH) / static_cast(VRAM_HEIGHT));
@@ -1479,8 +1477,7 @@ void GPU_HW_Vulkan::UpdateDisplay()
}
else
{
- g_host_display->SetDisplayTexture(&m_vram_texture, HostDisplayPixelFormat::RGBA8, m_vram_texture.GetWidth(),
- m_vram_texture.GetHeight(), scaled_vram_offset_x, scaled_vram_offset_y,
+ g_host_display->SetDisplayTexture(&m_vram_texture, scaled_vram_offset_x, scaled_vram_offset_y,
scaled_display_width, scaled_display_height);
}
}
@@ -1526,9 +1523,7 @@ void GPU_HW_Vulkan::UpdateDisplay()
}
else
{
- g_host_display->SetDisplayTexture(&m_display_texture, HostDisplayPixelFormat::RGBA8,
- m_display_texture.GetWidth(), m_display_texture.GetHeight(), 0, 0,
- scaled_display_width, scaled_display_height);
+ g_host_display->SetDisplayTexture(&m_display_texture, 0, 0, scaled_display_width, scaled_display_height);
RestoreGraphicsAPIState();
}
}
@@ -1577,8 +1572,8 @@ void GPU_HW_Vulkan::ReadVRAM(u32 x, u32 y, u32 width, u32 height)
m_vram_texture.TransitionToLayout(cmdbuf, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
// Stage the readback and copy it into our shadow buffer (will execute command buffer and stall).
- g_host_display->DownloadTexture(&m_vram_readback_texture, HostDisplayPixelFormat::RGBA8, 0, 0, encoded_width,
- encoded_height, &m_vram_shadow[copy_rect.top * VRAM_WIDTH + copy_rect.left],
+ g_host_display->DownloadTexture(&m_vram_readback_texture, 0, 0, encoded_width, encoded_height,
+ &m_vram_shadow[copy_rect.top * VRAM_WIDTH + copy_rect.left],
VRAM_WIDTH * sizeof(u16));
}
@@ -1890,9 +1885,7 @@ void GPU_HW_Vulkan::DownsampleFramebufferBoxFilter(Vulkan::Texture& source, u32
RestoreGraphicsAPIState();
- g_host_display->SetDisplayTexture(&m_downsample_texture, HostDisplayPixelFormat::RGBA8,
- m_downsample_texture.GetWidth(), m_downsample_texture.GetHeight(), ds_left, ds_top,
- ds_width, ds_height);
+ g_host_display->SetDisplayTexture(&m_downsample_texture, ds_left, ds_top, ds_width, ds_height);
}
void GPU_HW_Vulkan::DownsampleFramebufferAdaptive(Vulkan::Texture& source, u32 left, u32 top, u32 width, u32 height)
@@ -1989,8 +1982,7 @@ void GPU_HW_Vulkan::DownsampleFramebufferAdaptive(Vulkan::Texture& source, u32 l
}
RestoreGraphicsAPIState();
- g_host_display->SetDisplayTexture(&m_display_texture, HostDisplayPixelFormat::RGBA8, m_display_texture.GetWidth(),
- m_display_texture.GetHeight(), left, top, width, height);
+ g_host_display->SetDisplayTexture(&m_display_texture, left, top, width, height);
}
std::unique_ptr GPU::CreateHardwareVulkanRenderer()
diff --git a/src/core/gpu_hw_vulkan.h b/src/core/gpu_hw_vulkan.h
index 2d291d9c8..95fe3fad5 100644
--- a/src/core/gpu_hw_vulkan.h
+++ b/src/core/gpu_hw_vulkan.h
@@ -18,7 +18,7 @@ public:
bool Initialize() override;
void Reset(bool clear_vram) override;
- bool DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool update_display) override;
+ bool DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_display) override;
void ResetGraphicsAPIState() override;
void RestoreGraphicsAPIState() override;
diff --git a/src/core/gpu_sw.cpp b/src/core/gpu_sw.cpp
index f4c23057e..edf6c69c3 100644
--- a/src/core/gpu_sw.cpp
+++ b/src/core/gpu_sw.cpp
@@ -59,22 +59,22 @@ bool GPU_SW::Initialize()
if (!GPU::Initialize() || !m_backend.Initialize(false))
return false;
- static constexpr auto formats_for_16bit = make_array(HostDisplayPixelFormat::RGB565, HostDisplayPixelFormat::RGBA5551,
- HostDisplayPixelFormat::RGBA8, HostDisplayPixelFormat::BGRA8);
+ static constexpr auto formats_for_16bit = make_array(GPUTexture::Format::RGB565, GPUTexture::Format::RGBA5551,
+ GPUTexture::Format::RGBA8, GPUTexture::Format::BGRA8);
static constexpr auto formats_for_24bit =
- make_array(HostDisplayPixelFormat::RGBA8, HostDisplayPixelFormat::BGRA8, HostDisplayPixelFormat::RGB565,
- HostDisplayPixelFormat::RGBA5551);
- for (const HostDisplayPixelFormat format : formats_for_16bit)
+ make_array(GPUTexture::Format::RGBA8, GPUTexture::Format::BGRA8, GPUTexture::Format::RGB565,
+ GPUTexture::Format::RGBA5551);
+ for (const GPUTexture::Format format : formats_for_16bit)
{
- if (g_host_display->SupportsDisplayPixelFormat(format))
+ if (g_host_display->SupportsTextureFormat(format))
{
m_16bit_display_format = format;
break;
}
}
- for (const HostDisplayPixelFormat format : formats_for_24bit)
+ for (const GPUTexture::Format format : formats_for_24bit)
{
- if (g_host_display->SupportsDisplayPixelFormat(format))
+ if (g_host_display->SupportsTextureFormat(format))
{
m_24bit_display_format = format;
break;
@@ -84,7 +84,7 @@ bool GPU_SW::Initialize()
return true;
}
-bool GPU_SW::DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool update_display)
+bool GPU_SW::DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_display)
{
// ignore the host texture for software mode, since we want to save vram here
return GPU::DoState(sw, nullptr, update_display);
@@ -103,7 +103,7 @@ void GPU_SW::UpdateSettings()
m_backend.UpdateSettings();
}
-HostDisplayTexture* GPU_SW::GetDisplayTexture(u32 width, u32 height, HostDisplayPixelFormat format)
+GPUTexture* GPU_SW::GetDisplayTexture(u32 width, u32 height, GPUTexture::Format format)
{
if (!m_display_texture || m_display_texture->GetWidth() != width || m_display_texture->GetHeight() != height ||
m_display_texture->GetFormat() != format)
@@ -118,32 +118,32 @@ HostDisplayTexture* GPU_SW::GetDisplayTexture(u32 width, u32 height, HostDisplay
return m_display_texture.get();
}
-template
+template
static void CopyOutRow16(const u16* src_ptr, out_type* dst_ptr, u32 width);
-template
+template
static out_type VRAM16ToOutput(u16 value);
template<>
-ALWAYS_INLINE u16 VRAM16ToOutput(u16 value)
+ALWAYS_INLINE u16 VRAM16ToOutput(u16 value)
{
return (value & 0x3E0) | ((value >> 10) & 0x1F) | ((value & 0x1F) << 10);
}
template<>
-ALWAYS_INLINE u16 VRAM16ToOutput(u16 value)
+ALWAYS_INLINE u16 VRAM16ToOutput(u16 value)
{
return ((value & 0x3E0) << 1) | ((value & 0x20) << 1) | ((value >> 10) & 0x1F) | ((value & 0x1F) << 11);
}
template<>
-ALWAYS_INLINE u32 VRAM16ToOutput(u16 value)
+ALWAYS_INLINE u32 VRAM16ToOutput(u16 value)
{
return VRAMRGBA5551ToRGBA8888(value);
}
template<>
-ALWAYS_INLINE u32 VRAM16ToOutput(u16 value)
+ALWAYS_INLINE u32 VRAM16ToOutput(u16 value)
{
const u32 value32 = ZeroExtend32(value);
const u32 r = VRAMConvert5To8(value32 & 31u);
@@ -153,7 +153,7 @@ ALWAYS_INLINE u32 VRAM16ToOutput(u16 value)
}
template<>
-ALWAYS_INLINE void CopyOutRow16(const u16* src_ptr, u16* dst_ptr, u32 width)
+ALWAYS_INLINE void CopyOutRow16(const u16* src_ptr, u16* dst_ptr, u32 width)
{
u32 col = 0;
@@ -188,11 +188,11 @@ ALWAYS_INLINE void CopyOutRow16(const u16
#endif
for (; col < width; col++)
- *(dst_ptr++) = VRAM16ToOutput(*(src_ptr++));
+ *(dst_ptr++) = VRAM16ToOutput(*(src_ptr++));
}
template<>
-ALWAYS_INLINE void CopyOutRow16(const u16* src_ptr, u16* dst_ptr, u32 width)
+ALWAYS_INLINE void CopyOutRow16(const u16* src_ptr, u16* dst_ptr, u32 width)
{
u32 col = 0;
@@ -229,39 +229,39 @@ ALWAYS_INLINE void CopyOutRow16(const u16*
#endif
for (; col < width; col++)
- *(dst_ptr++) = VRAM16ToOutput(*(src_ptr++));
+ *(dst_ptr++) = VRAM16ToOutput(*(src_ptr++));
}
template<>
-ALWAYS_INLINE void CopyOutRow16(const u16* src_ptr, u32* dst_ptr, u32 width)
+ALWAYS_INLINE void CopyOutRow16(const u16* src_ptr, u32* dst_ptr, u32 width)
{
for (u32 col = 0; col < width; col++)
- *(dst_ptr++) = VRAM16ToOutput(*(src_ptr++));
+ *(dst_ptr++) = VRAM16ToOutput(*(src_ptr++));
}
template<>
-ALWAYS_INLINE void CopyOutRow16(const u16* src_ptr, u32* dst_ptr, u32 width)
+ALWAYS_INLINE void CopyOutRow16(const u16* src_ptr, u32* dst_ptr, u32 width)
{
for (u32 col = 0; col < width; col++)
- *(dst_ptr++) = VRAM16ToOutput(*(src_ptr++));
+ *(dst_ptr++) = VRAM16ToOutput(*(src_ptr++));
}
-template
+template
void GPU_SW::CopyOut15Bit(u32 src_x, u32 src_y, u32 width, u32 height, u32 field, bool interlaced, bool interleaved)
{
u8* dst_ptr;
u32 dst_stride;
using OutputPixelType = std::conditional_t<
- display_format == HostDisplayPixelFormat::RGBA8 || display_format == HostDisplayPixelFormat::BGRA8, u32, u16>;
+ display_format == GPUTexture::Format::RGBA8 || display_format == GPUTexture::Format::BGRA8, u32, u16>;
- HostDisplayTexture* texture = GetDisplayTexture(width, height, display_format);
+ GPUTexture* texture = GetDisplayTexture(width, height, display_format);
if (!texture)
return;
if (!interlaced)
{
- if (!texture->BeginUpdate(width, height, reinterpret_cast(&dst_ptr), &dst_stride))
+ if (!g_host_display->BeginTextureUpdate(texture, width, height, reinterpret_cast(&dst_ptr), &dst_stride))
return;
}
else
@@ -309,36 +309,36 @@ void GPU_SW::CopyOut15Bit(u32 src_x, u32 src_y, u32 width, u32 height, u32 field
}
if (!interlaced)
- texture->EndUpdate(0, 0, width, height);
+ g_host_display->EndTextureUpdate(texture, 0, 0, width, height);
else
- texture->Update(0, 0, width, height, m_display_texture_buffer.data(), output_stride);
+ g_host_display->UpdateTexture(texture, 0, 0, width, height, m_display_texture_buffer.data(), output_stride);
- g_host_display->SetDisplayTexture(texture->GetHandle(), display_format, width, height, 0, 0, width, height);
+ g_host_display->SetDisplayTexture(texture, 0, 0, width, height);
}
-void GPU_SW::CopyOut15Bit(HostDisplayPixelFormat display_format, u32 src_x, u32 src_y, u32 width, u32 height, u32 field,
+void GPU_SW::CopyOut15Bit(GPUTexture::Format display_format, u32 src_x, u32 src_y, u32 width, u32 height, u32 field,
bool interlaced, bool interleaved)
{
switch (display_format)
{
- case HostDisplayPixelFormat::RGBA5551:
- CopyOut15Bit(src_x, src_y, width, height, field, interlaced, interleaved);
+ case GPUTexture::Format::RGBA5551:
+ CopyOut15Bit(src_x, src_y, width, height, field, interlaced, interleaved);
break;
- case HostDisplayPixelFormat::RGB565:
- CopyOut15Bit(src_x, src_y, width, height, field, interlaced, interleaved);
+ case GPUTexture::Format::RGB565:
+ CopyOut15Bit(src_x, src_y, width, height, field, interlaced, interleaved);
break;
- case HostDisplayPixelFormat::RGBA8:
- CopyOut15Bit(src_x, src_y, width, height, field, interlaced, interleaved);
+ case GPUTexture::Format::RGBA8:
+ CopyOut15Bit(src_x, src_y, width, height, field, interlaced, interleaved);
break;
- case HostDisplayPixelFormat::BGRA8:
- CopyOut15Bit(src_x, src_y, width, height, field, interlaced, interleaved);
+ case GPUTexture::Format::BGRA8:
+ CopyOut15Bit(src_x, src_y, width, height, field, interlaced, interleaved);
break;
default:
break;
}
}
-template
+template
void GPU_SW::CopyOut24Bit(u32 src_x, u32 src_y, u32 skip_x, u32 width, u32 height, u32 field, bool interlaced,
bool interleaved)
{
@@ -346,15 +346,15 @@ void GPU_SW::CopyOut24Bit(u32 src_x, u32 src_y, u32 skip_x, u32 width, u32 heigh
u32 dst_stride;
using OutputPixelType = std::conditional_t<
- display_format == HostDisplayPixelFormat::RGBA8 || display_format == HostDisplayPixelFormat::BGRA8, u32, u16>;
+ display_format == GPUTexture::Format::RGBA8 || display_format == GPUTexture::Format::BGRA8, u32, u16>;
- HostDisplayTexture* texture = GetDisplayTexture(width, height, display_format);
+ GPUTexture* texture = GetDisplayTexture(width, height, display_format);
if (!texture)
return;
if (!interlaced)
{
- if (!texture->BeginUpdate(width, height, reinterpret_cast(&dst_ptr), &dst_stride))
+ if (!g_host_display->BeginTextureUpdate(texture, width, height, reinterpret_cast(&dst_ptr), &dst_stride))
return;
}
else
@@ -375,7 +375,7 @@ void GPU_SW::CopyOut24Bit(u32 src_x, u32 src_y, u32 skip_x, u32 width, u32 heigh
const u32 src_stride = (VRAM_WIDTH << interleaved_shift) * sizeof(u16);
for (u32 row = 0; row < rows; row++)
{
- if constexpr (display_format == HostDisplayPixelFormat::RGBA8)
+ if constexpr (display_format == GPUTexture::Format::RGBA8)
{
const u8* src_row_ptr = src_ptr;
u8* dst_row_ptr = reinterpret_cast(dst_ptr);
@@ -387,7 +387,7 @@ void GPU_SW::CopyOut24Bit(u32 src_x, u32 src_y, u32 skip_x, u32 width, u32 heigh
*(dst_row_ptr++) = 0xFF;
}
}
- else if constexpr (display_format == HostDisplayPixelFormat::BGRA8)
+ else if constexpr (display_format == GPUTexture::Format::BGRA8)
{
const u8* src_row_ptr = src_ptr;
u8* dst_row_ptr = reinterpret_cast(dst_ptr);
@@ -400,7 +400,7 @@ void GPU_SW::CopyOut24Bit(u32 src_x, u32 src_y, u32 skip_x, u32 width, u32 heigh
src_row_ptr += 3;
}
}
- else if constexpr (display_format == HostDisplayPixelFormat::RGB565)
+ else if constexpr (display_format == GPUTexture::Format::RGB565)
{
const u8* src_row_ptr = src_ptr;
u16* dst_row_ptr = reinterpret_cast(dst_ptr);
@@ -411,7 +411,7 @@ void GPU_SW::CopyOut24Bit(u32 src_x, u32 src_y, u32 skip_x, u32 width, u32 heigh
src_row_ptr += 3;
}
}
- else if constexpr (display_format == HostDisplayPixelFormat::RGBA5551)
+ else if constexpr (display_format == GPUTexture::Format::RGBA5551)
{
const u8* src_row_ptr = src_ptr;
u16* dst_row_ptr = reinterpret_cast(dst_ptr);
@@ -442,19 +442,19 @@ void GPU_SW::CopyOut24Bit(u32 src_x, u32 src_y, u32 skip_x, u32 width, u32 heigh
const u8 shift = static_cast(col & 1u) * 8;
const u32 rgb = (((ZeroExtend32(s1) << 16) | ZeroExtend32(s0)) >> shift);
- if constexpr (display_format == HostDisplayPixelFormat::RGBA8)
+ if constexpr (display_format == GPUTexture::Format::RGBA8)
{
*(dst_row_ptr++) = rgb | 0xFF000000u;
}
- else if constexpr (display_format == HostDisplayPixelFormat::BGRA8)
+ else if constexpr (display_format == GPUTexture::Format::BGRA8)
{
*(dst_row_ptr++) = (rgb & 0x00FF00) | ((rgb & 0xFF) << 16) | ((rgb >> 16) & 0xFF) | 0xFF000000u;
}
- else if constexpr (display_format == HostDisplayPixelFormat::RGB565)
+ else if constexpr (display_format == GPUTexture::Format::RGB565)
{
*(dst_row_ptr++) = ((rgb >> 3) & 0x1F) | (((rgb >> 10) << 5) & 0x7E0) | (((rgb >> 19) << 11) & 0x3E0000);
}
- else if constexpr (display_format == HostDisplayPixelFormat::RGBA5551)
+ else if constexpr (display_format == GPUTexture::Format::RGBA5551)
{
*(dst_row_ptr++) = ((rgb >> 3) & 0x1F) | (((rgb >> 11) << 5) & 0x3E0) | (((rgb >> 19) << 10) & 0x1F0000);
}
@@ -466,30 +466,30 @@ void GPU_SW::CopyOut24Bit(u32 src_x, u32 src_y, u32 skip_x, u32 width, u32 heigh
}
if (!interlaced)
- texture->EndUpdate(0, 0, width, height);
+ g_host_display->EndTextureUpdate(texture, 0, 0, width, height);
else
- texture->Update(0, 0, width, height, m_display_texture_buffer.data(), output_stride);
+ g_host_display->UpdateTexture(texture, 0, 0, width, height, m_display_texture_buffer.data(), output_stride);
- g_host_display->SetDisplayTexture(texture->GetHandle(), display_format, width, height, 0, 0, width, height);
+ g_host_display->SetDisplayTexture(texture, 0, 0, width, height);
}
-void GPU_SW::CopyOut24Bit(HostDisplayPixelFormat display_format, u32 src_x, u32 src_y, u32 skip_x, u32 width,
+void GPU_SW::CopyOut24Bit(GPUTexture::Format display_format, u32 src_x, u32 src_y, u32 skip_x, u32 width,
u32 height, u32 field, bool interlaced, bool interleaved)
{
switch (display_format)
{
- case HostDisplayPixelFormat::RGBA5551:
- CopyOut24Bit(src_x, src_y, skip_x, width, height, field, interlaced,
+ case GPUTexture::Format::RGBA5551:
+ CopyOut24Bit(src_x, src_y, skip_x, width, height, field, interlaced,
interleaved);
break;
- case HostDisplayPixelFormat::RGB565:
- CopyOut24Bit(src_x, src_y, skip_x, width, height, field, interlaced, interleaved);
+ case GPUTexture::Format::RGB565:
+ CopyOut24Bit(src_x, src_y, skip_x, width, height, field, interlaced, interleaved);
break;
- case HostDisplayPixelFormat::RGBA8:
- CopyOut24Bit(src_x, src_y, skip_x, width, height, field, interlaced, interleaved);
+ case GPUTexture::Format::RGBA8:
+ CopyOut24Bit(src_x, src_y, skip_x, width, height, field, interlaced, interleaved);
break;
- case HostDisplayPixelFormat::BGRA8:
- CopyOut24Bit(src_x, src_y, skip_x, width, height, field, interlaced, interleaved);
+ case GPUTexture::Format::BGRA8:
+ CopyOut24Bit(src_x, src_y, skip_x, width, height, field, interlaced, interleaved);
break;
default:
break;
diff --git a/src/core/gpu_sw.h b/src/core/gpu_sw.h
index c33d1d8d2..0186f3f6d 100644
--- a/src/core/gpu_sw.h
+++ b/src/core/gpu_sw.h
@@ -12,7 +12,7 @@ namespace Threading
class Thread;
}
-class HostDisplayTexture;
+class GPUTexture;
class GPU_SW final : public GPU
{
@@ -26,7 +26,7 @@ public:
const Threading::Thread* GetSWThread() const override;
bool Initialize() override;
- bool DoState(StateWrapper& sw, HostDisplayTexture** host_texture, bool update_display) override;
+ bool DoState(StateWrapper& sw, GPUTexture** host_texture, bool update_display) override;
void Reset(bool clear_vram) override;
void UpdateSettings() override;
@@ -36,15 +36,15 @@ protected:
void UpdateVRAM(u32 x, u32 y, u32 width, u32 height, const void* data, bool set_mask, bool check_mask) override;
void CopyVRAM(u32 src_x, u32 src_y, u32 dst_x, u32 dst_y, u32 width, u32 height) override;
- template