Add GLSL type aliases for SkRuntimeEffect SkSL
Adds vec[N], mat[N], and mat[NxM] aliases when building runtime effect
code. Also moves the "shader" alias for fragmentProcessor so it's only
usable in that context.
Bug: skia:10679
Change-Id: Ia337bb680c50da32639bb1d4ffc3bc01df306b0f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/325620
Auto-Submit: Brian Osman <brianosman@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/sksl/SkSLCompiler.cpp b/src/sksl/SkSLCompiler.cpp
index 9c5bd33..8a473ee 100644
--- a/src/sksl/SkSLCompiler.cpp
+++ b/src/sksl/SkSLCompiler.cpp
@@ -211,9 +211,6 @@
ADD_TYPE(Sampler);
ADD_TYPE(Texture2D);
- StringFragment fpAliasName("shader");
- fRootSymbolTable->addAlias(fpAliasName, fContext->fFragmentProcessor_Type.get());
-
// sk_Caps is "builtin", but all references to it are resolved to Settings, so we don't need to
// treat it as builtin (ie, no need to clone it into the Program).
StringFragment skCapsName("sk_Caps");
@@ -252,6 +249,33 @@
if (!fPipelineModule.fSymbols) {
fPipelineModule =
this->parseModule(Program::kPipelineStage_Kind, MODULE_DATA(pipeline), fGPUModule);
+
+ // Add some aliases to the pipeline module so that it's friendlier, and more like GLSL
+ fPipelineModule.fSymbols->addAlias("shader", fContext->fFragmentProcessor_Type.get());
+
+ fPipelineModule.fSymbols->addAlias("vec2", fContext->fFloat2_Type.get());
+ fPipelineModule.fSymbols->addAlias("vec3", fContext->fFloat3_Type.get());
+ fPipelineModule.fSymbols->addAlias("vec4", fContext->fFloat4_Type.get());
+
+ fPipelineModule.fSymbols->addAlias("bvec2", fContext->fBool2_Type.get());
+ fPipelineModule.fSymbols->addAlias("bvec3", fContext->fBool3_Type.get());
+ fPipelineModule.fSymbols->addAlias("bvec4", fContext->fBool4_Type.get());
+
+ fPipelineModule.fSymbols->addAlias("mat2", fContext->fFloat2x2_Type.get());
+ fPipelineModule.fSymbols->addAlias("mat3", fContext->fFloat3x3_Type.get());
+ fPipelineModule.fSymbols->addAlias("mat4", fContext->fFloat4x4_Type.get());
+
+ fPipelineModule.fSymbols->addAlias("mat2x2", fContext->fFloat2x2_Type.get());
+ fPipelineModule.fSymbols->addAlias("mat2x3", fContext->fFloat2x3_Type.get());
+ fPipelineModule.fSymbols->addAlias("mat2x4", fContext->fFloat2x4_Type.get());
+
+ fPipelineModule.fSymbols->addAlias("mat3x2", fContext->fFloat3x2_Type.get());
+ fPipelineModule.fSymbols->addAlias("mat3x3", fContext->fFloat3x3_Type.get());
+ fPipelineModule.fSymbols->addAlias("mat3x4", fContext->fFloat3x4_Type.get());
+
+ fPipelineModule.fSymbols->addAlias("mat4x2", fContext->fFloat4x2_Type.get());
+ fPipelineModule.fSymbols->addAlias("mat4x3", fContext->fFloat4x3_Type.get());
+ fPipelineModule.fSymbols->addAlias("mat4x4", fContext->fFloat4x4_Type.get());
}
return fPipelineModule;
}
diff --git a/tests/SkRuntimeEffectTest.cpp b/tests/SkRuntimeEffectTest.cpp
index 4d788cc..ed04972 100644
--- a/tests/SkRuntimeEffectTest.cpp
+++ b/tests/SkRuntimeEffectTest.cpp
@@ -223,6 +223,10 @@
effect.build("", "return float4(p - 0.5, 0, 1);");
effect.test(0xFF000000, 0xFF0000FF, 0xFF00FF00, 0xFF00FFFF);
+ // ... and support GLSL type names
+ effect.build("", "return vec4(p - 0.5, 0, 1);");
+ effect.test(0xFF000000, 0xFF0000FF, 0xFF00FF00, 0xFF00FFFF);
+
//
// Sampling children
//