diff --git a/crates/victory-shader/src/emit/lower.rs b/crates/victory-shader/src/emit/lower.rs index 718a9765c4..0ab7ad4114 100644 --- a/crates/victory-shader/src/emit/lower.rs +++ b/crates/victory-shader/src/emit/lower.rs @@ -6,6 +6,8 @@ //! emitter cannot express is `Missing` with a reason, and only fails the //! program when something with an effect (an export, a branch) needs it. +pub(super) mod amd; + use std::collections::{BTreeMap, HashMap, HashSet}; use super::UserData; @@ -5962,7 +5964,7 @@ impl<'a> Lower<'a> { } _ => return Err("a scalar memory read as data"), }; - let h = self.handle(site, &src, false, props)?; + let h = self.size_view_handle(site, first, &src, props, image.is_none())?; // amd.rs let words: Vec<(u32, V)> = match image { Some(kind) => self.image_size_words(h, kind, uav), None => { diff --git a/crates/victory-shader/src/emit/lower/amd.rs b/crates/victory-shader/src/emit/lower/amd.rs new file mode 100644 index 0000000000..e3e89a410b --- /dev/null +++ b/crates/victory-shader/src/emit/lower/amd.rs @@ -0,0 +1,96 @@ +//! Changes to the translation that keep AMD's shader compiler from failing on the title's +//! programs: amdxc64 8.18.10.0514 (Radeon RX 9060 XT / 9070 XT, driver 32.0.32029.2010) +//! dereferences null, or ends the process, creating some of their pipelines as otherwise +//! translated. Found by creating every program's pipeline (2,684 compute; 23,279 others with a +//! stand-in partner stage) in a process of its own. +//! +//! - A buffer's size is asked through a heap handle of its own, marked non-uniform +//! (`size_view_handle`; fxceless/victory-fork#1213): through the uniform handle the buffer's +//! loads use, the compiler crashes where a load's offset comes from that size. +//! - Nine programs build once one clean-up pass runs; it runs for them whatever +//! `VICTORY_SHADER_OPT` says (`passes`, by container digest). +//! +//! Kept to this file and a one-line hook where each change acts, so it carries to forks. + +use std::cell::Cell; + +use super::super::bitcode::V; +use super::super::bitcode::opt::{FACTS, FOLD}; +use super::{Lower, Site, Source, Why}; + +thread_local! { + /// The clean-up passes of the program being lowered on this thread. + static PASSES: Cell = const { Cell::new(0) }; +} + +/// (container digest, clean-up passes run whatever `VICTORY_SHADER_OPT` says). +const FIXES: [(u128, u32); 9] = [ + // indirect_diffuse_lighting:CS_ScreenProbes_ActivateRays_d60186e6_Wrapped: with no + // clean-up the process ends (0xFFFFFFFF); folding constants alone is enough. + (0x5212_83e5_0211_e301_e7fa_ed9e_0299_dc22, FOLD), + // The glints pixel programs build once branches tell their conditions. + // PS_MIRROR_PBR_MATERIAL_CLEARCOAT_GLINTS + (0xe416_8a83_c5c6_ff23_73e3_4325_35ad_7c9d, FACTS), + // PS_MIRROR_PBR_MATERIAL_GLINTS + (0x3024_35a1_3c4c_b152_2a2c_e785_8fab_7e34, FACTS), + // PS_MIRROR_PBR_MATERIAL_TERRAIN_GLINTS + (0x60f0_c383_b6ba_41b5_895d_4a40_39e7_a781, FACTS), + // PS_MIRROR_PBR_MATERIAL_TERRAIN_GLINTS_TRANSLUCENCY + (0xb867_ed98_e402_b5f8_8844_35ad_5d48_5b36, FACTS), + // PS_STUDIOSHOT_PBR_MATERIAL_CLEARCOAT_GLINTS_LIGHTING + (0x8e32_45bb_242a_2e59_17c1_d2ce_d51c_7fc9, FACTS), + // PS_STUDIOSHOT_PBR_MATERIAL_GLINTS_LIGHTING + (0x5bbf_8eed_9a4f_5133_8b8d_2e36_cd9f_4b66, FACTS), + // PS_STUDIOSHOT_PBR_MATERIAL_TERRAIN_GLINTS_LIGHTING + (0x3c03_fca2_b4cc_b79b_fb87_eb51_81de_8a70, FACTS), + // PS_STUDIOSHOT_PBR_MATERIAL_TERRAIN_GLINTS_TRANSLUCENCY_LIGHTING + (0x3df1_012d_c24c_6daf_af0b_c2ce_8fc7_8b7b, FACTS), +]; + +/// Before lowering the program whose container digest is `digest` on this thread. +pub(in crate::emit) fn begin(digest: [u8; 16]) { + let d = u128::from_be_bytes(digest); + PASSES.set(FIXES.iter().find(|f| f.0 == d).map_or(0, |f| f.1)); +} + +/// Clean-up passes the program being lowered gets whatever `VICTORY_SHADER_OPT` says. +pub(in crate::emit) fn passes() -> u32 { + PASSES.get() +} + +impl Lower<'_> { + /// The handle a buffer's size (`descriptor_data`) is asked through: for a buffer whose + /// descriptor every lane shares, one of its own marked non-uniform, not counted in + /// `nonuniform_handles` (its index is the same in every lane); otherwise the view's + /// handle as before. AMD's compiler reads a null pointer compiling the query through the + /// uniform handle the buffer's loads use (fxceless/victory-fork#1213, IxMxAMAR). + pub(super) fn size_view_handle( + &mut self, + site: Site, + first: u8, + src: &Source, + props: (u32, u32), + buffer: bool, + ) -> Result { + if !buffer || self.x.res.waterfall.loads.contains(&site) { + return self.handle(site, src, false, props); + } + let index = self.heap_index(site, first, false)?; + let h = self.s.heap_handle(self.cur, index, false, true, props); + self.s.nonuniform_handles -= 1; + Ok(h) + } +} + +#[cfg(test)] +mod tests { + #[test] + fn only_the_listed_programs_get_passes() { + super::begin([0; 16]); + assert_eq!(super::passes(), 0); + super::begin(0x5212_83e5_0211_e301_e7fa_ed9e_0299_dc22u128.to_be_bytes()); + assert_eq!(super::passes(), super::FOLD); + super::begin(0x3024_35a1_3c4c_b152_2a2c_e785_8fab_7e34u128.to_be_bytes()); + assert_eq!(super::passes(), super::FACTS); + } +} diff --git a/crates/victory-shader/src/emit/mod.rs b/crates/victory-shader/src/emit/mod.rs index 2f413de87d..a811cbbda7 100644 --- a/crates/victory-shader/src/emit/mod.rs +++ b/crates/victory-shader/src/emit/mod.rs @@ -777,6 +777,7 @@ fn emit_program( 0xba30_5538_e28d_414c_af39_a51a_4bc2_f308 | 0xd635_3bf6_df15_ff8e_c4aa_aec1_0dbf_3974 ) && matches!(native.io, crate::native::StageIo::Cs(cs) if cs.threads == [64, 1, 1]); + lower::amd::begin(c.digest); let l = lower::lower_program(&parts, box_rehydration, tiled_lighting_uint_srvs(c.digest), tiled_ambient(c, native))?; let wave_size = l.wave_size; let shader = HostShader { diff --git a/crates/victory-shader/src/emit/shader.rs b/crates/victory-shader/src/emit/shader.rs index 429a870146..b9610689b4 100644 --- a/crates/victory-shader/src/emit/shader.rs +++ b/crates/victory-shader/src/emit/shader.rs @@ -550,7 +550,7 @@ impl Shader { // The clean-up, before anything is declared about the code: a // feature whose last use it removed must not be declared (the // validator compares the flags with what the code uses). - let passes = super::shader_opt() & super::bitcode::opt::MODULE; + let passes = (super::shader_opt() | super::lower::amd::passes()) & super::bitcode::opt::MODULE; if passes != 0 { self.m.optimise(passes); let used = self.m.usage(); diff --git a/crates/victory-shader/src/lib.rs b/crates/victory-shader/src/lib.rs index 74838d0588..0805da8270 100644 --- a/crates/victory-shader/src/lib.rs +++ b/crates/victory-shader/src/lib.rs @@ -62,6 +62,7 @@ translation_inputs! { "emit/guest_address.rs", "emit/intersect.rs", "emit/lower.rs", + "emit/lower/amd.rs", "emit/mod.rs", "emit/own_bits.rs", "emit/packed_mask.rs",