From ddc03cbccfb54fe607374712ff940575c378b338 Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Tue, 8 Sep 2015 16:36:23 +0200 Subject: [PATCH] gsdx: add a nice enum to replace the hardcoded convert shader --- plugins/GSdx/GSDevice.cpp | 4 +++- plugins/GSdx/GSDevice.h | 21 +++++++++++++++++++++ plugins/GSdx/GSDeviceOGL.cpp | 6 +++--- plugins/GSdx/GSRendererOGL.cpp | 2 +- plugins/GSdx/GSTextureCache.cpp | 12 +++++------- 5 files changed, 33 insertions(+), 12 deletions(-) diff --git a/plugins/GSdx/GSDevice.cpp b/plugins/GSdx/GSDevice.cpp index c0a799e277..893c35feb7 100644 --- a/plugins/GSdx/GSDevice.cpp +++ b/plugins/GSdx/GSDevice.cpp @@ -112,7 +112,9 @@ void GSDevice::Present(const GSVector4i& r, int shader) if(m_current) { - static int s_shader[5] = {0, 5, 6, 8, 9}; // FIXME + static int s_shader[5] = {ShaderConvert_COPY, ShaderConvert_SCANLINE, + ShaderConvert_DIAGONAL_FILTER, ShaderConvert_TRIANGULAR_FILTER, + ShaderConvert_COMPLEX_FILTER}; // FIXME Present(m_current, m_backbuffer, GSVector4(r), s_shader[shader]); } diff --git a/plugins/GSdx/GSDevice.h b/plugins/GSdx/GSDevice.h index 820e911a73..a9f2bd3e71 100644 --- a/plugins/GSdx/GSDevice.h +++ b/plugins/GSdx/GSDevice.h @@ -26,6 +26,27 @@ #include "GSVertex.h" #include "GSAlignedClass.h" +enum ShaderConvert { + ShaderConvert_COPY = 0, + ShaderConvert_RGBA8_TO_16_BITS, + ShaderConvert_DATM_1, + ShaderConvert_DATM_0, + ShaderConvert_MOD_256, + ShaderConvert_SCANLINE = 5, + ShaderConvert_DIAGONAL_FILTER, + ShaderConvert_TRANSPARENCY_FILTER, + ShaderConvert_TRIANGULAR_FILTER, + ShaderConvert_COMPLEX_FILTER, + ShaderConvert_FLOAT32_TO_32_BITS = 10, + ShaderConvert_FLOAT32_TO_RGBA8, + ShaderConvert_FLOAT16_TO_RGB5A1, + ShaderConvert_RGBA8_TO_FLOAT32 = 13, + ShaderConvert_RGBA8_TO_FLOAT24, + ShaderConvert_RGBA8_TO_FLOAT16, + ShaderConvert_RGB5A1_TO_FLOAT16, + ShaderConvert_RGBA_TO_8I = 17 +}; + #pragma pack(push, 1) class ConvertConstantBuffer diff --git a/plugins/GSdx/GSDeviceOGL.cpp b/plugins/GSdx/GSDeviceOGL.cpp index 2690785c08..0fef4ec759 100644 --- a/plugins/GSdx/GSDeviceOGL.cpp +++ b/plugins/GSdx/GSDeviceOGL.cpp @@ -950,8 +950,8 @@ void GSDeviceOGL::StretchRect(GSTexture* sTex, const GSVector4& sRect, GSTexture return; } - bool draw_in_depth = (ps == m_convert.ps[13] || ps == m_convert.ps[14] || - ps == m_convert.ps[15] || ps == m_convert.ps[16]); + bool draw_in_depth = (ps == m_convert.ps[ShaderConvert_RGBA8_TO_FLOAT32] || ps == m_convert.ps[ShaderConvert_RGBA8_TO_FLOAT24] || + ps == m_convert.ps[ShaderConvert_RGBA8_TO_FLOAT16] || ps == m_convert.ps[ShaderConvert_RGB5A1_TO_FLOAT16]); // Performance optimization. It might be faster to use a framebuffer blit for standard case // instead to emulate it with shader @@ -1209,7 +1209,7 @@ void GSDeviceOGL::SetupDATE(GSTexture* rt, GSTexture* ds, const GSVertexPT1* ver m_shader->VS(m_convert.vs); m_shader->GS(0); - m_shader->PS(m_convert.ps[datm ? 2 : 3]); + m_shader->PS(m_convert.ps[datm ? ShaderConvert_DATM_1 : ShaderConvert_DATM_0]); // om diff --git a/plugins/GSdx/GSRendererOGL.cpp b/plugins/GSdx/GSRendererOGL.cpp index 168051fcee..506498075f 100644 --- a/plugins/GSdx/GSRendererOGL.cpp +++ b/plugins/GSdx/GSRendererOGL.cpp @@ -1013,7 +1013,7 @@ void GSRendererOGL::DrawPrims(GSTexture* rt, GSTexture* ds, GSTextureCache::Sour if (hdr_rt) { GSVector4 dRect(ComputeBoundingBox(rtscale, rtsize)); GSVector4 sRect = dRect / GSVector4(rtsize.x, rtsize.y).xyxy(); - dev->StretchRect(hdr_rt, sRect, rt, dRect, 4, false); + dev->StretchRect(hdr_rt, sRect, rt, dRect, ShaderConvert_MOD_256, false); dev->Recycle(hdr_rt); } diff --git a/plugins/GSdx/GSTextureCache.cpp b/plugins/GSdx/GSTextureCache.cpp index 753090838f..e8144130d2 100644 --- a/plugins/GSdx/GSTextureCache.cpp +++ b/plugins/GSdx/GSTextureCache.cpp @@ -291,11 +291,11 @@ GSTextureCache::Target* GSTextureCache::LookupTarget(const GIFRegTEX0& TEX0, int if (type == DepthStencil) { GL_CACHE("TC: Lookup Target(Depth) %dx%d, hit Color (0x%x, F:0x%x)", w, h, bp, TEX0.PSM); - int shader = 13 + GSLocalMemory::m_psm[TEX0.PSM].fmt; + int shader = ShaderConvert_RGBA8_TO_FLOAT32 + GSLocalMemory::m_psm[TEX0.PSM].fmt; m_renderer->m_dev->StretchRect(t->m_texture, sRect, dst->m_texture, dRect, shader, false); } else { GL_CACHE("TC: Lookup Target(Color) %dx%d, hit Depth (0x%x, F:0x%x)", w, h, bp, TEX0.PSM); - m_renderer->m_dev->StretchRect(t->m_texture, sRect, dst->m_texture, dRect, 11, false); + m_renderer->m_dev->StretchRect(t->m_texture, sRect, dst->m_texture, dRect, ShaderConvert_FLOAT32_TO_RGBA8, false); } break; @@ -862,14 +862,12 @@ GSTextureCache::Source* GSTextureCache::CreateSource(const GIFRegTEX0& TEX0, con { // TODO: clean up this mess - // Shader 11 convert depth to color - // Shader 14 convert 32 bits color to 8 bits color - int shader = dst->m_type != RenderTarget ? 11 : 0; + int shader = dst->m_type != RenderTarget ? ShaderConvert_FLOAT32_TO_RGBA8 : ShaderConvert_COPY; bool is_8bits = TEX0.PSM == PSM_PSMT8 && IsOpenGL(); if (is_8bits) { GL_INS("Reading RT as a packed-indexed 8 bits format"); - shader = 17; // ask a conversion to 8 bits format + shader = ShaderConvert_RGBA_TO_8I; } #ifdef ENABLE_OGL_DEBUG @@ -1555,7 +1553,7 @@ void GSTextureCache::Target::Update() GL_INS("ERROR: Update DepthStencil"); // FIXME linear or not? - m_renderer->m_dev->StretchRect(t, m_texture, GSVector4(r) * GSVector4(m_texture->GetScale()).xyxy(), 13); + m_renderer->m_dev->StretchRect(t, m_texture, GSVector4(r) * GSVector4(m_texture->GetScale()).xyxy(), ShaderConvert_RGBA8_TO_FLOAT32); } m_renderer->m_dev->Recycle(t);