Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
422f8e9
GPU memory: device limits and a memory budget instead of fixed GPU by…
vangel76 Dec 3, 2026
3e81d49
GPU memory: keep pipelines on retry, count capture inputs, budget in …
vangel76 Dec 3, 2026
04381ef
Test the micro map's metadata row against the device's texture size
vangel76 Dec 3, 2026
6ca186a
GPU memory: no fixed size in Auto, cached inputs grow until the GPU r…
vangel76 Dec 3, 2026
db265c3
Headless renders composite on the GPU; aux textures follow the displa…
vangel76 Dec 3, 2026
73608c5
Paint visibility depth on the GPU through an engine depth device, wit…
vangel76 Dec 3, 2026
00f36c8
Review: bounded CPU overlays at the renderer's set shift, mask previe…
vangel76 Dec 3, 2026
a7ef4b4
Fix the GPU depth readback and pass device and queue together
vangel76 Dec 3, 2026
6758d9d
Headless renders composite on the CPU on software and GL adapters, as…
vangel76 Dec 3, 2026
dc8706d
Aux views on the GPU at each set's display size; GPU errors are shown…
vangel76 Dec 3, 2026
78a7d01
Review: aux sources wrap into texture layers, quick mask memory retry…
vangel76 Dec 3, 2026
c3aa272
GPU brush readback and path tracing errors are shown, not redone on t…
vangel76 Dec 3, 2026
c1c9093
GPU paint uploads hold what the device binds, not a fixed 64 MB
vangel76 Dec 3, 2026
ffd423a
Projector depth grids rasterize on the GPU at full resolution
vangel76 Dec 3, 2026
ebf4bbc
Review: update windows keep their working size, depth raster ties sca…
vangel76 Dec 3, 2026
a6aba5b
The projector depth test readback returns its errors
vangel76 Dec 3, 2026
7e125b2
GPU brush start errors fail the stroke; only refusals paint on the CPU
vangel76 Dec 3, 2026
32a5845
Shelf filter and orb material previews composite on the GPU
vangel76 Dec 3, 2026
ccc28c9
Review: every library filter preview checked on the GPU, display map …
vangel76 Dec 3, 2026
7b3ac11
Paint upload windows follow the device; CPU projector depth keeps the…
vangel76 Dec 3, 2026
03ee492
Layer thumbnails composite on the GPU at a reduced size with their co…
vangel76 Dec 3, 2026
758e892
Review: neutral fills show in flat thumbnails, thumbnail errors repor…
vangel76 Dec 3, 2026
64dc6da
The material overview composites on the GPU off the UI thread; previe…
vangel76 Dec 4, 2026
dfb1f72
The GPU memory retry halves the paint window instead of asking for th…
vangel76 Dec 4, 2026
9213cb1
Library alphas generate on the GPU at the texture set's size
vangel76 Dec 4, 2026
8a2e5fa
Review: library tips sized by the brush and generated in bands, faile…
vangel76 Dec 4, 2026
1cae914
Merge upstream/main (shared-UV painting #869) into tc-404-gpu
vangel76 Dec 4, 2026
0f0a2ae
Shared-UV meshes paint on the GPU brush: every surface of a texel is …
vangel76 Dec 4, 2026
71af07c
GPU strokes leave the library alpha to the device instead of renderin…
vangel76 Dec 4, 2026
fc1ffa9
Resize repaints recorded strokes through the GPU brush; a GPU error f…
vangel76 Dec 4, 2026
149ade8
Review: CPU tip after a mid-stroke switch, resize replay on the GPU b…
vangel76 Dec 4, 2026
02af0c0
Keep the resize brush device out of web builds
vangel76 Dec 4, 2026
4d239a7
Mask stencils paint on the GPU brush: the stencil's stored gray times…
vangel76 Dec 4, 2026
122df11
Clone strokes paint on the GPU brush: dabs weighed by the source, car…
vangel76 Dec 4, 2026
4860e7d
Brush material strokes paint their alpha on the GPU brush; the patter…
vangel76 Dec 4, 2026
bac31db
Review: clone values filled per tile and channel, clone test strokes …
vangel76 Dec 4, 2026
50a11bc
The brush material pickup test expects the GPU brush
vangel76 Dec 4, 2026
36bfff1
Smudge strokes paint on the GPU brush: one pass per stamp, carried va…
vangel76 Dec 4, 2026
988f040
Review: a split smudge stamp deposits every chunk before copying back…
vangel76 Dec 4, 2026
b3a2900
Smudge sources composite on the GPU: the compositor writes the brush'…
vangel76 Dec 4, 2026
dbd959a
Review: only a source refusal composites the smudge source on the CPU…
vangel76 Dec 4, 2026
36e75e6
Mask smudge strokes paint on the GPU brush; a stamp centered on a tex…
vangel76 Dec 4, 2026
5aac1f0
Clone sources composite on the GPU: the brush reads the composite, a …
vangel76 Dec 4, 2026
c1eceda
Review: the clone readback is tested on packed scalars and at the set…
vangel76 Dec 4, 2026
bd60787
Clone and smudge strokes show live from the device's textures: no rea…
vangel76 Dec 4, 2026
2a8ef25
A brush material's source composites under its own cache key, so a pa…
vangel76 Dec 4, 2026
de63462
A GPU oracle for tied smudge centers on a mesh whose surfaces share UVs
vangel76 Dec 4, 2026
5356b64
Pickup source names cover clones as well as smudges
vangel76 Dec 4, 2026
b9d9bd4
Review: the readback at the stroke's end is chunked as the alpha read…
vangel76 Dec 4, 2026
87132a7
GPU-composited sets show the material overview on cold start; a dropp…
vangel76 Dec 4, 2026
1a454d9
A reduced composite without padding or filter fields uploads only the…
vangel76 Dec 4, 2026
8bf8c43
The overview test lets the composite replace the overview; the sample…
vangel76 Dec 4, 2026
bd61a18
Picking the clone or smudge tool compiles the live stroke's brush var…
vangel76 Dec 4, 2026
2221154
A preview GPU error is logged once per distinct error; the preview an…
vangel76 Dec 4, 2026
1317955
Review: remembered pipeline variants are forgotten with replaced sets…
vangel76 Dec 4, 2026
507f906
Sets whose UV or baked inputs exceed the device composite on the GPU …
vangel76 Dec 4, 2026
824c29b
Review: banded inputs hold one row more for bilinear and slope reads;…
vangel76 Dec 4, 2026
25e728b
Merge upstream/main (#846 smudge reads its layer, #939, #520, #406, #…
vangel76 Dec 4, 2026
fc928b4
Review: CPU routes for per-channel pickups are logged, a refused sour…
vangel76 Dec 4, 2026
32af9a3
Web builds: the immediate compose and the preview device setter are n…
vangel76 Dec 4, 2026
620c40f
Review round 3: memory accounting, error scopes and caches follow dev…
vangel76 Dec 4, 2026
de4ea38
A 3D path with points hidden from the camera paints on the GPU brush:…
vangel76 Dec 4, 2026
59dd4f1
Own-paint smudge and layer clones with per-channel coverage paint on …
vangel76 Dec 4, 2026
0d51777
A live smudge of a layer's own paint shows each channel by its own al…
vangel76 Dec 4, 2026
cf933ab
Smudge resolve binds the smudge uniform; the clone offset keeps the R…
vangel76 Dec 4, 2026
816ad0f
The hidden-point path oracle picks its points before turning the camera
vangel76 Dec 4, 2026
cdf9a1d
The live pickup oracle has a second channel whose own alpha stays bel…
vangel76 Dec 4, 2026
e1a9e52
fmt
vangel76 Dec 4, 2026
da3302b
Clippy: the per-channel source has a type name
vangel76 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.

3 changes: 3 additions & 0 deletions apps/texturecraft/src/gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ pub fn configure(options: &mut NativeOptions, cli_gpu: Option<String>, cli_power

if let WgpuSetup::CreateNew(create) = &mut options.wgpu_options.wgpu_setup {
create.power_preference = effective_power;

// Allocations past the system's GPU memory budget fail cleanly, so the compositor frees its caches and retries
create.instance_descriptor.memory_budget_thresholds = texturecraft_ui_egui::gpu_memory::instance_thresholds();
let device_descriptor = create.device_descriptor.clone();
create.device_descriptor = Arc::new(move |adapter| {
let mut descriptor = device_descriptor(adapter);
Expand Down
1 change: 1 addition & 0 deletions crates/automation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ rustix = { workspace = true }
[dev-dependencies]
tempfile = "3"
rmcp = { workspace = true, features = ["client"] }
texturecraft-render = { workspace = true, features = ["test-support"] }
4 changes: 2 additions & 2 deletions crates/automation/src/headless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,8 @@ impl Headless {
let session = &mut self.session;
let out = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| gpu.render(session, kind, size, camera)));
let (w, h, rgba) = match out {
Ok(Some(px)) => px,
Ok(None) => return Err(AutomationError::Other("the GPU returned no image".into())),
Ok(Ok(px)) => px,
Ok(Err(error)) => return Err(AutomationError::Other(format!("cannot render: {error}"))),
Err(_) => {
self.gpu = None;
return Err(AutomationError::Other("the GPU renderer failed".into()));
Expand Down
376 changes: 347 additions & 29 deletions crates/automation/src/render.rs

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions crates/automation/src/render/refused.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// Why the GPU did not composite a set
pub(super) enum Refused {
/// The set composites on the CPU (its layout or layer stack)
Cpu,
/// The GPU reported an error
Device(String),
}

impl Refused {
pub(super) fn of(error: String) -> Refused {
if texturecraft_render::gpu_memory::is_device_error(&error) { Refused::Device(error) } else { Refused::Cpu }
}
}
2 changes: 1 addition & 1 deletion crates/compose/src/fill_depth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl FillDepth {
return ProjectorDepth::build(view, mesh).map(Self::Single);
};

// Share one grid's storage and raster budget across the copy views
// Share one grid's storage across the copy views
let maps: Box<_> = ProjectorDepth::build_copies(view, mesh, &symmetry, center, radius).into_boxed_slice();

maps.iter().any(Option::is_some).then_some(Self::Copies(maps))
Expand Down
2 changes: 1 addition & 1 deletion crates/compose/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,5 +101,5 @@ pub mod distance_test_hooks {
pub use crate::distance_envelope::DistanceEnvelope;
pub use crate::shape_distance::{edge_distances, trail_distances};
}
pub use thumb::{THUMB_TEXELS, ThumbImage, ThumbTarget};
pub use thumb::{THUMB_TEXELS, ThumbImage, ThumbOutput, ThumbPlan, ThumbTarget};
pub use tile_pattern::{TileLayout, prepare_tile_layout};
109 changes: 45 additions & 64 deletions crates/compose/src/projector_depth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,16 @@ pub struct ProjectorDepth {
}

/// The smallest grid cell across and up, so a flat view still divides
const MIN_CELL_SIZE: f32 = 1e-6;
pub const MIN_CELL_SIZE: f32 = 1e-6;

/// A cell centre this close outside a triangle's edge (as a share of its area) still counts as inside, so shared edges leave no gaps
const EDGE_TOLERANCE: f32 = 1e-6;
pub const EDGE_TOLERANCE: f32 = 1e-6;

mod depth_grid;
mod grid_setup;

pub use depth_grid::DepthGrid;
pub use grid_setup::GridSetup;

impl ProjectorDepth {
/// The grid as `cover` reads it.
Expand All @@ -54,13 +56,19 @@ impl ProjectorDepth {
}

/// The depth maps of a fill's symmetry copies (one per copy, None where a copy sees nothing),
/// sharing one grid's storage and raster budget as the CPU evaluator does.
/// sharing one grid's storage as the CPU evaluator does.
pub fn build_copies(view: ProjectorView, mesh: &Mesh, symmetry: &FillSymmetry, center: Vec3, radius: f32) -> Vec<Option<ProjectorDepth>> {
let copies = FillCopies::new(symmetry, center, center, radius);
let count = symmetry.copies() as usize;
let grid_side = (GRID_SIDE * GRID_SIDE / count).isqrt();
let cell_budget = CELL_BUDGET / count;
(0..count).map(|index| Self::build_for_copy(view, mesh, Some(copies.copy(index as u32)), grid_side, cell_budget)).collect()
let grid_side = copy_grid_side(count);
(0..count).map(|index| Self::build_for_copy(view, mesh, Some(copies.copy(index as u32)), grid_side)).collect()
}

/// What [`Self::build_copies`] rasterizes per copy, at its grid side
pub fn copy_setups(view: ProjectorView, mesh: &Mesh, symmetry: &FillSymmetry, center: Vec3, radius: f32) -> Vec<Option<GridSetup>> {
let copies = FillCopies::new(symmetry, center, center, radius);
let count = symmetry.copies() as usize;
(0..count).map(|index| GridSetup::new(view, mesh, Some(copies.copy(index as u32)), copy_grid_side(count))).collect()
}

/// Build the depth map of a borrowed mesh, if the projection uses depth culling.
Expand All @@ -69,54 +77,35 @@ impl ProjectorDepth {
Self::build(view, mesh).map(Arc::new)
}

/// Rasterize the mesh in this view, using a coarser grid when the cell budget requires one.
/// Rasterize the mesh in this view on the full grid.
pub fn build(view: ProjectorView, mesh: &Mesh) -> Option<ProjectorDepth> {
Self::build_for_copy(view, mesh, None, GRID_SIDE, CELL_BUDGET)
Self::build_for_copy(view, mesh, None, GRID_SIDE)
}

/// [`Self::build`] for one copy of a fill (`copy` places the mesh), on a grid of at most `grid_side` cells across within `cell_budget` cell visits.
pub fn build_for_copy(view: ProjectorView, mesh: &Mesh, copy: Option<FillCopy>, mut grid_side: usize, cell_budget: usize) -> Option<Self> {
let projected: Vec<_> = mesh.positions.iter().map(|&point| view.local(copy.map_or(point, |copy| copy.point(point)))).collect();
let (min, max) = projected
.iter()
.flatten()
.fold((Vec2::splat(f32::MAX), Vec2::splat(f32::MIN)), |(lo, hi), view_point| (lo.min(view_point.truncate()), hi.max(view_point.truncate())));
if min.x > max.x || min.y > max.y {
/// [`Self::build`] for one copy of a fill (`copy` places the mesh), on a grid of `grid_side` cells across.
pub fn build_for_copy(view: ProjectorView, mesh: &Mesh, copy: Option<FillCopy>, grid_side: usize) -> Option<Self> {
if grid_side == 0 {
return None;
}

// The one-cell fallback can always afford one visit per triangle
let cell_budget = cell_budget.max(mesh.triangle_count());
let nearness_unit = view.unit();
while grid_side > 0 {
let cell = ((max - min) / grid_side as f32).max(Vec2::splat(MIN_CELL_SIZE));
let front = vec![[f32::NEG_INFINITY, 0.0, 0.0]; grid_side * grid_side];
let mut depth = ProjectorDepth { view, origin: min, grid_side, cell, nearness_unit, front };
let mut remaining = cell_budget;
let mut triangles = mesh.indices.as_chunks::<3>().0.iter().filter_map(|indices| {
let [a, b, c] = indices.map(|index| projected.get(index as usize).copied().flatten());
Some([a?, b?, c?])
});

if triangles.all(|triangle| depth.raster(triangle, &mut remaining)) {
return Some(depth);
}

// Discard any partial grid before retrying the whole mesh
grid_side /= 2;
let setup = GridSetup::new(view, mesh, copy, grid_side)?;
let front = vec![[f32::NEG_INFINITY, 0.0, 0.0]; grid_side * grid_side];
let mut depth = ProjectorDepth { view, origin: setup.origin, grid_side, cell: setup.cell, nearness_unit: setup.nearness_unit, front };
for triangle in setup.triangles(mesh) {
depth.raster(triangle);
}

None
Some(depth)
}

/// Keep `triangle` where it is nearer than what a cell holds; false once the cell budget runs out
fn raster(&mut self, triangle: [Vec3; 3], budget: &mut usize) -> bool {
/// Keep `triangle` where it is nearer than what a cell holds
fn raster(&mut self, triangle: [Vec3; 3]) {
let [a, b, c] = triangle;
let (edge_ab, edge_ac) = (b - a, c - a);
let determinant = edge_ab.x * edge_ac.y - edge_ab.y * edge_ac.x;
if !determinant.is_finite() || determinant.abs() < MIN_SCREEN_AREA {
// An edge-on triangle covers no cells
return true;
return;
}

let slope = Vec2::new((edge_ab.z * edge_ac.y - edge_ac.z * edge_ab.y) / determinant, (edge_ab.x * edge_ac.z - edge_ac.x * edge_ab.z) / determinant)
Expand All @@ -128,9 +117,6 @@ impl ProjectorDepth {
let first_cell = |position: f32| (position - 0.5).ceil().clamp(0.0, self.grid_side as f32) as usize;
let end_cell = |position: f32| ((position - 0.5).floor() + 1.0).clamp(0.0, self.grid_side as f32) as usize;
let (x0, x1, y0, y1) = (first_cell(lo.x), end_cell(hi.x), first_cell(lo.y), end_cell(hi.y));
let cells = x1.saturating_sub(x0).saturating_mul(y1.saturating_sub(y0));
let Some(left) = budget.checked_sub(cells) else { return false };
*budget = left;

let area = edge(pa, pb, pc);
for y in y0..y1 {
Expand All @@ -151,8 +137,6 @@ impl ProjectorDepth {
}
}
}

true
}

/// How much depth culling with `hardness` leaves of a projection at world point `p`: 0 behind the surface nearest the projector, 1 on it or where nothing is in front
Expand Down Expand Up @@ -196,23 +180,25 @@ fn edge(a: Vec2, b: Vec2, q: Vec2) -> f32 {
/// Cells across and up the grid
pub const GRID_SIDE: usize = 512;

/// A triangle flatter than this on screen is seen edge on
const MIN_SCREEN_AREA: f32 = 1e-12;
/// Cells across and up each copy's grid when `count` symmetry copies share one grid's storage
pub fn copy_grid_side(count: usize) -> usize {
(GRID_SIDE * GRID_SIDE / count.max(1)).isqrt()
}

/// Cell visits available at each resolution before large overlapping triangles require a coarser grid.
pub const CELL_BUDGET: usize = 256 * GRID_SIDE * GRID_SIDE;
/// A triangle flatter than this on screen is seen edge on
pub const MIN_SCREEN_AREA: f32 = 1e-12;

/// Steepest surface slope kept, in nearness per view unit
const MAX_SLOPE: f32 = 1e4;
pub const MAX_SLOPE: f32 = 1e4;

/// How far behind the nearest surface a point may sit and keep everything, in mesh radii
const BIAS: f32 = 0.002;
pub const BIAS: f32 = 0.002;

/// Most the slope adds to the bias, in mesh radii
const MAX_SLOPE_BIAS: f32 = 0.05;
pub const MAX_SLOPE_BIAS: f32 = 0.05;

/// How far behind the nearest surface culling fades out at hardness 0, in mesh radii
const FADE: f32 = 0.1;
pub const FADE: f32 = 0.1;

#[cfg(test)]
mod tests {
Expand Down Expand Up @@ -305,22 +291,17 @@ mod tests {
assert_eq!(depth.cover(Vec3::new(1.0, 1.0, -0.5), 1.0), 0.0);
}

/// A mesh of many large overlapping triangles keeps the full grid, as the GPU raster does
#[test]
fn raster_budget_fallback_accounts_for_the_last_triangle() {
fn many_overlapping_triangles_keep_the_full_grid() {
let mut mesh = two_squares(0.5, -0.5);
let rear_triangles = [4, 5, 6, 4, 6, 7];
let front_triangles = [0, 1, 2, 0, 2, 3];
mesh.indices = rear_triangles.repeat(CELL_BUDGET / (GRID_SIDE * GRID_SIDE));
mesh.indices.extend(front_triangles);
let projection = planar_z(true, 1.0);
let behind = Vec3::new(0.5, 0.3, -0.5);
mesh.indices = [4, 5, 6, 4, 6, 7].repeat(300);
mesh.indices.extend([0, 1, 2, 0, 2, 3]);

let front_last = ProjectorDepth::of(&mesh, mesh.bounds(), &projection).unwrap();
mesh.indices.rotate_right(front_triangles.len());
let front_first = ProjectorDepth::of(&mesh, mesh.bounds(), &projection).unwrap();
let depth = ProjectorDepth::of(&mesh, mesh.bounds(), &planar_z(true, 1.0)).unwrap();

assert_eq!(front_last.cover(behind, 1.0), 0.0);
assert_eq!(front_last.cover(behind, 1.0), front_first.cover(behind, 1.0));
assert_eq!(depth.grid_side, GRID_SIDE);
assert_eq!(depth.cover(Vec3::new(0.5, 0.3, -0.5), 1.0), 0.0, "the front square drawn last still culls");
}

#[test]
Expand Down
53 changes: 53 additions & 0 deletions crates/compose/src/projector_depth/grid_setup.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use super::{FillCopy, MIN_CELL_SIZE, Mesh, ProjectorView, Vec2, Vec3};

/// What a projector depth grid rasterizes: the mesh's corners in the view and the grid laid over
/// them. The CPU raster ([`super::ProjectorDepth::build_for_copy`]) and the GPU compositor's
/// raster start from the same numbers.
#[derive(Clone, Debug)]
pub struct GridSetup {
/// Each mesh corner in the view (across, up, nearness), None where the view has no point for it
pub projected: Vec<Option<Vec3>>,
/// The view point at the grid's lower corner
pub origin: Vec2,
/// One cell's size across and up in the view
pub cell: Vec2,
/// Cells across and up
pub grid_side: usize,
/// The mesh radius measured along the view's depth axis
pub nearness_unit: f32,
/// The view point at the grid's upper corner
upper: Vec2,
}

impl GridSetup {
/// The setup of `mesh` (placed by `copy`) in `view` at `grid_side` cells across; None when the
/// view sees none of its corners.
pub fn new(view: ProjectorView, mesh: &Mesh, copy: Option<FillCopy>, grid_side: usize) -> Option<Self> {
let projected: Vec<_> = mesh.positions.iter().map(|&point| view.local(copy.map_or(point, |copy| copy.point(point)))).collect();
let (min, max) = projected
.iter()
.flatten()
.fold((Vec2::splat(f32::MAX), Vec2::splat(f32::MIN)), |(lo, hi), view_point| (lo.min(view_point.truncate()), hi.max(view_point.truncate())));
if min.x > max.x || min.y > max.y {
return None;
}

let mut setup = Self { projected, origin: min, cell: Vec2::ZERO, grid_side, nearness_unit: view.unit(), upper: max };
setup.resize(grid_side);
Some(setup)
}

/// The same grid at `grid_side` cells across
pub(super) fn resize(&mut self, grid_side: usize) {
self.grid_side = grid_side;
self.cell = ((self.upper - self.origin) / grid_side.max(1) as f32).max(Vec2::splat(MIN_CELL_SIZE));
}

/// The triangles whose three corners the view sees, in mesh order
pub fn triangles<'a>(&'a self, mesh: &'a Mesh) -> impl Iterator<Item = [Vec3; 3]> + 'a {
mesh.indices.as_chunks::<3>().0.iter().filter_map(|indices| {
let [a, b, c] = indices.map(|index| self.projected.get(index as usize).copied().flatten());
Some([a?, b?, c?])
})
}
}
Loading
Loading