2
0
Эх сурвалжийг харах

[spirv] Accept array types for PS stage input variables (#1044)

We need to check the element types of PS input variables to
properly apply interpolation decorations. Previously the method
used to query element type does not support array types, which
caused an assertion eventually.
Lei Zhang 7 жил өмнө
parent
commit
88b02078a1

+ 7 - 2
tools/clang/lib/SPIRV/TypeTranslator.cpp

@@ -840,8 +840,13 @@ bool TypeTranslator::isSameType(QualType type1, QualType type2) {
 
 QualType TypeTranslator::getElementType(QualType type) {
   QualType elemType = {};
-  (void)(isScalarType(type, &elemType) || isVectorType(type, &elemType) ||
-         isMxNMatrix(type, &elemType));
+  if (isScalarType(type, &elemType) || isVectorType(type, &elemType) ||
+      isMxNMatrix(type, &elemType)) {
+  } else if (const auto *arrType = astContext.getAsConstantArrayType(type)) {
+    elemType = arrType->getElementType();
+  } else {
+    assert(false && "unhandled type");
+  }
   return elemType;
 }
 

+ 2 - 2
tools/clang/lib/SPIRV/TypeTranslator.h

@@ -201,8 +201,8 @@ public:
   /// \brief Returns a string name for the given type.
   static std::string getName(QualType type);
 
-  /// \brief Returns the the element type for the given scalar/vector/matrix
-  /// type. Returns empty QualType for other cases.
+  /// \brief Returns the the element type for the given scalar, vector, matrix,
+  /// or array type. Returns empty QualType for other cases.
   QualType getElementType(QualType type);
 
   /// \brief Generates the corresponding SPIR-V vector type for the given Clang

+ 3 - 0
tools/clang/test/CodeGenSPIRV/spirv.interpolation.hlsl

@@ -32,6 +32,9 @@ struct PSInput {
                        bool  bool_a: BOOLA;
 // CHECK: OpDecorate %in_var_BOOLD Flat
   nointerpolation      bool3 bool_d: BOOLD;
+
+// CHECK: OpDecorate %in_var_FPH Flat
+  nointerpolation      float4 fp_h[1]: FPH;
 };
 
 float4 main(                     PSInput input,