Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions crates/viport-shader/src/emit/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion crates/viport-shader/src/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
Expand Down