Skip to content

MSL: incorrect shared memory alignment, for vec3 #2494

Description

@Try

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions