cea8d9653b77 — Leonard Ritter 10 days ago
* SPIR-V: fixed wrong decorations for matrix types in structs
2 files changed, 32 insertions(+), 5 deletions(-)

M src/gen_spirv.cpp
M testing/test_glsl.sc
M src/gen_spirv.cpp +13 -5
@@ 468,7 468,9 @@ struct SPIRVGenerator {
         } */
         for (size_t i = 0; i < count; ++i) {
             Symbol key = SYM_Unnamed;
-            auto kq = try_qualifier<KeyQualifier>(ti->values[i]);
+            auto T = ti->values[i];
+            auto kq = try_qualifier<KeyQualifier>(T);
+            auto ST = storage_type(strip_qualifiers(T)).assert_ok();
             if (kq) {
                 key = kq->key;
             }

          
@@ 492,6 494,16 @@ struct SPIRVGenerator {
                 builder.addMemberDecoration(id, i, spv::DecorationFlat);
             } */
             builder.addMemberDecoration(id, i, spv::DecorationOffset, ti->offsets[i]);
+            switch (ST->kind()) {
+            case TK_Matrix: {
+                auto mi = cast<MatrixType>(ST);
+                builder.addMemberDecoration(id, i,
+                    spv::DecorationMatrixStride,
+                    SCOPES_GET_RESULT(size_of(mi->element_type)));
+                builder.addMemberDecoration(id, i, spv::DecorationColMajor);
+            } break;
+            default: break;
+            }
         }
         return id;
     }

          
@@ 549,10 561,6 @@ struct SPIRVGenerator {
             auto etype = SCOPES_GET_RESULT(type_to_spirv_type(mi->element_type));
 
             spv::Id ty = builder.makeMatrixType(etype, mi->count());
-            builder.addDecoration(ty,
-                spv::DecorationMatrixStride,
-                SCOPES_GET_RESULT(size_of(mi->element_type)));
-            builder.addDecoration(ty, spv::DecorationColMajor);
             return ty;
         } break;
         case TK_Vector: {

          
M testing/test_glsl.sc +19 -0
@@ 111,4 111,23 @@ print
 
         (compile-glsl 330 'vertex (typify main))
 
+do
+    using import struct
+    using import glm
+    using import glsl
+
+    struct Uniforms plain
+        mvp : mat4
+
+    fn vert ()
+        uniform u : Uniforms
+            binding = 0
+        gl_Position = (u.mvp * (vec4))
+        ;
+
+    print
+        compile-glsl 440 'vertex (static-typify vert)
+            #'dump-disassembly
+        #compile-spirv 'vertex (static-typify vert)
+            'dump-disassembly
 ;