Something went wrong. Try again.
Monorepo for Aesthetic.Computer aesthetic.computer
Something went wrong. Try again.
Markdown
WebGPU Renderer Research #
Current Rendering Pipeline #
The current rendering pipeline in aesthetic.computer is a distributed system split between the "Disk" (Worker) and the "BIOS" (Main Thread).
1. Disk (Client/Worker) #
Located in system/public/aesthetic.computer/lib/disk.mjs.
- Role: Acts as the application logic or "kernel". It generates graphics commands but does not execute them directly.
- Mechanism:
gpuObject: Exposes amessagefunction (Line ~2936) that sendsgpu-eventmessages to the host.graphFunction: (Line ~4460) Serializes 3D forms (vertices, colors, transforms) and sends them via aformsmessage.sendFunction: (Line ~7742) WrapspostMessageto transmit data to the main thread.
2. BIOS (Host/Main Thread) #
Located in system/public/aesthetic.computer/bios.mjs.
- Role: The host environment that manages the display and I/O.
- Mechanism:
receivedChange: (Line ~2938) A massive switch statement that handles incoming messages from the worker.gpu-eventHandler: (Line ~10310) Routesgpu-eventmessages to theThreeDrenderer:if (type === "gpu-event") { ThreeD?.handleEvent(content); return; }- Renderers:
TwoD: Currently disabled/undefined.ThreeD: Dynamically imported from./lib/3d.mjs.
Proposed WebGPU Architecture #
To implement a WebGPU renderer, we should follow the existing message-passing pattern but create a dedicated pipeline for WebGPU commands.
1. New Renderer Module #
Create a new module system/public/aesthetic.computer/lib/webgpu.mjs (or similar) that initializes the WebGPU context and handles rendering.
- Initialization: Request
navigator.gpu.requestAdapter()andadapter.requestDevice(). - Canvas: It will need access to a canvas element (likely passed from
bios.mjs).
2. Disk Extensions (disk.mjs) #
Extend the API available to pieces to include WebGPU commands.
webgpuObject: Add awebgpuobject to the API exposed to pieces.- Command Serialization: Implement methods to serialize WebGPU commands (buffers, shaders, pipelines) into a format suitable for
postMessage.- Note: WebGPU relies heavily on
ArrayBuffers. These are transferable objects, which is efficient forpostMessage.
- Note: WebGPU relies heavily on
3. BIOS Integration (bios.mjs) #
Update the host to handle WebGPU messages.
- Import: Import the new
WebGPUrenderer. - Message Handler: Add a handler for
webgpu-command(or similar) inreceivedChange.if (type === "webgpu-command") { WebGPU?.handleCommand(content); return; } - Initialization: Initialize the
WebGPUrenderer in thebootsequence, passing the necessary canvas/context.
Implementation Plan #
- Scaffold
webgpu.mjs: Create the basic class/module structure for the renderer. - Update
bios.mjs:- Import
webgpu.mjs. - Initialize it (request device, configure context).
- Add the message handler.
- Import
- Update
disk.mjs:- Add the
webgpuAPI surface. - Implement the
sendlogic for WebGPU commands.
- Add the
- Proof of Concept: Create a simple piece that sends a "clear screen" command via the new pipeline.
Considerations #
- Transferables: Ensure that large data buffers (vertices, textures) are sent as "transferables" in
postMessageto avoid copying overhead. - State Management: The
WebGPUrenderer on the main thread will need to maintain the state (pipelines, buffers, textures) that the worker refers to by ID or handle. - Async Nature: WebGPU initialization is async. The
diskmay need to wait for a "ready" signal from thebiosbefore issuing commands.