Use raw strings for more shaders

This commit is contained in:
Henrik Rydgård 2018-12-18 10:32:17 +01:00
parent 260fd3c9ee
commit de4dec2a80
5 changed files with 123 additions and 115 deletions

View file

@ -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, },

View file

@ -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);

View file

@ -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;

View file

@ -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);

View file

@ -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;