Avoid mix-up between MAIN_COORDS and FRAGCOORD.
When compiling test shaders, we were setting SK_FRAGCOORD_BUILTIN on the
`coords` parameter to main() instead of SK_MAIN_COORDS_BUILTIN. These
two built-ins don't have the same type (float2 vs. float4) and don't
mean quite the same thing.
The SPIR-V code generator saw a variable with the SK_FRAGCOORD_BUILTIN
builtin value and assumed the presence of a global variable named
`sk_FragCoord`, which didn't exist (because it was never referenced in
the code, so it was never cloned in from the sksl_frag module).
This is only a concern when compiling test shaders with skslc; real
shaders don't hit these code paths. The generated code here is still
imperfect; if you look closely, you'll see the GLSL and Metal code is
referencing the `coords` variable but it's never declared anywhere.
Change-Id: I3ad249469927ff35eb1e75d6536f95317502708f
Bug: skia:12340
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/440520
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/src/sksl/ir/SkSLFunctionDeclaration.cpp b/src/sksl/ir/SkSLFunctionDeclaration.cpp
index 7892947..d5a447c 100644
--- a/src/sksl/ir/SkSLFunctionDeclaration.cpp
+++ b/src/sksl/ir/SkSLFunctionDeclaration.cpp
@@ -108,9 +108,9 @@
} else if (context.fConfig->fKind == ProgramKind::kFragment) {
// For testing purposes, we have .sksl inputs that are treated as both runtime
// effects and fragment shaders. To make that work, fragment shaders are allowed to
- // have a coords parameter. We turn it into sk_FragCoord.
+ // have a coords parameter.
if (type == *context.fTypes.fFloat2) {
- m.fLayout.fBuiltin = SK_FRAGCOORD_BUILTIN;
+ m.fLayout.fBuiltin = SK_MAIN_COORDS_BUILTIN;
param->setModifiers(context.fModifiersPool->add(m));
}
}
@@ -133,9 +133,7 @@
const Variable& p = *parameters[idx];
return p.type() == *context.fTypes.fFloat2 &&
p.modifiers().fFlags == 0 &&
- p.modifiers().fLayout.fBuiltin == (kind == ProgramKind::kFragment
- ? SK_FRAGCOORD_BUILTIN
- : SK_MAIN_COORDS_BUILTIN);
+ p.modifiers().fLayout.fBuiltin == SK_MAIN_COORDS_BUILTIN;
};
auto paramIsBuiltinColor = [&](int idx, int builtinID) {