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.

Predictive strokes: every dab setting snapshotted per batch for the solver thread; debug knobs removed

islandmedca9b8775c65c
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 46ef8cf3..fa602e94 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -550,6 +550,12 @@ if(SCULPTFORGE_BUILD_TESTS)
# pointer's circle (#19).
add_test(NAME ui_stroke_path COMMAND sculptforge --run "new_sphere" --measure-stroke 1.5)
set_tests_properties(ui_stroke_path PROPERTIES LABELS ui TIMEOUT 60 ENVIRONMENT "SF_NO_UPDATE_CHECK=1")
+ # Predictive strokes with the brush size changing every frame mid-stroke: each batch of dabs keeps the size it
+ # was handed (no data race with the solver thread), replaying the stroke without the thread gives the same
+ # mesh, bit for bit, and its undo the mesh it started from.
+ add_test(NAME ui_stroke_resize COMMAND sculptforge --run "new_sphere" --measure-stroke 1.5)
+ set_tests_properties(ui_stroke_resize PROPERTIES LABELS ui TIMEOUT 60
+ ENVIRONMENT "SF_NO_UPDATE_CHECK=1;SF_MEASURE_RESIZE=1;SF_MEASURE_VERIFY=1;SF_PREDICTIVE_STROKE=1")
# The guide's keyboard table must match the app's default shortcuts (tools/guide/update_shortcuts.py).
if(Python3_Interpreter_FOUND)
sculptforge_runner(SCULPTFORGE_APP_RUNNER sculptforge)
diff --git a/docs/performance.md b/docs/performance.md
index d6a2870f..32bca515 100644
--- a/docs/performance.md
+++ b/docs/performance.md
@@ -64,7 +64,7 @@ with only the measurement additions, "B" this branch with Predictive Strokes on
| 33.6M, 240 px | A | 292 / 636 / 636 ms | 226 px | 226 px | 779 ms | 826 ms | 1362 ms |
| | B | **12.8 / 27.2 / 31.1 ms** | 337 px | 117 px* | **11 ms** | 0 ms | 1689 ms |
-\* One of the two runs had a preview lag of 230 px, the other 4 px; repeated runs with `SF_GHOST_DEBUG=1` gave
+\* One of the two runs had a preview lag of 230 px, the other 4 px; repeated runs with the head logged gave
4 px and couldn't reproduce it (a tiling window manager resizing the window mid-stroke, which other agents'
windows did during these runs, also moves the canvas under the scripted circle).
@@ -112,7 +112,7 @@ What changed, in order:
plane) for the bent normal and the cavity term, with no extra varyings (a tiled GPU writes every vertex's
outputs to memory). Each dab's surface point comes from a sphere fitted to the last two placed dabs (their
normals turn by an angle over the distance between them): centre within 0.003-0.07 r, normal within 1-5
- degrees (`SF_GHOST_DEBUG=1`). Only the clusters a ghost dab reaches use it. The brush cursor is drawn at the
+ degrees (measured with a debug log since removed). Only the clusters a ghost dab reaches use it. The brush cursor is drawn at the
predicted pen position too.
3. **Two-part upload** (Renderer::prepareStrokeUpload / commitStrokeUpload). The solver thread packs the dirty
vertices and the culling bounds; the GL thread only calls glBufferSubData. The cavity term comes from the
diff --git a/src/app/App.cpp b/src/app/App.cpp
index cb799463..2ad71a7a 100644
--- a/src/app/App.cpp
+++ b/src/app/App.cpp
@@ -676,6 +676,7 @@ int App::run() {
MeasureView view{}; // the view before the stroke (it starts once this has held still for a second)
double viewSince = 0.0;
std::vector<double> frameTimes; // seconds, for the percentiles
+ std::vector<float> radii; // each dab's brush radius (px)
// SF_MEASURE_VERIFY=1: the mesh before the stroke, to check undo and replay the dabs (verifyStroke).
uint64_t before = 0;
// SF_MEASURE_SNAPSHOT=prefix: the canvas at a few points of the stroke, as prefix-N.png.
@@ -763,6 +764,7 @@ int App::run() {
sm.started = true;
sm.start = sm.lastFrame = sm.pressAt = seconds();
strokeProbe_ = &sm.dabs;
+ strokeRadiusProbe_ = &sm.radii;
if (options_.measureStrokeRadius > 0.0f) radiusPx_ = std::clamp(options_.measureStrokeRadius, 2.0f, 800.0f);
if (verify) sm.before = meshStateHash(doc_.mesh);
onMouseDown(sm.cx + sm.r, sm.cy, SDL_BUTTON_LEFT);
@@ -773,6 +775,11 @@ int App::run() {
} else if (sm.moving) {
const double u = std::min(1.0, (seconds() - sm.start) / double(options_.measureStroke));
const double a = u * 4.0 * 3.14159265358979;
+ // SF_MEASURE_RESIZE=1: the brush size changes every frame mid-stroke, as [ and ] would (the solver thread
+ // must see each batch's own size: ui_stroke_resize, with verify).
+ static const bool resize = std::getenv("SF_MEASURE_RESIZE") != nullptr;
+ if (resize) radiusPx_ = std::clamp(options_.measureStrokeRadius > 0.0f ? options_.measureStrokeRadius : 60.0f, 2.0f, 800.0f) *
+ (1.0f + 0.4f * float(std::sin(u * 40.0)));
onMouseMove(sm.cx + sm.r * float(std::cos(a)), sm.cy + sm.r * float(std::sin(a)), 0.0f, 0.0f, false);
++sm.samples;
if (u >= 1.0) {
@@ -787,6 +794,7 @@ int App::run() {
const double releaseDoneMs = (seconds() - sm.releaseAt) * 1000.0;
const double releaseMs = sm.releaseMs;
strokeProbe_ = nullptr;
+ strokeRadiusProbe_ = nullptr;
std::vector<float> off;
for (const glm::vec2& d : sm.dabs) off.push_back(std::abs(std::hypot(d.x - sm.cx, d.y - sm.cy) - sm.r));
std::sort(off.begin(), off.end());
@@ -823,10 +831,11 @@ int App::run() {
if (verify && !(now == sm.view))
std::printf("verify: skipped (the view changed during the stroke: distance %.3f -> %.3f, canvas %.0fx%.0f -> %.0fx%.0f)\n",
double(sm.view.distance), double(now.distance), double(sm.view.w), double(sm.view.h), double(now.w), double(now.h));
- else if (verify && !verifyStroke(sm.before, sm.dabs)) return 1;
+ else if (verify && !verifyStroke(sm.before, sm.dabs, sm.radii)) return 1;
// The test (ui_stroke_path, a light sphere): every dab placed, all of them on the circle.
const float spacing = std::max(1.0f, radiusPx_ * 0.15f);
const double expected = 4.0 * 3.14159265358979 * double(sm.r) / double(spacing);
+ if (std::getenv("SF_MEASURE_RESIZE")) return 0; // (the spacing changed with the size: verify checked it)
return double(sm.dabs.size()) >= 0.9 * expected && !off.empty() && off.back() < spacing ? 0 : 1;
}
}
@@ -1296,8 +1305,11 @@ void App::beginStroke(float x, float y, const RayHit& hit) {
strokePath_.reset(x, y);
dabQueue_.clear();
dabSeconds_ = prepSeconds_ = 0.0; // measured again: the mesh and the brush may have changed
- // Predictive strokes (AsyncStroke.cpp): the solver thread, the ghost's first estimate (the picked triangle).
+ // Predictive strokes (AsyncStroke.cpp): the solver thread, the ghost's first estimate (the picked triangle);
+ // the stroke's own copies of the recipe and the alpha, which the solver thread reads (DabSettings).
asyncStroke_ = asyncStrokeAllowed();
+ strokeRecipe_ = asyncStroke_ && recipe ? std::make_shared<const BrushRecipe>(*recipe) : nullptr;
+ strokeAlpha_ = asyncStroke_ && !doc_.brushAlpha.empty() ? std::make_shared<const BrushAlpha>(doc_.brushAlpha) : nullptr;
pointerLatest_ = glm::vec2(x, y);
pointerLatestAt_ = double(SDL_GetTicksNS()) * 1e-9;
penPredictor_.reset(pointerLatest_, pointerLatestAt_);
@@ -1459,14 +1471,19 @@ void App::drainStrokeDabs(double budgetSeconds) {
}
void App::dabAt(float x, float y, float pressure) {
- // On the solver thread (predictive strokes) the dab sees the view as it was when its batch began.
+ // On the solver thread (predictive strokes) the dab sees the view and the brush settings as they were when its
+ // batch began (DabSettings), and nothing the main thread changes meanwhile.
+ const DabSettings live = dabView_ ? DabSettings() : dabSettings();
+ const DabSettings& st = dabView_ ? dabView_->settings : live;
if (dabView_) {
if (dabView_->probe) dabView_->probe->emplace_back(x, y);
+ if (dabView_->radiusProbe) dabView_->radiusProbe->push_back(st.radiusPx);
} else if (strokeProbe_) {
strokeProbe_->emplace_back(x, y);
+ if (strokeRadiusProbe_) strokeRadiusProbe_->push_back(st.radiusPx);
}
const Camera& cam = dabView_ ? dabView_->camera : camera_;
- const BrushRecipe* recipe = strokeRecipe();
+ const BrushRecipe* recipe = st.recipe;
if (recipe && recipe->jitter > 0.0f) {
// Deterministic per-stroke scatter (xorshift).
auto rnd = [this] {
@@ -1475,13 +1492,13 @@ void App::dabAt(float x, float y, float pressure) {
jitterSeed_ ^= jitterSeed_ << 5;
return float(jitterSeed_ & 0xffff) / 65535.0f * 2.0f - 1.0f;
};
- x += rnd() * recipe->jitter * radiusPx_;
- y += rnd() * recipe->jitter * radiusPx_;
+ x += rnd() * recipe->jitter * st.radiusPx;
+ y += rnd() * recipe->jitter * st.radiusPx;
}
dabRadiusScale_ = dabStrengthScale_ = 1.0f;
dabAngle_ = 0.0f;
- if (strokeType_ == StrokeType::Spray) {
- const SprayDab s = spray_.next(radiusPx_, sprayScatter_);
+ if (st.strokeType == StrokeType::Spray) {
+ const SprayDab s = spray_.next(st.radiusPx, st.sprayScatter);
x += s.offset.x;
y += s.offset.y;
dabRadiusScale_ = s.scale;
@@ -1495,33 +1512,33 @@ void App::dabAt(float x, float y, float pressure) {
DabParams p;
p.center = hit.position;
p.viewDir = cam.forward();
- p.radius = radiusPx_ * (pressureSize_ ? std::max(pressure, 0.05f) : 1.0f) *
+ p.radius = st.radiusPx * (st.pressureSize ? std::max(pressure, 0.05f) : 1.0f) *
cam.worldPerPixel(hit.position, dabView_ ? dabView_->canvas.h : canvasHeight()) * dabRadiusScale_;
// Smooth keeps its own Z Intensity (ZBrush), whether picked or held with Shift.
- p.strength = (strokeBrush_ == BrushType::Smooth ? smoothStrength_ : strength_) * dabStrengthScale_;
- p.pressure = pressureStrength_ ? pressure : 1.0f;
- p.invert = strokeInvert_;
- p.frontFacesOnly = frontFacesOnly_;
- p.focal = focalShift_;
+ p.strength = (st.brush == BrushType::Smooth ? st.smoothStrength : st.strength) * dabStrengthScale_;
+ p.pressure = st.pressureStrength ? pressure : 1.0f;
+ p.invert = st.invert;
+ p.frontFacesOnly = st.frontFacesOnly;
+ p.focal = st.focal;
if (!dabView_) lastDabScreen_ = glm::vec2(x, y); // (the solver's: when its batch is committed)
- if (strokeMask_) {
- p.strength = maskStrength_;
- doc_.sculptor.dabMask(doc_.mesh, doc_.bvh, p, symmetry_);
+ if (st.mask) {
+ p.strength = st.maskStrength;
+ doc_.sculptor.dabMask(doc_.mesh, doc_.bvh, p, st.symmetry);
return;
}
- p.alpha = &doc_.brushAlpha;
+ p.alpha = st.alpha;
p.alphaUp = cam.orientation() * glm::vec3(-std::sin(dabAngle_), std::cos(dabAngle_), 0.0f); // screenUpVector
- p.vdm = doc_.brushVdm.get();
+ p.vdm = st.vdm;
p.strokeDelta = haveLastDab_ ? hit.position - lastDabHit_ : glm::vec3(0.0f);
lastDabHit_ = hit.position;
haveLastDab_ = true;
- if (strokePaint_) paintAt(p);
- if (!strokeSculpt_) return;
+ if (st.paint) paintAt(p); // (never on the solver thread: painting strokes stay in the frame loop)
+ if (!st.sculpt) return;
if (recipe) {
- doc_.sculptor.dabRecipe(doc_.mesh, doc_.bvh, *recipe, p, symmetry_);
+ doc_.sculptor.dabRecipe(doc_.mesh, doc_.bvh, *recipe, p, st.symmetry);
return;
}
- doc_.sculptor.dab(doc_.mesh, doc_.bvh, strokeBrush_, p, symmetry_);
+ doc_.sculptor.dab(doc_.mesh, doc_.bvh, st.brush, p, st.symmetry);
}
void App::endStroke() {
@@ -1741,6 +1758,7 @@ void App::syncScene() {
}
void App::setLayerWeight(int index, float weight) {
+ if (solverBusy()) solverWait(); // (the solver thread is moving this mesh: after its batch)
doc_.mesh.setLayerWeight(index, weight);
doc_.bvhDirty = true;
doc_.modified = true;
diff --git a/src/app/App.h b/src/app/App.h
index e72cf4ad..5f1a19c3 100644
--- a/src/app/App.h
+++ b/src/app/App.h
@@ -218,6 +218,7 @@ private:
DabQueue dabQueue_;
std::vector<PathDab> strokeScratch_;
std::vector<glm::vec2>* strokeProbe_ = nullptr; // --measure-stroke: where each dab went (screen)
+ std::vector<float>* strokeRadiusProbe_ = nullptr; // ... and its brush radius (px)
double dabSeconds_ = 0.0; // what a dab of this stroke costs (running average), for the backlog limit
bool interactiveStrokes_ = false; // App::run(): budgeted dabs and curved long gaps; other loops dab at once
void drainStrokeDabs(double budgetSeconds); // places queued dabs; budget <= 0: all of them
@@ -230,10 +231,33 @@ private:
// The dabs, their order and so the geometry are those of the synchronous path. Preferences > Performance >
// Predictive strokes (SF_PREDICTIVE_STROKE=0 / 1 overrides it).
struct StrokeSolver;
- struct DabView { // what a dab on the solver thread sees of the view (the main thread's may move on)
+ // Everything a dab reads besides the mesh, the BVH and the sculptor (which the solver thread owns while it
+ // runs): taken on the main thread, by value, for each batch (dabSettings), so brush size, strength,
+ // symmetry, the brush, its alpha, recipe and VDM can change mid-stroke without the solver thread seeing a
+ // half-written value (they take effect from the next batch, as they did from the next dab before). The
+ // alpha and the recipe are the stroke's own copies (strokeAlpha_, strokeRecipe_), which nothing changes.
+ struct DabSettings {
+ float radiusPx = 60.0f, strength = 0.5f, smoothStrength = 0.5f, focal = 0.0f, maskStrength = 1.0f;
+ float sprayScatter = 1.0f;
+ bool pressureSize = false, pressureStrength = true, invert = false, frontFacesOnly = false;
+ bool mask = false, paint = false, sculpt = true, visible = true;
+ BrushType brush = BrushType::Standard;
+ StrokeType strokeType = StrokeType::Dots;
+ Symmetry symmetry;
+ const BrushRecipe* recipe = nullptr;
+ const BrushAlpha* alpha = nullptr;
+ const VectorDisplacement* vdm = nullptr;
+ std::shared_ptr<const VectorDisplacement> vdmOwner; // (keeps the VDM alive for the batch)
+ };
+ DabSettings dabSettings() const; // the live values (AsyncStroke.cpp)
+ std::shared_ptr<const BrushAlpha> strokeAlpha_; // this stroke's alpha and recipe (predictive strokes)
+ std::shared_ptr<const BrushRecipe> strokeRecipe_;
+ struct DabView { // what a dab on the solver thread sees (the main thread's may move on)
Camera camera;
CanvasRect canvas;
+ DabSettings settings;
std::vector<glm::vec2>* probe = nullptr; // --measure-stroke: where its dabs went
+ std::vector<float>* radiusProbe = nullptr; // ... and their brush radius in pixels (verify replays it)
};
std::unique_ptr<StrokeSolver> solver_;
const DabView* dabView_ = nullptr; // set while the solver thread places dabs (dabAt reads it)
@@ -269,7 +293,7 @@ private:
uint64_t popCommits_ = 0;
glm::vec2 predictedPointer() const; // where the pen will be when this frame shows (the cursor, the head)
static uint64_t meshStateHash(const Mesh& mesh); // --measure-stroke SF_MEASURE_VERIFY=1
- bool verifyStroke(uint64_t before, const std::vector<glm::vec2>& dabs);
+ bool verifyStroke(uint64_t before, const std::vector<glm::vec2>& dabs, const std::vector<float>& radii);
bool lastInputPen_ = false; // the last mouse event came from a pen (SDL_PEN_MOUSEID)
bool penSeen_ = false;
BrushType strokeBrush_ = BrushType::Standard;
diff --git a/src/app/AsyncStroke.cpp b/src/app/AsyncStroke.cpp
index 1ee71cff..b5646dd0 100644
--- a/src/app/AsyncStroke.cpp
+++ b/src/app/AsyncStroke.cpp
@@ -61,6 +61,7 @@ void App::StrokeSolver::loop() {
pending_ = false;
}
probe.clear();
+ radiusProbe.clear();
double spent = 0.0;
const SculptTimings before = app.doc_.sculptor.timings;
app.dabView_ = &view;
@@ -75,8 +76,6 @@ void App::StrokeSolver::loop() {
spent += std::chrono::duration<double>(std::chrono::steady_clock::now() - t0).count();
}
app.dabView_ = nullptr;
- static const char* slow = std::getenv("SF_SOLVER_DELAY_MS"); // (a slower solver, for testing the preview)
- if (slow && *slow) std::this_thread::sleep_for(std::chrono::milliseconds(std::atoi(slow)));
dabSeconds = batch.empty() ? 0.0 : spent / double(batch.size());
const auto prepStart = std::chrono::steady_clock::now();
uploadReady = prepare && app.renderer_.prepareStrokeUpload(uploadId, app.doc_.mesh, upload, app.doc_.sculptor.strokeCurvature());
@@ -173,25 +172,12 @@ void App::commitSolverBatch() {
syncScene(); // (the regular sync: a new grid, or a mesh the two-part upload doesn't handle)
}
if (strokeProbe_) strokeProbe_->insert(strokeProbe_->end(), s.probe.begin(), s.probe.end());
+ if (strokeRadiusProbe_) strokeRadiusProbe_->insert(strokeRadiusProbe_->end(), s.radiusProbe.begin(), s.radiusProbe.end());
if (s.prepSeconds > 0.0) prepSeconds_ = prepSeconds_ > 0.0 ? prepSeconds_ * 0.7 + s.prepSeconds * 0.3 : s.prepSeconds;
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;
}
- static const bool debug = std::getenv("SF_GHOST_DEBUG") != nullptr;
- if (debug && !s.batch.empty() && doc_.sculptor.lastFrame.valid) {
- // The last dab's estimate (from the frame before it) against where the solver placed it.
- const CanvasRect c = canvasRect();
- glm::vec3 origin, dir, est, n;
- camera_.screenRay(s.batch.back().x - c.x, s.batch.back().y - c.y, c.w, c.h, origin, dir);
- if (!ghostSurface(origin, dir, est, n)) est = n = glm::vec3(0.0f);
- const Sculptor::DabFrame& f = doc_.sculptor.lastFrame;
- const float r = radiusPx_ * camera_.worldPerPixel(f.center, c.h);
- SDL_Log("ghost: centre off by %.3f r, normal off %.1f deg, area depth est %.4f r real %.4f r", glm::distance(est, f.center) / r,
- glm::degrees(std::acos(std::clamp(glm::dot(n, f.normal), -1.0f, 1.0f))),
- glm::dot(ghostFrame_.center - ghostFrame_.areaCenter, ghostFrame_.normal) / r,
- glm::dot(f.center - f.areaCenter, f.normal) / r);
- }
if (doc_.sculptor.lastFrame.valid) {
// The surface's curvature along the stroke (signed, 1 / radius; > 0 convex), from how the area normal
// turned since the last frame, smoothed over the batches; small turns count as flat.
@@ -237,7 +223,11 @@ void App::pumpStroke() {
s.view.camera = camera_;
s.view.canvas = canvasRect();
s.view.probe = nullptr;
+ s.view.radiusProbe = nullptr;
+ s.view.settings = dabSettings();
s.uploadId = doc_.activeSubtoolInfo().id;
+ renderer_.bindStrokeUpload(s.uploadId, s.upload);
+ renderer_.bindStrokeUpload(s.uploadId, s.upload); // (the slot, found here: the thread doesn't walk the renderer's list)
s.prepare = &displayedMesh() == &doc_.mesh;
s.start();
return;
@@ -259,7 +249,10 @@ void App::pumpStroke() {
s.view.camera = camera_;
s.view.canvas = canvasRect();
s.view.probe = strokeProbe_ ? &s.probe : nullptr;
+ s.view.radiusProbe = strokeProbe_ ? &s.radiusProbe : nullptr;
+ s.view.settings = dabSettings();
s.uploadId = doc_.activeSubtoolInfo().id;
+ renderer_.bindStrokeUpload(s.uploadId, s.upload); // (the slot, found here: the thread doesn't walk the renderer's list)
s.prepare = &displayedMesh() == &doc_.mesh; // (a previewed LOD shows instead: nothing to pack)
renderer_.setDraftNormals(doc_.sculptor.draftActive() ? s.uploadId : 0);
s.start();
@@ -297,8 +290,35 @@ void App::finishStrokeNow() {
}
}
+App::DabSettings App::dabSettings() const {
+ DabSettings st;
+ st.radiusPx = radiusPx_;
+ st.strength = strength_;
+ st.smoothStrength = smoothStrength_;
+ st.focal = focalShift_;
+ st.maskStrength = maskStrength_;
+ st.sprayScatter = sprayScatter_;
+ st.pressureSize = pressureSize_;
+ st.pressureStrength = pressureStrength_;
+ st.invert = strokeInvert_;
+ st.frontFacesOnly = frontFacesOnly_;
+ st.mask = strokeMask_;
+ st.paint = strokePaint_;
+ st.sculpt = strokeSculpt_;
+ st.visible = doc_.activeSubtoolInfo().visible;
+ st.brush = strokeBrush_;
+ st.strokeType = strokeType_;
+ st.symmetry = symmetry_;
+ // A predictive stroke works from its own copies of the recipe and alpha (made when it began).
+ st.recipe = asyncStroke_ ? strokeRecipe_.get() : strokeRecipe();
+ st.alpha = asyncStroke_ ? strokeAlpha_.get() : &doc_.brushAlpha; // (null: round)
+ st.vdmOwner = doc_.brushVdm;
+ st.vdm = st.vdmOwner.get();
+ return st;
+}
+
bool App::pickWith(const DabView& view, float x, float y, RayHit& hit) const {
- if (!doc_.activeSubtoolInfo().visible) return false;
+ if (!view.settings.visible) return false;
glm::vec3 origin, dir;
view.camera.screenRay(x - view.canvas.x, y - view.canvas.y, view.canvas.w, view.canvas.h, origin, dir);
return doc_.bvh.raycast(doc_.mesh, origin, dir, hit);
@@ -368,10 +388,6 @@ void App::buildGhost() {
const bool moving = glm::length(penPredictor_.velocity()) > 20.0f; // px / s
if (moving && gap > 0.2f * spacing)
pending.push_back({head.x, head.y, lastStrokePressure_, std::min(1.0f, gap / spacing)});
- static const bool debug = std::getenv("SF_GHOST_DEBUG") != nullptr;
- if (debug && glm::distance(head, glm::vec2(mouseX_, mouseY_)) > 30.0f)
- SDL_Log("ghost: head %.0f %.0f pointer %.0f %.0f latest %.0f %.0f from %.0f %.0f v %.0f", head.x, head.y, mouseX_, mouseY_,
- pointerLatest_.x, pointerLatest_.y, from.x, from.y, glm::length(penPredictor_.velocity()));
}
if (!pending.empty()) {
ghostHead_ = glm::vec2(pending.back().x, pending.back().y);
@@ -431,7 +447,7 @@ uint64_t App::meshStateHash(const Mesh& mesh) {
return h;
}
-bool App::verifyStroke(uint64_t before, const std::vector<glm::vec2>& dabs) {
+bool App::verifyStroke(uint64_t before, const std::vector<glm::vec2>& dabs, const std::vector<float>& radii) {
const uint64_t after = meshStateHash(doc_.mesh);
runCommand("undo", {});
const uint64_t undone = meshStateHash(doc_.mesh);
@@ -445,7 +461,12 @@ bool App::verifyStroke(uint64_t before, const std::vector<glm::vec2>& dabs) {
haveLastDab_ = false;
doc_.sculptor.draftStrokes = draftStrokes(); // (the measured stroke is one the solver thread takes)
doc_.sculptor.beginStroke(doc_.mesh, brushName(strokeBrush_), doc_.activeLayer);
- for (const glm::vec2& d : dabs) dabAt(d.x, d.y, 1.0f);
+ const float radius = radiusPx_;
+ for (size_t i = 0; i < dabs.size(); ++i) {
+ if (i < radii.size()) radiusPx_ = radii[i]; // (the size each dab had: it may change mid-stroke)
+ dabAt(dabs[i].x, dabs[i].y, 1.0f);
+ }
+ radiusPx_ = radius;
doc_.sculptor.flushDraft(doc_.mesh, doc_.bvh);
doc_.undo.push(doc_.sculptor.endStroke());
return meshStateHash(doc_.mesh);
diff --git a/src/app/AsyncStroke.h b/src/app/AsyncStroke.h
index 9d42df94..6a05764f 100644
--- a/src/app/AsyncStroke.h
+++ b/src/app/AsyncStroke.h
@@ -30,6 +30,7 @@ struct App::StrokeSolver {
std::vector<PathDab> batch;
DabView view;
std::vector<glm::vec2> probe; // --measure-stroke: where the batch's dabs went
+ std::vector<float> radiusProbe;
double dabSeconds = 0.0; // the batch's mean cost per dab
double prepSeconds = 0.0; // what packing its upload cost
uint32_t uploadId = 0; // the active SubTool's renderer slot
diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp
index 2adaf9bc..771ce273 100644
--- a/src/render/Renderer.cpp
+++ b/src/render/Renderer.cpp
@@ -2535,10 +2535,8 @@ bool Renderer::prepareStrokeUpload(uint32_t id, Mesh& mesh, StrokeUpload& out, c
out.regrid = false;
out.packMs = out.boundsMs = 0.0;
const auto clock = std::chrono::steady_clock::now();
- MeshSlot* found = nullptr;
- for (MeshSlot& s : slots_)
- if (s.id == id) found = &s;
- if (!found) return false;
+ MeshSlot* found = static_cast<MeshSlot*>(out.slot); // (bindStrokeUpload: never the list from this thread)
+ if (!found || found->id != id) return false;
MeshSlot& s = *found;
const size_t nv = mesh.vertexCount();
// What only the regular sync handles: a new layout, faces, attributes appearing, dynamic topology, textures.
@@ -2733,14 +2731,18 @@ void Renderer::commitStrokeUpload(StrokeUpload& up) {
void Renderer::setDraftNormals(uint32_t id) { draftId_ = id; }
+void Renderer::bindStrokeUpload(uint32_t id, StrokeUpload& up) {
+ up.slot = nullptr;
+ for (MeshSlot& s : slots_)
+ if (s.id == id) up.slot = &s;
+}
+
void Renderer::refineStrokeBoundsInto(uint32_t id, const Mesh& mesh, StrokeUpload& up) {
up.exact = false;
up.exactClusters.clear();
up.exactBounds.clear();
- MeshSlot* found = nullptr;
- for (MeshSlot& s : slots_)
- if (s.id == id) found = &s;
- if (!found) return;
+ MeshSlot* found = static_cast<MeshSlot*>(up.slot);
+ if (!found || found->id != id) return;
MeshSlot& s = *found;
const size_t nc = s.order.clusters().size();
if (s.fresh || mesh.topologyDirty || s.bounds.size() != nc) return;
diff --git a/src/render/Renderer.h b/src/render/Renderer.h
index cdd04f98..bcf8b786 100644
--- a/src/render/Renderer.h
+++ b/src/render/Renderer.h
@@ -118,6 +118,7 @@ public:
// Only one prepare at a time, and no syncScene of that mesh until its commit.
struct StrokeUpload {
uint32_t id = 0;
+ void* slot = nullptr; // bindStrokeUpload
bool ready = false;
std::vector<PackedVertex> data;
struct Range {
@@ -139,6 +140,9 @@ public:
// `curvature` (optional, by vertex): the cavity term of every vertex the mesh marked dirty, already worked
// out (Sculptor::strokeCurvature).
bool prepareStrokeUpload(uint32_t id, Mesh& mesh, StrokeUpload& out, const float* curvature = nullptr);
+ // GL thread, before handing `up` to another thread: finds SubTool id's slot (slots come and go on the GL
+ // thread, e.g. thumbnails; the other thread uses this one, which stays put in the list).
+ void bindStrokeUpload(uint32_t id, StrokeUpload& up);
void commitStrokeUpload(StrokeUpload& up);
// The stroke uploads gave the clusters they moved quick culling bounds (around their vertices' boxes, which
// packing finds anyway, without the normal cone, so they are never culled as facing away); at the stroke's