KhronosGroup / KhronosGroup/SPIRV-Reflect
Rows and Columns not reflecting properly
- Dominant language
- C
- Stars
- 871
- Forks
- 188
- Avg merge
- 19m
- Merged PRs (30d)
- 1
Description
I'm having a couple of issues with shader reflection for matrices at the moment.
1) A simple shader with a 3x4 or 4x3 matrix always comes out with the dimensions flipped around. Another example, a 1x4 matrix says it has 4 rows and 1 column, always.
2) Matrices are also not decorated with SPV_REFLECT_DECORATION_ROW_MAJOR or the COLUMN_MAJOR variant, the decoration flags are always 0.
3) I'm also not understanding the stride, but it might be consistent with the rows and columns being flipped. The 3x4 matrix has a stride of 64 whereas the 4x3 has a stride of 48 bytes, whereas I would expect the opposite.
The issues all probably come from the fact that this code doesn't seem to account for them. Would it be possible to confirm whether this is indeed a bug? Thanks!
```c
case SpvOpTypeMatrix: {
p_type->type_flags |= SPV_REFLECT_TYPE_FLAG_MATRIX;
uint32_t column_type_id = (uint32_t)INVALID_VALUE;
IF_READU32(result, p_parser, p_node->word_offset + 2, column_type_id);
IF_READU32(result, p_parser, p_node->word_offset + 3, p_type->traits.numeric.matrix.column_count);
SpvReflectPrvNode* p_next_node = FindNode(p_parser, column_type_id);
if (IsNotNull(p_next_node)) {
result = ParseType(p_parser, p_next_node, NULL, p_module, p_type);
}
else {
result = SPV_REFLECT_RESULT_ERROR_SPIRV_INVALID_ID_REFERENCE;
SPV_REFLECT_ASSERT(false);
}
p_type->traits.numeric.matrix.row_count = p_type->traits.numeric.vector.component_count;
p_type->traits.numeric.matrix.stride = p_node->decorations.matrix_stride;
// NOTE: Matrix stride is decorated using OpMemberDecoreate - not OpDecoreate.
if (IsNotNull(p_struct_member_decorations)) {
p_type->traits.numeric.matrix.stride = p_struct_member_decorations->matrix_stride;
}
}
break;
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the shown SpvOpTypeMatrix branch in ParseType and trace how vector component counts, matrix stride, and member decorations are read. Compare the reported 3x4, 4x3, and 1x4 results with the SPIR-V matrix metadata and verify the row-major or column-major flags. Done means dimensions, stride, and decoration flags accurately reflect the shader inputs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100