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
Fast Big Brushes: fused batches sized to about 50 ms of work (measured per batch), not 64 dabs
islandmed9a72fc4e56ae
diff --git a/src/app/App.cpp b/src/app/App.cppindex fc031144..83aa67f7 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -1947,6 +1947,7 @@ void App::beginStroke(float x, float y, const RayHit& hit) {haveLastDab_ = false;doc_.sculptor.draftStrokes = draftStrokes() && asyncStrokeAllowed(); // (AsyncStroke.cpp)doc_.sculptor.adaptiveDabs = fastBigBrushes();+ fusedDabs_ = 64.0;if (!doc_.sculptor.beginStroke(doc_.mesh,!strokeSculpt_ ? std::string("Paint") : recipe ? recipe->name : brushLabel(strokeBrush_),strokeSculpt_ ? doc_.activeLayer : -1)) {diff --git a/src/app/App.h b/src/app/App.hindex 01277bcc..96005d35 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -299,6 +299,7 @@ private:// frame in the interactive loop, so a stroke on a huge mesh keeps its curve (core/StrokePath.h).StrokePath strokePath_;DabQueue dabQueue_;+ double fusedDabs_ = 64.0; // how many dabs a fused batch takes (AsyncStroke.cpp: sized to kFusedBatchSeconds)double lastDabsQueued_ = 0.0; // when pumpStroke last handed the solver dabs (catch-up waits for a pause)std::vector<PathDab> strokeScratch_;std::vector<glm::vec2>* strokeProbe_ = nullptr; // --measure-stroke: where each dab went (screen)diff --git a/src/app/AsyncStroke.cpp b/src/app/AsyncStroke.cppindex f4ae2df5..9b1de57d 100644--- a/src/app/AsyncStroke.cpp+++ b/src/app/AsyncStroke.cpp@@ -27,6 +27,9 @@ namespace {constexpr double kBatchSeconds = 0.033; // a batch's dabs: about this much work (the surface updates this often)// Background dabs (no preview to cover a batch): batches of about a frame's share of work, as the frame loop places.constexpr double kBackgroundBatchSeconds = 0.010;+// A fused batch (Fast Big Brushes) takes as many dabs as about this much work: a batch shows only when it is done,+// so on slow cores a long batch is lag, while on fast ones the dabs share the vertex walk, refit and upload.+constexpr double kFusedBatchSeconds = 0.05;// Meshes from this many vertices place a stroke's dabs on the solver thread even without predictive strokes: one// 240 px dab there moves millions of vertices (100-300 ms at 33M triangles), more than a frame can hold.constexpr size_t kBackgroundDabVertices = 2'000'000;@@ -246,6 +249,13 @@ void App::commitSolverBatch() {if (!s.batch.empty()) {lastDabScreen_ = glm::vec2(s.batch.back().x, s.batch.back().y);if (s.dabSeconds > 0.0) dabSeconds_ = dabSeconds_ > 0.0 ? dabSeconds_ * 0.8 + s.dabSeconds * 0.2 : s.dabSeconds;+ // The fused batch size, toward kFusedBatchSeconds of work: scaled by how far this batch was from it (down at once, up+ // at most 2x a batch, kept fractional so it climbs back from 1 where fusing pays). It settles where a batch costs+ // the budget; on cores where one dab alone costs more, at one dab a batch.+ if (s.dabSeconds > 0.0 && doc_.sculptor.fusesBatches()) {+ const double size = double(s.batch.size()), from = size >= std::floor(fusedDabs_) ? fusedDabs_ : size;+ fusedDabs_ = std::clamp(from * std::clamp(kFusedBatchSeconds / (s.dabSeconds * size), 0.0, 2.0), 1.0, 64.0);+ }}if (doc_.sculptor.lastFrame.valid) {// The surface's curvature along the stroke (signed, 1 / radius; > 0 convex), from how the area normal@@ -335,8 +345,10 @@ void App::pumpStroke() {const double target = std::max(predictiveStrokes() ? kBatchSeconds : std::max(kBackgroundBatchSeconds, frameSeconds_ * 0.8),prepSeconds_);size_t n = dabSeconds_ > 0.0 ? size_t(std::clamp(target / dabSeconds_, 1.0, 64.0)) : 1;- // A big brush's batch goes through the vertices together (Fast Big Brushes): every dab waiting, at once.- if (strokeFinishing_ || doc_.sculptor.fusesBatches()) n = 64;+ // A big brush's batch goes through the vertices together (Fast Big Brushes): about kFusedBatchSeconds of+ // dabs at once (every dab left once the pen has lifted).+ if (doc_.sculptor.fusesBatches()) n = size_t(fusedDabs_);+ if (strokeFinishing_) n = 64;s.batch.clear();while (!dabQueue_.empty() && s.batch.size() < n) s.batch.push_back(dabQueue_.pop());s.finalize = strokeFinishing_ && dabQueue_.empty();