2
0
Эх сурвалжийг харах

Merge pull request #634 from SAitken91/shader/image-sample-o

Shaders: image_sample_o with constant offsets
Marvis 2 өдөр өмнө
parent
commit
6f0a10a758

+ 11 - 0
crates/victory-shader/src/emit/bitcode.rs

@@ -291,6 +291,17 @@ impl Module {
         self.constant(ty, Const::Aggregate(ids))
         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).
     /// Gives constant `old` the content of `new` (both stay valid).
     pub fn replace_const(&mut self, old: V, new: V) {
     pub fn replace_const(&mut self, old: V, new: V) {
         if let (V::Const(o), V::Const(n)) = (old, new) {
         if let (V::Const(o), V::Const(n)) = (old, new) {

+ 20 - 1
crates/victory-shader/src/emit/lower.rs

@@ -5602,7 +5602,7 @@ impl<'a> Lower<'a> {
             return Ok(());
             return Ok(());
         }
         }
         let (op, sample) = match name {
         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_lz" | "image_sample_l" => (62, true),
             "image_sample_b" => (61, true),
             "image_sample_b" => (61, true),
             "image_sample_c_lz" => (65, true),
             "image_sample_c_lz" => (65, true),
@@ -5747,6 +5747,25 @@ impl<'a> Lower<'a> {
             args.extend(&cs);
             args.extend(&cs);
             match op {
             match op {
                 60 => {
                 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.extend(&os);
                     args.push(fu);
                     args.push(fu);
                     self.s
                     self.s