+ TorusKnotGeometry in a MeshPhysicalMaterial, three coloured PointLights, an environment map, 260 additive embers, a planar mirror drawn with the stencil buffer, and the PocketJS overlay.Running JavaScript on old consoles is not new, and neither is three.js outside a browser tab: desktop apps have shipped it for years, with a browser inside them. What we believe is new is three.js itself on hardware where it could not run at all: the scene code you already write, unchanged, drawn by a GPU from 2006, with a small native runtime in place of a browser.
+This post is how we got there: what three.js needs from a machine, how the PS3 draws when you look at it from WebGL, what we built in between, the five bugs that cost us the most, and what it measured. The work is part of ThreeRT, the native runtime for three.js.
+The premise
+three.js has always come with a browser, and it is easy to think it needs one. It does not. Its scene graph, math, geometry generators, materials, lights and cameras are plain JavaScript with no DOM in them. Two things need the browser: the renderer, which speaks WebGL or WebGPU, and the JIT that keeps the renderer’s per-frame JavaScript fast.
+three.js ran where a browser ran. Outside the web you shipped one with it: Electron, a WebView. On a machine with no WebGL or WebGPU and no JIT, three.js did not run at all.
three@0.187.0, imported as it is, builds the scene on the PS3’s Cell; a renderer we wrote draws it on the RSX at 1920 × 1080; PocketJS draws the interface into the same frame. Four demos run at 16 to 30 fps.
So we split the two. We kept everything of three.js that is plain JavaScript and replaced one thing, the renderer: once a frame, RSXRenderer walks the three.js scene and hands it to C code that draws on the RSX. The JavaScript runs on QuickJS, an interpreter with no JIT, on the Cell’s PowerPC core.
The console is a PlayStation 3 Slim (CECH-2500) on system software 4.81 with custom firmware, which homebrew needs. What carries over, and what does not yet:
+- keeps
- the scene:
Mesh,InstancedMesh,Points,Line; standard, physical, Phong, Lambert, basic and normal materials; ambient, hemisphere, directional and point lights; fog - replaces
WebGLRenderer, withRSXRendererand native code- not yet
- what lives inside three.js’s renderer: shadows,
ShaderMaterialand TSL, three.js’s post-processing
The PS3, seen from WebGL
+If you know WebGL, you know how the PS3 rasterizes: vertex and index buffers, depth testing, fragment programs, blending. What changes is everything around them. In a browser, a driver places your memory, compiles your shaders and synchronizes with the GPU. On a PS3 there is no driver: that is your code.
+ +In a browserWebGL
+WebGLRendererOn a Sony PS3RSX
+RSXRendererwalks the scene, packs typed arraysthe same on bothwhat we wrotethe driver’s job in a browser, ours on a PS3
+Two memories, and you manage both
+Memory is split in two: 256 MiB of XDR for the Cell, where QuickJS, three.js and PocketJS live, and 256 MiB of GDDR3 for the RSX. You allocate GPU memory yourself (rsxMemalign), turn CPU pointers into the offsets the RSX understands (rsxAddressToOffset), order your writes with a PowerPC barrier (eieio) and invalidate the RSX’s vertex and texture caches when you change what is in them. Two 1080p colour buffers and a depth-and-stencil buffer take about 25 MB; the rest is for meshes, textures and glyph atlases.
No driver: you write the command stream
+There is no gl.drawElements() on PS3 homebrew. The CPU and the RSX share a ring of 32-bit words, the command FIFO: every graphics call writes a method header and its arguments at put, and the RSX’s get chases it. Two things follow.
-
+
- You own synchronization. Overwrite a buffer the RSX has not read yet, or rewind the ring while
getis behindput, and it reads garbage and locks the console. You fence withrsxFinishand an increasing reference, and present withgcmSetFlip.
+ - You own the ring’s end. Write more in one frame than the segment holds without jumping back to its start (
rsxSetJumpCommand) and you run off its end. AnInstancedMeshtaught us this; see bug 5.
+
Two shader units, and fragment constants live inside the program
+The RSX comes from NVIDIA’s G70, the GeForce 7800 generation, and PSL1GHT drives it with NV40-class registers and assembly. It is the last generation before unified shaders: vertex programs (!!VP2.0) and fragment programs (!!FP2.0) run on different units with different rules. Vertex programs read constants from a bank of vec4 registers, c[…], loaded through the FIFO. Fragment programs have no such bank.
A fragment “uniform” is a 16-byte slot in the program’s own machine code. The assembler leaves the slot and records where it is. To set it, you write the value into the program in GPU memory, with a DMA write ordered with your other commands (rsxInlineTransfer), and every 32-bit float has its two 16-bit halves swapped, because that is the order in which the fragment unit fetches words. Then you point the RSX at the program again so it does not run a stale copy.
-
+
- Swap halves
1.0 = 0x3f800000 → 0x00003f800.85 = 0x3f59999a → 0x999a3f59
+ - Write it into the slot
rsxInlineTransfer(ctx, fp_offset + 0x10, …)
+ - Point the RSX at the program again
rsxLoadFragmentProgramLocation(…)
+
gl.uniform4f(loc, 1, 0.85, 0.4, 1).Big-endian on both sides
+The Cell is big-endian, and so is the RSX. QuickJS keeps a Float32Array in the CPU’s byte order, which is the order the RSX reads vertices and indices in. So when three.js fills a BufferGeometry or an InstancedMesh’s matrices, our bridge takes the array’s memory and copies it to the GPU as it is: no per-element conversion, no byte swapping.
One triangle, five stages
+The same coloured triangle, drawn both ways. Every design choice in the three.js renderer comes out of these five differences.
+ +1 · Upload the vertices
+// The driver places and caches it. +const vbo = gl.createBuffer(); +gl.bindBuffer(gl.ARRAY_BUFFER, vbo); +gl.bufferData(gl.ARRAY_BUFFER, verts, + gl.STATIC_DRAW);
// Aligned GPU memory, a barrier, an offset, a cache flush.
+TriVert *vb = rsxMemalign(64, 3 * sizeof(TriVert));
+memcpy(vb, triangle, 3 * sizeof(TriVert));
+__asm__ volatile("eieio" ::: "memory");
+u32 vb_off; rsxAddressToOffset(vb, &vb_off);
+rsxInvalidateVertexCache(ctx);2 · Load the shaders
+GLSL compiles on the user’s machine. RSX programs are assembled before the build (cgcomp -a); the vertex program is sent through the FIFO, and the fragment program is copied into GPU memory, because the RSX fetches fragment instructions from there.
// GLSL, compiled at run time. +gl_Position = uMVP * vec4(aPos, 1.0); +vColor = aColor; +// … +gl_FragColor = vColor * uTint;
# !!VP2.0: c[0..3] are the rows of uMVP +DP4 R0.x, v[0], c[0]; DP4 R0.y, v[0], c[1]; +DP4 R0.z, v[0], c[2]; DP4 R0.w, v[0], c[3]; +MOV o[HPOS], R0; MOV o[COL0], v[3]; +# !!FP2.0: c[0] is the uTint slot +MOV R1, c[0]; +MULR o[COLR], f[COL0], R1;
3 · Set the uniforms
+Here the two worlds part. A vertex constant is a block load through the FIFO, cheap enough for every draw. A fragment constant is a write into the program and a reload of it.
+gl.uniformMatrix4fv(locMVP, false, mvp); +gl.uniform4f(locTint, 1.0, 0.85, 0.4, 1.0);
// Vertex: four rows into c[0..3]. +rsxLoadVertexProgramParameterBlock(ctx, 0, 4, mvp_rows); +// Fragment: into the program itself, halves swapped. +for (u32 i = 0; i < tab->num; i++) + rsxInlineTransfer(ctx, fp_off + tab->offset[i], + swapped, 4, GCM_LOCATION_RSX); +rsxLoadFragmentProgramLocation(ctx, fp, fp_off, + GCM_LOCATION_RSX);
4 · Draw
+WebGL’s clip space has +Y up and the screen comes out right. The RSX scans out top-down with depth from 0 to 1, so a viewport with a negative Y scale maps three.js’s clip space onto it; attributes are bound by GPU offset.
+gl.viewport(0, 0, 1920, 1080); +gl.vertexAttribPointer(0, 3, gl.FLOAT, + false, 28, 0); +gl.drawArrays(gl.TRIANGLES, 0, 3);
f32 scale[4] = { 960, -540, 0.5f, 0 };
+f32 offset[4] = { 960, 540, 0.5f, 0 };
+rsxSetViewport(ctx, 0, 0, 1920, 1080, 0, 1, scale, offset);
+rsxBindVertexArrayAttrib(ctx, GCM_VERTEX_ATTRIB_POS, 0,
+ vb_off, sizeof(TriVert), 3, GCM_VERTEX_DATA_TYPE_F32,
+ GCM_LOCATION_RSX);
+rsxDrawVertexArray(ctx, GCM_TYPE_TRIANGLES, 0, 3);5 · Present
+In a browser you return from requestAnimationFrame. On a PS3 nothing reaches the TV until you flush the FIFO, fence the RSX, rewind the ring, wait for the last flip and queue the next.
requestAnimationFrame(loop);
rsxFlushBuffer(ctx); +rsxFinish(ctx, ++ref); // the RSX is done +rsxSetJumpCommand(ctx, begin_off); // rewind the ring +while (gcmGetFlipStatus() != 0) usleep(200); +gcmResetFlipStatus(); +while (gcmSetFlip(ctx, fb) != 0) usleep(200); +rsxFlushBuffer(ctx); +gcmSetWaitFlip(ctx); +fb ^= 1;
From three.js to the RSX
+The showcase starts with import * as THREE from "three". RSXRenderer (platforms/ps3/three-rsx-renderer.ts) walks that scene and talks to the C engine (platforms/ps3/rsx3d.c) through one global object, globalThis.__rsx3d, whose arguments are typed arrays.
Scene-wide values once a pass, per-object values per draw
+A fragment constant costs a write into the program and a reload, so the renderer splits uniforms along that line. Values that are the same for the whole scene (the camera position and exposure, the directional light, three point lights, the hemisphere light, fog) are written into the PBR fragment program once a pass. Everything per object (its matrices, colour, emissive, roughness, metalness, UV transform) goes into vertex constants and reaches the fragment unit through interpolators. No fragment program is reloaded per mesh.
+ +One call for an InstancedMesh, and what it still costs
+ QuickJS has no JIT, and calling into C once per instance with loose numbers would spend the frame on an in-order core. So for an InstancedMesh the renderer passes three.js’s own instanceMatrix.array and instanceColor.array to C in one call; C loads the shared material constants once and loops over the instances on the PPU.
That keeps JavaScript out of the loop, but the RSX has no hardware instancing: every instance is still a draw with its own constants. With 196 instances, writing those commands takes 28.9 ms of the PPU’s time a frame, and that demo is the slowest, at 16 fps. The Cell has six SPUs doing nothing; this loop is the first thing to move onto them.
+ +Two passes into one frame
+rsx_driver.c binds one 1920 × 1080 colour surface with a 24-bit depth and 8-bit stencil buffer and calls the scene first. Pass 1 clears colour, depth and stencil and draws the 3D scene. Pass 2 clears nothing, resets the depth, stencil and cull state, and draws the PocketJS interface over it with alpha blending. PocketJS apps that draw no 3D do not change.
Shaders for a 2006 GPU
+What makes a 2006 GPU look current is less how many triangles it draws than how materials answer light. Three things do most of that here.
+-
+
- Per-pixel PBR. Metalness and roughness, Schlick’s Fresnel without a
POW(x = 1 − N·V, thenx²·x²·x), a directional light with a roughness-scaled Blinn-Phong lobe and three point lights per pixel, then the ACES filmic curve, so highlights roll off instead of clipping.
+ - An environment map without trigonometry. A 256 × 128 studio panorama (a warm softbox overhead, a cool strip at the side, a ring at the zenith) sampled along the reflection vector with a projection that needs no
atan2:t = R.x / (|R.x| + |R.z|),u = R.z < 0 ? 0.75 − 0.25t : 0.25 + 0.25t,v = 0.5 − 0.48 R.y. The two halves meet atu = 0.5and wrap at 0 and 1.
+ - A planar mirror with the stencil buffer. Draw the floor into the stencil only; draw the reflectable meshes flipped below it where the stencil is set, with the winding reversed; clear depth; draw the floor over them, partly transparent. +
Five bugs
+The toolchain ran on an Apple-silicon Mac (PSL1GHT in a Docker image, Rust for powerpc64), and every one of these happened on the console. If you write for the RSX, they may save you some days.
1 · Every fragment uniform was zero
+The first three.js frame showed a sharp PocketJS overlay over a black screen. Disassembling PSL1GHT’s prebuilt rsxSetFragmentProgramParameter in librsx.a showed the value argument copied into a register that is overwritten before it is used, and a zeroed 16-byte stack buffer passed to rsxInlineTransfer instead: every fragment uniform, exposure and every light included, was uploaded as zeros. Our reading is that GCC 13 optimized the copy away under strict aliasing. A twelve-line replacement that copies with memcpy and calls rsxInlineTransfer itself fixed it.
48: mr r28, r6 # r28 = the value + d0: mr r28, r3 # overwritten before it is read + 104: addi r5, r1, 112 # the zeroed stack buffer + 110: bl rsxInlineTransfer+ +
2 · Every vertex landed on one point
+With uniforms fixed the sky appeared, and no triangle did. The vertex assembler (cgcomp -a -v) ignores write masks on output registers: four DP4 o[HPOS].x/.y/.z/.w each assembled to a full .xyzw write, so every vertex became (w, w, w, w). Computing into R0.x to R0.w and ending with MOV o[HPOS], R0 fixed it.
3 · The fragment assembler drops what it does not know
+cgcomp -a -f, used because NVIDIA’s Cg compiler does not run on ARM64 Linux, turned SUB into a 16-byte no-op (write ADD R0, R1, -R2), dropped ABS (write MOV R0, |R1|), read inline literals such as {14.0}.x as R0 (put every number in a named constant), and crashed on a blank line.
4 · The camera that never moved
+camera.updateMatrixWorld() does not update camera.matrixWorldInverse; WebGLRenderer.render() does, with matrixWorldInverse.copy(matrixWorld).invert(). A custom renderer that skips that line draws from the origin, looking down −Z, wherever the camera is.
5 · Off the end of the ring
+The instanced demo with 400 instances locked the RSX on its first frame. Each instance writes about 58 words (its constants and a draw), and 400 of them are about 92 KB, past the end of the FIFO segment. Two fixes: the driver rewinds the ring after every frame, and rsx3d.c checks for space before a batch and rewinds in the middle of a frame when it must. The demo also went to 196 instances (14 × 14), and the point lights’ POW became repeated squaring, which freed three registers in the PBR program.
What it measured
+Each frame below was read at 1920 × 1080 from the RSX’s front buffer over the DevShell, a TCP service on port 8623 that also reloads the app’s bundle in place and injects controller input, so we never went back to the console’s menu while working.
+



None of them reaches 60. In three of the four, writing the 3D commands takes 0.1 ms, so most of the frame goes somewhere we have not measured yet: QuickJS walking the scene on the PPU, the RSX shading two million pixels of PBR (twice, where there is a mirror), or waiting for vsync. That profile is the next piece of work, and then the SPUs.
+With a DualShock 3: L1 and R1 change the scene, the sticks orbit and zoom, △ shows wireframe, ○ turns the mirror off and on, □ stops the orbit, SELECT hides the overlay.
What it means for ThreeRT
+ThreeRT is a native runtime for three.js: no browser between your scene and the GPU. How much of three.js stays depends on the machine. On macOS and Linux, webgpu keeps all of it, three.js and its own WebGPURenderer, and replaces only the browser: a 9.9 MB app where Electron takes 445 MB. On GPUs with ray-tracing hardware, path replaces the renderer with a path tracer at 60 fps. The PS3 is the third case. It has no WebGPU and no JIT, so three.js keeps its scene graph and a native renderer draws it.
The PS3 port is experimental, and it is built in PocketJS (platforms/ps3), not by ThreeRT’s tools. What it shows is how little a three.js scene needs from a machine once the browser is gone. How the three ways differ is in RENDERING-METHODS.md.


