Translator: the shared bicubic switch reads each arm's image and format bits under the identity domains

A switch-at-use whose arms all take a bicubic sample (an array of textures, or textures chosen by
a function constant, sampled through one bicubic constexpr sampler) emulates once: a facts
dispatch yields the named candidate's size and format bits, and a taps dispatch reads its texels.
Both read each arm's combined binding and its BicubicTexels specialization, which the identity
domains do not declare, so every such switch under the runtime's domains failed with "internal
error: combined binding ... is not declared".

Under the identity domains an arm's image is now its texture slot's element of the set-1 array at
the index its pushed resource ID holds (emit::identity_image, the image half of the sampled image
a candidate's own sample makes), and its bits the slot's PushField::BicubicTexels, which the plan
already pushed (bicubic::format_bits, the one reading of a slot's bits the own and the shared
emulation share). The resident-table form is unchanged.

SEMANTICS 2278 (with the pixel-coordinate form that lands beside it): modules that failed now translate.
This commit is contained in:
Anees Iqbal committed 2026-11-22 22:54:11 -08:00
1 parent a1abb9e7e5
commit 52113199ee
5 files changed
+95 -59

No files matched your search

+1 -1
View File
@@ -60,7 +60,7 @@ mod tests;
/// unchanged version, and its bless records the version. Independent of the crate's version and of
/// [`ARTIFACT_FORMAT_VERSION`]. The commit that bumps it says what changed; this comment keeps no
/// history.
pub const SEMANTICS_VERSION: u32 = 2277;
pub const SEMANTICS_VERSION: u32 = 2278;
/// The byte-layout version of encoded artifacts (`CompiledFunction::to_bytes` and the
/// [`PipelineArtifact`] encodings). Every encoded artifact carries it, and a decode under another
@@ -1254,6 +1254,30 @@ pub(super) fn word_field(
fb.binary(BinOp::BitwiseAnd, f, m)
}
/// The bound format's treatment of texture slot `texture` under the bicubic filter: the slot's
/// `BicubicTexels` specialization, or under the identity domains its push field, which the
/// consumer writes from the bound texture, read in the open block.
pub(super) fn format_bits(
cx: &mut EmitCx<'_>,
fb: &mut FunctionBuilder<'_>,
texture: u32,
) -> BResult<Bits> {
if let Some(&spec) = cx.decl.families.sampler.bicubic.get(&texture) {
return Ok(Bits::Spec(spec));
}
if !cx.plan.families.access.identity {
return Err(cx.fail(format!(
"texture slot {texture} has no bicubic specialization"
)));
}
let Some(slot) = cx.plan.families.texture.slots.get(&texture) else {
return Err(cx.fail(format!("texture slot {texture} is not planned")));
};
Ok(Bits::Value(
cx.push_field(fb, PushField::BicubicTexels(slot.slot))?,
))
}
/// The `vec4` texel the bicubic sample `s` of sampled image `si` (image facts `image`) reads
/// (module docs), its `half` result the device's narrowing of the `f32` sum.
pub(super) fn emit(
@@ -1264,23 +1288,7 @@ pub(super) fn emit(
image: CombinedImage,
b: &Bicubic,
) -> BResult<SValue> {
let bits = match cx.decl.families.sampler.bicubic.get(&b.texture) {
Some(&spec) => Bits::Spec(spec),
// Under the identity domains the slot's push field, which the consumer writes from the
// bound texture.
None if cx.plan.families.access.identity => {
let Some(slot) = cx.plan.families.texture.slots.get(&b.texture) else {
return Err(cx.fail(format!("texture slot {} is not planned", b.texture)));
};
Bits::Value(cx.push_field(fb, PushField::BicubicTexels(slot.slot))?)
}
None => {
return Err(cx.fail(format!(
"texture slot {} has no bicubic specialization",
b.texture
)))
}
};
let bits = format_bits(cx, fb, b.texture)?;
let half = half_result(cx, s)?;
let t = Tys::new(fb)?;
let span = b.span();
+17 -14
View File
@@ -1381,15 +1381,14 @@ fn sampler_id(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, n: u32) -> BRes
cx.push_field(fb, crate::pipeline::sym::PushField::SlotGuestBase(slot))
}
/// Under the identity domains, the sampled image of combined binding `key`
/// ([`super::IdentitySampling`]): the texture slot's element of its class's set-1 array at the
/// index its pushed resource ID holds, and its sampler ([`identity_sampler`]), joined by
/// `OpSampledImage`.
fn identity_sampled_image(
/// Under the identity domains, the image of combined binding `key`, loaded in the open block: the
/// texture slot's element of its class's set-1 array at the index its pushed resource ID holds,
/// with the binding's identity sampling ([`super::IdentitySampling`]).
pub(super) fn identity_image(
cx: &mut EmitCx<'_>,
fb: &mut FunctionBuilder<'_>,
key: super::BindingKey,
) -> BResult<(SValue, CombinedImage)> {
) -> BResult<(SValue, super::IdentitySampling)> {
let Some(i) = cx.plan.families.sampler.identity.get(&key).copied() else {
return Err(cx.fail(format!("combined binding {key:?} has no identity sampling")));
};
@@ -1409,16 +1408,20 @@ fn identity_sampled_image(
let base = fb.module().global_value(images)?;
let p = fb.access_chain(base, &[element])?;
let img = fb.load(p, MemAccess::default())?;
Ok((img, i))
}
/// Under the identity domains, the sampled image of combined binding `key`: its image
/// ([`identity_image`]) and its sampler ([`identity_sampler`]), joined by `OpSampledImage`.
fn identity_sampled_image(
cx: &mut EmitCx<'_>,
fb: &mut FunctionBuilder<'_>,
key: super::BindingKey,
) -> BResult<(SValue, CombinedImage)> {
let (img, i) = identity_image(cx, fb, key)?;
let sampler = identity_sampler(cx, fb, key.sampler, i.use_)?;
let si = fb.sampled_image(img, sampler)?;
Ok((
si,
CombinedImage {
plane: super::plane_of(i.image.dim),
arrayed: i.image.arrayed,
texel: i.image.texel,
},
))
Ok((si, i.combined()))
}
/// Under the identity domains, sampler `sampler` in use `use_`: the element of the set-1 sampler
@@ -1253,6 +1253,17 @@ pub struct IdentitySampling {
pub use_: SamplerUse,
}
impl IdentitySampling {
/// The image facts emission reads of [`IdentitySampling::image`].
pub fn combined(&self) -> CombinedImage {
CombinedImage {
plane: plane_of(self.image.dim),
arrayed: self.image.arrayed,
texel: self.image.texel,
}
}
}
/// The image facts emission reads for a combined binding.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct CombinedImage {
+41 -27
View File
@@ -15,6 +15,10 @@
//! - the emulation on those facts (its footprint, weights and routine calls once), whose taps a
//! dispatch reads from each arm's image (the null arm's are zero).
//!
//! Under the identity domains an arm's image is its texture slot's element of the set-1 array at
//! the index its pushed resource ID holds, and its bits the slot's `PushField::BicubicTexels`, as
//! a candidate's own sample reads them.
//!
//! Where a handle names a candidate the facts are that candidate's, so every value is the one its
//! own arm computed; elsewhere the switch's null value is selected. The emulation of a null handle
//! runs on a size of ones and zero taps, whose value is discarded.
@@ -23,11 +27,11 @@ use crate::lower::emit::EmitCx;
use crate::lower::texture::{dispatch, with_word, NullLeaf};
use crate::spirv::builder::FunctionBuilder;
use crate::spirv::error::BResult;
use crate::spirv::ids::{ConstId, Value as SValue};
use crate::spirv::ids::Value as SValue;
use crate::spirv::ir::{ConstBits, Constant, ImageQuery, Type as SType};
use super::bicubic::Bicubic;
use super::{Binding, CombinedImage, SampleOp, Sampling, Source};
use super::{BindingKey, CombinedImage, SampleOp, Sampling, Source};
/// The candidates of a switch-at-use that emulates once: the handles' values dispatched on,
/// outermost first, and each arm's case literals and sampling.
@@ -51,28 +55,45 @@ impl Candidates<'_> {
dispatch(cx, fb, &self.sels, &self.arms, &leaf, null)
}
/// The image of arm sampling `a`'s binding, loaded in the open block.
/// The image of arm sampling `a`'s binding, loaded in the open block: its combined binding's,
/// or under the identity domains its texture slot's element of the set-1 array
/// (`emit::identity_image`).
pub(super) fn image(
&self,
cx: &mut EmitCx<'_>,
fb: &mut FunctionBuilder<'_>,
a: &Sampling,
) -> BResult<SValue> {
binding(cx, a)?.0.image(fb)
let key = key(cx, a)?;
if cx.plan.families.access.identity {
return Ok(super::emit::identity_image(cx, fb, key)?.0);
}
match cx.decl.families.sampler.combined.get(&key) {
Some(&(b, _)) => b.image(fb),
None => Err(cx.fail(format!("combined binding {key:?} is not declared"))),
}
}
}
/// The combined binding sampling `a` reads, and its image facts.
fn binding(cx: &mut EmitCx<'_>, a: &Sampling) -> BResult<(Binding, CombinedImage)> {
let Source::Combined(key) = a.source else {
return Err(cx.fail("a shared sampling of a heap element"));
};
match cx.decl.families.sampler.combined.get(&key) {
Some(&b) => Ok(b),
None => Err(cx.fail(format!("combined binding {key:?} is not declared"))),
/// The combined binding sampling `a` reads.
fn key(cx: &mut EmitCx<'_>, a: &Sampling) -> BResult<BindingKey> {
match a.source {
Source::Combined(key) => Ok(key),
_ => Err(cx.fail("a shared sampling of a heap element")),
}
}
/// The image facts of the binding sampling `a` reads: its combined binding's, or under the
/// identity domains its identity sampling's.
fn image_facts(cx: &mut EmitCx<'_>, a: &Sampling) -> BResult<CombinedImage> {
let key = key(cx, a)?;
let image = match cx.plan.families.access.identity {
true => (cx.plan.families.sampler.identity.get(&key)).map(|i| i.combined()),
false => (cx.decl.families.sampler.combined.get(&key)).map(|&(_, image)| image),
};
image.ok_or_else(|| cx.fail(format!("combined binding {key:?} is not declared")))
}
/// The bicubic sample every arm of a shared switch takes ([`Sampling::shared_shape`]).
fn bicubic(s: &Sampling) -> Option<&Bicubic> {
match &s.op {
@@ -81,16 +102,13 @@ fn bicubic(s: &Sampling) -> Option<&Bicubic> {
}
}
/// The specialization holding the bound format's bits of arm sampling `a`'s slot, its bicubic
/// sample's `BicubicTexels`.
fn bits(cx: &mut EmitCx<'_>, a: &Sampling) -> BResult<ConstId> {
/// The bound format's bits of arm sampling `a`'s slot, its bicubic sample's, read in the open
/// block (`bicubic::format_bits`).
fn bits(cx: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>, a: &Sampling) -> BResult<SValue> {
let Some(b) = bicubic(a) else {
return Err(cx.fail("a shared switch's arm without its bicubic sample"));
};
match cx.decl.families.sampler.bicubic.get(&b.texture) {
Some(&c) => Ok(c),
None => Err(cx.fail("a shared switch's arm without its format specialization")),
}
super::bicubic::format_bits(cx, fb, b.texture)?.value(fb)
}
/// The value of the shared switch over `c` (module docs): its sampling's value where a handle
@@ -107,9 +125,9 @@ pub(crate) fn shared_value(
let Some(b) = bicubic(first) else {
return Err(cx.fail("a shared switch without an emulation"));
};
let (_, image) = binding(cx, first)?;
let image = image_facts(cx, first)?;
for &(_, a) in &c.arms {
if binding(cx, a)?.1 != image {
if image_facts(cx, a)? != image {
return Err(cx.fail("a shared switch's candidates of different images"));
}
}
@@ -163,12 +181,8 @@ fn facts(
let img = c.image(cx, fb, a)?;
let level = fb.module().const_value(zero)?;
let size = fb.query(ImageQuery::SizeLod(level), img)?;
let bits = bits(cx, a)?;
Ok(vec![
size,
fb.module().const_value(bits)?,
fb.module().const_value(yes)?,
])
let bits = bits(cx, fb, a)?;
Ok(vec![size, bits, fb.module().const_value(yes)?])
};
let null_facts = |_: &mut EmitCx<'_>, fb: &mut FunctionBuilder<'_>| {
Ok(vec![