Immediate sampler slots are kept apart by comparison mode (upstream 2286e03)

One constant used by a comparison and an ordinary sample became a
comparison sampler for both.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-24 23:24:05 -06:00
1 parent 795d55eb73
commit 26a801e21a
2 files changed
+109 -24

No files matched your search

+17 -24
View File
@@ -50,7 +50,7 @@ enum Val {
pub(crate) struct Lowered {
pub dxil: Vec<u8>,
/// Bit n: immediate sampler n is used for comparisons.
/// Bit n: immediate sampler n is a comparison sampler.
pub cmp_samplers: u64,
pub root_cbvs: Vec<u8>,
pub root_srvs: Vec<u8>,
@@ -6467,23 +6467,8 @@ impl<'a> Lower<'a> {
Ok(h)
}
Source::Constant(words) if sampler => {
let words: [u32; 4] = words
.get(..4)
.and_then(|w| w.try_into().ok())
.ok_or("a sampler constant")?;
let n = match self.samplers.iter().position(|w| *w == words) {
Some(n) => n,
None => {
self.samplers.push(words);
self.samplers.len() - 1
}
};
if props.0 & 0x8000 != 0 {
// shortcut: one sampler used with and without comparison
// would need two static samplers; it becomes a comparison one.
self.s.cmp_samplers |= 1 << n;
}
Ok(self.s.sampler_handle(self.cur, n as u32))
let n = self.register_sampler(words, props.0 & 0x8000 != 0)?;
Ok(self.s.sampler_handle(self.cur, n))
}
Source::Constant(_) => Err("a constant resource descriptor"),
Source::Built { address, .. } => {
@@ -6594,22 +6579,30 @@ impl<'a> Lower<'a> {
Ok(phi)
}
/// Registers an immediate sampler constant and returns its slot index.
/// Registers an immediate sampler constant and returns its slot index: a
/// constant used with and without comparison takes one slot for each.
fn register_sampler(&mut self, words: &[u32], cmp: bool) -> Result<u32, Why> {
let words: [u32; 4] = words
.get(..4)
.and_then(|w| w.try_into().ok())
.ok_or("a sampler constant")?;
let n = match self.samplers.iter().position(|w| *w == words) {
let slot = self
.samplers
.iter()
.enumerate()
.position(|(n, w)| *w == words && (self.s.cmp_samplers >> n & 1 != 0) == cmp);
let n = match slot {
Some(n) => n,
None => {
let n = self.samplers.len();
if n >= u64::BITS as usize {
return Err("more than 64 immediate sampler slots");
}
self.samplers.push(words);
self.samplers.len() - 1
self.s.cmp_samplers |= u64::from(cmp) << n;
n
}
};
if cmp && n < 64 {
self.s.cmp_samplers |= 1 << n;
}
Ok(n as u32)
}