Validation: a bicubic sample of a format with no bicubic treatment is the runtime's limit

Two public cases of engine/bcx_rules failed on lavapipe:
bicubic-8-bit-normalized-and-srgb-sums-near-the-rounding-tie (63d0f152) and
bicubic-rounding-of-random-float-and-srgb-texels (cbf5dd18). Each binds
RGBA8Unorm_sRGB textures at slots 4-6 and 13, which the kernel samples
through its bicubic constexpr sampler. Until 94adea1c61 (with 0a3a4fe911,
SEMANTICS 2365) the translator refused the whole kernel for its 1D bicubic
samples (slots 12-15), so the cases read as the product's refusal. That
commit built the 1D sample, as meant; the kernel now compiles, and the
runtime refuses its dispatch at slot 4 as Gap::BicubicTexels, an old known
gap its README states (bicubic_texels_word is None for 8-bit sRGB codes).
The executor counted that Gap as a failure, since the case's structure
did not classify it as refused. The refusal moved from the translator to
the runtime; this makes the classification say so.

ToolingRequirement::BicubicTexels ("bicubic_texels"): Limit::Runtime, it
stops the engine's candidate and keeps its cases Metal-qualified. The
checker raises it in checked_requirements
(executor_contract::bicubic_texels) when the case binds, at a texture
slot its function samples through a bicubic constexpr sampler, a texture
whose format gets None from the public
metal2vulkan::metal::format::bicubic_texels_word, so the rule is the
runtime's own. "Samples through a bicubic sampler" is read from the AIR:
an air.sample_* call (with gradients or not, no comparison) of a 1D or
2D colour texture, as the product decodes it, whose sampler operand is a
constexpr sampler (!air.sampler_states) with a bicubic min or mag filter,
as the translator decides it, and whose texture operand is an entry
texture argument, followed through the arguments of direct calls. A
runtime sampler is never bicubic and the translator refuses an argument
buffer's texture, so neither is claimed; a texture reached another way
(a texture array's element, a loaded pointer) is no claim. No census row
carries it: it needs the bound format, a case literal.

The device test that holds the refusal both ways on lavapipe already
exists: metal2vulkan-runtime's
tests::bicubic::every_device_pushes_each_bicubic_slots_format_treatment
(six formats' words pushed, the RGBA8Unorm_sRGB texture refused), with
the conformance ledger's bicubic-texel-classes rgba8unorm-srgb/dispatch
refusal. The requirement's doc names both.

samplers.rs gives each constexpr sampler's state by its global's name
(constexpr_sampler_states); min_lod_clamp.rs's call parsing is shared
(direct_call, operand_list); neither changes what classification
computes. The new module is listed beside depth_range.rs as the
checker's rule over case literals, not classification.

AUTHORED_COMPILE_CENSUS_VERSION 11: the two cases' cells move from
compiled to not_supported{tooling_requirement:bicubic_texels}, which a
cached cell would hide; the census is due a bless on development.
ENGINE_EXECUTOR_ABI is not bumped: no recorded candidate row holds
these cases (corpus/observations holds only their Metal rows).
SEMANTICS_VERSION is untouched: no translation changes.

Tests: requirement.rs's
a_bicubic_sample_of_a_format_with_no_treatment_stops_only_the_candidate
and the Runtime list; bicubic_texels.rs's own: every bcx_rules slot is
found; an RGBA8Unorm_sRGB texture at a 2D or 1D slot (or a texture
array's element there) raises it and RGBA8Unorm does not; a linear
sampler or a gather raises nothing; operands followed through direct
calls; and checked_requirements keeps the case for Metal and stops the
candidate.

Verified at this tree (f8eb488b95's), on lavapipe:
- job m3-max-86229: both cases read not_supported{tooling_requirement:
  bicubic_texels} (refusal=1 failure=0 each), and the public batch
  (ci-lavapipe, device type cpu, validation layer 1.4.363.0) reads
  cases=1189 match=815 mismatch=15 noted_difference=164 refusal=195
  failure=0 held_open=15 new_mismatch=0;
- job m3-max-86238, the same batch at db7bedc60d (the base): match=815
  mismatch=15 noted_difference=164 refusal=193 failure=2, the two
  failures these cases (exit=1, the runtime's BicubicTexels). The change
  moves exactly them from failure to refusal;
- job m3-max-86228: fmt, clippy (plain, --cfg m2v_gpu, --cfg m2v_cpu_icd),
  Rustdoc -D warnings, and the validation suite, 1349 passed, 2 skipped.
This commit is contained in:
Anees Iqbal committed 2026-12-03 17:02:29 -08:00
1 parent f838b75e6c
commit f514d6f283
9 files changed
+544 -37

No files matched your search

@@ -30,8 +30,8 @@ mod tests;
#[cfg(test)]
pub(crate) use build::{interface_from_kernel, interface_from_vertex};
pub use samplers::{
SamplerAddressMode, SamplerBorderColor, SamplerCompareFunction, SamplerCoordinates,
SamplerFilter, SamplerMipFilter, SamplerReduction, SamplerState,
constexpr_sampler_states, SamplerAddressMode, SamplerBorderColor, SamplerCompareFunction,
SamplerCoordinates, SamplerFilter, SamplerMipFilter, SamplerReduction, SamplerState,
};
/// Entries of the Metal threadgroup-buffer argument table (`air.max_threadgroup_buffers` is 31, so
@@ -218,7 +218,7 @@ pub(super) fn add_static_samplers(interface: &mut ShaderInterface, ll: &str) ->
.filter_map(|binding| binding.descriptor.map(|descriptor| descriptor.binding))
.collect::<std::collections::BTreeSet<_>>();
let band = sampler_band();
for words in constants {
for (_, words) in constants {
let binding = band
.clone()
.find(|binding| !occupied.contains(binding))
@@ -253,7 +253,20 @@ pub(super) fn add_static_samplers(interface: &mut ShaderInterface, ll: &str) ->
Ok(())
}
fn parse_static_sampler_constants(ll: &str) -> Result<Vec<[u64; 2]>, String> {
/// The module's constexpr samplers (`!air.sampler_states`), each by the name its global's operand
/// spells (`@__air_sampler_state`), with the state its words encode.
pub fn constexpr_sampler_states(
ll: &str,
) -> Result<std::collections::BTreeMap<String, SamplerState>, String> {
parse_static_sampler_constants(ll)?
.into_iter()
.map(|(name, words)| Ok((name, SamplerState::from_air_words(words)?)))
.collect()
}
/// The words of the module's constexpr samplers, each with its global's name, in
/// [`static_sampler_name_order`].
fn parse_static_sampler_constants(ll: &str) -> Result<Vec<(String, [u64; 2])>, String> {
let mut globals = std::collections::HashMap::<String, [u64; 2]>::new();
let mut nodes = std::collections::HashMap::<u32, String>::new();
let mut root = None;
@@ -312,7 +325,7 @@ fn parse_static_sampler_constants(ll: &str) -> Result<Vec<[u64; 2]>, String> {
constants.push((name.to_string(), words));
}
constants.sort_by_key(|(name, _)| static_sampler_name_order(name));
Ok(constants.into_iter().map(|(_, words)| words).collect())
Ok(constants)
}
/// A total order over a module's `__air_sampler_state` globals: the whole dot-separated suffix
@@ -98,7 +98,10 @@ mod tests;
/// 10: a kernel case with stage inputs of a fixed stride compiles under its stage-input descriptor
/// (`PipelineRequest::Kernel::stage_input`), where it was refused as `kernel_stage_input`; one
/// of a dynamic stride is refused as `dynamic_stage_in_stride`.
pub const AUTHORED_COMPILE_CENSUS_VERSION: u32 = 10;
/// 11: a case that binds a texture of a format with no bicubic treatment at a slot its function
/// samples through a bicubic constexpr sampler is refused as `bicubic_texels`, where it
/// compiled.
pub const AUTHORED_COMPILE_CENSUS_VERSION: u32 = 11;
/// The expectation file's name under the corpus root (`validation/corpus`).
pub const EXPECTATIONS: &str = "authored-compile.tsv";
@@ -1,3 +1,4 @@
pub mod bicubic_texels;
pub mod buffer_slots;
pub mod depth_range;
pub mod depth_stencil;
@@ -970,8 +971,10 @@ const INDEXED_DRAWS_ALONE: RenderDraws = RenderDraws {
/// Every requirement of `case` against its source: what the source's structure raises
/// ([`unsupported_source_requirements`]), what its mesh draw needs ([`mesh::mesh_requirements`]),
/// what its stage's observation needs ([`unsupported_observation_requirements`]), and the families
/// of the case's own literals ([`case_requirements`]). The checker computes it once per checked
/// what its stage's observation needs ([`unsupported_observation_requirements`]), the families
/// of the case's own literals ([`case_requirements`]), and a format the case binds at a slot its
/// function samples through a bicubic sampler that the runtime has no bicubic treatment for
/// ([`bicubic_texels::bicubic_texels_requirement`]). The checker computes it once per checked
/// shader; each executor refuses the ones that stop it.
pub fn checked_requirements(
case: &AuthoredCase,
@@ -988,6 +991,9 @@ pub fn checked_requirements(
case.stage, source_ll, reflection,
));
requirements.extend(case_requirements(case));
requirements.extend(bicubic_texels::bicubic_texels_requirement(
case, source_ll, reflection,
));
requirements
}
@@ -1622,7 +1628,7 @@ mod tests {
}
}
fn case() -> AuthoredCase {
pub(super) fn case() -> AuthoredCase {
AuthoredCase {
air_sha256: "11".repeat(32),
case_id: "22".repeat(32),
@@ -0,0 +1,427 @@
//! A bicubic sample of a texture whose format the runtime has no bicubic treatment for.
//!
//! The translator emulates Metal's bicubic filter by fetches and reads the bound format's treatment
//! from the texture slot's pushed word, which the runtime writes from the bound texture
//! (`metal2vulkan::metal::format::bicubic_texels_word`). A format with no such word (one of 8-bit
//! sRGB codes, or one of no measured family) is refused at the dispatch or draw that binds it:
//! `metal2vulkan_runtime::Gap::BicubicTexels`, naming the slot and the format. So a case that binds
//! such a texture at a slot its function samples through a bicubic sampler is the runtime's limit
//! ([`ToolingRequirement::BicubicTexels`]), and the Metal oracle runs it.
//!
//! The rule reads the structure and the case's literals. A sample counts when the product decodes
//! its `air.*` name as a sample (with gradients or not, never a comparison) of a 1D or 2D colour
//! texture, its sampler operand is a constexpr sampler (`!air.sampler_states`) whose minification
//! or magnification filter is bicubic, as the translator decides it, and its texture operand is
//! the entry's texture argument: in the entry's body, or in a function the entry reaches by direct
//! calls that pass both operands down as arguments. The slot is the argument's `[[texture(n)]]`,
//! and the format the case binds there is the one the engine's candidate makes
//! (`candidate::engine::resources::pixel_format`), with no swizzle, which does not decide whether a
//! format has a word. A runtime sampler is never bicubic (a `Cubic` descriptor filters as
//! nearest), and a texture an argument buffer holds is never sampled so (the translator refuses
//! it): neither is claimed. A texture reached any other way (an element of a texture array, a
//! pointer loaded from memory) is no claim either: the case meets the runtime's refusal, as a
//! failure, until a case of it shows the rule its slot follows.
use super::min_lod_clamp::{direct_call, function_bodies, global_name, operand_list};
use crate::air::reflect::{constexpr_sampler_states, ResourceKind, SamplerFilter, ShaderInterface};
use crate::case::{AuthoredCase, TextureFormat};
use crate::requirement::ToolingRequirement;
use metal2vulkan::metal::format::bicubic_texels_word;
use metal2vulkan::metal::TextureSwizzleChannels;
use metal2vulkan_air::intrinsics::{AirIntrinsic, ImageDim, TexOp, TexRole};
use std::collections::{BTreeMap, BTreeSet};
/// [`ToolingRequirement::BicubicTexels`] when `case` binds, at a texture slot the entry of
/// `reflection` samples through a bicubic constexpr sampler ([`bicubic_slots`]), a texture of a
/// format with no bicubic word.
pub fn bicubic_texels_requirement(
case: &AuthoredCase,
source_ll: &str,
reflection: &ShaderInterface,
) -> Option<ToolingRequirement> {
let refused = |slot| {
bound_format(case, slot).is_some_and(|format| {
let pf = crate::candidate::engine::resources::pixel_format(format);
bicubic_texels_word(pf, TextureSwizzleChannels::DEFAULT).is_none()
})
};
bicubic_slots(source_ll, reflection)
.into_iter()
.any(refused)
.then_some(ToolingRequirement::BicubicTexels)
}
/// The format of the texture `case` binds at texture slot `slot`, as the engine's candidate binds
/// them (`candidate::engine::resources::bound_textures`): a texture array's element there, which
/// only an array that overrides its base slot shares with a texture, else the texture.
fn bound_format(case: &AuthoredCase, slot: u32) -> Option<TextureFormat> {
let element = case.texture_arrays.iter().find(|array| {
slot.checked_sub(array.binding)
.is_some_and(|element| (element as usize) < array.elements.len())
});
element.map(|array| array.format).or_else(|| {
(case.textures.iter())
.find(|texture| texture.binding == slot)
.map(|texture| texture.format)
})
}
/// The texture slots the entry of `reflection` samples through a bicubic constexpr sampler: the
/// `[[texture(n)]]` of each texture argument [`bicubic_arguments`] finds.
pub fn bicubic_slots(source_ll: &str, reflection: &ShaderInterface) -> BTreeSet<u32> {
let Some(entry) = reflection.entry_point.as_deref() else {
return BTreeSet::new();
};
let arguments = bicubic_arguments(source_ll, entry);
(reflection.bindings.iter())
.filter(|binding| binding.kind == ResourceKind::Texture)
.filter(|binding| {
binding
.param_index
.is_some_and(|param| arguments.contains(&param))
})
.map(|binding| binding.metal_index)
.collect()
}
/// Where a value comes from: the entry's argument at a position, or a global.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
enum Origin<'a> {
Argument(u32),
Global(&'a str),
}
/// The positions of the arguments of the function `entry` of `source_ll` that a sample in its
/// body, or in a function it reaches by direct calls, takes as its texture operand through a
/// constexpr sampler whose minification or magnification filter is bicubic (module docs). An
/// operand is followed from the entry's arguments and the module's globals through the arguments
/// of direct calls, and no further.
pub fn bicubic_arguments(source_ll: &str, entry: &str) -> BTreeSet<u32> {
if !source_ll.contains("@air.sample_") {
return BTreeSet::new();
}
let Ok(samplers) = constexpr_sampler_states(source_ll) else {
return BTreeSet::new();
};
let bicubic = (samplers.iter())
.filter(|(_, state)| {
state.min_filter == SamplerFilter::Bicubic || state.mag_filter == SamplerFilter::Bicubic
})
.map(|(name, _)| name.as_str())
.collect::<BTreeSet<_>>();
if bicubic.is_empty() {
return BTreeSet::new();
}
let bodies = function_bodies(source_ll);
let params = function_params(source_ll);
let Some((&entry, entry_params)) = params.get_key_value(entry) else {
return BTreeSet::new();
};
let mut origins = Origins::new();
for (position, &name) in (0u32..).zip(entry_params) {
origins.insert((entry, name), BTreeSet::from([Origin::Argument(position)]));
}
// A function is revisited when one of its parameters gains an origin; origins only grow, so
// the list drains.
let mut pending = vec![entry];
let mut reached = BTreeSet::from([entry]);
while let Some(function) = pending.pop() {
let calls = bodies.get(function).into_iter().flatten();
for (callee, operands) in calls.filter_map(|text| direct_call(text)) {
let (Some(callee_params), true) = (params.get(callee), bodies.contains_key(callee))
else {
continue;
};
let mut grew = reached.insert(callee);
for (&operand, &param) in operands.iter().zip(callee_params) {
let add = origin_of(&origins, function, operand);
let known = origins.entry((callee, param)).or_default();
let before = known.len();
known.extend(add);
grew |= known.len() != before;
}
if grew {
pending.push(callee);
}
}
}
let mut arguments = BTreeSet::new();
for &function in &reached {
let calls = bodies.get(function).into_iter().flatten();
for (callee, operands) in calls.filter_map(|text| direct_call(text)) {
let Some((texture, sampler)) = bicubic_operands(callee, &operands) else {
continue;
};
let sampled = origin_of(&origins, function, sampler)
.iter()
.any(|origin| matches!(origin, Origin::Global(name) if bicubic.contains(name)));
if sampled {
arguments.extend(origin_of(&origins, function, texture).iter().filter_map(
|origin| match origin {
Origin::Argument(position) => Some(*position),
Origin::Global(_) => None,
},
));
}
}
}
arguments
}
/// The origins each named value of each function has, by function and value name.
type Origins<'a> = BTreeMap<(&'a str, &'a str), BTreeSet<Origin<'a>>>;
/// The origins of the typed operand `operand` of a call in `function`: a global's own name, or
/// what `origins` holds for a local value (nothing for a constant or an untracked value).
fn origin_of<'a>(
origins: &Origins<'a>,
function: &'a str,
operand: &'a str,
) -> BTreeSet<Origin<'a>> {
let value = operand.split_whitespace().last().unwrap_or_default();
if value.starts_with('@') {
return BTreeSet::from([Origin::Global(value)]);
}
origins.get(&(function, value)).cloned().unwrap_or_default()
}
/// The texture and sampler operands of a call of `callee` with `operands` when the product decodes
/// it as a sample, with gradients or not and never a comparison, of a 1D or 2D colour texture, and
/// its operands fill the layout's positions; `None` for any other call.
fn bicubic_operands<'a>(callee: &str, operands: &[&'a str]) -> Option<(&'a str, &'a str)> {
let Some(AirIntrinsic::Texture(texture)) = AirIntrinsic::parse(callee) else {
return None;
};
let sample = matches!(
texture.op,
TexOp::Sample { compare: false, .. } | TexOp::SampleGrad { compare: false, .. }
);
let image = texture.image;
let shape = matches!(image.dim, ImageDim::D1 | ImageDim::D2) && !image.depth && !image.ms;
let layout = texture.layout();
if !sample || !shape || operands.len() != layout.positions().count() {
return None;
}
let texture_operand = *operands.get(layout.index(TexRole::Texture)?)?;
let sampler_operand = *operands.get(layout.index(TexRole::Sampler)?)?;
Some((texture_operand, sampler_operand))
}
/// The parameter names of each function `source_ll` defines, in order, by name.
fn function_params(source_ll: &str) -> BTreeMap<&str, Vec<&str>> {
(source_ll.lines())
.filter_map(|line| line.strip_prefix("define "))
.filter_map(|define| {
let (name, after) = global_name(&define[define.find('@')? + 1..])?;
let params = operand_list(after.strip_prefix('(')?)?;
let names = (params.iter())
.filter_map(|param| param.split_whitespace().last())
.collect();
Some((name, names))
})
.collect()
}
#[cfg(test)]
mod tests {
use super::*;
use crate::case::{Stage, TextureArrayElement, TextureArrayResource, TextureType};
/// The owned public fixture whose two committed cases this rule classifies: sixteen sampled
/// textures (2D at slots 0 to 11, 1D at 12 to 15), each sampled through one bicubic constexpr
/// sampler at pixel coordinates.
const BCX_RULES: &str = include_str!("../../fixtures/public/engine/bcx_rules.ll");
fn reflection(ll: &str) -> ShaderInterface {
crate::air::reflect::inspect(ll, Stage::Kernel, "bcx_rules", &[]).unwrap()
}
/// A kernel case of `bcx_rules` that binds `format` at every slot, 2D or 1D as the slot's
/// argument is.
fn case(format: TextureFormat) -> AuthoredCase {
let mut case = super::super::tests::case();
case.entry = "bcx_rules".into();
case.textures = (0..16)
.map(|binding| crate::case::TextureResource {
binding,
role: crate::case::ResourceRole::Input,
texture_type: if binding < 12 {
TextureType::D2
} else {
TextureType::D1
},
format,
dimensions: [4, if binding < 12 { 4 } else { 1 }, 1],
sample_count: 1,
bytes_b64: None,
initial_bytes_b64: None,
sparse: None,
mip_levels: 1,
})
.collect();
case
}
/// Every slot of `bcx_rules` is sampled through its bicubic sampler, 2D and 1D alike.
#[test]
fn every_slot_of_the_fixture_is_sampled_through_its_bicubic_sampler() {
assert_eq!(
bicubic_slots(BCX_RULES, &reflection(BCX_RULES)),
(0..16).collect::<BTreeSet<_>>()
);
}
/// A bicubic sample of an `RGBA8Unorm_sRGB` texture raises the requirement, at a 2D slot and
/// at a 1D one; of an `RGBA8Unorm` texture, whose word the runtime writes, it does not.
#[test]
fn an_srgb_texture_raises_it_and_a_unorm_one_does_not() {
let reflection = reflection(BCX_RULES);
let unorm = case(TextureFormat::Rgba8Unorm);
assert_eq!(
bicubic_texels_requirement(&unorm, BCX_RULES, &reflection),
None
);
for slot in [4, 13] {
let mut srgb = unorm.clone();
srgb.textures[slot].format = TextureFormat::Rgba8UnormSrgb;
assert_eq!(
bicubic_texels_requirement(&srgb, BCX_RULES, &reflection),
Some(ToolingRequirement::BicubicTexels),
"slot {slot}"
);
}
// A texture array's element at a slot is the texture bound there.
let mut element = unorm.clone();
element.texture_arrays.push(TextureArrayResource {
binding: 4,
role: crate::case::ResourceRole::Input,
texture_type: TextureType::D2,
format: TextureFormat::Rgba8UnormSrgb,
sample_count: 1,
overrides_texture_at_base: true,
elements: vec![TextureArrayElement {
dimensions: [4, 4, 1],
bytes_b64: None,
initial_bytes_b64: None,
}],
});
assert_eq!(
bicubic_texels_requirement(&element, BCX_RULES, &reflection),
Some(ToolingRequirement::BicubicTexels)
);
// A slot bound to nothing has the runtime's unbound word.
let mut unbound = unorm.clone();
unbound.textures.clear();
assert_eq!(
bicubic_texels_requirement(&unbound, BCX_RULES, &reflection),
None
);
}
/// The checker raises it among a case's requirements, and the case stays checkable on Metal
/// alone: the Metal oracle runs it, and the engine's candidate refuses it, typed.
#[test]
fn the_checker_keeps_the_case_for_metal_and_stops_the_candidate() {
use super::super::{checked_requirements, evidence_gap, require_executor};
use crate::requirement::Executor;
let reflection = reflection(BCX_RULES);
let srgb = case(TextureFormat::Rgba8UnormSrgb);
let requirements = checked_requirements(&srgb, BCX_RULES, &reflection);
assert!(requirements.contains(&ToolingRequirement::BicubicTexels));
assert_eq!(evidence_gap(&requirements), None);
assert_eq!(
require_executor(&requirements, Executor::MetalOracle),
Ok(())
);
assert_eq!(
require_executor(&requirements, Executor::EngineCandidate),
Err(BTreeSet::from([ToolingRequirement::BicubicTexels]))
);
let unorm = case(TextureFormat::Rgba8Unorm);
let requirements = checked_requirements(&unorm, BCX_RULES, &reflection);
assert!(!requirements.contains(&ToolingRequirement::BicubicTexels));
}
/// The sampler decides it: the same module under a linear sampler, or with its samples
/// spelled as gathers, raises nothing for an sRGB texture.
#[test]
fn only_a_bicubic_sample_raises_it() {
let srgb = case(TextureFormat::Rgba8UnormSrgb);
let reflection = reflection(BCX_RULES);
assert_eq!(
bicubic_texels_requirement(&srgb, BCX_RULES, &reflection),
Some(ToolingRequirement::BicubicTexels)
);
// Both filters linear (code 1 at bits 9-10 and 11-12), every other field kept.
let bicubic = 34_901_797_601_055_817u64;
let linear = (bicubic & !(0xf << 9)) | (0b0101 << 9);
let linear = BCX_RULES.replace(&format!("i64 {bicubic}"), &format!("i64 {linear}"));
assert_ne!(linear, BCX_RULES);
assert_eq!(
bicubic_texels_requirement(&srgb, &linear, &reflection),
None
);
}
/// A kernel `@k` whose texture argument `%t` and the constexpr sampler of `words` reach the
/// sample `call` through `helper`'s body, or the entry's own where `helper` is empty.
fn module(words: u64, entry_body: &str, helper: &str) -> String {
format!(
"@__air_sampler_state = internal addrspace(2) constant [2 x i64] [i64 {words}, i64 \
0], align 8\n\ndefine void @k(ptr addrspace(1) %t, ptr addrspace(1) %u) {{\n \
{entry_body}\n ret void\n}}\n\ndefine internal fastcc void @\"h.1\"(ptr \
addrspace(1) %a, ptr addrspace(2) %s) {{\n {helper}\n ret void\n}}\n\n\
!air.sampler_states = !{{!0}}\n!0 = !{{!\"air.sampler_state\", ptr addrspace(2) \
@__air_sampler_state}}\n"
)
}
fn sample(texture: &str, sampler: &str) -> String {
format!(
"%r = tail call {{ <4 x float>, i8 }} @air.sample_texture_2d.v4f32(ptr addrspace(1) \
readonly captures(none) {texture}, ptr addrspace(2) readonly captures(none) \
{sampler}, <2 x float> zeroinitializer, i1 true, <2 x i32> zeroinitializer, i1 \
false, float 0.000000e+00, float 0.000000e+00, i32 0) #3"
)
}
/// The scan follows the texture and the sampler from the entry's arguments and the module's
/// globals through the arguments of direct calls: a sample in a helper the entry passes its
/// second argument and the sampler counts that argument. A helper never called, or called
/// through a pointer, is no claim, nor is a comparison or a gather.
#[test]
fn operands_are_followed_through_direct_calls() {
let bicubic = 34_901_797_601_055_817u64;
let own = module(bicubic, &sample("%t", "@__air_sampler_state"), "");
assert_eq!(bicubic_arguments(&own, "k"), BTreeSet::from([0]));
let helper = sample("%a", "%s");
let called = module(
bicubic,
"tail call fastcc void @\"h.1\"(ptr addrspace(1) %u, ptr addrspace(2) \
@__air_sampler_state)",
&helper,
);
assert_eq!(bicubic_arguments(&called, "k"), BTreeSet::from([1]));
for unreached in [
module(bicubic, "%x = fadd float 1.0, 1.0", &helper),
module(
bicubic,
"tail call fastcc void %p(ptr addrspace(1) %u, ptr addrspace(2) \
@__air_sampler_state)",
&helper,
),
] {
assert!(bicubic_arguments(&unreached, "k").is_empty(), "{unreached}");
}
let gather = "%g = call { <4 x float>, i8 } @air.gather_texture_2d.v4f32(ptr \
addrspace(1) %t, ptr addrspace(2) @__air_sampler_state, <2 x float> \
zeroinitializer, i1 false, <2 x i32> zeroinitializer, i32 0, i32 0)";
assert!(bicubic_arguments(&module(bicubic, gather, ""), "k").is_empty());
assert!(bicubic_arguments(&own, "absent").is_empty());
// A plain nearest sampler (every field zero): no bicubic filter.
assert!(
bicubic_arguments(&module(0, &sample("%t", "@__air_sampler_state"), ""), "k")
.is_empty()
);
}
}
@@ -136,19 +136,48 @@ pub(super) fn function_bodies(source_ll: &str) -> BTreeMap<&str, Vec<&str>> {
/// other instruction and for a call through a pointer (`call ... %f(...)`). The callee is the
/// first named value directly followed by the operand list: a type's name (`%struct.t`) is not.
pub(super) fn direct_callee(text: &str) -> Option<&str> {
direct_call(text).map(|(name, _)| name)
}
/// The function a call instruction's text names directly ([`direct_callee`]) and its operands, as
/// [`operand_list`] splits them; `None` for any other instruction, for a call through a pointer,
/// and for a call whose operand list does not close.
pub(super) fn direct_call(text: &str) -> Option<(&str, Vec<&str>)> {
let mut rest = &text[text.find("call ")? + "call ".len()..];
loop {
let at = rest.find(['@', '%'])?;
let (name, after) = global_name(&rest[at + 1..])?;
if after.starts_with('(') {
return (rest.as_bytes()[at] == b'@').then_some(name);
if let Some(arguments) = after.strip_prefix('(') {
if rest.as_bytes()[at] != b'@' {
return None;
}
return Some((name, operand_list(arguments)?));
}
rest = after;
}
}
/// The operands of the list `arguments` opens (the text after its `(`), split at its top level,
/// up to the `)` that closes it; `None` when none does.
pub(super) fn operand_list(arguments: &str) -> Option<Vec<&str>> {
let mut depth = 0usize;
let end = arguments.char_indices().find_map(|(index, ch)| match ch {
'(' => {
depth += 1;
None
}
')' if depth == 0 => Some(index),
')' => {
depth -= 1;
None
}
_ => None,
})?;
Some(split_top_level(&arguments[..end]))
}
/// The name at the start of `text` (after its sigil), quoted or not, and the text after it.
fn global_name(text: &str) -> Option<(&str, &str)> {
pub(super) fn global_name(text: &str) -> Option<(&str, &str)> {
if let Some(quoted) = text.strip_prefix('"') {
let end = quoted.find('"')?;
return Some((&quoted[..end], &quoted[end + 1..]));
@@ -197,21 +226,7 @@ fn clamp_operand(text: &str) -> Option<&str> {
let layout = texture.layout();
let clamp = layout.index(TexRole::MinLodClamp)?;
let lod_mode = layout.index(TexRole::LodMode)?;
let arguments = &callee[name_start + name_length + 1..];
let mut depth = 0usize;
let end = arguments.char_indices().find_map(|(index, ch)| match ch {
'(' => {
depth += 1;
None
}
')' if depth == 0 => Some(index),
')' => {
depth -= 1;
None
}
_ => None,
});
let operands = split_top_level(&arguments[..end?]);
let operands = operand_list(&callee[name_start + name_length + 1..])?;
let implicit_level = operands
.get(lod_mode)
.and_then(|operand| operand.split_whitespace().last())
@@ -257,6 +257,22 @@ pub enum ToolingRequirement {
/// into an argument buffer's pipeline-state field, and its indirect commands set no pipeline
/// state of their own (`IndirectCommandsKind::CommandPipelines`).
ArgumentBufferPipelineState,
/// A texture a case binds at a texture slot its function samples through a bicubic constexpr
/// sampler, of a pixel format the runtime has no bicubic treatment for
/// (`executor_contract::bicubic_texels`): `metal2vulkan::metal::format::bicubic_texels_word`
/// is `None` for it (a format of 8-bit sRGB codes, such as `RGBA8Unorm_sRGB`, or of no
/// measured family). Metal samples it; the runtime refuses the dispatch or draw that binds it
/// (`metal2vulkan_runtime::Gap::BicubicTexels`, naming the slot and the format, a known gap its
/// README states), so the limit is the runtime's ([`Limit::Runtime`]) and the engine's
/// candidate does not run the case. A device test holds the refusal both ways on lavapipe:
/// `metal2vulkan-runtime`'s `tests::bicubic` (`every_device_pushes_each_bicubic_slots_format_treatment`)
/// dispatches the bicubic kernel with six formats' words bound and is refused at an
/// `RGBA8Unorm_sRGB` texture, and the conformance ledger's `bicubic-texel-classes` row records
/// the refusal of its `rgba8unorm-srgb` dispatch. The case checker raises it from the case's
/// literals (the bound format) against the source's structure, so no census row carries it.
/// The Metal oracle runs it, so a case of it stays Metal-qualified
/// ([`Self::qualifies_on_metal`]).
BicubicTexels,
/// An indirect command buffer of the one shape the runtime builds, which no runtime limit
/// above names (`executor_contract::case_requirements`): render commands of indexed draws
/// alone that inherit the pipeline state and bind their own buffers, none of them encoded by
@@ -273,7 +289,7 @@ const AUTHORING: &[Executor] = &Executor::ALL;
const ENGINE: &[Executor] = &[Executor::EngineCandidate];
impl ToolingRequirement {
pub const ALL: [Self; 40] = [
pub const ALL: [Self; 41] = [
Self::FunctionConstantLiteral,
Self::VertexAttributeLiteral,
Self::TessellationAttributeLiteral,
@@ -313,6 +329,7 @@ impl ToolingRequirement {
Self::IndirectCommandInheritance,
Self::HostEncodedIndirectCommands,
Self::ArgumentBufferPipelineState,
Self::BicubicTexels,
Self::IndirectIndexedDraws,
];
@@ -359,6 +376,7 @@ impl ToolingRequirement {
Self::IndirectCommandInheritance => "indirect_command_inheritance",
Self::HostEncodedIndirectCommands => "host_encoded_indirect_commands",
Self::ArgumentBufferPipelineState => "argument_buffer_pipeline_state",
Self::BicubicTexels => "bicubic_texels",
Self::IndirectIndexedDraws => "indirect_indexed_draws",
}
}
@@ -379,11 +397,11 @@ impl ToolingRequirement {
/// depth outside `[0, 1]` a case gives a depth image, which the runtime puts nowhere
/// ([`ToolingRequirement::DepthOutsideUnitRange`]), and a mesh render pipeline it does not
/// draw ([`ToolingRequirement::MeshRenderPipeline`]), and a render function's function
/// table, an indexed draw past its index buffer, a 64-bit texture atomic and separate depth
/// and stencil attachments, which the runtime refuses
/// ([`ToolingRequirement::RenderFunctionTable`],
/// table, an indexed draw past its index buffer, a 64-bit texture atomic, separate depth
/// and stencil attachments and a bicubic sample of a format with no bicubic treatment, which
/// the runtime refuses ([`ToolingRequirement::RenderFunctionTable`],
/// [`ToolingRequirement::IndexBufferPastEnd`], [`ToolingRequirement::UlongTextureAtomic`],
/// [`ToolingRequirement::SeparateDepthStencil`]).
/// [`ToolingRequirement::SeparateDepthStencil`], [`ToolingRequirement::BicubicTexels`]).
///
/// The requirements that stopped only the old engine's candidate were retired with it.
pub const fn stops(self) -> &'static [Executor] {
@@ -427,6 +445,7 @@ impl ToolingRequirement {
| Self::IndirectCommandInheritance
| Self::HostEncodedIndirectCommands
| Self::ArgumentBufferPipelineState
| Self::BicubicTexels
| Self::IndirectIndexedDraws => ENGINE,
}
}
@@ -451,9 +470,9 @@ impl ToolingRequirement {
/// [`ToolingRequirement::DynamicStageInStride`], [`ToolingRequirement::RasterizationRateMap`],
/// [`ToolingRequirement::DynamicVertexStride`], [`ToolingRequirement::IndirectComputeCommands`],
/// [`ToolingRequirement::IndirectDrawTypes`], [`ToolingRequirement::IndirectCommandInheritance`],
/// [`ToolingRequirement::HostEncodedIndirectCommands`] and
/// [`ToolingRequirement::ArgumentBufferPipelineState`], which the runtime refuses or does not
/// build, or, for [`ToolingRequirement::DynamicStageInStride`], which the engine's candidate
/// [`ToolingRequirement::HostEncodedIndirectCommands`],
/// [`ToolingRequirement::ArgumentBufferPipelineState`] and
/// [`ToolingRequirement::BicubicTexels`], which the runtime refuses or does not build, or, for [`ToolingRequirement::DynamicStageInStride`], which the engine's candidate
/// does not bind yet.
pub const fn limit(self) -> Limit {
match self {
@@ -475,7 +494,8 @@ impl ToolingRequirement {
| Self::IndirectDrawTypes
| Self::IndirectCommandInheritance
| Self::HostEncodedIndirectCommands
| Self::ArgumentBufferPipelineState => Limit::Runtime,
| Self::ArgumentBufferPipelineState
| Self::BicubicTexels => Limit::Runtime,
_ => Limit::Tooling,
}
}
@@ -672,6 +692,19 @@ mod tests {
assert_eq!("separate_depth_stencil".parse(), Ok(requirement));
}
/// A bicubic sample of a format with no bicubic treatment: the Metal oracle samples it, so its
/// cases stay Metal-qualified; the runtime refuses the dispatch or draw that binds it, so the
/// engine's candidate runs none, the runtime's limit, which closes its rows.
#[test]
fn a_bicubic_sample_of_a_format_with_no_treatment_stops_only_the_candidate() {
let requirement = ToolingRequirement::BicubicTexels;
assert_eq!(requirement.stops(), [Executor::EngineCandidate]);
assert_eq!(requirement.limit(), Limit::Runtime, "{requirement}");
assert!(!requirement.blocks_closure(), "{requirement}");
assert!(requirement.qualifies_on_metal(), "{requirement}");
assert_eq!("bicubic_texels".parse(), Ok(requirement));
}
/// The runtime's own indirect command shape, which the engine's candidate does not map: a
/// tooling gap, so the checker takes no case of it.
#[test]
@@ -799,6 +832,7 @@ mod tests {
ToolingRequirement::IndirectCommandInheritance,
ToolingRequirement::HostEncodedIndirectCommands,
ToolingRequirement::ArgumentBufferPipelineState,
ToolingRequirement::BicubicTexels,
]
);
for executor in Executor::ALL {
@@ -1963,6 +1963,11 @@ entry:
"the case checker's depth-range rule over a case's depth bytes; classification \
reads no depth",
),
(
"src/executor_contract/bicubic_texels.rs",
"the case checker's bicubic rule over the formats a case binds; classification \
reads no case literal",
),
(
"src/executor_contract/render_target_array.rs",
"the executors' render target array length; classification draws no pass",
+5 -1
View File
@@ -559,7 +559,11 @@ cargo run -p metal2vulkan-validation --release --bin corpus-vulkan -- \
writing that sample's texel from a buffer, a color one through an unsigned-integer view of its
texel size so its bits cross unconverted, a depth one under an always-passing depth test that
writes. A cube array is made as any cube, of its cubes' faces. A bound sparse
texture carries `sparse_texture`, which the runtime does not make; a bound texture buffer runs
texture carries `sparse_texture`, which the runtime does not make; a texture bound at a slot
the function samples through a bicubic constexpr sampler, of a format the runtime has no bicubic
treatment for (`metal2vulkan::metal::format::bicubic_texels_word` is `None`: 8-bit sRGB codes
among them), carries `bicubic_texels`, which the runtime refuses at the dispatch or draw
(`Gap::BicubicTexels`), and runs on Metal alone; a bound texture buffer runs
on both executors (the runtime makes it over its buffer's bytes); a kernel's visible-function
table runs on both: the run makes it of the state, as the oracle does, each authored entry the
handle of its linked function, and binds it at its index. A kernel's explicit imageblock runs