From 9047fba14eceed47cbb1b722a07c63d7d4278eac Mon Sep 17 00:00:00 2001 From: HumanlyDev Date: Fri, 27 Nov 2026 00:08:21 +0200 Subject: [PATCH] fix(gpu,shader): preserve point filtering for anisotropic-point samplers --- crates/victory-gpu/src/sampler.rs | 20 +++++++++++++++++++- crates/victory-shader/src/emit/sampler.rs | 10 +++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/crates/victory-gpu/src/sampler.rs b/crates/victory-gpu/src/sampler.rs index 2132273..10bd209 100644 --- a/crates/victory-gpu/src/sampler.rs +++ b/crates/victory-gpu/src/sampler.rs @@ -29,7 +29,7 @@ struct Fields { impl Fields { fn host(&self) -> D3D12_SAMPLER_DESC { let linear = |f: u32| u32::from(f == 1 || f == 3); - let aniso = self.mag >= 2 || self.min >= 2; + let aniso = self.mag == 3 || self.min == 3; // The console compares when the instruction says so, with the // sampler's function; the host needs a comparison sampler for that. // A sampler given a real test (less ... greater-or-equal) is one; @@ -226,4 +226,22 @@ mod tests { ); assert_eq!(d.ComparisonFunc, D3D12_COMPARISON_FUNC_LESS_EQUAL); } + + #[test] + fn anisotropic_point_samplers_stay_point() { + let mut w = [0u32; 27]; + w[1] = 2; // anisotropic point mag + w[2] = 2; // anisotropic point min + w[3] = 1; // point mip + w[13] = 8; + let d = console(&w); + assert_eq!(d.Filter.0, 0x00); + assert_eq!(d.MaxAnisotropy, 1); + + w[1] = 3; // anisotropic bilinear mag + w[2] = 3; // anisotropic bilinear min + let d = console(&w); + assert_eq!(d.Filter.0, 0x55); + assert_eq!(d.MaxAnisotropy, 8); + } } diff --git a/crates/victory-shader/src/emit/sampler.rs b/crates/victory-shader/src/emit/sampler.rs index ca010e5..f5b12fb 100644 --- a/crates/victory-shader/src/emit/sampler.rs +++ b/crates/victory-shader/src/emit/sampler.rs @@ -58,7 +58,7 @@ impl StaticSampler { 2 => 3, _ => 0, }; - let filter = if mag >= 2 || min >= 2 { + let filter = if mag == 3 || min == 3 { 0x54 | u32::from(mip == 2) | reduction << 7 } else { (min & 1) << 4 | (mag & 1) << 2 | u32::from(mip == 2) | reduction << 7 @@ -148,9 +148,13 @@ mod tests { let s = StaticSampler::from_words([w0, 0x00FF_F000, w2, 0]); assert_eq!(s.filter, base | 1, "reduction={reduction} mip=2"); } - // Mixed anisotropic mag (2) with linear min (1) and point mip (1). + // Anisotropic point mag (2) with linear min (1) and point mip (1) stays point mag. let mixed = StaticSampler::from_words([0, 0, (1 << 26) | (1 << 22) | (2 << 20), 0]); - assert_eq!(mixed.filter, 0x54); + assert_eq!(mixed.filter, 0x10); + let aniso_point = StaticSampler::from_words([0, 0, (1 << 26) | (2 << 22) | (2 << 20), 0]); + assert_eq!(aniso_point.filter, 0x00); + let aniso_linear = StaticSampler::from_words([0, 0, (1 << 26) | (1 << 22) | (3 << 20), 0]); + assert_eq!(aniso_linear.filter, 0x54); } #[test]