Skip to content

Commit c021360

Browse files
brianosmanSkia Commit-Bot
authored andcommitted
Only include one variable per declaration statement
This removes VarDeclarationsStatement entirely. VarDeclaration instances appear directly as statements in Programs. SkSL that declares multiple variables in a single declaration is transformed to represent that as a series of VarDeclaration statements. Similarly, global variable declarations are represented by GlobalVarDeclaration program elements, one per variable. Bug: skia:10806 Change-Id: Idd8a2d971a8217733ed57f0dd2249d62f2f0e9c5 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/323102 Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: John Stiles <johnstiles@google.com>
1 parent f41762a commit c021360

File tree

134 files changed

+1229
-1418
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+1229
-1418
lines changed

gn/sksl.gni

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ skia_sksl_sources = [
106106
"$_src/sksl/ir/SkSLTypeReference.h",
107107
"$_src/sksl/ir/SkSLUnresolvedFunction.h",
108108
"$_src/sksl/ir/SkSLVarDeclarations.h",
109-
"$_src/sksl/ir/SkSLVarDeclarationsStatement.h",
110109
"$_src/sksl/ir/SkSLVariable.h",
111110
"$_src/sksl/ir/SkSLVariableReference.cpp",
112111
"$_src/sksl/ir/SkSLVariableReference.h",

src/core/SkRuntimeEffect.cpp

Lines changed: 50 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -153,68 +153,66 @@ SkRuntimeEffect::EffectResult SkRuntimeEffect::Make(SkString sksl) {
153153
// Go through program elements, pulling out information that we need
154154
for (const auto& elem : *program) {
155155
// Variables (uniform, varying, etc.)
156-
if (elem.kind() == SkSL::ProgramElement::Kind::kVar) {
157-
const auto& varDecls = static_cast<const SkSL::VarDeclarations&>(elem);
158-
for (const auto& varDecl : varDecls.fVars) {
159-
const SkSL::Variable& var =
160-
*(static_cast<const SkSL::VarDeclaration&>(*varDecl).fVar);
161-
const SkSL::Type& varType = var.type();
162-
163-
// Varyings (only used in conjunction with drawVertices)
164-
if (var.fModifiers.fFlags & SkSL::Modifiers::kVarying_Flag) {
165-
varyings.push_back({var.name(),
166-
varType.typeKind() == SkSL::Type::TypeKind::kVector
167-
? varType.columns()
168-
: 1});
169-
}
170-
// Fragment Processors (aka 'shader'): These are child effects
171-
else if (&varType == ctx.fFragmentProcessor_Type.get()) {
172-
children.push_back(var.name());
173-
sampleUsages.push_back(SkSL::Analysis::GetSampleUsage(*program, var));
156+
if (elem.is<SkSL::GlobalVarDeclaration>()) {
157+
const auto& varDecl = elem.as<SkSL::GlobalVarDeclaration>().fDecl;
158+
159+
const SkSL::Variable& var = *varDecl->fVar;
160+
const SkSL::Type& varType = var.type();
161+
162+
// Varyings (only used in conjunction with drawVertices)
163+
if (var.fModifiers.fFlags & SkSL::Modifiers::kVarying_Flag) {
164+
varyings.push_back({var.name(),
165+
varType.typeKind() == SkSL::Type::TypeKind::kVector
166+
? varType.columns()
167+
: 1});
168+
}
169+
// Fragment Processors (aka 'shader'): These are child effects
170+
else if (&varType == ctx.fFragmentProcessor_Type.get()) {
171+
children.push_back(var.name());
172+
sampleUsages.push_back(SkSL::Analysis::GetSampleUsage(*program, var));
173+
}
174+
// 'uniform' variables
175+
else if (var.fModifiers.fFlags & SkSL::Modifiers::kUniform_Flag) {
176+
Uniform uni;
177+
uni.fName = var.name();
178+
uni.fFlags = 0;
179+
uni.fCount = 1;
180+
181+
const SkSL::Type* type = &var.type();
182+
if (type->typeKind() == SkSL::Type::TypeKind::kArray) {
183+
uni.fFlags |= Uniform::kArray_Flag;
184+
uni.fCount = type->columns();
185+
type = &type->componentType();
174186
}
175-
// 'uniform' variables
176-
else if (var.fModifiers.fFlags & SkSL::Modifiers::kUniform_Flag) {
177-
Uniform uni;
178-
uni.fName = var.name();
179-
uni.fFlags = 0;
180-
uni.fCount = 1;
181-
182-
const SkSL::Type* type = &var.type();
183-
if (type->typeKind() == SkSL::Type::TypeKind::kArray) {
184-
uni.fFlags |= Uniform::kArray_Flag;
185-
uni.fCount = type->columns();
186-
type = &type->componentType();
187-
}
188187

189-
if (!init_uniform_type(ctx, type, &uni)) {
190-
RETURN_FAILURE("Invalid uniform type: '%s'", type->displayName().c_str());
191-
}
188+
if (!init_uniform_type(ctx, type, &uni)) {
189+
RETURN_FAILURE("Invalid uniform type: '%s'", type->displayName().c_str());
190+
}
192191

193-
const SkSL::StringFragment& marker(var.fModifiers.fLayout.fMarker);
194-
if (marker.fLength) {
195-
uni.fFlags |= Uniform::kMarker_Flag;
196-
allowColorFilter = false;
197-
if (!parse_marker(marker, &uni.fMarker, &uni.fFlags)) {
198-
RETURN_FAILURE("Invalid 'marker' string: '%.*s'", (int)marker.fLength,
199-
marker.fChars);
200-
}
192+
const SkSL::StringFragment& marker(var.fModifiers.fLayout.fMarker);
193+
if (marker.fLength) {
194+
uni.fFlags |= Uniform::kMarker_Flag;
195+
allowColorFilter = false;
196+
if (!parse_marker(marker, &uni.fMarker, &uni.fFlags)) {
197+
RETURN_FAILURE("Invalid 'marker' string: '%.*s'", (int)marker.fLength,
198+
marker.fChars);
201199
}
200+
}
202201

203-
if (var.fModifiers.fLayout.fFlags & SkSL::Layout::Flag::kSRGBUnpremul_Flag) {
204-
uni.fFlags |= Uniform::kSRGBUnpremul_Flag;
205-
}
202+
if (var.fModifiers.fLayout.fFlags & SkSL::Layout::Flag::kSRGBUnpremul_Flag) {
203+
uni.fFlags |= Uniform::kSRGBUnpremul_Flag;
204+
}
206205

207-
uni.fOffset = offset;
208-
offset += uni.sizeInBytes();
209-
SkASSERT(SkIsAlign4(offset));
206+
uni.fOffset = offset;
207+
offset += uni.sizeInBytes();
208+
SkASSERT(SkIsAlign4(offset));
210209

211-
uniforms.push_back(uni);
212-
}
210+
uniforms.push_back(uni);
213211
}
214212
}
215213
// Functions
216-
else if (elem.kind() == SkSL::ProgramElement::Kind::kFunction) {
217-
const auto& func = static_cast<const SkSL::FunctionDefinition&>(elem);
214+
else if (elem.is<SkSL::FunctionDefinition>()) {
215+
const auto& func = elem.as<SkSL::FunctionDefinition>();
218216
const SkSL::FunctionDeclaration& decl = func.fDeclaration;
219217
if (decl.name() == "main") {
220218
hasMain = true;

src/gpu/effects/generated/GrAARectEffect.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ half alpha;
4040
alpha = half(all(greaterThan(float4(sk_FragCoord.xy, %s.zw), float4(%s.xy, sk_FragCoord.xy))) ? 1 : 0);
4141
break;
4242
default:
43-
half xSub, ySub;
43+
half xSub;
44+
half ySub;
45+
4446
xSub = min(half(sk_FragCoord.x - %s.x), 0.0);
4547
xSub += min(half(%s.z - sk_FragCoord.x), 0.0);
4648
ySub = min(half(sk_FragCoord.y - %s.y), 0.0);

src/gpu/effects/generated/GrHighContrastFilterEffect.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ if (t > 1.0) t -= 1.0;
4848
return t < 0.1666666716337204 ? p + ((q - p) * 6.0) * t : (t < 0.5 ? q : (t < 0.66666668653488159 ? p + ((q - p) * (0.66666668653488159 - t)) * 6.0 : p));
4949
)SkSL",
5050
&HSLToRGB_name);
51+
fragBuilder->codeAppendf(
52+
R"SkSL(;)SkSL");
5153
SkString _sample896 = this->invokeChild(0, args);
5254
fragBuilder->codeAppendf(
5355
R"SkSL(

src/gpu/effects/generated/GrLumaColorFilterEffect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class GrGLSLLumaColorFilterEffect : public GrGLSLFragmentProcessor {
2727
SkString _sample870 = this->invokeChild(0, args);
2828
fragBuilder->codeAppendf(
2929
R"SkSL(half4 inputColor = %s;
30-
30+
;
3131
half luma = clamp(dot(half3(0.2125999927520752, 0.71520000696182251, 0.072200000286102295), inputColor.xyz), 0.0, 1.0);
3232
%s = half4(0.0, 0.0, 0.0, luma);
3333
)SkSL",

src/gpu/effects/generated/GrRGBToHSLFilterEffect.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class GrGLSLRGBToHSLFilterEffect : public GrGLSLFragmentProcessor {
2929
R"SkSL(half4 c = %s;
3030
half4 p = c.y < c.z ? half4(c.zy, -1.0, 0.66666668653488159) : half4(c.yz, 0.0, -0.3333333432674408);
3131
half4 q = c.x < p.x ? half4(p.x, c.x, p.yw) : half4(c.x, p.x, p.yz);
32-
32+
;
3333
half pmV = q.x;
3434
half pmC = pmV - min(q.y, q.z);
3535
half pmL = pmV - pmC * 0.5;

src/gpu/effects/generated/GrRectBlurEffect.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ class GrGLSLRectBlurEffect : public GrGLSLFragmentProcessor {
4949
}
5050
fragBuilder->codeAppendf(
5151
R"SkSL(/* key */ bool highp = %s;
52-
half xCoverage, yCoverage;
52+
half xCoverage;
53+
half yCoverage;
54+
5355
float2 pos = sk_FragCoord.xy;
5456
@if (%s) {
5557
pos = (%s * float3(pos, 1.0)).xy;

src/gpu/gradients/generated/GrDualIntervalGradientColorizer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ class GrGLSLDualIntervalGradientColorizer : public GrGLSLFragmentProcessor {
4747
kHalf_GrSLType, "threshold");
4848
fragBuilder->codeAppendf(
4949
R"SkSL(half t = half(%s.x);
50-
float4 scale, bias;
50+
float4 scale;
51+
float4 bias;
52+
5153
if (t < %s) {
5254
scale = %s;
5355
bias = %s;

src/gpu/gradients/generated/GrUnrolledBinaryGradientColorizer.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ class GrGLSLUnrolledBinaryGradientColorizer : public GrGLSLFragmentProcessor {
129129
kHalf4_GrSLType, "thresholds9_13");
130130
fragBuilder->codeAppendf(
131131
R"SkSL(half t = half(%s.x);
132-
float4 scale, bias;
132+
float4 scale;
133+
float4 bias;
134+
133135
if (%d <= 4 || t < %s.w) {
134136
if (%d <= 2 || t < %s.y) {
135137
if (%d <= 1 || t < %s.x) {

src/sksl/SkSLAnalysis.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#include "src/sksl/ir/SkSLNop.h"
3636
#include "src/sksl/ir/SkSLReturnStatement.h"
3737
#include "src/sksl/ir/SkSLSwitchStatement.h"
38-
#include "src/sksl/ir/SkSLVarDeclarationsStatement.h"
3938
#include "src/sksl/ir/SkSLWhileStatement.h"
4039

4140
// Expressions
@@ -486,10 +485,6 @@ bool TProgramVisitor<PROG, EXPR, STMT, ELEM>::visitStatement(STMT s) {
486485
}
487486
return v.fValue && this->visitExpression(*v.fValue);
488487
}
489-
case Statement::Kind::kVarDeclarations:
490-
return this->visitProgramElement(
491-
*s.template as<VarDeclarationsStatement>().fDeclaration);
492-
493488
case Statement::Kind::kWhile: {
494489
auto& w = s.template as<WhileStatement>();
495490
return this->visitExpression(*w.fTest) || this->visitStatement(*w.fStatement);
@@ -520,11 +515,9 @@ bool TProgramVisitor<PROG, EXPR, STMT, ELEM>::visitProgramElement(ELEM pe) {
520515
}
521516
return false;
522517

523-
case ProgramElement::Kind::kVar:
524-
for (auto& v : pe.template as<VarDeclarations>().fVars) {
525-
if (this->visitStatement(*v)) {
526-
return true;
527-
}
518+
case ProgramElement::Kind::kGlobalVar:
519+
if (this->visitStatement(*pe.template as<GlobalVarDeclaration>().fDecl)) {
520+
return true;
528521
}
529522
return false;
530523

0 commit comments

Comments
 (0)