Report an error when samplers in Metal don't have layout data.
Previously, attempting to compile SkSL with samplers that lacked a
layout(binding=...) annotation would generate MSL code containing
[[texture(-1)]] and [[sampler(-1)]], without reporting any errors.
This error mirrors existing messages in `MetalCodeGenerator::
writeUniformStruct` that report missing layout data.
Change-Id: Ib8c4005912301e3cbe6c639d0555ce842803f394
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/300636
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/src/sksl/SkSLMetalCodeGenerator.cpp b/src/sksl/SkSLMetalCodeGenerator.cpp
index 21fb47f..e518a13 100644
--- a/src/sksl/SkSLMetalCodeGenerator.cpp
+++ b/src/sksl/SkSLMetalCodeGenerator.cpp
@@ -892,6 +892,10 @@
for (const auto& stmt: decls.fVars) {
VarDeclaration& var = (VarDeclaration&) *stmt;
if (var.fVar->fType.kind() == Type::kSampler_Kind) {
+ if (var.fVar->fModifiers.fLayout.fBinding < 0) {
+ fErrors.error(decls.fOffset,
+ "Metal samplers must have 'layout(binding=...)'");
+ }
this->write(", texture2d<float> "); // FIXME - support other texture types
this->writeName(var.fVar->fName);
this->write("[[texture(");