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
UI test for Preferences > Performance; Fast Navigation counts still frames
islandmed551080b3d49c
diff --git a/src/app/App.cpp b/src/app/App.cppindex e4831e19..2bf85246 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -355,7 +355,9 @@ int App::runUiTest(int w, int h, int fps) {ImGui::LogFinish();ImGui::Render();+ const auto syncStart = std::chrono::steady_clock::now();syncScene();+ notePerformanceFrame(std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - syncStart).count());viewSamples(); // keeps Fast Navigation's view of the camera current (UI tests read view_samples)++frames;const std::string shot = demo_->takeShotRequest();diff --git a/src/app/App.h b/src/app/App.hindex 9e92a167..f930f955 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -434,8 +434,9 @@ private:void notePerformanceFrame(double syncMs); // after syncScene: upload time, GPU memory warningsstruct PerfState {glm::mat4 lastView{0.0f};- double lastCameraMove = -1.0; // seconds (SDL ticks)+ int framesStill = 0; // frames since the view last movedbool fastNow = false; // this frame draws without antialiasing (fast navigation)+ int samplesWanted = 0; // viewSamples() for the last frameint samplesUsed = 0; // what the renderer managed last frame (fewer when out of memory)double strokeSyncMs = 0.0; // upload time summed over the open stroke's framesint strokeFrames = 0;diff --git a/src/app/PanelPerformance.cpp b/src/app/PanelPerformance.cppindex d02d1c4d..0f4e1a31 100644--- a/src/app/PanelPerformance.cpp+++ b/src/app/PanelPerformance.cpp@@ -12,14 +12,19 @@#include <chrono>#include <cstdio>+#include <cstdlib>namespace sf {namespace {constexpr const char* kPath = "Preferences > Performance";-// Scenes this big draw without antialiasing while the view moves (with Fast Navigation on).-constexpr size_t kFastNavigationTriangles = 10'000'000;+// Scenes this big draw without antialiasing while the view moves (with Fast Navigation on). UI tests lower it+// with the environment variable SF_FAST_NAVIGATION_TRIANGLES, so they needn't build a huge mesh.+size_t fastNavigationTriangles() {+ const char* v = std::getenv("SF_FAST_NAVIGATION_TRIANGLES");+ return v && *v ? size_t(std::strtoull(v, nullptr, 10)) : size_t(10'000'000);+}std::string megabytes(size_t bytes) {char buf[32];@@ -85,19 +90,21 @@ void App::applyPerformancePrefs() { ThreadPool::shared().setSerial(!uiPrefs_.mulint App::viewSamples() {const int aa = uiPrefs_.antialiasing;- // The view moved this frame or a moment ago (orbit, pan, zoom, snapping, framing), or is being dragged.+ // The view moved in the last few frames (orbit, pan, zoom, snapping, framing), or is being dragged.const glm::mat4 view = camera_.view();- const double now = double(SDL_GetTicks()) / 1000.0;if (view != perf_.lastView) {perf_.lastView = view;- perf_.lastCameraMove = now;+ perf_.framesStill = 0;+ } else if (perf_.framesStill < 1000) {+ ++perf_.framesStill;}- const bool moving = drag_ == Drag::Orbit || drag_ == Drag::Pan || drag_ == Drag::Zoom || now - perf_.lastCameraMove < 0.25;+ const bool moving = drag_ == Drag::Orbit || drag_ == Drag::Pan || drag_ == Drag::Zoom || perf_.framesStill < 8;size_t triangles = 0;for (int i = 0; i < doc_.subtoolCount(); ++i)if (doc_.subtools[size_t(i)].visible) triangles += doc_.subtoolMesh(i).triangleCount();- perf_.fastNow = aa > 1 && uiPrefs_.fastNavigation && moving && triangles >= kFastNavigationTriangles;- return perf_.fastNow ? 1 : aa;+ perf_.fastNow = aa > 1 && uiPrefs_.fastNavigation && moving && triangles >= fastNavigationTriangles();+ perf_.samplesWanted = perf_.fastNow ? 1 : aa;+ return perf_.samplesWanted;}void App::notePerformanceFrame(double syncMs) {@@ -129,9 +136,10 @@ void App::drawPerformanceSection() {// --- Threads ---bool threads = !ThreadPool::shared().serial();- if (ImGui::Checkbox(("Multithreading (" + std::to_string(ThreadPool::shared().threads()) + " threads)##perf.mt").c_str(), &threads))- actions_.find("perf.multithreading")->run();+ if (ImGui::Checkbox("Multithreading##perf.mt", &threads)) actions_.find("perf.multithreading")->run();ui::HelpAction(*this, "perf.multithreading");+ ImGui::SameLine();+ ImGui::TextDisabled("%d threads", threads ? ThreadPool::shared().threads() : 1);// --- The last stroke ---ImGui::Spacing();diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cppindex e135b726..d78554f0 100644--- a/src/app/UiTest.cpp+++ b/src/app/UiTest.cpp@@ -239,7 +239,7 @@ double Demo::query(const std::string& name, bool& known) const {if (name == "sdiv") return subdivLevelCount(m) ? double(subdivCurrentLevel(m) + 1) : 0.0;if (name == "sdiv_levels") return double(subdivLevelCount(m));if (name == "antialiasing") return double(app_.uiPrefs_.antialiasing);- if (name == "view_samples") return double(app_.viewSamples());+ if (name == "view_samples") return double(app_.perf_.samplesWanted);if (name == "multithreading") return ThreadPool::shared().serial() ? 0.0 : 1.0;if (name == "last_stroke_dabs") return double(app_.perf_.lastStroke.dabs);if (name == "texture_size") return hasTexture(m) ? double(m.texture->width) : 0.0;diff --git a/tests/ui/performance.sfui b/tests/ui/performance.sfuinew file mode 100644index 00000000..23263dc6--- /dev/null+++ b/tests/ui/performance.sfui@@ -0,0 +1,81 @@+# Preferences > Performance: antialiasing, Fast Navigation (a big scene draws without antialiasing while the view+# moves; the threshold is lowered here so a small sphere counts as big), multithreading, what the last stroke cost+# per dab, and memory. Strokes give the same result with multithreading off.+run new_sphere subdivisions=6+click "Preferences##palette.preferences"+click "Performance##preferences.performance"+expect_text Antialiasing+expect_text Sculpt a stroke to see what it costs+expect_text Memory+expect_value antialiasing == 4+expect_value multithreading == 1++# Ctrl-hover help on the new controls.+hold ctrl+hover "AA 4x##perf.aa_4"+expect_help "samples per pixel"+hover "Fast Navigation"+expect_help "10 million triangles"+hover "Multithreading##perf.mt"+expect_help "every core"+hold none++# Antialiasing off and back; 8x.+click "AA Off##perf.aa_1"+expect_value antialiasing == 1+expect_value view_samples == 1+click "AA 8x##perf.aa_8"+expect_value antialiasing == 8+click "AA 4x##perf.aa_4"+expect_value view_samples == 4+key escape++# A stroke: the panel shows its cost per dab.+snapshot+stroke 0.3 0.4 0.7 0.5+expect_value last_stroke_dabs > 3+remember moved_sum threaded+click "Preferences##palette.preferences"+expect_text dabs,+expect_text Brush+expect_text GPU upload+shot performance-after-stroke+key escape++# Multithreading off: the same stroke moves the mesh the same way.+key ctrl+z+click "Preferences##palette.preferences"+click "Multithreading##perf.mt"+expect_value multithreading == 0+expect_status "one thread"+key escape+stroke 0.3 0.4 0.7 0.5+expect_value moved_sum == $threaded+click "Preferences##palette.preferences"+click "Multithreading##perf.mt"+expect_value multithreading == 1+shot performance-panel+key escape++# Fast Navigation: the "big" scene draws with one sample while the view turns, and 4x once it stops.+env SF_FAST_NAVIGATION_TRIANGLES 10000+orbit 120 0+expect_value view_samples == 1+wait 0.5+expect_value view_samples == 4+click "Preferences##palette.preferences"+click "Fast Navigation"+key escape+orbit 120 0+expect_value view_samples == 4+click "Preferences##palette.preferences"+click "Fast Navigation"+key escape+env SF_FAST_NAVIGATION_TRIANGLES 10000000++# The settings are in the F3 command palette.+key f3+type "##Command palette" "fast navigation"+expect_text Fast Navigation+shot command-palette+key escape