diff --git a/reference/shaders-reflection/asm/op-source-glsl-ssbo-1.asm.comp.json b/reference/shaders-reflection/asm/op-source-glsl-ssbo-1.asm.comp.json index 7325f5b6..3b0c9868 100644 --- a/reference/shaders-reflection/asm/op-source-glsl-ssbo-1.asm.comp.json +++ b/reference/shaders-reflection/asm/op-source-glsl-ssbo-1.asm.comp.json @@ -28,7 +28,8 @@ "array_size_is_literal" : [ true ], - "offset" : 0 + "offset" : 0, + "array_stride" : 16 } ] } diff --git a/reference/shaders-reflection/asm/op-source-glsl-ssbo-2.asm.comp.json b/reference/shaders-reflection/asm/op-source-glsl-ssbo-2.asm.comp.json index b5a53da9..80cf8622 100644 --- a/reference/shaders-reflection/asm/op-source-glsl-ssbo-2.asm.comp.json +++ b/reference/shaders-reflection/asm/op-source-glsl-ssbo-2.asm.comp.json @@ -28,7 +28,8 @@ "array_size_is_literal" : [ true ], - "offset" : 0 + "offset" : 0, + "array_stride" : 16 } ] }, @@ -44,7 +45,8 @@ "array_size_is_literal" : [ true ], - "offset" : 0 + "offset" : 0, + "array_stride" : 16 } ] } diff --git a/reference/shaders-reflection/asm/op-source-hlsl-uav-1.asm.comp.json b/reference/shaders-reflection/asm/op-source-hlsl-uav-1.asm.comp.json index 7c7510cf..19feacc4 100644 --- a/reference/shaders-reflection/asm/op-source-hlsl-uav-1.asm.comp.json +++ b/reference/shaders-reflection/asm/op-source-hlsl-uav-1.asm.comp.json @@ -28,7 +28,8 @@ "array_size_is_literal" : [ true ], - "offset" : 0 + "offset" : 0, + "array_stride" : 16 } ] } diff --git a/reference/shaders-reflection/asm/op-source-hlsl-uav-2.asm.comp.json b/reference/shaders-reflection/asm/op-source-hlsl-uav-2.asm.comp.json index ff4f9d4d..6d0b685c 100644 --- a/reference/shaders-reflection/asm/op-source-hlsl-uav-2.asm.comp.json +++ b/reference/shaders-reflection/asm/op-source-hlsl-uav-2.asm.comp.json @@ -28,7 +28,8 @@ "array_size_is_literal" : [ true ], - "offset" : 0 + "offset" : 0, + "array_stride" : 16 } ] } diff --git a/reference/shaders-reflection/asm/op-source-none-ssbo-1.asm.comp.json b/reference/shaders-reflection/asm/op-source-none-ssbo-1.asm.comp.json index 7325f5b6..3b0c9868 100644 --- a/reference/shaders-reflection/asm/op-source-none-ssbo-1.asm.comp.json +++ b/reference/shaders-reflection/asm/op-source-none-ssbo-1.asm.comp.json @@ -28,7 +28,8 @@ "array_size_is_literal" : [ true ], - "offset" : 0 + "offset" : 0, + "array_stride" : 16 } ] } diff --git a/reference/shaders-reflection/asm/op-source-none-ssbo-2.asm.comp.json b/reference/shaders-reflection/asm/op-source-none-ssbo-2.asm.comp.json index b5a53da9..80cf8622 100644 --- a/reference/shaders-reflection/asm/op-source-none-ssbo-2.asm.comp.json +++ b/reference/shaders-reflection/asm/op-source-none-ssbo-2.asm.comp.json @@ -28,7 +28,8 @@ "array_size_is_literal" : [ true ], - "offset" : 0 + "offset" : 0, + "array_stride" : 16 } ] }, @@ -44,7 +45,8 @@ "array_size_is_literal" : [ true ], - "offset" : 0 + "offset" : 0, + "array_stride" : 16 } ] } diff --git a/reference/shaders-reflection/asm/op-source-none-uav-1.asm.comp.json b/reference/shaders-reflection/asm/op-source-none-uav-1.asm.comp.json index 7c7510cf..19feacc4 100644 --- a/reference/shaders-reflection/asm/op-source-none-uav-1.asm.comp.json +++ b/reference/shaders-reflection/asm/op-source-none-uav-1.asm.comp.json @@ -28,7 +28,8 @@ "array_size_is_literal" : [ true ], - "offset" : 0 + "offset" : 0, + "array_stride" : 16 } ] } diff --git a/reference/shaders-reflection/asm/op-source-none-uav-2.asm.comp.json b/reference/shaders-reflection/asm/op-source-none-uav-2.asm.comp.json index ff4f9d4d..6d0b685c 100644 --- a/reference/shaders-reflection/asm/op-source-none-uav-2.asm.comp.json +++ b/reference/shaders-reflection/asm/op-source-none-uav-2.asm.comp.json @@ -28,7 +28,8 @@ "array_size_is_literal" : [ true ], - "offset" : 0 + "offset" : 0, + "array_stride" : 16 } ] } diff --git a/reference/shaders-reflection/comp/struct-layout.comp.json b/reference/shaders-reflection/comp/struct-layout.comp.json index 9f6bd0c9..e9bf7eea 100644 --- a/reference/shaders-reflection/comp/struct-layout.comp.json +++ b/reference/shaders-reflection/comp/struct-layout.comp.json @@ -22,7 +22,8 @@ { "name" : "m", "type" : "mat4", - "offset" : 0 + "offset" : 0, + "matrix_stride" : 16 } ] }, @@ -38,7 +39,8 @@ "array_size_is_literal" : [ true ], - "offset" : 0 + "offset" : 0, + "array_stride" : 64 } ] }, @@ -54,7 +56,8 @@ "array_size_is_literal" : [ true ], - "offset" : 0 + "offset" : 0, + "array_stride" : 64 } ] } diff --git a/reference/shaders-reflection/comp/struct-packing.comp.json b/reference/shaders-reflection/comp/struct-packing.comp.json index 92234c7e..12285ae2 100644 --- a/reference/shaders-reflection/comp/struct-packing.comp.json +++ b/reference/shaders-reflection/comp/struct-packing.comp.json @@ -28,7 +28,8 @@ "array_size_is_literal" : [ true ], - "offset" : 0 + "offset" : 0, + "array_stride" : 8 }, { "name" : "b", @@ -64,7 +65,8 @@ "array_size_is_literal" : [ true ], - "offset" : 0 + "offset" : 0, + "array_stride" : 16 }, { "name" : "b", @@ -110,7 +112,8 @@ "array_size_is_literal" : [ true ], - "offset" : 0 + "offset" : 0, + "array_stride" : 16 }, { "name" : "m1s", @@ -121,7 +124,8 @@ "array_size_is_literal" : [ true ], - "offset" : 16 + "offset" : 16, + "array_stride" : 16 }, { "name" : "m2s", @@ -132,7 +136,8 @@ "array_size_is_literal" : [ true ], - "offset" : 32 + "offset" : 32, + "array_stride" : 32 }, { "name" : "m0", @@ -168,7 +173,8 @@ "array_size_is_literal" : [ true ], - "offset" : 152 + "offset" : 152, + "array_stride" : 8 } ] }, @@ -189,7 +195,8 @@ "array_size_is_literal" : [ true ], - "offset" : 224 + "offset" : 224, + "array_stride" : 224 }, { "name" : "content2", @@ -199,12 +206,14 @@ { "name" : "m0", "type" : "mat2", - "offset" : 896 + "offset" : 896, + "matrix_stride" : 8 }, { "name" : "m1", "type" : "mat2", - "offset" : 912 + "offset" : 912, + "matrix_stride" : 8 }, { "name" : "m2", @@ -215,35 +224,40 @@ "array_size_is_literal" : [ true ], - "offset" : 928 + "offset" : 928, + "array_stride" : 32, + "matrix_stride" : 16 }, { "name" : "m3", "type" : "mat3x2", - "offset" : 1056 + "offset" : 1056, + "matrix_stride" : 8 }, { "name" : "m4", "type" : "mat2", - "row_major" : true, - "offset" : 1080 + "offset" : 1080, + "matrix_stride" : 8, + "row_major" : true }, { "name" : "m5", "type" : "mat2", - "row_major" : true, "array" : [ 9 ], "array_size_is_literal" : [ true ], - "offset" : 1096 + "offset" : 1096, + "array_stride" : 16, + "matrix_stride" : 8, + "row_major" : true }, { "name" : "m6", "type" : "mat2x3", - "row_major" : true, "array" : [ 2, 4 @@ -252,13 +266,17 @@ true, true ], - "offset" : 1240 + "offset" : 1240, + "array_stride" : 48, + "matrix_stride" : 8, + "row_major" : true }, { "name" : "m7", "type" : "mat3x2", - "row_major" : true, - "offset" : 1440 + "offset" : 1440, + "matrix_stride" : 16, + "row_major" : true }, { "name" : "array", @@ -269,7 +287,8 @@ "array_size_is_literal" : [ true ], - "offset" : 1472 + "offset" : 1472, + "array_stride" : 4 } ] }, @@ -285,7 +304,8 @@ "array_size_is_literal" : [ true ], - "offset" : 0 + "offset" : 0, + "array_stride" : 16 }, { "name" : "b", @@ -321,7 +341,8 @@ "array_size_is_literal" : [ true ], - "offset" : 0 + "offset" : 0, + "array_stride" : 16 }, { "name" : "b", @@ -367,7 +388,8 @@ "array_size_is_literal" : [ true ], - "offset" : 0 + "offset" : 0, + "array_stride" : 32 }, { "name" : "m1s", @@ -378,7 +400,8 @@ "array_size_is_literal" : [ true ], - "offset" : 32 + "offset" : 32, + "array_stride" : 16 }, { "name" : "m2s", @@ -389,7 +412,8 @@ "array_size_is_literal" : [ true ], - "offset" : 48 + "offset" : 48, + "array_stride" : 32 }, { "name" : "m0", @@ -425,7 +449,8 @@ "array_size_is_literal" : [ true ], - "offset" : 192 + "offset" : 192, + "array_stride" : 16 } ] }, @@ -446,7 +471,8 @@ "array_size_is_literal" : [ true ], - "offset" : 320 + "offset" : 320, + "array_stride" : 320 }, { "name" : "content2", @@ -456,12 +482,14 @@ { "name" : "m0", "type" : "mat2", - "offset" : 1280 + "offset" : 1280, + "matrix_stride" : 16 }, { "name" : "m1", "type" : "mat2", - "offset" : 1312 + "offset" : 1312, + "matrix_stride" : 16 }, { "name" : "m2", @@ -472,35 +500,40 @@ "array_size_is_literal" : [ true ], - "offset" : 1344 + "offset" : 1344, + "array_stride" : 32, + "matrix_stride" : 16 }, { "name" : "m3", "type" : "mat3x2", - "offset" : 1472 + "offset" : 1472, + "matrix_stride" : 16 }, { "name" : "m4", "type" : "mat2", - "row_major" : true, - "offset" : 1520 + "offset" : 1520, + "matrix_stride" : 16, + "row_major" : true }, { "name" : "m5", "type" : "mat2", - "row_major" : true, "array" : [ 9 ], "array_size_is_literal" : [ true ], - "offset" : 1552 + "offset" : 1552, + "array_stride" : 32, + "matrix_stride" : 16, + "row_major" : true }, { "name" : "m6", "type" : "mat2x3", - "row_major" : true, "array" : [ 2, 4 @@ -509,13 +542,17 @@ true, true ], - "offset" : 1840 + "offset" : 1840, + "array_stride" : 96, + "matrix_stride" : 16, + "row_major" : true }, { "name" : "m7", "type" : "mat3x2", - "row_major" : true, - "offset" : 2224 + "offset" : 2224, + "matrix_stride" : 16, + "row_major" : true }, { "name" : "array", @@ -526,7 +563,8 @@ "array_size_is_literal" : [ true ], - "offset" : 2256 + "offset" : 2256, + "array_stride" : 16 } ] } diff --git a/reference/shaders-reflection/vert/array-size-reflection.vert.json b/reference/shaders-reflection/vert/array-size-reflection.vert.json index c7b5cede..dc363226 100644 --- a/reference/shaders-reflection/vert/array-size-reflection.vert.json +++ b/reference/shaders-reflection/vert/array-size-reflection.vert.json @@ -51,7 +51,8 @@ "array_size_is_literal" : [ false ], - "offset" : 0 + "offset" : 0, + "array_stride" : 16 } ] } diff --git a/reference/shaders-reflection/vert/read-from-row-major-array.vert.json b/reference/shaders-reflection/vert/read-from-row-major-array.vert.json index 6ec6c90e..cebd66bd 100644 --- a/reference/shaders-reflection/vert/read-from-row-major-array.vert.json +++ b/reference/shaders-reflection/vert/read-from-row-major-array.vert.json @@ -25,7 +25,6 @@ { "name" : "var", "type" : "mat2x3", - "row_major" : true, "array" : [ 4, 3 @@ -34,7 +33,10 @@ true, true ], - "offset" : 0 + "offset" : 0, + "array_stride" : 192, + "matrix_stride" : 16, + "row_major" : true } ] } diff --git a/reference/shaders-reflection/vert/stride-reflection.vert.json b/reference/shaders-reflection/vert/stride-reflection.vert.json new file mode 100644 index 00000000..1dd8f189 --- /dev/null +++ b/reference/shaders-reflection/vert/stride-reflection.vert.json @@ -0,0 +1,96 @@ +{ + "entryPoints" : [ + { + "name" : "main", + "mode" : "vert" + } + ], + "types" : { + "_11" : { + "name" : "gl_PerVertex", + "members" : [ + { + "name" : "gl_Position", + "type" : "vec4" + }, + { + "name" : "gl_PointSize", + "type" : "float" + }, + { + "name" : "gl_ClipDistance", + "type" : "float", + "array" : [ + 1 + ], + "array_size_is_literal" : [ + true + ] + }, + { + "name" : "gl_CullDistance", + "type" : "float", + "array" : [ + 1 + ], + "array_size_is_literal" : [ + true + ] + } + ] + }, + "_21" : { + "name" : "U", + "members" : [ + { + "name" : "v", + "type" : "vec4", + "array" : [ + 4 + ], + "array_size_is_literal" : [ + true + ], + "offset" : 0, + "array_stride" : 16 + }, + { + "name" : "c", + "type" : "mat4", + "array" : [ + 4 + ], + "array_size_is_literal" : [ + true + ], + "offset" : 64, + "array_stride" : 64, + "matrix_stride" : 16 + }, + { + "name" : "r", + "type" : "mat4", + "array" : [ + 4 + ], + "array_size_is_literal" : [ + true + ], + "offset" : 320, + "array_stride" : 64, + "matrix_stride" : 16, + "row_major" : true + } + ] + } + }, + "ubos" : [ + { + "type" : "_21", + "name" : "U", + "block_size" : 576, + "set" : 0, + "binding" : 0 + } + ] +} \ No newline at end of file diff --git a/shaders-reflection/vert/stride-reflection.vert b/shaders-reflection/vert/stride-reflection.vert new file mode 100644 index 00000000..6e7d96df --- /dev/null +++ b/shaders-reflection/vert/stride-reflection.vert @@ -0,0 +1,14 @@ +#version 450 + +layout(binding = 0, set = 0, std140) uniform U +{ + vec4 v[4]; + mat4 c[4]; + layout(row_major) mat4 r[4]; +}; + +void main() +{ + gl_Position = v[0]; +} + diff --git a/spirv_reflect.cpp b/spirv_reflect.cpp index f9bf529a..c0bf1370 100644 --- a/spirv_reflect.cpp +++ b/spirv_reflect.cpp @@ -368,10 +368,6 @@ void CompilerReflection::emit_type_array(const SPIRType &type) void CompilerReflection::emit_type_member_qualifiers(const SPIRType &type, uint32_t index) { - auto flags = combined_decoration_for_member(type, index); - if (flags.get(DecorationRowMajor)) - json_stream->emit_json_key_value("row_major", true); - auto &membertype = get(type.member_types[index]); emit_type_array(membertype); auto &memb = ir.meta[type.self].members; @@ -382,6 +378,15 @@ void CompilerReflection::emit_type_member_qualifiers(const SPIRType &type, uint3 json_stream->emit_json_key_value("location", dec.location); if (dec.decoration_flags.get(DecorationOffset)) json_stream->emit_json_key_value("offset", dec.offset); + + // Array stride is a property of the array type, not the struct. + if (has_decoration(type.member_types[index], DecorationArrayStride)) + json_stream->emit_json_key_value("array_stride", get_decoration(type.member_types[index], DecorationArrayStride)); + + if (dec.decoration_flags.get(DecorationMatrixStride)) + json_stream->emit_json_key_value("matrix_stride", dec.matrix_stride); + if (dec.decoration_flags.get(DecorationRowMajor)) + json_stream->emit_json_key_value("row_major", true); } }