GS: Convert texture format to enum

This commit is contained in:
TellowKrinkle 2021-11-02 02:37:07 -05:00 committed by tellowkrinkle
parent 1d37ba47f4
commit a4b8c33cf3
25 changed files with 165 additions and 149 deletions

View File

@ -135,7 +135,7 @@ void GSDevice::Present(GSTexture* sTex, GSTexture* dTex, const GSVector4& dRect,
StretchRect(sTex, dTex, dRect, shader, m_linear_present); StretchRect(sTex, dTex, dRect, shader, m_linear_present);
} }
GSTexture* GSDevice::FetchSurface(GSTexture::Type type, int w, int h, int format) GSTexture* GSDevice::FetchSurface(GSTexture::Type type, int w, int h, GSTexture::Format format)
{ {
const GSVector2i size(w, h); const GSVector2i size(w, h);
@ -223,36 +223,44 @@ void GSDevice::PurgePool()
} }
} }
GSTexture* GSDevice::CreateSparseRenderTarget(int w, int h, int format) GSTexture* GSDevice::CreateSparseRenderTarget(int w, int h, GSTexture::Format format)
{ {
return FetchSurface(HasColorSparse() ? GSTexture::Type::SparseRenderTarget : GSTexture::Type::RenderTarget, w, h, format); return FetchSurface(HasColorSparse() ? GSTexture::Type::SparseRenderTarget : GSTexture::Type::RenderTarget, w, h, format);
} }
GSTexture* GSDevice::CreateSparseDepthStencil(int w, int h, int format) GSTexture* GSDevice::CreateSparseDepthStencil(int w, int h, GSTexture::Format format)
{ {
return FetchSurface(HasDepthSparse() ? GSTexture::Type::SparseDepthStencil : GSTexture::Type::DepthStencil, w, h, format); return FetchSurface(HasDepthSparse() ? GSTexture::Type::SparseDepthStencil : GSTexture::Type::DepthStencil, w, h, format);
} }
GSTexture* GSDevice::CreateRenderTarget(int w, int h, int format) GSTexture* GSDevice::CreateRenderTarget(int w, int h, GSTexture::Format format)
{ {
return FetchSurface(GSTexture::Type::RenderTarget, w, h, format); return FetchSurface(GSTexture::Type::RenderTarget, w, h, format);
} }
GSTexture* GSDevice::CreateDepthStencil(int w, int h, int format) GSTexture* GSDevice::CreateDepthStencil(int w, int h, GSTexture::Format format)
{ {
return FetchSurface(GSTexture::Type::DepthStencil, w, h, format); return FetchSurface(GSTexture::Type::DepthStencil, w, h, format);
} }
GSTexture* GSDevice::CreateTexture(int w, int h, int format) GSTexture* GSDevice::CreateTexture(int w, int h, GSTexture::Format format)
{ {
return FetchSurface(GSTexture::Type::Texture, w, h, format); return FetchSurface(GSTexture::Type::Texture, w, h, format);
} }
GSTexture* GSDevice::CreateOffscreen(int w, int h, int format) GSTexture* GSDevice::CreateOffscreen(int w, int h, GSTexture::Format format)
{ {
return FetchSurface(GSTexture::Type::Offscreen, w, h, format); return FetchSurface(GSTexture::Type::Offscreen, w, h, format);
} }
GSTexture::Format GSDevice::GetDefaultTextureFormat(GSTexture::Type type)
{
if (type == GSTexture::Type::DepthStencil || type == GSTexture::Type::SparseDepthStencil)
return GSTexture::Format::DepthStencil;
else
return GSTexture::Format::Color;
}
void GSDevice::StretchRect(GSTexture* sTex, GSTexture* dTex, const GSVector4& dRect, ShaderConvert shader, bool linear) void GSDevice::StretchRect(GSTexture* sTex, GSTexture* dTex, const GSVector4& dRect, ShaderConvert shader, bool linear)
{ {
StretchRect(sTex, GSVector4(0, 0, 1, 1), dTex, dRect, shader, linear); StretchRect(sTex, GSVector4(0, 0, 1, 1), dTex, dRect, shader, linear);
@ -390,9 +398,10 @@ bool GSDevice::ResizeTexture(GSTexture** t, GSTexture::Type type, int w, int h)
if (t2 == NULL || t2->GetWidth() != w || t2->GetHeight() != h) if (t2 == NULL || t2->GetWidth() != w || t2->GetHeight() != h)
{ {
GSTexture::Format fmt = t2 ? t2->GetFormat() : GetDefaultTextureFormat(type);
delete t2; delete t2;
t2 = FetchSurface(type, w, h, 0); t2 = FetchSurface(type, w, h, fmt);
*t = t2; *t = t2;
} }

View File

@ -175,8 +175,8 @@ protected:
unsigned int m_frame; // for ageing the pool unsigned int m_frame; // for ageing the pool
bool m_linear_present; bool m_linear_present;
virtual GSTexture* CreateSurface(GSTexture::Type type, int w, int h, int format) = 0; virtual GSTexture* CreateSurface(GSTexture::Type type, int w, int h, GSTexture::Format format) = 0;
virtual GSTexture* FetchSurface(GSTexture::Type type, int w, int h, int format); virtual GSTexture* FetchSurface(GSTexture::Type type, int w, int h, GSTexture::Format format);
virtual void DoMerge(GSTexture* sTex[3], GSVector4* sRect, GSTexture* dTex, GSVector4* dRect, const GSRegPMODE& PMODE, const GSRegEXTBUF& EXTBUF, const GSVector4& c) = 0; virtual void DoMerge(GSTexture* sTex[3], GSVector4* sRect, GSTexture* dTex, GSVector4* dRect, const GSRegPMODE& PMODE, const GSRegEXTBUF& EXTBUF, const GSVector4& c) = 0;
virtual void DoInterlace(GSTexture* sTex, GSTexture* dTex, int shader, bool linear, float yoffset) = 0; virtual void DoInterlace(GSTexture* sTex, GSTexture* dTex, int shader, bool linear, float yoffset) = 0;
@ -220,14 +220,15 @@ public:
virtual void ClearDepth(GSTexture* t) {} virtual void ClearDepth(GSTexture* t) {}
virtual void ClearStencil(GSTexture* t, u8 c) {} virtual void ClearStencil(GSTexture* t, u8 c) {}
GSTexture* CreateSparseRenderTarget(int w, int h, int format = 0); GSTexture* CreateSparseRenderTarget(int w, int h, GSTexture::Format format);
GSTexture* CreateSparseDepthStencil(int w, int h, int format = 0); GSTexture* CreateSparseDepthStencil(int w, int h, GSTexture::Format format);
GSTexture* CreateRenderTarget(int w, int h, int format = 0); GSTexture* CreateRenderTarget(int w, int h, GSTexture::Format format);
GSTexture* CreateDepthStencil(int w, int h, int format = 0); GSTexture* CreateDepthStencil(int w, int h, GSTexture::Format format);
GSTexture* CreateTexture(int w, int h, int format = 0); GSTexture* CreateTexture(int w, int h, GSTexture::Format format);
GSTexture* CreateOffscreen(int w, int h, int format = 0); GSTexture* CreateOffscreen(int w, int h, GSTexture::Format format);
GSTexture::Format GetDefaultTextureFormat(GSTexture::Type type);
virtual GSTexture* CopyOffscreen(GSTexture* src, const GSVector4& sRect, int w, int h, int format = 0, ShaderConvert ps_shader = ShaderConvert::COPY) { return NULL; } virtual GSTexture* CopyOffscreen(GSTexture* src, const GSVector4& sRect, int w, int h, GSTexture::Format format, ShaderConvert ps_shader = ShaderConvert::COPY) { return NULL; }
virtual void CopyRect(GSTexture* sTex, GSTexture* dTex, const GSVector4i& r) {} virtual void CopyRect(GSTexture* sTex, GSTexture* dTex, const GSVector4i& r) {}
virtual void StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture* dTex, const GSVector4& dRect, ShaderConvert shader = ShaderConvert::COPY, bool linear = true) {} virtual void StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture* dTex, const GSVector4& dRect, ShaderConvert shader = ShaderConvert::COPY, bool linear = true) {}

View File

@ -512,7 +512,7 @@ void GSRenderer::VSync(int field)
{ {
GSVector2i size = m_capture.GetSize(); GSVector2i size = m_capture.GetSize();
if (GSTexture* offscreen = m_dev->CopyOffscreen(current, GSVector4(0, 0, 1, 1), size.x, size.y)) if (GSTexture* offscreen = m_dev->CopyOffscreen(current, GSVector4(0, 0, 1, 1), size.x, size.y, GSTexture::Format::Color))
{ {
GSTexture::GSMap m; GSTexture::GSMap m;

View File

@ -23,7 +23,7 @@ GSTexture::GSTexture()
, m_committed_size(0, 0) , m_committed_size(0, 0)
, m_gpu_page_size(0, 0) , m_gpu_page_size(0, 0)
, m_type(Type::Invalid) , m_type(Type::Invalid)
, m_format(0) , m_format(Format::Invalid)
, m_sparse(false) , m_sparse(false)
, last_frame_used(0) , last_frame_used(0)
, LikelyOffset(false) , LikelyOffset(false)

View File

@ -38,13 +38,26 @@ public:
SparseDepthStencil, SparseDepthStencil,
}; };
enum class Format
{
Invalid = 0, ///< Used for initialization
Backbuffer, ///< For displaying to the screen
Color, ///< Standard (RGBA8) color texture
FloatColor, ///< Float-based color texture for colclip emulation (RGBA32F)
DepthStencil, ///< Depth stencil texture
UNorm8, ///< A8UNorm texture for paletted textures and the OSD font
UInt16, ///< UInt16 texture for reading back 16-bit depth
UInt32, ///< UInt32 texture for reading back 24 and 32-bit depth
Int32, ///< Int32 texture for date emulation
};
protected: protected:
GSVector2 m_scale; GSVector2 m_scale;
GSVector2i m_size; GSVector2i m_size;
GSVector2i m_committed_size; GSVector2i m_committed_size;
GSVector2i m_gpu_page_size; GSVector2i m_gpu_page_size;
Type m_type; Type m_type;
int m_format; Format m_format;
bool m_sparse; bool m_sparse;
public: public:
@ -72,7 +85,7 @@ public:
GSVector2i GetSize() const { return m_size; } GSVector2i GetSize() const { return m_size; }
Type GetType() const { return m_type; } Type GetType() const { return m_type; }
int GetFormat() const { return m_format; } Format GetFormat() const { return m_format; }
virtual void CommitPages(const GSVector2i& region, bool commit) {} virtual void CommitPages(const GSVector2i& region, bool commit) {}
void CommitRegion(const GSVector2i& region); void CommitRegion(const GSVector2i& region);

View File

@ -418,7 +418,7 @@ bool GSDevice11::Create(const WindowInfo& wi)
const GSVector2i tex_font = m_osd.get_texture_font_size(); const GSVector2i tex_font = m_osd.get_texture_font_size();
m_font = std::unique_ptr<GSTexture>( m_font = std::unique_ptr<GSTexture>(
CreateSurface(GSTexture::Type::Texture, tex_font.x, tex_font.y, DXGI_FORMAT_R8_UNORM)); CreateSurface(GSTexture::Type::Texture, tex_font.x, tex_font.y, GSTexture::Format::UNorm8));
return true; return true;
} }
@ -443,7 +443,7 @@ bool GSDevice11::Reset(int w, int h)
return false; return false;
} }
m_backbuffer = new GSTexture11(std::move(backbuffer)); m_backbuffer = new GSTexture11(std::move(backbuffer), GSTexture::Format::Backbuffer);
} }
return true; return true;
@ -562,16 +562,32 @@ void GSDevice11::ClearStencil(GSTexture* t, u8 c)
m_ctx->ClearDepthStencilView(*(GSTexture11*)t, D3D11_CLEAR_STENCIL, 0, c); m_ctx->ClearDepthStencilView(*(GSTexture11*)t, D3D11_CLEAR_STENCIL, 0, c);
} }
GSTexture* GSDevice11::CreateSurface(GSTexture::Type type, int w, int h, int format) GSTexture* GSDevice11::CreateSurface(GSTexture::Type type, int w, int h, GSTexture::Format format)
{ {
D3D11_TEXTURE2D_DESC desc; D3D11_TEXTURE2D_DESC desc;
memset(&desc, 0, sizeof(desc)); memset(&desc, 0, sizeof(desc));
DXGI_FORMAT dxformat;
switch (format)
{
case GSTexture::Format::Color: dxformat = DXGI_FORMAT_R8G8B8A8_UNORM; break;
case GSTexture::Format::FloatColor: dxformat = DXGI_FORMAT_R32G32B32A32_FLOAT; break;
case GSTexture::Format::DepthStencil: dxformat = DXGI_FORMAT_R32G8X24_TYPELESS; break;
case GSTexture::Format::UNorm8: dxformat = DXGI_FORMAT_A8_UNORM; break;
case GSTexture::Format::UInt16: dxformat = DXGI_FORMAT_R16_UINT; break;
case GSTexture::Format::UInt32: dxformat = DXGI_FORMAT_R32_UINT; break;
case GSTexture::Format::Int32: dxformat = DXGI_FORMAT_R32_SINT; break;
case GSTexture::Format::Invalid:
case GSTexture::Format::Backbuffer:
ASSERT(0);
dxformat = DXGI_FORMAT_UNKNOWN;
}
// Texture limit for D3D10/11 min 1, max 8192 D3D10, max 16384 D3D11. // Texture limit for D3D10/11 min 1, max 8192 D3D10, max 16384 D3D11.
desc.Width = std::max(1, std::min(w, m_d3d_texsize)); desc.Width = std::max(1, std::min(w, m_d3d_texsize));
desc.Height = std::max(1, std::min(h, m_d3d_texsize)); desc.Height = std::max(1, std::min(h, m_d3d_texsize));
desc.Format = (DXGI_FORMAT)format; desc.Format = dxformat;
desc.MipLevels = 1; desc.MipLevels = 1;
desc.ArraySize = 1; desc.ArraySize = 1;
desc.SampleDesc.Count = 1; desc.SampleDesc.Count = 1;
@ -580,7 +596,7 @@ GSTexture* GSDevice11::CreateSurface(GSTexture::Type type, int w, int h, int for
// mipmap = m_mipmap > 1 || m_filter != TriFiltering::None; // mipmap = m_mipmap > 1 || m_filter != TriFiltering::None;
const bool mipmap = m_mipmap > 1; const bool mipmap = m_mipmap > 1;
const int layers = mipmap && format == DXGI_FORMAT_R8G8B8A8_UNORM ? (int)log2(std::max(w, h)) : 1; const int layers = mipmap && format == GSTexture::Format::Color ? (int)log2(std::max(w, h)) : 1;
switch (type) switch (type)
{ {
@ -607,7 +623,7 @@ GSTexture* GSDevice11::CreateSurface(GSTexture::Type type, int w, int h, int for
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
{ {
t = new GSTexture11(std::move(texture)); t = new GSTexture11(std::move(texture), format);
switch (type) switch (type)
{ {
@ -627,24 +643,16 @@ GSTexture* GSDevice11::CreateSurface(GSTexture::Type type, int w, int h, int for
return t; return t;
} }
GSTexture* GSDevice11::FetchSurface(GSTexture::Type type, int w, int h, int format) GSTexture* GSDevice11::FetchSurface(GSTexture::Type type, int w, int h, GSTexture::Format format)
{ {
if (format == 0)
format = (type == GSTexture::Type::DepthStencil || type == GSTexture::Type::SparseDepthStencil) ? DXGI_FORMAT_R32G8X24_TYPELESS : DXGI_FORMAT_R8G8B8A8_UNORM;
return __super::FetchSurface(type, w, h, format); return __super::FetchSurface(type, w, h, format);
} }
GSTexture* GSDevice11::CopyOffscreen(GSTexture* src, const GSVector4& sRect, int w, int h, int format, ShaderConvert ps_shader) GSTexture* GSDevice11::CopyOffscreen(GSTexture* src, const GSVector4& sRect, int w, int h, GSTexture::Format format, ShaderConvert ps_shader)
{ {
GSTexture* dst = NULL; GSTexture* dst = NULL;
if (format == 0) ASSERT(format == GSTexture::Format::Color || format == GSTexture::Format::UInt16 || format == GSTexture::Format::UInt32);
{
format = DXGI_FORMAT_R8G8B8A8_UNORM;
}
ASSERT(format == DXGI_FORMAT_R8G8B8A8_UNORM || format == DXGI_FORMAT_R16_UINT || format == DXGI_FORMAT_R32_UINT);
if (GSTexture* rt = CreateRenderTarget(w, h, format)) if (GSTexture* rt = CreateRenderTarget(w, h, format))
{ {

View File

@ -396,8 +396,8 @@ private:
int m_mipmap; int m_mipmap;
int m_d3d_texsize; int m_d3d_texsize;
GSTexture* CreateSurface(GSTexture::Type type, int w, int h, int format) final; GSTexture* CreateSurface(GSTexture::Type type, int w, int h, GSTexture::Format format) final;
GSTexture* FetchSurface(GSTexture::Type type, int w, int h, int format) final; GSTexture* FetchSurface(GSTexture::Type type, int w, int h, GSTexture::Format format) final;
void DoMerge(GSTexture* sTex[3], GSVector4* sRect, GSTexture* dTex, GSVector4* dRect, const GSRegPMODE& PMODE, const GSRegEXTBUF& EXTBUF, const GSVector4& c) final; void DoMerge(GSTexture* sTex[3], GSVector4* sRect, GSTexture* dTex, GSVector4* dRect, const GSRegPMODE& PMODE, const GSRegEXTBUF& EXTBUF, const GSVector4& c) final;
void DoInterlace(GSTexture* sTex, GSTexture* dTex, int shader, bool linear, float yoffset = 0) final; void DoInterlace(GSTexture* sTex, GSTexture* dTex, int shader, bool linear, float yoffset = 0) final;
@ -542,7 +542,7 @@ public:
void ClearDepth(GSTexture* t) final; void ClearDepth(GSTexture* t) final;
void ClearStencil(GSTexture* t, u8 c) final; void ClearStencil(GSTexture* t, u8 c) final;
GSTexture* CopyOffscreen(GSTexture* src, const GSVector4& sRect, int w, int h, int format = 0, ShaderConvert ps_shader = ShaderConvert::COPY) final; GSTexture* CopyOffscreen(GSTexture* src, const GSVector4& sRect, int w, int h, GSTexture::Format format, ShaderConvert ps_shader = ShaderConvert::COPY) final;
void CloneTexture(GSTexture* src, GSTexture** dest); void CloneTexture(GSTexture* src, GSTexture** dest);

View File

@ -890,7 +890,7 @@ void GSRendererDX11::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sou
{ {
const GSVector4 dRect(ComputeBoundingBox(rtscale, rtsize)); const GSVector4 dRect(ComputeBoundingBox(rtscale, rtsize));
const GSVector4 sRect = dRect / GSVector4(rtsize.x, rtsize.y).xyxy(); const GSVector4 sRect = dRect / GSVector4(rtsize.x, rtsize.y).xyxy();
hdr_rt = dev->CreateRenderTarget(rtsize.x, rtsize.y, DXGI_FORMAT_R32G32B32A32_FLOAT); hdr_rt = dev->CreateRenderTarget(rtsize.x, rtsize.y, GSTexture::Format::FloatColor);
// Warning: StretchRect must be called before BeginScene otherwise // Warning: StretchRect must be called before BeginScene otherwise
// vertices will be overwritten. Trust me you don't want to do that. // vertices will be overwritten. Trust me you don't want to do that.
dev->StretchRect(rt, sRect, hdr_rt, dRect, ShaderConvert::COPY, false); dev->StretchRect(rt, sRect, hdr_rt, dRect, ShaderConvert::COPY, false);

View File

@ -17,7 +17,7 @@
#include "GSTexture11.h" #include "GSTexture11.h"
#include "GS/GSPng.h" #include "GS/GSPng.h"
GSTexture11::GSTexture11(wil::com_ptr_nothrow<ID3D11Texture2D> texture) GSTexture11::GSTexture11(wil::com_ptr_nothrow<ID3D11Texture2D> texture, GSTexture::Format format)
: m_texture(std::move(texture)), m_layer(0) : m_texture(std::move(texture)), m_layer(0)
{ {
ASSERT(m_texture); ASSERT(m_texture);
@ -39,7 +39,7 @@ GSTexture11::GSTexture11(wil::com_ptr_nothrow<ID3D11Texture2D> texture)
else if (m_desc.Usage == D3D11_USAGE_STAGING) else if (m_desc.Usage == D3D11_USAGE_STAGING)
m_type = Type::Offscreen; m_type = Type::Offscreen;
m_format = (int)m_desc.Format; m_format = format;
m_max_layer = m_desc.MipLevels; m_max_layer = m_desc.MipLevels;
} }

View File

@ -34,7 +34,7 @@ class GSTexture11 : public GSTexture
int m_max_layer; int m_max_layer;
public: public:
explicit GSTexture11(wil::com_ptr_nothrow<ID3D11Texture2D> texture); explicit GSTexture11(wil::com_ptr_nothrow<ID3D11Texture2D> texture, GSTexture::Format format);
bool Update(const GSVector4i& r, const void* data, int pitch, int layer = 0); bool Update(const GSVector4i& r, const void* data, int pitch, int layer = 0);
bool Map(GSMap& m, const GSVector4i* r = NULL, int layer = 0); bool Map(GSMap& m, const GSVector4i* r = NULL, int layer = 0);

View File

@ -32,31 +32,31 @@ void GSTextureCache11::Read(Target* t, const GSVector4i& r)
const GIFRegTEX0& TEX0 = t->m_TEX0; const GIFRegTEX0& TEX0 = t->m_TEX0;
DXGI_FORMAT format; GSTexture::Format format;
ShaderConvert ps_shader; ShaderConvert ps_shader;
switch (TEX0.PSM) switch (TEX0.PSM)
{ {
case PSM_PSMCT32: case PSM_PSMCT32:
case PSM_PSMCT24: case PSM_PSMCT24:
format = DXGI_FORMAT_R8G8B8A8_UNORM; format = GSTexture::Format::Color;
ps_shader = ShaderConvert::COPY; ps_shader = ShaderConvert::COPY;
break; break;
case PSM_PSMCT16: case PSM_PSMCT16:
case PSM_PSMCT16S: case PSM_PSMCT16S:
format = DXGI_FORMAT_R16_UINT; format = GSTexture::Format::UInt16;
ps_shader = ShaderConvert::RGBA8_TO_16_BITS; ps_shader = ShaderConvert::RGBA8_TO_16_BITS;
break; break;
case PSM_PSMZ32: case PSM_PSMZ32:
case PSM_PSMZ24: case PSM_PSMZ24:
format = DXGI_FORMAT_R32_UINT; format = GSTexture::Format::UInt32;
ps_shader = ShaderConvert::FLOAT32_TO_32_BITS; ps_shader = ShaderConvert::FLOAT32_TO_32_BITS;
break; break;
case PSM_PSMZ16: case PSM_PSMZ16:
case PSM_PSMZ16S: case PSM_PSMZ16S:
format = DXGI_FORMAT_R16_UINT; format = GSTexture::Format::UInt16;
ps_shader = ShaderConvert::FLOAT32_TO_32_BITS; ps_shader = ShaderConvert::FLOAT32_TO_32_BITS;
break; break;
@ -115,7 +115,7 @@ void GSTextureCache11::Read(Source* t, const GSVector4i& r)
const GIFRegTEX0& TEX0 = t->m_TEX0; const GIFRegTEX0& TEX0 = t->m_TEX0;
if (GSTexture* offscreen = m_renderer->m_dev->CreateOffscreen(r.width(), r.height())) if (GSTexture* offscreen = m_renderer->m_dev->CreateOffscreen(r.width(), r.height(), GSTexture::Format::Color))
{ {
m_renderer->m_dev->CopyRect(t->m_texture, offscreen, r); m_renderer->m_dev->CopyRect(t->m_texture, offscreen, r);

View File

@ -1905,7 +1905,7 @@ bool GSRendererHW::OI_BlitFMV(GSTextureCache::Target* _rt, GSTextureCache::Sourc
// Do the blit. With a Copy mess to avoid issue with limited API (dx) // Do the blit. With a Copy mess to avoid issue with limited API (dx)
// m_dev->StretchRect(tex->m_texture, sRect, tex->m_texture, dRect); // m_dev->StretchRect(tex->m_texture, sRect, tex->m_texture, dRect);
const GSVector4i r_full(0, 0, tw, th); const GSVector4i r_full(0, 0, tw, th);
if (GSTexture* rt = m_dev->CreateRenderTarget(tw, th)) if (GSTexture* rt = m_dev->CreateRenderTarget(tw, th, GSTexture::Format::Color))
{ {
m_dev->CopyRect(tex->m_texture, rt, r_full); m_dev->CopyRect(tex->m_texture, rt, r_full);
@ -2032,7 +2032,7 @@ bool GSRendererHW::OI_FFXII(GSTexture* rt, GSTexture* ds, GSTextureCache::Source
m_dev->Recycle(t->m_texture); m_dev->Recycle(t->m_texture);
t->m_texture = m_dev->CreateTexture(512, 512); t->m_texture = m_dev->CreateTexture(512, 512, GSTexture::Format::Color);
t->m_texture->Update(GSVector4i(0, 0, 448, lines), video, 448 * 4); t->m_texture->Update(GSVector4i(0, 0, 448, lines), video, 448 * 4);

View File

@ -1301,7 +1301,7 @@ GSTextureCache::Source* GSTextureCache::CreateSource(const GIFRegTEX0& TEX0, con
int h = (int)(scale.y * th); int h = (int)(scale.y * th);
GSTexture* sTex = dst->m_texture; GSTexture* sTex = dst->m_texture;
GSTexture* dTex = m_renderer->m_dev->CreateRenderTarget(w, h); GSTexture* dTex = m_renderer->m_dev->CreateRenderTarget(w, h, GSTexture::Format::Color);
GSVector4i area(x, y, x + w, y + h); GSVector4i area(x, y, x + w, y + h);
m_renderer->m_dev->CopyRect(sTex, dTex, area); m_renderer->m_dev->CopyRect(sTex, dTex, area);
@ -1333,7 +1333,7 @@ GSTextureCache::Source* GSTextureCache::CreateSource(const GIFRegTEX0& TEX0, con
// So it could be tricky to put in the middle of the DrawPrims // So it could be tricky to put in the middle of the DrawPrims
// Texture is created to keep code compatibility // Texture is created to keep code compatibility
GSTexture* dTex = m_renderer->m_dev->CreateRenderTarget(tw, th); GSTexture* dTex = m_renderer->m_dev->CreateRenderTarget(tw, th, GSTexture::Format::Color);
// Keep a trace of origin of the texture // Keep a trace of origin of the texture
src->m_texture = dTex; src->m_texture = dTex;
@ -1504,7 +1504,7 @@ GSTextureCache::Source* GSTextureCache::CreateSource(const GIFRegTEX0& TEX0, con
// Don't be fooled by the name. 'dst' is the old target (hence the input) // Don't be fooled by the name. 'dst' is the old target (hence the input)
// 'src' is the new texture cache entry (hence the output) // 'src' is the new texture cache entry (hence the output)
GSTexture* sTex = dst->m_texture; GSTexture* sTex = dst->m_texture;
GSTexture* dTex = m_renderer->m_dev->CreateRenderTarget(w, h); GSTexture* dTex = m_renderer->m_dev->CreateRenderTarget(w, h, GSTexture::Format::Color);
src->m_texture = dTex; src->m_texture = dTex;
// GH: by default (m_paltex == 0) GS converts texture to the 32 bit format // GH: by default (m_paltex == 0) GS converts texture to the 32 bit format
@ -1609,12 +1609,12 @@ GSTextureCache::Source* GSTextureCache::CreateSource(const GIFRegTEX0& TEX0, con
{ {
if (m_paltex && psm.pal > 0) if (m_paltex && psm.pal > 0)
{ {
src->m_texture = m_renderer->m_dev->CreateTexture(tw, th, Get8bitFormat()); src->m_texture = m_renderer->m_dev->CreateTexture(tw, th, GSTexture::Format::UNorm8);
AttachPaletteToSource(src, psm.pal, true); AttachPaletteToSource(src, psm.pal, true);
} }
else else
{ {
src->m_texture = m_renderer->m_dev->CreateTexture(tw, th); src->m_texture = m_renderer->m_dev->CreateTexture(tw, th, GSTexture::Format::Color);
if (psm.pal > 0) if (psm.pal > 0)
{ {
AttachPaletteToSource(src, psm.pal, false); AttachPaletteToSource(src, psm.pal, false);
@ -1641,13 +1641,13 @@ GSTextureCache::Target* GSTextureCache::CreateTarget(const GIFRegTEX0& TEX0, int
if (type == RenderTarget) if (type == RenderTarget)
{ {
t->m_texture = m_renderer->m_dev->CreateSparseRenderTarget(w, h); t->m_texture = m_renderer->m_dev->CreateSparseRenderTarget(w, h, GSTexture::Format::Color);
t->m_used = true; // FIXME t->m_used = true; // FIXME
} }
else if (type == DepthStencil) else if (type == DepthStencil)
{ {
t->m_texture = m_renderer->m_dev->CreateSparseDepthStencil(w, h); t->m_texture = m_renderer->m_dev->CreateSparseDepthStencil(w, h, GSTexture::Format::DepthStencil);
} }
m_dst[type].push_front(t); m_dst[type].push_front(t);
@ -2067,7 +2067,7 @@ void GSTextureCache::Target::Update()
TEXA.TA0 = 0; TEXA.TA0 = 0;
TEXA.TA1 = 0x80; TEXA.TA1 = 0x80;
GSTexture* t = m_renderer->m_dev->CreateTexture(w, h); GSTexture* t = m_renderer->m_dev->CreateTexture(w, h, GSTexture::Format::Color);
GSOffset off = m_renderer->m_mem.GetOffset(m_TEX0.TBP0, m_TEX0.TBW, m_TEX0.PSM); GSOffset off = m_renderer->m_mem.GetOffset(m_TEX0.TBP0, m_TEX0.TBW, m_TEX0.PSM);
@ -2227,7 +2227,7 @@ void GSTextureCache::Palette::InitializeTexture()
// sampling such texture are always normalized by 255. // sampling such texture are always normalized by 255.
// This is because indexes are stored as normalized values of an RGBA texture (e.g. index 15 will be read as (15/255), // This is because indexes are stored as normalized values of an RGBA texture (e.g. index 15 will be read as (15/255),
// and therefore will read texel 15/255 * texture size). // and therefore will read texel 15/255 * texture size).
m_tex_palette = m_renderer->m_dev->CreateTexture(256, 1); m_tex_palette = m_renderer->m_dev->CreateTexture(256, 1, GSTexture::Format::Color);
m_tex_palette->Update(GSVector4i(0, 0, m_pal, 1), m_clut, m_pal * sizeof(m_clut[0])); m_tex_palette->Update(GSVector4i(0, 0, m_pal, 1), m_clut, m_pal * sizeof(m_clut[0]));
} }
} }

View File

@ -31,7 +31,7 @@ bool GSDeviceNull::Reset(int w, int h)
return GSDevice::Reset(w, h); return GSDevice::Reset(w, h);
} }
GSTexture* GSDeviceNull::CreateSurface(GSTexture::Type type, int w, int h, int format) GSTexture* GSDeviceNull::CreateSurface(GSTexture::Type type, int w, int h, GSTexture::Format format)
{ {
return new GSTextureNull(type, w, h, format); return new GSTextureNull(type, w, h, format);
} }

View File

@ -21,7 +21,7 @@
class GSDeviceNull : public GSDevice class GSDeviceNull : public GSDevice
{ {
private: private:
GSTexture* CreateSurface(GSTexture::Type type, int w, int h, int format); GSTexture* CreateSurface(GSTexture::Type type, int w, int h, GSTexture::Format format);
void DoMerge(GSTexture* sTex[3], GSVector4* sRect, GSTexture* dTex, GSVector4* dRect, const GSRegPMODE& PMODE, const GSRegEXTBUF& EXTBUF, const GSVector4& c) {} void DoMerge(GSTexture* sTex[3], GSVector4* sRect, GSTexture* dTex, GSVector4* dRect, const GSRegPMODE& PMODE, const GSRegEXTBUF& EXTBUF, const GSVector4& c) {}
void DoInterlace(GSTexture* sTex, GSTexture* dTex, int shader, bool linear, float yoffset = 0) {} void DoInterlace(GSTexture* sTex, GSTexture* dTex, int shader, bool linear, float yoffset = 0) {}

View File

@ -21,7 +21,7 @@ GSTextureNull::GSTextureNull()
memset(&m_desc, 0, sizeof(m_desc)); memset(&m_desc, 0, sizeof(m_desc));
} }
GSTextureNull::GSTextureNull(Type type, int w, int h, int format) GSTextureNull::GSTextureNull(Type type, int w, int h, GSTexture::Format format)
{ {
m_desc.type = type; m_desc.type = type;
m_desc.w = w; m_desc.w = w;

View File

@ -22,15 +22,16 @@ class GSTextureNull : public GSTexture
struct struct
{ {
Type type; Type type;
int w, h, format; Format format;
int w, h;
} m_desc; } m_desc;
public: public:
GSTextureNull(); GSTextureNull();
GSTextureNull(Type type, int w, int h, int format); GSTextureNull(Type type, int w, int h, Format format);
Type GetType() const { return m_desc.type; } Type GetType() const { return m_desc.type; }
int GetFormat() const { return m_desc.format; } Format GetFormat() const { return m_desc.format; }
bool Update(const GSVector4i& r, const void* data, int pitch, int layer = 0) { return true; } bool Update(const GSVector4i& r, const void* data, int pitch, int layer = 0) { return true; }
bool Map(GSMap& m, const GSVector4i* r = NULL, int layer = 0) { return false; } bool Map(GSMap& m, const GSVector4i* r = NULL, int layer = 0) { return false; }

View File

@ -239,7 +239,7 @@ void GSDeviceOGL::GenerateProfilerData()
} }
} }
GSTexture* GSDeviceOGL::CreateSurface(GSTexture::Type type, int w, int h, int fmt) GSTexture* GSDeviceOGL::CreateSurface(GSTexture::Type type, int w, int h, GSTexture::Format fmt)
{ {
GL_PUSH("Create surface"); GL_PUSH("Create surface");
@ -272,11 +272,8 @@ GSTexture* GSDeviceOGL::CreateSurface(GSTexture::Type type, int w, int h, int fm
return t; return t;
} }
GSTexture* GSDeviceOGL::FetchSurface(GSTexture::Type type, int w, int h, int format) GSTexture* GSDeviceOGL::FetchSurface(GSTexture::Type type, int w, int h, GSTexture::Format format)
{ {
if (format == 0)
format = (type == GSTexture::Type::DepthStencil || type == GSTexture::Type::SparseDepthStencil) ? GL_DEPTH32F_STENCIL8 : GL_RGBA8;
GSTexture* t = GSDevice::FetchSurface(type, w, h, format); GSTexture* t = GSDevice::FetchSurface(type, w, h, format);
@ -621,7 +618,7 @@ bool GSDeviceOGL::Create(const WindowInfo& wi)
const GSVector2i tex_font = m_osd.get_texture_font_size(); const GSVector2i tex_font = m_osd.get_texture_font_size();
m_font = std::unique_ptr<GSTexture>( m_font = std::unique_ptr<GSTexture>(
new GSTextureOGL(GSTexture::Type::Texture, tex_font.x, tex_font.y, GL_R8, m_fbo_read, false) new GSTextureOGL(GSTexture::Type::Texture, tex_font.x, tex_font.y, GSTexture::Format::UNorm8, m_fbo_read, false)
); );
// **************************************************************** // ****************************************************************
@ -686,7 +683,7 @@ bool GSDeviceOGL::Reset(int w, int h)
// in the backbuffer // in the backbuffer
m_gl_context->ResizeSurface(w, h); m_gl_context->ResizeSurface(w, h);
m_backbuffer = new GSTextureOGL(GSTexture::Type::Backbuffer, m_gl_context->GetSurfaceWidth(), m_backbuffer = new GSTextureOGL(GSTexture::Type::Backbuffer, m_gl_context->GetSurfaceWidth(),
m_gl_context->GetSurfaceHeight(), 0, m_fbo_read, false); m_gl_context->GetSurfaceHeight(), GSTexture::Format::Backbuffer, m_fbo_read, false);
return true; return true;
} }
@ -961,7 +958,7 @@ void GSDeviceOGL::InitPrimDateTexture(GSTexture* rt, const GSVector4i& area)
// Create a texture to avoid the useless clean@0 // Create a texture to avoid the useless clean@0
if (m_date.t == NULL) if (m_date.t == NULL)
m_date.t = CreateTexture(rtsize.x, rtsize.y, GL_R32I); m_date.t = CreateTexture(rtsize.x, rtsize.y, GSTexture::Format::Int32);
// Clean with the max signed value // Clean with the max signed value
const int max_int = 0x7FFFFFFF; const int max_int = 0x7FFFFFFF;
@ -1275,13 +1272,10 @@ void GSDeviceOGL::SelfShaderTest()
} }
// blit a texture into an offscreen buffer // blit a texture into an offscreen buffer
GSTexture* GSDeviceOGL::CopyOffscreen(GSTexture* src, const GSVector4& sRect, int w, int h, int format, ShaderConvert ps_shader) GSTexture* GSDeviceOGL::CopyOffscreen(GSTexture* src, const GSVector4& sRect, int w, int h, GSTexture::Format format, ShaderConvert ps_shader)
{ {
if (format == 0)
format = GL_RGBA8;
ASSERT(src); ASSERT(src);
ASSERT(format == GL_RGBA8 || format == GL_R16UI || format == GL_R32UI); ASSERT(format == GSTexture::Format::Color || format == GSTexture::Format::UInt16 || format == GSTexture::Format::UInt32);
GSTexture* dst = CreateOffscreen(w, h, format); GSTexture* dst = CreateOffscreen(w, h, format);

View File

@ -559,8 +559,8 @@ private:
std::unique_ptr<GSTexture> m_font; std::unique_ptr<GSTexture> m_font;
GSTexture* CreateSurface(GSTexture::Type type, int w, int h, int format) final; GSTexture* CreateSurface(GSTexture::Type type, int w, int h, GSTexture::Format format) final;
GSTexture* FetchSurface(GSTexture::Type type, int w, int h, int format) final; GSTexture* FetchSurface(GSTexture::Type type, int w, int h, GSTexture::Format format) final;
void DoMerge(GSTexture* sTex[3], GSVector4* sRect, GSTexture* dTex, GSVector4* dRect, const GSRegPMODE& PMODE, const GSRegEXTBUF& EXTBUF, const GSVector4& c) final; void DoMerge(GSTexture* sTex[3], GSVector4* sRect, GSTexture* dTex, GSVector4* dRect, const GSRegPMODE& PMODE, const GSRegEXTBUF& EXTBUF, const GSVector4& c) final;
void DoInterlace(GSTexture* sTex, GSTexture* dTex, int shader, bool linear, float yoffset = 0) final; void DoInterlace(GSTexture* sTex, GSTexture* dTex, int shader, bool linear, float yoffset = 0) final;
@ -605,7 +605,7 @@ public:
void InitPrimDateTexture(GSTexture* rt, const GSVector4i& area); void InitPrimDateTexture(GSTexture* rt, const GSVector4i& area);
void RecycleDateTexture(); void RecycleDateTexture();
GSTexture* CopyOffscreen(GSTexture* src, const GSVector4& sRect, int w, int h, int format = 0, ShaderConvert ps_shader = ShaderConvert::COPY) final; GSTexture* CopyOffscreen(GSTexture* src, const GSVector4& sRect, int w, int h, GSTexture::Format format, ShaderConvert ps_shader = ShaderConvert::COPY) final;
void CopyRect(GSTexture* sTex, GSTexture* dTex, const GSVector4i& r) final; void CopyRect(GSTexture* sTex, GSTexture* dTex, const GSVector4i& r) final;

View File

@ -1424,7 +1424,7 @@ void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sour
if (m_ps_sel.hdr) if (m_ps_sel.hdr)
{ {
hdr_rt = dev->CreateRenderTarget(rtsize.x, rtsize.y, GL_RGBA32F); hdr_rt = dev->CreateRenderTarget(rtsize.x, rtsize.y, GSTexture::Format::FloatColor);
dev->OMSetRenderTargets(hdr_rt, ds, &scissor); dev->OMSetRenderTargets(hdr_rt, ds, &scissor);
// save blend state, since BlitRect destroys it // save blend state, since BlitRect destroys it

View File

@ -28,31 +28,31 @@ void GSTextureCacheOGL::Read(Target* t, const GSVector4i& r)
const GIFRegTEX0& TEX0 = t->m_TEX0; const GIFRegTEX0& TEX0 = t->m_TEX0;
GLuint fmt; GSTexture::Format fmt;
ShaderConvert ps_shader; ShaderConvert ps_shader;
switch (TEX0.PSM) switch (TEX0.PSM)
{ {
case PSM_PSMCT32: case PSM_PSMCT32:
case PSM_PSMCT24: case PSM_PSMCT24:
fmt = GL_RGBA8; fmt = GSTexture::Format::Color;
ps_shader = ShaderConvert::COPY; ps_shader = ShaderConvert::COPY;
break; break;
case PSM_PSMCT16: case PSM_PSMCT16:
case PSM_PSMCT16S: case PSM_PSMCT16S:
fmt = GL_R16UI; fmt = GSTexture::Format::UInt16;
ps_shader = ShaderConvert::RGBA8_TO_16_BITS; ps_shader = ShaderConvert::RGBA8_TO_16_BITS;
break; break;
case PSM_PSMZ32: case PSM_PSMZ32:
case PSM_PSMZ24: case PSM_PSMZ24:
fmt = GL_R32UI; fmt = GSTexture::Format::UInt32;
ps_shader = ShaderConvert::FLOAT32_TO_32_BITS; ps_shader = ShaderConvert::FLOAT32_TO_32_BITS;
break; break;
case PSM_PSMZ16: case PSM_PSMZ16:
case PSM_PSMZ16S: case PSM_PSMZ16S:
fmt = GL_R16UI; fmt = GSTexture::Format::UInt16;
ps_shader = ShaderConvert::FLOAT32_TO_32_BITS; ps_shader = ShaderConvert::FLOAT32_TO_32_BITS;
break; break;
@ -116,7 +116,7 @@ void GSTextureCacheOGL::Read(Source* t, const GSVector4i& r)
// FIXME Create a get function to avoid the useless copy // FIXME Create a get function to avoid the useless copy
// Note: With openGL 4.5 you can use glGetTextureSubImage // Note: With openGL 4.5 you can use glGetTextureSubImage
if (GSTexture* offscreen = m_renderer->m_dev->CreateOffscreen(r.width(), r.height())) if (GSTexture* offscreen = m_renderer->m_dev->CreateOffscreen(r.width(), r.height(), GSTexture::Format::Color))
{ {
m_renderer->m_dev->CopyRect(t->m_texture, offscreen, r); m_renderer->m_dev->CopyRect(t->m_texture, offscreen, r);

View File

@ -161,7 +161,7 @@ namespace PboPool
} }
} // namespace PboPool } // namespace PboPool
GSTextureOGL::GSTextureOGL(Type type, int w, int h, int format, GLuint fbo_read, bool mipmap) GSTextureOGL::GSTextureOGL(Type type, int w, int h, Format format, GLuint fbo_read, bool mipmap)
: m_clean(false), m_generate_mipmap(true), m_local_buffer(nullptr), m_r_x(0), m_r_y(0), m_r_w(0), m_r_h(0), m_layer(0) : m_clean(false), m_generate_mipmap(true), m_local_buffer(nullptr), m_r_x(0), m_r_y(0), m_r_w(0), m_r_h(0), m_layer(0)
{ {
// OpenGL didn't like dimensions of size 0 // OpenGL didn't like dimensions of size 0
@ -173,77 +173,71 @@ GSTextureOGL::GSTextureOGL(Type type, int w, int h, int format, GLuint fbo_read,
m_texture_id = 0; m_texture_id = 0;
m_sparse = false; m_sparse = false;
m_max_layer = 1; m_max_layer = 1;
int gl_fmt = 0;
// Bunch of constant parameter // Bunch of constant parameter
switch (m_format) switch (m_format)
{ {
// 1 Channel integer // 1 Channel integer
case GL_R32UI: case Format::Int32:
case GL_R32I: gl_fmt = GL_R32I;
m_int_format = GL_RED_INTEGER; m_int_format = GL_RED_INTEGER;
m_int_type = (m_format == GL_R32UI) ? GL_UNSIGNED_INT : GL_INT; m_int_type = GL_INT;
m_int_shift = 2; m_int_shift = 2;
break; break;
case GL_R16UI: case Format::UInt32:
gl_fmt = GL_R32UI;
m_int_format = GL_RED_INTEGER;
m_int_type = GL_UNSIGNED_INT;
m_int_shift = 2;
break;
case Format::UInt16:
gl_fmt = GL_R16UI;
m_int_format = GL_RED_INTEGER; m_int_format = GL_RED_INTEGER;
m_int_type = GL_UNSIGNED_SHORT; m_int_type = GL_UNSIGNED_SHORT;
m_int_shift = 1; m_int_shift = 1;
break; break;
// 1 Channel normalized // 1 Channel normalized
case GL_R8: case Format::UNorm8:
gl_fmt = GL_R8;
m_int_format = GL_RED; m_int_format = GL_RED;
m_int_type = GL_UNSIGNED_BYTE; m_int_type = GL_UNSIGNED_BYTE;
m_int_shift = 0; m_int_shift = 0;
break; break;
// 4 channel normalized // 4 channel normalized
case GL_RGBA16: case Format::Color:
m_int_format = GL_RGBA; gl_fmt = GL_RGBA8;
m_int_type = GL_UNSIGNED_SHORT;
m_int_shift = 3;
break;
case GL_RGBA8:
m_int_format = GL_RGBA; m_int_format = GL_RGBA;
m_int_type = GL_UNSIGNED_BYTE; m_int_type = GL_UNSIGNED_BYTE;
m_int_shift = 2; m_int_shift = 2;
break; break;
// 4 channel integer // 4 channel float
case GL_RGBA16I: case Format::FloatColor:
case GL_RGBA16UI: gl_fmt = GL_RGBA32F;
m_int_format = GL_RGBA_INTEGER;
m_int_type = (m_format == GL_R16UI) ? GL_UNSIGNED_SHORT : GL_SHORT;
m_int_shift = 3;
break;
// 4 channel float
case GL_RGBA32F:
m_int_format = GL_RGBA; m_int_format = GL_RGBA;
m_int_type = GL_FLOAT; m_int_type = GL_FLOAT;
m_int_shift = 4; m_int_shift = 4;
break; break;
case GL_RGBA16F:
m_int_format = GL_RGBA;
m_int_type = GL_HALF_FLOAT;
m_int_shift = 3;
break;
// Depth buffer // Depth buffer
case GL_DEPTH32F_STENCIL8: case Format::DepthStencil:
gl_fmt = GL_DEPTH32F_STENCIL8;
m_int_format = GL_DEPTH_STENCIL; m_int_format = GL_DEPTH_STENCIL;
m_int_type = GL_FLOAT_32_UNSIGNED_INT_24_8_REV; m_int_type = GL_FLOAT_32_UNSIGNED_INT_24_8_REV;
m_int_shift = 3; // 4 bytes for depth + 4 bytes for stencil by texels m_int_shift = 3; // 4 bytes for depth + 4 bytes for stencil by texels
break; break;
// Backbuffer // Backbuffer
case 0: case Format::Backbuffer:
m_int_format = 0; m_int_format = 0;
m_int_type = 0; m_int_type = 0;
m_int_shift = 2; // 4 bytes by texels m_int_shift = 2; // 4 bytes by texels
break; break;
default: case Format::Invalid:
m_int_format = 0; m_int_format = 0;
m_int_type = 0; m_int_type = 0;
m_int_shift = 0; m_int_shift = 0;
@ -260,7 +254,7 @@ GSTextureOGL::GSTextureOGL(Type type, int w, int h, int format, GLuint fbo_read,
break; break;
case Type::Texture: case Type::Texture:
// Only 32 bits input texture will be supported for mipmap // Only 32 bits input texture will be supported for mipmap
m_max_layer = mipmap && m_format == GL_RGBA8 ? (int)log2(std::max(w, h)) : 1; m_max_layer = mipmap && m_format == Format::Color ? (int)log2(std::max(w, h)) : 1;
break; break;
case Type::SparseRenderTarget: case Type::SparseRenderTarget:
case Type::SparseDepthStencil: case Type::SparseDepthStencil:
@ -272,41 +266,37 @@ GSTextureOGL::GSTextureOGL(Type type, int w, int h, int format, GLuint fbo_read,
switch (m_format) switch (m_format)
{ {
case GL_R16UI: case Format::UInt16:
case GL_R8: case Format::UNorm8:
m_sparse &= GLLoader::found_compatible_GL_ARB_sparse_texture2; m_sparse &= GLLoader::found_compatible_GL_ARB_sparse_texture2;
SetGpuPageSize(GSVector2i(255, 255)); SetGpuPageSize(GSVector2i(255, 255));
break; break;
case GL_R32UI: case Format::Color:
case GL_R32I: case Format::UInt32:
case GL_RGBA16: case Format::Int32:
case GL_RGBA8: case Format::Backbuffer:
case GL_RGBA16I:
case GL_RGBA16UI:
case GL_RGBA16F:
case 0:
m_sparse &= GLLoader::found_compatible_GL_ARB_sparse_texture2; m_sparse &= GLLoader::found_compatible_GL_ARB_sparse_texture2;
SetGpuPageSize(GSVector2i(127, 127)); SetGpuPageSize(GSVector2i(127, 127));
break; break;
case GL_RGBA32F: case Format::FloatColor:
m_sparse &= GLLoader::found_compatible_GL_ARB_sparse_texture2; m_sparse &= GLLoader::found_compatible_GL_ARB_sparse_texture2;
SetGpuPageSize(GSVector2i(63, 63)); SetGpuPageSize(GSVector2i(63, 63));
break; break;
case GL_DEPTH32F_STENCIL8: case Format::DepthStencil:
m_sparse &= GLLoader::found_compatible_sparse_depth; m_sparse &= GLLoader::found_compatible_sparse_depth;
SetGpuPageSize(GSVector2i(127, 127)); SetGpuPageSize(GSVector2i(127, 127));
break; break;
default: case Format::Invalid:
ASSERT(0); ASSERT(0);
} }
// Create a gl object (texture isn't allocated here) // Create a gl object (texture isn't allocated here)
glCreateTextures(GL_TEXTURE_2D, 1, &m_texture_id); glCreateTextures(GL_TEXTURE_2D, 1, &m_texture_id);
if (m_format == GL_R8) if (m_format == Format::UNorm8)
{ {
// Emulate DX behavior, beside it avoid special code in shader to differentiate // Emulate DX behavior, beside it avoid special code in shader to differentiate
// palette texture from a GL_RGBA target or a GL_R texture. // palette texture from a GL_RGBA target or a GL_R texture.
@ -341,7 +331,7 @@ GSTextureOGL::GSTextureOGL(Type type, int w, int h, int format, GLuint fbo_read,
throw std::bad_alloc(); throw std::bad_alloc();
} }
glTextureStorage2D(m_texture_id, m_max_layer + GL_TEX_LEVEL_0, m_format, m_size.x, m_size.y); glTextureStorage2D(m_texture_id, m_max_layer + GL_TEX_LEVEL_0, gl_fmt, m_size.x, m_size.y);
} }
GSTextureOGL::~GSTextureOGL() GSTextureOGL::~GSTextureOGL()
@ -610,7 +600,7 @@ bool GSTextureOGL::Save(const std::string& fn)
fmt = GSPng::RGB_A_PNG; fmt = GSPng::RGB_A_PNG;
} }
else if (m_format == GL_R32I) else if (m_format == Format::Int32)
{ {
// Note: 4.5 function used for accurate DATE // Note: 4.5 function used for accurate DATE
// barely used outside of dev and not sparse anyway // barely used outside of dev and not sparse anyway
@ -624,16 +614,16 @@ bool GSTextureOGL::Save(const std::string& fn)
glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texture_id, 0); glFramebufferTexture2D(GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_texture_id, 0);
if (m_format == GL_RGBA8) if (m_format == Format::Color)
{ {
glReadPixels(0, 0, m_committed_size.x, m_committed_size.y, GL_RGBA, GL_UNSIGNED_BYTE, image.get()); glReadPixels(0, 0, m_committed_size.x, m_committed_size.y, GL_RGBA, GL_UNSIGNED_BYTE, image.get());
} }
else if (m_format == GL_R16UI) else if (m_format == Format::UInt16)
{ {
glReadPixels(0, 0, m_committed_size.x, m_committed_size.y, GL_RED_INTEGER, GL_UNSIGNED_SHORT, image.get()); glReadPixels(0, 0, m_committed_size.x, m_committed_size.y, GL_RED_INTEGER, GL_UNSIGNED_SHORT, image.get());
fmt = GSPng::R16I_PNG; fmt = GSPng::R16I_PNG;
} }
else if (m_format == GL_R8) else if (m_format == Format::UNorm8)
{ {
fmt = GSPng::R8I_PNG; fmt = GSPng::R8I_PNG;
glReadPixels(0, 0, m_committed_size.x, m_committed_size.y, GL_RED, GL_UNSIGNED_BYTE, image.get()); glReadPixels(0, 0, m_committed_size.x, m_committed_size.y, GL_RED, GL_UNSIGNED_BYTE, image.get());

View File

@ -60,7 +60,7 @@ private:
u32 m_mem_usage; u32 m_mem_usage;
public: public:
explicit GSTextureOGL(Type type, int w, int h, int format, GLuint fbo_read, bool mipmap); explicit GSTextureOGL(Type type, int w, int h, Format format, GLuint fbo_read, bool mipmap);
virtual ~GSTextureOGL(); virtual ~GSTextureOGL();
bool Update(const GSVector4i& r, const void* data, int pitch, int layer = 0) final; bool Update(const GSVector4i& r, const void* data, int pitch, int layer = 0) final;

View File

@ -22,7 +22,7 @@ GSTextureSW::GSTextureSW(Type type, int width, int height)
m_mapped.clear(std::memory_order_release); m_mapped.clear(std::memory_order_release);
m_size = GSVector2i(width, height); m_size = GSVector2i(width, height);
m_type = type; m_type = type;
m_format = 0; m_format = Format::Invalid;
m_pitch = ((width << 2) + 31) & ~31; m_pitch = ((width << 2) + 31) & ~31;
m_data = _aligned_malloc(m_pitch * height, 32); m_data = _aligned_malloc(m_pitch * height, 32);
} }

View File

@ -371,7 +371,7 @@ PS_OUTPUT ps_main19(PS_INPUT input)
{ {
PS_OUTPUT output; PS_OUTPUT output;
output.c = input.c * float4(1.0, 1.0, 1.0, sample_c(input.t).r); output.c = input.c * float4(1.0, 1.0, 1.0, sample_c(input.t).a);
return output; return output;
} }