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
Two main tiers (Laptop / Budget, Workstation) plus Software safe mode; core/TierConfig with battery detection
islandmeddc55eb96c803
diff --git a/CMakeLists.txt b/CMakeLists.txtindex e647baed..9a780894 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -34,6 +34,7 @@ add_library(sculptforge_core STATICsrc/core/Benchmark.cppsrc/core/HardwareProfile.cppsrc/core/FrameGovernor.cpp+ src/core/TierConfig.cppsrc/core/Sculpt.cppsrc/core/Dyntopo.cppsrc/core/DyntopoCommands.cppdiff --git a/src/app/Calibration.cpp b/src/app/Calibration.cppindex cf3c3ad4..0a5ca53c 100644--- a/src/app/Calibration.cpp+++ b/src/app/Calibration.cpp@@ -3,6 +3,7 @@#include "app/Calibration.h"#include "core/ThreadPool.h"+#include "core/TierConfig.h"#include "render/GL.h"#include <SDL3/SDL.h>@@ -562,7 +563,9 @@ void Calibrator::skip() {stage_ = kStages;}-HardwareProfile Calibrator::profile(const ProfileOverrides& overrides) const { return mapProfile(hw_, cal_, overrides); }+HardwareProfile Calibrator::profile(const ProfileOverrides& overrides, const ProfileTier* previous) const {+ return mapProfile(hw_, cal_, overrides, previous);+}void applyCachedThreadCount() {HardwareProfile cached;@@ -570,10 +573,10 @@ void applyCachedThreadCount() {ThreadPool::setSharedThreadCount(cached.settings.threads);}-HardwareProfile calibrateNow(bool quick, const ProfileOverrides& overrides) {+HardwareProfile calibrateNow(bool quick, const ProfileOverrides& overrides, const ProfileTier* previous) {Calibrator c(quick);while (c.step()) {}- return c.profile(overrides);+ return c.profile(overrides, previous); // the same GPU as last time: its tier holds near a boundary}int runCalibrateCommandLine(bool quick, bool save) {@@ -603,8 +606,22 @@ int runCalibrateCommandLine(bool quick, bool save) {HardwareProfile cached;const std::string path = hardwareProfilePath();const bool hadCache = loadHardwareProfile(path, cached);- const HardwareProfile p = calibrateNow(quick, hadCache ? cached.overrides : ProfileOverrides{});- const Json j = calibrationJson(p);+ HardwareInfo now;+ probeHardware(now);+ const bool sameGpu = hadCache && cached.hardware.glRenderer == now.glRenderer && cached.hardware.glVendor == now.glVendor;+ const HardwareProfile p = calibrateNow(quick, hadCache ? cached.overrides : ProfileOverrides{}, sameGpu ? &cached.measuredTier : nullptr);+ // The tier configuration for this power source and the primary display.+ PowerSource power = PowerSource::Unknown;+ switch (SDL_GetPowerInfo(nullptr, nullptr)) {+ case SDL_POWERSTATE_ON_BATTERY: power = PowerSource::Battery; break;+ case SDL_POWERSTATE_NO_BATTERY:+ case SDL_POWERSTATE_CHARGING:+ case SDL_POWERSTATE_CHARGED: power = PowerSource::AC; break;+ default: break;+ }+ const SDL_DisplayMode* mode = SDL_GetCurrentDisplayMode(SDL_GetPrimaryDisplay());+ const TierConfig tier = tierConfigFor(p, power, mode ? int(mode->refresh_rate + 0.5f) : 0);+ const Json j = calibrationJson(p, &tier);std::string error;if (!validateCalibrationJson(j, error)) {std::fprintf(stderr, "calibration JSON is invalid: %s\n", error.c_str());diff --git a/src/app/Calibration.h b/src/app/Calibration.hindex ff6e0c3f..e65e09cd 100644--- a/src/app/Calibration.h+++ b/src/app/Calibration.h@@ -33,7 +33,8 @@ public:// Marks calibration skipped: the profile is mapped from the probe alone.void skip();// The result (valid once done()), mapped with `overrides`.- HardwareProfile profile(const ProfileOverrides& overrides = {}) const;+ // `previous`: the tier of the same GPU's last calibration (kept when the measurement is close to a boundary).+ HardwareProfile profile(const ProfileOverrides& overrides = {}, const ProfileTier* previous = nullptr) const;private:static constexpr int kStages = 5; // probe, triangles, upload, memory, dab@@ -67,7 +68,7 @@ private:void applyCachedThreadCount();// Calibrates now, blocking (about 2-3 s; quick: about 1 s). Needs a current OpenGL context.-HardwareProfile calibrateNow(bool quick, const ProfileOverrides& overrides);+HardwareProfile calibrateNow(bool quick, const ProfileOverrides& overrides, const ProfileTier* previous = nullptr);// sculptforge --calibrate [--calibrate-quick] [--calibrate-no-save]: a hidden window and context, calibrate, print// the JSON (schema sculptforge.calibration/1) to stdout, save it as the cached profile. Returns the exit code.diff --git a/src/app/PanelPerformanceProfile.cpp b/src/app/PanelPerformanceProfile.cppindex ed702a42..69a516d9 100644--- a/src/app/PanelPerformanceProfile.cpp+++ b/src/app/PanelPerformanceProfile.cpp@@ -18,6 +18,7 @@#include "core/FrameGovernor.h"#include "core/HardwareProfile.h"#include "core/ThreadPool.h"+#include "core/TierConfig.h"#include <SDL3/SDL.h>@@ -48,6 +49,9 @@ struct HwProfileUi {std::deque<Pending> pending; // frames waiting for their GPU timeuint64_t revision = 0; // performanceSettingsRevision() when last appliedint displayHz = 0;+ PowerSource power = PowerSource::Unknown;+ double nextPowerCheck = 0.0; // seconds (SDL ticks)+ TierConfig tier; // what currentTierConfig() holdsdouble lastCpuMs = 0.0, lastGpuMs = -1.0;bool overridesOpen = false;};@@ -75,6 +79,17 @@ bool calibrationDisabled() {return v && *v && *v != '0';}+// Battery or mains (SDL_GetPowerInfo): a laptop on battery drops to draft brushes and 60 Hz (core/TierConfig.h).+PowerSource powerSource() {+ switch (SDL_GetPowerInfo(nullptr, nullptr)) {+ case SDL_POWERSTATE_ON_BATTERY: return PowerSource::Battery;+ case SDL_POWERSTATE_NO_BATTERY:+ case SDL_POWERSTATE_CHARGING:+ case SDL_POWERSTATE_CHARGED: return PowerSource::AC;+ default: return PowerSource::Unknown;+ }+}+int displayRefreshHz(SDL_Window* window) {if (!window) return 0;const SDL_DisplayID display = SDL_GetDisplayForWindow(window);@@ -94,11 +109,13 @@ void App::initHardwareProfile() {hwProfile_ = std::make_shared<HwProfileUi>();HwProfileUi& hw = *hwProfile_;hw.displayHz = displayRefreshHz(window_);+ hw.power = powerSource();// The calibrate command (console, MCP) measures the GPU too while the app runs.setGpuCalibrator([this](HardwareProfile& out, std::string&) {HardwareProfile cached;const ProfileOverrides keep = loadHardwareProfile(hardwareProfilePath(), cached) ? cached.overrides : hwProfile_->profile.overrides;- out = calibrateNow(false, keep);+ const bool same = cached.hardware.glRenderer == hwProfile_->profile.hardware.glRenderer;+ out = calibrateNow(false, keep, same ? &cached.measuredTier : nullptr);std::string error;saveHardwareProfile(hardwareProfilePath(), out, error);// Applied on the next frame (the command saved it; the revision check reloads it).@@ -138,8 +155,12 @@ void App::applyHardwareProfile(const HardwareProfile& p, bool announce) {HwProfileUi& hw = *hwProfile_;hw.profile = p;hw.active = true;+ // The tier's knobs for this power source and display; its target Hz is the governor's (60 / 120 / 144).+ hw.tier = tierConfigFor(p, hw.power, hw.displayHz);+ setCurrentTierConfig(hw.tier);PerformanceSettings s = p.settings;- if (!p.overrides.targetFps) s.targetFps = hw.displayHz >= 119 ? 120 : 60; // 120 where the display can show it+ s.targetFps = hw.tier.targetHz;+ s.uploadBudgetMBPerFrame = hw.tier.uploadBudgetMBPerFrame;hw.profile.settings.targetFps = s.targetFps;setCurrentPerformanceSettings(s);GovernorConfig cfg;@@ -160,7 +181,8 @@ void App::finishCalibration() {HwProfileUi& hw = *hwProfile_;HardwareProfile cached;const ProfileOverrides keep = loadHardwareProfile(hardwareProfilePath(), cached) ? cached.overrides : hw.profile.overrides;- const HardwareProfile p = hw.calibrator->profile(keep);+ const bool same = !cached.hardware.glRenderer.empty() && cached.hardware.glRenderer == hw.profile.hardware.glRenderer;+ const HardwareProfile p = hw.calibrator->profile(keep, same ? &cached.measuredTier : nullptr);hw.calibrator.reset();std::string error;hw.saved = saveHardwareProfile(hardwareProfilePath(), p, error);@@ -225,12 +247,22 @@ void App::hardwareProfileFrameEnd() {}if (changed && hw.profile.overrides.governor && !hw.profile.overrides.motionProxyThreshold)setGovernedBudgets(hw.governor.budget(), hw.governor.proxyThreshold());- // The display may change (the window moved to a 120 Hz screen): follow it.- if (frame % 600 == 0) {+ // The display (the window moved to a 120 Hz screen) or the power source (unplugged) may change: every few+ // seconds, look; a change re-applies the profile with the new tier configuration.+ if (const double t = double(SDL_GetTicksNS()) * 1e-9; t >= hw.nextPowerCheck) {+ hw.nextPowerCheck = t + 5.0;const int hz = displayRefreshHz(window_);- if (hz != hw.displayHz) {+ const PowerSource power = powerSource();+ if (hz != hw.displayHz || power != hw.power) {+ const bool battery = power == PowerSource::Battery, wasBattery = hw.power == PowerSource::Battery;hw.displayHz = hz;- if (!hw.profile.overrides.targetFps) hw.governor.setTargetFps(hz >= 119 ? 120 : 60);+ hw.power = power;+ const HardwareProfile p = hw.profile;+ applyHardwareProfile(p, false);+ if (battery != wasBattery)+ status_ = battery ? "On battery: draft brushes (normals and cavity at pen release), " + std::to_string(hw.tier.targetHz) + " Hz"+ : "On mains power: " + std::string(hw.tier.draftBrushMode ? "draft" : "continuous") + " brushes, " ++ std::to_string(hw.tier.targetHz) + " Hz";}}// The set_performance_override or calibrate command changed the profile: take it up.@@ -372,6 +404,11 @@ void App::drawPerformanceProfileSection() {"\n" + std::to_string(s.threads) + " threads" +(s.threads != ThreadPool::shared().threads() ? " (after a restart; now " + std::to_string(ThreadPool::shared().threads()) + ")" : std::string()) +", target " + std::to_string(s.targetFps) + " fps";+ const TierConfig& tc = hw.tier;+ set += "\n" + std::string(tc.draftBrushMode ? "Draft brushes (normals and cavity at pen release)" : "Continuous brushes") ++ ", active " + formatTriangles(tc.activeTriangleBudget) + " triangles, cache up to " + formatMegabytes(tc.residentCacheCapMB) ++ (tc.zeroCopyUMA ? ", zero-copy (shared memory)" : "") ++ (tc.onBattery() ? "\nOn battery" : tc.power == PowerSource::AC ? "\nOn mains power" : "");ImGui::TextWrapped("%s", set.c_str());ImGui::LogText("%s", set.c_str());@@ -394,12 +431,12 @@ void App::drawPerformanceProfileSection() {if (ImGui::TreeNode("Manual overrides")) {ProfileOverrides o = p.overrides;bool edited = false;- const char* tiers[] = {"Automatic", "Software (safe mode)", "Laptop", "Workstation", "Monster"};+ const char* tiers[] = {"Tier: automatic", "Software (safe mode)", "Laptop / Budget", "Workstation"};int tierIndex = 0;ProfileTier forced;if (!o.tier.empty() && tierFromName(o.tier, forced)) tierIndex = int(forced) + 1;ImGui::SetNextItemWidth(-1.0f);- if (ImGui::Combo("##perf.tier", &tierIndex, tiers, 5)) {+ if (ImGui::Combo("##perf.tier", &tierIndex, tiers, 4)) {o.tier = tierIndex == 0 ? std::string() : std::string(tierName(ProfileTier(tierIndex - 1)));edited = true;}@@ -427,6 +464,9 @@ void App::drawPerformanceProfileSection() {number("Threads (next start)", threads, uint64_t(p.automatic.threads), 1.0, "");o.threads = int(threads);}+ const char* draftNames[] = {"Draft brushes: automatic", "Draft brushes: always", "Draft brushes: never"};+ ImGui::SetNextItemWidth(-1.0f);+ if (ImGui::Combo("##perf.draft", &o.draftBrush, draftNames, 3)) edited = true;const char* fpsNames[] = {"Target: automatic", "30 fps", "60 fps", "120 fps", "144 fps"};const int fpsValues[] = {0, 30, 60, 120, 144};int fpsIndex = 0;diff --git a/src/core/HardwareProfile.cpp b/src/core/HardwareProfile.cppindex b3c868de..87f3cbb9 100644--- a/src/core/HardwareProfile.cpp+++ b/src/core/HardwareProfile.cpp@@ -7,6 +7,7 @@#include "core/Commands.h"#include "core/Document.h"#include "core/Sculpt.h"+#include "core/TierConfig.h"#include <algorithm>#include <atomic>@@ -113,14 +114,13 @@ const char* tierName(ProfileTier tier) {case ProfileTier::Software: return "Software";case ProfileTier::Laptop: return "Laptop";case ProfileTier::Workstation: return "Workstation";- case ProfileTier::Monster: return "Monster";}return "Laptop";}bool tierFromName(const std::string& name, ProfileTier& out) {const std::string n = lower(name);- for (ProfileTier t : {ProfileTier::Software, ProfileTier::Laptop, ProfileTier::Workstation, ProfileTier::Monster})+ for (ProfileTier t : {ProfileTier::Software, ProfileTier::Laptop, ProfileTier::Workstation})if (n == lower(tierName(t))) {out = t;return true;@@ -129,6 +129,14 @@ bool tierFromName(const std::string& name, ProfileTier& out) {out = ProfileTier::Software;return true;}+ if (n == "budget" || n == "laptop/budget") {+ out = ProfileTier::Laptop;+ return true;+ }+ if (n == "monster") { // the 0.9.8 development builds' third tier+ out = ProfileTier::Workstation;+ return true;+ }return false;}@@ -363,14 +371,16 @@ TierLimits limits(ProfileTier t) {switch (t) {case ProfileTier::Software: return {250'000, 4 * kM, 1 * kM, 1024, 16, 4096, 20 * kM, 16 * kM};case ProfileTier::Laptop: return {2 * kM, 40 * kM, 8 * kM, 2048, 64, 8192, 120 * kM, 256 * kM};- case ProfileTier::Workstation: return {8 * kM, 150 * kM, 30 * kM, 6144, 128, 16384, 500 * kM, 1024 * kM};- case ProfileTier::Monster: return {30 * kM, 600 * kM, 100 * kM, 12288, 256, 16384, 2000 * kM, 4096 * kM};+ case ProfileTier::Workstation: return {8 * kM, 600 * kM, 40 * kM, 12288, 256, 16384, 2000 * kM, 4096 * kM};}return limits(ProfileTier::Laptop);}+// Workstation: a discrete GPU with 16 GB or more and 64 GB or more of RAM (what the OS reports is a little less+// than the label: 16 GB cards say about 15.9 GB, 64 GB machines about 62.5 GB), which also measures fast.+constexpr uint64_t kWorkstationVramMB = 15 * 1024, kWorkstationRamMB = 60 * 1024;// Thresholds on measured triangle throughput (million small triangles per second, trivial shading).-constexpr double kSoftwareBelowM = 60.0, kWorkstationFromM = 1000.0, kMonsterFromM = 5000.0;+constexpr double kSoftwareBelowM = 60.0, kWorkstationFromM = 1000.0;// A re-calibration of the same GPU keeps its previous tier when the new measurement lands within this factor of// the boundary between the two (measurements vary a little from run to run, more on a busy machine).@@ -378,52 +388,49 @@ constexpr double kStickyBand = 1.15;ProfileTier tierFromMeasurements(const HardwareInfo& hw, const Calibration& c, const ProfileTier* previous, std::string& why) {char buf[256];- ProfileTier t;if (hw.gpuKind == GpuKind::Software) {why = "a software renderer (" + hw.glRenderer + "): safe mode";return ProfileTier::Software;}- if (c.trianglesPerSecondM > 0.0) {- if (c.trianglesPerSecondM < kSoftwareBelowM) t = ProfileTier::Software;- else if (c.trianglesPerSecondM < kWorkstationFromM) t = ProfileTier::Laptop;- else if (c.trianglesPerSecondM < kMonsterFromM) t = ProfileTier::Workstation;- else t = ProfileTier::Monster;- std::snprintf(buf, sizeof buf, "%.0fM triangles/s", c.trianglesPerSecondM);+ const double tri = c.trianglesPerSecondM;+ if (tri > 0.0) {+ std::snprintf(buf, sizeof buf, "%.0fM triangles/s", tri);why = buf;- if (previous && std::abs(int(*previous) - int(t)) == 1) {- const ProfileTier upper = int(*previous) > int(t) ? *previous : t;- const double boundary = upper == ProfileTier::Laptop ? kSoftwareBelowM- : upper == ProfileTier::Workstation ? kWorkstationFromM- : kMonsterFromM;- if (c.trianglesPerSecondM >= boundary / kStickyBand && c.trianglesPerSecondM <= boundary * kStickyBand) {- t = *previous;- why += ", kept " + std::string(tierName(t)) + " (close to the boundary)";- }- }} else {- // Nothing measured: a conservative guess from the memory sizes.- const uint64_t gpu = usableGpuMemoryMB(hw);- t = ProfileTier::Laptop;- if (gpu >= 8192 && hw.ramMB >= 24 * 1024) t = ProfileTier::Workstation;- why = "not calibrated, from memory sizes";+ why = "not calibrated";}- // Memory caps: a fast GPU with little memory, or a machine with little RAM, can't hold the big scenes.+ // Too slow for anything but safe mode, whatever the GPU says it is.+ if (tri > 0.0 && tri < kSoftwareBelowM) {+ if (previous && *previous == ProfileTier::Laptop && tri >= kSoftwareBelowM / kStickyBand) {+ why += ", kept Laptop (close to the boundary)";+ return ProfileTier::Laptop;+ }+ why += ", safe mode";+ return ProfileTier::Software;+ }+ // Workstation needs the memory (a 16 GB+ discrete GPU, 64 GB+ RAM) and the measured speed. Everything else,+ // including Apple Silicon and other unified-memory machines, is Laptop / Budget.const uint64_t gpu = usableGpuMemoryMB(hw);- auto cap = [&](ProfileTier most, const char* reason) {- if (int(t) > int(most)) {- t = most;- why += std::string(", capped by ") + reason;+ std::string missing;+ if (hw.gpuKind != GpuKind::Discrete) missing = std::string("no discrete GPU (") + gpuKindName(hw.gpuKind) + ")";+ else if (gpu < kWorkstationVramMB) missing = formatMegabytes(gpu) + " of video memory";+ if (missing.empty() && hw.ramMB && hw.ramMB < kWorkstationRamMB) missing = formatMegabytes(hw.ramMB) + " RAM";+ if (missing.empty() && c.dabMs > 3.0) missing = "slow brushes";+ if (missing.empty() && c.memoryGBps > 0.0 && c.memoryGBps < 4.0) missing = "slow memory";+ if (missing.empty() && tri > 0.0 && tri < kWorkstationFromM) {+ if (previous && *previous == ProfileTier::Workstation && tri >= kWorkstationFromM / kStickyBand) {+ why += ", kept Workstation (close to the boundary)";+ return ProfileTier::Workstation;}- };- if (gpu && gpu < 3072) cap(ProfileTier::Laptop, "GPU memory");- else if (gpu && gpu < 10240) cap(ProfileTier::Workstation, "GPU memory");- if (hw.ramMB && hw.ramMB < 8 * 1024) cap(ProfileTier::Laptop, "system memory");- else if (hw.ramMB && hw.ramMB < 24 * 1024) cap(ProfileTier::Workstation, "system memory");- if (c.dabMs > 3.0) cap(ProfileTier::Laptop, "brush speed");- if (c.memoryGBps > 0.0 && c.memoryGBps < 4.0) cap(ProfileTier::Laptop, "memory bandwidth");- if (t != ProfileTier::Software && c.trianglesPerSecondM > 0.0 && c.trianglesPerSecondM < kSoftwareBelowM)- t = ProfileTier::Software;- return t;+ missing = "GPU throughput";+ }+ if (missing.empty() && previous && *previous == ProfileTier::Laptop && tri > 0.0 && tri < kWorkstationFromM * kStickyBand) {+ why += ", kept Laptop (close to the boundary)";+ return ProfileTier::Laptop;+ }+ if (missing.empty()) return ProfileTier::Workstation;+ why += ", Laptop / Budget: " + missing;+ return ProfileTier::Laptop;}} // namespace@@ -480,7 +487,8 @@ PerformanceSettings applyOverrides(const PerformanceSettings& a, const ProfileOvbool ProfileOverrides::any() const {return !tier.empty() || renderTriangleBudget || motionProxyThreshold || vramBudgetMB || uploadBudgetMBPerFrame ||- maxTextureSize || maxSubdivisionTriangles || microTriangleLimit || threads || targetFps || !governor;+ maxTextureSize || maxSubdivisionTriangles || microTriangleLimit || threads || targetFps || !governor ||+ draftBrush;}HardwareProfile mapProfile(const HardwareInfo& hardware, const Calibration& calibration, const ProfileOverrides& overrides,@@ -617,6 +625,7 @@ Json overridesJson(const ProfileOverrides& o) {if (o.threads) j.set("threads", o.threads);if (o.targetFps) j.set("target_fps", o.targetFps);if (!o.governor) j.set("governor", false);+ if (o.draftBrush) j.set("draft_brush", o.draftBrush == 1 ? "on" : "off");return j;}@@ -633,6 +642,7 @@ void overridesFromJson(const Json& j, ProfileOverrides& o) {o.threads = int(j["threads"].asNumber());o.targetFps = int(j["target_fps"].asNumber());o.governor = j["governor"].asBool(true);+ o.draftBrush = j["draft_brush"].asString() == "on" ? 1 : j["draft_brush"].asString() == "off" ? 2 : 0;}} // namespace@@ -728,7 +738,7 @@ bool needsRecalibration(const HardwareProfile* cached, const HardwareInfo& currereturn !recalibrationReason(cached, current).empty();}-Json calibrationJson(const HardwareProfile& p) {+Json calibrationJson(const HardwareProfile& p, const TierConfig* tier) {Json j = Json::object();j.set("schema", kCalibrationSchema);j.set("app_version", p.hardware.appVersion);@@ -739,6 +749,7 @@ Json calibrationJson(const HardwareProfile& p) {j.set("settings", settingsJson(p.settings));j.set("automatic", settingsJson(p.automatic));j.set("overrides", overridesJson(p.overrides));+ j.set("tier_config", tierConfigJson(tier ? *tier : tierConfigFor(p, PowerSource::Unknown, 0)));j.set("network", false); // calibration never uses the network (no telemetry)return j;}@@ -770,6 +781,7 @@ bool validateCalibrationJson(const Json& j, std::string& error) {need(j, "$", "automatic", T::Object);need(j, "$", "overrides", T::Object);need(j, "$", "network", T::Bool);+ need(j, "$", "tier_config", T::Object);if (!error.empty()) return false;ProfileTier tier;if (!tierFromName(j["profile"].asString(), tier)) {@@ -799,6 +811,12 @@ bool validateCalibrationJson(const Json& j, std::string& error) {if (error.empty() && s["render_triangle_budget"].asNumber() <= 0) error = std::string(which) + ".render_triangle_budget must be > 0";if (error.empty() && s["threads"].asNumber() < 1) error = std::string(which) + ".threads must be >= 1";}+ const Json& tc = j["tier_config"];+ need(tc, "tier_config", "tier", T::String);+ need(tc, "tier_config", "power", T::String);+ for (const char* k : {"resident_cache_cap_mb", "active_triangle_budget", "upload_budget_mb_per_frame", "target_hz"})+ need(tc, "tier_config", k, T::Number);+ for (const char* k : {"draft_brush_mode", "zero_copy_uma", "on_battery"}) need(tc, "tier_config", k, T::Bool);return error.empty();}@@ -950,7 +968,7 @@ bool setOverride(ProfileOverrides& o, const std::string& name, const std::stringif (clear) o.tier.clear();else if (tierFromName(text, t)) o.tier = tierName(t);else {- error = "tier must be Software, Laptop, Workstation, Monster or auto";+ error = "tier must be Software, Laptop (or Budget), Workstation or auto";return false;}} else if (name == "render_triangle_budget") o.renderTriangleBudget = u;@@ -962,7 +980,15 @@ bool setOverride(ProfileOverrides& o, const std::string& name, const std::stringelse if (name == "micro_triangle_limit") o.microTriangleLimit = u;else if (name == "threads") o.threads = int(u);else if (name == "target_fps") o.targetFps = int(u);- else if (name == "governor") o.governor = clear ? true : value != 0.0 || text == "on" || text == "true";+ else if (name == "draft_brush") {+ if (clear) o.draftBrush = 0;+ else if (text == "on" || text == "true" || value == 1.0) o.draftBrush = 1;+ else if (text == "off" || text == "false" || (text.empty() && value == 2.0)) o.draftBrush = 2;+ else {+ error = "draft_brush must be on, off or auto";+ return false;+ }+ } else if (name == "governor") o.governor = clear ? true : value != 0.0 || text == "on" || text == "true";else {error = "unknown setting " + name;return false;@@ -975,7 +1001,7 @@ bool setOverride(ProfileOverrides& o, const std::string& name, const std::stringvoid registerHardwareProfileCommands(CommandRegistry& registry) {registry.add({"performance_profile","The hardware profile as JSON (schema sculptforge.calibration/1): the GPU, its memory, RAM, CPU threads "- "and SIMD, what calibration measured, the tier (Software / Laptop / Workstation / Monster) and its "+ "and SIMD, what calibration measured, the tier (Software safe mode, Laptop / Budget, Workstation) and its ""settings (render triangle budget, motion proxy threshold, VRAM budget, ...). Nothing is sent anywhere.",{},[](Document&, const Args&) -> CommandResult {@@ -1032,10 +1058,10 @@ void registerHardwareProfileCommands(CommandRegistry& registry) {}});registry.add({"set_performance_override","Override one setting of the performance profile by hand (kept across re-calibrations), or give it "- "back to the profile with value=auto. Settings: tier (Software, Laptop, Workstation, Monster), "+ "back to the profile with value=auto. Settings: tier (Software, Laptop, Workstation), ""render_triangle_budget, motion_proxy_threshold, vram_budget_mb, upload_budget_mb_per_frame, ""max_texture_size, max_subdivision_triangles, micro_triangle_limit, threads (next start), target_fps, "- "governor (on / off).",+ "draft_brush (on / off: normals and cavity at pen release), governor (on / off).",{{"name", ParamSpec::Type::String, "The setting.", true},{"value", ParamSpec::Type::String, "A number, a tier name, on / off, or auto.", true}},[](Document&, const Args& a) -> CommandResult {diff --git a/src/core/HardwareProfile.h b/src/core/HardwareProfile.hindex f005deb7..7b3e746b 100644--- a/src/core/HardwareProfile.h+++ b/src/core/HardwareProfile.h@@ -5,7 +5,10 @@//// What the computer is (HardwareInfo: the GPU's OpenGL strings and memory, system RAM, CPU threads, SIMD, OS)// and how fast it measured (Calibration: triangle throughput, buffer upload bandwidth, brush dab cost, memory-// bandwidth) map to a profile tier (Software / Laptop / Workstation / Monster) with concrete settings+// bandwidth) map to a profile tier with concrete settings. Two main tiers: Laptop / Budget (8-16 GB RAM, a 2-4 GB+// GPU or Apple Silicon's unified memory, thermal and battery limits) and Workstation (64 GB+ RAM and a 16 GB++// discrete GPU that measures fast), plus a Software safe mode for llvmpipe and friends. core/TierConfig.h turns the+// profile, the power source and the display into the knobs the renderer and brushes read. Settings:// (PerformanceSettings: render triangle budget, motion proxy threshold, VRAM budget, ...). The mapping uses// the measurements and memory sizes, never GPU names: names only tell unified from discrete memory and spot a// software renderer (llvmpipe and friends).@@ -33,8 +36,9 @@ enum class GpuKind { Unknown, Discrete, Integrated, Unified, Software };const char* gpuKindName(GpuKind kind); // "discrete", "integrated", "unified", "software", "unknown"GpuKind gpuKindFromName(const std::string& name);-enum class ProfileTier { Software, Laptop, Workstation, Monster };-const char* tierName(ProfileTier tier); // "Software", "Laptop", "Workstation", "Monster"+enum class ProfileTier { Software, Laptop, Workstation };+const char* tierName(ProfileTier tier); // "Software", "Laptop", "Workstation"+// Also accepts "llvmpipe" / "safe" (Software), "budget" (Laptop) and "monster" (Workstation), in any case.bool tierFromName(const std::string& name, ProfileTier& out);// What the computer is. GPU fields stay empty / 0 where no OpenGL context was probed (sculptforge-cli).@@ -108,6 +112,7 @@ struct ProfileOverrides {int threads = 0;int targetFps = 0;bool governor = true; // the adaptive frame governor (off: the budgets stay as set)+ int draftBrush = 0; // TierConfig::draftBrushMode: 0 automatic, 1 always, 2 neverbool any() const;};@@ -150,7 +155,10 @@ std::string recalibrationReason(const HardwareProfile* cached, const HardwareInf// --- JSON output (sculptforge --calibrate, the calibrate / performance_profile commands) ---constexpr const char* kCalibrationSchema = "sculptforge.calibration/1";-Json calibrationJson(const HardwareProfile& profile);+// `tier`: the tier configuration to report (core/TierConfig.h); default: the profile's on an unknown power source+// and display.+struct TierConfig;+Json calibrationJson(const HardwareProfile& profile, const TierConfig* tier = nullptr);// Checks `j` has every field of kCalibrationSchema with the right types; `error` names the first problem.bool validateCalibrationJson(const Json& j, std::string& error);diff --git a/src/core/TierConfig.cpp b/src/core/TierConfig.cppnew file mode 100644index 00000000..71fe324f--- /dev/null+++ b/src/core/TierConfig.cpp@@ -0,0 +1,97 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+#include "core/TierConfig.h"++#include <algorithm>+#include <atomic>+#include <mutex>++namespace sf {++const char* powerSourceName(PowerSource power) {+ switch (power) {+ case PowerSource::AC: return "ac";+ case PowerSource::Battery: return "battery";+ case PowerSource::Unknown: break;+ }+ return "unknown";+}++int targetHzForDisplay(int hz) {+ if (hz >= 143) return 144;+ if (hz >= 119) return 120;+ return 60;+}++TierConfig tierConfigFor(const HardwareProfile& p, PowerSource power, int displayHz) {+ TierConfig c;+ c.tier = p.tier;+ c.power = power;+ const uint64_t ram = p.hardware.ramMB ? p.hardware.ramMB : 8192;+ const PerformanceSettings& s = p.settings;+ switch (p.tier) {+ case ProfileTier::Software:+ c.residentCacheCapMB = std::clamp<uint64_t>(ram / 8, 256, 1024);+ c.activeTriangleBudget = 500'000;+ break;+ case ProfileTier::Laptop:+ c.residentCacheCapMB = std::clamp<uint64_t>(ram / 4, 512, 4096);+ c.activeTriangleBudget = 2'000'000;+ break;+ case ProfileTier::Workstation:+ c.residentCacheCapMB = std::clamp<uint64_t>(ram * 2 / 5, 4096, 65536);+ c.activeTriangleBudget = std::clamp<uint64_t>(s.renderTriangleBudget / 2, 8'000'000, 64'000'000);+ break;+ }+ c.uploadBudgetMBPerFrame = std::max<uint64_t>(s.uploadBudgetMBPerFrame, 4);+ c.zeroCopyUMA = p.hardware.gpuKind == GpuKind::Unified || p.hardware.gpuKind == GpuKind::Integrated;+ c.draftBrushMode = p.tier != ProfileTier::Workstation;+ c.targetHz = p.overrides.targetFps ? p.overrides.targetFps : targetHzForDisplay(displayHz);+ if (p.tier == ProfileTier::Software) c.targetHz = std::min(c.targetHz, 60);+ if (c.onBattery()) {+ // On battery: less heat and power. Draft brushes, half the uploads, 60 Hz (unless set by hand).+ c.draftBrushMode = true;+ c.uploadBudgetMBPerFrame = std::max<uint64_t>(c.uploadBudgetMBPerFrame / 2, 4);+ if (!p.overrides.targetFps) c.targetHz = 60;+ }+ if (p.overrides.draftBrush == 1) c.draftBrushMode = true;+ else if (p.overrides.draftBrush == 2) c.draftBrushMode = false;+ return c;+}++Json tierConfigJson(const TierConfig& c) {+ Json j = Json::object();+ j.set("tier", tierName(c.tier));+ j.set("resident_cache_cap_mb", double(c.residentCacheCapMB));+ j.set("active_triangle_budget", double(c.activeTriangleBudget));+ j.set("upload_budget_mb_per_frame", double(c.uploadBudgetMBPerFrame));+ j.set("draft_brush_mode", c.draftBrushMode);+ j.set("zero_copy_uma", c.zeroCopyUMA);+ j.set("target_hz", c.targetHz);+ j.set("power", powerSourceName(c.power));+ j.set("on_battery", c.onBattery());+ return j;+}++namespace {+std::mutex g_mutex;+TierConfig g_config;+std::atomic<uint64_t> g_revision{0};+} // namespace++TierConfig currentTierConfig() {+ std::lock_guard<std::mutex> lock(g_mutex);+ return g_config;+}++void setCurrentTierConfig(const TierConfig& config) {+ {+ std::lock_guard<std::mutex> lock(g_mutex);+ g_config = config;+ }+ g_revision.fetch_add(1, std::memory_order_relaxed);+}++uint64_t tierConfigRevision() { return g_revision.load(std::memory_order_relaxed); }++} // namespace sfdiff --git a/src/core/TierConfig.h b/src/core/TierConfig.hnew file mode 100644index 00000000..d058f701--- /dev/null+++ b/src/core/TierConfig.h@@ -0,0 +1,55 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// The tier's knobs for the renderer, brushes and streaming code (feat/micromesh, feat/zero-latency read these):+// what the hardware profile (core/HardwareProfile.h) gives, adjusted for the power source (battery: draft brushes,+// smaller uploads, 60 Hz) and the display (target 60, 120 or 144 Hz).+//+// Software (safe) Laptop / Budget Workstation+// resident cache RAM / 8, <= 1 GB RAM / 4, <= 4 GB RAM * 2 / 5, <= 64 GB+// active triangles 0.5M 2M 8M+ (half the render budget, <= 64M)+// draft brushes yes yes no (yes on battery)+// zero-copy UMA the GPU shares system memory (Apple Silicon, Asahi, integrated GPUs)+// target Hz 60 display's (60 on battery) display's: 60 / 120 / 144+//+// Read it with currentTierConfig() (thread-safe, cheap) every frame or stroke; tierConfigRevision() changes+// whenever it does (a new profile, the power cable, another display). Nothing here changes the model's data.+#pragma once++#include "core/HardwareProfile.h"+#include "core/Json.h"++#include <cstdint>++namespace sf {++enum class PowerSource { Unknown, AC, Battery };+const char* powerSourceName(PowerSource power); // "unknown", "ac", "battery"++struct TierConfig {+ ProfileTier tier = ProfileTier::Laptop;+ uint64_t residentCacheCapMB = 2048; // most memory resident caches (micromesh pages, streamed levels) may hold+ uint64_t activeTriangleBudget = 2'000'000; // triangles a brush / micro-displacement may keep "active" (full+ // detail, updated live) at once; the rest waits or uses coarser levels+ uint64_t uploadBudgetMBPerFrame = 64; // vertex data to send to the GPU per frame before deferring the rest+ bool draftBrushMode = true; // defer normal and cavity recomputation to pen release (Laptop, battery);+ // false: continuous, every dab (Workstation)+ bool zeroCopyUMA = false; // the GPU shares system memory: uploads may write in place (persistent+ // mapped buffers) instead of staging copies+ int targetHz = 60; // 60, 120 or 144: what the display shows (60 on battery, Software)+ PowerSource power = PowerSource::Unknown;+ bool onBattery() const { return power == PowerSource::Battery; }+};++// 144 for displays of 143 Hz and up, 120 from 119 Hz, else 60 (also when unknown: 0).+int targetHzForDisplay(int displayHz);+// The knobs for `profile` on this power source and display (displayHz 0 = unknown). Deterministic.+TierConfig tierConfigFor(const HardwareProfile& profile, PowerSource power, int displayHz);+Json tierConfigJson(const TierConfig& config);++// The configuration in effect (the app sets it from the profile, the power source and the display).+TierConfig currentTierConfig();+void setCurrentTierConfig(const TierConfig& config);+uint64_t tierConfigRevision();++} // namespace sfdiff --git a/tests/test_hardware_profile.cpp b/tests/test_hardware_profile.cppindex 7a8c52bb..17d4a75f 100644--- a/tests/test_hardware_profile.cpp+++ b/tests/test_hardware_profile.cpp@@ -9,6 +9,7 @@#include "core/Commands.h"#include "core/FrameGovernor.h"#include "core/HardwareProfile.h"+#include "core/TierConfig.h"#include <cmath>#include <cstdlib>@@ -144,23 +145,29 @@ TEST(hw_profile_mapping) {CHECK(p.settings.renderTriangleBudget <= 4'000'000);CHECK(p.settings.maxTextureSize <= 4096);}- // A big discrete card on a big machine.+ // A 16 GB+ discrete card on a 64 GB machine that measures fast: Workstation.{const HardwareProfile p = mapProfile(machine("NVIDIA Corporation", "NVIDIA GeForce RTX 4090/PCIe/SSE2", 24564, 65536, 32),measured(15000.0, 25.0, 0.2, 40.0));- CHECK(p.tier == ProfileTier::Monster);+ CHECK(p.tier == ProfileTier::Workstation);CHECK(p.settings.renderTriangleBudget >= 100'000'000);CHECK(p.settings.vramBudgetMB == 24564 * 4 / 5);CHECK(p.settings.threads == 16); // the thread pool's limit- CHECK(p.reason.find("Monster") != std::string::npos);+ CHECK(p.reason.find("Workstation") != std::string::npos);CHECK(p.reason.find("RTX 4090") != std::string::npos);}- // A mid card: measured as a workstation, its 8 GB keep it there.+ // A fast card with 8 GB: Laptop / Budget, and the reason says why.{- const HardwareProfile p = mapProfile(machine("NVIDIA Corporation", "NVIDIA GeForce RTX 3070/PCIe/SSE2", 8192, 32768),+ const HardwareProfile p = mapProfile(machine("NVIDIA Corporation", "NVIDIA GeForce RTX 3070/PCIe/SSE2", 8192, 65536),measured(8000.0));- CHECK(p.tier == ProfileTier::Workstation);- CHECK(p.reason.find("capped by GPU memory") != std::string::npos);+ CHECK(p.tier == ProfileTier::Laptop);+ CHECK(p.reason.find("video memory") != std::string::npos);+ }+ // 16 GB of video memory but 32 GB of RAM: Laptop / Budget.+ {+ const HardwareProfile p = mapProfile(machine("AMD", "AMD Radeon RX 7800 XT", 16368, 32768), measured(6000.0));+ CHECK(p.tier == ProfileTier::Laptop);+ CHECK(p.reason.find("RAM") != std::string::npos);}// An integrated GPU on a 16 GB laptop.{@@ -175,12 +182,15 @@ TEST(hw_profile_mapping) {CHECK(p.tier == ProfileTier::Laptop);CHECK(p.settings.maxTextureSize <= 8192);}- // Unified memory: two thirds of the RAM for the GPU.+ // Unified memory (Apple Silicon): two thirds of the RAM for the GPU, even when the driver reports all of it;+ // Laptop / Budget however fast it measures.{- const HardwareProfile p = mapProfile(machine("Mesa", "Apple M1 Pro (G13S C0)", 0, 32768, 10), measured(2000.0));+ const HardwareProfile p = mapProfile(machine("Mesa", "Apple M1 Pro (G13S C0)", 31667, 31667, 10), measured(2000.0));CHECK(p.hardware.gpuKind == GpuKind::Unified);- CHECK(p.settings.vramBudgetMB == 32768 * 2 / 3);- CHECK(p.tier == ProfileTier::Workstation);+ CHECK(p.settings.vramBudgetMB == 31667 * 2 / 3);+ CHECK(p.tier == ProfileTier::Laptop);+ const HardwareProfile big = mapProfile(machine("Apple", "Apple M2 Ultra", 0, 196608, 24), measured(6000.0));+ CHECK(big.tier == ProfileTier::Laptop);}// Measurements decide, not names: an unknown GPU that measures like software is safe mode.CHECK(mapProfile(machine("Weird", "Mystery GPU", 4096, 16384), measured(20.0)).tier == ProfileTier::Software);@@ -188,19 +198,41 @@ TEST(hw_profile_mapping) {{const HardwareProfile a = mapProfile(machine("NVIDIA Corporation", "NVIDIA RTX A4000", 16384, 65536), measured(4000.0));const HardwareProfile b = mapProfile(machine("NVIDIA Corporation", "NVIDIA GeForce RTX 4070 Ti SUPER", 16384, 65536), measured(4000.0));+ CHECK(a.tier == ProfileTier::Workstation);CHECK(a.tier == b.tier);CHECK(sameSettings(a.settings, b.settings));}- // Nothing measured (skipped): a guess from memory sizes, never above Workstation.+ // Nothing measured (skipped): from the GPU type and memory sizes.{Calibration skipped;skipped.skipped = true;CHECK(mapProfile(machine("NVIDIA Corporation", "NVIDIA GeForce RTX 4090", 24564, 65536), skipped).tier == ProfileTier::Workstation);CHECK(mapProfile(machine("Intel", "Intel(R) UHD Graphics", 0, 8192), skipped).tier == ProfileTier::Laptop);}- // Slow brushes or memory cap the tier.+ // Slow brushes keep a big machine at Laptop / Budget.CHECK(mapProfile(machine("NVIDIA Corporation", "NVIDIA GeForce RTX 4090", 24564, 65536), measured(15000.0, 25.0, 5.0)).tier ==ProfileTier::Laptop);+ // A re-calibration of the same GPU holds its tier near the boundary (and only there).+ {+ const HardwareInfo h = machine("NVIDIA Corporation", "NVIDIA GeForce RTX 4080", 16384, 65536);+ const ProfileTier ws = ProfileTier::Workstation, laptop = ProfileTier::Laptop;+ CHECK(mapProfile(h, measured(950.0)).tier == ProfileTier::Laptop);+ CHECK(mapProfile(h, measured(950.0), {}, &ws).tier == ProfileTier::Workstation);+ CHECK(mapProfile(h, measured(950.0), {}, &ws).reason.find("close to the boundary") != std::string::npos);+ CHECK(mapProfile(h, measured(800.0), {}, &ws).tier == ProfileTier::Laptop);+ CHECK(mapProfile(h, measured(1050.0), {}, &laptop).tier == ProfileTier::Laptop);+ CHECK(mapProfile(h, measured(1200.0), {}, &laptop).tier == ProfileTier::Workstation);+ CHECK(mapProfile(h, measured(55.0), {}, &laptop).tier == ProfileTier::Laptop);+ CHECK(mapProfile(h, measured(40.0), {}, &laptop).tier == ProfileTier::Software);+ // The saved tier settles a reload the same way.+ const std::string path = tempPath("sf_hw_sticky.json");+ std::string error;+ CHECK(saveHardwareProfile(path, mapProfile(h, measured(950.0), {}, &ws), error));+ HardwareProfile back;+ CHECK(loadHardwareProfile(path, back) && back.tier == ProfileTier::Workstation);+ std::error_code ec;+ std::filesystem::remove(path, ec);+ }// Deterministic, and sane everywhere.for (double tri : {10.0, 100.0, 900.0, 1500.0, 4000.0, 6000.0, 30000.0}) {const HardwareInfo h = machine("NVIDIA Corporation", "NVIDIA GeForce RTX 4080", 16384, 65536);@@ -227,13 +259,14 @@ TEST(hw_profile_mapping) {}TEST(hw_profile_overrides) {- const HardwareInfo h = machine("NVIDIA Corporation", "NVIDIA GeForce RTX 3060", 12288, 32768);+ const HardwareInfo h = machine("NVIDIA Corporation", "NVIDIA GeForce RTX 4090", 24564, 131072);ProfileOverrides o;o.tier = "Laptop";o.renderTriangleBudget = 5'000'000;o.threads = 3;const HardwareProfile p = mapProfile(h, measured(3000.0), o);CHECK(p.tier == ProfileTier::Laptop);+ CHECK(p.measuredTier == ProfileTier::Workstation);CHECK(p.reason.find("by hand") != std::string::npos);CHECK(p.settings.renderTriangleBudget == 5'000'000);CHECK(p.settings.motionProxyThreshold == 5'000'000); // follows the budget@@ -243,7 +276,9 @@ TEST(hw_profile_overrides) {CHECK(!ProfileOverrides{}.any());// A tier name in any case, and the safe-mode alias.ProfileTier t;- CHECK(tierFromName("monster", t) && t == ProfileTier::Monster);+ CHECK(tierFromName("workstation", t) && t == ProfileTier::Workstation);+ CHECK(tierFromName("Budget", t) && t == ProfileTier::Laptop);+ CHECK(tierFromName("monster", t) && t == ProfileTier::Workstation);CHECK(tierFromName("llvmpipe", t) && t == ProfileTier::Software);CHECK(!tierFromName("fast", t));}@@ -332,7 +367,9 @@ TEST(hw_calibration_json_schema) {CHECK(Json::parse(j.dump(true), parsed, error));CHECK(validateCalibrationJson(parsed, error));CHECK(parsed["schema"].asString() == kCalibrationSchema);- CHECK(parsed["profile"].asString() == "Workstation");+ CHECK(parsed["profile"].asString() == "Laptop");+ CHECK(parsed["tier_config"]["zero_copy_uma"].asBool());+ CHECK(parsed["tier_config"]["draft_brush_mode"].asBool());CHECK(parsed["hardware"]["gpu_kind"].asString() == "unified");CHECK(parsed["settings"]["render_triangle_budget"].asNumber() > 0);CHECK(!parsed["network"].asBool());@@ -362,6 +399,13 @@ TEST(hw_calibration_json_schema) {CHECK(!validateCalibrationJson(bad, error));CHECK(error.find("dab_ms") != std::string::npos);}+ {+ Json bad = parsed;+ Json tc = parsed["tier_config"];+ tc.set("draft_brush_mode", 1.0);+ bad.set("tier_config", tc);+ CHECK(!validateCalibrationJson(bad, error));+ }{Json bad = parsed;bad.set("schema", "sculptforge.calibration/0");@@ -388,13 +432,19 @@ TEST(hw_profile_commands) {CHECK(r.ok);CHECK(currentPerformanceSettings().renderTriangleBudget == 12'000'000);CHECK(renderTriangleBudget() == 12'000'000);- r = registry.execute(doc, "set_performance_override", {{"name", std::string("tier")}, {"value", std::string("Monster")}});+ r = registry.execute(doc, "set_performance_override", {{"name", std::string("tier")}, {"value", std::string("Workstation")}});CHECK(r.ok);r = registry.execute(doc, "performance_profile");CHECK(Json::parse(r.message, j, error));- CHECK(j["profile"].asString() == "Monster");+ CHECK(j["profile"].asString() == "Workstation");CHECK(j["settings"]["render_triangle_budget"].asNumber() == 12'000'000);- CHECK(j["overrides"]["tier"].asString() == "Monster");+ CHECK(j["overrides"]["tier"].asString() == "Workstation");+ r = registry.execute(doc, "set_performance_override", {{"name", std::string("draft_brush")}, {"value", std::string("off")}});+ CHECK(r.ok);+ r = registry.execute(doc, "performance_profile");+ CHECK(Json::parse(r.message, j, error));+ CHECK(j["overrides"]["draft_brush"].asString() == "off");+ CHECK(!j["tier_config"]["draft_brush_mode"].asBool());r = registry.execute(doc, "set_performance_override", {{"name", std::string("tier")}, {"value", std::string("auto")}});CHECK(r.ok);r = registry.execute(doc, "set_performance_override", {{"name", std::string("warp_drive")}, {"value", std::string("1")}});@@ -614,3 +664,59 @@ TEST(governor_target_120) {g60.setTargetFps(120);CHECK(std::abs(g60.targetMs() - 1000.0 / 120.0) < 1e-9);}++TEST(hw_tier_config) {+ // Laptop / Budget: 2M active triangles, draft brushes, a quarter of the RAM for caches.+ const HardwareProfile laptop = mapProfile(machine("Intel", "Mesa Intel(R) Xe Graphics (TGL GT2)", 0, 16384, 8), measured(400.0, 4.0));+ TierConfig c = tierConfigFor(laptop, PowerSource::AC, 60);+ CHECK(c.tier == ProfileTier::Laptop);+ CHECK(c.activeTriangleBudget == 2'000'000);+ CHECK(c.draftBrushMode);+ CHECK(c.residentCacheCapMB == 4096);+ CHECK(c.zeroCopyUMA); // an integrated GPU shares the memory+ CHECK(c.targetHz == 60);+ // Workstation: 8M+ active, continuous brushes, the display's rate.+ const HardwareProfile ws = mapProfile(machine("NVIDIA Corporation", "NVIDIA GeForce RTX 4090", 24564, 131072, 32), measured(15000.0, 25.0));+ c = tierConfigFor(ws, PowerSource::AC, 144);+ CHECK(c.tier == ProfileTier::Workstation);+ CHECK(c.activeTriangleBudget >= 8'000'000);+ CHECK(!c.draftBrushMode);+ CHECK(!c.zeroCopyUMA);+ CHECK(c.targetHz == 144);+ CHECK(tierConfigFor(ws, PowerSource::AC, 120).targetHz == 120);+ CHECK(tierConfigFor(ws, PowerSource::AC, 165).targetHz == 144);+ CHECK(tierConfigFor(ws, PowerSource::AC, 0).targetHz == 60);+ CHECK(tierConfigFor(ws, PowerSource::Unknown, 59).targetHz == 60);+ // On battery: draft brushes, half the uploads, 60 Hz.+ const TierConfig b = tierConfigFor(ws, PowerSource::Battery, 144);+ CHECK(b.onBattery());+ CHECK(b.draftBrushMode);+ CHECK(b.targetHz == 60);+ CHECK(b.uploadBudgetMBPerFrame == std::max<uint64_t>(c.uploadBudgetMBPerFrame / 2, 4));+ // Overrides win: draft never, a fixed target.+ ProfileOverrides o;+ o.draftBrush = 2;+ o.targetFps = 120;+ const TierConfig forced = tierConfigFor(mapProfile(ws.hardware, ws.calibration, o), PowerSource::Battery, 60);+ CHECK(!forced.draftBrushMode);+ CHECK(forced.targetHz == 120);+ // Apple Silicon: unified memory, zero-copy.+ const HardwareProfile mac = mapProfile(machine("Apple", "Apple M3 Max", 0, 65536, 16), measured(3000.0));+ CHECK(tierConfigFor(mac, PowerSource::AC, 120).zeroCopyUMA);+ CHECK(tierConfigFor(mac, PowerSource::AC, 120).targetHz == 120);+ // Software: safe mode at 60 Hz at most.+ const HardwareProfile sw = mapProfile(machine("Mesa", "llvmpipe (LLVM 19.1.0, 256 bits)", 0, 16384), measured(40.0));+ CHECK(tierConfigFor(sw, PowerSource::AC, 144).targetHz == 60);+ CHECK(tierConfigFor(sw, PowerSource::AC, 144).activeTriangleBudget <= 500'000);+ // The process-wide copy.+ const uint64_t rev = tierConfigRevision();+ setCurrentTierConfig(b);+ CHECK(tierConfigRevision() == rev + 1);+ CHECK(currentTierConfig().onBattery());+ setCurrentTierConfig(TierConfig{});+ // JSON.+ const Json j = tierConfigJson(b);+ CHECK(j["power"].asString() == "battery");+ CHECK(j["on_battery"].asBool());+ CHECK(j["target_hz"].asNumber() == 60);+}