Skip to content

Difference between alignment of struct with size 8 vs vec2<f32> in uniform buffers. #4497

@Swoorup

Description

@Swoorup

I don't understand what is the difference here. Why doesn't the spec allow for 8 bytes alignment for struct?

Consider these 2 samples:

Case 1

struct fp64 {
  high: f32,
  low: f32
}

struct TestStruct {
  logical_offset: fp64,
  coord_offset: fp64,
  base_value: fp64,
}
@group(1) @binding(1) var<uniform> testStructUniform: TestStruct;

Case 2

alias fv64 = vec2<f32>;
struct TestStruct2 {
  logical_offset: fv64,
  coord_offset: fv64,
  base_value: fv64,
}
@group(1) @binding(2) var<uniform> testStructUniform2: TestStruct2;

Case 2 compiles fine without any issues, while case 1 fails with an error saying that the alignment of fp64 must be 16 bytes.

I checked the spec and it is indeed as per spec.
Are vec2<f32> and fp64 basically the same thing in hardware. Just out of curiosity why is it restrictive?

Metadata

Metadata

Assignees

No one assigned

    Labels

    copyeditingPure editorial stuff (copyediting, *.bs file syntax, etc.)wgslWebGPU Shading Language Issues

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions