Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
6e7ff6e
Remove fixed size caps and make undo, caches and resources follow the…
vangel76 Dec 3, 2026
aaecd8c
Share one memory-aware cache ledger, stride line blurs, check set all…
vangel76 Dec 3, 2026
09cd9e4
Count Max RAM for file work's share of the system's memory without ro…
vangel76 Dec 3, 2026
4a428dd
Merge remote-tracking branch 'upstream/main' into tc-404-limits
vangel76 Dec 3, 2026
d7b76cb
Keep mesh references in the mesh's folder, refuse files that change w…
vangel76 Dec 3, 2026
63c9b62
Keep set caches until every new one is built, count MaterialX images …
vangel76 Dec 3, 2026
2b06887
Keep the browser build free of an unused import
vangel76 Dec 3, 2026
7dd959b
Bound far bake strokes, reads and decodes by what is left, and refres…
vangel76 Dec 3, 2026
03d68f5
Keep evicted cache bytes counted until freed, evict a lone oversized …
vangel76 Dec 3, 2026
c5ff353
Keep the browser preset library loading, give back unread MaterialX m…
vangel76 Dec 3, 2026
65c7d8e
Merge remote-tracking branch 'upstream/main' into tc-404-limits
vangel76 Dec 3, 2026
0add1aa
Merge remote-tracking branch 'upstream/main' into tc-404-limits
vangel76 Dec 4, 2026
4044400
Count cooks closing the app, the gray paint map, protocol imports, ZI…
vangel76 Dec 4, 2026
8189748
Remove the CPU path tracer's 8192 clamp and the 64 KiB template limit…
vangel76 Dec 4, 2026
e944dbc
Merge remote-tracking branch 'upstream/main' into tc-404-limits
vangel76 Dec 4, 2026
4cae7c0
Bound glTF reference reads before they are read, count the decoder's …
vangel76 Dec 4, 2026
4db8b18
Auto: Integrate main and fix file-work and render lifetimes
chasse20 Dec 4, 2026
f264d97
Auto: Fix extreme bake strokes and integrate main
chasse20 Dec 4, 2026
d1c1ead
Auto: Restrict the atomic batch-write test helper to Unix
chasse20 Dec 4, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

139 changes: 139 additions & 0 deletions apps/texturecraft-cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ use clap::{Args, FromArgMatches, Parser, Subcommand};
use serde_json::Value;
use texturecraft_automation::agents::WhenAppClosed;

#[path = "args/cache_cap.rs"]
mod cache_cap;

use cache_cap::CacheCap;

/// The end of `--help` of every command.
const EXIT_STATUS: &str = "Exit status:\n 0 success\n 1 a command failed\n 2 usage error\n\nA process ended by a signal exits 128 + the signal number (130 for Ctrl-C), as in the shell.";

Expand All @@ -21,6 +26,95 @@ const INPUTS: &str = "An <INPUT> is a .tcraft project, a mesh file (.glb .gltf .
pub(crate) struct Cli {
#[command(subcommand)]
pub(crate) command: Command,
#[command(flatten)]
pub(crate) prefs: PrefsArgs,
}

/// The desktop app's settings every command works with: read from its saved settings, unless
/// --no-prefs, then each flag given wins
#[derive(Args, Debug, Default)]
pub(crate) struct PrefsArgs {
/// Ignore the desktop app's saved settings and start from the defaults
#[arg(long, global = true)]
pub(crate) no_prefs: bool,
/// Folder of brushes, project templates and export templates (Settings > Files > Data folder)
#[arg(long, global = true, value_name = "DIR", value_parser = data_folder)]
pub(crate) data_folder: Option<String>,
/// Worker threads (0: one per logical CPU)
#[arg(long, global = true, value_name = "N")]
pub(crate) threads: Option<u32>,
/// Cores saving, export, import and bakes leave free
#[arg(long, global = true, value_name = "N")]
pub(crate) reserved_cores: Option<u32>,
/// Share of free RAM saving, export and import may use, in percent
#[arg(long, global = true, value_name = "PERCENT", value_parser = clap::value_parser!(u8).range(0..=100))]
pub(crate) ram_percent: Option<u8>,
/// Largest decompressed project accepted on open, in GiB
#[arg(long, global = true, value_name = "GIB", value_parser = clap::value_parser!(u32).range(1..))]
pub(crate) open_limit_gib: Option<u32>,
/// A cap on the rebuildable caches in MiB, or `auto` to keep them while memory is free
#[arg(long, global = true, value_name = "MIB|auto", value_parser = cache_cap)]
pub(crate) cache_budget_mib: Option<CacheCap>,
/// Undo steps kept (0: every step)
#[arg(long, global = true, value_name = "N")]
pub(crate) undo_steps: Option<u32>,
/// Cast bake rays on the GPU when one is available
#[arg(long, global = true, value_name = "BOOL")]
pub(crate) gpu_raytracing: Option<bool>,
}

/// `--cache-budget-mib`: `auto` or a cap in MiB
fn cache_cap(text: &str) -> Result<CacheCap, String> {
if text.trim().eq_ignore_ascii_case("auto") {
return Ok(CacheCap(None));
}

text.trim().parse::<u32>().map(|mib| CacheCap(Some(mib))).map_err(|_| format!("expected a number of MiB or auto, not {text}"))
}

/// `--data-folder`: the folder as an absolute path, a relative one taken from the working directory
fn data_folder(text: &str) -> Result<String, String> {
// Empty keeps the default folder, as an empty saved setting does
if text.trim().is_empty() {
return Ok(text.to_owned());
}
if std::path::Path::new(text).is_absolute() {
return absolute_folder_in(std::path::Path::new(""), text);
}

let cwd = std::env::current_dir().map_err(|e| format!("cannot read the working directory for {text}: {e}"))?;
absolute_folder_in(&cwd, text)
}

/// `folder` made absolute against `cwd`; an absolute form that is not Unicode is refused rather than
/// kept relative, which the saved settings would not accept and replace with the default folder
fn absolute_folder_in(cwd: &std::path::Path, folder: &str) -> Result<String, String> {
let path = std::path::absolute(cwd.join(folder)).map_err(|e| format!("cannot make {folder} absolute: {e}"))?;
path.into_os_string().into_string().map_err(|path| format!("the folder {} is not valid Unicode from the working directory", path.to_string_lossy()))
}

impl PrefsArgs {
/// The saved settings (or the defaults with --no-prefs) with the flags applied
pub(crate) fn prefs(&self) -> texturecraft_automation::DesktopPrefs {
let saved = if self.no_prefs { texturecraft_automation::DesktopPrefs::default() } else { texturecraft_automation::DesktopPrefs::load() };
self.apply_to(saved)
}

/// `prefs` with each given flag applied
fn apply_to(&self, mut prefs: texturecraft_automation::DesktopPrefs) -> texturecraft_automation::DesktopPrefs {
// Already absolute: `data_folder` resolved it from the working directory
if let Some(folder) = &self.data_folder {
prefs.data_folder = folder.clone();
}
prefs.work_threads = self.threads.unwrap_or(prefs.work_threads);
prefs.reserved_cores = self.reserved_cores.unwrap_or(prefs.reserved_cores);
prefs.save_ram_percent = self.ram_percent.unwrap_or(prefs.save_ram_percent);
prefs.project_open_limit_gib = self.open_limit_gib.unwrap_or(prefs.project_open_limit_gib);
prefs.cache_budget_mib = self.cache_budget_mib.map_or(prefs.cache_budget_mib, |cap| cap.0);
prefs.undo_history_steps = self.undo_steps.unwrap_or(prefs.undo_history_steps);
prefs.gpu_raytracing = self.gpu_raytracing.unwrap_or(prefs.gpu_raytracing);
prefs
}
}

#[derive(Subcommand, Debug)]
Expand Down Expand Up @@ -460,3 +554,48 @@ pub(crate) fn parse(args: &[OsString], window: &dyn Fn() -> bool) -> Result<Cli,
cli.command.check(window).map_err(|(sub, e)| e.into_clap(sub))?;
Ok(cli)
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn flags_win_over_the_saved_settings_and_no_prefs_starts_from_the_defaults() {
let folder = std::env::temp_dir().join("studio-data");
let args = [OsString::from("--no-prefs"), "--undo-steps".into(), "0".into(), "--data-folder".into(), folder.clone().into(), "commands".into()];

let prefs = parse(&args, &|| false).unwrap().prefs.prefs();

assert_eq!((prefs.undo_history_steps, prefs.data_folder.as_str()), (0, folder.to_str().unwrap()));
assert_eq!(prefs.save_ram_percent, texturecraft_automation::DesktopPrefs::default().save_ram_percent);
}

#[test]
fn a_flag_replaces_a_saved_value_and_a_missing_flag_keeps_it() {
const SAVED_CACHE_MIB: u32 = 512;
let saved = texturecraft_automation::DesktopPrefs { cache_budget_mib: Some(SAVED_CACHE_MIB), ..Default::default() };
let flags = |args: &[&str]| parse(&args.iter().map(OsString::from).collect::<Vec<_>>(), &|| false).unwrap().prefs;

assert_eq!(flags(&["--cache-budget-mib", "auto", "commands"]).apply_to(saved.clone()).cache_budget_mib, None);
assert_eq!(flags(&["commands"]).apply_to(saved).cache_budget_mib, Some(SAVED_CACHE_MIB));
}

#[cfg(unix)]
#[test]
fn a_data_folder_that_is_not_unicode_is_refused_not_renamed() {
use std::os::unix::ffi::OsStringExt as _;
let args = [OsString::from("--data-folder"), OsString::from_vec(b"/data-\xff".to_vec()), "commands".into()];

assert!(parse(&args, &|| false).is_err(), "a lossy copy would name another folder");
}

#[cfg(unix)]
#[test]
fn a_relative_data_folder_under_a_working_directory_that_is_not_unicode_is_refused() {
use std::os::unix::ffi::OsStringExt as _;
let cwd = std::path::PathBuf::from(OsString::from_vec(b"/work-\xff".to_vec()));

assert!(absolute_folder_in(&cwd, "studio").is_err(), "keeping it relative would fall back to the default folder");
assert_eq!(absolute_folder_in(std::path::Path::new("/work"), "studio").unwrap(), "/work/studio");
}
}
3 changes: 3 additions & 0 deletions apps/texturecraft-cli/src/args/cache_cap.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// `--cache-budget-mib`: a cap on the rebuildable caches in MiB, or None for Auto
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) struct CacheCap(pub(crate) Option<u32>);
Loading
Loading