From 6a951995e154e91e9da89c17a913ff6c74dd62ce Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Thu, 12 Nov 2026 02:33:45 -0800 Subject: [PATCH] The lowest level a slot reads counts no size query: it reads no texel What: LevelReads::lowest_read counted a size query at a constant level as a read of that level. A sample's lowering queries the level-0 size for offsets, pixel coordinates and bias axes (lower/sampler/emit.rs), so every such slot stated lowest_read 0 and no read past an attached level could read in place: the lane and runtime tests of the past-level reads counted the slots first-level or reaching (m3-max-20154, at 70b6b737e7 on lavapipe). A size query reads no texel, and the view a narrowed slot binds keeps the texture's first level as its own, so it answers the same at any level the view holds; the query still raises named, which keeps that level in the view. Fetches and gathers read texels and still count. Tests: level_reads::tests::each_read_states_the_levels_it_reaches (a size query at level 3: named 3, lowest_read none). Verified: built and run in the next job. --- crates/metal2vulkan/src/pipeline/interface.rs | 11 ++++++----- .../src/spirv/requirements/level_reads.rs | 9 ++++++--- .../src/spirv/requirements/level_reads/tests.rs | 16 +++++++++++----- docs/API.md | 4 ++-- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/crates/metal2vulkan/src/pipeline/interface.rs b/crates/metal2vulkan/src/pipeline/interface.rs index 276441320..16834c04c 100644 --- a/crates/metal2vulkan/src/pipeline/interface.rs +++ b/crates/metal2vulkan/src/pipeline/interface.rs @@ -477,8 +477,9 @@ pub struct LevelReads { /// level 0), or the highest constant a level-count containment compares; `None` where none /// does. pub named: Option, - /// The lowest level a fetch, a size query or a gather reads, each a constant (a gather reads - /// level 0); `None` where none does. A level-count containment's comparison reads no level. + /// The lowest level whose texels a fetch or a gather reads, each a constant (a gather reads + /// level 0); `None` where none does. A size query reads no texel, nor does a level-count + /// containment's comparison: each raises `named` alone. pub lowest_read: Option, /// The slot's samples, by the sampler each reads through, sorted by sampler. pub sampled: Vec, @@ -673,9 +674,9 @@ impl LevelReads { /// The lowest level, counted from the view's first, that the slot's reads may reach, where /// `sampled` answers for each of its samplers' samples the lowest level they may reach /// through the sampler the runtime binds ([`SampledLevels::lowest`]): 0 where a read may reach - /// any level ([`LevelReads::any`]); `None` where no read reaches a level (a size query - /// without one, a level-count containment's comparison). Over a view of the same first level - /// whose last level is lower, a read reaches that last level in its place. + /// any level ([`LevelReads::any`]); `None` where no read reaches a level's texels (a size + /// query, a level-count containment's comparison). Over a view of the same first level whose + /// last level is lower, a read reaches that last level in its place. pub fn lowest_level(&self, sampled: impl Fn(&SampledLevels) -> u32) -> Option { if self.any { return Some(0); diff --git a/crates/metal2vulkan/src/spirv/requirements/level_reads.rs b/crates/metal2vulkan/src/spirv/requirements/level_reads.rs index ecbabc590..e7908a569 100644 --- a/crates/metal2vulkan/src/spirv/requirements/level_reads.rs +++ b/crates/metal2vulkan/src/spirv/requirements/level_reads.rs @@ -71,12 +71,13 @@ struct Lods { } impl Found { - /// A level-count containment's comparison of `level`: the view holds more levels than it. + /// A level-count containment's comparison of `level`, or a size query at it: the view holds + /// more levels than it. fn name(&mut self, level: u32) { self.named = Some(self.named.map_or(level, |n| n.max(level))); } - /// A read of `level`. + /// A read of `level`'s texels. fn read(&mut self, level: u32) { self.name(level); self.lowest_read = Some(self.lowest_read.map_or(level, |l| l.min(level))); @@ -401,8 +402,10 @@ fn judge( inst if carried_on(inst) == Some(v) && result.is_some() => {} Inst::ImageQuery { query, image } if *image == v => match query { ImageQuery::Size | ImageQuery::Samples => {} + // A size query reads no texel: the view holds the level, which raises the highest + // alone. ImageQuery::SizeLod(l) => match contained.level(m, *l, slot)? { - Some(c) => f.read(c), + Some(c) => f.name(c), None => f.any = true, }, // Its uses are judged as the level count's (`level_reads`). diff --git a/crates/metal2vulkan/src/spirv/requirements/level_reads/tests.rs b/crates/metal2vulkan/src/spirv/requirements/level_reads/tests.rs index 57f7ba782..870200260 100644 --- a/crates/metal2vulkan/src/spirv/requirements/level_reads/tests.rs +++ b/crates/metal2vulkan/src/spirv/requirements/level_reads/tests.rs @@ -282,10 +282,10 @@ fn sampled(sampler: SamplerRef, lods: Option<(f32, f32)>, computed: bool) -> Sam /// Each read states the levels it reaches: a sample by its sampler, a constant level of detail /// or a computed one; a gather, a fetch and a size query the level they name, the lowering's -/// containment of a constant included, as the highest and the lowest read (a comparison of the -/// level count raises the highest alone); and a fetch or level at a computed level, a level count -/// used otherwise, a level-of-detail query, a minimum level of detail and a storage write any -/// level. +/// containment of a constant included, as the highest and (but a size query, which reads no +/// texel) the lowest read (a comparison of the level count raises the highest alone); and a fetch +/// or level at a computed level, a level count used otherwise, a level-of-detail query, a minimum +/// level of detail and a storage write any level. #[test] fn each_read_states_the_levels_it_reaches() { let runtime = SamplerRef::Slot(0); @@ -333,7 +333,13 @@ fn each_read_states_the_levels_it_reaches() { (Read::FetchBase, reads(false, Some(0), Vec::new())), (Read::LevelsElsewhere, reads(true, None, Vec::new())), (Read::QueryLod, reads(true, None, Vec::new())), - (Read::SizeConstant, reads(false, Some(3), Vec::new())), + ( + Read::SizeConstant, + LevelReads { + lowest_read: None, + ..reads(false, Some(3), Vec::new()) + }, + ), (Read::Size, reads(false, None, Vec::new())), (Read::Write, reads(true, None, Vec::new())), ] { diff --git a/docs/API.md b/docs/API.md index 04f62701c..bf224bfda 100644 --- a/docs/API.md +++ b/docs/API.md @@ -1539,8 +1539,8 @@ view's first level (`StageModule::level_reads`, one `LevelReads` a slot): whethe reach any level (`any`: a level the function computes, a level-count query used beyond the containment of a constant level, a level-of-detail query, a sample through no sampler or with a minimum level of detail, a storage access, or a use the analysis does not follow), the highest -constant level a fetch, size query or gather names (`named`) and the lowest one it reads -(`lowest_read`), and its samples by the sampler each reads through (`sampled`, with the highest +constant level a fetch, size query or gather names (`named`) and the lowest whose texels a fetch +or gather reads (`lowest_read`), and its samples by the sampler each reads through (`sampled`, with the highest and the lowest constant level of detail). A sample's level is its sampler's to bound: ask `LevelReads::highest_level` with `SampledLevels::level` of the sampler you bind (`SamplerLevels::of` its `vk::SamplerDesc`, and `SamplerLevels::finite_texels` of the view's