demo · v144 · WebGPU

vec3 Padding Trap

Uniform buffer standard layout lets WGSL uniforms use the same layout constraints as storage buffers, removing forced 16-byte padding for arrays and nested structs. Use the controls to test the classic vec3 assumptions, then inspect the exact offsets and bytes each layout expects.

WebGPU APIchecking
WGSL extensionchecking
Adapter/devicechecking
Shader probewaiting

The layout calculator runs without WebGPU. The probe checks whether this browser exposes navigator.gpu.wgslLanguageFeatures, can create a device, and can compile a shader that uses requires uniform_buffer_standard_layout;.

3
0.25
0.50
0.75
1.00

default uniform constraints

Total size0 B
Padding0 B
Stride rulen/a

Select a byte to inspect its owner and value.

FieldTypeOffsetStrideData bytesPadding

with uniform_buffer_standard_layout

Total size0 B
Padding0 B
Stride rulen/a

Select a byte to inspect its owner and value.

FieldTypeOffsetStrideData bytesPadding

the API

if (!navigator.gpu?.wgslLanguageFeatures?.has("uniform_buffer_standard_layout")) {
  throw new Error("WGSL uniform buffer standard layout is not available");
}

const adapter = await navigator.gpu.requestAdapter();
const device = await adapter.requestDevice();

const shaderModule = device.createShaderModule({ code: `
  requires uniform_buffer_standard_layout;

  struct Inner {
    x: f32,
  }

  struct Uniforms {
    inner: Inner,
    weight: f32, // offset 4 with standard layout, offset 16 without it
  }

  @group(0) @binding(0) var<uniform> u: Uniforms;
` });

generated WGSL

see also