Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.
C++ 3d3d-sculptingcppdear-imguidigital-sculptingfbxgame-developmentgaussian-splattinggltfimage-to-3dmcpopenglopenusdsculptingtext-to-3dunreal-engine
core-200m phase 1: design doc and a memory-only 200M benchmark scene
islandmed0136d4f20533
diff --git a/docs/design/core-200m.md b/docs/design/core-200m.mdnew file mode 100644index 00000000..4c0ccfa8--- /dev/null+++ b/docs/design/core-200m.md@@ -0,0 +1,194 @@+# Core 200M: 200 million sculptable polygons on a 16 GB laptop with an integrated GPU++Research branch `research/core-200m` (2026-11-03). Generic techniques, designed here from first principles (regular+grids, multiresolution offsets, quantization, page tables, copy-on-write); no competitor code, files or docs.++**Headline target, floor profile** (integrated GPU, GL 3.3, 4 cores; perf-moonshots.md §0, `SF_HW_SIMULATE=floor`):++| | target |+|---|---|+| Asset | 200M triangles on a 16 GB laptop with an iGPU (shared video memory) |+| Stroke latency (pen to visible surface) | < 16 ms |+| Frame while sculpting | p99 < 33 ms |+| Orbit | smooth (p99 < 33 ms), full detail refined on release |+| Open | < 5 s to a sculptable, fully shaded view |+| Memory | 0.6-1.2 GB for the 200M asset (RSS, everything) |++The rule behind every piece: **cost follows the pixels on screen and the brush footprint, never the total count.**++## 0. What we already have (mapped before designing)++| Piece | Where | State | What it gives 200M | Gap |+|---|---|---|---|---|+| Regular grid patches over the base cage, implicit topology | `core/Micro.h` (`MicroMesh`, `MicroPatch`, `BaseCage`) | on | the storage model of §1: one grid of `(n+1)(n+2)/2` points per base triangle, no index buffer, edges stitched | heights are one level, measured from the Phong surface of the cage, not from a smoothed lower level |+| 16-bit quantized displacement | `MicroMesh::disp` (`MicroStore`) | on | 2 B a grid point, 1.11 B a triangle at Micro 5 | edges and corners stored once per patch (~10% extra at Micro 5) |+| Derived normals | `MicroShader` (CPU), shading grid on the GPU | on | no normals stored on the CPU | the GPU shading grid is 4 B a point for every patch (440 MB at 200M) and the first full shading runs at open |+| Per-cluster LOD to a triangle budget | `render/MicroRenderer` | on | draw cost bounded by `renderTriangleBudget` (3-4M drawn at 299M-1B, 8-13 ms on this laptop) | every patch's full grid is resident on the GPU (6 B a point); the budget is triangles, not pixels |+| Stride-sampled ("scale-adaptive") dabs | `MicroStroke::adaptive`, `kBrushSamples = 48` | on | the kernel evaluates ~48 samples across the radius at any level | the interpolated values are still written to every fine point: a 300 px dab at 1B writes millions of points (283 ms) |+| Out of core | `MicroStore` (mmap sparse file), `PatchPageTable` | on (auto above 1/4 of RAM) | levels larger than RAM; the OS page cache is the LRU | no compression in memory, no visible-first order |+| Compressed streamed patches | `core/FocusDetail` (`.sfdetail`, zstd, coarse level-3 grids, focus promotion 0.04 ms a tile) | prototype, off | 1.02B opens in < 1 s from 241 MB; `tileLevel(tri)` per patch | CPU array still dense; GPU doesn't use per-tile levels; not wired into projects |+| Per-patch undo | `MicroUndo` journal (Morton-ordered tiles, delta + bit-packed) | on | 0.6-11 MB a 30-dab stroke (31 KB for a short stroke at 5M) | rounding noise of fine writes inflates it; coarse-level edits (§3) would shrink it to KBs |+| Patch-parallel jobs | `ThreadPool::poolFor` in MicroSculpt / Micro / MicroRenderer / FocusDetail | on | deterministic block-parallel kernels | the parallel loops are fork-join per dab; dirty bits are plain words written by one thread at a time; stitching serialises at patch edges |+| Canvas cache | perf-moonshots.md §7 (research/perf-moonshots) | design | idle frames composite only; a dab re-rasterizes its rectangle | not built |++So phase 1 needs no new storage: a 200M micro level fits on today's code. What it doesn't do yet is make the GPU+copy, the open time and the big-brush cost follow the screen and the brush. That is phases 2-5.++## 1. Storage++**Layout.** Each base triangle of the cage (the Part's top subdivision level) carries a regular grid of+`n = 2^L` segments per edge: `n^2` micro triangles, `(n+1)(n+2)/2` points. Topology is implicit (index arithmetic,+`MicroMesh::index`); only heights are stored.++**Heights against the smoothed lower level.** Phase 1 stores, as today, one 16-bit height per point along the+normal of the Phong-tessellated cage. The target layout (phase 3) is multiresolution: level `l` stores, per point+it adds (the odd points of the level-`l` grid), a 16-bit offset from the *smoothed* level `l-1` surface (the+Loop-style average of its neighbours, evaluated from the coarser level), along that surface's normal. Points that+exist at `l-1` are not stored again. Total points over all levels are the same as the finest grid (each point is+stored once, at the level that introduces it), so the memory is the same 2 B a point; what changes is that a big+form lives in a few coarse values and the fine values stay small (and compress, §4).++**Arithmetic for 200M** (Micro 5: n = 32, 1,024 triangles and 561 points a patch; 195,313 base triangles):++| Item | Per | Count | Bytes |+|---|---|---|---|+| Micro triangles | | 195,313 x 1,024 | **200.0M** |+| Grid points, per-patch copies (today) | 561 a patch | 109.6M | |+| Grid points, unique (edges once) | ~triangles / 2 | 100.0M | |+| Heights, today's layout | 2 B a point | 109.6M | **219 MB** (1.10 B a triangle) |+| Heights, edges stored once (phase 3) | 2 B a point | 100.0M | 200 MB |+| Base cage + BVH (195K triangles, ~90 B + BVH) | | | ~25 MB |+| Mask, sparse 32x32-point tiles, 1 B a point | where masked | 10% of the surface | ~11 MB (0 when unused) |+| Colour, sparse tiles, RGBA8 | where painted | 25% painted / all | ~110 MB / 440 MB |+| Derived normals | | | 0 on the CPU (computed per patch when drawn) |+| GPU: today (2 B height + 4 B shading, every patch) | 6 B a point | 109.6M | 658 MB |+| GPU: pixel-bounded (§2), resident patches only | 6 B a point | ~10-20M points | 60-120 MB |+| Undo, per-patch copy-on-write (§5), 50 steps | | | ~5-50 MB |+| App, fonts, GL driver, UI | | | ~250 MB |++- **Sculpt only, pixel-bounded GPU:** 219 + 25 + 120 + 50 + 250 = **~0.66 GB**.+- **Mask + all-over colour:** + 11 + 440 = **~1.1 GB**.+- **Today's renderer (phase 1 prototype):** 219 + 25 + 658 (on unified memory this is system RAM) + 250 = ~1.15 GB,+ plus the shading pass at open. Phase 1 measures this.++So 2 B a vertex for shape, 3 with a mask, 6 with colour everywhere: 2-6 B a vertex, 0.6-1.2 GB for 200M.++## 2. Pixel-bounded draw++- **Per-patch stride LOD.** A patch draws at stride `s = 2^k` (its grid every `s` points: `(n/s)^2` triangles),+ chosen so its micro edge projects to about one pixel (`targetPx`), clamped by the frame's triangle budget from+ the hardware profile. MicroRenderer does this per cluster today; phase 2 makes it per patch and makes the GPU+ *residency* follow it: a patch's GPU grid holds only the levels the view needs (coarse level-3 grids for+ everything, full grids for the patches whose projected edge needs them), using `FocusDetail::tileLevel(tri)`.+ Crack-free borders: the finer side snaps its edge points to the coarser edge (as now).+- **Budget.** At 1920x1080 about 2M pixels are covered at most: ~2-4M triangles drawn at one triangle a pixel,+ whatever the asset size. On the floor profile 2M (1M moving).+- **Shading on demand.** Shading (octahedral normal, curvature) is computed for resident patches at their resident+ level only, visible first; a coarse patch shades its 45 points, not 561 (cuts the open-time shading ~12x at+ Micro 5, ~180x at Micro 7).+- **Canvas cache** (perf-moonshots.md §7): with the screen cached, an idle frame composites one quad and a dab+ re-rasterizes only the patches under its dirty rectangle, so stroke frames cost the brush's pixels.+- **Orbit:** draw the moving budget (coarser stride, lower view resolution on the floor), refine to full on release.++## 3. Scale-adaptive dabs and lazy push-up++- A dab is applied at the level `l` where its radius spans **64-256 samples** (`r / edge(l)` in that range), not+ at the finest level. A 300 px brush at 200M lands on a level with ~10^4 points under it instead of ~10^6.+- With the multiresolution layout (§1) the finer levels are offsets from the smoothed coarser one, so the detail+ rides along with no write at all; Clay, Standard, Inflate and Move are pure coarse edits.+- Brushes that need fine values (Smooth of fine detail, Flatten to a plane, Pinch) read the finest level under the+ brush, so they apply at the finest level their radius allows (radius / 256 or coarser) and only there.+- **Lazy push-up:** where a coarse edit invalidates something fine (the shading grid, a cached finest-level+ position on the GPU, a Focus Detail tile's compressed copy), the patch is marked `stale(l)`. Visible stale patches+ are refreshed within the frame's budget, nearest the brush first; hidden ones by a background job at idle+ ("catch-up"), or when they become visible. Nothing is pushed into patches nobody looks at.+- **Checkpoint numbers to beat** (docs/performance.md, today): Standard 300 px 115 ms a step at 299M Micro 4,+ 283 ms at 1.02B; phase 3 target < 8 ms CPU a dab at 200M on the laptop, < 16 ms on the floor profile.++## 4. Out-of-core compressed patches, visible-first++Reuse Focus Detail (`core/FocusDetail`, docs/design/focus-detail.md): patches as quantized, row-delta coded,+zstd-compressed tiles, a coarse level-3 grid per tile in compressed chunks, a directory, crash-safe header-last+saves, promotion 0.04 ms a tile. What 200M adds:+- **Visible-first open:** read the cage and the coarse chunks (a few MB), draw; then decompress the visible patches+ nearest the camera first; the rest stream in the background or stay compressed. First frame < 1 s.+- **Sparse CPU pool** (focus-detail.md §7 item 4): full grids only for promoted patches, indexed per patch, so RSS+ follows the focus, not the asset. Only required past ~1B on 16 GB; for 200M the dense array (219 MB) is+ affordable, so this is the last step, not the first.+- **Project integration:** `.sfproj` stores or references the detail file; Save writes dirty tiles only (53 ms).++## 5. Per-patch copy-on-write undo++A stroke saves, the first time it touches a patch, that patch's old heights (and mask / colour tile); the step is+the set of touched patches, delta-coded and bit-packed (the `MicroUndo` journal already does this, Morton+ordered). With coarse-level edits (§3) a big stroke touches thousands of coarse values instead of millions of fine+ones, so steps become **KBs per stroke** (today 0.6-11 MB for a 30-dab benchmark stroke, from rounding noise in+fine writes). Undo and redo apply the same deltas; Focus Detail promotes the patches first (`ensureFull`).++## 6. Lock-free patch-parallel jobs++- Patches are the unit of work and ownership: a job owns a patch for the dab (no locks inside), interior points+ are independent; only edge stitching reads a neighbour, done in a second pass after a barrier, edge by edge+ (each shared edge has one owner: the patch with the lower index).+- Dirty and stale state is an atomic bitset (`fetch_or`), so the solver, the renderer's sync and background+ catch-up never take a lock; the renderer swaps out the dirty words it consumed.+- A small job graph per frame (pick → dab kernels per patch → stitch → shade visible → upload) on the existing+ `ThreadPool`, with the block-ordered determinism it already guarantees; background catch-up and decompression+ run at low priority and yield to the stroke.+- Floor profile: 4 workers; the stroke's jobs run first, everything else fills idle time.++## 7. Phases and checkpoints++Every number twice: this laptop and the floor profile (`SF_HW_SIMULATE=floor`), at load < 2.++| Phase | What | Checkpoint (measurable) |+|---|---|---|+| **1** (this branch) | Memory-only 200M prototype on today's micro levels: `--benchmark core-200m` (off by default; writes the scene once, then opens it and orbits) | RSS, open time (project open, first frame, fully shaded), orbit p50 / p99, GPU MB: measured below |+| 2 | Pixel-bounded GPU: per-patch resident levels (coarse grids + full where needed), shading on demand, visible first | GPU < 150 MB at 200M; open to fully shaded < 2 s; orbit p99 < 33 ms on the floor profile; picture equal to today's at rest (screenshot test) |+| 3 | Multiresolution offsets + dabs at the 64-256-sample level + lazy push-up + background catch-up | 300 px dab < 8 ms CPU on the laptop, < 16 ms floor; stroke latency < 16 ms; p99 frame while sculpting < 33 ms floor; same result as the fine-level brush within quantization (test) |+| 4 | Focus Detail for 200M: compressed patches, visible-first open, project integration, sparse pool | open < 5 s floor (first frame < 1 s); file < 300 MB; RSS with colour < 1.2 GB |+| 5 | COW undo on coarse edits; atomic dirty/stale bits; per-frame job graph | undo < 100 KB a typical stroke; 4-thread speed-up > 3x on dab kernels; no lock on the stroke path (TSan clean) |+| 6 | Canvas cache (perf-moonshots §7) on top; real iGPU runs by testers (Windows UHD 620 / Iris Xe first) | idle frame ~0 ms GPU; floor numbers confirmed on real hardware before anything defaults on |++Nothing here merges into a release without the floor-tier numbers.++## 8. Phase 1 results++Run: `sculptforge --benchmark core-200m --benchmark-no-video` (Release). The scene: the bench head at 196,608 base+triangles (asked for 195,313; the head's cube quads round it), Micro 5, two octaves of `microNoise` (wrinkle- and pore-sized), in memory; written once as a project+in the swap folder, then each run opens it (`loadProject`), shows it, waits until the shading is complete and+orbits twice (10 s each, the view moving every frame).++**This laptop** (MacBook Pro 16" M1 Pro, 10 cores, 32 GB unified, Asahi Mesa 26.1.8 GL 4.6, framebuffer 3408x2136;+Release @ the branch's SHA; three runs back to back at 1-minute load 1.8 / 2.2 / 1.8, so at or just about load 2):++| | run a | run b | run c |+|---|---:|---:|---:|+| Micro triangles (196,608 base x 1,024, Micro 5) | 201.3M | 201.3M | 201.3M |+| Project file (written once) | 148 MB | | |+| Open project (`loadProject`) | 0.17 s | 0.17 s | 0.17 s |+| Open to first frame (shading and upload of every patch included) | 0.69 s | 0.69 s | 0.70 s |+| RSS when shown | 569 MB | 567 MB | 578 MB |+| Peak RSS (whole run) | 579 MB | 569 MB | 591 MB |+| GPU buffers (renderer, not in RSS; on unified memory this is system RAM too) | 640 MB | 640 MB | 640 MB |+| Orbit 1 (10 s, moving every frame): p50 / p99 | 12.4 / 51.7 ms | 12.9 / 35.9 ms | 12.6 / 32.1 ms |+| Orbit 2: p50 / p99 | 12.2 / 37.5 ms | 12.8 / 24.4 ms | 13.3 / 37.7 ms |+| Worst single frame | 68 ms | 66 ms | 67 ms |++Reading it:+- **Memory: met.** 0.57-0.59 GB RSS plus 0.64 GB of GPU buffers = ~1.2 GB in all for 200M, the top of the 0.6-1.2 GB+ range of §1, as predicted for today's renderer (every patch's full grid on the GPU). Phase 2 takes the 640 MB+ down to ~100 MB.+- **Open: met** (0.7 s to a fully shaded view, target < 5 s). The first frame shades every patch at once+ (~0.5 s at 110M points on 10 cores); on 4 floor cores that is ~1.3 s, still a single stall phase 2 removes.+- **Orbit: p50 met (~80 fps), p99 not yet.** p99 24-52 ms against < 33 ms; one 60-68 ms frame per run. The p50 is+ the per-cluster LOD doing its job (the draw follows the budget, not the 200M); the tail is not yet explained+ (candidates: the motion-proxy switch at the start of a move, shared-machine noise at load ~2, the 7.3M-pixel+ framebuffer). To profile in phase 2 before claiming "smooth".+- **Floor profile: not measured yet.** `SF_HW_SIMULATE=floor` is not in research/perf-moonshots yet; the same+ command reruns there once it lands. Expect the open to be ~2x slower (4 workers) and GPU memory the problem: 640 MB+ of buffers against the 1-2 GB of shared video memory of a floor iGPU fits but leaves little; phase 2 is the fix.++Reproduce: `sculptforge --benchmark core-200m --benchmark-no-video` (the first run writes+`~/.cache/sculptforge/core-200m-v1.sfproj`, about 3 s). Test: `micro_core200m_scene_small` (scene build, in memory,+project round trip bit-exact).diff --git a/src/app/ProofMode.cpp b/src/app/ProofMode.cppindex 62ca9143..583165c3 100644--- a/src/app/ProofMode.cpp+++ b/src/app/ProofMode.cpp@@ -24,6 +24,7 @@#include "core/Benchmark.h"#include "core/MemoryGuard.h"#include "core/Primitives.h"+#include "core/Project.h"#include "core/Timeline.h"#include "render/GL.h"@@ -99,6 +100,19 @@ std::vector<ProofMeshSize> proofStandardScene(const std::string& name) {}, 5};return {s1b};}+ if (name == "core-200m") { // research (docs/design/core-200m.md, phase 1): ~200M micro triangles in memory, opened from a project+ const ProofMeshSize s200{200, "200M micro", [](size_t) {+ std::string err;+ const std::string path = core200mScenePath(err); // (main wrote it first)+ Document d;+ if (path.empty() || !loadProject(path, d, err)) {+ std::fprintf(stderr, "core-200m: %s\n", err.c_str());+ return makeBenchHead(size_t(1) << 20);+ }+ return std::move(d.mesh);+ }, 8};+ return {s200};+ }return {};}@@ -373,6 +387,9 @@ struct SizeResult {std::string label;size_t triangles = 0, vertices = 0;double buildSeconds = 0;+ double firstFrameSeconds = 0; // build start to the first frame showing the mesh+ double shadedSeconds = 0; // ... to the frame its micro level's shading was complete (0: no micro level)+ size_t loadedRamBytes = 0; // resident memory at that framesize_t ramBytes = 0, peakRamBytes = 0;size_t gpuBufferBytes = 0; // the most the renderer's vertex and index buffers held (documentMemory().gpu)long long vramUsedKb = -1; // the most the driver's free graphics memory dropped from before the build (-1: unknown)@@ -394,6 +411,7 @@ struct ProofState {std::string jsonPath, videoPath;std::vector<ProofMeshSize> sizes;size_t sizeIndex = 0, phaseIndex = 0;+ double buildStart = 0; // when the current size's build beganstd::vector<PhaseSpec> phases;std::vector<SizeResult> results;double stageStart = 0, lastFrame = 0, lastSample = 0;@@ -496,7 +514,8 @@ void App::startProofMode() {};p->jsonPath = !options_.benchmarkOut.empty() ? options_.benchmarkOut : u8(dir / ("sculptforge-benchmark-" + stamp + ".json"));p->videoPath = !options_.benchmarkVideo.empty() ? options_.benchmarkVideo : u8(dir / ("sculptforge-benchmark-" + stamp + ".mp4"));- if (!p->scene.empty()) p->phases = standardPhases(p->strokeSeconds);+ if (p->scene == "core-200m") p->phases = {{"orbit", 0.0f, 10.0}, {"orbit again", 0.0f, 10.0}}; // phase 1: loads and orbits+ else if (!p->scene.empty()) p->phases = standardPhases(p->strokeSeconds);else p->phases = {{"stroke", 60.0f, p->strokeSeconds}, {"large brush stroke", 240.0f, p->strokeSeconds}, {"orbit", 0.0f, 3.0}};p->stage = p->cli ? ProofState::Stage::Announce : ProofState::Stage::Intro;p->radiusBefore = radiusPx_;@@ -746,7 +765,7 @@ void App::proofBeforeSwap(int fbW, int fbH) {auto nextPhase = [&] {SizeResult& r = p.results.back();if (r.phases.back().seconds == 0) r.phases.back().seconds = now - p.stageStart; // (a stroke set it at its release)- r.gpuBufferBytes = std::max(r.gpuBufferBytes, documentMemory(doc_).gpu);+ r.gpuBufferBytes = std::max({r.gpuBufferBytes, documentMemory(doc_).gpu, renderer_.gpuBytes()}); // (the estimate leaves micro levels out)if (r.vramFreeBeforeKb >= 0)if (const long long freeKb = driverFreeVramKb(); freeKb >= 0)r.vramUsedKb = std::max(r.vramUsedKb, std::max(0LL, r.vramFreeBeforeKb - freeKb));@@ -823,10 +842,11 @@ void App::proofBeforeSwap(int fbW, int fbH) {Mesh m = s.build ? s.build(tris) : makeBenchSphere(tris);SizeResult r;r.label = s.label;- r.triangles = m.micro && m.micro->focus ? microTriangleCount(m) : m.triangleCount(); // (Focus Detail: its micro triangles)+ r.triangles = m.micro ? microTriangleCount(m) : m.triangleCount(); // (a micro level: its micro triangles)r.vertices = m.vertexCount();doc_.setMesh(std::move(m), "Benchmark");r.buildSeconds = nowSeconds() - t0;+ p.buildStart = t0;r.vramFreeBeforeKb = vramBefore;p.results.push_back(r);camera_.frame(sceneBounds());@@ -841,9 +861,18 @@ void App::proofBeforeSwap(int fbW, int fbH) {p.hudLine2 = "settling (the first upload to the GPU)";break;}- case Stage::Settle:- if (now - p.stageStart > 1.0 && !backgroundBusy()) beginPhase();+ case Stage::Settle: {+ // (called before the swap: this frame has drawn the new mesh)+ SizeResult& r = p.results.back();+ if (r.firstFrameSeconds == 0) r.firstFrameSeconds = now - p.buildStart;+ const bool shading = renderer_.microPendingShading() > 0;+ if (doc_.mesh.micro && !shading && r.shadedSeconds == 0) {+ r.shadedSeconds = now - p.buildStart;+ r.loadedRamBytes = residentBytes();+ }+ if (now - p.stageStart > 1.0 && !backgroundBusy() && !shading) beginPhase();break;+ }case Stage::Phase: {const PhaseSpec& spec = p.phases[p.phaseIndex];PhaseResult& ph = p.results.back().phases.back();@@ -985,6 +1014,11 @@ void App::proofBeforeSwap(int fbW, int fbH) {run.set("triangles", double(r.triangles));run.set("vertices", double(r.vertices));run.set("build_seconds", std::round(r.buildSeconds * 100) / 100);+ run.set("first_frame_seconds", std::round(r.firstFrameSeconds * 100) / 100);+ if (r.shadedSeconds > 0) {+ run.set("shaded_seconds", std::round(r.shadedSeconds * 100) / 100);+ run.set("loaded_ram_mb", double(r.loadedRamBytes >> 20));+ }run.set("ram_mb", double(r.ramBytes >> 20));run.set("peak_ram_mb", double(r.peakRamBytes >> 20));run.set("gpu_buffers_mb", double(r.gpuBufferBytes >> 20));@@ -1038,6 +1072,10 @@ void App::proofBeforeSwap(int fbW, int fbH) {std::printf(" %s\n", r.skipped.c_str());continue;}+ std::printf(" %-5s %.1fM triangles: built / opened %.2f s, first frame %.2f s", r.label.c_str(), double(r.triangles) / 1e6,+ r.buildSeconds, r.firstFrameSeconds);+ if (r.shadedSeconds > 0) std::printf(", fully shaded %.2f s (RAM then %zu MB)", r.shadedSeconds, r.loadedRamBytes >> 20);+ std::printf("\n");std::printf(" %-5s peak RAM %zu MB, GPU buffers %zu MB%s, worst stall %.0f ms\n", r.label.c_str(), r.peakRamBytes >> 20,r.gpuBufferBytes >> 20, r.vramUsedKb > 0 ? (", driver VRAM used " + std::to_string(r.vramUsedKb >> 10) + " MB").c_str() : "",[&] { double w = 0; for (const PhaseResult& ph : r.phases) w = std::max(w, worstStallMs(ph.frameMs, ph.releaseMs)); return w; }());diff --git a/src/app/main.cpp b/src/app/main.cppindex 1376d8ac..b853e166 100644--- a/src/app/main.cpp+++ b/src/app/main.cpp@@ -5,6 +5,7 @@#include "app/Calibration.h"#include "app/CrashLog.h"#include "ai/AiPolicy.h"+#include "core/Benchmark.h"#include "core/FocusDetail.h"#include "core/Pack.h"@@ -71,6 +72,7 @@ void usage() {" --benchmark standard-15m The standard scene: a 15M triangle head, Clay S/M/L, Move, Smooth and a 240 px\n"" brush (standard-33m: 33M; standard: both). The numbers on sculptforge.app/benchmarks\n"" --benchmark standard-1b Experimental Focus Detail: a billion micro triangle head streamed from disk\n"+ " --benchmark core-200m Research: a 200 million micro triangle head in memory (open and orbit)\n"" --focus-detail FILE Experimental: open a Focus Detail file (.sfdetail)\n"" --benchmark-sizes 5,20 Proof mode mesh sizes in millions of triangles\n"" --benchmark-out FILE Where the JSON result goes (default: sculptforge-benchmark-<time>.json here)\n"@@ -195,11 +197,12 @@ int main(int argc, char** argv) {else if (a == "--benchmark") {options.benchmark = true;// An optional scene name: sculptforge --benchmark standard-15m- if (i + 1 < argc && std::string(argv[i + 1]).rfind("standard", 0) == 0) {+ if (i + 1 < argc && (std::string(argv[i + 1]).rfind("standard", 0) == 0 || std::string(argv[i + 1]) == "core-200m")) {options.benchmarkScene = argv[++i];if (options.benchmarkScene != "standard" && options.benchmarkScene != "standard-15m" &&- options.benchmarkScene != "standard-33m" && options.benchmarkScene != "standard-1b") {- std::fprintf(stderr, "Unknown benchmark scene %s (standard-15m, standard-33m, standard or standard-1b)\n", argv[i]);+ options.benchmarkScene != "standard-33m" && options.benchmarkScene != "standard-1b" &&+ options.benchmarkScene != "core-200m") {+ std::fprintf(stderr, "Unknown benchmark scene %s (standard-15m, standard-33m, standard, standard-1b or core-200m)\n", argv[i]);return 1;}}@@ -239,6 +242,13 @@ int main(int argc, char** argv) {return 1;}}+ if (options.benchmarkScene == "core-200m") { // research: 200M micro triangles in memory, the project written once+ std::string error;+ if (sf::core200mScenePath(error, [](const std::string& s) { std::fprintf(stderr, "%s\n", s.c_str()); }).empty()) {+ std::fprintf(stderr, "core-200m: %s\n", error.c_str());+ return 1;+ }+ }if (options.benchmark && !sizeGiven) options.width = 1920, options.height = 1080;if (options.benchmark || !options.timelapsePath.empty()) isolateSettings(); // the user's settings and files untouchedif (!options.timelapsePath.empty() && !sizeGiven) options.width = 1920, options.height = 1080;diff --git a/src/core/Benchmark.cpp b/src/core/Benchmark.cppindex 0deae298..7cb9da81 100644--- a/src/core/Benchmark.cpp+++ b/src/core/Benchmark.cpp@@ -196,6 +196,41 @@ Mesh benchMesh(size_t triangles, bool head) {Mesh makeBenchSphere(size_t triangles) { return benchMesh(triangles, false); }Mesh makeBenchHead(size_t triangles) { return benchMesh(triangles, true); }+Mesh makeCore200mMesh(size_t baseTriangles, int level) {+ Mesh m = makeBenchHead(baseTriangles);+ std::string err;+ if (!microDivide(m, level, err, 0)) return m; // (in memory: phase 1 is the memory-only prototype)+ microNoise(m, 0.004f, 40.0f, 1); // forms the size of wrinkles+ microNoise(m, 0.0008f, 400.0f, 2); // and pores+ m.micro->clearDirty();+ m.micro->markAllDirty();+ return m;+}++std::string core200mScenePath(std::string& error, const std::function<void(const std::string&)>& log) {+ namespace fs = std::filesystem;+ const fs::path dir = MicroStore::swapFolder();+ std::error_code ec;+ fs::create_directories(dir, ec);+ const fs::path path = dir / "core-200m-v1.sfproj";+ if (fs::exists(path, ec)) return path.string(); // (renamed into place when whole)+ if (log) log("Writing the core-200m scene (once): " + path.string());+ Document doc;+ doc.mesh = makeCore200mMesh();+ if (!doc.mesh.micro) {+ error = "core-200m: couldn't divide to micro level 5";+ return {};+ }+ const fs::path tmp = fs::path(path.string() + ".tmp.sfproj");+ if (!saveProject(tmp.string(), doc, error)) return {};+ fs::rename(tmp, path, ec);+ if (ec) {+ error = "Can't write " + path.string();+ return {};+ }+ return path.string();+}+namespace {using Clock = std::chrono::steady_clock;diff --git a/src/core/Benchmark.h b/src/core/Benchmark.hindex b9532f07..36f26b06 100644--- a/src/core/Benchmark.h+++ b/src/core/Benchmark.h@@ -81,6 +81,13 @@ Mesh makeBenchSphere(size_t triangles);// eye sockets, nose, cheekbones, jaw, ears, neck) of about `triangles` triangles, with subdivision levels. Made// from a formula, not a file, so every build and platform sculpts the same surface.Mesh makeBenchHead(size_t triangles);+// The core-200m research scene (docs/design/core-200m.md, phase 1; --benchmark core-200m, off by default): the+// bench head at micro level 5 with procedural detail, about 200 million micro triangles, held in memory. Written+// once as a project in the swap folder (a few seconds) so the benchmark measures opening it; returns its path,+// or "" with `error`.+std::string core200mScenePath(std::string& error, const std::function<void(const std::string&)>& log = {});+// The scene itself, built in memory (what core200mScenePath saves): `baseTriangles` base triangles at `level`.+Mesh makeCore200mMesh(size_t baseTriangles = 195313, int level = 5);// Resident memory of this process in bytes (0 where unknown).size_t residentBytes();diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cppindex 2a4ed610..8c740995 100644--- a/src/render/Renderer.cpp+++ b/src/render/Renderer.cpp@@ -1080,6 +1080,13 @@ void Renderer::freeSlot(MeshSlot& s) {s = MeshSlot();}+size_t Renderer::microPendingShading() const {+ size_t total = 0;+ for (const MeshSlot& s : slots_)+ if (s.micro) total += s.micro->pendingShading();+ return total;+}+size_t Renderer::gpuBytes() const {size_t total = 0;for (const MeshSlot& s : slots_) {diff --git a/src/render/Renderer.h b/src/render/Renderer.hindex e69ec29f..dc77a452 100644--- a/src/render/Renderer.h+++ b/src/render/Renderer.h@@ -225,6 +225,8 @@ public:// Bytes of GPU buffers and textures the mesh slots hold.size_t gpuBytes() const;+ // Micro grid points whose shading still waits for a frame's budget (MicroRenderer::pendingShading, all slots).+ size_t microPendingShading() const;// Triangles the last draw() sent to the GPU (after culling), for the benchmark.size_t lastDrawnTriangles() const { return lastDrawn_; }// The last syncScene left motion proxies to build (a few milliseconds of them a frame; the rest draw in full).diff --git a/tests/test_micro.cpp b/tests/test_micro.cppindex 40f6e4e5..f26da718 100644--- a/tests/test_micro.cpp+++ b/tests/test_micro.cpp@@ -570,3 +570,33 @@ TEST(micro_tier_config_and_page_table) {CHECK(ooc.mesh.micro->disp[7 * ooc.mesh.micro->samples] == 3); // trimmed pages come back from the file}}++TEST(micro_core200m_scene_small) {+ // The core-200m research scene (docs/design/core-200m.md), at a test's size: in memory, detailed, and it+ // survives a project round trip unchanged.+ Document doc;+ doc.mesh = makeCore200mMesh(2000, 3);+ CHECK(doc.mesh.micro);+ if (!doc.mesh.micro) return;+ const MicroMesh& mm = *doc.mesh.micro;+ CHECK(mm.level == 3 && !mm.disp.mapped());+ CHECK(microTriangleCount(doc.mesh) == size_t(mm.baseTriangles) * 64);+ CHECK(mm.rangeMax > 0); // the noise is there+ namespace fs = std::filesystem;+ std::error_code ec;+ const std::string path = (fs::temp_directory_path(ec) / "sf-test-core200m.sfproj").string();+ std::string err;+ const bool saved = saveProject(path, doc, err);+ CHECK(saved);+ Document back;+ const bool loaded = saved && loadProject(path, back, err);+ CHECK(loaded);+ fs::remove(path, ec);+ if (!loaded) return;+ CHECK(back.mesh.micro);+ if (!back.mesh.micro) return;+ CHECK(back.mesh.micro->baseTriangles == mm.baseTriangles && back.mesh.micro->level == 3);+ bool same = true;+ for (size_t i = 0; i < mm.disp.size() && same; ++i) same = back.mesh.micro->disp[i] == mm.disp[i];+ CHECK(same);+}