Brian Osman | 088913a | 2019-12-19 15:44:56 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 Google LLC |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 8 | #include "include/core/SkBitmap.h" |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 9 | #include "include/core/SkCanvas.h" |
Brian Osman | 92aac1e | 2020-08-05 16:48:58 -0400 | [diff] [blame] | 10 | #include "include/core/SkColorFilter.h" |
Brian Osman | 269b21c | 2020-08-06 12:15:53 -0400 | [diff] [blame] | 11 | #include "include/core/SkData.h" |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 12 | #include "include/core/SkPaint.h" |
| 13 | #include "include/core/SkSurface.h" |
Brian Osman | ee426f2 | 2020-01-02 11:55:24 -0500 | [diff] [blame] | 14 | #include "include/effects/SkRuntimeEffect.h" |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 15 | #include "include/gpu/GrDirectContext.h" |
Brian Osman | d9bde07 | 2020-04-15 14:18:13 -0400 | [diff] [blame] | 16 | #include "src/core/SkTLazy.h" |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 17 | #include "src/gpu/GrColor.h" |
Brian Osman | 088913a | 2019-12-19 15:44:56 -0500 | [diff] [blame] | 18 | #include "tests/Test.h" |
| 19 | |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 20 | #include <algorithm> |
| 21 | |
Brian Osman | 5f6b41e | 2020-03-09 11:53:24 -0400 | [diff] [blame] | 22 | DEF_TEST(SkRuntimeEffectInvalid, r) { |
| 23 | auto test = [r](const char* hdr, const char* body, const char* expected) { |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 24 | SkString src = SkStringPrintf("%s half4 main(float2 p) { %s return half4(0); }", |
Brian Osman | 5f6b41e | 2020-03-09 11:53:24 -0400 | [diff] [blame] | 25 | hdr, body); |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 26 | auto[effect, errorText] = SkRuntimeEffect::Make(src); |
Brian Osman | 088913a | 2019-12-19 15:44:56 -0500 | [diff] [blame] | 27 | REPORTER_ASSERT(r, !effect); |
| 28 | REPORTER_ASSERT(r, errorText.contains(expected), |
| 29 | "Expected error message to contain \"%s\". Actual message: \"%s\"", |
| 30 | expected, errorText.c_str()); |
| 31 | }; |
| 32 | |
| 33 | // Features that are only allowed in .fp files (key, in uniform, ctype, when, tracked). |
| 34 | // Ensure that these fail, and the error messages contain the relevant keyword. |
Brian Osman | 5f6b41e | 2020-03-09 11:53:24 -0400 | [diff] [blame] | 35 | test("layout(key) in bool Input;", "", "key"); |
| 36 | test("in uniform float Input;", "", "in uniform"); |
| 37 | test("layout(ctype=SkRect) float4 Input;", "", "ctype"); |
| 38 | test("in bool Flag; layout(when=Flag) uniform float Input;", "", "when"); |
| 39 | test("layout(tracked) uniform float Input;", "", "tracked"); |
Brian Osman | 088913a | 2019-12-19 15:44:56 -0500 | [diff] [blame] | 40 | |
Brian Osman | a4b9169 | 2020-08-10 14:26:16 -0400 | [diff] [blame] | 41 | // Runtime SkSL supports a limited set of uniform types. No samplers, bool, or int, for example: |
| 42 | test("uniform sampler2D s;", "", "uniform"); |
| 43 | test("uniform bool b;", "", "uniform"); |
| 44 | test("uniform int i;", "", "uniform"); |
Brian Osman | 088913a | 2019-12-19 15:44:56 -0500 | [diff] [blame] | 45 | |
Brian Osman | a4b9169 | 2020-08-10 14:26:16 -0400 | [diff] [blame] | 46 | // 'in' variables aren't allowed at all: |
| 47 | test("in bool b;", "", "'in'"); |
| 48 | test("in float f;", "", "'in'"); |
| 49 | test("in float2 v;", "", "'in'"); |
| 50 | test("in half3x3 m;", "", "'in'"); |
Brian Osman | 8783b78 | 2020-01-06 11:13:45 -0500 | [diff] [blame] | 51 | |
Brian Osman | a4b9169 | 2020-08-10 14:26:16 -0400 | [diff] [blame] | 52 | // 'marker' is only permitted on float4x4 uniforms |
Brian Osman | e64ae86 | 2020-07-16 15:29:15 -0400 | [diff] [blame] | 53 | test("layout(marker=local_to_world) uniform float3x3 localToWorld;", "", "float4x4"); |
| 54 | |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 55 | test("float missing();", "p.x = missing();", "undefined function"); |
Brian Osman | 182c92e | 2020-07-20 15:18:33 -0400 | [diff] [blame] | 56 | |
| 57 | // Shouldn't be possible to create an SkRuntimeEffect without "main" |
| 58 | test("//", "", "main"); |
Brian Osman | 8232900 | 2020-07-21 09:39:27 -0400 | [diff] [blame] | 59 | |
| 60 | // Various places that shaders (fragmentProcessors) should not be allowed |
| 61 | test("", |
| 62 | "shader child;", |
| 63 | "must be global"); |
| 64 | test("in shader child; half4 helper(shader fp) { return sample(fp); }", |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 65 | "half4 color = helper(child);", |
Brian Osman | 8232900 | 2020-07-21 09:39:27 -0400 | [diff] [blame] | 66 | "parameter"); |
| 67 | test("in shader child; shader get_child() { return child; }", |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 68 | "half4 color = sample(get_child());", |
Brian Osman | 8232900 | 2020-07-21 09:39:27 -0400 | [diff] [blame] | 69 | "return"); |
| 70 | test("in shader child;", |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 71 | "half4 color = sample(shader(child));", |
Brian Osman | 8232900 | 2020-07-21 09:39:27 -0400 | [diff] [blame] | 72 | "construct"); |
| 73 | test("in shader child1; in shader child2;", |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 74 | "half4 color = sample(p.x > 10 ? child1 : child2);", |
Brian Osman | 8232900 | 2020-07-21 09:39:27 -0400 | [diff] [blame] | 75 | "expression"); |
Brian Osman | e12939f | 2020-08-12 11:36:56 -0400 | [diff] [blame] | 76 | |
| 77 | // Errors that aren't caught until later in the compilation process (during optimize()) |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 78 | test("", "return half4(1);", "unreachable"); |
Brian Osman | e12939f | 2020-08-12 11:36:56 -0400 | [diff] [blame] | 79 | test("half badFunc() { }", "", "without returning"); |
Brian Osman | 088913a | 2019-12-19 15:44:56 -0500 | [diff] [blame] | 80 | } |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 81 | |
Brian Osman | 92aac1e | 2020-08-05 16:48:58 -0400 | [diff] [blame] | 82 | DEF_TEST(SkRuntimeEffectInvalidColorFilters, r) { |
| 83 | auto test = [r](const char* sksl) { |
| 84 | auto [effect, errorText] = SkRuntimeEffect::Make(SkString(sksl)); |
| 85 | REPORTER_ASSERT(r, effect); |
Brian Osman | 269b21c | 2020-08-06 12:15:53 -0400 | [diff] [blame] | 86 | |
Brian Osman | a4b9169 | 2020-08-10 14:26:16 -0400 | [diff] [blame] | 87 | sk_sp<SkData> uniforms = SkData::MakeUninitialized(effect->uniformSize()); |
Brian Osman | 269b21c | 2020-08-06 12:15:53 -0400 | [diff] [blame] | 88 | |
Brian Osman | a4b9169 | 2020-08-10 14:26:16 -0400 | [diff] [blame] | 89 | REPORTER_ASSERT(r, effect->makeShader(uniforms, nullptr, 0, nullptr, false)); |
| 90 | REPORTER_ASSERT(r, !effect->makeColorFilter(uniforms)); |
Brian Osman | 92aac1e | 2020-08-05 16:48:58 -0400 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | // Runtime effects that use sample coords or sk_FragCoord are valid shaders, |
| 94 | // but not valid color filters |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 95 | test("half4 main(float2 p) { return half2(p).xy01; }"); |
| 96 | test("half4 main(float2 p) { return half2(sk_FragCoord.xy).xy01; }"); |
Brian Osman | 269b21c | 2020-08-06 12:15:53 -0400 | [diff] [blame] | 97 | |
| 98 | // We also can't use layout(marker), which would give the runtime color filter CTM information |
| 99 | test("layout(marker=ctm) uniform float4x4 ctm;" |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 100 | "half4 main(float2 p) { return half4(half(ctm[0][0]), 0, 0, 1); }"); |
Brian Osman | 92aac1e | 2020-08-05 16:48:58 -0400 | [diff] [blame] | 101 | } |
| 102 | |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 103 | class TestEffect { |
| 104 | public: |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 105 | TestEffect(skiatest::Reporter* r, sk_sp<SkSurface> surface) |
| 106 | : fReporter(r), fSurface(std::move(surface)) {} |
| 107 | |
| 108 | void build(const char* header, const char* body) { |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 109 | SkString src = SkStringPrintf("%s half4 main(float2 p) { %s }", |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 110 | header, body); |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 111 | auto[effect, errorText] = SkRuntimeEffect::Make(src); |
| 112 | if (!effect) { |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 113 | REPORT_FAILURE(fReporter, "effect", |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 114 | SkStringPrintf("Effect didn't compile: %s", errorText.c_str())); |
| 115 | return; |
| 116 | } |
Brian Osman | d9bde07 | 2020-04-15 14:18:13 -0400 | [diff] [blame] | 117 | fBuilder.init(std::move(effect)); |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 118 | } |
| 119 | |
Brian Osman | a4b9169 | 2020-08-10 14:26:16 -0400 | [diff] [blame] | 120 | SkRuntimeShaderBuilder::BuilderUniform uniform(const char* name) { |
| 121 | return fBuilder->uniform(name); |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 122 | } |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 123 | SkRuntimeShaderBuilder::BuilderChild child(const char* name) { |
| 124 | return fBuilder->child(name); |
| 125 | } |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 126 | |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 127 | using PreTestFn = std::function<void(SkCanvas*, SkPaint*)>; |
| 128 | |
| 129 | void test(GrColor TL, GrColor TR, GrColor BL, GrColor BR, |
| 130 | PreTestFn preTestCallback = nullptr) { |
Brian Osman | d9bde07 | 2020-04-15 14:18:13 -0400 | [diff] [blame] | 131 | auto shader = fBuilder->makeShader(nullptr, false); |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 132 | if (!shader) { |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 133 | REPORT_FAILURE(fReporter, "shader", SkString("Effect didn't produce a shader")); |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 134 | return; |
| 135 | } |
| 136 | |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 137 | SkCanvas* canvas = fSurface->getCanvas(); |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 138 | SkPaint paint; |
| 139 | paint.setShader(std::move(shader)); |
| 140 | paint.setBlendMode(SkBlendMode::kSrc); |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 141 | |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 142 | canvas->save(); |
| 143 | if (preTestCallback) { |
| 144 | preTestCallback(canvas, &paint); |
| 145 | } |
| 146 | canvas->drawPaint(paint); |
| 147 | canvas->restore(); |
| 148 | |
| 149 | GrColor actual[4]; |
| 150 | SkImageInfo info = fSurface->imageInfo(); |
| 151 | if (!fSurface->readPixels(info, actual, info.minRowBytes(), 0, 0)) { |
| 152 | REPORT_FAILURE(fReporter, "readPixels", SkString("readPixels failed")); |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 153 | return; |
| 154 | } |
| 155 | |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 156 | GrColor expected[4] = {TL, TR, BL, BR}; |
John Stiles | c1c3c6d | 2020-08-15 23:22:53 -0400 | [diff] [blame] | 157 | if (0 != memcmp(actual, expected, sizeof(actual))) { |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 158 | REPORT_FAILURE(fReporter, "Runtime effect didn't match expectations", |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 159 | SkStringPrintf("\n" |
| 160 | "Expected: [ %08x %08x %08x %08x ]\n" |
| 161 | "Got : [ %08x %08x %08x %08x ]\n" |
| 162 | "SkSL:\n%s\n", |
| 163 | TL, TR, BL, BR, actual[0], actual[1], actual[2], |
Brian Osman | d9bde07 | 2020-04-15 14:18:13 -0400 | [diff] [blame] | 164 | actual[3], fBuilder->fEffect->source().c_str())); |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 165 | } |
| 166 | } |
| 167 | |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 168 | void test(GrColor expected, PreTestFn preTestCallback = nullptr) { |
| 169 | this->test(expected, expected, expected, expected, preTestCallback); |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | private: |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 173 | skiatest::Reporter* fReporter; |
| 174 | sk_sp<SkSurface> fSurface; |
Brian Osman | d9bde07 | 2020-04-15 14:18:13 -0400 | [diff] [blame] | 175 | SkTLazy<SkRuntimeShaderBuilder> fBuilder; |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 176 | }; |
| 177 | |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 178 | // Produces a 2x2 bitmap shader, with opaque colors: |
| 179 | // [ Red, Green ] |
| 180 | // [ Blue, White ] |
| 181 | static sk_sp<SkShader> make_RGBW_shader() { |
| 182 | SkBitmap bmp; |
| 183 | bmp.allocPixels(SkImageInfo::Make(2, 2, kRGBA_8888_SkColorType, kPremul_SkAlphaType)); |
| 184 | SkIRect topLeft = SkIRect::MakeWH(1, 1); |
| 185 | bmp.pixmap().erase(SK_ColorRED, topLeft); |
| 186 | bmp.pixmap().erase(SK_ColorGREEN, topLeft.makeOffset(1, 0)); |
| 187 | bmp.pixmap().erase(SK_ColorBLUE, topLeft.makeOffset(0, 1)); |
| 188 | bmp.pixmap().erase(SK_ColorWHITE, topLeft.makeOffset(1, 1)); |
| 189 | return bmp.makeShader(); |
| 190 | } |
| 191 | |
Robert Phillips | e94b4e1 | 2020-07-23 13:54:35 -0400 | [diff] [blame] | 192 | static void test_RuntimeEffect_Shaders(skiatest::Reporter* r, GrRecordingContext* rContext) { |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 193 | SkImageInfo info = SkImageInfo::Make(2, 2, kRGBA_8888_SkColorType, kPremul_SkAlphaType); |
Robert Phillips | e94b4e1 | 2020-07-23 13:54:35 -0400 | [diff] [blame] | 194 | sk_sp<SkSurface> surface = rContext |
| 195 | ? SkSurface::MakeRenderTarget(rContext, SkBudgeted::kNo, info) |
| 196 | : SkSurface::MakeRaster(info); |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 197 | REPORTER_ASSERT(r, surface); |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 198 | TestEffect effect(r, surface); |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 199 | |
Brian Osman | 504032e | 2020-01-10 10:05:24 -0500 | [diff] [blame] | 200 | using float4 = std::array<float, 4>; |
| 201 | |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 202 | // Local coords |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 203 | effect.build("", "return half4(half2(p - 0.5), 0, 1);"); |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 204 | effect.test(0xFF000000, 0xFF0000FF, 0xFF00FF00, 0xFF00FFFF); |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 205 | |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 206 | // Use of a simple uniform. (Draw twice with two values to ensure it's updated). |
| 207 | effect.build("uniform float4 gColor;", |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 208 | "return half4(gColor);"); |
Brian Osman | a4b9169 | 2020-08-10 14:26:16 -0400 | [diff] [blame] | 209 | effect.uniform("gColor") = float4{ 0.0f, 0.25f, 0.75f, 1.0f }; |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 210 | effect.test(0xFFBF4000); |
Brian Osman | a4b9169 | 2020-08-10 14:26:16 -0400 | [diff] [blame] | 211 | effect.uniform("gColor") = float4{ 1.0f, 0.0f, 0.0f, 0.498f }; |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 212 | effect.test(0x7F00007F); // Tests that we clamp to valid premul |
Michael Ludwig | 5e6b3cd | 2020-05-27 17:02:37 -0400 | [diff] [blame] | 213 | |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 214 | // Test sk_FragCoord (device coords). Rotate the canvas to be sure we're seeing device coords. |
| 215 | // Since the surface is 2x2, we should see (0,0), (1,0), (0,1), (1,1). Multiply by 0.498 to |
| 216 | // make sure we're not saturating unexpectedly. |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 217 | effect.build("", "return half4(0.498 * (half2(sk_FragCoord.xy) - 0.5), 0, 1);"); |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 218 | effect.test(0xFF000000, 0xFF00007F, 0xFF007F00, 0xFF007F7F, |
| 219 | [](SkCanvas* canvas, SkPaint*) { canvas->rotate(45.0f); }); |
Michael Ludwig | 22534f2 | 2020-05-27 17:25:33 -0400 | [diff] [blame] | 220 | |
Brian Osman | b5f0f52 | 2020-07-23 13:28:14 -0400 | [diff] [blame] | 221 | // |
| 222 | // Sampling children |
| 223 | // |
| 224 | |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 225 | // Sampling a null child should return the paint color |
| 226 | effect.build("in shader child;", |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 227 | "return sample(child);"); |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 228 | effect.child("child") = nullptr; |
| 229 | effect.test(0xFF00FFFF, |
| 230 | [](SkCanvas*, SkPaint* paint) { paint->setColor4f({1.0f, 1.0f, 0.0f, 1.0f}); }); |
| 231 | |
| 232 | sk_sp<SkShader> rgbwShader = make_RGBW_shader(); |
| 233 | |
| 234 | // Sampling a simple child at our coordinates (implicitly) |
| 235 | effect.build("in shader child;", |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 236 | "return sample(child);"); |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 237 | effect.child("child") = rgbwShader; |
| 238 | effect.test(0xFF0000FF, 0xFF00FF00, 0xFFFF0000, 0xFFFFFFFF); |
| 239 | |
| 240 | // Sampling with explicit coordinates (reflecting about the diagonal) |
| 241 | effect.build("in shader child;", |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 242 | "return sample(child, p.yx);"); |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 243 | effect.child("child") = rgbwShader; |
| 244 | effect.test(0xFF0000FF, 0xFFFF0000, 0xFF00FF00, 0xFFFFFFFF); |
| 245 | |
| 246 | // Sampling with a matrix (again, reflecting about the diagonal) |
| 247 | effect.build("in shader child;", |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 248 | "return sample(child, float3x3(0, 1, 0, 1, 0, 0, 0, 0, 1));"); |
Brian Osman | 6241961 | 2020-07-22 10:19:02 -0400 | [diff] [blame] | 249 | effect.child("child") = rgbwShader; |
| 250 | effect.test(0xFF0000FF, 0xFFFF0000, 0xFF00FF00, 0xFFFFFFFF); |
Brian Osman | b5f0f52 | 2020-07-23 13:28:14 -0400 | [diff] [blame] | 251 | |
| 252 | // |
| 253 | // Helper functions |
| 254 | // |
| 255 | |
| 256 | // Test case for inlining in the pipeline-stage and fragment-shader passes (skbug.com/10526): |
| 257 | effect.build("float2 helper(float2 x) { return x + 1; }", |
| 258 | "float2 v = helper(p);" |
Brian Osman | 767f444 | 2020-08-13 16:59:48 -0400 | [diff] [blame] | 259 | "return half4(half2(v), 0, 1);"); |
Brian Osman | b5f0f52 | 2020-07-23 13:28:14 -0400 | [diff] [blame] | 260 | effect.test(0xFF00FFFF); |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | DEF_TEST(SkRuntimeEffectSimple, r) { |
| 264 | test_RuntimeEffect_Shaders(r, nullptr); |
| 265 | } |
| 266 | |
| 267 | DEF_GPUTEST_FOR_RENDERING_CONTEXTS(SkRuntimeEffectSimple_GPU, r, ctxInfo) { |
Robert Phillips | 6d344c3 | 2020-07-06 10:56:46 -0400 | [diff] [blame] | 268 | test_RuntimeEffect_Shaders(r, ctxInfo.directContext()); |
Brian Osman | f72dedd | 2020-01-08 13:19:58 -0500 | [diff] [blame] | 269 | } |