KhronosGroup / KhronosGroup/glslang
glslang/SPIR-V has issues with degenerate HLSL 1D matrices
- Dominant language
- C++
- Stars
- 3.6k
- Forks
- 989
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 31
Description
HLSL allows 1D matrices like `float4x1` and `float1x4`. Currently glslang converts these literally to SPIR-V, although SPIR-V requires matrix and vector dimensions to be >= 1 so the resulting SPIR-V is not valid.
Note there's an extra wrinkle of packing - `row_major float4x1` or `column_major float1x4` takes up 64 bytes (well, 52 since the last row/column isn't complete but you get the idea) which means it's not safe just to decay these into vectors in all cases. You'd maybe need to emulate it as individual floats with padded offsets and then a constant composite whenever it's accessed.
glslang also seems to disallow casting these objects to vectors implicitly, which fxc seems to allow. E.g. this shader compiles with fxc but fails on glslang:
```
cbuffer consts
{
row_major float4x1 a; // offset 0, size 52
row_major float1x4 b; // offset 64, size 16
column_major float4x1 c; // offset 80, size 16
column_major float1x4 d; // offset 92, size 52
};
float4 main() : SV_Target0
{
float4 ret = 0;
ret += a;
ret += b;
ret += c;
ret += d;
return ret;
}
```
Contributor guide
Research direction
Start by tracing glslang's HLSL handling of degenerate floatNxM matrices through SPIR-V generation and constant-buffer packing. Compare row-major and column-major float4x1 and float1x4 behavior, including implicit vector casts. Done means the shader produces valid SPIR-V with correct offsets, sizes, accesses, and accepted casts.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100