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
Renderer: a vertex's cavity bits written from its first GPU slot only (data race in uploadVertices / prepareStrokeUpload)
islandmed006eab351aab
diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cppindex 5429e76f..572e860a 100644--- a/src/render/Renderer.cpp+++ b/src/render/Renderer.cpp@@ -1476,7 +1476,9 @@ void Renderer::uploadVertices(MeshSlot& s, const Mesh& mesh, bool full) {if (v < nv) { // (else a vertex dynamic topology removed, which only patched clusters named)inside &= packVertex(s.grid, mesh.positions[v], normals ? mesh.normals[v] : glm::vec3(0.0f, 0.0f, 1.0f),curvatureAt(mesh, v), pv);- sent[v] = uint16_t(pv.normal >> 22);+ // Only the vertex's first slot writes: its copies in other clusters may be packed on another thread+ // at the same time (the same value, but a data race; ThreadSanitizer, 11-05).+ if (s.order.toGpu(v) == i) sent[v] = uint16_t(pv.normal >> 22);box.expand(mesh.positions[v]);}out[i - b] = pv;@@ -3467,7 +3469,7 @@ bool Renderer::prepareStrokeUpload(uint32_t id, Mesh& mesh, StrokeUpload& out, cinside &= packVertex(grid, mesh.positions[v], mesh.normals[v], keep && sent ? 0.0f : c, pv);if (sent) {if (keep) pv.normal = (pv.normal & 0x003FFFFFu) | uint32_t(sent[v]) << 22;- else sent[v] = uint16_t(pv.normal >> 22);+ else if (s.order.toGpu(v) == i) sent[v] = uint16_t(pv.normal >> 22); // (first slot only, as uploadVertices)}box.expand(mesh.positions[v]);}diff --git a/tests/tsan/strokes.sfui b/tests/tsan/strokes.sfuinew file mode 100644index 00000000..051e0669--- /dev/null+++ b/tests/tsan/strokes.sfui@@ -0,0 +1,14 @@+# ThreadSanitizer smoke (tools/test/tsan.sh): strokes, a mask stroke and full uploads on a mesh big enough that the+# vertex uploads run on several threads. Renderer::uploadVertices and prepareStrokeUpload wrote a vertex's cavity+# bits from every copy of it at once (11-05).+run new_sphere subdivisions=6+key f+stroke 0.2 0.5 0.8 0.5+stroke 0.3 0.3 0.7 0.7+hold ctrl+stroke 0.3 0.6 0.7 0.4+hold none+stroke 0.5 0.2 0.5 0.8+run subdivide+stroke 0.2 0.4 0.8 0.6+wait 0.5diff --git a/tests/tsan/tsan.supp b/tests/tsan/tsan.suppnew file mode 100644index 00000000..951ef954--- /dev/null+++ b/tests/tsan/tsan.supp@@ -0,0 +1,4 @@+# ThreadSanitizer suppressions for tools/test/tsan.sh: only reports inside system libraries we don't call directly.+# libdbus: two of its own mutexes in opposite orders when SDL closes its D-Bus connection at exit+# (dbus_connection_close from SDL_Quit; our code never calls libdbus). Not ours to fix.+deadlock:libdbus-1.sodiff --git a/tools/test/tsan.sh b/tools/test/tsan.shnew file mode 100755index 00000000..0348fc5c--- /dev/null+++ b/tools/test/tsan.sh@@ -0,0 +1,29 @@+#!/usr/bin/env bash+# ThreadSanitizer smoke: builds sculptforge with -fsanitize=thread in build-tsan (RelWithDebInfo) and runs+# tests/tsan/*.sfui offscreen; fails on any report left after tests/tsan/tsan.supp. Slow (a full TSan build, then+# the app at a fraction of its speed): run it by hand or nightly, through ~/Work/.sf/heavy.sh on the laptop.+# tools/test/tsan.sh [build dir, default build-tsan]+set -euo pipefail+root=$(cd "$(dirname "$0")/../.." && pwd)+build=${1:-$root/build-tsan}+flags="-fsanitize=thread -fno-omit-frame-pointer"+[ -f "$build/CMakeCache.txt" ] || cmake -S "$root" -B "$build" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_CXX_FLAGS="$flags" \+ -DCMAKE_C_FLAGS="$flags" -DCMAKE_EXE_LINKER_FLAGS=-fsanitize=thread >/dev/null+cmake --build "$build" -j"${JOBS:-3}" --target sculptforge >/dev/null+logs=$(mktemp -d)+status=0+for script in "$root"/tests/tsan/*.sfui; do+ name=$(basename "$script" .sfui)+ TSAN_OPTIONS="halt_on_error=0 second_deadlock_stack=1 suppressions=$root/tests/tsan/tsan.supp log_path=$logs/$name" \+ SDL_VIDEO_DRIVER=offscreen "$build/sculptforge" --ui-test "$script" --ui-out "$logs/$name-shots" >/dev/null 2>&1 || {+ echo "tsan: $name: the script failed"; status=1; }+ if reports=$(cat "$logs/$name".* 2>/dev/null | grep -c "WARNING: ThreadSanitizer"); [ "$reports" -gt 0 ]; then+ echo "tsan: $name: $reports report(s):"+ grep -h -A3 "WARNING: ThreadSanitizer" "$logs/$name".* | head -40+ status=1+ else+ echo "tsan: $name: clean"+ fi+done+[ $status -eq 0 ] && rm -rf "$logs" || echo "tsan: logs in $logs"+exit $status