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
Micro levels: a stroke's shading per frame held to 10 ms (TierConfig::strokeShadeMs) at the renderer's measured cost per point
islandmeda8adedddd168
diff --git a/src/app/Bench.cpp b/src/app/Bench.cppindex ddce54b8..3563ceb4 100644--- a/src/app/Bench.cpp+++ b/src/app/Bench.cpp@@ -10,6 +10,7 @@#include "render/Renderer.h"#include "core/Image.h"+#include "core/TierConfig.h"#include <SDL3/SDL.h>@@ -62,6 +63,13 @@ int runAppBenchmark(BenchCommandLine cl) {} else if (!renderer.init(error)) {std::fprintf(stderr, "%s\n", error.c_str());} else {+ // SF_BENCH_STROKE_SHADE_MS=N: a micro stroke's shading per frame held to N ms (TierConfig::strokeShadeMs; 0 = the+ // points budget only, as before 11-04).+ if (const char* e = std::getenv("SF_BENCH_STROKE_SHADE_MS")) {+ TierConfig t = currentTierConfig();+ t.strokeShadeMs = std::atof(e);+ setCurrentTierConfig(t);+ }BenchGpu gpu;gpu.description = std::string(reinterpret_cast<const char*>(gl::GetString(GL_RENDERER))) + ", OpenGL " +reinterpret_cast<const char*>(gl::GetString(GL_VERSION));diff --git a/src/core/TierConfig.cpp b/src/core/TierConfig.cppindex d3398eb2..24f92f4b 100644--- a/src/core/TierConfig.cpp+++ b/src/core/TierConfig.cpp@@ -17,6 +17,12 @@ const char* powerSourceName(PowerSource power) {return "unknown";}+size_t strokeShadeBudget(size_t points, double ms, double nsPerPoint, size_t minPoints) {+ if (!(ms > 0.0) || !(nsPerPoint > 0.0)) return points;+ const size_t timed = std::max(size_t(ms * 1e6 / nsPerPoint), minPoints);+ return points ? std::min(points, timed) : timed;+}+int targetHzForDisplay(int hz) {if (hz >= 143) return 144;if (hz >= 119) return 120;@@ -71,6 +77,7 @@ Json tierConfigJson(const TierConfig& c) {j.set("resident_cache_cap_mb", double(c.residentCacheCapMB));j.set("active_triangle_budget", double(c.activeTriangleBudget));j.set("shade_budget_points", double(c.shadeBudgetPoints));+ j.set("stroke_shade_ms", c.strokeShadeMs);j.set("out_of_core_points", double(c.outOfCorePoints));j.set("upload_budget_mb_per_frame", double(c.uploadBudgetMBPerFrame));j.set("draft_brush_mode", c.draftBrushMode);diff --git a/src/core/TierConfig.h b/src/core/TierConfig.hindex a26b92b0..b302d5a0 100644--- a/src/core/TierConfig.h+++ b/src/core/TierConfig.h@@ -42,10 +42,17 @@ struct TierConfig {// frame at most (a quarter of it while a stroke runs in draft mode; the rest follows), and the size in grid// points above which a level is kept out of core (MicroStore; 0 = when it would take a quarter of RAM).uint64_t shadeBudgetPoints = 3u << 20;+ // ... and while a stroke runs, at most this long a frame (ms; the points from the measured cost per point, so a+ // slower CPU shades fewer and the dabs keep up; 0 = the points budget only).+ double strokeShadeMs = 10.0;uint64_t outOfCorePoints = 0;bool onBattery() const { return power == PowerSource::Battery; }};+// The shading budget (grid points) for a frame while a micro stroke runs: `points` (0 = no limit), and no more than+// `ms` at `nsPerPoint` (the renderer's measured cost; 0 = not known yet: `points`), at least `minPoints`.+size_t strokeShadeBudget(size_t points, double ms, double nsPerPoint, size_t minPoints);+// 144 for displays of 143 Hz and up, 120 from 119 Hz, else 60 (also when unknown: 0).int targetHzForDisplay(int displayHz);// The knobs for `profile` on this power source and display (displayHz 0 = unknown). Deterministic.diff --git a/src/render/MicroRenderer.cpp b/src/render/MicroRenderer.cppindex b1e8eda7..c2f0a077 100644--- a/src/render/MicroRenderer.cpp+++ b/src/render/MicroRenderer.cpp@@ -8,6 +8,7 @@#include <glm/gtc/type_ptr.hpp>#include <algorithm>+#include <chrono>#include <bit>#include <cmath>#include <cstring>@@ -426,6 +427,7 @@ void MicroRenderer::shadePending(const Mesh& mesh, bool all) {seeds.erase(std::unique(seeds.begin(), seeds.end()), seeds.end());if (seeds.size() > limit) seeds.resize(limit);if (seeds.empty()) return;+ const auto started = std::chrono::steady_clock::now();std::vector<uint32_t> sorted;if (stageIndex_.size() != mm.baseTriangles) stageIndex_.assign(mm.baseTriangles, 0);shader_.shade(mesh, seeds, false, written_, [&](uint32_t t) -> uint32_t* {@@ -447,6 +449,11 @@ void MicroRenderer::shadePending(const Mesh& mesh, bool all) {i = j;}gl::BindBuffer(GL_TEXTURE_BUFFER, 0);+ if (!written_.empty()) { // the cost per point, smoothed (a stroke's shading budget in time follows it)+ const double ns = std::chrono::duration<double, std::nano>(std::chrono::steady_clock::now() - started).count() /+ double(written_.size() * S);+ shadeNsPerPoint_ = shadeNsPerPoint_ > 0.0 ? shadeNsPerPoint_ * 0.7 + ns * 0.3 : ns;+ }for (uint32_t t : written_) {uint64_t& w = pending_[t >> 6];const uint64_t bit = uint64_t(1) << (t & 63);@@ -540,6 +547,9 @@ bool MicroRenderer::sync(Mesh& mesh) {// stroke runs (the rest follows when it ends).const TierConfig tier = currentTierConfig();shadeBudget = size_t(tier.shadeBudgetPoints) / (mm.stroking && tier.draftBrushMode ? 4 : 1);+ // While a stroke runs, also no more than strokeShadeMs of it (at least one patch and its ring), so a+ // slower CPU doesn't spend the frame the dabs need on shading; the rest follows as before.+ if (mm.stroking) shadeBudget = strokeShadeBudget(shadeBudget, tier.strokeShadeMs, shadeNsPerPoint_, size_t(mm.samples) * 3);if (pendingCount_) shadePending(mesh, false);}}diff --git a/src/render/MicroRenderer.h b/src/render/MicroRenderer.hindex a01cc4c1..771c22cc 100644--- a/src/render/MicroRenderer.h+++ b/src/render/MicroRenderer.h@@ -88,6 +88,7 @@ private:size_t bytes_ = 0;MicroShader shader_;std::vector<uint64_t> pending_; // per base triangle: shading out of date+ double shadeNsPerPoint_ = 0.0; // what shading a grid point (and sending it) took lately (TierConfig::strokeShadeMs)size_t pendingCount_ = 0;std::vector<uint32_t> scratch_, written_, stageIndex_;std::vector<uint8_t> staging_;diff --git a/tests/test_hardware_profile.cpp b/tests/test_hardware_profile.cppindex acbc7afb..861170d8 100644--- a/tests/test_hardware_profile.cpp+++ b/tests/test_hardware_profile.cpp@@ -678,6 +678,17 @@ TEST(governor_target_120) {CHECK(std::abs(g60.targetMs() - 1000.0 / 120.0) < 1e-9);}+TEST(hw_stroke_shade_budget) {+ // A micro stroke's shading per frame: the points budget, held to TierConfig::strokeShadeMs at the measured cost.+ CHECK(TierConfig().strokeShadeMs == 10.0);+ CHECK(strokeShadeBudget(1u << 20, 10.0, 0.0, 300) == (1u << 20)); // cost not measured yet: the points+ CHECK(strokeShadeBudget(1u << 20, 0.0, 20.0, 300) == (1u << 20)); // off+ CHECK(strokeShadeBudget(1u << 20, 10.0, 20.0, 300) == 500000); // 10 ms at 20 ns a point+ CHECK(strokeShadeBudget(1u << 20, 10.0, 2.0, 300) == (1u << 20)); // fast enough: the points still cap it+ CHECK(strokeShadeBudget(0, 10.0, 20.0, 300) == 500000); // no points limit+ CHECK(strokeShadeBudget(1u << 20, 10.0, 1e9, 300) == 300); // at least one patch and its ring+}+TEST(hw_tier_config) {// Laptop / Budget: 2M active triangles, continuous brushes on mains, a quarter of the RAM for caches.const HardwareProfile laptop = mapProfile(machine("Intel", "Mesa Intel(R) Xe Graphics (TGL GT2)", 0, 16384, 8), measured(400.0, 4.0));