Skip to content
Closed
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
16 changes: 9 additions & 7 deletions tools/shader-compiler/src/hlsl/emitter/resource_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ impl<'a> Emitter<'a> {
if self.pixel_heap {
lane_reads::step(ins, sym, self.one_word_vector_mask());
}
// Dataflow key of a scalar location: SGPR number, or 1000+ for a lane-spill slot.
// Dataflow key of a scalar location: SGPR number (including vcc_lo/vcc_hi), or 1000+ for a lane-spill slot.
let sg = |o: &Opnd| match o {
Opnd::Sgpr(n) => Some(*n as u16),
Opnd::VccLo => Some(106),
Opnd::VccHi => Some(107),
Opnd::Temp(n) if *n >= LANE_TEMP_BASE => Some(1000 + (*n - LANE_TEMP_BASE)),
_ => None,
};
Expand Down Expand Up @@ -139,7 +141,7 @@ impl<'a> Emitter<'a> {
if let (Some(d), Some(source)) = (ins.dst.first().and_then(sg), ins.src.first().and_then(sg)) {
let entry = match sym.get(&source) {
Some(Sym::Table(t)) => Some(*t),
None if !written.contains(&source) => u8::try_from(source).ok(),
None if source < 106 && !written.contains(&source) => u8::try_from(source).ok(),
_ => None,
};
if let Some(index) = entry.and_then(|n| sampler_heap::index(self.ex, n)) {
Expand Down Expand Up @@ -172,7 +174,7 @@ impl<'a> Emitter<'a> {
// A never-written user SGPR copied before use is still a table pointer.
let s = ins.src.first().and_then(sg);
match s {
Some(s) if !written.contains(&s) => {
Some(s) if s < 106 && !written.contains(&s) => {
sym.insert(d, Sym::Table(s as u8));
}
_ => {
Expand Down Expand Up @@ -205,7 +207,7 @@ impl<'a> Emitter<'a> {
None => match s {
// A never-written user SGPR is a root table pointer (see
// s_mov_b32); a 64-bit copy carries it in the low half.
Some(s) if k == 0 && !written.contains(&s) => {
Some(s) if k == 0 && s < 106 && !written.contains(&s) => {
sym.insert(d, Sym::Table(s as u8));
}
_ => {
Expand Down Expand Up @@ -299,7 +301,7 @@ impl<'a> Emitter<'a> {
let d = ins.dst.first().and_then(sg).ok_or("s_load: bad dst")?;
let table = match sym.get(&b) {
Some(Sym::Table(t)) => *t,
None if !written.contains(&b) => b as u8,
None if b < 106 && !written.contains(&b) => b as u8,
other => {
return Err(format!(
"s_load at {:#x}: base s{b} is not a root table pointer ({other:?})",
Expand All @@ -319,7 +321,7 @@ impl<'a> Emitter<'a> {
return Err(format!("s_load at {:#x}: heap buffer in a pixel shader", ins.offset));
}
let heap_offset = sym.get(&soff) == Some(&Sym::HeapOffset)
|| (self.compute_heap && !self.pixel_heap && soff < 106 && written.contains(&soff));
|| (self.compute_heap && !self.pixel_heap && soff <= 107 && written.contains(&soff));
if self.resource_heap_base == Some(table) && matches!(n, 4 | 8)
&& (ins.aux.imm == 0 || (ins.aux.imm >= 0 && ins.aux.imm % 32 == 0 && sym.get(&soff) == Some(&Sym::HeapOffset)))
&& heap_offset {
Expand All @@ -335,7 +337,7 @@ impl<'a> Emitter<'a> {
// heap (CS_RaytracingResolve: per-material index << 4, then a waterfall).
// Statically resolved sampler offsets keep their own path below.
if self.sampler_heap_base == Some(table) && n == 4 && ins.aux.imm == 0
&& soff < 106 && written.contains(&soff)
&& soff <= 107 && written.contains(&soff)
&& (!self.pixel_heap || sym.get(&soff) == Some(&Sym::HeapSamplerOffset))
&& !matches!(sym.get(&soff), Some(Sym::SamplerOffset(_)))
{
Expand Down
4 changes: 2 additions & 2 deletions tools/shader-compiler/src/hlsl/emitter/scalar_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ impl<'a> Emitter<'a> {
if ins.op <= 4 {
if let Some(Res::HeapLoad(offset)) = self.res.get(&idx).and_then(|v| v.first()).copied() {
let value = ssrc_name(u32::from(offset))?;
self.regs.insert(value.clone());
self.touch(&sreg_opnd(offset as u8));
let dst = d.ok_or("missing direct descriptor destination")?;
self.touch(&dst);
let byte_offset = if ins.aux.imm == 0 { value }
Expand All @@ -34,7 +34,7 @@ impl<'a> Emitter<'a> {
}
if let Some(Res::HeapSamplerLoad(offset)) = self.res.get(&idx).and_then(|v| v.first()).copied() {
let value = ssrc_name(u32::from(offset))?;
self.regs.insert(value.clone());
self.touch(&sreg_opnd(offset as u8));
let dst = d.ok_or("missing sampler descriptor destination")?;
self.touch(&dst);
// The guest sampler-heap pointer is the heap start (as for the static
Expand Down
2 changes: 1 addition & 1 deletion tools/shader-compiler/src/hlsl/wave_loops/scalar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ pub(super) fn scalar_step(em: &Emitter<'_>, flow: &Flow, effects: &[Effect], i:
Some([Res::Raw(_, false) | Res::Buf(_, false)]) => {
fixed_buffer(em, flow, effects, i, 0)
}
Some([Res::HeapLoad(0..=105) | Res::HeapBuffer(0..=105)]) => em.compute_heap,
Some([Res::HeapLoad(0..=107) | Res::HeapBuffer(0..=107)]) => em.compute_heap,
Some([Res::CodeTbl | Res::HeapSamplerLoad(_)]) => true,
None => op.op <= 4, // Descriptor-only load resolved before emission.
_ => false,
Expand Down
19 changes: 19 additions & 0 deletions tools/shader-compiler/src/tests/hlsl/sampler_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,25 @@ fn pixel_heap_refuses_what_it_cannot_prove() {
assert!(refusal(&pixel(&load)).contains("unknown component type"));
}

#[test]
fn pixel_heap_allows_vcc_offsets() {
for (sdst, soff) in [(106u32, 106u32 << 25), (107u32, 107u32 << 25)] {
let mut vcc = SAMPLE;
vcc[0] = (0x8f00_850a & !(0x7f << 16)) | (sdst << 16); // vcc_{lo,hi} = s10 << 5
vcc[3] = soff; // s[4:11] = heap[s14:15][vcc_{lo,hi}]
let out = super::super::translate(&pixel(&vcc)).unwrap();
let name = if sdst == 106 { "vcc_lo" } else { "vcc_hi" };
assert!(out.hlsl.contains(&format!("s4 = tb_heap_index({name} >> 5)")), "{}", out.hlsl);
assert!(!out.hlsl.contains(&format!("uint {name} =")), "{}", out.hlsl);
}
// A vector comparison overwrites vcc_lo/vcc_hi and invalidates the offset proof.
let mut clobbered = SAMPLE.to_vec();
clobbered[0] = (0x8f00_850a & !(0x7f << 16)) | (106 << 16);
clobbered[3] = 106 << 25;
clobbered.insert(1, 0x7c94_0904); // v_cmp_eq_u32 vcc, v4, v4
assert!(refusal(&pixel(&clobbered)).contains("dynamic soffset unsupported"));
}

#[test]
fn sampled_value_must_not_keep_sampler_offset_proof() {
// v7 = v5 << 4; sample overwrites v7; readfirstlane s1,v7.
Expand Down