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
Strokes whose solver can't keep up don't overlap the GPU (Lucy 28M stroke frame p99 back under 33 ms)
islandmedfa66499d30f3
diff --git a/src/app/App.cpp b/src/app/App.cppindex c81cc969..1965455e 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -322,8 +322,7 @@ void App::shutdown() {spaceMouseClose();shutdownHardwareProfile(); // its timer queries need the GL context- if (lastFrameFence_) gl::DeleteSync(lastFrameFence_);- lastFrameFence_ = nullptr;+ waitLastFrame();if (refTexture_) gl::DeleteTextures(1, &refTexture_);gallery_.reset(); // its preview textures need the GL contextthumbs_.clear();@@ -1081,6 +1080,9 @@ int App::run() {continuousDabAt_ = nowS;}}+ // A stroke whose solver can't keep up: no overlap. The GPU drawing the last frame slows the solver (they share+ // the memory on Apple silicon: Lucy 28M stroke frame p99 31 -> 37 ms); light strokes keep overlapping.+ if (solverBound_ && (drag_ == Drag::Stroke || solverBusy())) waitLastFrame();flushGrab(); // Move: the pointer's moves since the last frame, as oneif (asyncStroke_) pumpStroke();else drainStrokeDabs(kStrokeBudgetSeconds);@@ -1195,10 +1197,7 @@ int App::run() {if (proof_) proofBeforeSwap(fbW, fbH); // Help > Benchmark: timing, video capture, the scripted pointer// CPU and GPU overlap: the GPU draws this frame while the CPU builds the next. At most one frame in flight// (the input lag doesn't grow): the last frame's GPU work is done before this one is shown.- if (lastFrameFence_) {- gl::ClientWaitSync(lastFrameFence_, GL_SYNC_FLUSH_COMMANDS_BIT, 100'000'000ull); // (100 ms: never stuck)- gl::DeleteSync(lastFrameFence_);- }+ waitLastFrame();SDL_GL_SwapWindow(window_);lastFrameFence_ = gl::FenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);gl::Flush(); // (to the GPU now: an offscreen swap sends nothing)@@ -4189,5 +4188,12 @@ void App::drawBrushCursor() {if (!sizeRingPreview_) drawPrecisionCursor(dl, c, r, col); // Steady Stroke's string, the precision drag, the size in mm (Precision.cpp; the pop-up shows the size itself)}+void App::waitLastFrame() {+ if (!lastFrameFence_) return;+ gl::ClientWaitSync(lastFrameFence_, GL_SYNC_FLUSH_COMMANDS_BIT, 100'000'000ull); // (100 ms: never stuck)+ gl::DeleteSync(lastFrameFence_);+ lastFrameFence_ = nullptr;+}+} // namespace sfdiff --git a/src/app/App.h b/src/app/App.hindex 25c0b4f9..f4b61d0f 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -2375,6 +2375,11 @@ private:// UI draw + swap (where the frame waits for the GPU).double frameSplitMs_[6] = {};GLsync lastFrameFence_ = nullptr; // the last shown frame's GPU work is done+ void waitLastFrame(); // (the last shown frame's GPU work done: nothing of it in flight)+ // The stroke solver is the bottleneck (a recent share of background batches not done within their wait): frames+ // don't overlap the GPU then.+ double solverLateShare_ = 0.0;+ bool solverBound_ = false;// GPU time of frames (GL_TIME_ELAPSED, a few frames late) since Help > Benchmark last took them.std::vector<double> proofGpuMs_;// The view's resolution while it moves (experimental, docs/design/perf-moonshots.md §0): 0.75 on the simulateddiff --git a/src/app/AsyncStroke.cpp b/src/app/AsyncStroke.cppindex 14112218..3f2da961 100644--- a/src/app/AsyncStroke.cpp+++ b/src/app/AsyncStroke.cpp@@ -368,8 +368,16 @@ void App::pumpStroke() {s.start();// Background dabs: a batch is waited for here up to a frame's share of work, so a light one shows in this frame// as in the frame loop's own path; a heavier one goes on while the frame draws, and the next frame commits it.- if (!previewStrokes() && dabSeconds_ > 0.0 && s.waitFor(kBackgroundBatchSeconds * 1.25) && s.done)- commitSolverBatch();+ // (How often the batch isn't done in time: a stroke whose solver is the bottleneck. The frame loop then stops+ // overlapping the GPU with it: see App::run.)+ if (!previewStrokes() && dabSeconds_ > 0.0) {+ const bool inTime = s.waitFor(kBackgroundBatchSeconds * 1.25);+ solverLateShare_ += 0.1 * ((inTime ? 0.0 : 1.0) - solverLateShare_);+ // (On above a fifth late, off below one in twenty: Lucy 28M's ~35% stays on between its late runs.)+ if (solverLateShare_ > 0.2) solverBound_ = true;+ else if (solverLateShare_ < 0.05) solverBound_ = false;+ if (inTime && s.done) commitSolverBatch();+ }}bool App::liveMoveEnabled() const {