electrobun-webgpu

Solid

Use when working with WebGPU in Electrobun — GpuWindow, WGPUView, WGSL shaders, KEEPALIVE pattern, render loops, FFI pointer management, and GPU buffer serialization.

Web & Frontend 394 stars 68 forks Updated today MIT

Install

View on GitHub

Quality Score: 87/100

Stars 20%
86
Recency 20%
100
Frontmatter 20%
70
Documentation 15%
100
Issue Health 10%
50
License 10%
100
Description 5%
100

Skill Content

# 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 ...

Details

Author
milady-ai
Repository
milady-ai/milady
Created
3 months ago
Last Updated
today
Language
HTML
License
MIT

Similar Skills

Semantically similar based on skill content — not just same category