webgpu-wgsl-memory-layout

Validate WGSL buffer layouts against AlignOf and SizeOf rules.

Updated May 20, 2026
One-click install
npx skills add https://github.com/Impertio-Studio/WebGPU-Claude-Skill-Package --skill webgpu-wgsl-memory-layout
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: webgpu-wgsl-memory-layout
Source: https://github.com/Impertio-Studio/WebGPU-Claude-Skill-Package/tree/main/skills/source/webgpu-wgsl/webgpu-wgsl-memory-layout
Command: npx skills add https://github.com/Impertio-Studio/WebGPU-Claude-Skill-Package --skill webgpu-wgsl-memory-layout

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill prevents host and shader memory mismatches when WebGPU code binds WGSL structs, buffers, and pointers, especially the vec3 alignment trap that causes silent garbage reads.

Core Features & Use Cases

  • Lays out uniform and storage structs with correct AlignOf, SizeOf, and padding.
  • Chooses the right WGSL address space, including function, private, workgroup, uniform, storage, and handle.
  • Handles runtime-sized arrays, array stride rules, and @align and @size annotations.
  • Use it when a JavaScript typed array must match a shader struct, when a compute shader writes to storage buffers, or when a uniform buffer keeps producing incorrect values.

Quick Start

Ask the assistant to review my WGSL struct and matching JavaScript buffer and return the correct byte offsets, padding, and array sizes for the chosen address space.

Frequently Asked Questions about webgpu-wgsl-memory-layout

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
Why does my WebGPU uniform buffer produce incorrect values in the shader?

WebGPU uniform buffers read incorrect values when WGSL memory layout violates AlignOf and SizeOf rules or the 16-byte array-stride constraint. This Skill corrects struct padding and byte offsets to eliminate silent garbage reads.

How do I calculate byte offsets and padding for a WGSL struct matching a JavaScript typed array?

To calculate byte offsets and padding for a WGSL struct, you must apply AlignOf and SizeOf rules alongside vec3-safe padding. This Skill reviews your shader struct and JavaScript buffer to return deterministic memory mapping with correct byte offsets, padding, and array sizes.

What is the vec3 alignment trap in WGSL memory layout?

The vec3 alignment trap in WGSL memory layout is a padding issue where vec3 types require 16-byte alignment, causing silent garbage reads if host-side typed arrays do not match. This Skill applies vec3-safe padding to ensure deterministic memory mapping between JavaScript and WebGPU shaders.

Do I need @align and @size annotations for runtime-sized arrays in storage buffers?

You need @align and @size annotations for runtime-sized arrays in storage buffers when explicit control over array stride and padding is required to match host-side typed arrays. This Skill handles array stride rules and annotations to satisfy WGSL memory layout constraints.

How do I choose the right WGSL address space for compute and render data?

Choosing the right WGSL address space depends on data access patterns across function, private, workgroup, uniform, and storage spaces. This Skill selects the correct address space for your WebGPU compute and render code to ensure valid pointer mutation and buffer binding.