Skip to content

Commit 91292e9

Browse files
brianosmanSkia Commit-Bot
authored andcommitted
Runtime Effects: Support 'uniform shader' (vs. 'in shader')
The previous behavior leaked Skia-internal concepts into public SkSL. Users coming from GLSL will expect that bindable/sampleable objects are uniform (just like texture2D). This keeps the old support around (and tested), but updates all of our examples to use 'uniform'. Bug: skia:10679 Change-Id: I0c98162f5e21dad7014d9778ceb26143d2f6030e Reviewed-on: https://skia-review.googlesource.com/c/skia/+/332376 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: John Stiles <johnstiles@google.com>
1 parent 95acbbc commit 91292e9

File tree

17 files changed

+60
-51
lines changed

17 files changed

+60
-51
lines changed

bench/ColorFilterBench.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class ColorFilterBench final : public Benchmark {
128128
};
129129

130130
const char RuntimeNone_GPU_SRC[] = R"(
131-
in shader input;
131+
uniform shader input;
132132
half4 main() { return sample(input); }
133133
)";
134134

@@ -138,7 +138,7 @@ const char RuntimeColorMatrix_GPU_SRC[] = R"(
138138
m5 , m6 , m7 , m8 , m9 ,
139139
m10, m11, m12, m13, m14,
140140
m15, m16, m17, m18, m19;
141-
in shader input;
141+
uniform shader input;
142142
half4 main() {
143143
half4 c = unpremul(sample(input));
144144

gm/fp_sample_chaining.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ DEF_SIMPLE_GPU_GM(fp_sample_chaining, ctx, rtCtx, canvas, 380, 306) {
277277
}
278278

279279
const char* gConstantMatrixSkSL = R"(
280-
in shader child;
280+
uniform shader child;
281281
half4 main(float2 xy) {
282282
return sample(child, float3x3(0.5, 0.0, 0.0,
283283
0.0, 1.0, 0.0,
@@ -286,7 +286,7 @@ const char* gConstantMatrixSkSL = R"(
286286
)";
287287

288288
const char* gUniformMatrixSkSL = R"(
289-
in shader child;
289+
uniform shader child;
290290
uniform float3x3 matrix;
291291
half4 main(float2 xy) {
292292
return sample(child, matrix);
@@ -297,7 +297,7 @@ const char* gUniformMatrixSkSL = R"(
297297
// when scanning for sample matrices. With that pulled into a separate local, it's highly unlikely
298298
// we'll ever treat this as anything else.
299299
const char* gVariableMatrixSkSL = R"(
300-
in shader child;
300+
uniform shader child;
301301
uniform float3x3 matrix;
302302
half4 main(float2 xy) {
303303
float3x3 varMatrix = matrix * 0.5;
@@ -306,7 +306,7 @@ const char* gVariableMatrixSkSL = R"(
306306
)";
307307

308308
const char* gExplicitCoordSkSL = R"(
309-
in shader child;
309+
uniform shader child;
310310
half4 main(float2 xy) {
311311
return sample(child, xy + float2(0, 8));
312312
}

gm/mixercolorfilter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ class MixerCFGM final : public skiagm::GM {
110110
sk_sp<SkRuntimeEffect> effect;
111111
if (fRuntime) {
112112
const char* sksl = R"(
113-
in shader cf0;
114-
in shader cf1;
113+
uniform shader cf0;
114+
uniform shader cf1;
115115
uniform half t;
116116
half4 main() {
117117
return mix(sample(cf0), sample(cf1), t);

gm/runtimecolorfilter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@
2121
#include <utility>
2222

2323
const char* gNoop = R"(
24-
in shader input;
24+
uniform shader input;
2525
half4 main() {
2626
return sample(input);
2727
}
2828
)";
2929

3030
const char* gLumaSrc = R"(
31-
in shader input;
31+
uniform shader input;
3232
half4 main() {
3333
return dot(sample(input).rgb, half3(0.3, 0.6, 0.1)).000r;
3434
}
3535
)";
3636

3737
const char* gLumaSrcWithCoords = R"(
38-
in shader input;
38+
uniform shader input;
3939
half4 main(float2 p) {
4040
return dot(sample(input).rgb, half3(0.3, 0.6, 0.1)).000r;
4141
}
@@ -46,7 +46,7 @@ const char* gLumaSrcWithCoords = R"(
4646

4747
// Simplest to run; hardest to write?
4848
const char* gTernary = R"(
49-
in shader input;
49+
uniform shader input;
5050
half4 main() {
5151
half4 color = sample(input);
5252
half luma = dot(color.rgb, half3(0.3, 0.6, 0.1));
@@ -60,7 +60,7 @@ const char* gTernary = R"(
6060

6161
// Uses conditional if statements but no early return.
6262
const char* gIfs = R"(
63-
in shader input;
63+
uniform shader input;
6464
half4 main() {
6565
half4 color = sample(input);
6666
half luma = dot(color.rgb, half3(0.3, 0.6, 0.1));
@@ -79,7 +79,7 @@ const char* gIfs = R"(
7979

8080
// Distilled from AOSP tone mapping shaders, more like what people tend to write.
8181
const char* gEarlyReturn = R"(
82-
in shader input;
82+
uniform shader input;
8383
half4 main() {
8484
half4 color = sample(input);
8585
half luma = dot(color.rgb, half3(0.3, 0.6, 0.1));

gm/runtimeshader.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ static sk_sp<SkShader> make_threshold(SkISize size) {
120120
class ThresholdRT : public RuntimeShaderGM {
121121
public:
122122
ThresholdRT() : RuntimeShaderGM("threshold_rt", {256, 256}, R"(
123-
in shader before_map;
124-
in shader after_map;
125-
in shader threshold_map;
123+
uniform shader before_map;
124+
uniform shader after_map;
125+
uniform shader threshold_map;
126126
127127
uniform float cutoff;
128128
uniform float slope;
@@ -218,8 +218,8 @@ DEF_GM(return new SpiralRT;)
218218
class ColorCubeRT : public RuntimeShaderGM {
219219
public:
220220
ColorCubeRT() : RuntimeShaderGM("color_cube_rt", {512, 512}, R"(
221-
in shader input;
222-
in shader color_cube;
221+
uniform shader input;
222+
uniform shader color_cube;
223223
224224
uniform float rg_scale;
225225
uniform float rg_bias;
@@ -303,7 +303,7 @@ class DefaultColorRT : public RuntimeShaderGM {
303303
// This test also *explicitly* doesn't include coords in main's parameter list, to test that
304304
// runtime shaders work without them being declared (when they're not used).
305305
DefaultColorRT() : RuntimeShaderGM("default_color_rt", {512, 256}, R"(
306-
in shader input;
306+
uniform shader input;
307307
half4 main() {
308308
return sample(input);
309309
}

gm/vertices.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,8 @@ DEF_SIMPLE_GM(vertices_data_lerp, canvas, 256, 256) {
377377

378378
SkPaint paint;
379379
const char* gProg = R"(
380-
in shader c0;
381-
in shader c1;
380+
uniform shader c0;
381+
uniform shader c1;
382382
varying float vtx_lerp;
383383
half4 main(float2 p) {
384384
half4 col0 = sample(c0, p);

modules/canvaskit/canvaskit/extra.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,9 @@ <h2> Support for extended color spaces </h2>
333333
}
334334

335335
const prog = `
336-
in shader before_map;
337-
in shader after_map;
338-
in shader threshold_map;
336+
uniform shader before_map;
337+
uniform shader after_map;
338+
uniform shader threshold_map;
339339
340340
uniform float cutoff;
341341
uniform float slope;
@@ -503,8 +503,8 @@ <h2> Support for extended color spaces </h2>
503503
const children = [textureShader, normalShader];
504504

505505
const prog = `
506-
in shader color_map;
507-
in shader normal_map;
506+
uniform shader color_map;
507+
uniform shader normal_map;
508508
509509
uniform float3 lightPos;
510510
layout (marker=local_to_world) uniform float4x4 localToWorld;

modules/canvaskit/tests/rtshader.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ half4 main(float2 p) {
7878
.then((response) => response.arrayBuffer());
7979

8080
const thresholdSkSL = `
81-
in shader before_map;
82-
in shader after_map;
83-
in shader threshold_map;
81+
uniform shader before_map;
82+
uniform shader after_map;
83+
uniform shader threshold_map;
8484
8585
uniform float cutoff;
8686
uniform float slope;

modules/skottie/src/effects/BlackAndWhiteEffect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace {
3434

3535
static sk_sp<SkRuntimeEffect> make_effect() {
3636
static constexpr char BLACK_AND_WHITE_EFFECT[] = R"(
37-
in shader input;
37+
uniform shader input;
3838
uniform half kR, kY, kG, kC, kB, kM;
3939
4040
half4 main() {

modules/skottie/src/effects/BrightnessContrastEffect.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ static constexpr char CONTRAST_EFFECT[] = R"(
7373
uniform half a;
7474
uniform half b;
7575
uniform half c;
76-
in shader input;
76+
uniform shader input;
7777
7878
half4 main() {
7979
// C' = a*C^3 + b*C^2 + c*C
@@ -97,7 +97,7 @@ static sk_sp<SkData> make_contrast_coeffs(float contrast) {
9797

9898
static constexpr char CONTRAST_EFFECT[] = R"(
9999
uniform half a;
100-
in shader input;
100+
uniform shader input;
101101
102102
half4 main() {
103103
half4 color = sample(input);
@@ -124,7 +124,7 @@ static sk_sp<SkData> make_brightness_coeffs(float brightness) {
124124

125125
static constexpr char BRIGHTNESS_EFFECT[] = R"(
126126
uniform half a;
127-
in shader input;
127+
uniform shader input;
128128
129129
half4 main() {
130130
half4 color = sample(input);

0 commit comments

Comments
 (0)