diff --git a/crates/viport-shader/src/emit/lower.rs b/crates/viport-shader/src/emit/lower.rs index 05ccaeb..c0ecb86 100644 --- a/crates/viport-shader/src/emit/lower.rs +++ b/crates/viport-shader/src/emit/lower.rs @@ -9920,6 +9920,17 @@ impl<'a> Lower<'a> { unreachable!() }; let name = inst.name(); + if name == "buffer_gl0_inv" || name == "buffer_gl1_inv" { + // Console cache coherence: gl0 writes back and invalidates the + // per-CU shader L0, gl1 invalidates GL1, so one wavefront's + // writes become visible to others. D3D12 already guarantees UAV + // coherence across wavefronts and dispatches, DXIL has no + // equivalent instruction, and this project's host-visible + // writeback comes from command-stream GpuWrite ranges rather + // than shader cache hints. Ordering is kept by the surrounding + // s_waitcnt/s_barrier, which the translator does lower. + return Ok(()); + } if *lds || *tfe { return Err("a buffer access to LDS or with tfe"); } @@ -11803,6 +11814,14 @@ mod tests { )); } + #[test] + fn buffer_cache_invalidations_lower_as_no_ops() { + // MUBUF opcode 0x071/0x072 with no data operand: the title asks the + // host to invalidate its cached view of a buffer. + assert!(lowers(&[0xE1C4_0000, 0, S_ENDPGM], 0).is_ok(), "buffer_gl0_inv"); + assert!(lowers(&[0xE1C8_0000, 0, S_ENDPGM], 0).is_ok(), "buffer_gl1_inv"); + } + #[test] fn a_scalar_carry_chain_reaches_the_select() { // The high dword of a 64-bit add or subtract, then a select on the diff --git a/crates/viport-shader/src/resource.rs b/crates/viport-shader/src/resource.rs index 0857a4a..8f59586 100644 --- a/crates/viport-shader/src/resource.rs +++ b/crates/viport-shader/src/resource.rs @@ -221,7 +221,14 @@ pub fn track( descriptor(s, Role::Sampler)?; } } - Fields::Buffer { rsrc, .. } => descriptor(rsrc, Role::Resource)?, + // A cache invalidation names a buffer only to scope the + // address range it flushes; it reads no data through the + // descriptor. Lowering one is a no-op on the host, so there + // is no descriptor to keep alive for it. + Fields::Buffer { rsrc, .. } if !inst.name().ends_with("_inv") => { + descriptor(rsrc, Role::Resource)? + } + Fields::Buffer { .. } => {} Fields::Smem { base, .. } if inst.name().starts_with("s_buffer_") => { descriptor(base, Role::Resource)?; }