From 9a8453c61217599122f7569da3d60217c2996619 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Sun, 25 Oct 2026 06:11:52 +0100 Subject: [PATCH] Shader packs, clean room 27: sample mip chains only while current A program sampled every level of a buffer that has mipmaps, even after a later program had rewritten the buffer: the levels below the first were stale. Complementary's FXAA, which samples its colour buffer with implicit derivatives inside branches, picked those levels at edges and drew black dots along every edge. A buffer now binds its whole chain only while the chain matches its content, and its first level otherwise (6.1.7). Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/gfx/pack_post.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/crates/horizon-client/src/gfx/pack_post.rs b/crates/horizon-client/src/gfx/pack_post.rs index 972ac82f3..c3a67f22e 100644 --- a/crates/horizon-client/src/gfx/pack_post.rs +++ b/crates/horizon-client/src/gfx/pack_post.rs @@ -156,7 +156,9 @@ struct Pass { atlas: Option, /// Reads `mc_Entity`'s table (`PackPost::block_ids`). ids: bool, - groups: HashMap, + /// Bind groups by the sides read (low 16 bits) and the buffers whose mip chain is current + /// (high 16 bits). + groups: HashMap, } /// One side of a buffer with mipmaps. @@ -1152,7 +1154,10 @@ impl PackPost { queue.write_buffer(&pass.ubo, 0, &pass.block); } let targets = self.targets.as_ref().expect("resized"); - let key = self.main & pass.reads; + // A chain is sampled only while it is current: a buffer written since its last chain + // reads its first level, never stale levels (6.1.7). + let current = self.mips_valid & self.mipped & pass.reads; + let key = u32::from(self.main & pass.reads) | u32::from(current) << 16; let group = pass.groups.entry(key).or_insert_with(|| { let mut entries = vec![wgpu::BindGroupEntry { binding: 0, @@ -1163,9 +1168,9 @@ impl PackPost { Source::Color(i) => { let side = usize::from(key & 1 << i != 0); match (&targets.mips[i], &targets.color[i]) { - (Some(m), _) => &m[side].all, - (None, Some(t)) => &t[side], - (None, None) => &self.dummy, + (Some(m), _) if current & 1 << i != 0 => &m[side].all, + (_, Some(t)) => &t[side], + (_, None) => &self.dummy, } } Source::Depth => &targets.depth,