From 5b061e062c90b21d8896ac5599a33992e5d9be63 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Sun, 15 May 2016 15:54:29 +0200 Subject: [PATCH] gsdx ogl: replace ClearRenderTarget_i by glClearTexSubImage Avoid state change, avoid potential texture buffer reallocation Note: require GL_ARB_clear_texture --- plugins/GSdx/GSDeviceOGL.cpp | 12 ++++++++++-- plugins/GSdx/GSDeviceOGL.h | 2 +- plugins/GSdx/GSRendererOGL.cpp | 2 +- plugins/GSdx/GSTextureOGL.cpp | 2 +- 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/plugins/GSdx/GSDeviceOGL.cpp b/plugins/GSdx/GSDeviceOGL.cpp index 0e089d9753..ed13406e89 100644 --- a/plugins/GSdx/GSDeviceOGL.cpp +++ b/plugins/GSdx/GSDeviceOGL.cpp @@ -565,6 +565,9 @@ void GSDeviceOGL::ClearRenderTarget(GSTexture* t, uint32 c) void GSDeviceOGL::ClearRenderTarget_i(GSTexture* t, int32 c) { + // Hopefully AMD mesa will support this extension soon + ASSERT(!GLLoader::found_GL_ARB_clear_texture); + if (!t) return; GSTextureOGL* T = static_cast(t); @@ -715,7 +718,7 @@ GSDepthStencilOGL* GSDeviceOGL::CreateDepthStencil(OMDepthStencilSelector dssel) return dss; } -void GSDeviceOGL::InitPrimDateTexture(GSTexture* rt) +void GSDeviceOGL::InitPrimDateTexture(GSTexture* rt, const GSVector4i& area) { const GSVector2i& rtsize = rt->GetSize(); @@ -724,7 +727,12 @@ void GSDeviceOGL::InitPrimDateTexture(GSTexture* rt) m_date.t = CreateTexture(rtsize.x, rtsize.y, GL_R32I); // Clean with the max signed value - ClearRenderTarget_i(m_date.t, 0x7FFFFFFF); + int max_int = 0x7FFFFFFF; + if (GLLoader::found_GL_ARB_clear_texture) { + static_cast(m_date.t)->Clear(&max_int, area); + } else { + ClearRenderTarget_i(m_date.t, max_int); + } glBindImageTexture(2, static_cast(m_date.t)->GetID(), 0, false, 0, GL_READ_WRITE, GL_R32I); #ifdef ENABLE_OGL_DEBUG diff --git a/plugins/GSdx/GSDeviceOGL.h b/plugins/GSdx/GSDeviceOGL.h index 8b83075f2f..de91021467 100644 --- a/plugins/GSdx/GSDeviceOGL.h +++ b/plugins/GSdx/GSDeviceOGL.h @@ -501,7 +501,7 @@ class GSDeviceOGL final : public GSDevice GSTexture* CreateDepthStencil(int w, int h, bool msaa, int format = 0) final; GSTexture* CreateTexture(int w, int h, int format = 0) final; GSTexture* CreateOffscreen(int w, int h, int format = 0) final; - void InitPrimDateTexture(GSTexture* rt); + void InitPrimDateTexture(GSTexture* rt, const GSVector4i& area); void RecycleDateTexture(); GSTexture* CopyOffscreen(GSTexture* src, const GSVector4& sRect, int w, int h, int format = 0, int ps_shader = 0) final; diff --git a/plugins/GSdx/GSRendererOGL.cpp b/plugins/GSdx/GSRendererOGL.cpp index fa5f0ae643..e705b097ac 100644 --- a/plugins/GSdx/GSRendererOGL.cpp +++ b/plugins/GSdx/GSRendererOGL.cpp @@ -858,7 +858,7 @@ void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sour // Must be done here to avoid any GL state pertubation (clear function...) // Create an r32ui image that will containt primitive ID if (DATE_GL42) { - dev->InitPrimDateTexture(rt); + dev->InitPrimDateTexture(rt, dRect); } else { GSVector4 src = GSVector4(dRect) / GSVector4(rtsize.x, rtsize.y).xyxy(); GSVector4 dst = src * 2.0f - 1.0f; diff --git a/plugins/GSdx/GSTextureOGL.cpp b/plugins/GSdx/GSTextureOGL.cpp index 07dad5e2b1..77844e7e85 100644 --- a/plugins/GSdx/GSTextureOGL.cpp +++ b/plugins/GSdx/GSTextureOGL.cpp @@ -293,7 +293,7 @@ void GSTextureOGL::Clear(const void* data) void GSTextureOGL::Clear(const void* data, const GSVector4i& area) { - glClearTexSubImage(m_texture_id, area.x, area.y, 0, area.width(), area.height(), 1, GL_TEX_LEVEL_0, m_int_format, m_int_type, data); + glClearTexSubImage(m_texture_id, GL_TEX_LEVEL_0, area.x, area.y, 0, area.width(), area.height(), 1, m_int_format, m_int_type, data); } bool GSTextureOGL::Update(const GSVector4i& r, const void* data, int pitch)