disallow varying matrices in shaders
Bug: skia:7869
Change-Id: I7440194ae9cbc3c9f2277172f718646b7214bc01
Reviewed-on: https://skia-review.googlesource.com/c/181903
Reviewed-by: Chris Dalton <csmartdalton@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
diff --git a/src/gpu/glsl/GrGLSLVarying.h b/src/gpu/glsl/GrGLSLVarying.h
index 0da88a0..73048e7 100644
--- a/src/gpu/glsl/GrGLSLVarying.h
+++ b/src/gpu/glsl/GrGLSLVarying.h
@@ -16,6 +16,22 @@
class GrGLSLProgramBuilder;
+#ifdef SK_DEBUG
+static bool is_matrix(GrSLType type) {
+ switch (type) {
+ case kFloat2x2_GrSLType:
+ case kFloat3x3_GrSLType:
+ case kFloat4x4_GrSLType:
+ case kHalf2x2_GrSLType:
+ case kHalf3x3_GrSLType:
+ case kHalf4x4_GrSLType:
+ return true;
+ default:
+ return false;
+ }
+}
+#endif
+
class GrGLSLVarying {
public:
enum class Scope {
@@ -25,9 +41,16 @@
};
GrGLSLVarying() = default;
- GrGLSLVarying(GrSLType type, Scope scope = Scope::kVertToFrag) : fType(type), fScope(scope) {}
+ GrGLSLVarying(GrSLType type, Scope scope = Scope::kVertToFrag)
+ : fType(type)
+ , fScope(scope) {
+ // Metal doesn't support varying matrices, so we disallow them everywhere for consistency
+ SkASSERT(!is_matrix(type));
+ }
void reset(GrSLType type, Scope scope = Scope::kVertToFrag) {
+ // Metal doesn't support varying matrices, so we disallow them everywhere for consistency
+ SkASSERT(!is_matrix(type));
*this = GrGLSLVarying();
fType = type;
fScope = scope;
diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp
index 6f9fcd9..f9d4098 100644
--- a/src/sksl/SkSLIRGenerator.cpp
+++ b/src/sksl/SkSLIRGenerator.cpp
@@ -257,6 +257,11 @@
if (!baseType) {
return nullptr;
}
+ if (fKind != Program::kFragmentProcessor_Kind &&
+ (decl.fModifiers.fFlags & Modifiers::kIn_Flag) &&
+ baseType->kind() == Type::Kind::kMatrix_Kind) {
+ fErrors.error(decl.fOffset, "'in' variables may not have matrix type");
+ }
for (const auto& varDecl : decl.fVars) {
if (decl.fModifiers.fLayout.fLocation == 0 && decl.fModifiers.fLayout.fIndex == 0 &&
(decl.fModifiers.fFlags & Modifiers::kOut_Flag) && fKind == Program::kFragment_Kind &&