From 643ed528c2f3303413b3cf815aae4f6e6b897682 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Thu, 7 Feb 2019 12:08:44 +0100 Subject: [PATCH] gsdx hw: allow to create sparse texture at device level Obviously texture allocation should be updated too --- plugins/GSdx/Renderers/Common/GSDevice.cpp | 10 ++++++++++ plugins/GSdx/Renderers/Common/GSDevice.h | 5 +++++ plugins/GSdx/Renderers/Common/GSTexture.h | 2 +- plugins/GSdx/Renderers/DX11/GSDevice11.cpp | 2 +- plugins/GSdx/Renderers/OpenGL/GSDeviceOGL.cpp | 2 +- 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/plugins/GSdx/Renderers/Common/GSDevice.cpp b/plugins/GSdx/Renderers/Common/GSDevice.cpp index bcd1ed6b4c..06a7790631 100644 --- a/plugins/GSdx/Renderers/Common/GSDevice.cpp +++ b/plugins/GSdx/Renderers/Common/GSDevice.cpp @@ -201,6 +201,16 @@ void GSDevice::PurgePool() } } +GSTexture* GSDevice::CreateSparseRenderTarget(int w, int h, int format) +{ + return FetchSurface(HasColorSparse() ? GSTexture::SparseRenderTarget : GSTexture::RenderTarget, w, h, format); +} + +GSTexture* GSDevice::CreateSparseDepthStencil(int w, int h, int format) +{ + return FetchSurface(HasDepthSparse() ? GSTexture::SparseDepthStencil : GSTexture::DepthStencil, w, h, format); +} + GSTexture* GSDevice::CreateRenderTarget(int w, int h, int format) { return FetchSurface(GSTexture::RenderTarget, w, h, format); diff --git a/plugins/GSdx/Renderers/Common/GSDevice.h b/plugins/GSdx/Renderers/Common/GSDevice.h index 11c7c443fd..e9b0c89632 100644 --- a/plugins/GSdx/Renderers/Common/GSDevice.h +++ b/plugins/GSdx/Renderers/Common/GSDevice.h @@ -167,11 +167,16 @@ public: virtual void DrawIndexedPrimitive(int offset, int count) {} virtual void EndScene(); + virtual bool HasDepthSparse() { return false; } + virtual bool HasColorSparse() { return false; } + virtual void ClearRenderTarget(GSTexture* t, const GSVector4& c) {} virtual void ClearRenderTarget(GSTexture* t, uint32 c) {} virtual void ClearDepth(GSTexture* t) {} virtual void ClearStencil(GSTexture* t, uint8 c) {} + GSTexture* CreateSparseRenderTarget(int w, int h, int format = 0); + GSTexture* CreateSparseDepthStencil(int w, int h, int format = 0); GSTexture* CreateRenderTarget(int w, int h, int format = 0); GSTexture* CreateDepthStencil(int w, int h, int format = 0); GSTexture* CreateTexture(int w, int h, int format = 0); diff --git a/plugins/GSdx/Renderers/Common/GSTexture.h b/plugins/GSdx/Renderers/Common/GSTexture.h index 534d48b02b..ed4dd87805 100644 --- a/plugins/GSdx/Renderers/Common/GSTexture.h +++ b/plugins/GSdx/Renderers/Common/GSTexture.h @@ -34,7 +34,7 @@ protected: public: struct GSMap {uint8* bits; int pitch;}; - enum {RenderTarget = 1, DepthStencil, Texture, Offscreen, Backbuffer}; + enum {RenderTarget = 1, DepthStencil, Texture, Offscreen, Backbuffer, SparseRenderTarget, SparseDepthStencil}; public: GSTexture(); diff --git a/plugins/GSdx/Renderers/DX11/GSDevice11.cpp b/plugins/GSdx/Renderers/DX11/GSDevice11.cpp index 12c481f417..e727997238 100644 --- a/plugins/GSdx/Renderers/DX11/GSDevice11.cpp +++ b/plugins/GSdx/Renderers/DX11/GSDevice11.cpp @@ -735,7 +735,7 @@ GSTexture* GSDevice11::CreateSurface(int type, int w, int h, int format) GSTexture* GSDevice11::FetchSurface(int type, int w, int h, int format) { if (format == 0) - format = (type == GSTexture::DepthStencil) ? DXGI_FORMAT_R32G8X24_TYPELESS : DXGI_FORMAT_R8G8B8A8_UNORM; + format = (type == GSTexture::DepthStencil || type == GSTexture::SparseDepthStencil) ? DXGI_FORMAT_R32G8X24_TYPELESS : DXGI_FORMAT_R8G8B8A8_UNORM; return __super::FetchSurface(type, w, h, format); } diff --git a/plugins/GSdx/Renderers/OpenGL/GSDeviceOGL.cpp b/plugins/GSdx/Renderers/OpenGL/GSDeviceOGL.cpp index 8cbc563b50..22be9c1758 100644 --- a/plugins/GSdx/Renderers/OpenGL/GSDeviceOGL.cpp +++ b/plugins/GSdx/Renderers/OpenGL/GSDeviceOGL.cpp @@ -258,7 +258,7 @@ GSTexture* GSDeviceOGL::CreateSurface(int type, int w, int h, int fmt) GSTexture* GSDeviceOGL::FetchSurface(int type, int w, int h, int format) { if (format == 0) - format = (type == GSTexture::DepthStencil) ? GL_DEPTH32F_STENCIL8 : GL_RGBA8; + format = (type == GSTexture::DepthStencil || type == GSTexture::SparseDepthStencil) ? GL_DEPTH32F_STENCIL8 : GL_RGBA8; GSTexture* t = GSDevice::FetchSurface(type, w, h, format);