KhronosGroup / KhronosGroup/SPIRV-Cross
MSL: incorrect shared memory alignment, for `vec3`
Nobody has claimed this yet.
- Dominant language
- GLSL
- Stars
- 2.5k
- Forks
- 713
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 16
Description
In GLSL shared memory follow std430 alignment rules, meaning padding after vec3 can be utilized by 4-byte variable.
For example:
struct S {
vec3 pos;
uint uv;
};
// sizeof(S) == 16
However, when translated to MSL, it becomes:
struct S
{
float3 pos; // size = 16'bytes, alignment = 16'bytes
uint uv;
};
// sizeof(S) == 32
This mismatch can cause significant memory overuse. In my particular case, resulting in shader fail to run, due to use of more than 32kb of memory.
Suggested fix: use packed_float3 with alignas:
struct S
{
alignas(16) packed_float3 pos;
uint uv;
};
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the MSL struct emission and the std430 layout handling for shared vec3 members. Compare the generated MSL layout with the GLSL example, then verify that a following 4-byte member occupies vec3's padding and that the resulting struct size matches the source layout.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100