|
|
@@ -411,6 +411,68 @@ mod tests {
|
|
|
use super::*;
|
|
|
use crate::native::{ComputeIo, StageIo};
|
|
|
|
|
|
+ /// A pixel shader writing SV_StencilRef (channel y of `exp mrtz`).
|
|
|
+ /// DXC sets ShaderFlags.StencilRef (bit 11) for a pixel shader whose
|
|
|
+ /// output signature has SV_StencilRef, and the feature bit
|
|
|
+ /// D3D_SHADER_FEATURE_STENCIL_REF (0x200) in SFI0; the validator checks
|
|
|
+ /// both against the module.
|
|
|
+ #[test]
|
|
|
+ fn a_stencil_export_declares_the_stencil_ref_feature() {
|
|
|
+ let words = [
|
|
|
+ 0x7E00_02F2u32, // v_mov_b32 v0, 1.0
|
|
|
+ 0x7E02_0285, // v_mov_b32 v1, 5
|
|
|
+ 0xF800_1883,
|
|
|
+ 0x0000_0100, // exp mrtz v0, v1, off, off done vm
|
|
|
+ 0xBF81_0000,
|
|
|
+ ];
|
|
|
+ let native = NativeProgram {
|
|
|
+ stage: HwStage::Ps,
|
|
|
+ wave64: false,
|
|
|
+ vgprs: 2,
|
|
|
+ layout: vec![],
|
|
|
+ used: vec![],
|
|
|
+ io: StageIo::Ps {
|
|
|
+ inputs: vec![],
|
|
|
+ input_addr: 0,
|
|
|
+ db_shader_control: 0,
|
|
|
+ patches: vec![],
|
|
|
+ },
|
|
|
+ code: words.iter().flat_map(|w| w.to_le_bytes()).collect(),
|
|
|
+ };
|
|
|
+ let el = |name: &str, kind, comp| SigElement {
|
|
|
+ name: name.into(),
|
|
|
+ index: 0,
|
|
|
+ kind,
|
|
|
+ comp,
|
|
|
+ interp: 0,
|
|
|
+ row: None,
|
|
|
+ col: 0,
|
|
|
+ cols: 1,
|
|
|
+ usage: 1,
|
|
|
+ half: false,
|
|
|
+ };
|
|
|
+ let osg1 =
|
|
|
+ container::signature(&[el("SV_Depth", 17, 9), el("SV_StencilRef", 20, 5)], false);
|
|
|
+ let bytes = crate::dxbc::build(&[(FourCC::OSG1, &osg1)]);
|
|
|
+ let c = Container::parse(&bytes).unwrap();
|
|
|
+ let p = ir::build(&native.patched_code(), native.wave64, native.vgprs).unwrap();
|
|
|
+ let res = resource::track(&p, &native.layout, native.stage).unwrap();
|
|
|
+ let io = io::raise(&p, &native).unwrap();
|
|
|
+ let st = structure::structure(&p).unwrap();
|
|
|
+ let out = emit(&c, &native, &p, &st, &io, &res).unwrap();
|
|
|
+ // dxil.dll, where there is one, checks the flags against the module.
|
|
|
+ #[cfg(windows)]
|
|
|
+ if let Ok(mut v) = super::validator::Validator::load(
|
|
|
+ super::validator::Validator::default_path().as_deref(),
|
|
|
+ ) {
|
|
|
+ v.validate(&mut out.dxil.clone()).unwrap();
|
|
|
+ }
|
|
|
+ let host = Container::parse(&out.dxil).unwrap();
|
|
|
+ let sfi0 = host.part(FourCC::SFI0).unwrap().data;
|
|
|
+ let features = u64::from_le_bytes(sfi0.try_into().unwrap());
|
|
|
+ assert_ne!(features & 0x200, 0, "SFI0 {features:#x}: no StencilRef");
|
|
|
+ }
|
|
|
+
|
|
|
/// A wave64 compute program that writes only EXEC's high dword
|
|
|
/// (`s_mov_b32 exec_hi, 0`) before a vector instruction. The new mask is
|
|
|
/// opaque and keyed by the unchanged low dword, so building its lane bit
|