From 72664bede49fa22bc99020a904cd6ad5e53785f5 Mon Sep 17 00:00:00 2001 From: John Stiles Date: Wed, 16 Sep 2020 17:43:11 -0400 Subject: [PATCH] Add support for #pragma settings comments in SkSL. This will allow us to write skslc-based golden tests that deviate from the standalone skslc settings. This CL provides six options; more will be added as necessary. - Default (caps) - UsesPrecisionModifiers (caps) - Version110 (caps) - Version450Core (caps) - ForceHighPrecision (settings flag bit) - Sharpen (settings flag bit) Change-Id: I9b779e039b2f0c0ccf43dca226fb4844aff3526b Reviewed-on: https://skia-review.googlesource.com/c/skia/+/317237 Commit-Queue: John Stiles Auto-Submit: John Stiles Reviewed-by: Brian Osman --- gn/sksl_tests.gni | 10 + src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp | 2 +- src/sksl/SkSLMain.cpp | 64 ++++- src/sksl/SkSLString.cpp | 12 + src/sksl/SkSLString.h | 5 +- src/sksl/SkSLUtil.h | 3 +- tests/SkSLGLSLTest.cpp | 243 ------------------ tests/sksl/glsl/ForceHighPrecision.sksl | 6 + tests/sksl/glsl/Texture.sksl | 10 + tests/sksl/glsl/TextureSharpen.sksl | 12 + tests/sksl/glsl/TextureSharpenVersion110.sksl | 12 + tests/sksl/glsl/TextureVersion110.sksl | 12 + tests/sksl/glsl/TypePrecisionDisabled.sksl | 10 + tests/sksl/glsl/TypePrecisionEnabled.sksl | 12 + tests/sksl/glsl/UsesPrecisionModifiers.sksl | 9 + tests/sksl/glsl/Version110.sksl | 5 + tests/sksl/glsl/Version450Core.sksl | 5 + .../sksl/glsl/golden/ForceHighPrecision.glsl | 9 + tests/sksl/glsl/golden/Texture.glsl | 11 + tests/sksl/glsl/golden/TextureSharpen.glsl | 11 + .../glsl/golden/TextureSharpenVersion110.glsl | 10 + tests/sksl/glsl/golden/TextureVersion110.glsl | 10 + .../glsl/golden/TypePrecisionDisabled.glsl | 11 + .../glsl/golden/TypePrecisionEnabled.glsl | 13 + .../glsl/golden/UsesPrecisionModifiers.glsl | 11 + tests/sksl/glsl/golden/Version110.glsl | 5 + tests/sksl/glsl/golden/Version450Core.glsl | 6 + 27 files changed, 276 insertions(+), 253 deletions(-) create mode 100644 tests/sksl/glsl/ForceHighPrecision.sksl create mode 100644 tests/sksl/glsl/Texture.sksl create mode 100644 tests/sksl/glsl/TextureSharpen.sksl create mode 100644 tests/sksl/glsl/TextureSharpenVersion110.sksl create mode 100644 tests/sksl/glsl/TextureVersion110.sksl create mode 100644 tests/sksl/glsl/TypePrecisionDisabled.sksl create mode 100644 tests/sksl/glsl/TypePrecisionEnabled.sksl create mode 100644 tests/sksl/glsl/UsesPrecisionModifiers.sksl create mode 100644 tests/sksl/glsl/Version110.sksl create mode 100644 tests/sksl/glsl/Version450Core.sksl create mode 100644 tests/sksl/glsl/golden/ForceHighPrecision.glsl create mode 100644 tests/sksl/glsl/golden/Texture.glsl create mode 100644 tests/sksl/glsl/golden/TextureSharpen.glsl create mode 100644 tests/sksl/glsl/golden/TextureSharpenVersion110.glsl create mode 100644 tests/sksl/glsl/golden/TextureVersion110.glsl create mode 100644 tests/sksl/glsl/golden/TypePrecisionDisabled.glsl create mode 100644 tests/sksl/glsl/golden/TypePrecisionEnabled.glsl create mode 100644 tests/sksl/glsl/golden/UsesPrecisionModifiers.glsl create mode 100644 tests/sksl/glsl/golden/Version110.glsl create mode 100644 tests/sksl/glsl/golden/Version450Core.glsl diff --git a/gn/sksl_tests.gni b/gn/sksl_tests.gni index d822dc33c7..8712df18f1 100644 --- a/gn/sksl_tests.gni +++ b/gn/sksl_tests.gni @@ -31,6 +31,7 @@ sksl_glsl_tests_sources = [ "$_tests/sksl/glsl/DependentInitializers.sksl", "$_tests/sksl/glsl/Discard.sksl", "$_tests/sksl/glsl/FloatFolding.sksl", + "$_tests/sksl/glsl/ForceHighPrecision.sksl", "$_tests/sksl/glsl/FrExp.sksl", "$_tests/sksl/glsl/Functions.sksl", "$_tests/sksl/glsl/Height.sksl", @@ -72,9 +73,18 @@ sksl_glsl_tests_sources = [ "$_tests/sksl/glsl/TernaryAsLValueEntirelyFoldable.sksl", "$_tests/sksl/glsl/TernaryAsLValueFoldableTest.sksl", "$_tests/sksl/glsl/TernaryAsLValueUnfoldable.sksl", + "$_tests/sksl/glsl/Texture.sksl", + "$_tests/sksl/glsl/TextureSharpen.sksl", + "$_tests/sksl/glsl/TextureSharpenVersion110.sksl", + "$_tests/sksl/glsl/TextureVersion110.sksl", + "$_tests/sksl/glsl/TypePrecisionDisabled.sksl", + "$_tests/sksl/glsl/TypePrecisionEnabled.sksl", "$_tests/sksl/glsl/UnusedVariables.sksl", + "$_tests/sksl/glsl/UsesPrecisionModifiers.sksl", "$_tests/sksl/glsl/VectorConstructors.sksl", "$_tests/sksl/glsl/VectorFolding.sksl", + "$_tests/sksl/glsl/Version110.sksl", + "$_tests/sksl/glsl/Version450Core.sksl", "$_tests/sksl/glsl/VertexID.vert", "$_tests/sksl/glsl/Width.sksl", "$_tests/sksl/inliner/DoWhileBodyMustBeInlinedIntoAScope.sksl", diff --git a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp index 02eb64ecd3..d554f0fa92 100644 --- a/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp +++ b/src/gpu/glsl/GrGLSLFragmentShaderBuilder.cpp @@ -263,7 +263,7 @@ void GrGLSLFragmentShaderBuilder::enableSecondaryOutput() { // If the primary output is declared, we must declare also the secondary output // and vice versa, since it is not allowed to use a built-in gl_FragColor and a custom - // output. The condition also co-incides with the condition in whici GLES SL 2.0 + // output. The condition also co-incides with the condition in which GLES SL 2.0 // requires the built-in gl_SecondaryFragColorEXT, where as 3.0 requires a custom output. if (caps.mustDeclareFragmentShaderOutput()) { fOutputs.emplace_back(DeclaredSecondaryColorOutputName(), kHalf4_GrSLType, diff --git a/src/sksl/SkSLMain.cpp b/src/sksl/SkSLMain.cpp index 20e70dfd59..63ab247262 100644 --- a/src/sksl/SkSLMain.cpp +++ b/src/sksl/SkSLMain.cpp @@ -33,6 +33,62 @@ static SkSL::String base_name(const char* fpPath, const char* prefix, const char return result; } +// Given a string containing an SkSL program, searches for a #pragma settings comment, like so: +// /*#pragma settings Default Sharpen*/ +// The passed-in Settings object will be updated accordingly. Any number of options can be provided. +static void detect_shader_settings(const SkSL::String& text, SkSL::Program::Settings* settings) { + // Find a matching comment and isolate the name portion. + static constexpr char kPragmaSettings[] = "/*#pragma settings "; + const char* settingsPtr = strstr(text.c_str(), kPragmaSettings); + if (settingsPtr != nullptr) { + // Subtract one here in order to preserve the leading space, which is necessary to allow + // consumeSuffix to find the first item. + settingsPtr += strlen(kPragmaSettings) - 1; + + const char* settingsEnd = strstr(settingsPtr, "*/"); + if (settingsEnd != nullptr) { + SkSL::String settingsText{settingsPtr, size_t(settingsEnd - settingsPtr)}; + + // Apply settings as requested. Since they can come in any order, repeat until we've + // consumed them all. + for (;;) { + const size_t startingLength = settingsText.length(); + + if (settingsText.consumeSuffix(" Default")) { + static auto s_defaultCaps = SkSL::ShaderCapsFactory::Default(); + settings->fCaps = s_defaultCaps.get(); + } + if (settingsText.consumeSuffix(" UsesPrecisionModifiers")) { + static auto s_precisionCaps = SkSL::ShaderCapsFactory::UsesPrecisionModifiers(); + settings->fCaps = s_precisionCaps.get(); + } + if (settingsText.consumeSuffix(" Version110")) { + static auto s_version110Caps = SkSL::ShaderCapsFactory::Version110(); + settings->fCaps = s_version110Caps.get(); + } + if (settingsText.consumeSuffix(" Version450Core")) { + static auto s_version450CoreCaps = SkSL::ShaderCapsFactory::Version450Core(); + settings->fCaps = s_version450CoreCaps.get(); + } + if (settingsText.consumeSuffix(" ForceHighPrecision")) { + settings->fForceHighPrecision = true; + } + if (settingsText.consumeSuffix(" Sharpen")) { + settings->fSharpenTextures = true; + } + + if (settingsText.empty()) { + break; + } + if (settingsText.length() == startingLength) { + printf("Unrecognized #pragma settings: %s\n", settingsText.c_str()); + exit(3); + } + } + } + } +} + /** * Very simple standalone executable to facilitate testing. */ @@ -60,17 +116,15 @@ int main(int argc, const char** argv) { } std::ifstream in(argv[1]); - std::string stdText((std::istreambuf_iterator(in)), - std::istreambuf_iterator()); - SkSL::String text(stdText.c_str()); + SkSL::String text((std::istreambuf_iterator(in)), + std::istreambuf_iterator()); if (in.rdstate()) { printf("error reading '%s'\n", argv[1]); exit(2); } - SkSL::ShaderCapsPointer caps = SkSL::ShaderCapsFactory::Standalone(); SkSL::Program::Settings settings; - settings.fCaps = caps.get(); + detect_shader_settings(text, &settings); SkSL::String name(argv[2]); if (name.endsWith(".spirv")) { SkSL::FileOutputStream out(argv[2]); diff --git a/src/sksl/SkSLString.cpp b/src/sksl/SkSLString.cpp index 0528fceda9..409c76210b 100644 --- a/src/sksl/SkSLString.cpp +++ b/src/sksl/SkSLString.cpp @@ -61,6 +61,18 @@ bool String::endsWith(const char suffix[]) const { return !strncmp(this->data() + this->size() - suffixLength, suffix, suffixLength); } +bool String::consumeSuffix(const char suffix[]) { + size_t suffixLength = strlen(suffix); + if (this->length() < suffixLength) { + return false; + } + if (0 != strncmp(this->data() + this->size() - suffixLength, suffix, suffixLength)) { + return false; + } + this->resize(this->length() - suffixLength); + return true; +} + String String::operator+(const char* s) const { String result(*this); result.append(s); diff --git a/src/sksl/SkSLString.h b/src/sksl/SkSLString.h index c97c0fbca7..6510588d82 100644 --- a/src/sksl/SkSLString.h +++ b/src/sksl/SkSLString.h @@ -65,8 +65,9 @@ public: void appendf(const char* fmt, ...); void vappendf(const char* fmt, va_list va); - bool startsWith(const char* prefix) const; - bool endsWith(const char* suffix) const; + bool startsWith(const char prefix[]) const; + bool endsWith(const char suffix[]) const; + bool consumeSuffix(const char suffix[]); String operator+(const char* s) const; String operator+(const String& s) const; diff --git a/src/sksl/SkSLUtil.h b/src/sksl/SkSLUtil.h index d8a9717efb..61423bd330 100644 --- a/src/sksl/SkSLUtil.h +++ b/src/sksl/SkSLUtil.h @@ -85,9 +85,8 @@ public: return fUsesPrecisionModifiers; } - bool fMustDeclareFragmentShaderOutput = true; bool mustDeclareFragmentShaderOutput() const { - return fMustDeclareFragmentShaderOutput; + return fGLSLGeneration > k110_GrGLSLGeneration; } bool fFBFetchSupport = true; diff --git a/tests/SkSLGLSLTest.cpp b/tests/SkSLGLSLTest.cpp index 2a4548d704..b097e2777f 100644 --- a/tests/SkSLGLSLTest.cpp +++ b/tests/SkSLGLSLTest.cpp @@ -49,57 +49,6 @@ static void test(skiatest::Reporter* r, const char* src, const GrShaderCaps& cap test(r, src, settings, expected, &inputs, kind); } -DEF_TEST(SkSLVersion, r) { - test(r, - "in float test; void main() { sk_FragColor.r = half(test); }", - *SkSL::ShaderCapsFactory::Version450Core(), - "#version 450 core\n" - "out vec4 sk_FragColor;\n" - "in float test;\n" - "void main() {\n" - " sk_FragColor.x = test;\n" - "}\n"); - test(r, - "in float test; void main() { sk_FragColor.r = half(test); }", - *SkSL::ShaderCapsFactory::Version110(), - "#version 110\n" - "varying float test;\n" - "void main() {\n" - " gl_FragColor.x = test;\n" - "}\n"); -} - -DEF_TEST(SkSLUsesPrecisionModifiers, r) { - test(r, - "void main() { half x = 0.75; float y = 1; x++; y++;" - "sk_FragColor.rg = half2(x, half(y)); }", - *SkSL::ShaderCapsFactory::Default(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "void main() {\n" - " float x = 0.75;\n" - " float y = 1.0;\n" - " x++;\n" - " y++;\n" - " sk_FragColor.xy = vec2(x, y);\n" - "}\n"); - test(r, - "void main() { half x = 0.75; float y = 1; x++; y++;" - "sk_FragColor.rg = half2(x, half(y)); }", - *SkSL::ShaderCapsFactory::UsesPrecisionModifiers(), - "#version 400\n" - "precision mediump float;\n" - "precision mediump sampler2D;\n" - "out mediump vec4 sk_FragColor;\n" - "void main() {\n" - " mediump float x = 0.75;\n" - " highp float y = 1.0;\n" - " x++;\n" - " y++;\n" - " sk_FragColor.xy = vec2(x, y);\n" - "}\n"); -} - DEF_TEST(SkSLMinAbs, r) { test(r, "void main() {" @@ -230,108 +179,6 @@ DEF_TEST(SkSLDerivatives, r) { &inputs); } -DEF_TEST(SkSLTexture, r) { - test(r, - "uniform sampler1D one;" - "uniform sampler2D two;" - "void main() {" - "float4 a = sample(one, 0);" - "float4 b = sample(two, float2(0));" - "float4 c = sample(one, float2(0));" - "float4 d = sample(two, float3(0));" - "sk_FragColor = half4(half(a.x), half(b.x), half(c.x), half(d.x));" - "}", - *SkSL::ShaderCapsFactory::Default(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "uniform sampler1D one;\n" - "uniform sampler2D two;\n" - "void main() {\n" - " vec4 a = texture(one, 0.0);\n" - " vec4 b = texture(two, vec2(0.0));\n" - " vec4 c = textureProj(one, vec2(0.0));\n" - " vec4 d = textureProj(two, vec3(0.0));\n" - " sk_FragColor = vec4(a.x, b.x, c.x, d.x);\n" - "}\n"); - test(r, - "uniform sampler1D one;" - "uniform sampler2D two;" - "void main() {" - "float4 a = sample(one, 0);" - "float4 b = sample(two, float2(0));" - "float4 c = sample(one, float2(0));" - "float4 d = sample(two, float3(0));" - "sk_FragColor = half4(half(a.x), half(b.x), half(c.x), half(d.x));" - "}", - *SkSL::ShaderCapsFactory::Version110(), - "#version 110\n" - "uniform sampler1D one;\n" - "uniform sampler2D two;\n" - "void main() {\n" - " vec4 a = texture1D(one, 0.0);\n" - " vec4 b = texture2D(two, vec2(0.0));\n" - " vec4 c = texture1DProj(one, vec2(0.0));\n" - " vec4 d = texture2DProj(two, vec3(0.0));\n" - " gl_FragColor = vec4(a.x, b.x, c.x, d.x);\n" - "}\n"); -} - -DEF_TEST(SkSLSharpen, r) { - SkSL::Program::Settings settings; - settings.fSharpenTextures = true; - sk_sp caps = SkSL::ShaderCapsFactory::Default(); - settings.fCaps = caps.get(); - SkSL::Program::Inputs inputs; - test(r, - "uniform sampler1D one;" - "uniform sampler2D two;" - "void main() {" - "float4 a = sample(one, 0);" - "float4 b = sample(two, float2(0));" - "float4 c = sample(one, float2(0));" - "float4 d = sample(two, float3(0));" - "sk_FragColor = half4(half(a.x), half(b.x), half(c.x), half(d.x));" - "}", - settings, - "#version 400\n" - "out vec4 sk_FragColor;\n" - "uniform sampler1D one;\n" - "uniform sampler2D two;\n" - "void main() {\n" - " vec4 a = texture(one, 0.0, -0.5);\n" - " vec4 b = texture(two, vec2(0.0), -0.5);\n" - " vec4 c = textureProj(one, vec2(0.0), -0.5);\n" - " vec4 d = textureProj(two, vec3(0.0), -0.5);\n" - " sk_FragColor = vec4(a.x, b.x, c.x, d.x);\n" - "}\n", - &inputs); - - caps = SkSL::ShaderCapsFactory::Version110(); - settings.fCaps = caps.get(); - test(r, - "uniform sampler1D one;" - "uniform sampler2D two;" - "void main() {" - "float4 a = sample(one, 0);" - "float4 b = sample(two, float2(0));" - "float4 c = sample(one, float2(0));" - "float4 d = sample(two, float3(0));" - "sk_FragColor = half4(half(a.x), half(b.x), half(c.x), half(d.x));" - "}", - settings, - "#version 110\n" - "uniform sampler1D one;\n" - "uniform sampler2D two;\n" - "void main() {\n" - " vec4 a = texture1D(one, 0.0, -0.5);\n" - " vec4 b = texture2D(two, vec2(0.0), -0.5);\n" - " vec4 c = texture1DProj(one, vec2(0.0), -0.5);\n" - " vec4 d = texture2DProj(two, vec3(0.0), -0.5);\n" - " gl_FragColor = vec4(a.x, b.x, c.x, d.x);\n" - "}\n", - &inputs); -} - DEF_TEST(SkSLFragCoord, r) { SkSL::Program::Settings settings; settings.fFlipY = true; @@ -540,96 +387,6 @@ void main() { SkSL::Program::kGeometry_Kind); } -DEF_TEST(SkSLTypePrecision, r) { - test(r, - "float f = 1;" - "half h = 2;" - "float d = 3;" - "float2 f2 = float2(1, 2);" - "half3 h3 = half3(1, 2, 3);" - "float4 d4 = float4(1, 2, 3, 4);" - "float2x2 f22 = float2x2(1, 2, 3, 4);" - "half2x4 h24 = half2x4(1, 2, 3, 4, 5, 6, 7, 8);" - "float4x2 d42 = float4x2(1, 2, 3, 4, 5, 6, 7, 8);" - "void main() {" - "sk_FragColor.r = half(f + h + d + f2.x + h3.x + d4.x + f22[0][0] + h24[0][0] + " - "d42[0][0]);" - "}", - *SkSL::ShaderCapsFactory::Default(), - "#version 400\n" - "out vec4 sk_FragColor;\n" - "float f = 1.0;\n" - "float h = 2.0;\n" - "float d = 3.0;\n" - "vec2 f2 = vec2(1.0, 2.0);\n" - "vec3 h3 = vec3(1.0, 2.0, 3.0);\n" - "vec4 d4 = vec4(1.0, 2.0, 3.0, 4.0);\n" - "mat2 f22 = mat2(1.0, 2.0, 3.0, 4.0);\n" - "mat2x4 h24 = mat2x4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);\n" - "mat4x2 d42 = mat4x2(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);\n" - "void main() {\n" - " sk_FragColor.x = (((((((f + h) + d) + f2.x) + h3.x) + d4.x) + " - "f22[0][0]) + h24[0][0]) + d42[0][0];\n" - "}\n"); - test(r, - "float f = 1;" - "half h = 2;" - "float2 f2 = float2(1, 2);" - "half3 h3 = half3(1, 2, 3);" - "float2x2 f22 = float2x2(1, 2, 3, 4);" - "half2x4 h24 = half2x4(1, 2, 3, 4, 5, 6, 7, 8);" - "void main() {" - "sk_FragColor.r = half(f + h + f2.x + h3.x + f22[0][0] + h24[0][0]);" - "}", - *SkSL::ShaderCapsFactory::UsesPrecisionModifiers(), - "#version 400\n" - "precision mediump float;\n" - "precision mediump sampler2D;\n" - "out mediump vec4 sk_FragColor;\n" - "highp float f = 1.0;\n" - "mediump float h = 2.0;\n" - "highp vec2 f2 = vec2(1.0, 2.0);\n" - "mediump vec3 h3 = vec3(1.0, 2.0, 3.0);\n" - "highp mat2 f22 = mat2(1.0, 2.0, 3.0, 4.0);\n" - "mediump mat2x4 h24 = mat2x4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0);\n" - "void main() {\n" - " sk_FragColor.x = ((((f + h) + f2.x) + h3.x) + f22[0][0]) + h24[0][0];\n" - "}\n"); -} - -DEF_TEST(SkSLForceHighPrecision, r) { - test(r, - "void main() {\n half x = half(sqrt(1));\n half4 y = half4(x);\n sk_FragColor = y;\n }", - *SkSL::ShaderCapsFactory::UsesPrecisionModifiers(), - "#version 400\n" - "precision mediump float;\n" - "precision mediump sampler2D;\n" - "out mediump vec4 sk_FragColor;\n" - "void main() {\n" - " mediump float x = sqrt(1.0);\n" - " mediump vec4 y = vec4(x);\n" - " sk_FragColor = y;\n" - "}\n"); - SkSL::Program::Settings settings; - settings.fForceHighPrecision = true; - sk_sp caps = SkSL::ShaderCapsFactory::UsesPrecisionModifiers(); - settings.fCaps = caps.get(); - SkSL::Program::Inputs inputs; - test(r, - "void main() { half x = half(sqrt(1)); half4 y = half4(x); sk_FragColor = y; }", - settings, - "#version 400\n" - "precision mediump float;\n" - "precision mediump sampler2D;\n" - "out mediump vec4 sk_FragColor;\n" - "void main() {\n" - " highp float x = sqrt(1.0);\n" - " highp vec4 y = vec4(x);\n" - " sk_FragColor = y;\n" - "}\n", - &inputs); -} - DEF_TEST(SkSLNormalization, r) { test(r, "uniform float4 sk_RTAdjust; void main() { sk_Position = half4(1); }", diff --git a/tests/sksl/glsl/ForceHighPrecision.sksl b/tests/sksl/glsl/ForceHighPrecision.sksl new file mode 100644 index 0000000000..b3bd729180 --- /dev/null +++ b/tests/sksl/glsl/ForceHighPrecision.sksl @@ -0,0 +1,6 @@ +/*#pragma settings UsesPrecisionModifiers ForceHighPrecision*/ + +void main() { half x = half(sqrt(1)); + half4 y = half4(x); + sk_FragColor = y; +} diff --git a/tests/sksl/glsl/Texture.sksl b/tests/sksl/glsl/Texture.sksl new file mode 100644 index 0000000000..4fd3c48a14 --- /dev/null +++ b/tests/sksl/glsl/Texture.sksl @@ -0,0 +1,10 @@ +uniform sampler1D one; +uniform sampler2D two; + +void main() { + float4 a = sample(one, 0); + float4 b = sample(two, float2(0)); + float4 c = sample(one, float2(0)); + float4 d = sample(two, float3(0)); + sk_FragColor = half4(half(a.x), half(b.x), half(c.x), half(d.x)); +} diff --git a/tests/sksl/glsl/TextureSharpen.sksl b/tests/sksl/glsl/TextureSharpen.sksl new file mode 100644 index 0000000000..fd45a6c367 --- /dev/null +++ b/tests/sksl/glsl/TextureSharpen.sksl @@ -0,0 +1,12 @@ +/*#pragma settings Sharpen*/ + +uniform sampler1D one; +uniform sampler2D two; + +void main() { + float4 a = sample(one, 0); + float4 b = sample(two, float2(0)); + float4 c = sample(one, float2(0)); + float4 d = sample(two, float3(0)); + sk_FragColor = half4(half(a.x), half(b.x), half(c.x), half(d.x)); +} diff --git a/tests/sksl/glsl/TextureSharpenVersion110.sksl b/tests/sksl/glsl/TextureSharpenVersion110.sksl new file mode 100644 index 0000000000..670413f2f0 --- /dev/null +++ b/tests/sksl/glsl/TextureSharpenVersion110.sksl @@ -0,0 +1,12 @@ +/*#pragma settings Version110 Sharpen*/ + +uniform sampler1D one; +uniform sampler2D two; + +void main() { + float4 a = sample(one, 0); + float4 b = sample(two, float2(0)); + float4 c = sample(one, float2(0)); + float4 d = sample(two, float3(0)); + sk_FragColor = half4(half(a.x), half(b.x), half(c.x), half(d.x)); +} diff --git a/tests/sksl/glsl/TextureVersion110.sksl b/tests/sksl/glsl/TextureVersion110.sksl new file mode 100644 index 0000000000..13776f812c --- /dev/null +++ b/tests/sksl/glsl/TextureVersion110.sksl @@ -0,0 +1,12 @@ +/*#pragma settings Version110*/ + +uniform sampler1D one; +uniform sampler2D two; + +void main() { + float4 a = sample(one, 0); + float4 b = sample(two, float2(0)); + float4 c = sample(one, float2(0)); + float4 d = sample(two, float3(0)); + sk_FragColor = half4(half(a.x), half(b.x), half(c.x), half(d.x)); +} diff --git a/tests/sksl/glsl/TypePrecisionDisabled.sksl b/tests/sksl/glsl/TypePrecisionDisabled.sksl new file mode 100644 index 0000000000..87bc0ffe26 --- /dev/null +++ b/tests/sksl/glsl/TypePrecisionDisabled.sksl @@ -0,0 +1,10 @@ +float f = 1; +half h = 2; +float2 f2 = float2(1, 2); +half3 h3 = half3(1, 2, 3); +float2x2 f22 = float2x2(1, 2, 3, 4); +half2x4 h24 = half2x4(1, 2, 3, 4, 5, 6, 7, 8); + +void main() { + sk_FragColor.r = half(f + h + f2.x + h3.x + f22[0][0] + h24[0][0]); +} diff --git a/tests/sksl/glsl/TypePrecisionEnabled.sksl b/tests/sksl/glsl/TypePrecisionEnabled.sksl new file mode 100644 index 0000000000..b3f9faddbc --- /dev/null +++ b/tests/sksl/glsl/TypePrecisionEnabled.sksl @@ -0,0 +1,12 @@ +/*#pragma settings UsesPrecisionModifiers*/ + +float f = 1; +half h = 2; +float2 f2 = float2(1, 2); +half3 h3 = half3(1, 2, 3); +float2x2 f22 = float2x2(1, 2, 3, 4); +half2x4 h24 = half2x4(1, 2, 3, 4, 5, 6, 7, 8); + +void main() { + sk_FragColor.r = half(f + h + f2.x + h3.x + f22[0][0] + h24[0][0]); +} diff --git a/tests/sksl/glsl/UsesPrecisionModifiers.sksl b/tests/sksl/glsl/UsesPrecisionModifiers.sksl new file mode 100644 index 0000000000..e7b6594df8 --- /dev/null +++ b/tests/sksl/glsl/UsesPrecisionModifiers.sksl @@ -0,0 +1,9 @@ +/*#pragma settings UsesPrecisionModifiers*/ + +void main() { + half x = 0.75; + float y = 1; + x++; + y++; + sk_FragColor.rg = half2(x, half(y)); +} diff --git a/tests/sksl/glsl/Version110.sksl b/tests/sksl/glsl/Version110.sksl new file mode 100644 index 0000000000..5a48ccd169 --- /dev/null +++ b/tests/sksl/glsl/Version110.sksl @@ -0,0 +1,5 @@ +/*#pragma settings Version110*/ + +in float test; + +void main() { sk_FragColor.r = half(test); } diff --git a/tests/sksl/glsl/Version450Core.sksl b/tests/sksl/glsl/Version450Core.sksl new file mode 100644 index 0000000000..932206666e --- /dev/null +++ b/tests/sksl/glsl/Version450Core.sksl @@ -0,0 +1,5 @@ +/*#pragma settings Version450Core*/ + +in float test; + +void main() { sk_FragColor.r = half(test); } diff --git a/tests/sksl/glsl/golden/ForceHighPrecision.glsl b/tests/sksl/glsl/golden/ForceHighPrecision.glsl new file mode 100644 index 0000000000..97dda9785e --- /dev/null +++ b/tests/sksl/glsl/golden/ForceHighPrecision.glsl @@ -0,0 +1,9 @@ +#version 400 +precision mediump float; +precision mediump sampler2D; +out mediump vec4 sk_FragColor; +void main() { + highp float x = sqrt(1.0); + highp vec4 y = vec4(x); + sk_FragColor = y; +} diff --git a/tests/sksl/glsl/golden/Texture.glsl b/tests/sksl/glsl/golden/Texture.glsl new file mode 100644 index 0000000000..530d094ac3 --- /dev/null +++ b/tests/sksl/glsl/golden/Texture.glsl @@ -0,0 +1,11 @@ + +out vec4 sk_FragColor; +uniform sampler1D one; +uniform sampler2D two; +void main() { + vec4 a = texture(one, 0.0); + vec4 b = texture(two, vec2(0.0)); + vec4 c = textureProj(one, vec2(0.0)); + vec4 d = textureProj(two, vec3(0.0)); + sk_FragColor = vec4(a.x, b.x, c.x, d.x); +} diff --git a/tests/sksl/glsl/golden/TextureSharpen.glsl b/tests/sksl/glsl/golden/TextureSharpen.glsl new file mode 100644 index 0000000000..f2ed4e85db --- /dev/null +++ b/tests/sksl/glsl/golden/TextureSharpen.glsl @@ -0,0 +1,11 @@ + +out vec4 sk_FragColor; +uniform sampler1D one; +uniform sampler2D two; +void main() { + vec4 a = texture(one, 0.0, -0.5); + vec4 b = texture(two, vec2(0.0), -0.5); + vec4 c = textureProj(one, vec2(0.0), -0.5); + vec4 d = textureProj(two, vec3(0.0), -0.5); + sk_FragColor = vec4(a.x, b.x, c.x, d.x); +} diff --git a/tests/sksl/glsl/golden/TextureSharpenVersion110.glsl b/tests/sksl/glsl/golden/TextureSharpenVersion110.glsl new file mode 100644 index 0000000000..1921c10bdd --- /dev/null +++ b/tests/sksl/glsl/golden/TextureSharpenVersion110.glsl @@ -0,0 +1,10 @@ +#version 110 +uniform sampler1D one; +uniform sampler2D two; +void main() { + vec4 a = texture1D(one, 0.0, -0.5); + vec4 b = texture2D(two, vec2(0.0), -0.5); + vec4 c = texture1DProj(one, vec2(0.0), -0.5); + vec4 d = texture2DProj(two, vec3(0.0), -0.5); + gl_FragColor = vec4(a.x, b.x, c.x, d.x); +} diff --git a/tests/sksl/glsl/golden/TextureVersion110.glsl b/tests/sksl/glsl/golden/TextureVersion110.glsl new file mode 100644 index 0000000000..752a34ab7a --- /dev/null +++ b/tests/sksl/glsl/golden/TextureVersion110.glsl @@ -0,0 +1,10 @@ +#version 110 +uniform sampler1D one; +uniform sampler2D two; +void main() { + vec4 a = texture1D(one, 0.0); + vec4 b = texture2D(two, vec2(0.0)); + vec4 c = texture1DProj(one, vec2(0.0)); + vec4 d = texture2DProj(two, vec3(0.0)); + gl_FragColor = vec4(a.x, b.x, c.x, d.x); +} diff --git a/tests/sksl/glsl/golden/TypePrecisionDisabled.glsl b/tests/sksl/glsl/golden/TypePrecisionDisabled.glsl new file mode 100644 index 0000000000..e42d397111 --- /dev/null +++ b/tests/sksl/glsl/golden/TypePrecisionDisabled.glsl @@ -0,0 +1,11 @@ + +out vec4 sk_FragColor; +float f = 1.0; +float h = 2.0; +vec2 f2 = vec2(1.0, 2.0); +vec3 h3 = vec3(1.0, 2.0, 3.0); +mat2 f22 = mat2(1.0, 2.0, 3.0, 4.0); +mat2x4 h24 = mat2x4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0); +void main() { + sk_FragColor.x = ((((f + h) + f2.x) + h3.x) + f22[0][0]) + h24[0][0]; +} diff --git a/tests/sksl/glsl/golden/TypePrecisionEnabled.glsl b/tests/sksl/glsl/golden/TypePrecisionEnabled.glsl new file mode 100644 index 0000000000..7e3804bf74 --- /dev/null +++ b/tests/sksl/glsl/golden/TypePrecisionEnabled.glsl @@ -0,0 +1,13 @@ +#version 400 +precision mediump float; +precision mediump sampler2D; +out mediump vec4 sk_FragColor; +highp float f = 1.0; +mediump float h = 2.0; +highp vec2 f2 = vec2(1.0, 2.0); +mediump vec3 h3 = vec3(1.0, 2.0, 3.0); +highp mat2 f22 = mat2(1.0, 2.0, 3.0, 4.0); +mediump mat2x4 h24 = mat2x4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0); +void main() { + sk_FragColor.x = ((((f + h) + f2.x) + h3.x) + f22[0][0]) + h24[0][0]; +} diff --git a/tests/sksl/glsl/golden/UsesPrecisionModifiers.glsl b/tests/sksl/glsl/golden/UsesPrecisionModifiers.glsl new file mode 100644 index 0000000000..abd44c5aa6 --- /dev/null +++ b/tests/sksl/glsl/golden/UsesPrecisionModifiers.glsl @@ -0,0 +1,11 @@ +#version 400 +precision mediump float; +precision mediump sampler2D; +out mediump vec4 sk_FragColor; +void main() { + mediump float x = 0.75; + highp float y = 1.0; + x++; + y++; + sk_FragColor.xy = vec2(x, y); +} diff --git a/tests/sksl/glsl/golden/Version110.glsl b/tests/sksl/glsl/golden/Version110.glsl new file mode 100644 index 0000000000..c6944318f2 --- /dev/null +++ b/tests/sksl/glsl/golden/Version110.glsl @@ -0,0 +1,5 @@ +#version 110 +varying float test; +void main() { + gl_FragColor.x = test; +} diff --git a/tests/sksl/glsl/golden/Version450Core.glsl b/tests/sksl/glsl/golden/Version450Core.glsl new file mode 100644 index 0000000000..97caa31642 --- /dev/null +++ b/tests/sksl/glsl/golden/Version450Core.glsl @@ -0,0 +1,6 @@ +#version 450 core +out vec4 sk_FragColor; +in float test; +void main() { + sk_FragColor.x = test; +}