Skip to content

Vertex paint: coalesce vertex color uploads during stroke - #343

Merged
fernandotonon merged 2 commits into
masterfrom
feat/vertex-paint-perf
Apr 29, 2026
Merged

Vertex paint: coalesce vertex color uploads during stroke#343
fernandotonon merged 2 commits into
masterfrom
feat/vertex-paint-perf

Conversation

@fernandotonon

@fernandotonon fernandotonon commented Apr 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • Improve vertex paint stroke performance by coalescing vertex color uploads.
  • Instead of committing colors on every mouse-move, schedule a single-shot flush and upload at most once per event loop tick.
  • Force a final flush on stroke end to ensure the last sample is visible and captured.

Rationale

On dense meshes, uploading vertex colors every mouse-move can dominate frame time and make the brush feel sticky. This keeps the painting math unchanged while reducing buffer churn.

Test plan

  • Enter Edit Mode, enable Vertex Paint.
  • Paint continuously over a dense mesh: brush should feel smoother and colors should still update interactively.
  • Release mouse: last painted sample should be visible immediately and undo should revert the stroke.

Made with Cursor

Summary by CodeRabbit

  • Bug Fixes
    • Improved vertex painting performance by deferring color updates instead of processing them immediately on each brush sample.
    • Enhanced reliability of undo snapshots to ensure painted states are properly captured before editing completes.

Avoid committing vertex colors to the entity on every mouse-move. Instead schedule a single-shot flush and upload at most once per event loop tick, plus force a final flush on stroke end.

Made-with: Cursor
@coderabbitai

coderabbitai Bot commented Apr 29, 2026

Copy link
Copy Markdown

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

Vertex-paint GPU color commits transition from synchronous to deferred execution. Brush sample changes mark a pending flush flag and schedule commitment via a zero-delay timer, validating edit-mode state before executing. Edit-mode exit clears pending flags, and stroke completion with commit enabled forces immediate flush to capture final state before undo snapshot.

Changes

Cohort / File(s) Summary
Header Declarations
src/EditModeController.h
Added two private boolean flags (m_vertexPaintFlushPending and m_vertexPaintFlushScheduled) to track deferred flush state in vertex-paint operations.
Implementation Logic
src/EditModeController.cpp
Refactored vertex-paint commit flow to defer GPU color updates via zero-delay QTimer callback instead of immediate execution; validates edit-mode and pointer validity before commit; clears pending flags on edit-mode exit; forces immediate flush on stroke completion with commit enabled.

Sequence Diagram

sequenceDiagram
    participant Brush as Brush Sample
    participant Controller as EditModeController
    participant Timer as QTimer
    participant GPU as Mesh/GPU Commit
    
    Brush->>Controller: applyVertexColorBrush()
    activate Controller
    Controller->>Controller: Check if flush pending
    alt Flush not scheduled
        Controller->>Timer: Schedule zero-delay callback
        Controller->>Controller: Set m_vertexPaintFlushPending = true
        Controller->>Controller: Set m_vertexPaintFlushScheduled = true
    else Flush already scheduled
        Controller->>Controller: Set m_vertexPaintFlushPending = true
    end
    deactivate Controller
    
    Timer-->>Controller: Callback triggered
    activate Controller
    Controller->>Controller: Validate edit-mode active & pointers valid
    alt Validation passed
        Controller->>GPU: commitVertexColorsToEntity()
        GPU->>GPU: meshDataChanged()
    end
    Controller->>Controller: Clear pending/scheduled flags
    deactivate Controller
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 With brush in paw, I paint so free,
But hold my work—don't rush, you see!
A timer waits with patient care,
Then batches color through the air,
One final stroke, commit with might,
Our painted strokes now set just right! 🎨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main performance optimization: coalescing vertex color uploads during painting strokes instead of committing on every brush sample.
Description check ✅ Passed The description includes a clear summary of changes, rationale for the optimization, and a practical test plan, but lacks explicit feature/bugfix categorization matching the template.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/vertex-paint-perf

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
Review rate limit: 0/1 reviews remaining, refill in 60 minutes.

Comment @coderabbitai help to get the list of available commands and usage tips.

@fernandotonon
fernandotonon merged commit ae1370a into master Apr 29, 2026
11 of 12 checks passed
@fernandotonon
fernandotonon deleted the feat/vertex-paint-perf branch April 29, 2026 20:21
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant