3D engine that AI agents drive
Draw the multisampled depth with 16 bits when no depth texture is kept (part of #287)
Nguyen Xuan An6dab7c048a7a
diff --git a/bench/runtime/README.md b/bench/runtime/README.mdindex 33f95609..634dd845 100644--- a/bench/runtime/README.md+++ b/bench/runtime/README.md@@ -23,62 +23,64 @@ CI does not run this suite. It needs Chrome and a GPU, and `tests/runtime-report## Result-Measured on 2026-11-03 at 960 by 540 with 4 MSAA samples, against three.js 0.187.0 (0.186.1 before), after the issue 74 changes. The GPU was shared with other jobs during this run (`gpuBusyBefore` in `report.json`), and the RTX 3060 rows are about twice the earlier 0.186.1 run for both engines (three.js `many-materials` took 1.6 ms before and 7.0 ms now), so treat them as noise and compare the SwiftShader table. A ratio above 1 means that 67js costs more.+Measured on 2026-11-04 at 960 by 540 with 4 MSAA samples, against three.js 0.187.0, after the issue 74 and issue 287 changes. The GPU was shared with other jobs during this run (`gpuBusyBefore` in `report.json`: 8 to 26 percent before each scene, 95 percent before `many-materials`), so treat the RTX 3060 rows as noisy and compare the SwiftShader table. A ratio above 1 means that 67js costs more.**Full frame on SwiftShader, in milliseconds.** This is the path that a headless agent uses.| Scene | 67js | three.js | Ratio || --- | --- | --- | --- |-| `instanced-objects` | 160 | 44 (instanced 44) | 3.6 |-| `many-materials` | 559 | 190 | 2.9 |-| `many-lights` | 388 | 143 | 2.7 |-| `transparency` | 287 | 65 | 4.4 |-| `moving-shadows` | 71 | 21 | 3.4 |-| `large-mesh` | 529 | 221 | 2.4 |-| `skinned-characters` | 164 | 43 | 3.8 |+| `instanced-objects` | 107 | 33 (instanced 33) | 3.2 |+| `many-materials` | 344 | 152 | 2.3 |+| `many-lights` | 278 | 111 | 2.5 |+| `transparency` | 238 | 52 | 4.6 |+| `moving-shadows` | 66 | 19 | 3.4 |+| `large-mesh` | 362 | 159 | 2.3 |+| `skinned-characters` | 101 | 25 | 4.0 |**Full frame on an RTX 3060, in milliseconds.** Other jobs shared the GPU during parts of this run, so these numbers are noisy.| Scene | 67js | three.js | Ratio || --- | --- | --- | --- |-| `instanced-objects` | 0.88 | 2.34 (instanced 0.28) | 0.4 |-| `many-materials` | 3.77 | 6.96 | 0.5 |-| `many-lights` | 2.95 | 2.01 | 1.5 |-| `transparency` | 2.33 | 1.88 | 1.2 |-| `moving-shadows` | 1.74 | 2.30 | 0.8 |-| `large-mesh` | 3.42 | 1.10 | 3.1 |-| `skinned-characters` | 8.23 | 3.94 | 2.1 |+| `instanced-objects` | 0.80 | 2.17 (instanced 0.24) | 0.4 |+| `many-materials` | 2.31 | 1.35 | 1.7 |+| `many-lights` | 1.52 | 0.78 | 1.9 |+| `transparency` | 1.03 | 0.70 | 1.5 |+| `moving-shadows` | 0.79 | 1.12 | 0.7 |+| `large-mesh` | 1.86 | 0.34 | 5.5 |+| `skinned-characters` | 3.44 | 1.55 | 2.2 |**First frame on an RTX 3060, in milliseconds.** Each run has an empty browser profile, so no shader cache helps either engine.| Scene | 67js | three.js | Ratio || --- | --- | --- | --- |-| `instanced-objects` | 259 | 112 (instanced 427) | 2.3 |-| `many-materials` | 447 | 184 | 2.4 |-| `many-lights` | 381 | 203 | 1.9 |-| `transparency` | 347 | 159 | 2.2 |-| `moving-shadows` | 492 | 97 | 5.1 |-| `large-mesh` | 666 | 627 | 1.1 |-| `skinned-characters` | 681 | 457 | 1.5 |+| `instanced-objects` | 235 | 97 (instanced 87) | 2.4 |+| `many-materials` | 214 | 98 | 2.2 |+| `many-lights` | 240 | 128 | 1.9 |+| `transparency` | 201 | 111 | 1.8 |+| `moving-shadows` | 215 | 91 | 2.4 |+| `large-mesh` | 371 | 233 | 1.6 |+| `skinned-characters` | 276 | 219 | 1.3 |## GPU memory per render target-Each 67js result in `report.json` lists its render targets (`renderTargets`: name, size, format, samples, bytes). The same list comes from `renderer.memoryReport()`. At 960 by 540 with 4 samples, for `instanced-objects` and `large-outdoor` alike: `shadowMap` 16 MB (2048 by 2048 depth), `multisampleColor` 15.82 MB (RGBA16F), `multisampleDepth` 7.91 MB and `frameColor` 3.96 MB. The counter totals 45.31 MB and 47.54 MB, so 1.6 to 3.8 MB is geometry and textures.+Each 67js result in `report.json` lists its render targets (`renderTargets`: name, size, format, samples, bytes). The same list comes from `renderer.memoryReport()`. At 960 by 540 with 4 samples, for `instanced-objects` and `large-outdoor` alike: `shadowMap` 16 MB (2048 by 2048 depth), `multisampleColor` 15.82 MB (RGBA16F), `multisampleDepth` 3.96 MB (16 bits, it was 7.91 MB with 24 bits) and `frameColor` 3.96 MB. The counter totals 41.36 MB and 43.58 MB, so 1.4 to 3.6 MB is geometry and textures.++Issue 287 asked for at most 23.25 MB, half of the 46.5 MB the first run showed. It is not met: 41.36 MB is the most the pictures allow today. Each step was scored by FLIP of the new 67js picture against the old one, over the 25 reference scenes, and the limit was 0.002. The 16-bit multisampled depth scored 0.0000 everywhere and is in. Left out: an R11G11B10F colour target (saves 9.9 MB; 0.002 to 0.034, about 0.02 on most scenes, because the packed format truncates), a 1024 shadow map for small views (saves 12 MB; `subsurface` 0.006) and a 16-bit sun shadow map (saves 8 MB; `brick-flat` 0.0023 and `brick-graph` 0.0031). A renderer that needs the alpha of the colour target would also have to keep RGBA16F, so the packed format would need a flag for such an addon.## Where each engine wins**three.js wins:**- Full frames on SwiftShader, in every scene.-- Full frames on the RTX 3060, in 4 of 7 scenes (`many-lights`, `transparency`, `large-mesh`, `skinned-characters`); the loaded GPU put `many-materials` the other way. 67js is faster than three.js with separate meshes in `instanced-objects` and `moving-shadows`, but an `InstancedMesh` beats 67js in `instanced-objects` by 3.1 times.+- Full frames on the RTX 3060, in 5 of 7 scenes (`many-materials`, `many-lights`, `transparency`, `large-mesh`, `skinned-characters`). 67js is faster than three.js with separate meshes in `instanced-objects` and `moving-shadows`, but an `InstancedMesh` beats 67js in `instanced-objects` by 3.3 times.- The first frame, in every scene.-- GPU memory that WebGL calls show, in every scene. 67js allocates about 44 MB for its render targets (it was 46 MB): 16 MB shadow map, 15.8 MB multisampled colour, 7.9 MB multisampled depth and 4 MB resolved colour at this size. A scene with no shadow casters allocates a one texel shadow map instead of 16 MB, and bloom, ambient occlusion, cascades and the point light atlas allocate only when used. The benchmark scenes all cast shadows. three.js shows 0 to 32 MB because its targets live in the canvas, which the counter leaves out.+- GPU memory that WebGL calls show, in every scene. 67js allocates about 41 MB for its render targets (it was 46 MB): 16 MB shadow map, 15.8 MB multisampled colour, 4 MB multisampled depth and 4 MB resolved colour at this size. A scene with no shadow casters allocates a one texel shadow map instead of 16 MB, and bloom, ambient occlusion, cascades and the point light atlas allocate only when used. The benchmark scenes all cast shadows. three.js shows 0 to 32 MB because its targets live in the canvas, which the counter leaves out.- Fewer triangles when objects are off camera, because it culls them. 67js draws all of them (issue 37).- Heap memory in `skinned-characters`, because three.js clones one parsed file.**67js wins:**-- CPU time to submit a frame, in 6 of 7 scenes. It takes 0.07 ms against 3.91 ms for 5,000 individual meshes. It groups objects into a few draw calls by itself. An `InstancedMesh` needs the same grouping by hand in three.js.+- CPU time to submit a frame, in 6 of 7 scenes (all but `large-mesh`). It takes 0.27 ms against 1.88 ms for 5,000 individual meshes. It groups objects into a few draw calls by itself. An `InstancedMesh` needs the same grouping by hand in three.js.- Heap memory in 6 of 7 scenes.Issue 74 tracks the frame and first-frame costs. The cause is not measured yet.diff --git a/bench/runtime/report.json b/bench/runtime/report.jsonindex ea7c5439..ad637091 100644--- a/bench/runtime/report.json+++ b/bench/runtime/report.json@@ -12,14 +12,14 @@"gpu": {"instanced-objects": {"67js": {- "firstFrameMilliseconds": 259,+ "firstFrameMilliseconds": 235,"updateMilliseconds": 0,- "renderCpuMilliseconds": 0.28,+ "renderCpuMilliseconds": 0.27,"gpuMilliseconds": 0.25,- "fullFrameMilliseconds": 0.88,+ "fullFrameMilliseconds": 0.8,"drawCalls": 3,"triangles": 49850,- "gpuMegabytes": 45.31,+ "gpuMegabytes": 41.36,"heapMegabytes": 5.9,"renderTargets": [{@@ -47,10 +47,10 @@"width": 960,"height": 540,"layers": 1,- "format": "DEPTH_COMPONENT24",+ "format": "DEPTH_COMPONENT16","samples": 4,- "bytes": 8294400,- "megabytes": 7.91+ "bytes": 4147200,+ "megabytes": 3.96},{"name": "frameColor",@@ -63,46 +63,46 @@"megabytes": 3.96}],- "gpuBusyBefore": 15+ "gpuBusyBefore": 11},"three": {- "firstFrameMilliseconds": 112,+ "firstFrameMilliseconds": 97,"updateMilliseconds": 0,- "renderCpuMilliseconds": 1.95,- "gpuMilliseconds": 0.09,- "fullFrameMilliseconds": 2.34,+ "renderCpuMilliseconds": 1.88,+ "gpuMilliseconds": 0.1,+ "fullFrameMilliseconds": 2.17,"drawCalls": 4154,"triangles": 49848,"gpuMegabytes": 0,"heapMegabytes": 8.5,"renderTargets": null,- "gpuBusyBefore": 41+ "gpuBusyBefore": 20},"three-instanced": {- "firstFrameMilliseconds": 427,+ "firstFrameMilliseconds": 87,"updateMilliseconds": 0,"renderCpuMilliseconds": 0.04,"gpuMilliseconds": 0.05,- "fullFrameMilliseconds": 0.28,+ "fullFrameMilliseconds": 0.24,"drawCalls": 1,"triangles": 60000,"gpuMegabytes": 0.31,"heapMegabytes": 2.4,"renderTargets": null,- "gpuBusyBefore": 19+ "gpuBusyBefore": 9}},"large-outdoor": {"67js": {- "firstFrameMilliseconds": 296,+ "firstFrameMilliseconds": 227,"updateMilliseconds": 0,- "renderCpuMilliseconds": 0.35,- "gpuMilliseconds": 0.75,- "fullFrameMilliseconds": 1.58,+ "renderCpuMilliseconds": 0.4,+ "gpuMilliseconds": 0.76,+ "fullFrameMilliseconds": 1.55,"drawCalls": 6,"triangles": 270474,- "gpuMegabytes": 47.54,- "heapMegabytes": 6.9,+ "gpuMegabytes": 43.58,+ "heapMegabytes": 6.8,"renderTargets": [{"name": "shadowMap",@@ -129,10 +129,10 @@"width": 960,"height": 540,"layers": 1,- "format": "DEPTH_COMPONENT24",+ "format": "DEPTH_COMPONENT16","samples": 4,- "bytes": 8294400,- "megabytes": 7.91+ "bytes": 4147200,+ "megabytes": 3.96},{"name": "frameColor",@@ -145,31 +145,31 @@"megabytes": 3.96}],- "gpuBusyBefore": 12+ "gpuBusyBefore": 9},"three": {- "firstFrameMilliseconds": 109,+ "firstFrameMilliseconds": 94,"updateMilliseconds": 0,- "renderCpuMilliseconds": 3.72,- "gpuMilliseconds": 0.72,- "fullFrameMilliseconds": 4.48,+ "renderCpuMilliseconds": 3.58,+ "gpuMilliseconds": 0.73,+ "fullFrameMilliseconds": 4.33,"drawCalls": 4542,"triangles": 4359372,"gpuMegabytes": 0.03,"heapMegabytes": 9.9,"renderTargets": null,- "gpuBusyBefore": 65+ "gpuBusyBefore": 59},"67js-no-lod": {- "firstFrameMilliseconds": 263,+ "firstFrameMilliseconds": 537,"updateMilliseconds": 0,- "renderCpuMilliseconds": 0.52,- "gpuMilliseconds": 8.88,- "fullFrameMilliseconds": 10.11,+ "renderCpuMilliseconds": 0.41,+ "gpuMilliseconds": 6.54,+ "fullFrameMilliseconds": 7.39,"drawCalls": 4,"triangles": 4359374,- "gpuMegabytes": 45.65,- "heapMegabytes": 6.4,+ "gpuMegabytes": 41.7,+ "heapMegabytes": 6.3,"renderTargets": [{"name": "shadowMap",@@ -196,10 +196,10 @@"width": 960,"height": 540,"layers": 1,- "format": "DEPTH_COMPONENT24",+ "format": "DEPTH_COMPONENT16","samples": 4,- "bytes": 8294400,- "megabytes": 7.91+ "bytes": 4147200,+ "megabytes": 3.96},{"name": "frameColor",@@ -212,18 +212,18 @@"megabytes": 3.96}],- "gpuBusyBefore": 23+ "gpuBusyBefore": 26},"67js-no-culling": {- "firstFrameMilliseconds": 267,+ "firstFrameMilliseconds": 234,"updateMilliseconds": 0,- "renderCpuMilliseconds": 0.23,- "gpuMilliseconds": 11.45,- "fullFrameMilliseconds": 12.57,+ "renderCpuMilliseconds": 0.11,+ "gpuMilliseconds": 8.08,+ "fullFrameMilliseconds": 8.56,"drawCalls": 4,"triangles": 5760014,- "gpuMegabytes": 44.72,- "heapMegabytes": 5.6,+ "gpuMegabytes": 40.76,+ "heapMegabytes": 5.5,"renderTargets": [{"name": "shadowMap",@@ -250,10 +250,10 @@"width": 960,"height": 540,"layers": 1,- "format": "DEPTH_COMPONENT24",+ "format": "DEPTH_COMPONENT16","samples": 4,- "bytes": 8294400,- "megabytes": 7.91+ "bytes": 4147200,+ "megabytes": 3.96},{"name": "frameColor",@@ -266,19 +266,19 @@"megabytes": 3.96}],- "gpuBusyBefore": 51+ "gpuBusyBefore": 88}},"many-materials": {"67js": {- "firstFrameMilliseconds": 447,+ "firstFrameMilliseconds": 214,"updateMilliseconds": 0,- "renderCpuMilliseconds": 0.48,- "gpuMilliseconds": 1.82,- "fullFrameMilliseconds": 3.77,+ "renderCpuMilliseconds": 0.12,+ "gpuMilliseconds": 1.86,+ "fullFrameMilliseconds": 2.31,"drawCalls": 4,"triangles": 925454,- "gpuMegabytes": 44.09,+ "gpuMegabytes": 40.14,"heapMegabytes": 2.7,"renderTargets": [{@@ -306,10 +306,10 @@"width": 960,"height": 540,"layers": 1,- "format": "DEPTH_COMPONENT24",+ "format": "DEPTH_COMPONENT16","samples": 4,- "bytes": 8294400,- "megabytes": 7.91+ "bytes": 4147200,+ "megabytes": 3.96},{"name": "frameColor",@@ -322,32 +322,32 @@"megabytes": 3.96}],- "gpuBusyBefore": 18+ "gpuBusyBefore": 95},"three": {- "firstFrameMilliseconds": 184,+ "firstFrameMilliseconds": 98,"updateMilliseconds": 0,- "renderCpuMilliseconds": 5.3,- "gpuMilliseconds": 0.23,- "fullFrameMilliseconds": 6.96,+ "renderCpuMilliseconds": 0.92,+ "gpuMilliseconds": 0.19,+ "fullFrameMilliseconds": 1.35,"drawCalls": 965,"triangles": 925452,"gpuMegabytes": 0.03,"heapMegabytes": 13,"renderTargets": null,- "gpuBusyBefore": 11+ "gpuBusyBefore": 86}},"many-lights": {"67js": {- "firstFrameMilliseconds": 381,+ "firstFrameMilliseconds": 240,"updateMilliseconds": 0,- "renderCpuMilliseconds": 0.4,- "gpuMilliseconds": 1.33,- "fullFrameMilliseconds": 2.95,+ "renderCpuMilliseconds": 0.12,+ "gpuMilliseconds": 1.05,+ "fullFrameMilliseconds": 1.52,"drawCalls": 4,"triangles": 368654,- "gpuMegabytes": 43.9,+ "gpuMegabytes": 39.95,"heapMegabytes": 1.8,"renderTargets": [{@@ -375,10 +375,10 @@"width": 960,"height": 540,"layers": 1,- "format": "DEPTH_COMPONENT24",+ "format": "DEPTH_COMPONENT16","samples": 4,- "bytes": 8294400,- "megabytes": 7.91+ "bytes": 4147200,+ "megabytes": 3.96},{"name": "frameColor",@@ -391,33 +391,33 @@"megabytes": 3.96}],- "gpuBusyBefore": 17+ "gpuBusyBefore": 25},"three": {- "firstFrameMilliseconds": 203,+ "firstFrameMilliseconds": 128,"updateMilliseconds": 0,- "renderCpuMilliseconds": 0.83,- "gpuMilliseconds": 0.36,- "fullFrameMilliseconds": 2.01,+ "renderCpuMilliseconds": 0.24,+ "gpuMilliseconds": 0.33,+ "fullFrameMilliseconds": 0.78,"drawCalls": 385,"triangles": 368652,"gpuMegabytes": 0.03,"heapMegabytes": 2.4,"renderTargets": null,- "gpuBusyBefore": 11+ "gpuBusyBefore": 76}},"transparency": {"67js": {- "firstFrameMilliseconds": 347,+ "firstFrameMilliseconds": 201,"updateMilliseconds": 0,- "renderCpuMilliseconds": 0.44,- "gpuMilliseconds": 0.64,- "fullFrameMilliseconds": 2.33,+ "renderCpuMilliseconds": 0.12,+ "gpuMilliseconds": 0.68,+ "fullFrameMilliseconds": 1.03,"drawCalls": 4,"triangles": 288014,- "gpuMegabytes": 43.82,- "heapMegabytes": 1.9,+ "gpuMegabytes": 39.87,+ "heapMegabytes": 1.8,"renderTargets": [{"name": "shadowMap",@@ -444,10 +444,10 @@"width": 960,"height": 540,"layers": 1,- "format": "DEPTH_COMPONENT24",+ "format": "DEPTH_COMPONENT16","samples": 4,- "bytes": 8294400,- "megabytes": 7.91+ "bytes": 4147200,+ "megabytes": 3.96},{"name": "frameColor",@@ -460,33 +460,33 @@"megabytes": 3.96}],- "gpuBusyBefore": 10+ "gpuBusyBefore": 8},"three": {- "firstFrameMilliseconds": 159,+ "firstFrameMilliseconds": 111,"updateMilliseconds": 0,- "renderCpuMilliseconds": 1.11,+ "renderCpuMilliseconds": 0.33,"gpuMilliseconds": 0.17,- "fullFrameMilliseconds": 1.88,+ "fullFrameMilliseconds": 0.7,"drawCalls": 301,"triangles": 288012,"gpuMegabytes": 0.03,"heapMegabytes": 5.5,"renderTargets": null,- "gpuBusyBefore": 53+ "gpuBusyBefore": 73}},"moving-shadows": {"67js": {- "firstFrameMilliseconds": 492,- "updateMilliseconds": 0.31,- "renderCpuMilliseconds": 0.5,- "gpuMilliseconds": 0.33,- "fullFrameMilliseconds": 1.74,+ "firstFrameMilliseconds": 215,+ "updateMilliseconds": 0.11,+ "renderCpuMilliseconds": 0.19,+ "gpuMilliseconds": 0.3,+ "fullFrameMilliseconds": 0.79,"drawCalls": 4,"triangles": 12026,- "gpuMegabytes": 43.83,- "heapMegabytes": 1.7,+ "gpuMegabytes": 39.87,+ "heapMegabytes": 1.6,"renderTargets": [{"name": "shadowMap",@@ -513,10 +513,10 @@"width": 960,"height": 540,"layers": 1,- "format": "DEPTH_COMPONENT24",+ "format": "DEPTH_COMPONENT16","samples": 4,- "bytes": 8294400,- "megabytes": 7.91+ "bytes": 4147200,+ "megabytes": 3.96},{"name": "frameColor",@@ -529,32 +529,32 @@"megabytes": 3.96}],- "gpuBusyBefore": 14+ "gpuBusyBefore": 22},"three": {- "firstFrameMilliseconds": 97,- "updateMilliseconds": 0.08,- "renderCpuMilliseconds": 1.55,- "gpuMilliseconds": 0.16,- "fullFrameMilliseconds": 2.3,+ "firstFrameMilliseconds": 91,+ "updateMilliseconds": 0.03,+ "renderCpuMilliseconds": 0.75,+ "gpuMilliseconds": 0.17,+ "fullFrameMilliseconds": 1.12,"drawCalls": 1002,"triangles": 12024,"gpuMegabytes": 32,"heapMegabytes": 2.1,"renderTargets": null,- "gpuBusyBefore": 67+ "gpuBusyBefore": 17}},"large-mesh": {"67js": {- "firstFrameMilliseconds": 666,+ "firstFrameMilliseconds": 371,"updateMilliseconds": 0,- "renderCpuMilliseconds": 0.17,- "gpuMilliseconds": 2.56,- "fullFrameMilliseconds": 3.42,+ "renderCpuMilliseconds": 0.06,+ "gpuMilliseconds": 1.55,+ "fullFrameMilliseconds": 1.86,"drawCalls": 3,"triangles": 1046530,- "gpuMegabytes": 71.77,+ "gpuMegabytes": 67.82,"heapMegabytes": 28.7,"renderTargets": [{@@ -582,10 +582,10 @@"width": 960,"height": 540,"layers": 1,- "format": "DEPTH_COMPONENT24",+ "format": "DEPTH_COMPONENT16","samples": 4,- "bytes": 8294400,- "megabytes": 7.91+ "bytes": 4147200,+ "megabytes": 3.96},{"name": "frameColor",@@ -598,32 +598,32 @@"megabytes": 3.96}],- "gpuBusyBefore": 58+ "gpuBusyBefore": 26},"three": {- "firstFrameMilliseconds": 627,+ "firstFrameMilliseconds": 233,"updateMilliseconds": 0,- "renderCpuMilliseconds": 0.17,- "gpuMilliseconds": 0.16,- "fullFrameMilliseconds": 1.1,+ "renderCpuMilliseconds": 0.04,+ "gpuMilliseconds": 0.15,+ "fullFrameMilliseconds": 0.34,"drawCalls": 1,"triangles": 1046528,"gpuMegabytes": 24.01,"heapMegabytes": 29,"renderTargets": null,- "gpuBusyBefore": 91+ "gpuBusyBefore": 68}},"skinned-characters": {"67js": {- "firstFrameMilliseconds": 681,- "updateMilliseconds": 13.4,- "renderCpuMilliseconds": 2.28,- "gpuMilliseconds": 2.45,- "fullFrameMilliseconds": 8.23,+ "firstFrameMilliseconds": 276,+ "updateMilliseconds": 4.77,+ "renderCpuMilliseconds": 0.64,+ "gpuMilliseconds": 1.75,+ "fullFrameMilliseconds": 3.44,"drawCalls": 308,"triangles": 51818,- "gpuMegabytes": 47.04,+ "gpuMegabytes": 43.09,"heapMegabytes": 17.4,"renderTargets": [{@@ -651,10 +651,10 @@"width": 960,"height": 540,"layers": 1,- "format": "DEPTH_COMPONENT24",+ "format": "DEPTH_COMPONENT16","samples": 4,- "bytes": 8294400,- "megabytes": 7.91+ "bytes": 4147200,+ "megabytes": 3.96},{"name": "frameColor",@@ -667,35 +667,35 @@"megabytes": 3.96}],- "gpuBusyBefore": 24+ "gpuBusyBefore": 25},"three": {- "firstFrameMilliseconds": 457,- "updateMilliseconds": 0.08,- "renderCpuMilliseconds": 2.41,- "gpuMilliseconds": 0.38,- "fullFrameMilliseconds": 3.94,+ "firstFrameMilliseconds": 219,+ "updateMilliseconds": 0.02,+ "renderCpuMilliseconds": 0.7,+ "gpuMilliseconds": 0.39,+ "fullFrameMilliseconds": 1.55,"drawCalls": 306,"triangles": 51816,"gpuMegabytes": 32.34,- "heapMegabytes": 5.6,+ "heapMegabytes": 4.2,"renderTargets": null,- "gpuBusyBefore": 23+ "gpuBusyBefore": 21}}},"cpu": {"instanced-objects": {"67js": {- "firstFrameMilliseconds": 710,+ "firstFrameMilliseconds": 434,"updateMilliseconds": 0,- "renderCpuMilliseconds": 0.78,- "gpuMilliseconds": 157.64,- "fullFrameMilliseconds": 159.52,+ "renderCpuMilliseconds": 0.53,+ "gpuMilliseconds": 105.15,+ "fullFrameMilliseconds": 106.66,"drawCalls": 3,"triangles": 49850,- "gpuMegabytes": 45.31,- "heapMegabytes": 5.9,+ "gpuMegabytes": 41.36,+ "heapMegabytes": 5.8,"renderTargets": [{"name": "shadowMap",@@ -722,10 +722,10 @@"width": 960,"height": 540,"layers": 1,- "format": "DEPTH_COMPONENT24",+ "format": "DEPTH_COMPONENT16","samples": 4,- "bytes": 8294400,- "megabytes": 7.91+ "bytes": 4147200,+ "megabytes": 3.96},{"name": "frameColor",@@ -738,45 +738,45 @@"megabytes": 3.96}],- "gpuBusyBefore": 10+ "gpuBusyBefore": 8},"three": {- "firstFrameMilliseconds": 317,+ "firstFrameMilliseconds": 232,"updateMilliseconds": 0,- "renderCpuMilliseconds": 4.11,- "gpuMilliseconds": 38.03,- "fullFrameMilliseconds": 44.48,+ "renderCpuMilliseconds": 2.36,+ "gpuMilliseconds": 29.16,+ "fullFrameMilliseconds": 33.22,"drawCalls": 4154,"triangles": 49848,"gpuMegabytes": 0,"heapMegabytes": 8.5,"renderTargets": null,- "gpuBusyBefore": 25+ "gpuBusyBefore": 8},"three-instanced": {- "firstFrameMilliseconds": 324,+ "firstFrameMilliseconds": 218,"updateMilliseconds": 0,- "renderCpuMilliseconds": 0.16,- "gpuMilliseconds": 43.01,- "fullFrameMilliseconds": 44.43,+ "renderCpuMilliseconds": 0.11,+ "gpuMilliseconds": 32.34,+ "fullFrameMilliseconds": 33.06,"drawCalls": 1,"triangles": 60000,"gpuMegabytes": 0.31,"heapMegabytes": 2.4,"renderTargets": null,- "gpuBusyBefore": 14+ "gpuBusyBefore": 8}},"large-outdoor": {"67js": {- "firstFrameMilliseconds": 765,+ "firstFrameMilliseconds": 443,"updateMilliseconds": 0,- "renderCpuMilliseconds": 0.94,- "gpuMilliseconds": 262.55,- "fullFrameMilliseconds": 265.75,+ "renderCpuMilliseconds": 0.57,+ "gpuMilliseconds": 158.4,+ "fullFrameMilliseconds": 159.78,"drawCalls": 6,"triangles": 270474,- "gpuMegabytes": 47.54,+ "gpuMegabytes": 43.58,"heapMegabytes": 6.8,"renderTargets": [{@@ -804,10 +804,10 @@"width": 960,"height": 540,"layers": 1,- "format": "DEPTH_COMPONENT24",+ "format": "DEPTH_COMPONENT16","samples": 4,- "bytes": 8294400,- "megabytes": 7.91+ "bytes": 4147200,+ "megabytes": 3.96},{"name": "frameColor",@@ -820,31 +820,31 @@"megabytes": 3.96}],- "gpuBusyBefore": 17+ "gpuBusyBefore": 8},"three": {- "firstFrameMilliseconds": 1172,+ "firstFrameMilliseconds": 885,"updateMilliseconds": 0,- "renderCpuMilliseconds": 9.17,- "gpuMilliseconds": 886.88,- "fullFrameMilliseconds": 896.97,+ "renderCpuMilliseconds": 4.63,+ "gpuMilliseconds": 714.22,+ "fullFrameMilliseconds": 720.31,"drawCalls": 4542,"triangles": 4359372,"gpuMegabytes": 0.03,"heapMegabytes": 9.8,"renderTargets": null,- "gpuBusyBefore": 11+ "gpuBusyBefore": 8},"67js-no-lod": {- "firstFrameMilliseconds": 2096,+ "firstFrameMilliseconds": 1581,"updateMilliseconds": 0,- "renderCpuMilliseconds": 0.88,- "gpuMilliseconds": 1853.46,- "fullFrameMilliseconds": 1855.51,+ "renderCpuMilliseconds": 0.69,+ "gpuMilliseconds": 1296.78,+ "fullFrameMilliseconds": 1298.2,"drawCalls": 4,"triangles": 4359374,- "gpuMegabytes": 45.65,- "heapMegabytes": 6.4,+ "gpuMegabytes": 41.7,+ "heapMegabytes": 6.3,"renderTargets": [{"name": "shadowMap",@@ -871,10 +871,10 @@"width": 960,"height": 540,"layers": 1,- "format": "DEPTH_COMPONENT24",+ "format": "DEPTH_COMPONENT16","samples": 4,- "bytes": 8294400,- "megabytes": 7.91+ "bytes": 4147200,+ "megabytes": 3.96},{"name": "frameColor",@@ -887,18 +887,18 @@"megabytes": 3.96}],- "gpuBusyBefore": 23+ "gpuBusyBefore": 8},"67js-no-culling": {- "firstFrameMilliseconds": 3065,- "updateMilliseconds": 0.01,- "renderCpuMilliseconds": 0.34,- "gpuMilliseconds": 2129.47,- "fullFrameMilliseconds": 2132.61,+ "firstFrameMilliseconds": 1924,+ "updateMilliseconds": 0,+ "renderCpuMilliseconds": 0.17,+ "gpuMilliseconds": 1445.71,+ "fullFrameMilliseconds": 1447.03,"drawCalls": 4,"triangles": 5760014,- "gpuMegabytes": 44.72,- "heapMegabytes": 5.6,+ "gpuMegabytes": 40.76,+ "heapMegabytes": 5.5,"renderTargets": [{"name": "shadowMap",@@ -925,10 +925,10 @@"width": 960,"height": 540,"layers": 1,- "format": "DEPTH_COMPONENT24",+ "format": "DEPTH_COMPONENT16","samples": 4,- "bytes": 8294400,- "megabytes": 7.91+ "bytes": 4147200,+ "megabytes": 3.96},{"name": "frameColor",@@ -941,20 +941,20 @@"megabytes": 3.96}],- "gpuBusyBefore": 11+ "gpuBusyBefore": 8}},"many-materials": {"67js": {- "firstFrameMilliseconds": 1283,+ "firstFrameMilliseconds": 687,"updateMilliseconds": 0,- "renderCpuMilliseconds": 0.61,- "gpuMilliseconds": 556.8,- "fullFrameMilliseconds": 559.32,+ "renderCpuMilliseconds": 0.3,+ "gpuMilliseconds": 343.17,+ "fullFrameMilliseconds": 344.06,"drawCalls": 4,"triangles": 925454,- "gpuMegabytes": 44.09,- "heapMegabytes": 2.7,+ "gpuMegabytes": 40.14,+ "heapMegabytes": 2.6,"renderTargets": [{"name": "shadowMap",@@ -981,10 +981,10 @@"width": 960,"height": 540,"layers": 1,- "format": "DEPTH_COMPONENT24",+ "format": "DEPTH_COMPONENT16","samples": 4,- "bytes": 8294400,- "megabytes": 7.91+ "bytes": 4147200,+ "megabytes": 3.96},{"name": "frameColor",@@ -997,32 +997,32 @@"megabytes": 3.96}],- "gpuBusyBefore": 12+ "gpuBusyBefore": 8},"three": {- "firstFrameMilliseconds": 549,+ "firstFrameMilliseconds": 362,"updateMilliseconds": 0,- "renderCpuMilliseconds": 2.46,- "gpuMilliseconds": 186.88,- "fullFrameMilliseconds": 190.19,+ "renderCpuMilliseconds": 1.69,+ "gpuMilliseconds": 149.51,+ "fullFrameMilliseconds": 152.28,"drawCalls": 965,"triangles": 925452,"gpuMegabytes": 0.03,"heapMegabytes": 13,"renderTargets": null,- "gpuBusyBefore": 11+ "gpuBusyBefore": 8}},"many-lights": {"67js": {- "firstFrameMilliseconds": 950,+ "firstFrameMilliseconds": 585,"updateMilliseconds": 0,- "renderCpuMilliseconds": 0.26,- "gpuMilliseconds": 385.68,- "fullFrameMilliseconds": 388.45,+ "renderCpuMilliseconds": 0.27,+ "gpuMilliseconds": 276.98,+ "fullFrameMilliseconds": 277.95,"drawCalls": 4,"triangles": 368654,- "gpuMegabytes": 43.9,+ "gpuMegabytes": 39.95,"heapMegabytes": 1.8,"renderTargets": [{@@ -1050,10 +1050,10 @@"width": 960,"height": 540,"layers": 1,- "format": "DEPTH_COMPONENT24",+ "format": "DEPTH_COMPONENT16","samples": 4,- "bytes": 8294400,- "megabytes": 7.91+ "bytes": 4147200,+ "megabytes": 3.96},{"name": "frameColor",@@ -1066,32 +1066,32 @@"megabytes": 3.96}],- "gpuBusyBefore": 12+ "gpuBusyBefore": 8},"three": {- "firstFrameMilliseconds": 476,+ "firstFrameMilliseconds": 312,"updateMilliseconds": 0,- "renderCpuMilliseconds": 0.62,- "gpuMilliseconds": 140.11,- "fullFrameMilliseconds": 142.62,+ "renderCpuMilliseconds": 0.59,+ "gpuMilliseconds": 109.15,+ "fullFrameMilliseconds": 111.33,"drawCalls": 385,"triangles": 368652,"gpuMegabytes": 0.03,"heapMegabytes": 2.3,"renderTargets": null,- "gpuBusyBefore": 16+ "gpuBusyBefore": 8}},"transparency": {"67js": {- "firstFrameMilliseconds": 706,+ "firstFrameMilliseconds": 574,"updateMilliseconds": 0,- "renderCpuMilliseconds": 0.24,- "gpuMilliseconds": 285.46,- "fullFrameMilliseconds": 286.55,+ "renderCpuMilliseconds": 0.31,+ "gpuMilliseconds": 236.9,+ "fullFrameMilliseconds": 238.05,"drawCalls": 4,"triangles": 288014,- "gpuMegabytes": 43.82,+ "gpuMegabytes": 39.87,"heapMegabytes": 1.4,"renderTargets": [{@@ -1119,10 +1119,10 @@"width": 960,"height": 540,"layers": 1,- "format": "DEPTH_COMPONENT24",+ "format": "DEPTH_COMPONENT16","samples": 4,- "bytes": 8294400,- "megabytes": 7.91+ "bytes": 4147200,+ "megabytes": 3.96},{"name": "frameColor",@@ -1135,32 +1135,32 @@"megabytes": 3.96}],- "gpuBusyBefore": 16+ "gpuBusyBefore": 8},"three": {- "firstFrameMilliseconds": 299,+ "firstFrameMilliseconds": 279,"updateMilliseconds": 0,- "renderCpuMilliseconds": 0.76,- "gpuMilliseconds": 62.63,- "fullFrameMilliseconds": 64.7,+ "renderCpuMilliseconds": 0.67,+ "gpuMilliseconds": 50.21,+ "fullFrameMilliseconds": 51.78,"drawCalls": 301,"triangles": 288012,"gpuMegabytes": 0.03,"heapMegabytes": 5,"renderTargets": null,- "gpuBusyBefore": 17+ "gpuBusyBefore": 0}},"moving-shadows": {"67js": {- "firstFrameMilliseconds": 414,- "updateMilliseconds": 0.17,- "renderCpuMilliseconds": 0.31,- "gpuMilliseconds": 69.79,- "fullFrameMilliseconds": 70.77,+ "firstFrameMilliseconds": 367,+ "updateMilliseconds": 0.15,+ "renderCpuMilliseconds": 0.32,+ "gpuMilliseconds": 64.74,+ "fullFrameMilliseconds": 66,"drawCalls": 4,"triangles": 12026,- "gpuMegabytes": 43.83,+ "gpuMegabytes": 39.87,"heapMegabytes": 1.6,"renderTargets": [{@@ -1188,10 +1188,10 @@"width": 960,"height": 540,"layers": 1,- "format": "DEPTH_COMPONENT24",+ "format": "DEPTH_COMPONENT16","samples": 4,- "bytes": 8294400,- "megabytes": 7.91+ "bytes": 4147200,+ "megabytes": 3.96},{"name": "frameColor",@@ -1204,32 +1204,32 @@"megabytes": 3.96}],- "gpuBusyBefore": 17+ "gpuBusyBefore": 8},"three": {- "firstFrameMilliseconds": 266,- "updateMilliseconds": 0.11,- "renderCpuMilliseconds": 1.05,- "gpuMilliseconds": 18.62,- "fullFrameMilliseconds": 20.77,+ "firstFrameMilliseconds": 232,+ "updateMilliseconds": 0.09,+ "renderCpuMilliseconds": 0.99,+ "gpuMilliseconds": 17.43,+ "fullFrameMilliseconds": 19.37,"drawCalls": 1002,"triangles": 12024,"gpuMegabytes": 32,"heapMegabytes": 2.1,"renderTargets": null,- "gpuBusyBefore": 18+ "gpuBusyBefore": 0}},"large-mesh": {"67js": {- "firstFrameMilliseconds": 864,+ "firstFrameMilliseconds": 741,"updateMilliseconds": 0,- "renderCpuMilliseconds": 0.39,- "gpuMilliseconds": 525.29,- "fullFrameMilliseconds": 528.53,+ "renderCpuMilliseconds": 0.17,+ "gpuMilliseconds": 360.86,+ "fullFrameMilliseconds": 361.91,"drawCalls": 3,"triangles": 1046530,- "gpuMegabytes": 71.77,+ "gpuMegabytes": 67.82,"heapMegabytes": 28.7,"renderTargets": [{@@ -1257,10 +1257,10 @@"width": 960,"height": 540,"layers": 1,- "format": "DEPTH_COMPONENT24",+ "format": "DEPTH_COMPONENT16","samples": 4,- "bytes": 8294400,- "megabytes": 7.91+ "bytes": 4147200,+ "megabytes": 3.96},{"name": "frameColor",@@ -1273,33 +1273,33 @@"megabytes": 3.96}],- "gpuBusyBefore": 18+ "gpuBusyBefore": 8},"three": {- "firstFrameMilliseconds": 823,- "updateMilliseconds": 0.01,- "renderCpuMilliseconds": 0.29,- "gpuMilliseconds": 218.42,- "fullFrameMilliseconds": 220.51,+ "firstFrameMilliseconds": 383,+ "updateMilliseconds": 0,+ "renderCpuMilliseconds": 0.13,+ "gpuMilliseconds": 157.79,+ "fullFrameMilliseconds": 158.72,"drawCalls": 1,"triangles": 1046528,"gpuMegabytes": 24.01,"heapMegabytes": 29,"renderTargets": null,- "gpuBusyBefore": 11+ "gpuBusyBefore": 8}},"skinned-characters": {"67js": {- "firstFrameMilliseconds": 963,- "updateMilliseconds": 8.31,- "renderCpuMilliseconds": 1.36,- "gpuMilliseconds": 158.72,- "fullFrameMilliseconds": 164.47,+ "firstFrameMilliseconds": 378,+ "updateMilliseconds": 6.02,+ "renderCpuMilliseconds": 0.79,+ "gpuMilliseconds": 97.63,+ "fullFrameMilliseconds": 100.67,"drawCalls": 308,"triangles": 51818,- "gpuMegabytes": 47.04,- "heapMegabytes": 17.4,+ "gpuMegabytes": 43.09,+ "heapMegabytes": 17.3,"renderTargets": [{"name": "shadowMap",@@ -1326,10 +1326,10 @@"width": 960,"height": 540,"layers": 1,- "format": "DEPTH_COMPONENT24",+ "format": "DEPTH_COMPONENT16","samples": 4,- "bytes": 8294400,- "megabytes": 7.91+ "bytes": 4147200,+ "megabytes": 3.96},{"name": "frameColor",@@ -1342,20 +1342,20 @@"megabytes": 3.96}],- "gpuBusyBefore": 12+ "gpuBusyBefore": 8},"three": {- "firstFrameMilliseconds": 600,- "updateMilliseconds": 0.1,- "renderCpuMilliseconds": 2,- "gpuMilliseconds": 38.87,- "fullFrameMilliseconds": 42.84,+ "firstFrameMilliseconds": 361,+ "updateMilliseconds": 0.05,+ "renderCpuMilliseconds": 1.06,+ "gpuMilliseconds": 22.73,+ "fullFrameMilliseconds": 25.11,"drawCalls": 306,"triangles": 51816,"gpuMegabytes": 32.34,- "heapMegabytes": 4,+ "heapMegabytes": 4.5,"renderTargets": null,- "gpuBusyBefore": 18+ "gpuBusyBefore": 1}}}@@ -1377,7 +1377,7 @@"cpu-many-lights": 0.1327,"cpu-many-materials": 0.2684,"cpu-moving-shadows": 0.0731,- "cpu-skinned-characters": 0.1072,+ "cpu-skinned-characters": 0.1075,"cpu-transparency": 0.1307,"gpu-instanced-objects": 0.0477,"gpu-large-mesh": 0.0271,diff --git a/changes/287.md b/changes/287.mdindex b3e3c752..b0d2ed52 100644--- a/changes/287.md+++ b/changes/287.md@@ -1 +1 @@-- Add `renderer.memoryReport()` and a per-target GPU memory list in the runtime benchmark (issue #287), and allocate render targets only when used: bloom targets on the first bloom frame, a one texel shadow map for scenes with no shadow casters (16 MB saved), and a local shadow atlas with one row per four tiles in use (24 MB down to 6 MB for one light). Reference pictures are byte identical on all 23 scenes on both backends. `bench/runtime/report.json` is rerun after issue 74.+- Draw the multisampled depth with 16 bits when the renderer has no depth texture (issue #287). A plain lit scene at 960 by 540 with 4 samples allocates 41.36 MB of render targets instead of 45.31 MB (`instanced-objects`), and the 25 reference scenes draw the same pictures (worst FLIP against the previous 67js picture 0.0000). A renderer with `depth: true` keeps 24 bits, because its resolve needs the same format. Two other steps failed the 0.002 FLIP limit and are not in: a 16-bit sun shadow map (brick scenes 0.0023 and 0.0031) and an R11G11B10F colour target (0.002 to 0.034 over the 25 scenes, about 0.02 on most). A 1024 shadow map changed `subsurface` by 0.006.diff --git a/src/render-target-ledger.js b/src/render-target-ledger.jsindex f391e1bd..23bf3309 100644--- a/src/render-target-ledger.js+++ b/src/render-target-ledger.js@@ -1,6 +1,6 @@// Lists the GPU render targets a renderer owns, so an agent can read what each one costs.// Sizes follow the texel format, so they are the same on every machine, whatever padding a driver adds.-const BYTES_PER_PIXEL = { R8: 1, RGBA8: 4, RGBA16F: 8, DEPTH_COMPONENT24: 4 };+const BYTES_PER_PIXEL = { R8: 1, RGBA8: 4, RGBA16F: 8, DEPTH_COMPONENT16: 2, DEPTH_COMPONENT24: 4 };const BYTES_PER_MEGABYTE = 1048576;export class RenderTargetLedger {diff --git a/src/renderer.js b/src/renderer.jsindex bedc71cf..ef376465 100644--- a/src/renderer.js+++ b/src/renderer.js@@ -1531,11 +1531,13 @@ export class Renderer67 {context.framebufferRenderbuffer(context.FRAMEBUFFER, context.COLOR_ATTACHMENT0, context.RENDERBUFFER, this.multisampleColor);this.multisampleDepth = context.createRenderbuffer();context.bindRenderbuffer(context.RENDERBUFFER, this.multisampleDepth);- context.renderbufferStorageMultisample(context.RENDERBUFFER, this.multisampleSamples, context.DEPTH_COMPONENT24, width, height);+ // Without a depth texture nothing reads or resolves the depth, so the visibility test can use 16 bits; a depth texture needs the same format.+ const depthFormat = this.depth ? 'DEPTH_COMPONENT24' : 'DEPTH_COMPONENT16';+ context.renderbufferStorageMultisample(context.RENDERBUFFER, this.multisampleSamples, context[depthFormat], width, height);context.framebufferRenderbuffer(context.FRAMEBUFFER, context.DEPTH_ATTACHMENT, context.RENDERBUFFER, this.multisampleDepth);if (context.checkFramebufferStatus(context.FRAMEBUFFER) !== context.FRAMEBUFFER_COMPLETE) throw new Error('Multisample framebuffer allocation failed. Choose a lower quality preset.');this.renderTargets.record('multisampleColor', { width, height, format: this.hdr ? 'RGBA16F' : 'RGBA8', samples: this.multisampleSamples });- this.renderTargets.record('multisampleDepth', { width, height, format: 'DEPTH_COMPONENT24', samples: this.multisampleSamples });+ this.renderTargets.record('multisampleDepth', { width, height, format: depthFormat, samples: this.multisampleSamples });this.renderTargets.record('frameColor', { width, height, format: this.hdr ? 'RGBA16F' : 'RGBA8' });this.frameTexture = context.createTexture();context.bindTexture(context.TEXTURE_2D, this.frameTexture);diff --git a/tests/render-target-memory.test.js b/tests/render-target-memory.test.jsindex 08e4b59e..9e9c5bbf 100644--- a/tests/render-target-memory.test.js+++ b/tests/render-target-memory.test.js@@ -68,3 +68,25 @@ test('the local shadow atlas holds one row of tiles per four shadow tiles and reassert.deepEqual(sizes, [[2048, 512], [2048, 1024]]);assert.equal(renderer.memoryReport().targets[0].height, 1024);});++function frameTargetRenderer(depth) {+ const { context } = recordingContext();+ const renderer = Object.create(Renderer67.prototype);+ Object.assign(renderer, {+ context, depth, hdr: true, multisampleSamples: 4, renderTargets: new RenderTargetLedger(), releaseFrameTargets() {},+ });+ return renderer;+}++test('the multisampled depth uses 16 bits unless a depth texture needs the same format as its resolve', () => {+ const plain = frameTargetRenderer(false);+ plain.allocateFrameTargets(960, 540);+ const plainDepth = plain.memoryReport().targets.find(target => target.name === 'multisampleDepth');+ assert.equal(plainDepth.format, 'DEPTH_COMPONENT16');+ assert.equal(plainDepth.bytes, 960 * 540 * 4 * 2);+ const withTexture = frameTargetRenderer(true);+ withTexture.allocateFrameTargets(960, 540);+ const textureDepth = withTexture.memoryReport().targets.find(target => target.name === 'multisampleDepth');+ assert.equal(textureDepth.format, 'DEPTH_COMPONENT24');+ assert.equal(textureDepth.bytes, 960 * 540 * 4 * 4);+});