Shaders: image_sample_o with constant offsets

image_sample_o was refused by name. Its offset dword (x in bits 0-5, y
in 8-13, z in 16-21, signed) becomes sample's immediate offsets when it
is a constant within DXIL's -8..7; a computed or wider offset is still
refused, now saying so. Module::int_value reads an integer constant.

translate --validate on shaders.rpf: vertex/pixel 12172 -> 12176
validated (all four).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Saitken91andClaude Opus 5.5 committed 2026-11-23 23:58:14 -06:00
1 parent d2a4bae1f4
commit 260611acaa
2 files changed
+31 -1

No files matched your search

+11
View File
@@ -291,6 +291,17 @@ impl Module {
self.constant(ty, Const::Aggregate(ids))
}
/// The value of an integer constant; `None` for anything else.
pub fn int_value(&self, v: V) -> Option<i64> {
match v {
V::Const(i) => match self.consts[i as usize].1 {
Const::Int(x) => Some(x),
_ => None,
},
_ => None,
}
}
/// Gives constant `old` the content of `new` (both stay valid).
pub fn replace_const(&mut self, old: V, new: V) {
if let (V::Const(o), V::Const(n)) = (old, new) {
+20 -1
View File
@@ -5425,7 +5425,7 @@ impl<'a> Lower<'a> {
return Ok(());
}
let (op, sample) = match name {
"image_sample" => (60, true),
"image_sample" | "image_sample_o" => (60, true),
"image_sample_lz" | "image_sample_l" => (62, true),
"image_sample_b" => (61, true),
"image_sample_c_lz" => (65, true),
@@ -5570,6 +5570,25 @@ impl<'a> Lower<'a> {
args.extend(&cs);
match op {
60 => {
if offset_word {
// DXIL takes immediate offsets in -8..=7; the
// console's are 6-bit and may be computed.
let w = addr_val(self, 0)?;
let w = self
.s
.m
.int_value(w)
.ok_or("a sample offset that is not constant")?
as u32;
for (k, o) in os.iter_mut().enumerate().take(offsets) {
let x = (w >> (8 * k) & 0x3F) as i32;
let x = if x >= 32 { x - 64 } else { x };
if !(-8..=7).contains(&x) {
return Err("a sample offset past -8..7");
}
*o = self.s.m.i32(x as u32);
}
}
args.extend(&os);
args.push(fu);
self.s