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
Floor tier: SF_HW_SIMULATE=floor, benchmark frame split, design targets and canvas track
islandmed94c9136f34d9
diff --git a/docs/design/perf-moonshots.md b/docs/design/perf-moonshots.mdindex 3cec8bb8..3af47249 100644--- a/docs/design/perf-moonshots.md+++ b/docs/design/perf-moonshots.md@@ -10,6 +10,61 @@ Starting point (Tony's clean 33M run, M1 Pro, Asahi, Mesa GL 4.6, unified memoryp99s to about 30 ms; what it leaves is the surface trailing the pen (each 240 px dab at 33M still costs100-200 ms of CPU) and Move, which never used the solver path.+## 0. Hard requirement: the floor tier (Tony, 11-03)++Weak GPUs must get great performance too, not only big cards. Every idea, prototype and default below is held to+this; an experiment that misses it stays off for that tier or doesn't ship.++1. **Floor hardware.** Integrated GPUs: Intel UHD 620 / Iris Xe, AMD Vega / 680M iGPU, Apple M1 base. OpenGL 3.3,+ 8 GB RAM, about 1-2 GB of shared video memory, 4 cores. Windows first (the biggest install base; real-hardware+ checks by testers).+2. **Costs bounded by screen pixels and brush footprint, never total polygon count.** The cluster-LOD pixel budget+ and the draw budget come from the hardware profile (calibration: `renderTriangleBudget()`,+ `motionProxyThreshold()`, `TierConfig::uploadBudgetMBPerFrame`). Under load they degrade gracefully: fewer drawn+ triangles, a lower view resolution while the view moves, full quality on release. They never stutter: a budget+ is cut before a frame is late, not after.+3. **GPU work is optional.** Sculpting, normals, picking and undo stay on the CPU, multithreaded; the GPU only draws+ a budgeted set. No feature may require compute shaders, SSBOs, mesh shaders or big VRAM; anything newer than+ GL 3.3 is an optional fast path with a GL 3.3 fallback that produces the same picture. A CPU raster path for+ sub-pixel clusters (and for the canvas, §7 E) is part of the plan.+4. **Memory.** Compact per-vertex storage so 20M+ triangles fit in 8 GB with headroom. Today the scene is about+ 90 bytes per triangle (docs/performance.md): 20M = 1.8 GB plus undo, which fits; 50M = 4.5 GB, which does not+ leave headroom on 8 GB. Target: 60 bytes per triangle at the top level (quantized positions in the cluster grid,+ octahedral normals, implicit adjacency), and micro levels (1.25 bytes per triangle) above ~8M.+5. **Benchmarks.** Every number is reported twice: this laptop and the **iGPU-simulated floor profile** (below),+ with p99 frame time and stroke latency at 5, 20 and 50M triangles. A beta must not regress the floor tier.++**The iGPU-simulated profile** (`SF_HW_SIMULATE=floor`, core/HardwareProfile.h; applied where the hardware+profile is applied, so it is the same code a real floor machine runs): Laptop tier; 4 worker threads;+render triangle budget 2M (1M while the view moves); motion proxy from 3M visible triangles; upload budget+16 MB a frame; no GL 4.4 buffer storage (Fast Upload falls back); resident caches capped at 1 GB; the governor+may lower the budget, never raise it. Still to add: view resolution 75% while the view moves (only a fixed view+resolution exists today).++**Frame split.** `--benchmark` now writes `frame_split_ms` per phase (p50 / p95 / p99 of the main thread's+events, sculpt, UI, upload = ghost + scene sync, draw = GL calls, swap_wait = UI draw + swap, where the frame+waits for the GPU). It decides whether a native backend (D3D11/12, Metal) behind a thin render interface should+move earlier: only if draw + swap_wait dominate on the floor profile at 20M while sculpt and upload are within+budget. Run: `--benchmark --benchmark-sizes 5,20,50`, with and without `SF_HW_SIMULATE=floor`. It simulates the budgets, not the GPU's fill+rate, so real iGPU runs by testers (Windows UHD 620 / Iris Xe first) confirm it.++**Targets, floor profile** (laptop targets in brackets):++| | 5M | 20M | 50M |+|---|---|---|---|+| p99 frame, orbit | < 16 ms [< 8] | < 33 ms [< 11] | < 33 ms, proxy [< 16] |+| p99 frame, 240 px stroke | < 33 ms [< 16] | < 33 ms [< 33] | < 50 ms [< 33] |+| stroke latency (pen to visible surface), p99 | < 16 ms | < 16 ms (canvas track, §7) | < 33 ms |+| RSS after load + 20 strokes | < 1 GB | < 2.5 GB | < 5 GB (needs item 4) |++**The three prototypes against the floor:**++| Prototype | GL needed | Floor tier |+|---|---|---|+| Live Move | GL 3.3 (vertex shader, uniform arrays) | works; takes per-frame grab and upload work off the CPU, so it helps most here. The commit at pen lift is one grab on the CPU (cost is the brush footprint) |+| Background Preview | GL 3.3 | works; draws only the clusters the dabs reach |+| Fast Upload | GL 4.4 buffer storage (optional) | an optional fast path: without the extension (GL 3.3 contexts, macOS GL 4.1) it is off and uploads go the old way, same picture; on Windows iGPUs (GL 4.6 drivers) it needs the floor-profile numbers before it may default on |+## 1. What SculptForge already does (so the ideas below are measured against the right thing)| Piece | Where | State |@@ -191,6 +246,41 @@ the frame; Fast Upload moves the GL thread's 2-10 ms commit copy to a GPU copy.data (3) belongs with the Sculpt Timeline; coarse-first (2) and learned prediction (7) don't pay once thepreview is on.+## 7. Canvas track (the cached screen; Tony, 11-03)++Generic techniques, designed here from first principles (clean room: no decompiling, no copied code or docs). Goal:+a dab costs about the brush's pixels, whatever the mesh size, so the floor tier sculpts 20M like a small mesh.++- **A. Cached screen canvas.** Keep a G-buffer between frames: depth, normal (octahedral, 2x16 bit), material and+ colour per pixel. When nothing moves, nothing is redrawn (the canvas is composited as one quad). While sculpting,+ only the clusters overlapping the brush's dirty screen rectangle (the dab's screen bound, grown by the move) are+ re-rasterized into the canvas, scissored to that rectangle, and only that rectangle is re-shaded. The rectangle+ comes from the dab list we already have (the solver's dabs and the ghost's bounds); the clusters come from the+ existing cluster bounds. Cost per dab: brush pixels plus the clusters under them. Correctness: the depth test+ inside the scissor against the cached depth outside it; clusters straddling the edge are drawn whole and clipped.+- **B. Deferred Lit Sphere shading.** Shade the canvas per pixel from its cached normals with the Lit Sphere lookup+ (one texture fetch, no lights, no shadows) in the interactive path; the full material (PBR, cavity, shadows) is+ applied when the view is still. Re-shading a rectangle is then a texture pass, not a geometry pass.+- **C. Motion.** While orbiting or zooming: draw a lower level or budget (the motion proxy, micro levels' coarse+ level), or reproject the cached canvas for the first frames of a move; full detail returns on release. Input is+ never stalled: the frame takes what the budget allows, never waits for geometry.+- **D. Compact data, levels as offsets.** Multires levels stored as offsets from the level below (the micro levels'+ 16-bit heights already are), so a large brush works at a coarse level and the detail rides along; with §0 item 4+ this is how 50M fits the floor.+- **E. CPU rasterizer for the canvas.** A tiled, multithreaded CPU rasterizer (binning by 64x64 tiles, SIMD edge+ functions, one thread per tile) that writes the same G-buffer, so a GL 3.3 iGPU only composites one textured+ quad. Also the path for sub-pixel clusters (§0 item 3). Compare CPU vs GPU fill per machine on the floor profile;+ calibration measures both and the hardware profile picks one (`TierConfig`, a new `canvasRaster` field).++**Targets (floor profile, 20M):** stroke latency < 16 ms, p99 frame < 33 ms; idle frames ~0 ms of GPU (composite+only). Measured as in §0 (5/20/50M, laptop and floor).++**Order of experiments**, each behind a flag, off by default, with numbers before it ships: (1) A + B on the GPU+(the canvas, dirty rectangles, Lit Sphere re-shade); (2) C reprojection of the canvas; (3) E the CPU rasterizer+writing the same canvas, and the per-machine pick; (4) D with Focus Detail's per-tile levels. Risks: the canvas+must match a full redraw (a screenshot test compares them pixel for pixel at rest); transparency, X-Ray and+wireframe overlays draw on top of the canvas, not into it.+## References1. NVIDIA Research, *Micro-Mesh Construction* project page and micro-mesh format: https://research.nvidia.com/publication/2023-08_micro-mesh-constructiondiff --git a/src/app/App.cpp b/src/app/App.cppindex cb485f16..78944a10 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -666,7 +666,7 @@ int App::run() {double phase[10] = {};int phases = 0;const auto mark = [&] {- if (frameLogMs >= 0.0 && phases < 10) phase[phases++] = double(SDL_GetTicksNS()) * 1e-6;+ if ((frameLogMs >= 0.0 || proof_) && phases < 10) phase[phases++] = double(SDL_GetTicksNS()) * 1e-6;};auto seconds = [] { return double(SDL_GetTicksNS()) * 1e-9; };// --measure-idle: let start-up settle (first frames, the LightBox's thumbnails), then count.@@ -1014,7 +1014,9 @@ int App::run() {if (proof_) proofBeforeSwap(fbW, fbH); // Help > Benchmark: timing, video capture, the scripted pointerSDL_GL_SwapWindow(window_);mark();- if (phases == 7 && phase[6] - phase[0] > frameLogMs)+ if (phases == 7) // (Help > Benchmark splits each phase's frames by these)+ for (int k = 0; k < 6; ++k) frameSplitMs_[k] = phase[k + 1] - phase[k];+ if (phases == 7 && frameLogMs >= 0.0 && phase[6] - phase[0] > frameLogMs)SDL_Log("frame %.1f ms: events %.1f, dabs %.1f, UI %.1f, ghost + sync %.1f, draw %.1f, UI draw + swap %.1f",phase[6] - phase[0], phase[1] - phase[0], phase[2] - phase[1], phase[3] - phase[2], phase[4] - phase[3],phase[5] - phase[4], phase[6] - phase[5]);diff --git a/src/app/App.h b/src/app/App.hindex 13e4f4b4..f33d560d 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -2068,6 +2068,9 @@ private:// stroke through the input handlers on 5M..100M+ meshes with a live HUD, an MP4 and a JSON result.std::shared_ptr<struct TimelineUiState> timelineUi_;std::shared_ptr<struct ProofState> proof_;+ // The last drawn frame's time by part (run()'s marks): events, dabs, UI, ghost + scene sync (the upload), draw,+ // UI draw + swap (where the frame waits for the GPU).+ double frameSplitMs_[6] = {};void drawTimelineUi(); // once a frame from drawUi: keeps the timeline attached and draws the stripfloat timelineTopInset_ = 0.0f; // how far down the canvas the strip (or its tab) reaches at the top; 0 at the bottomfloat timelineStripY_ = -1.0f; // the strip's (or tab's) top edge in window pixels this frame (-1: not shown)diff --git a/src/app/Calibration.cpp b/src/app/Calibration.cppindex 05ddd8c5..07bc42ea 100644--- a/src/app/Calibration.cpp+++ b/src/app/Calibration.cpp@@ -570,6 +570,10 @@ HardwareProfile Calibrator::profile(const ProfileOverrides& overrides, const Pro}void applyCachedThreadCount() {+ if (simulatedFloorTier()) { // (4 cores; the renderer leaves out GL 4.4 buffer storage: Renderer::persistentUpload)+ ThreadPool::setSharedThreadCount(4);+ return;+ }HardwareProfile cached;if (loadHardwareProfile(hardwareProfilePath(), cached) && cached.settings.threads > 0)ThreadPool::setSharedThreadCount(cached.settings.threads);diff --git a/src/app/PanelPerformanceProfile.cpp b/src/app/PanelPerformanceProfile.cppindex 386405ea..7d564894 100644--- a/src/app/PanelPerformanceProfile.cpp+++ b/src/app/PanelPerformanceProfile.cpp@@ -164,12 +164,26 @@ void App::applyHardwareProfile(const HardwareProfile& p, bool announce) {PerformanceSettings s = p.settings;s.targetFps = hw.tier.targetHz;s.uploadBudgetMBPerFrame = hw.tier.uploadBudgetMBPerFrame;+ const bool floor = simulatedFloorTier();+ if (floor) { // SF_HW_SIMULATE=floor: an integrated GPU's budgets (docs/design/perf-moonshots.md §0)+ s.renderTriangleBudget = std::min<uint64_t>(s.renderTriangleBudget, 2'000'000);+ s.motionProxyThreshold = std::min<uint64_t>(s.motionProxyThreshold, 3'000'000);+ s.vramBudgetMB = std::min<uint64_t>(s.vramBudgetMB, 1536);+ s.uploadBudgetMBPerFrame = std::min<uint64_t>(s.uploadBudgetMBPerFrame, 16);+ s.threads = 4;+ hw.tier.uploadBudgetMBPerFrame = s.uploadBudgetMBPerFrame;+ hw.tier.residentCacheCapMB = std::min<uint64_t>(hw.tier.residentCacheCapMB, 1024);+ hw.tier.zeroCopyUMA = false;+ setCurrentTierConfig(hw.tier);+ SDL_Log("Hardware profile: simulating the floor tier (SF_HW_SIMULATE=floor): budget 2M triangles, 4 threads");+ }hw.profile.settings.targetFps = s.targetFps;setCurrentPerformanceSettings(s);GovernorConfig cfg;cfg.targetFps = s.targetFps;cfg.minBudget = std::max<uint64_t>(250'000, s.renderTriangleBudget / 8);cfg.maxBudget = std::min<uint64_t>(2'000'000'000, std::max<uint64_t>(s.renderTriangleBudget * 4, cfg.minBudget));+ if (floor) cfg.maxBudget = s.renderTriangleBudget; // (the governor may lower the budget, never raise it)hw.governor.reset(cfg, s.renderTriangleBudget);hw.revision = performanceSettingsRevision();if (!announce) return;diff --git a/src/app/ProofMode.cpp b/src/app/ProofMode.cppindex 62ca9143..1be2915e 100644--- a/src/app/ProofMode.cpp+++ b/src/app/ProofMode.cpp@@ -367,6 +367,7 @@ struct PhaseResult {size_t dabs = 0, samples = 0;std::vector<double> frameMs, lagMs, lagPx;std::vector<double> previewLagPx; // the predictive preview's head behind the pointer (the surface's without it)+ std::vector<double> split[6]; // each frame by part (App::frameSplitMs_, the frame before: the swap comes after)};struct SizeResult {@@ -856,7 +857,10 @@ void App::proofBeforeSwap(int fbW, int fbH) {nextPhase();break;}- if (ph.frameMs.size() < 1000000 && now - p.stageStart > 0.0) ph.frameMs.push_back(frameMs);+ if (ph.frameMs.size() < 1000000 && now - p.stageStart > 0.0) {+ ph.frameMs.push_back(frameMs);+ for (int k = 0; k < 6; ++k) ph.split[k].push_back(frameSplitMs_[k]);+ }const double u = std::min(1.0, (now - p.stageStart) / spec.seconds);if (spec.radiusPx <= 0) { // orbit: the view turns, as a drag wouldcamera_.yaw = float(6.2831853 * u);@@ -1003,6 +1007,12 @@ void App::proofBeforeSwap(int fbW, int fbH) {j.set("frames", double(ph.frameMs.size()));j.set("fps", ph.seconds > 0 ? std::round(double(ph.frameMs.size()) / ph.seconds * 10) / 10 : 0.0);j.set("frame_ms", percentilesJson(percentiles(ph.frameMs)));+ { // where the frames went (main thread; the solver thread's dabs run beside them, waits are in "sculpt")+ Json split = Json::object();+ const char* names[6] = {"events", "sculpt", "ui", "upload", "draw", "swap_wait"};+ for (int k = 0; k < 6; ++k) split.set(names[k], percentilesJson(percentiles(ph.split[k])));+ j.set("frame_split_ms", split);+ }if (ph.radiusPx > 0) {if (!ph.lagMs.empty()) { // (Move drags the surface without dabs: no stroke to trail the pointer)j.set("lag_ms", percentilesJson(percentiles(ph.lagMs)));diff --git a/src/core/HardwareProfile.cpp b/src/core/HardwareProfile.cppindex 550237d1..1ba0ea40 100644--- a/src/core/HardwareProfile.cpp+++ b/src/core/HardwareProfile.cpp@@ -118,6 +118,14 @@ const char* tierName(ProfileTier tier) {return "Laptop";}+bool simulatedFloorTier() {+ static const bool on = [] {+ const char* v = std::getenv("SF_HW_SIMULATE");+ return v && std::string(v) == "floor";+ }();+ return on;+}+bool tierFromName(const std::string& name, ProfileTier& out) {const std::string n = lower(name);for (ProfileTier t : {ProfileTier::Software, ProfileTier::Laptop, ProfileTier::Workstation})diff --git a/src/core/HardwareProfile.h b/src/core/HardwareProfile.hindex 828c9e51..f9292cfc 100644--- a/src/core/HardwareProfile.h+++ b/src/core/HardwareProfile.h@@ -41,6 +41,9 @@ enum class ProfileTier { Software, Laptop, Workstation };const char* tierName(ProfileTier tier); // "Software", "Laptop", "Workstation"// Also accepts "llvmpipe" / "safe" (Software), "budget" (Laptop) and "monster" (Workstation), in any case.bool tierFromName(const std::string& name, ProfileTier& out);+// SF_HW_SIMULATE=floor: run with the floor tier's budgets (docs/design/perf-moonshots.md §0: an integrated GPU,+// GL 3.3, 4 cores) on a faster machine, to measure what such a computer gets. Budgets only, not the GPU's speed.+bool simulatedFloorTier();// What the computer is. GPU fields stay empty / 0 where no OpenGL context was probed (sculptforge-cli).struct HardwareInfo {diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cppindex 96a5c1a8..4f8df250 100644--- a/src/render/Renderer.cpp+++ b/src/render/Renderer.cpp@@ -3492,7 +3492,11 @@ bool Renderer::persistentUpload() const {const char* v = std::getenv("SF_PERSISTENT_UPLOAD");return v && *v ? (*v == '0' ? 0 : 1) : -1;}();- return (env >= 0 ? env == 1 : persistentUpload_) && gl::BufferStorage != nullptr;+ static const bool floor = [] { // SF_HW_SIMULATE=floor (core/HardwareProfile.h): GL 3.3, no buffer storage+ const char* v = std::getenv("SF_HW_SIMULATE");+ return v && std::string(v) == "floor";+ }();+ return (env >= 0 ? env == 1 : persistentUpload_) && gl::BufferStorage != nullptr && !floor;}void Renderer::bindStrokeUpload(uint32_t id, StrokeUpload& up) {