The native runtime for three.js: three.js, down to the metal. 45× smaller than Electron, on a Sony PS3, and path-traced at 60 fps on ray-tracing GPUs.
Rust electron-alternativegame-engineglobal-illuminationgraphicsjavascript-runtimemetalpath-tracingray-tracingreal-time-renderingrenderingrustthreejstypescriptvoxelvulkanwebgpuwgpu
docs(blog): follow one RGB triangle through the PS3 and WebGL pipelines (#309)
Evan (Yifeng) Wanga8567d0414a4
diff --git a/site/blog/ps3/index.html b/site/blog/ps3/index.htmlindex 594fbbd..b170401 100644--- a/site/blog/ps3/index.html+++ b/site/blog/ps3/index.html@@ -152,6 +152,126 @@.grid4 figcaption b { color: var(--bone); font-weight: 600; }.grid4 figcaption b:first-child { display: block; font-family: var(--font-sans); font-size: 14px; }+ /* One RGB triangle, stage by stage: what it is at each stage, and who carries it to the next. */+ .tp-defs { position: absolute; width: 0; height: 0; overflow: hidden; }+ svg.tp { display: block; width: 100%; height: auto; }+ svg.tp text { font-family: var(--font-mono); fill: #bdb8af; }+ .tp-rail { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); grid-template-rows: repeat(5, auto); gap: 8px 18px; }+ .tp-card { position: relative; grid-row: span 5; display: grid; grid-template-rows: subgrid; min-width: 0; }+ .tp-card + .tp-card::before { content: "→"; position: absolute; left: -14px; top: 62px; color: var(--mute); font-size: 14px; }+ .tp-n { font: 500 11.5px var(--font-mono); color: var(--bone-2); }+ .tp-n b { color: var(--tungsten); font-weight: 600; }+ .tp-th { display: block; aspect-ratio: 16 / 11; border-radius: 10px; border: 1px solid var(--line); background: #07080b; overflow: hidden; }+ .tp-th svg { display: block; width: 100%; height: 100%; }+ .tp-th text { font-family: var(--font-mono); fill: #80858e; }+ .tp-is { font: 600 14px/1.25 var(--font-sans); color: var(--bone); }+ .tp-w { padding: 7px 9px; border-radius: 8px; border: 1px solid var(--line); background: #10131a; min-width: 0; font-size: 12.5px; line-height: 1.4; color: var(--bone-2); }+ .tp-w.you { border-color: color-mix(in srgb, var(--ember) 45%, transparent); background: color-mix(in srgb, var(--ember) 8%, var(--ink-1)); color: var(--bone); }+ .tp-w span { display: block; font: 500 10px/1.6 var(--font-mono); text-transform: uppercase; letter-spacing: .06em; color: var(--mute); }+ .tp-w.you span { color: var(--c-ps); }+ .tp-w code { font-size: 11px; white-space: normal; }++ .tp-lanes { display: grid; gap: 10px; }+ .tp-lane { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 12px; align-items: center; }+ .tp-lab { font: 500 11px/1.35 var(--font-mono); color: var(--mute); }+ .tp-lane.rsx .tp-lab { color: var(--c-ps); }+ .tp-flow { display: flex; align-items: stretch; gap: 6px; min-width: 0; }+ .tp-flow > .bx { flex: 1 1 0; }+ .tp-flow > .ar { flex: 0 0 14px; align-self: center; }+ .bx.you { border-color: color-mix(in srgb, var(--ember) 55%, transparent); background: color-mix(in srgb, var(--ember) 10%, var(--ink-1)); }+ .bx.fog { border-style: dashed; background: transparent; }+ .bx code { font-size: 11.5px; }+ .tp-flow .bx small { overflow-wrap: anywhere; }+ .tp-split { display: grid; grid-template-columns: var(--tp-left, 180px) minmax(0, 1fr); gap: 22px; align-items: center; }+ .tp-split + .tp-lanes, .tp-bytes + .tp-lanes { margin-top: 18px; }++ /* Stage 1: the bytes. */+ .tp-bytes { display: grid; grid-template-columns: 58px repeat(7, minmax(0, 1fr)); gap: 4px; font: 500 11px/1.3 var(--font-mono); }+ .tp-bytes > span { min-width: 0; }+ .tp-bytes .h { color: var(--mute); text-align: center; font-size: 10.5px; }+ .tp-bytes .h.grp { grid-column: span 3; border-bottom: 1px solid var(--line-2); padding-bottom: 3px; }+ .tp-bytes .h.grp + .h.grp { grid-column: span 4; }+ .tp-bytes .v { display: flex; align-items: center; gap: 6px; color: var(--bone-2); white-space: nowrap; }+ .tp-bytes .v i { flex: none; width: 9px; height: 9px; border-radius: 50%; }+ .tp-bytes .v small { color: var(--mute); font-size: 10px; }+ .tp-bytes .f { padding: 6px 4px; border-radius: 6px; border: 1px solid var(--line); background: #12151c; text-align: center; color: var(--bone); }+ .tp-bytes .f small { display: block; margin-top: 2px; font-size: 10px; color: var(--mute); overflow-wrap: anywhere; }+ .tp-bytes .f.r { background: color-mix(in srgb, #ff2a2a 26%, #12151c); border-color: rgba(255, 42, 42, .5); }+ .tp-bytes .f.g { background: color-mix(in srgb, #22e04a 20%, #12151c); border-color: rgba(34, 224, 74, .45); }+ .tp-bytes .f.b { background: color-mix(in srgb, #3b5bff 32%, #12151c); border-color: rgba(59, 91, 255, .6); }+ .tp-bytes .f.r small, .tp-bytes .f.g small, .tp-bytes .f.b small { color: var(--bone-2); }++ /* Stage 2: the processors. */+ .tp-cores { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 7px; }+ .tp-cores i { width: 10px; height: 10px; border-radius: 3px; background: #1a1d24; border: 1px solid rgba(236, 232, 225, .14); }+ .tp-cores i.r { background: #ff2a2a; border-color: #ff2a2a; } .tp-cores i.g { background: #22e04a; border-color: #22e04a; } .tp-cores i.b { background: #3b5bff; border-color: #3b5bff; }+ .tp-cores i.f { background: color-mix(in srgb, var(--tungsten) 55%, #12151c); border-color: color-mix(in srgb, var(--tungsten) 70%, transparent); }++ /* Stage 3: the tint, and where it is kept. */+ .tp-eq { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 8px; font: 500 11px var(--font-mono); color: var(--mute); text-align: center; }+ .tp-eq svg { display: block; width: 100%; height: auto; }+ .tp-eq .sw { display: grid; gap: 4px; justify-items: center; }+ .tp-eq .sw i { width: 26px; height: 26px; border-radius: 7px; background: rgb(255, 217, 102); box-shadow: 0 0 0 1px rgba(236, 232, 225, .2); }+ .tp-eq small { display: block; margin-top: 6px; }+ .tp-regs { display: grid; gap: 3px; margin-top: 7px; font: 500 10.5px/1.35 var(--font-mono); }+ .tp-regs span { display: grid; grid-template-columns: 38px minmax(0, 1fr); gap: 6px; padding: 3px 7px; border-radius: 5px; background: #0e1016; border: 1px solid var(--line); color: var(--bone-2); overflow-wrap: anywhere; }+ .tp-regs span em { font-style: normal; color: var(--mute); }+ .tp-regs.q { grid-template-columns: 1fr 1fr; }+ .tp-regs span.hot { border-color: color-mix(in srgb, var(--ember) 65%, transparent); background: color-mix(in srgb, var(--ember) 12%, var(--ink-1)); color: var(--bone); }++ /* Stage 4: the pixels. */+ .tp-s4 { display: grid; grid-template-columns: 186px minmax(0, 1fr); gap: 20px; align-items: start; }+ .tp-side { display: grid; gap: 14px; }+ .tp-vp { display: grid; gap: 6px; font: 500 11.5px/1.45 var(--font-mono); color: var(--bone-2); }+ .tp-vp > span { font-size: 10.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--mute); }+ .tp-vp b { color: var(--tungsten); font-weight: 600; }+ .tp-vp p { margin: 2px 0 0 !important; font: 13px/1.45 var(--font-sans) !important; color: var(--bone-2) !important; }+ .tp-tog { display: inline-flex; justify-self: start; gap: 2px; padding: 2px; border: 1px solid var(--line-2); border-radius: 999px; }+ .tp-tog button { font: 500 11px var(--font-mono); color: var(--mute); background: none; border: 0; padding: 5px 10px; border-radius: 999px; cursor: pointer; }+ .tp-tog button[aria-pressed="true"] { background: color-mix(in srgb, var(--c-ps) 24%, transparent); color: var(--bone); }+ .tp-screen { display: grid; gap: 6px; min-width: 0; }+ .tp-screen .edge { display: flex; justify-content: space-between; gap: 12px; font: 500 10.5px var(--font-mono); color: var(--mute); }+ .tp-screen .edge .rsx { color: var(--c-ps); }+ .tp-px { border-radius: 10px; border: 1px solid var(--line-2); cursor: crosshair; outline: none; }+ .tp-px:focus-visible { box-shadow: 0 0 0 2px var(--c-ps); }+ .tp-read { display: grid; grid-template-columns: 76px minmax(0, 1fr); gap: 7px 12px; margin: 16px 0 0; padding: 14px 16px; border-radius: 12px; border: 1px solid var(--line); background: #0e1016; font: 500 12px/1.5 var(--font-mono); color: var(--bone-2); }+ .tp-read dt { color: var(--mute); }+ .tp-read dt.rsx { color: var(--c-ps); }+ .tp-read dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }+ .tp-read b { color: var(--bone); font-weight: 600; }+ .tp-read small { color: var(--mute); font-size: 10.5px; }+ .tp-read .sw { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -2px; margin-right: 6px; box-shadow: 0 0 0 1px rgba(236, 232, 225, .25); }++ /* Stage 5: two colour buffers and a flip. */+ .tp-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }+ .tp-fb { display: grid; gap: 4px; min-width: 0; font: 500 10.5px/1.35 var(--font-mono); color: var(--mute); }+ .tp-fb svg { display: block; width: 100%; height: auto; border-radius: 5px; border: 1px solid var(--line-2); background: #07080b; }+ .tp-fb.scan svg { border-color: color-mix(in srgb, var(--c-ps) 80%, transparent); box-shadow: 0 0 16px -5px rgba(122, 162, 247, .7); }+ .tp-fb.scan { color: var(--c-ps); }+ .tp-fb.ghost svg { border-style: dashed; background: transparent; }+ .tp-fb b { display: block; color: var(--bone); font-weight: 600; }+ .tp-flow > .bx.wide { flex-grow: 1.6; }+ .bx > .tp-fb:first-child { margin-bottom: 8px; }+ .bx > .tp-pair { margin-top: 8px; }+ .tp-side > svg { max-width: 200px; }++ @media (max-width: 760px) {+ .tp-rail { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; gap: 26px; }+ .tp-card { grid-row: auto; grid-template-rows: none; grid-template-columns: 112px minmax(0, 1fr); gap: 6px 14px; align-items: start; }+ .tp-card > * { grid-column: 2; }+ .tp-card > .tp-th { grid-column: 1; grid-row: 1 / span 4; }+ .tp-card + .tp-card::before { content: "↓"; left: 50px; top: -20px; }+ .tp-split, .tp-s4 { grid-template-columns: minmax(0, 1fr); }+ .tp-split > :first-child { max-width: 240px; }+ .tp-lane, .tp-read { grid-template-columns: minmax(0, 1fr); gap: 6px; }+ .tp-flow { flex-direction: column; }+ .tp-flow > .ar { transform: rotate(90deg); flex-basis: auto; }+ .tp-bytes { grid-template-columns: 40px repeat(7, minmax(0, 1fr)); gap: 3px; }+ .tp-bytes .v small { display: none; }+ .tp-bytes .f { padding: 5px 2px; font-size: 10px; }+ .tp-bytes .f small { font-size: 8.5px; }+ }+@media (max-width: 960px) {.doc { grid-template-columns: 1fr; gap: 28px; } .toc { position: static; display: flex; flex-wrap: wrap; gap: 6px 18px; } .toc a { padding: 2px 0; border-left: 0; }}@@ -327,9 +447,104 @@<span class="num">02</span><h2>Side by side: drawing one triangle in WebGL vs. the RSX</h2><p>Every graphics programmer learns by drawing a single coloured triangle. Walking through the <b>five stages</b> of that one triangle side by side makes the PS3 click—and explains every optimization we had to build for Three.js later.</p>+ <p>Ours has a red, a green and a blue corner, so you can follow it. At each stage it is something different—84 bytes, three vertices, two uniforms, 259,200 pixels, a frame on the TV—and the GPU math on the way is the same on both machines. What differs is who carries it from one stage to the next.</p>++ <svg class="tp-defs" aria-hidden="true" focusable="false">+ <defs>+ <linearGradient id="tp-r" gradientUnits="userSpaceOnUse" x1="50" y1="100" x2="50" y2="0"><stop offset="0" stop-color="#000"/><stop offset="1" stop-color="#f00"/></linearGradient>+ <linearGradient id="tp-g" gradientUnits="userSpaceOnUse" x1="80" y1="60" x2="0" y2="100"><stop offset="0" stop-color="#000"/><stop offset="1" stop-color="#0f0"/></linearGradient>+ <linearGradient id="tp-b" gradientUnits="userSpaceOnUse" x1="20" y1="60" x2="100" y2="100"><stop offset="0" stop-color="#000"/><stop offset="1" stop-color="#00f"/></linearGradient>+ <linearGradient id="tp-rt" gradientUnits="userSpaceOnUse" x1="50" y1="100" x2="50" y2="0"><stop offset="0" stop-color="#000"/><stop offset="1" stop-color="#f00"/></linearGradient>+ <linearGradient id="tp-gt" gradientUnits="userSpaceOnUse" x1="80" y1="60" x2="0" y2="100"><stop offset="0" stop-color="#000"/><stop offset="1" stop-color="#00d900"/></linearGradient>+ <linearGradient id="tp-bt" gradientUnits="userSpaceOnUse" x1="20" y1="60" x2="100" y2="100"><stop offset="0" stop-color="#000"/><stop offset="1" stop-color="#000066"/></linearGradient>+ <!-- A triangle's corners are 1 in one channel each, so three gradients added (screen, one channel apiece) are the exact interpolation. -->+ <symbol id="tp-tri" viewBox="0 0 100 100" preserveAspectRatio="none" overflow="visible"><g style="isolation:isolate"><path d="M50 0L0 100H100Z" fill="#000"/><path d="M50 0L0 100H100Z" fill="url(#tp-r)" style="mix-blend-mode:screen"/><path d="M50 0L0 100H100Z" fill="url(#tp-g)" style="mix-blend-mode:screen"/><path d="M50 0L0 100H100Z" fill="url(#tp-b)" style="mix-blend-mode:screen"/></g></symbol>+ <symbol id="tp-tri-t" viewBox="0 0 100 100" preserveAspectRatio="none" overflow="visible"><g style="isolation:isolate"><path d="M50 0L0 100H100Z" fill="#000"/><path d="M50 0L0 100H100Z" fill="url(#tp-rt)" style="mix-blend-mode:screen"/><path d="M50 0L0 100H100Z" fill="url(#tp-gt)" style="mix-blend-mode:screen"/><path d="M50 0L0 100H100Z" fill="url(#tp-bt)" style="mix-blend-mode:screen"/></g></symbol>+ <!-- The 1080p surface in 60 × 60 blocks: a block is lit where its centre pixel is inside the triangle, in that pixel's colour. -->+ <symbol id="tp-px" viewBox="0 0 1920 1080"><rect x="905" y="305" width="50" height="50" rx="8" fill="#e21303"/><rect x="965" y="305" width="50" height="50" rx="8" fill="#e20509"/><rect x="845" y="365" width="50" height="50" rx="8" fill="#c62c02"/><rect x="905" y="365" width="50" height="50" rx="8" fill="#c61f08"/><rect x="965" y="365" width="50" height="50" rx="8" fill="#c6110f"/><rect x="1025" y="365" width="50" height="50" rx="8" fill="#c60415"/><rect x="785" y="425" width="50" height="50" rx="8" fill="#aa4601"/><rect x="845" y="425" width="50" height="50" rx="8" fill="#aa3808"/><rect x="905" y="425" width="50" height="50" rx="8" fill="#aa2b0e"/><rect x="965" y="425" width="50" height="50" rx="8" fill="#aa1d14"/><rect x="1025" y="425" width="50" height="50" rx="8" fill="#aa101b"/><rect x="1085" y="425" width="50" height="50" rx="8" fill="#aa0221"/><rect x="725" y="485" width="50" height="50" rx="8" fill="#8d6000"/><rect x="785" y="485" width="50" height="50" rx="8" fill="#8d5207"/><rect x="845" y="485" width="50" height="50" rx="8" fill="#8d440d"/><rect x="905" y="485" width="50" height="50" rx="8" fill="#8d3714"/><rect x="965" y="485" width="50" height="50" rx="8" fill="#8d291a"/><rect x="1025" y="485" width="50" height="50" rx="8" fill="#8d1c20"/><rect x="1085" y="485" width="50" height="50" rx="8" fill="#8d0e27"/><rect x="1145" y="485" width="50" height="50" rx="8" fill="#8d012d"/><rect x="725" y="545" width="50" height="50" rx="8" fill="#716c06"/><rect x="785" y="545" width="50" height="50" rx="8" fill="#715e0c"/><rect x="845" y="545" width="50" height="50" rx="8" fill="#715113"/><rect x="905" y="545" width="50" height="50" rx="8" fill="#714319"/><rect x="965" y="545" width="50" height="50" rx="8" fill="#713520"/><rect x="1025" y="545" width="50" height="50" rx="8" fill="#712826"/><rect x="1085" y="545" width="50" height="50" rx="8" fill="#711a2c"/><rect x="1145" y="545" width="50" height="50" rx="8" fill="#710d33"/><rect x="665" y="605" width="50" height="50" rx="8" fill="#558505"/><rect x="725" y="605" width="50" height="50" rx="8" fill="#55780c"/><rect x="785" y="605" width="50" height="50" rx="8" fill="#556a12"/><rect x="845" y="605" width="50" height="50" rx="8" fill="#555d19"/><rect x="905" y="605" width="50" height="50" rx="8" fill="#554f1f"/><rect x="965" y="605" width="50" height="50" rx="8" fill="#554125"/><rect x="1025" y="605" width="50" height="50" rx="8" fill="#55342c"/><rect x="1085" y="605" width="50" height="50" rx="8" fill="#552632"/><rect x="1145" y="605" width="50" height="50" rx="8" fill="#551938"/><rect x="1205" y="605" width="50" height="50" rx="8" fill="#550b3f"/><rect x="605" y="665" width="50" height="50" rx="8" fill="#389f05"/><rect x="665" y="665" width="50" height="50" rx="8" fill="#38910b"/><rect x="725" y="665" width="50" height="50" rx="8" fill="#388411"/><rect x="785" y="665" width="50" height="50" rx="8" fill="#387618"/><rect x="845" y="665" width="50" height="50" rx="8" fill="#38691e"/><rect x="905" y="665" width="50" height="50" rx="8" fill="#385b25"/><rect x="965" y="665" width="50" height="50" rx="8" fill="#384e2b"/><rect x="1025" y="665" width="50" height="50" rx="8" fill="#384031"/><rect x="1085" y="665" width="50" height="50" rx="8" fill="#383238"/><rect x="1145" y="665" width="50" height="50" rx="8" fill="#38253e"/><rect x="1205" y="665" width="50" height="50" rx="8" fill="#381744"/><rect x="1265" y="665" width="50" height="50" rx="8" fill="#380a4b"/><rect x="545" y="725" width="50" height="50" rx="8" fill="#1cb804"/><rect x="605" y="725" width="50" height="50" rx="8" fill="#1cab0a"/><rect x="665" y="725" width="50" height="50" rx="8" fill="#1c9d11"/><rect x="725" y="725" width="50" height="50" rx="8" fill="#1c9017"/><rect x="785" y="725" width="50" height="50" rx="8" fill="#1c821d"/><rect x="845" y="725" width="50" height="50" rx="8" fill="#1c7524"/><rect x="905" y="725" width="50" height="50" rx="8" fill="#1c672a"/><rect x="965" y="725" width="50" height="50" rx="8" fill="#1c5a31"/><rect x="1025" y="725" width="50" height="50" rx="8" fill="#1c4c37"/><rect x="1085" y="725" width="50" height="50" rx="8" fill="#1c3e3d"/><rect x="1145" y="725" width="50" height="50" rx="8" fill="#1c3144"/><rect x="1205" y="725" width="50" height="50" rx="8" fill="#1c234a"/><rect x="1265" y="725" width="50" height="50" rx="8" fill="#1c1650"/><rect x="1325" y="725" width="50" height="50" rx="8" fill="#1c0857"/></symbol>+ <symbol id="tp-px-half" viewBox="0 0 1920 1080"><rect x="905" y="305" width="50" height="50" rx="8" fill="#e21303"/><rect x="965" y="305" width="50" height="50" rx="8" fill="#e20509"/><rect x="845" y="365" width="50" height="50" rx="8" fill="#c62c02"/><rect x="905" y="365" width="50" height="50" rx="8" fill="#c61f08"/><rect x="965" y="365" width="50" height="50" rx="8" fill="#c6110f"/><rect x="1025" y="365" width="50" height="50" rx="8" fill="#c60415"/><rect x="785" y="425" width="50" height="50" rx="8" fill="#aa4601"/><rect x="845" y="425" width="50" height="50" rx="8" fill="#aa3808"/><rect x="905" y="425" width="50" height="50" rx="8" fill="#aa2b0e"/><rect x="965" y="425" width="50" height="50" rx="8" fill="#aa1d14"/><rect x="1025" y="425" width="50" height="50" rx="8" fill="#aa101b"/><rect x="1085" y="425" width="50" height="50" rx="8" fill="#aa0221"/><rect x="725" y="485" width="50" height="50" rx="8" fill="#8d6000"/><rect x="785" y="485" width="50" height="50" rx="8" fill="#8d5207"/><rect x="845" y="485" width="50" height="50" rx="8" fill="#8d440d"/><rect x="905" y="485" width="50" height="50" rx="8" fill="#8d3714"/><rect x="965" y="485" width="50" height="50" rx="8" fill="#8d291a"/><rect x="1025" y="485" width="50" height="50" rx="8" fill="#8d1c20"/><rect x="1085" y="485" width="50" height="50" rx="8" fill="#8d0e27"/><rect x="1145" y="485" width="50" height="50" rx="8" fill="#8d012d"/><rect x="725" y="545" width="50" height="50" rx="8" fill="#716c06"/><rect x="785" y="545" width="50" height="50" rx="8" fill="#715e0c"/><rect x="845" y="545" width="50" height="50" rx="8" fill="#715113"/><path d="M960 270L480 810H1440Z" fill="none" stroke="#ece8e1" stroke-opacity=".35" stroke-width="8" stroke-dasharray="24 18"/></symbol>+ </defs>+ </svg>++ <figure class="dg">+ <span class="ttl">One RGB triangle through the five stages</span>+ <div class="tp-rail">+ <div class="tp-card">+ <span class="tp-n"><b>1</b> · Upload</span>+ <div class="tp-th"><svg viewBox="0 0 160 110" role="img" aria-label="Three rows of seven floats: a position and a colour for each vertex">+ <text x="11" y="19" font-size="8.5">x y z</text><text x="71" y="19" font-size="8.5">r g b a</text>+ <g><rect x="11" y="26" width="18" height="20" rx="3" fill="#2a2f3a"/><rect x="31" y="26" width="18" height="20" rx="3" fill="#2a2f3a"/><rect x="51" y="26" width="18" height="20" rx="3" fill="#2a2f3a"/><rect x="71" y="26" width="18" height="20" rx="3" fill="#ff2a2a"/><rect x="91" y="26" width="18" height="20" rx="3" fill="#15181f"/><rect x="111" y="26" width="18" height="20" rx="3" fill="#15181f"/><rect x="131" y="26" width="18" height="20" rx="3" fill="#5b606b"/></g>+ <g><rect x="11" y="50" width="18" height="20" rx="3" fill="#2a2f3a"/><rect x="31" y="50" width="18" height="20" rx="3" fill="#2a2f3a"/><rect x="51" y="50" width="18" height="20" rx="3" fill="#2a2f3a"/><rect x="71" y="50" width="18" height="20" rx="3" fill="#15181f"/><rect x="91" y="50" width="18" height="20" rx="3" fill="#22e04a"/><rect x="111" y="50" width="18" height="20" rx="3" fill="#15181f"/><rect x="131" y="50" width="18" height="20" rx="3" fill="#5b606b"/></g>+ <g><rect x="11" y="74" width="18" height="20" rx="3" fill="#2a2f3a"/><rect x="31" y="74" width="18" height="20" rx="3" fill="#2a2f3a"/><rect x="51" y="74" width="18" height="20" rx="3" fill="#2a2f3a"/><rect x="71" y="74" width="18" height="20" rx="3" fill="#15181f"/><rect x="91" y="74" width="18" height="20" rx="3" fill="#15181f"/><rect x="111" y="74" width="18" height="20" rx="3" fill="#3b5bff"/><rect x="131" y="74" width="18" height="20" rx="3" fill="#5b606b"/></g>+ </svg></div>+ <span class="tp-is">84 bytes</span>+ <div class="tp-w"><span>WebGL</span><code>bufferData</code>; the driver picks the memory</div><div class="tp-w you"><span>PS3 RSX</span>you place it in GDDR3, fence, flush</div>+ </div>+ <div class="tp-card">+ <span class="tp-n"><b>2</b> · Shaders</span>+ <div class="tp-th"><svg viewBox="0 0 160 110" role="img" aria-label="Three coloured points in clip space, joined by dashed edges">+ <rect x="36" y="11" width="88" height="88" fill="none" stroke="#ece8e1" stroke-opacity=".14"/><path d="M80 11V99M36 55H124" stroke="#ece8e1" stroke-opacity=".1"/>+ <path d="M80 33L58 77H102Z" fill="none" stroke="#ece8e1" stroke-opacity=".45" stroke-dasharray="3 3"/>+ <circle cx="80" cy="33" r="5" fill="#ff2a2a"/><circle cx="58" cy="77" r="5" fill="#22e04a"/><circle cx="102" cy="77" r="5" fill="#3b5bff"/>+ </svg></div>+ <span class="tp-is">3 vertices</span>+ <div class="tp-w"><span>WebGL</span>GLSL, compiled on the user’s machine</div><div class="tp-w you"><span>PS3 RSX</span>assembled offline; the fragment code copied into VRAM</div>+ </div>+ <div class="tp-card">+ <span class="tp-n"><b>3</b> · Uniforms</span>+ <div class="tp-th"><svg viewBox="0 0 160 110" role="img" aria-label="The RGB triangle, times a warm tint, makes the tinted triangle">+ <use href="#tp-tri" x="8" y="34" width="48" height="42"/>+ <text x="63" y="60" font-size="11">×</text><rect x="72" y="45" width="16" height="16" rx="4" fill="rgb(255,217,102)"/><text x="93" y="60" font-size="11">=</text>+ <use href="#tp-tri-t" x="104" y="34" width="48" height="42"/>+ <text x="80" y="92" font-size="8.5" text-anchor="middle">uMVP · uTint</text>+ </svg></div>+ <span class="tp-is">2 uniforms</span>+ <div class="tp-w"><span>WebGL</span>one call, either stage</div><div class="tp-w you"><span>PS3 RSX</span>vertex: registers; fragment: a patch in VRAM</div>+ </div>+ <div class="tp-card">+ <span class="tp-n"><b>4</b> · Draw</span>+ <div class="tp-th"><svg viewBox="0 0 160 110" role="img" aria-label="The triangle as lit pixels on a 1080p grid">+ <rect x="8" y="10" width="144" height="81" fill="#0b0d11" stroke="#ece8e1" stroke-opacity=".16"/>+ <use href="#tp-px" x="8" y="10" width="144" height="81"/>+ <text x="80" y="104" font-size="8.5" text-anchor="middle">1920 × 1080</text>+ </svg></div>+ <span class="tp-is">259,200 pixels</span>+ <div class="tp-w"><span>WebGL</span>+Y up, by default</div><div class="tp-w you"><span>PS3 RSX</span>your surface, your viewport, Y flipped</div>+ </div>+ <div class="tp-card">+ <span class="tp-n"><b>5</b> · Present</span>+ <div class="tp-th"><svg viewBox="0 0 160 110" role="img" aria-label="The triangle on a TV">+ <rect x="18" y="10" width="124" height="72" rx="5" fill="#0b0d11" stroke="#ece8e1" stroke-opacity=".35" stroke-width="1.5"/>+ <use href="#tp-px" x="22" y="14" width="116" height="65.25"/>+ <path d="M72 83L68 94M88 83L92 94M56 95H104" stroke="#ece8e1" stroke-opacity=".35" stroke-width="1.5" fill="none"/>+ </svg></div>+ <span class="tp-is">1 frame on the TV</span>+ <div class="tp-w"><span>WebGL</span>return from <code>request<wbr>Animation<wbr>Frame</code></div><div class="tp-w you"><span>PS3 RSX</span>fence, rewind the FIFO, flip</div>+ </div>+ </div>+ <p class="lg"><span><i class="you"></i>the driver’s job in a browser, ours on a PS3</span></p>+ <figcaption>The rasterizer, the interpolation and the pixels are the same on both: the RSX is a GPU like any other once a draw starts. Everything that gets the triangle to that point, and from there to the TV, is the driver’s in a browser and your C code’s on a PS3. The five stages below zoom in one at a time.</figcaption>+ </figure><h3>Stage 1 · Uploading vertex data</h3><p>In WebGL you hand a <code>Float32Array</code> to the driver and forget where it lives. On the RSX you carve aligned bytes out of GDDR3 yourself, enforce a PowerPC memory barrier, convert the CPU pointer into an RSX offset, and flush the GPU’s vertex cache:</p>+ <figure class="dg">+ <span class="ttl">Stage 1 · The triangle as 84 bytes, and where they go</span>+ <div class="tp-bytes" role="img" aria-label="Three vertices of seven floats each. Vertex 0: position 0, 0.5, 0, colour red 1, 0, 0, 1. Vertex 1: position −0.5, −0.5, 0, colour green. Vertex 2: position 0.5, −0.5, 0, colour blue.">+ <span></span><span class="h grp">position</span><span class="h grp">colour</span>+ <span></span><span class="h">x +0</span><span class="h">y +4</span><span class="h">z +8</span><span class="h">r +12</span><span class="h">g +16</span><span class="h">b +20</span><span class="h">a +24</span>+ <span class="v"><i style="background:#ff2a2a"></i>v0 <small>+0</small></span><span class="f">0<small>00 00 00 00</small></span><span class="f">0.5<small>3f 00 00 00</small></span><span class="f">0<small>00 00 00 00</small></span><span class="f r">1<small>3f 80 00 00</small></span><span class="f">0<small>00 00 00 00</small></span><span class="f">0<small>00 00 00 00</small></span><span class="f">1<small>3f 80 00 00</small></span>+ <span class="v"><i style="background:#22e04a"></i>v1 <small>+28</small></span><span class="f">−0.5<small>bf 00 00 00</small></span><span class="f">−0.5<small>bf 00 00 00</small></span><span class="f">0<small>00 00 00 00</small></span><span class="f">0<small>00 00 00 00</small></span><span class="f g">1<small>3f 80 00 00</small></span><span class="f">0<small>00 00 00 00</small></span><span class="f">1<small>3f 80 00 00</small></span>+ <span class="v"><i style="background:#3b5bff"></i>v2 <small>+56</small></span><span class="f">0.5<small>3f 00 00 00</small></span><span class="f">−0.5<small>bf 00 00 00</small></span><span class="f">0<small>00 00 00 00</small></span><span class="f">0<small>00 00 00 00</small></span><span class="f">0<small>00 00 00 00</small></span><span class="f b">1<small>3f 80 00 00</small></span><span class="f">1<small>3f 80 00 00</small></span>+ </div>+ <div class="tp-lanes">+ <div class="tp-lane"><span class="tp-lab">WebGL</span>+ <div class="tp-flow"><div class="bx"><b><code>Float32Array</code></b><small>in the JS heap; little-endian on x86 and ARM, so 0.5 is 00 00 00 3f</small></div><span class="ar">→</span><div class="bx"><b><code>gl.bufferData</code></b><small>hands the bytes to the driver</small></div><span class="ar">→</span><div class="bx fog"><b>Somewhere</b><small>VRAM or system memory: the driver decides, and may move it later</small></div></div></div>+ <div class="tp-lane rsx"><span class="tp-lab">PS3 RSX</span>+ <div class="tp-flow"><div class="bx"><b><code>Float32Array</code></b><small>in XDR; big-endian, so 0.5 is 3f 00 00 00</small></div><span class="ar">→</span><div class="bx you"><b><code>memcpy</code>, <code>eieio</code></b><small>into rsxMemalign(64, 84)</small></div><span class="ar">→</span><div class="bx"><b>GDDR3, at <code>vb_off</code></b><small>an offset the RSX reads, not a pointer</small></div><span class="ar">→</span><div class="bx you"><b>Cache flushed</b><small>rsxInvalidateVertexCache</small></div></div></div>+ </div>+ <figcaption>Seven floats a vertex, a position and a colour, so the vertices are 28 bytes apart: the stride both APIs are given in stage 4. The hex is big-endian, the order the Cell stores the floats in and the RSX reads them in, so the bytes cross into VRAM exactly as they are.</figcaption>+ </figure><div class="two"><div><span class="lbl">WebGL</span><pre class="code js">// The driver allocates, aligns,// migrates and caches it for you.@@ -348,6 +563,29 @@ rsxInvalidateVertexCache(ctx); // old vertices are stale</pre></div><h3>Stage 2 · Writing and loading shaders</h3><p>In WebGL, GLSL strings compile on the user’s machine at run time. On the RSX, shaders are assembled <b>offline</b> into separate <code>!!VP2.0</code> and <code>!!FP2.0</code> microcode (<code>cgcomp -a</code>). Vertex microcode goes inline over the FIFO, but <b>fragment microcode has to be copied into 64-byte-aligned VRAM</b>, because the RSX fetches pixel instructions straight from GDDR3:</p>+ <figure class="dg">+ <span class="ttl">Stage 2 · Three vertices, and the processors that run the programs</span>+ <div class="tp-split" style="--tp-left: 170px">+ <svg class="tp" viewBox="0 0 200 200" role="img" aria-label="Clip space from −1 to 1 on both axes, +Y up, with the three vertices at (0, 0.5) in red, (−0.5, −0.5) in green and (0.5, −0.5) in blue, joined by dashed edges">+ <rect x="20" y="20" width="160" height="160" fill="none" stroke="#ece8e1" stroke-opacity=".16"/>+ <path d="M100 20V180M20 100H180" stroke="#ece8e1" stroke-opacity=".1"/>+ <path d="M100 60L60 140H140Z" fill="none" stroke="#ece8e1" stroke-opacity=".5" stroke-dasharray="4 4"/>+ <circle cx="100" cy="60" r="7" fill="#ff2a2a"/><circle cx="60" cy="140" r="7" fill="#22e04a"/><circle cx="140" cy="140" r="7" fill="#3b5bff"/>+ <text x="100" y="46" font-size="10" text-anchor="middle">(0, 0.5)</text><text x="60" y="160" font-size="10" text-anchor="middle">(−0.5, −0.5)</text><text x="140" y="160" font-size="10" text-anchor="middle">(0.5, −0.5)</text>+ <text x="105" y="31" font-size="9">+Y</text><text x="164" y="94" font-size="9">+X</text>+ <text x="100" y="196" font-size="9" text-anchor="middle">clip space, w = 1</text>+ </svg>+ <div class="tp-lanes">+ <div class="tp-lane"><span class="tp-lab">WebGL</span>+ <div class="tp-flow"><div class="bx"><b>GLSL source</b><small>strings, shipped with the page</small></div><span class="ar">→</span><div class="bx"><b>The driver compiles</b><small>on the user’s machine, at run time</small></div><span class="ar">→</span><div class="bx"><b>One pool of cores</b><small>vertices and pixels alike</small><span class="tp-cores"><i class="r"></i><i class="g"></i><i class="b"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i></span></div></div></div>+ <div class="tp-lane rsx"><span class="tp-lab">RSX vertex</span>+ <div class="tp-flow"><div class="bx you"><b><code>!!VP2.0</code></b><small>cgcomp, offline</small></div><span class="ar">→</span><div class="bx you"><b>Microcode</b><small>sent inline, through the FIFO</small></div><span class="ar">→</span><div class="bx"><b>8 vertex units</b><small>a vertex each</small><span class="tp-cores"><i class="r"></i><i class="g"></i><i class="b"></i><i></i><i></i><i></i><i></i><i></i></span></div></div></div>+ <div class="tp-lane rsx"><span class="tp-lab">RSX fragment</span>+ <div class="tp-flow"><div class="bx you"><b><code>!!FP2.0</code></b><small>cgcomp, offline</small></div><span class="ar">→</span><div class="bx you"><b>Microcode, in VRAM</b><small>64-byte aligned, at <code>fp_off</code></small></div><span class="ar">→</span><div class="bx"><b>24 pixel pipelines</b><small>fetch it from GDDR3</small><span class="tp-cores"><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i><i class="f"></i></span></div></div></div>+ </div>+ </div>+ <figcaption>uMVP is the identity here, so clip space is just the positions. The vertex program sees three points and nothing between them: no pixel exists yet. The RSX runs the two programs on different processors, loaded two different ways; a unified GPU runs both on one pool of cores.</figcaption>+ </figure><div class="two"><div><span class="lbl">WebGL</span><pre class="code js">// GLSL, compiled at run time.gl_Position = uMVP * vec4(aPos, 1.0);@@ -370,6 +608,25 @@ rsxAddressToOffset(fp_vram, &fp_off);</pre></div><h3>Stage 3 · Updating uniforms (the biggest mental shift)</h3><p>In WebGL, vertex and fragment uniforms look identical. On the RSX they are <b>two completely different hardware mechanisms</b>:</p>+ <figure class="dg">+ <span class="ttl">Stage 3 · Two uniforms, kept in two different places</span>+ <div class="tp-split" style="--tp-left: 210px">+ <div class="tp-eq" role="img" aria-label="The interpolated vertex colours, times uTint (1, 0.85, 0.4), give the tinted triangle the fragment program writes">+ <div><svg viewBox="0 0 100 92"><use href="#tp-tri" x="4" y="4" width="92" height="84"/></svg><small>vColor</small></div>+ <div class="sw"><span>×</span><i></i><small>uTint<br>1, .85, .4</small></div>+ <div><svg viewBox="0 0 100 92"><use href="#tp-tri-t" x="4" y="4" width="92" height="84"/></svg><small>written</small></div>+ </div>+ <div class="tp-lanes">+ <div class="tp-lane"><span class="tp-lab">WebGL</span>+ <div class="tp-flow"><div class="bx"><b><code>uniformMatrix4fv</code>, <code>uniform4f</code></b><small>the same kind of call for either stage</small></div><span class="ar">→</span><div class="bx"><b>Uniform storage</b><small>the driver’s; both programs read it the same way</small></div></div></div>+ <div class="tp-lane rsx"><span class="tp-lab">RSX vertex</span>+ <div class="tp-flow"><div class="bx you"><b>uMVP, as rows</b><small>one block load through the FIFO</small></div><span class="ar">→</span><div class="bx"><b>Constant registers</b><span class="tp-regs q"><span><em>c[0]</em>1 0 0 0</span><span><em>c[1]</em>0 1 0 0</span><span><em>c[2]</em>0 0 1 0</span><span><em>c[3]</em>0 0 0 1</span></span></div></div></div>+ <div class="tp-lane rsx"><span class="tp-lab">RSX fragment</span>+ <div class="tp-flow"><div class="bx you"><b>uTint, halves swapped</b><small>rsxInlineTransfer into the program, then point the RSX at it again</small></div><span class="ar">→</span><div class="bx"><b>The program itself, in GDDR3</b><span class="tp-regs"><span><em>+0x00</em>MOV R1, c[0]</span><span class="hot"><em>+0x10</em>00003f80 999a3f59 cccd3ecc 00003f80</span><span><em>+0x20</em>MULR o[COLR], f[COL0], R1</span></span></div></div></div>+ </div>+ </div>+ <figcaption>The tint keeps red at 1 and takes green to 0.85 and blue to 0.4: the triangle on the right is what the fragment program writes. In WebGL both uniforms are one call each. On the RSX, uMVP becomes four registers loaded through the FIFO, and uTint becomes sixteen bytes in the middle of the fragment program, rewritten in VRAM whenever it changes.</figcaption>+ </figure><div class="two"><div><span class="lbl">WebGL</span><pre class="code js">// Symmetric across stages.gl.useProgram(program);@@ -392,12 +649,58 @@ rsxLoadFragmentProgramLocation(ctx, fp, fp_off,<h3>Stage 4 · Binding attributes, viewport and the draw</h3><p>In WebGL, OpenGL’s convention (+Y up, depth from −1 to 1) is automatic. On the RSX you bind the colour + <code>Z24S8</code> surface yourself, set a <b>negative-Y viewport scale</b> so Three.js’s +Y-up clip space lands right side up on the PS3’s top-down scanout, bind attributes by VRAM offset, and emit the draw packet into the FIFO:</p>+ <figure class="dg" id="tp-raster">+ <span class="ttl">Stage 4 · From three vertices to 259,200 pixels</span>+ <div class="tp-s4">+ <div class="tp-side">+ <svg class="tp" viewBox="0 0 200 200" role="img" aria-label="The three vertices in clip space, +Y up">+ <rect x="20" y="20" width="160" height="160" fill="none" stroke="#ece8e1" stroke-opacity=".16"/>+ <path d="M100 20V180M20 100H180" stroke="#ece8e1" stroke-opacity=".1"/>+ <path d="M100 60L60 140H140Z" fill="none" stroke="#ece8e1" stroke-opacity=".5" stroke-dasharray="4 4"/>+ <circle cx="100" cy="60" r="7" fill="#ff2a2a"/><circle cx="60" cy="140" r="7" fill="#22e04a"/><circle cx="140" cy="140" r="7" fill="#3b5bff"/>+ <text x="105" y="31" font-size="9">+Y</text><text x="164" y="94" font-size="9">+X</text>+ <text x="100" y="196" font-size="9" text-anchor="middle">clip space</text>+ </svg>+ <div class="tp-vp">+ <span>The viewport</span>+ <code>x = 960 · x<sub>ndc</sub> + 960</code>+ <code>y = <b data-o="sy">−540</b> · y<sub>ndc</sub> + 540</code>+ <div class="tp-tog" role="group" aria-label="The viewport’s Y scale"><button type="button" data-sy="-1" aria-pressed="true">scale.y −540</button><button type="button" data-sy="1" aria-pressed="false">+540</button></div>+ <p data-o="note">Upright. Clip space’s +Y is up and the TV’s row 0 is its top, so the scale is negative.</p>+ </div>+ </div>+ <div class="tp-screen">+ <div class="edge"><span class="rsx">↓ RSX row 0: the top of the TV</span><span>1920 × 1080</span></div>+ <svg class="tp tp-px" viewBox="0 0 1920 1080" tabindex="0" role="img" aria-label="The 1920 by 1080 surface in 40-pixel squares; the squares inside the triangle are lit in their pixels’ colours. Point at one, or use the arrow keys, to read it below.">+ <defs><pattern id="tp-cell" width="40" height="40" patternUnits="userSpaceOnUse"><path d="M40 0H0V40" fill="none" stroke="#ece8e1" stroke-opacity=".07" stroke-width="2"/></pattern></defs>+ <rect width="1920" height="1080" fill="#07080b"/><rect width="1920" height="1080" fill="url(#tp-cell)"/>+ <g data-cells><rect x="923" y="283" width="34" height="34" rx="5" fill="#f10b01"/><rect x="963" y="283" width="34" height="34" rx="5" fill="#f10105"/><rect x="883" y="323" width="34" height="34" rx="5" fill="#de1c00"/><rect x="923" y="323" width="34" height="34" rx="5" fill="#de1305"/><rect x="963" y="323" width="34" height="34" rx="5" fill="#de0a09"/><rect x="1003" y="323" width="34" height="34" rx="5" fill="#de000d"/><rect x="883" y="363" width="34" height="34" rx="5" fill="#cb2404"/><rect x="923" y="363" width="34" height="34" rx="5" fill="#cb1b08"/><rect x="963" y="363" width="34" height="34" rx="5" fill="#cb120d"/><rect x="1003" y="363" width="34" height="34" rx="5" fill="#cb0911"/><rect x="843" y="403" width="34" height="34" rx="5" fill="#b83504"/><rect x="883" y="403" width="34" height="34" rx="5" fill="#b82c08"/><rect x="923" y="403" width="34" height="34" rx="5" fill="#b8230c"/><rect x="963" y="403" width="34" height="34" rx="5" fill="#b81a10"/><rect x="1003" y="403" width="34" height="34" rx="5" fill="#b81115"/><rect x="1043" y="403" width="34" height="34" rx="5" fill="#b80819"/><rect x="803" y="443" width="34" height="34" rx="5" fill="#a54603"/><rect x="843" y="443" width="34" height="34" rx="5" fill="#a53d07"/><rect x="883" y="443" width="34" height="34" rx="5" fill="#a5340c"/><rect x="923" y="443" width="34" height="34" rx="5" fill="#a52b10"/><rect x="963" y="443" width="34" height="34" rx="5" fill="#a52214"/><rect x="1003" y="443" width="34" height="34" rx="5" fill="#a51918"/><rect x="1043" y="443" width="34" height="34" rx="5" fill="#a5101d"/><rect x="1083" y="443" width="34" height="34" rx="5" fill="#a50721"/><rect x="763" y="483" width="34" height="34" rx="5" fill="#925703"/><rect x="803" y="483" width="34" height="34" rx="5" fill="#924e07"/><rect x="843" y="483" width="34" height="34" rx="5" fill="#92450b"/><rect x="883" y="483" width="34" height="34" rx="5" fill="#923c0f"/><rect x="923" y="483" width="34" height="34" rx="5" fill="#923314"/><rect x="963" y="483" width="34" height="34" rx="5" fill="#922a18"/><rect x="1003" y="483" width="34" height="34" rx="5" fill="#92211c"/><rect x="1043" y="483" width="34" height="34" rx="5" fill="#921820"/><rect x="1083" y="483" width="34" height="34" rx="5" fill="#920f25"/><rect x="1123" y="483" width="34" height="34" rx="5" fill="#920629"/><rect x="723" y="523" width="34" height="34" rx="5" fill="#7f6802"/><rect x="763" y="523" width="34" height="34" rx="5" fill="#7f5f06"/><rect x="803" y="523" width="34" height="34" rx="5" fill="#7f560b"/><rect x="843" y="523" width="34" height="34" rx="5" fill="#7f4d0f"/><rect x="883" y="523" width="34" height="34" rx="5" fill="#7f4413"/><rect x="923" y="523" width="34" height="34" rx="5" fill="#7f3b17"/><rect x="963" y="523" width="34" height="34" rx="5" fill="#7f321c"/><rect x="1003" y="523" width="34" height="34" rx="5" fill="#7f2920"/><rect x="1043" y="523" width="34" height="34" rx="5" fill="#7f2024"/><rect x="1083" y="523" width="34" height="34" rx="5" fill="#7f1728"/><rect x="1123" y="523" width="34" height="34" rx="5" fill="#7f0e2d"/><rect x="1163" y="523" width="34" height="34" rx="5" fill="#7f0531"/><rect x="683" y="563" width="34" height="34" rx="5" fill="#6c7902"/><rect x="723" y="563" width="34" height="34" rx="5" fill="#6c7006"/><rect x="763" y="563" width="34" height="34" rx="5" fill="#6c670a"/><rect x="803" y="563" width="34" height="34" rx="5" fill="#6c5e0f"/><rect x="843" y="563" width="34" height="34" rx="5" fill="#6c5513"/><rect x="883" y="563" width="34" height="34" rx="5" fill="#6c4c17"/><rect x="923" y="563" width="34" height="34" rx="5" fill="#6c431b"/><rect x="963" y="563" width="34" height="34" rx="5" fill="#6c3a20"/><rect x="1003" y="563" width="34" height="34" rx="5" fill="#6c3124"/><rect x="1043" y="563" width="34" height="34" rx="5" fill="#6c2828"/><rect x="1083" y="563" width="34" height="34" rx="5" fill="#6c1f2c"/><rect x="1123" y="563" width="34" height="34" rx="5" fill="#6c1631"/><rect x="1163" y="563" width="34" height="34" rx="5" fill="#6c0d35"/><rect x="1203" y="563" width="34" height="34" rx="5" fill="#6c0339"/><rect x="643" y="603" width="34" height="34" rx="5" fill="#598a01"/><rect x="683" y="603" width="34" height="34" rx="5" fill="#598106"/><rect x="723" y="603" width="34" height="34" rx="5" fill="#59780a"/><rect x="763" y="603" width="34" height="34" rx="5" fill="#596f0e"/><rect x="803" y="603" width="34" height="34" rx="5" fill="#596612"/><rect x="843" y="603" width="34" height="34" rx="5" fill="#595d17"/><rect x="883" y="603" width="34" height="34" rx="5" fill="#59541b"/><rect x="923" y="603" width="34" height="34" rx="5" fill="#594b1f"/><rect x="963" y="603" width="34" height="34" rx="5" fill="#594223"/><rect x="1003" y="603" width="34" height="34" rx="5" fill="#593928"/><rect x="1043" y="603" width="34" height="34" rx="5" fill="#59302c"/><rect x="1083" y="603" width="34" height="34" rx="5" fill="#592730"/><rect x="1123" y="603" width="34" height="34" rx="5" fill="#591e34"/><rect x="1163" y="603" width="34" height="34" rx="5" fill="#591539"/><rect x="1203" y="603" width="34" height="34" rx="5" fill="#590c3d"/><rect x="1243" y="603" width="34" height="34" rx="5" fill="#590241"/><rect x="603" y="643" width="34" height="34" rx="5" fill="#479b01"/><rect x="643" y="643" width="34" height="34" rx="5" fill="#479205"/><rect x="683" y="643" width="34" height="34" rx="5" fill="#478909"/><rect x="723" y="643" width="34" height="34" rx="5" fill="#47800e"/><rect x="763" y="643" width="34" height="34" rx="5" fill="#477712"/><rect x="803" y="643" width="34" height="34" rx="5" fill="#476e16"/><rect x="843" y="643" width="34" height="34" rx="5" fill="#47651a"/><rect x="883" y="643" width="34" height="34" rx="5" fill="#475c1f"/><rect x="923" y="643" width="34" height="34" rx="5" fill="#475323"/><rect x="963" y="643" width="34" height="34" rx="5" fill="#474a27"/><rect x="1003" y="643" width="34" height="34" rx="5" fill="#47412b"/><rect x="1043" y="643" width="34" height="34" rx="5" fill="#473830"/><rect x="1083" y="643" width="34" height="34" rx="5" fill="#472f34"/><rect x="1123" y="643" width="34" height="34" rx="5" fill="#472638"/><rect x="1163" y="643" width="34" height="34" rx="5" fill="#471d3c"/><rect x="1203" y="643" width="34" height="34" rx="5" fill="#471441"/><rect x="1243" y="643" width="34" height="34" rx="5" fill="#470b45"/><rect x="1283" y="643" width="34" height="34" rx="5" fill="#470149"/><rect x="563" y="683" width="34" height="34" rx="5" fill="#34ac00"/><rect x="603" y="683" width="34" height="34" rx="5" fill="#34a305"/><rect x="643" y="683" width="34" height="34" rx="5" fill="#349a09"/><rect x="683" y="683" width="34" height="34" rx="5" fill="#34910d"/><rect x="723" y="683" width="34" height="34" rx="5" fill="#348811"/><rect x="763" y="683" width="34" height="34" rx="5" fill="#347f16"/><rect x="803" y="683" width="34" height="34" rx="5" fill="#34761a"/><rect x="843" y="683" width="34" height="34" rx="5" fill="#346d1e"/><rect x="883" y="683" width="34" height="34" rx="5" fill="#346422"/><rect x="923" y="683" width="34" height="34" rx="5" fill="#345b27"/><rect x="963" y="683" width="34" height="34" rx="5" fill="#34522b"/><rect x="1003" y="683" width="34" height="34" rx="5" fill="#34492f"/><rect x="1043" y="683" width="34" height="34" rx="5" fill="#344033"/><rect x="1083" y="683" width="34" height="34" rx="5" fill="#343738"/><rect x="1123" y="683" width="34" height="34" rx="5" fill="#342e3c"/><rect x="1163" y="683" width="34" height="34" rx="5" fill="#342540"/><rect x="1203" y="683" width="34" height="34" rx="5" fill="#341c44"/><rect x="1243" y="683" width="34" height="34" rx="5" fill="#341349"/><rect x="1283" y="683" width="34" height="34" rx="5" fill="#340a4d"/><rect x="1323" y="683" width="34" height="34" rx="5" fill="#340051"/><rect x="563" y="723" width="34" height="34" rx="5" fill="#21b404"/><rect x="603" y="723" width="34" height="34" rx="5" fill="#21ab08"/><rect x="643" y="723" width="34" height="34" rx="5" fill="#21a20d"/><rect x="683" y="723" width="34" height="34" rx="5" fill="#219911"/><rect x="723" y="723" width="34" height="34" rx="5" fill="#219015"/><rect x="763" y="723" width="34" height="34" rx="5" fill="#218719"/><rect x="803" y="723" width="34" height="34" rx="5" fill="#217e1e"/><rect x="843" y="723" width="34" height="34" rx="5" fill="#217522"/><rect x="883" y="723" width="34" height="34" rx="5" fill="#216c26"/><rect x="923" y="723" width="34" height="34" rx="5" fill="#21632a"/><rect x="963" y="723" width="34" height="34" rx="5" fill="#215a2f"/><rect x="1003" y="723" width="34" height="34" rx="5" fill="#215133"/><rect x="1043" y="723" width="34" height="34" rx="5" fill="#214837"/><rect x="1083" y="723" width="34" height="34" rx="5" fill="#213f3b"/><rect x="1123" y="723" width="34" height="34" rx="5" fill="#213640"/><rect x="1163" y="723" width="34" height="34" rx="5" fill="#212d44"/><rect x="1203" y="723" width="34" height="34" rx="5" fill="#212448"/><rect x="1243" y="723" width="34" height="34" rx="5" fill="#211b4c"/><rect x="1283" y="723" width="34" height="34" rx="5" fill="#211251"/><rect x="1323" y="723" width="34" height="34" rx="5" fill="#210955"/><rect x="523" y="763" width="34" height="34" rx="5" fill="#0ec504"/><rect x="563" y="763" width="34" height="34" rx="5" fill="#0ebc08"/><rect x="603" y="763" width="34" height="34" rx="5" fill="#0eb30c"/><rect x="643" y="763" width="34" height="34" rx="5" fill="#0eaa10"/><rect x="683" y="763" width="34" height="34" rx="5" fill="#0ea115"/><rect x="723" y="763" width="34" height="34" rx="5" fill="#0e9819"/><rect x="763" y="763" width="34" height="34" rx="5" fill="#0e8f1d"/><rect x="803" y="763" width="34" height="34" rx="5" fill="#0e8621"/><rect x="843" y="763" width="34" height="34" rx="5" fill="#0e7d26"/><rect x="883" y="763" width="34" height="34" rx="5" fill="#0e742a"/><rect x="923" y="763" width="34" height="34" rx="5" fill="#0e6b2e"/><rect x="963" y="763" width="34" height="34" rx="5" fill="#0e6232"/><rect x="1003" y="763" width="34" height="34" rx="5" fill="#0e5937"/><rect x="1043" y="763" width="34" height="34" rx="5" fill="#0e503b"/><rect x="1083" y="763" width="34" height="34" rx="5" fill="#0e473f"/><rect x="1123" y="763" width="34" height="34" rx="5" fill="#0e3e43"/><rect x="1163" y="763" width="34" height="34" rx="5" fill="#0e3548"/><rect x="1203" y="763" width="34" height="34" rx="5" fill="#0e2c4c"/><rect x="1243" y="763" width="34" height="34" rx="5" fill="#0e2350"/><rect x="1283" y="763" width="34" height="34" rx="5" fill="#0e1a54"/><rect x="1323" y="763" width="34" height="34" rx="5" fill="#0e1159"/><rect x="1363" y="763" width="34" height="34" rx="5" fill="#0e085d"/></g>+ <path data-o="edge" d="M960 270L480 810L1440 810Z" fill="none" stroke="#ece8e1" stroke-opacity=".55" stroke-width="3"/>+ <g data-o="dots" stroke="#07080b" stroke-width="5"><circle cx="960" cy="270" r="13" fill="#ff2a2a"/><circle cx="480" cy="810" r="13" fill="#22e04a"/><circle cx="1440" cy="810" r="13" fill="#3b5bff"/></g>+ <g data-o="labels" font-size="34" text-anchor="middle"><text x="960" y="238">(960, 270)</text><text x="480" y="862">(480, 810)</text><text x="1440" y="862">(1440, 810)</text></g>+ <rect data-o="hi" x="960" y="600" width="40" height="40" rx="6" fill="none" stroke="#fff" stroke-width="5"/>+ </svg>+ <div class="edge"><span>↑ WebGL row 0: the bottom</span><span>a square is 40 × 40 pixels</span></div>+ </div>+ </div>+ <dl class="tp-read" aria-live="polite">+ <dt>pixel</dt><dd data-o="px"><b>(980, 620)</b> on the TV: column 980, row 620 from the top</dd>+ <dt>raster</dt><dd data-o="raster">weights 0.351 · 0.303 · 0.346 → vColor (0.351, 0.303, 0.346)</dd>+ <dt>fragment</dt><dd data-o="frag"><i class="sw" style="background:#594223"></i>× uTint = (0.351, 0.258, 0.138) → 8 bits: 59 42 23</dd>+ <dt>WebGL</dt><dd data-o="gl">row 459 from the bottom · <code>readPixels(980, 459, …)</code> → <b>59 42 23 ff</b> <small>R G B A</small></dd>+ <dt class="rsx">PS3 RSX</dt><dd data-o="rsx">row 620 from the top · fb + 620 × 7680 + 980 × 4 = fb + 4,765,520 → <b>ff 59 42 23</b> <small>A R G B, one big-endian word</small></dd>+ </dl>+ <figcaption>A square is lit where the pixel at its centre is inside the triangle, in the colour that pixel gets. Point at one (or tap it, or use the arrow keys) to follow it: the rasterizer weighs the three vertex colours by how close the pixel is to each corner (<code>GCM_SHADE_MODEL_SMOOTH</code>; a <code>varying</code> in GLSL), the fragment program multiplies by uTint, and the result is 32 bits—which WebGL keeps behind <code>readPixels</code>, and the RSX keeps at an address you can compute: 7680 bytes is a row of the surface. Flip the viewport’s sign to see why the negative scale is there.</figcaption>+ </figure><div class="two"><div><span class="lbl">WebGL</span><pre class="code js">gl.viewport(0, 0, 1920, 1080);gl.clear(gl.COLOR_BUFFER_BIT |gl.DEPTH_BUFFER_BIT);+// xyz, then rgba 12 bytes ingl.vertexAttribPointer(0, 3, gl.FLOAT,false, 28, 0);+gl.vertexAttribPointer(1, 4, gl.FLOAT,+ false, 28, 12);gl.drawArrays(gl.TRIANGLES, 0, 3);</pre></div><div><span class="lbl">PS3 RSX</span><pre class="code">rsxSetSurface(ctx, &surface); // A8R8G8B8 + Z24S8rsxClearSurface(ctx, GCM_CLEAR_R | GCM_CLEAR_G |@@ -409,11 +712,42 @@ 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);+// The colour, 12 bytes in: v[3] in the vertex program+rsxBindVertexArrayAttrib(ctx, GCM_VERTEX_ATTRIB_COLOR0, 0,+ vb_off + 12, sizeof(TriVert), 4, GCM_VERTEX_DATA_TYPE_F32,+ GCM_LOCATION_RSX);rsxDrawVertexArray(ctx, GCM_TYPE_TRIANGLES, 0, 3);</pre></div></div><h3>Stage 5 · Presenting the frame (sync, rewind, flip)</h3><p>In WebGL, presentation is invisible—you just return from <code>requestAnimationFrame</code>. On the RSX, <em>nothing</em> reaches your TV until you flush the FIFO, fence the GPU, rewind the ring so it never overflows, wait for the previous flip, and queue the next scanout buffer:</p>+ <figure class="dg">+ <span class="ttl">Stage 5 · From finished pixels to the TV</span>+ <div class="tp-lanes">+ <div class="tp-lane"><span class="tp-lab">WebGL</span>+ <div class="tp-flow">+ <div class="bx wide"><b>Your callback returns</b><div class="tp-pair"><div class="tp-fb"><svg viewBox="0 0 1920 1080" role="img" aria-label="The canvas’s buffer, with the triangle in it"><use href="#tp-px" width="1920" height="1080"/></svg><span><b>canvas</b>drawn</span></div><div class="tp-fb ghost"><svg viewBox="0 0 1920 1080" role="img" aria-label="The front buffer, which the browser keeps"></svg><span><b>front</b>the browser’s</span></div></div></div>+ <span class="ar">→</span>+ <div class="bx"><b>The browser composites</b><small>the canvas into the page, on its own schedule</small></div>+ <span class="ar">→</span>+ <div class="bx wide"><b>At a vsync it picks</b><div class="tp-pair"><div class="tp-fb scan"><svg viewBox="0 0 1920 1080" role="img" aria-label="The browser window: the page, with the canvas in it">+ <rect width="1920" height="1080" fill="#0b0d11"/><rect width="1920" height="150" fill="#171a22"/>+ <circle cx="80" cy="75" r="22" fill="#3a3f4a"/><circle cx="150" cy="75" r="22" fill="#3a3f4a"/><circle cx="220" cy="75" r="22" fill="#3a3f4a"/><rect x="320" y="40" width="1100" height="70" rx="35" fill="#0b0d11"/>+ <g fill="#262a33"><rect x="100" y="250" width="540" height="40" rx="20"/><rect x="100" y="330" width="460" height="40" rx="20"/><rect x="100" y="410" width="560" height="40" rx="20"/><rect x="100" y="490" width="400" height="40" rx="20"/><rect x="100" y="900" width="1700" height="40" rx="20"/><rect x="100" y="980" width="1200" height="40" rx="20"/></g>+ <rect x="760" y="230" width="1060" height="596" fill="#07080b" stroke="#ece8e1" stroke-opacity=".3" stroke-width="6"/><use href="#tp-px" x="760" y="230" width="1060" height="596"/>+ </svg><span><b>window</b>on screen</span></div></div></div>+ </div></div>+ <div class="tp-lane rsx"><span class="tp-lab">PS3 RSX</span>+ <div class="tp-flow">+ <div class="bx wide"><b>Frame N</b><div class="tp-pair"><div class="tp-fb scan"><svg viewBox="0 0 1920 1080" role="img" aria-label="Buffer 0, finished, on HDMI"><use href="#tp-px" width="1920" height="1080"/></svg><span><b>fb 0</b>on HDMI</span></div><div class="tp-fb"><svg viewBox="0 0 1920 1080" role="img" aria-label="Buffer 1, half drawn"><use href="#tp-px-half" width="1920" height="1080"/></svg><span><b>fb 1</b>being drawn</span></div></div></div>+ <span class="ar">→</span>+ <div class="bx you"><b>Flip</b><small>flush · rsxFinish · rewind the FIFO · wait for the last flip · gcmSetFlip(fb 1)</small></div>+ <span class="ar">→</span>+ <div class="bx wide"><b>At vsync: frame N + 1</b><div class="tp-pair"><div class="tp-fb"><svg viewBox="0 0 1920 1080" role="img" aria-label="Buffer 0, the old frame, about to be cleared"><use href="#tp-px" width="1920" height="1080" opacity=".3"/></svg><span><b>fb 0</b>drawn next</span></div><div class="tp-fb scan"><svg viewBox="0 0 1920 1080" role="img" aria-label="Buffer 1, finished, on HDMI"><use href="#tp-px" width="1920" height="1080"/></svg><span><b>fb 1</b>on HDMI</span></div></div></div>+ </div></div>+ </div>+ <figcaption>Each colour buffer is 1920 × 1080 × 4 = 8,294,400 bytes of GDDR3, at an offset HDMI was given once, at boot (<code>gcmSetDisplayBuffer</code>). The RSX never draws into the buffer HDMI is reading: the flip swaps the two at vsync, and <code>fb ^= 1</code> sends the next frame to the other one. A browser keeps a front buffer too; it is just never yours.</figcaption>+ </figure><div class="two"><div><span class="lbl">WebGL</span><pre class="code js">// The browser flushes, waits for// vsync and composites for you.@@ -618,6 +952,91 @@ DP4 o[HPOS].w, v[0], c[3]; -> 6041ff80 (mask = XYZW!)</pre>import { $$, highlight } from "../../js/threert.js";import { guard } from "../../js/site.js";guard("code", () => { for (const el of $$(".code.js")) el.innerHTML = highlight(el.textContent); });++ // Stage 4's pixels: the squares follow the viewport's Y scale, and the readout follows the pointer (or the arrow keys).+ // The same arithmetic made the squares in the page, so it holds without the script too.+ guard("triangle", () => {+ const fig = document.getElementById("tp-raster");+ if (!fig) return;+ const svg = fig.querySelector(".tp-px");+ const cells = fig.querySelector("[data-cells]");+ const o = (k) => fig.querySelector(`[data-o="${k}"]`);+ const N = 40, COLS = 48, ROWS = 27, PITCH = 7680;+ const NDC = [[0, 0.5], [-0.5, -0.5], [0.5, -0.5]], TINT = [1, 0.85, 0.4];+ const NOTE = {+ "-1": "Upright. Clip space’s +Y is up and the TV’s row 0 is its top, so the scale is negative.",+ "1": "Upside down. That is OpenGL’s formula, for a framebuffer whose row 0 is the bottom; the RSX sends row 0 to the top of the TV.",+ };+ let sy = -1, cur = [24, 15];+ const verts = () => NDC.map(([x, y]) => [960 * x + 960, sy * 540 * y + 540]);+ const edge = (a, b, p) => (b[0] - a[0]) * (p[1] - a[1]) - (b[1] - a[1]) * (p[0] - a[0]);+ const hex = (n) => n.toString(16).padStart(2, "0");+ const f3 = (k) => k.toFixed(3);+ /** The pixel at the centre of square (cx, cy): its weights, its colour after uTint, and that colour's bytes. */+ function pixel(cx, cy) {+ const v = verts(), x = cx * N + N / 2, y = cy * N + N / 2, p = [x + 0.5, y + 0.5], A = edge(v[0], v[1], v[2]);+ const w = [edge(v[1], v[2], p) / A, edge(v[2], v[0], p) / A, edge(v[0], v[1], p) / A];+ const c = w.map((k, i) => k * TINT[i]);+ return { x, y, w, c, b: c.map((k) => hex(Math.round(Math.min(1, Math.max(0, k)) * 255))), inside: w.every((k) => k > 0) };+ }+ function draw() {+ let s = "";+ for (let cy = 0; cy < ROWS; cy++) for (let cx = 0; cx < COLS; cx++) {+ const p = pixel(cx, cy);+ if (p.inside) s += `<rect x="${cx * N + 3}" y="${cy * N + 3}" width="34" height="34" rx="5" fill="#${p.b.join("")}"/>`;+ }+ cells.innerHTML = s;+ const v = verts();+ o("edge").setAttribute("d", `M${v[0]}L${v[1]}L${v[2]}Z`);+ [...o("dots").children].forEach((d, i) => d.setAttribute("cy", v[i][1]));+ [...o("labels").children].forEach((t, i) => {+ t.setAttribute("y", v[i][1] < 540 ? v[i][1] - 32 : v[i][1] + 52);+ t.textContent = `(${v[i][0]}, ${v[i][1]})`;+ });+ }+ function read() {+ const [cx, cy] = cur, p = pixel(cx, cy), row = 1079 - p.y, at = `fb + ${p.y} × ${PITCH} + ${p.x} × 4 = fb + ${(p.y * PITCH + p.x * 4).toLocaleString("en-US")}`;+ o("hi").setAttribute("x", cx * N);+ o("hi").setAttribute("y", cy * N);+ o("px").innerHTML = `<b>(${p.x}, ${p.y})</b> on the TV: column ${p.x}, row ${p.y} from the top`;+ if (!p.inside) {+ o("raster").textContent = "outside the triangle: no fragment";+ o("frag").textContent = "the fragment program never runs here; the clear colour stays";+ o("gl").innerHTML = `row ${row} from the bottom`;+ o("rsx").innerHTML = `row ${p.y} from the top · ${at}`;+ return;+ }+ o("raster").textContent = `weights ${p.w.map(f3).join(" · ")} → vColor (${p.w.map(f3).join(", ")})`;+ o("frag").innerHTML = `<i class="sw" style="background:#${p.b.join("")}"></i>× uTint = (${p.c.map(f3).join(", ")}) → 8 bits: ${p.b.join(" ")}`;+ o("gl").innerHTML = `row ${row} from the bottom · <code>readPixels(${p.x}, ${row}, …)</code> → <b>${p.b.join(" ")} ff</b> <small>R G B A</small>`;+ o("rsx").innerHTML = `row ${p.y} from the top · ${at} → <b>ff ${p.b.join(" ")}</b> <small>A R G B, one big-endian word</small>`;+ }+ function point(e) {+ const r = svg.getBoundingClientRect();+ const cx = Math.floor(((e.clientX - r.left) / r.width) * COLS), cy = Math.floor(((e.clientY - r.top) / r.height) * ROWS);+ if (cx < 0 || cy < 0 || cx >= COLS || cy >= ROWS || (cx === cur[0] && cy === cur[1])) return;+ cur = [cx, cy];+ read();+ }+ svg.addEventListener("pointermove", point);+ svg.addEventListener("pointerdown", point);+ svg.addEventListener("keydown", (e) => {+ const d = { ArrowLeft: [-1, 0], ArrowRight: [1, 0], ArrowUp: [0, -1], ArrowDown: [0, 1] }[e.key];+ if (!d) return;+ e.preventDefault();+ cur = [Math.min(COLS - 1, Math.max(0, cur[0] + d[0])), Math.min(ROWS - 1, Math.max(0, cur[1] + d[1]))];+ read();+ });+ for (const b of fig.querySelectorAll("button[data-sy]")) b.addEventListener("click", () => {+ sy = Number(b.dataset.sy);+ for (const x of fig.querySelectorAll("button[data-sy]")) x.setAttribute("aria-pressed", String(x === b));+ o("sy").textContent = sy < 0 ? "−540" : "+540";+ o("note").textContent = NOTE[sy];+ draw();+ read();+ });+ read();+ });</script></body></html>