Reflection: Add array stride/matrix stride reflection.

This commit is contained in:
Hans-Kristian Arntzen 2020-01-15 17:01:35 +01:00
parent 18e24c3ca2
commit 762c87a7bb
15 changed files with 229 additions and 60 deletions

View File

@ -28,7 +28,8 @@
"array_size_is_literal" : [
true
],
"offset" : 0
"offset" : 0,
"array_stride" : 16
}
]
}

View File

@ -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
}
]
}

View File

@ -28,7 +28,8 @@
"array_size_is_literal" : [
true
],
"offset" : 0
"offset" : 0,
"array_stride" : 16
}
]
}

View File

@ -28,7 +28,8 @@
"array_size_is_literal" : [
true
],
"offset" : 0
"offset" : 0,
"array_stride" : 16
}
]
}

View File

@ -28,7 +28,8 @@
"array_size_is_literal" : [
true
],
"offset" : 0
"offset" : 0,
"array_stride" : 16
}
]
}

View File

@ -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
}
]
}

View File

@ -28,7 +28,8 @@
"array_size_is_literal" : [
true
],
"offset" : 0
"offset" : 0,
"array_stride" : 16
}
]
}

View File

@ -28,7 +28,8 @@
"array_size_is_literal" : [
true
],
"offset" : 0
"offset" : 0,
"array_stride" : 16
}
]
}

View File

@ -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
}
]
}

View File

@ -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
}
]
}

View File

@ -51,7 +51,8 @@
"array_size_is_literal" : [
false
],
"offset" : 0
"offset" : 0,
"array_stride" : 16
}
]
}

View File

@ -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
}
]
}

View File

@ -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
}
]
}

View File

@ -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];
}

View File

@ -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<SPIRType>(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);
}
}