Skip to content

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.

Micro levels: shading catch-up while the view moves gets the stroke's time cap (strokeShadeMs), still frames the full points

islandmed7acabc05d03e
diff --git a/src/core/TierConfig.cpp b/src/core/TierConfig.cpp
index 24f92f4b..9ed98df1 100644
--- a/src/core/TierConfig.cpp
+++ b/src/core/TierConfig.cpp
@@ -23,6 +23,11 @@ size_t strokeShadeBudget(size_t points, double ms, double nsPerPoint, size_t min
return points ? std::min(points, timed) : timed;
}
+size_t microShadeBudget(const TierConfig& tier, bool stroking, bool viewMoving, double nsPerPoint, size_t minPoints) {
+ const size_t points = size_t(tier.shadeBudgetPoints) / (stroking && tier.draftBrushMode ? 4 : 1);
+ return stroking || viewMoving ? strokeShadeBudget(points, tier.strokeShadeMs, nsPerPoint, minPoints) : points;
+}
+
int targetHzForDisplay(int hz) {
if (hz >= 143) return 144;
if (hz >= 119) return 120;
diff --git a/src/core/TierConfig.h b/src/core/TierConfig.h
index b302d5a0..11f2c7c0 100644
--- a/src/core/TierConfig.h
+++ b/src/core/TierConfig.h
@@ -42,8 +42,8 @@ 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).
+ // ... and while a stroke runs or the view moves, at most this long a frame (ms; the points from the measured cost
+ // per point, so a slower CPU shades fewer and the dabs and the orbit keep up; 0 = the points budget only).
double strokeShadeMs = 10.0;
uint64_t outOfCorePoints = 0;
bool onBattery() const { return power == PowerSource::Battery; }
@@ -52,6 +52,10 @@ struct TierConfig {
// 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);
+// A micro level's shading budget for one frame: the tier's points (a quarter while a draft stroke runs); while a
+// stroke runs or the view moves, also no more than strokeShadeMs of it (the catch-up after big strokes ran ~30 ms a
+// frame through the orbit on the floor tier); still frames get all of the points, as nothing waits for them.
+size_t microShadeBudget(const TierConfig& tier, bool stroking, bool viewMoving, 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);
diff --git a/src/render/MicroRenderer.cpp b/src/render/MicroRenderer.cpp
index 4c3af026..c4cc67c0 100644
--- a/src/render/MicroRenderer.cpp
+++ b/src/render/MicroRenderer.cpp
@@ -640,13 +640,10 @@ bool MicroRenderer::sync(Mesh& mesh) {
const uint64_t bit = uint64_t(1) << (t & 63);
if (!(w & bit)) w |= bit, ++pendingCount_;
}
- // TierConfig: continuous normals shade up to the budget every sync; draft ones a quarter of it while a
- // 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);
+ // TierConfig (microShadeBudget): the budget every sync, a quarter of it while a draft stroke runs; while a
+ // stroke runs or the view moves, no more than strokeShadeMs of it (at least one patch and its ring), so a
+ // slower CPU doesn't spend the frame the dabs or the orbit need on shading; the rest follows.
+ shadeBudget = microShadeBudget(currentTierConfig(), mm.stroking, viewMoving, shadeNsPerPoint_, size_t(mm.samples) * 3);
if (pendingCount_) shadePending(mesh, false);
}
}
diff --git a/src/render/MicroRenderer.h b/src/render/MicroRenderer.h
index 45f2e79b..ea257813 100644
--- a/src/render/MicroRenderer.h
+++ b/src/render/MicroRenderer.h
@@ -47,6 +47,8 @@ public:
size_t pendingShading() const { return pendingCount_; }
// Grid points of shading recomputed per sync at most (0 = no limit).
size_t shadeBudget = size_t(3) << 20;
+ // The view moves (set by the Renderer before sync: Fast Navigation's proxy frames): shading gets a time cap.
+ bool viewMoving = false;
// The last draw: the level used by each visible cluster (-1 = culled), and the target it settled on.
float lastTargetPx = 0.0f;
diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp
index 97d0b045..af061209 100644
--- a/src/render/Renderer.cpp
+++ b/src/render/Renderer.cpp
@@ -2139,6 +2139,7 @@ void Renderer::drawPatches(const MeshSlot& s, GLenum mode, DrawPart part, GLint
void Renderer::sync(MeshSlot& s, Mesh& mesh, const NormalMapView* normalMap, bool wireframe, bool pbr) {
if (mesh.micro && microMatches(mesh)) { // a micro level draws its own way (render/MicroRenderer.h)
if (!s.micro) s.micro = std::make_shared<MicroRenderer>();
+ s.micro->viewMoving = proxyUsed_; // (the last draw's: the view moving)
s.outOfMemory = !s.micro->sync(mesh);
s.drawnTriangles = s.outOfMemory ? 0 : 1; // (draw() skips empty slots)
s.fresh = true; // (back to a mesh: a full upload)
diff --git a/tests/test_hardware_profile.cpp b/tests/test_hardware_profile.cpp
index 861170d8..cbf91096 100644
--- a/tests/test_hardware_profile.cpp
+++ b/tests/test_hardware_profile.cpp
@@ -689,6 +689,19 @@ TEST(hw_stroke_shade_budget) {
CHECK(strokeShadeBudget(1u << 20, 10.0, 1e9, 300) == 300); // at least one patch and its ring
}
+TEST(hw_micro_shade_budget) {
+ // A micro level's shading per frame: still frames all of the points; strokes and a moving view 10 ms of them.
+ TierConfig t;
+ t.shadeBudgetPoints = 1u << 20;
+ CHECK(microShadeBudget(t, false, false, 30.0, 300) == (1u << 20)); // still: the points (nothing waits)
+ CHECK(microShadeBudget(t, false, true, 30.0, 300) == 333333); // orbit: 10 ms at 30 ns a point
+ CHECK(microShadeBudget(t, true, false, 30.0, 300) == 333333); // stroke: the same
+ CHECK(microShadeBudget(t, false, true, 0.0, 300) == (1u << 20)); // cost not measured yet: the points
+ t.draftBrushMode = true;
+ CHECK(microShadeBudget(t, true, false, 2.0, 300) == (1u << 18)); // draft stroke: a quarter, fast enough
+ CHECK(microShadeBudget(t, false, true, 2.0, 300) == (1u << 20)); // a moving view isn't a draft stroke
+}
+
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));