SPV: Distinguish between std140 and std430 layouts, and correctly use alignments...
authorJohn Kessenich <cepheus@frii.com>
Mon, 7 Dec 2015 02:17:49 +0000 (19:17 -0700)
committerJohn Kessenich <cepheus@frii.com>
Mon, 7 Dec 2015 02:17:49 +0000 (19:17 -0700)
SPIRV/GlslangToSpv.cpp
Test/baseResults/spv.140.frag.out
glslang/Include/revision.h

index 3528c82..41b6c5d 100755 (executable)
@@ -1630,10 +1630,18 @@ bool TGlslangToSpvTraverser::requiresExplicitLayout(const glslang::TType& type)
 // Given an array type, returns the integer stride required for that array
 int TGlslangToSpvTraverser::getArrayStride(const glslang::TType& arrayType)
 {
-    glslang::TType derefType(arrayType, 0);
     int size;
-    glslangIntermediate->getBaseAlignment(derefType, size, true);
-    return size;
+    int stride = glslangIntermediate->getBaseAlignment(arrayType, size, arrayType.getQualifier().layoutPacking == glslang::ElpStd140);
+    if (arrayType.isMatrix()) {
+        // GLSL strides are set to alignments of the matrix flattened to individual rows/cols,
+        // but SPV needs an array stride for the whole matrix, not the rows/cols
+        if (arrayType.getQualifier().layoutMatrix == glslang::ElmRowMajor)
+            stride *= arrayType.getMatrixRows();
+        else
+            stride *= arrayType.getMatrixCols();
+    }
+
+    return stride;
 }
 
 // Given a matrix type, returns the integer stride required for that matrix
@@ -1641,7 +1649,7 @@ int TGlslangToSpvTraverser::getArrayStride(const glslang::TType& arrayType)
 int TGlslangToSpvTraverser::getMatrixStride(const glslang::TType& matrixType)
 {
     int size;
-    return glslangIntermediate->getBaseAlignment(matrixType, size, true);
+    return glslangIntermediate->getBaseAlignment(matrixType, size, matrixType.getQualifier().layoutPacking == glslang::ElpStd140);
 }
 
 // Given a member type of a struct, realign the current offset for it, and compute
index 0477bc2..9f9891c 100755 (executable)
@@ -54,7 +54,7 @@ Linked fragment stage:
                               MemberDecorate 88(bn) 4 Offset 640\r
                               MemberDecorate 88(bn) 4 MatrixStride 16\r
                               Decorate 88(bn) Block\r
-                              Decorate 92 ArrayStride 12\r
+                              Decorate 92 ArrayStride 16\r
                               MemberDecorate 93(bi) 0 Offset 0\r
                               Decorate 93(bi) Block\r
                2:             TypeVoid\r
index 2b62b6d..647ba85 100644 (file)
@@ -2,5 +2,5 @@
 // For the version, it uses the latest git tag followed by the number of commits.
 // For the date, it uses the current date (when then script is run).
 
-#define GLSLANG_REVISION "SPIRV99.821"
+#define GLSLANG_REVISION "SPIRV99.822"
 #define GLSLANG_DATE "06-Dec-2015"