From de4dec2a803df7d6f271811f52a34973b0ab12ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 18 Dec 2018 10:32:17 +0100 Subject: [PATCH] Use raw strings for more shaders --- GPU/D3D11/DepalettizeShaderD3D11.cpp | 31 ++++++------ GPU/Directx9/DepalettizeShaderDX9.cpp | 31 ++++++------ GPU/Directx9/StencilBufferDX9.cpp | 58 ++++++++++----------- GPU/GLES/DepalettizeShaderGLES.cpp | 46 +++++++++-------- GPU/GLES/StencilBufferGLES.cpp | 72 ++++++++++++++------------- 5 files changed, 123 insertions(+), 115 deletions(-) diff --git a/GPU/D3D11/DepalettizeShaderD3D11.cpp b/GPU/D3D11/DepalettizeShaderD3D11.cpp index 88520f404b..ddd17dc3a8 100644 --- a/GPU/D3D11/DepalettizeShaderD3D11.cpp +++ b/GPU/D3D11/DepalettizeShaderD3D11.cpp @@ -33,21 +33,22 @@ #define SHADERLOG #endif -static const char *depalVShaderHLSL = -"struct VS_IN {\n" -" float3 a_position : POSITION;\n" -" float2 a_texcoord0 : TEXCOORD0;\n" -"};\n" -"struct VS_OUT {\n" -" float2 Texcoord : TEXCOORD0;\n" -" float4 Position : SV_Position;\n" -"};\n" -"VS_OUT main(VS_IN input) {\n" -" VS_OUT output;\n" -" output.Texcoord = input.a_texcoord0;\n" -" output.Position = float4(input.a_position, 1.0);\n" -" return output;\n" -"}\n"; +static const char *depalVShaderHLSL = R"( +struct VS_IN { + float3 a_position : POSITION; + float2 a_texcoord0 : TEXCOORD0; +}; +struct VS_OUT { + float2 Texcoord : TEXCOORD0; + float4 Position : SV_Position; +}; +VS_OUT main(VS_IN input) { + VS_OUT output; + output.Texcoord = input.a_texcoord0; + output.Position = float4(input.a_position, 1.0); + return output; +}; +)"; static const D3D11_INPUT_ELEMENT_DESC g_DepalVertexElements[] = { { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, }, diff --git a/GPU/Directx9/DepalettizeShaderDX9.cpp b/GPU/Directx9/DepalettizeShaderDX9.cpp index 08824b7a98..6c387e1618 100644 --- a/GPU/Directx9/DepalettizeShaderDX9.cpp +++ b/GPU/Directx9/DepalettizeShaderDX9.cpp @@ -36,21 +36,22 @@ static const int DEPAL_TEXTURE_OLD_AGE = 120; #define SHADERLOG #endif -static const char *depalVShaderHLSL = -"struct VS_IN {\n" -" float3 a_position : POSITION;\n" -" float2 a_texcoord0 : TEXCOORD0;\n" -"};\n" -"struct VS_OUT {\n" -" float4 Position : POSITION;\n" -" float2 Texcoord : TEXCOORD0;\n" -"};\n" -"VS_OUT main(VS_IN input) {\n" -" VS_OUT output;\n" -" output.Texcoord = input.a_texcoord0;\n" -" output.Position = float4(input.a_position, 1.0);\n" -" return output;\n" -"}\n"; +static const char *depalVShaderHLSL = R"( +struct VS_IN { + float3 a_position : POSITION; + float2 a_texcoord0 : TEXCOORD0; +}; +struct VS_OUT { + float4 Position : POSITION; + float2 Texcoord : TEXCOORD0; +}; +VS_OUT main(VS_IN input) { + VS_OUT output; + output.Texcoord = input.a_texcoord0; + output.Position = float4(input.a_position, 1.0); + return output; +}; +)"; DepalShaderCacheDX9::DepalShaderCacheDX9(Draw::DrawContext *draw) : vertexShader_(nullptr) { device_ = (LPDIRECT3DDEVICE9)draw->GetNativeObject(Draw::NativeObject::DEVICE); diff --git a/GPU/Directx9/StencilBufferDX9.cpp b/GPU/Directx9/StencilBufferDX9.cpp index c6823cba63..927e052a3e 100644 --- a/GPU/Directx9/StencilBufferDX9.cpp +++ b/GPU/Directx9/StencilBufferDX9.cpp @@ -33,36 +33,38 @@ namespace DX9 { #define STR_HELPER(x) #x #define STR(x) STR_HELPER(x) -static const char *stencil_ps = -"sampler tex: register(s0);\n" +static const char *stencil_ps = R"( +sampler tex: register(s0); // TODO: Don't use fixed registers? Or don't overlap? -"float4 u_stencilValue : register(c" STR(CONST_PS_STENCILVALUE) ");\n" -"struct PS_IN {\n" -" float2 v_texcoord0 : TEXCOORD0;\n" -"};\n" -"float roundAndScaleTo255f(in float x) { return floor(x * 255.99); }\n" -"float4 main(PS_IN In) : COLOR {\n" -" float4 index = tex2D(tex, In.v_texcoord0);\n" -" float shifted = roundAndScaleTo255f(index.a) / roundAndScaleTo255f(u_stencilValue.x);\n" -" clip(fmod(floor(shifted), 2.0) - 0.99);\n" -" return index.aaaa;\n" -"}\n"; +float4 u_stencilValue : register(c" STR(CONST_PS_STENCILVALUE) "); +struct PS_IN { + float2 v_texcoord0 : TEXCOORD0; +}; +float roundAndScaleTo255f(in float x) { return floor(x * 255.99); } +float4 main(PS_IN In) : COLOR { + float4 index = tex2D(tex, In.v_texcoord0); + float shifted = roundAndScaleTo255f(index.a) / roundAndScaleTo255f(u_stencilValue.x); + clip(fmod(floor(shifted), 2.0) - 0.99); + return index.aaaa; +} +)"; -static const char *stencil_vs = -"struct VS_IN {\n" -" float4 a_position : POSITION;\n" -" float2 a_texcoord0 : TEXCOORD0;\n" -"};\n" -"struct VS_OUT {\n" -" float4 position : POSITION;\n" -" float2 v_texcoord0 : TEXCOORD0;\n" -"};\n" -"VS_OUT main(VS_IN In) {\n" -" VS_OUT Out;\n" -" Out.position = In.a_position;\n" -" Out.v_texcoord0 = In.a_texcoord0;\n" -" return Out;\n" -"}\n"; +static const char *stencil_vs = R"( +struct VS_IN { + float4 a_position : POSITION; + float2 a_texcoord0 : TEXCOORD0; +}; +struct VS_OUT { + float4 position : POSITION; + float2 v_texcoord0 : TEXCOORD0; +}; +VS_OUT main(VS_IN In) { + VS_OUT Out; + Out.position = In.a_position; + Out.v_texcoord0 = In.a_texcoord0; + return Out; +} +)"; bool FramebufferManagerDX9::NotifyStencilUpload(u32 addr, int size, bool skipZero) { addr &= 0x3FFFFFFF; diff --git a/GPU/GLES/DepalettizeShaderGLES.cpp b/GPU/GLES/DepalettizeShaderGLES.cpp index 5886df27ee..8d5780ac62 100644 --- a/GPU/GLES/DepalettizeShaderGLES.cpp +++ b/GPU/GLES/DepalettizeShaderGLES.cpp @@ -25,29 +25,31 @@ #include "GPU/GLES/TextureCacheGLES.h" #include "GPU/Common/DepalettizeShaderCommon.h" -static const char *depalVShader100 = -"#ifdef GL_ES\n" -"precision highp float;\n" -"#endif\n" -"attribute vec4 a_position;\n" -"attribute vec2 a_texcoord0;\n" -"varying vec2 v_texcoord0;\n" -"void main() {\n" -" v_texcoord0 = a_texcoord0;\n" -" gl_Position = a_position;\n" -"}\n"; +static const char *depalVShader100 = R"( +#ifdef GL_ES +precision highp float; +#endif +attribute vec4 a_position; +attribute vec2 a_texcoord0; +varying vec2 v_texcoord0; +void main() { + v_texcoord0 = a_texcoord0; + gl_Position = a_position; +}; +)"; -static const char *depalVShader300 = -"#ifdef GL_ES\n" -"precision highp float;\n" -"#endif\n" -"in vec4 a_position;\n" -"in vec2 a_texcoord0;\n" -"out vec2 v_texcoord0;\n" -"void main() {\n" -" v_texcoord0 = a_texcoord0;\n" -" gl_Position = a_position;\n" -"}\n"; +static const char *depalVShader300 = R"( +#ifdef GL_ES +precision highp float; +#endif +in vec4 a_position; +in vec2 a_texcoord0; +out vec2 v_texcoord0; +void main() { + v_texcoord0 = a_texcoord0; + gl_Position = a_position; +}; +)"; DepalShaderCacheGLES::DepalShaderCacheGLES(Draw::DrawContext *draw) { _assert_(draw); diff --git a/GPU/GLES/StencilBufferGLES.cpp b/GPU/GLES/StencilBufferGLES.cpp index 17d7469dfa..31a98bb9e3 100644 --- a/GPU/GLES/StencilBufferGLES.cpp +++ b/GPU/GLES/StencilBufferGLES.cpp @@ -24,42 +24,44 @@ #include "GPU/GLES/ShaderManagerGLES.h" #include "GPU/GLES/TextureCacheGLES.h" -static const char *stencil_fs = -"#ifdef GL_ES\n" -"precision highp float;\n" -"#endif\n" -"#if __VERSION__ >= 130\n" -"#define varying in\n" -"#define texture2D texture\n" -"#define gl_FragColor fragColor0\n" -"out vec4 fragColor0;\n" -"#endif\n" -"varying vec2 v_texcoord0;\n" -"uniform float u_stencilValue;\n" -"uniform sampler2D tex;\n" -"float roundAndScaleTo255f(in float x) { return floor(x * 255.99); }\n" -"void main() {\n" -" vec4 index = texture2D(tex, v_texcoord0);\n" -" gl_FragColor = vec4(index.a);\n" -" float shifted = roundAndScaleTo255f(index.a) / roundAndScaleTo255f(u_stencilValue);\n" -" if (mod(floor(shifted), 2.0) < 0.99) discard;\n" -"}\n"; +static const char *stencil_fs = R"( +#ifdef GL_ES +precision highp float; +#endif +#if __VERSION__ >= 130 +#define varying in +#define texture2D texture +#define gl_FragColor fragColor0 +out vec4 fragColor0; +#endif +varying vec2 v_texcoord0; +uniform float u_stencilValue; +uniform sampler2D tex; +float roundAndScaleTo255f(in float x) { return floor(x * 255.99); } +void main() { + vec4 index = texture2D(tex, v_texcoord0); + gl_FragColor = vec4(index.a); + float shifted = roundAndScaleTo255f(index.a) / roundAndScaleTo255f(u_stencilValue); + if (mod(floor(shifted), 2.0) < 0.99) discard; +} +)"; -static const char *stencil_vs = -"#ifdef GL_ES\n" -"precision highp float;\n" -"#endif\n" -"#if __VERSION__ >= 130\n" -"#define attribute in\n" -"#define varying out\n" -"#endif\n" -"attribute vec4 a_position;\n" -"attribute vec2 a_texcoord0;\n" -"varying vec2 v_texcoord0;\n" -"void main() {\n" -" v_texcoord0 = a_texcoord0;\n" -" gl_Position = a_position;\n" -"}\n"; +static const char *stencil_vs = R"( +#ifdef GL_ES +precision highp float; +#endif +#if __VERSION__ >= 130 +#define attribute in +#define varying out +#endif +attribute vec4 a_position; +attribute vec2 a_texcoord0; +varying vec2 v_texcoord0; +void main() { + v_texcoord0 = a_texcoord0; + gl_Position = a_position; +} +)"; bool FramebufferManagerGLES::NotifyStencilUpload(u32 addr, int size, bool skipZero) { addr &= 0x3FFFFFFF;