dexploarer/plugin-electrobun-dev/electrobun-webgpu

Claude Code and agent skill by dexploarer/plugin-electrobun-dev

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

This skill should be used when the user asks about "electrobun WebGPU", "GpuWindow", "WGPUView", "WGSL shaders", "KEEPALIVE pattern", "electrobun GPU", render loops in electrobun, FFI pointer management, or GPU buffer serialization.

Install

npx vskill@latest install dexploarer/plugin-electrobun-dev/electrobun-webgpu

SKILL.md

The same SKILL.md was published earlier as dexploarer/plugin-electrobun-dev/electrobun-webgpu.

Electrobun WebGPU Patterns

Electrobun wraps WGPU (a Rust WebGPU abstraction) via Bun FFI. GPU windows bypass the webview entirely — they render directly to a native surface.

Config Requirement

Always required before WebGPU code will work:

typescript
// electrobun.config.ts
mac: { bundleWGPU: true },
win: { bundleWGPU: true },
linux: { bundleWGPU: true },

GpuWindow Setup

typescript
import { GpuWindow } from "electrobun/bun";
const gpuWin = new GpuWindow({
title: "GPU App",
frame: { width: 800, height: 600 },
centered: true,
});
const view = gpuWin.createView(); // WGPUView

KEEPALIVE — Critical Pattern

Bun's GC will collect FFI pointers unless you hold a reference to them. Without KEEPALIVE, your app will crash mid-render with a segfault.

typescript
// ALWAYS create this array and push every GPU object into it
const KEEPALIVE: unknown[] = [];
const adapter = await navigator.gpu.requestAdapter();
KEEPALIVE.push(adapter);
const device = await adapter.requestDevice();
KEEPALIVE.push(device);
const pipeline = device.createRenderPipeline({ /* ... */ });
KEEPALIVE.push(pipeline);
const buffer = device.createBuffer({ /* ... */ });
KEEPALIVE.push(buffer);

Render Loop Pattern

typescript
const FRAME_MS = 16; // ~60fps
function renderFrame() {
// 1. Update uniform buffer with current state
const data = new ArrayBuffer(32);
const view = new DataView(data);
view.setFloat32(0, performance.now() / 1000, true); // time
view.setFloat32(4, canvas.width, true); // resolution.x
view.setFloat32(8, canvas.height, true); // resolution.y
view.setFloat32(12, mouseX, true); // mouse.x
view.setFloat32(16, mouseY, true); // mouse.y
device.queue.writeBuffer(uniformBuffer, 0, data);
// 2. Create command encoder
const encoder = device.createCommandEncoder();
KEEPALIVE.push(encoder);
// 3. Begin render pass
const pass = encoder.beginRenderPass({
colorAttachments: [{
view: context.getCurrentTexture().createView(),
clearValue: { r: 0, g: 0, b: 0, a: 1 },
loadOp: "clear",
storeOp: "store",
}],
});
// 4. Draw
pass.setPipeline(pipeline);
pass.setVertexBuffer(0, vertexBuffer);
pass.draw(3);
pass.end();
// 5. Submit
device.queue.submit([encoder.finish()]);
}
setInterval(renderFrame, FRAME_MS);

WGSL Shader Structure

wgsl
// Vertex shader
struct VertexOutput {
@builtin(position) position: vec4f,
@location(0) uv: vec2f,
}
@vertex
fn vs_main(@builtin(vertex_index) idx: u32) -> VertexOutput {
// Full-screen triangle
var positions = array<vec2f, 3>(
vec2f(-1.0, -1.0),
vec2f( 3.0, -1.0),
vec2f(-1.0, 3.0),
);
var out: VertexOutput;
out.position = vec4f(positions[idx], 0.0, 1.0);
out.uv = (positions[idx] + vec2f(1.0)) * 0.5;
return out;
}
@fragment
fn fs_main(in: VertexOutput) -> @location(0) vec4f {
// TODO: replace with your shader logic
return vec4f(in.uv, 0.5, 1.0);
}

Vertex Buffer with DataView

GPU structs must be manually serialized. Vertex layout: [x, y, time, res.x, res.y, mouse.x, mouse.y] (all f32).

typescript
// 3 vertices × 7 floats × 4 bytes = 84 bytes
const vertexData = new ArrayBuffer(3 * 7 * 4);
const dv = new DataView(vertexData);
// Full-screen triangle vertices
const verts = [
[-1, -1], [3, -1], [-1, 3],
];
verts.forEach(([x, y], i) => {
const offset = i * 7 * 4;
dv.setFloat32(offset + 0, x, true); // position.x
dv.setFloat32(offset + 4, y, true); // position.y
dv.setFloat32(offset + 8, time, true); // time
dv.setFloat32(offset + 12, width, true);
dv.setFloat32(offset + 16, height, true);
dv.setFloat32(offset + 20, mouseX, true);
dv.setFloat32(offset + 24, mouseY, true);
});

Common Mistakes

  1. No KEEPALIVE → segfault or silent corruption mid-render.
  2. `bundleWGPU: false` → runtime error; Electrobun won't include the WGPU native library.
  3. Not recreating swap chain on resize → distorted rendering after window resize.
  4. Forgetting `little-endian: true` in DataView.setFloat32 → garbage GPU data on most platforms.
  5. Blocking the render loop → use async I/O outside the render interval, never inside.

Security

  • Security scanPassed, 95 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

Repository stars
5
Repository forks
1
7-day trend score
9

Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/dexploarer/plugin-electrobun-dev/electrobun-webgpu/badge)](https://verified-skill.com/skills/dexploarer/plugin-electrobun-dev/electrobun-webgpu)

Something wrong with this skill or its page? Tell us.