Command Palette

Search for a command to run...

Back to skills
skill № 33444

webgpu-webgl-rendering

Use when the user asks about WebGPU, WGSL, WebGL2, GLSL shaders, bind groups, render pipelines, GPU buffers or compute shaders in the browser. Produces…

FreeNo executable scripts
j4flmaoby j4flmao★ 47 GitHub stars

Install webgpu-webgl-rendering in Claude Code & Claude Desktop

Sign up to install this skill

Create a free account to reveal the install command and save the skill to your library.

  • Reveal the one-line install command
  • Save skills to your synced library
  • Get notified when skills update
Sign up freeI already have an account

About this skill

WebGPU & WebGL: Pipelines and GPU Memory

Purpose

WebGPU is the modern browser GPU API (modelled on Vulkan/Metal/D3D12) with explicit pipelines, bind groups, command encoders and compute shaders written in WGSL. It ships in Chromium-based browsers (desktop since Chrome 113, Android since 121), Safari 26 and Firefox 141 on Windows, with other platforms rolling out; WebGL2 remains the universal fallback. This skill produces correct setup code, memory layout and frame-loop rules.

Agent Protocol

Trigger

"WebGPU", "WGSL", "WebGL2", "GLSL", "bind group", "uniform buffer alignment", "compute shader", "instancing", "draw calls", "GPU device lost".

Input Context

  • Target browsers/devices and whether a WebGL2 fallback is required.
  • Workload: rendering, compute (ML, particles, image processing) or both.
  • Data sizes and update frequency (static meshes vs. per-frame uniforms).

Output Artifact

Initialization code, WGSL/GLSL shaders, buffer layout table and frame-loop structure.

Response Format

API: {WebGPU|WebGL2|WebGPU+WebGL2 fallback}
Pipelines: {name -> shader stages, vertex layout}
Bind groups: {group index -> resources, update frequency}
Buffers: {name, usage flags, size, alignment}
Per-frame work: {uploads, passes, dispatches}

Feature Detection and Device Setup

export async function initWebGPU(canvas: HTMLCanvasElement) {
  if (!('gpu' in navigator)) throw new Error('WebGPU not supported: use WebGL2 fallback');
  const adapter = await navigator.gpu.requestAdapter({ powerPreference: 'high-performance' });
  if (!adapter) throw new Error('No suitable GPU adapter found');
  const device = await adapter.requestDevice();

  device.lost.then((info) => {
    console.error(`WebGPU device lost (${info.reason}): ${info.message}`);
    // Recreate device and all GPU resources unless reason === 'destroyed'
  });

  const context = canvas.getContext('webgpu');
  if (!context) throw new Error('Failed to get webgpu canvas context');
  const format = navigator.gpu.getPreferredCanvasFormat();
  context.configure({ device, format, alphaMode: 'premultiplied' });
  return { device, context, format };
}

Minimal Render Pipeline (WGSL)

struct Uniforms { mvp : mat4x4<f32> };
@group(0) @binding(0) var<uniform> u : Uniforms;

struct VSOut { @builtin(position) pos : vec4<f32>, @location(0) color : vec3<f32> };

@vertex
fn vs(@location(0) position : vec3<f32>, @location(1) color : vec3<f32>) -> VSOut {
  var o : VSOut;
  o.pos = u.mvp * vec4<f32>(position, 1.0);
  o.color = color;
  return o;
}

@fragment
fn fs(in : VSOut) -> @location(0) vec4<f32> {
  return vec4<f32>(in.color, 1.0);
}
const module = device.createShaderModule({ code: shaderSource });
const pipeline = device.createRenderPipeline({
  layout: 'auto',
  vertex: {
    module, entryPoint: 'vs',
    buffers: [{
      arrayStride: 24, // 6 floats: position + color
      attributes: [
        { shaderLocation: 0, offset: 0, format: 'float32x3' },
        { shaderLocation: 1, offset: 12, format: 'float32x3' },
      ],
    }],
  },
  fragment: { module, entryPoint: 'fs', targets: [{ format }] },
  primitive: { topology: 'triangle-list', cullMode: 'back' },
  depthStencil: { format: 'depth24plus', depthWriteEnabled: true, depthCompare: 'less' },
});

const uniformBuffer = device.createBuffer({
  size: 64, // mat4x4<f32>
  usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST,
});
const bindGroup = device.createBindGroup({
  layout: pipeline.getBindGroupLayout(0),
  entries: [{ binding: 0, resource: { buffer: uniformBuffer } }],
});

function frame(mvp: Float32Array, vertexBuffer: GPUBuffer, vertexCount: number, depthView: GPUTextureView) {
  device.queue.writeBuffer(uniformBuffer, 0, mvp);
  const encoder = device.createCommandEncoder();
  const pass = encoder.beginRenderPass({
    colorAttachments: [{
      view: context.getCurrentTexture().createView(),
      clearValue: { r: 0, g: 0, b: 0, a: 1 }, loadOp: 'clear', storeOp: 'store',
    }],
    depthStencilAttachment: { view: depthView, depthClearValue: 1, depthLoadOp: 'clear', depthStoreOp: 'store' },
  });
  pass.setPipeline(pipeline);
  pass.setBindGroup(0, bindGroup);
  pass.setVertexBuffer(0, vertexBuffer);
  pass.draw(vertexCount);
  pass.end();
  device.queue.submit([encoder.finish()]);
  requestAnimationFrame(() => frame(mvp, vertexBuffer, vertexCount, depthView));
}

Create pipelines and bind groups once at load; only write buffers and encode passes per frame. Prefer createRenderPipelineAsync for large shaders to avoid main-thread stalls.

Memory Layout Rules (WGSL)

Type Size Alignment
f32, i32, u32 4 4
vec2<f32> 8 8
vec3<f32> 12 16
vec4<f32> 16 16
mat4x4<f32> 64 16
struct in uniform buffer rounded up to its largest member alignment members in uniform arrays need 16-byte stride
  • Dynamic uniform buffer offsets must be multiples of `min
Full SKILL.md on GitHub

Allowed tools

Tools this skill is permitted to call.

No restriction — this skill can use any tool.

FAQ

What does the webgpu-webgl-rendering skill do?

Use when the user asks about WebGPU, WGSL, WebGL2, GLSL shaders, bind groups, render pipelines, GPU buffers or compute shaders in the browser. Produces low-level browser GPU pipeline setup, buffer alignment, WebGL2 fallback and per-frame performance rules. Not for Three.js or React Three Fiber scenes (use web3d-webgl).

How do I install the webgpu-webgl-rendering skill?

Copy the skill folder into ~/.claude/skills (the Claude Code tab above does this in one command), or install it as a plugin.

Does the webgpu-webgl-rendering skill run scripts?

No, this skill is instructions only (SKILL.md) with no executable scripts.

Related skills

Compare webgpu-webgl-rendering with