Преглед изворни кода

[spirv] Add MatrixStride for SB<floatMxN> cases. (#1997)

Ehsan пре 6 година
родитељ
комит
0b6973cc4d

+ 10 - 6
tools/clang/lib/SPIRV/LowerTypeVisitor.cpp

@@ -529,15 +529,19 @@ const SpirvType *LowerTypeVisitor::lowerResourceType(QualType type,
     const auto *raType = spvContext.getRuntimeArrayType(structType, size);
     const bool isReadOnly = (name == "StructuredBuffer");
 
-    // Attach majorness decoration if this is a *StructuredBuffer<matrix>.
-    llvm::Optional<bool> isRowMajor =
-        isMxNMatrix(s) ? llvm::Optional<bool>(isRowMajorMatrix(spvOptions, s))
-                       : llvm::None;
+    // Attach majorness and stride decorations if this is a
+    // *StructuredBuffer<matrix>.
+    llvm::Optional<bool> isRowMajor = llvm::None;
+    llvm::Optional<uint32_t> matrixStride = llvm::None;
+    if (isMxNMatrix(s)) {
+      isRowMajor = isRowMajorMatrix(spvOptions, s);
+      matrixStride = stride;
+    }
 
     const std::string typeName = "type." + name.str() + "." + structName;
     const auto *valType = spvContext.getStructType(
-        {StructType::FieldInfo(raType, /*name*/ "", /*offset*/ 0,
-                               /*matrixStride*/ llvm::None, isRowMajor)},
+        {StructType::FieldInfo(raType, /*name*/ "", /*offset*/ 0, matrixStride,
+                               isRowMajor)},
         typeName, isReadOnly, StructInterfaceType::StorageBuffer);
 
     if (asAlias) {

+ 4 - 0
tools/clang/test/CodeGenSPIRV/type.matrix.majorness.zpc.hlsl

@@ -1,15 +1,19 @@
 // Run: %dxc -T ps_6_0 -E main -Zpc
 
 // CHECK: OpDecorate %_runtimearr_mat2v3float ArrayStride 24
+// CHECK: OpMemberDecorate %type_StructuredBuffer_mat2v3float 0 MatrixStride 8
 // CHECK: OpMemberDecorate %type_StructuredBuffer_mat2v3float 0 RowMajor
        StructuredBuffer<float2x3> ROSB1;
 // CHECK: OpDecorate %_runtimearr_mat3v2float ArrayStride 32
+// CHECK: OpMemberDecorate %type_RWStructuredBuffer_mat3v2float 0 MatrixStride 16
 // CHECK: OpMemberDecorate %type_RWStructuredBuffer_mat3v2float 0 RowMajor
      RWStructuredBuffer<float3x2> RWSB1;
 // CHECK: OpDecorate %_runtimearr_mat4v3float ArrayStride 48
+// CHECK: OpMemberDecorate %type_AppendStructuredBuffer_mat4v3float 0 MatrixStride 16
 // CHECK: OpMemberDecorate %type_AppendStructuredBuffer_mat4v3float 0 RowMajor
  AppendStructuredBuffer<float4x3> ASB1;
 // CHECK: OpDecorate %_runtimearr_mat3v4float ArrayStride 64
+// CHECK: OpMemberDecorate %type_ConsumeStructuredBuffer_mat3v4float 0 MatrixStride 16
 // CHECK: OpMemberDecorate %type_ConsumeStructuredBuffer_mat3v4float 0 RowMajor
 ConsumeStructuredBuffer<float3x4> CSB1;