Publish the pareto-residency Windows build and portable launcher

This commit is contained in:
codec_d committed 2026-11-25 22:33:14 -08:00
1 parent efeef1d65b
commit 545f89019e
20 files changed
+1671 -217

No files matched your search

+35 -4
View File
@@ -1228,12 +1228,43 @@ fn translated_compute_matches_pc() {
let mut root_views: Vec<(u8, bool)> = cs_c.root_cbvs.iter().map(|&s| (s, false)).collect();
root_views.extend(cs_c.root_srvs.iter().map(|&s| (s, true)));
root_views.sort_unstable();
let view_strides: Vec<u32> = views
.iter()
.map(|v| match *v {
View::RawUav(_) => 1,
View::HalfUav(_) => 8,
View::Buffer { stride, .. } => match stride {
Stride::Raw => 1,
Stride::Typed => 16,
Stride::Structured(s) => s,
Stride::Format(f, bytes) => {
let kind = match f.0 as u32 {
3 | 7 | 12 | 17 | 25 | 30 | 36 | 42 | 50 | 57 | 62 => {
super::VIEW_INTEGER
}
4 | 8 | 14 | 18 | 32 | 38 | 43 | 52 | 59 | 64 => {
super::VIEW_INTEGER | super::VIEW_SIGNED
}
_ => 0,
};
bytes | kind
}
},
_ => 0,
})
.collect();
for (n, (slot, srv)) in root_views.into_iter().enumerate() {
assert_eq!(slot, 4 + u8::from(srv), "{name}: root view");
let data = if srv {
root_srv.clone()
let data = if srv
&& (slot == super::SLOT_STRIDES || slot == super::SLOT_TABLE_STRIDES)
{
view_strides.clone()
} else {
root_cbv.clone()
assert_eq!(slot, 4 + u8::from(srv), "{name}: root view");
if srv {
root_srv.clone()
} else {
root_cbv.clone()
}
};
roots.push((1 + n as u32, Root::View { srv, data }));
}
+46
View File
@@ -1004,6 +1004,12 @@ pub enum View<'a> {
UintTextureUav(u32, u32),
/// A typed RGBA16F buffer UAV of this many elements, zeroed.
HalfUav(u32),
/// A typed buffer UAV pre-filled with `data` (`format`, bytes per element).
TypedUav {
data: &'a [u32],
format: DXGI_FORMAT,
elem_bytes: u32,
},
/// A constant buffer of these dwords.
Cbv(&'a [u32]),
/// A buffer SRV over these dwords.
@@ -1279,6 +1285,46 @@ impl Host {
)?;
uavs.push((b, None, n, rb));
}
View::TypedUav {
data,
format,
elem_bytes,
} => {
let n = data.len() as u32;
let bytes = u64::from(n) * 4;
let elements = (bytes / u64::from(elem_bytes)) as u32;
let b = make(
D3D12_HEAP_TYPE_DEFAULT,
&buffer(bytes, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS),
D3D12_RESOURCE_STATE_COPY_DEST,
)?;
let up = upload(data)?;
list.CopyBufferRegion(&b, 0, &up, 0, bytes);
list.ResourceBarrier(&[transition(
&b,
D3D12_RESOURCE_STATE_COPY_DEST,
D3D12_RESOURCE_STATE_UNORDERED_ACCESS,
)]);
keep.push(up);
let desc = D3D12_UNORDERED_ACCESS_VIEW_DESC {
Format: format,
ViewDimension: D3D12_UAV_DIMENSION_BUFFER,
Anonymous: D3D12_UNORDERED_ACCESS_VIEW_DESC_0 {
Buffer: D3D12_BUFFER_UAV {
NumElements: elements,
Flags: D3D12_BUFFER_UAV_FLAG_NONE,
..Default::default()
},
},
};
dev.CreateUnorderedAccessView(&b, None, Some(&desc), at);
let rb = make(
D3D12_HEAP_TYPE_READBACK,
&buffer(bytes, D3D12_RESOURCE_FLAG_NONE),
D3D12_RESOURCE_STATE_COPY_DEST,
)?;
uavs.push((b, None, n, rb));
}
View::TextureUav(w, h) => {
let t = make(
D3D12_HEAP_TYPE_DEFAULT,
+19 -15
View File
@@ -7501,7 +7501,7 @@ impl<'a> Lower<'a> {
/// `ResourceHeap`): read from the host's table by heap slot in the
/// current block.
fn slot_stride(&mut self, src: &Source) -> Result<Option<V>, Why> {
let word = self.slot_word(src)?;
let word = self.slot_word(src, false)?;
Ok(word.map(|word| {
let bits = self.s.m.i32(super::shader::VIEW_STRIDE_BITS);
self.s.m.bin(self.cur, Bin::And, word, bits)
@@ -7509,10 +7509,9 @@ impl<'a> Lower<'a> {
}
/// Whether the typed buffer view `src` names is one of an integer format,
/// and whether a signed one, as [`Self::slot_stride`] (`None`: a view the
/// program does not pick from the heap).
/// and whether a signed one (`ResourceHeap` or `Table`).
fn integer_view(&mut self, src: &Source) -> Result<Option<(V, V)>, Why> {
let Some(word) = self.slot_word(src)? else {
let Some(word) = self.slot_word(src, true)? else {
return Ok(None);
};
let c = self.cur;
@@ -7526,19 +7525,22 @@ impl<'a> Lower<'a> {
}
/// The host's word for the buffer view `src` names: its stride and
/// format kind ([`super::shader::SLOT_STRIDES`]).
fn slot_word(&mut self, src: &Source) -> Result<Option<V>, Why> {
/// format kind ([`super::shader::SLOT_STRIDES`] for `ResourceHeap`,
/// [`super::shader::SLOT_TABLE_STRIDES`] for `Table` when `allow_table`).
fn slot_word(&mut self, src: &Source, allow_table: bool) -> Result<Option<V>, Why> {
let Source::Loaded { load, first } = src else {
return Ok(None);
};
let heap = self
let srv_slot = match self
.scalar
.get(load)
.and_then(|a| self.x.native.layout.get(a.param))
.is_some_and(|p| p.root == RootType::ResourceHeap);
if !heap {
return Ok(None);
}
.map(|p| p.root)
{
Some(RootType::ResourceHeap) => super::shader::SLOT_STRIDES,
Some(RootType::Table) if allow_table => super::shader::SLOT_TABLE_STRIDES,
_ => return Ok(None),
};
let key = (self.cur, *load, *first);
if let Some(&v) = self.strides.get(&key) {
return Ok(Some(v));
@@ -7553,7 +7555,7 @@ impl<'a> Lower<'a> {
self.s.m.tag(slot, Tag::Clamp);
let two = self.s.m.i32(2);
let byte = self.s.m.bin(c, Bin::Shl, slot, two);
let h = self.s.root_srv_handle(super::shader::SLOT_STRIDES);
let h = self.s.root_srv_handle(srv_slot);
let iu = self.s.m.undef(self.s.t.i32);
let mask = self.s.m.i8(1);
let align = self.s.m.i32(4);
@@ -11901,9 +11903,11 @@ impl<'a> Lower<'a> {
// store; through a view of an integer format it is a 16-bit
// integer, zero- or sign-extended (VIctory 4243a96a: the face
// network keeps its halves in UINT views; its output was
// noise). shortcut: that is known of the views a program
// picks from the heap, not of those in its tables; and the
// handle stays a float one, whose bits the drivers pass.
// noise). Both `ResourceHeap` (`SLOT_STRIDES`) and `Table`
// (`SLOT_TABLE_STRIDES`, dynamic table snapshots included)
// populate the view-kind bits, while the handle stays a float
// one (`0x409`), whose raw bits RTX and WARP pass bit-exact
// without extra CFG blocks or touching non-d16 shaders.
let integer = if typed { self.integer_view(src)? } else { None };
let mut wide = Vec::new();
for k in 0..count {
+55 -12
View File
@@ -122,7 +122,7 @@ pub use lower::{host_settings, set_host_max_wave, set_host_rdna};
pub use rect::rect_list_gs;
pub use shader::{
MEMORY_FAULTS, MEMORY_PAGES, MEMORY_READ_ONLY, ROOT_CBV_SPACE, SAMPLER_SPACE, SLOT_FAULTS, SLOT_MEMORY, SLOT_STRIDES,
SLOT_STRIDES_COUNT, USER_DATA_SPACE, VIEW_INTEGER, VIEW_SIGNED, VIEW_STRIDE_BITS, USER_DISPATCH_THREADS_X, USER_MEMORY_BASE, USER_ROOT_ADDRESS, USER_VIEW_ADDRESS, USER_VIEW_BIAS,
SLOT_STRIDES_COUNT, SLOT_TABLE_STRIDES, USER_DATA_SPACE, VIEW_INTEGER, VIEW_SIGNED, VIEW_STRIDE_BITS, USER_DISPATCH_THREADS_X, USER_MEMORY_BASE, USER_ROOT_ADDRESS, USER_VIEW_ADDRESS, USER_VIEW_BIAS,
raw_views, set_raw_views, set_view_heap_limit, view_heap_limit,
};
@@ -485,17 +485,45 @@ pub fn emit(
};
// The program in two other forms: without its early-outs, and
// without any branch that only skips code no lane is left for.
let form = |p: Option<ir::Program>| {
p.and_then(|p| {
let st = structure::structure(&p).ok()?;
let io = io::raise(&p, native).ok()?;
let res = resource::track(&p, &native.layout, native.stage, Some(&st)).ok()?;
Some((p, st, io, res))
})
let form = |label: &str, p: Option<ir::Program>| {
let Some(p) = p else {
if why {
eprintln!("WAVE64-FORM {label}: ir returned None");
}
return None;
};
let st = match structure::structure(&p) {
Ok(st) => st,
Err(e) => {
if why {
eprintln!("WAVE64-FORM {label}: structure failed: {e}");
}
return None;
}
};
let io = match io::raise(&p, native) {
Ok(io) => io,
Err(e) => {
if why {
eprintln!("WAVE64-FORM {label}: io::raise failed: {e}");
}
return None;
}
};
let res = match resource::track(&p, &native.layout, native.stage, Some(&st)) {
Ok(res) => res,
Err(e) => {
if why {
eprintln!("WAVE64-FORM {label}: resource::track failed: {e}");
}
return None;
}
};
Some((p, st, io, res))
};
let forms = [
("without early-outs", form(ir::without_early_outs(p))),
("without skips", form(ir::without_skips(p, false))),
("without early-outs", form("without early-outs", ir::without_early_outs(p))),
("without skips", form("without skips", ir::without_skips(p, false))),
];
for (name, f) in &forms {
if let Some((p, st, io, res)) = f {
@@ -539,7 +567,7 @@ pub fn emit(
// lane runs, where the two host waves can exchange.
// (`VICTORY_WAVE_DEEP_SKIPS=0` and `VICTORY_WAVE_WIDE=0` turn the two off.)
let deep_on = std::env::var_os("VICTORY_WAVE_DEEP_SKIPS").is_none_or(|v| v != "0");
let deep = if deep_on { form(ir::without_skips(p, true)) } else { None };
let deep = if deep_on { form("without skips, scalars followed", ir::without_skips(p, true)) } else { None };
if let Some((p, st, io, res)) = &deep {
let again = emit_program(c, native, p, st, io, res);
report("without skips, scalars followed", &again);
@@ -700,7 +728,22 @@ fn widen(
|| matches!(&r, Ok((_, Some(64)))) && !needs.is_empty();
if !stuck {
if why {
eprintln!("WAVE64-WIDE {} branches taken wave-wide", wide.len());
let order = ir::reverse_postorder(&p.blocks);
let mut rpo = vec![0usize; p.blocks.len()];
for (i, &b) in order.iter().enumerate() {
rpo[b] = i;
}
let mut sorted: Vec<usize> = wide.iter().copied().collect();
sorted.sort_unstable();
let desc: Vec<String> = sorted
.iter()
.map(|&b| {
let back = matches!(p.blocks[b].exit, ir::Exit::Branch { taken, not_taken } if rpo[taken] <= rpo[b] || rpo[not_taken] <= rpo[b]);
let nm = p.blocks[b].insts.last().map_or("?", |i| i.name());
format!("B{b}({nm}{})", if back { ",BACK" } else { "" })
})
.collect();
eprintln!("WAVE64-WIDE {} branches taken wave-wide: [{}]", wide.len(), desc.join(", "));
}
return r;
}
+5
View File
@@ -24,6 +24,11 @@ pub const ROOT_CBV_SPACE: u32 = 1;
/// root SRV also tells the host that the buffer views of the whole heap
/// must be ready when it runs, not only those its tables name.
pub const SLOT_STRIDES: u8 = 255;
/// The same table of strides and format kinds as [`SLOT_STRIDES`], bound for
/// shaders that only inspect views from descriptor tables (`RootType::Table`).
/// Kept distinct from [`SLOT_STRIDES`] so the host binds the table without
/// running the full bindless heap buffer sweep.
pub const SLOT_TABLE_STRIDES: u8 = 252;
/// The bits of a [`SLOT_STRIDES`] dword that hold the stride.
pub const VIEW_STRIDE_BITS: u32 = (1 << 30) - 1;
/// In a [`SLOT_STRIDES`] dword: a typed buffer view of an integer format
@@ -2057,3 +2057,337 @@ fn rdna_forms_give_what_the_spelled_out_ones_give() {
}
}
}
/// MUBUF `op vdata, vaddr, s[srsrc:srsrc+3], 0 idxen`.
const fn mubuf_idxen(op: u8, vdata: u8, vaddr: u8, srsrc: u8) -> [u32; 2] {
[
0x38 << 26 | (op as u32) << 18 | 1 << 13,
0x80 << 24 | ((srsrc as u32 >> 2) & 0x1F) << 16 | (vdata as u32) << 8 | vaddr as u32,
]
}
/// SMEM `s_load_dwordx4 s[dst:dst+3], s[base:base+1], byte_offset` (soffset = null).
const fn s_load_dwordx4_off(dst: u8, base: u8, byte_offset: u32) -> [u32; 2] {
[
0x3D << 26 | 0x02 << 18 | (dst as u32) << 6 | (base as u32 >> 1),
(125 << 25) | (byte_offset & 0x1F_FFFF),
]
}
/// Builds a compute shader whose descriptors live in a `RootType::Table` at
/// `s4` (like `compute_graph_ops` and `ped_standard_head_cs`).
fn build_table_typed_cs(body: &[u32], used: Vec<UsedResource>) -> HostShader {
let mut words = Vec::new();
words.push(s_mov_b32(5, 0x80)); // s5 = 0
words.extend_from_slice(body);
words.push(S_ENDPGM);
let code: Vec<u8> = words.iter().flat_map(|w| w.to_le_bytes()).collect();
let native = NativeProgram {
stage: HwStage::Cs,
wave64: false,
vgprs: 8,
layout: vec![RootParam {
root: RootType::Table,
table_offset_dwords: 0,
sgprs: 1,
base_register: 0,
user_data: 4,
slot: 0,
}],
used,
io: StageIo::Cs(ComputeIo {
rsrc2: 5 << 1, // 5 user SGPRs: s0..s4
threads: [4, 1, 1],
}),
code,
};
let p = ir::build(&native.code, native.wave64, native.vgprs).expect("ir::build");
let st = structure::structure(&p).expect("structure");
let res =
resource::track(&p, &native.layout, native.stage, Some(&st)).expect("resource::track");
let io = io::raise(&p, &native).expect("io::raise");
let lowered = lower::lower(&lower::Parts {
native: &native,
p: &p,
st: &st,
io: &io,
res: &res,
inputs: Vec::new(),
outputs: Vec::new(),
prims: Vec::new(),
mesh_stride: 0,
})
.expect("lower");
let shader = HostShader {
stage: HwStage::Cs,
dxil: lowered.dxil,
user_data: lowered.user_data,
samplers: lowered.samplers,
static_samplers: Vec::new(),
root_cbvs: lowered.root_cbvs,
root_srvs: lowered.root_srvs,
root_uavs: lowered.root_uavs,
root_indexed_views: res.root_indexed_views,
};
if let Ok(mut v) = validator::Validator::load(validator::Validator::default_path().as_deref()) {
let mut copy = shader.dxil.clone();
v.validate(&mut copy).expect("DXIL validation failed");
}
shader
}
/// `compute_graph_ops` (facial lip-sync & wrapped submesh solver) binds
/// `R16G16B16A16_UINT` / `R16_UINT` UAVs via `RootType::Table` (which on NVIDIA
/// are snapshotted into dynamic descriptor slots) and reads/writes FP16 bit
/// patterns with `buffer_load_format_d16_xyzw` and `buffer_store_format_d16_xyzw`.
/// Verify bit-exact round-trips for UINT, SINT, and FLOAT views (including
/// non-zero table offsets matching dynamic descriptor snapshots) on hardware
/// GPU and WARP.
#[test]
fn typed_d16_table_uav_roundtrip_uint_sint_and_float() {
use windows::Win32::Graphics::Dxgi::Common::{
DXGI_FORMAT_R16G16B16A16_FLOAT, DXGI_FORMAT_R16G16B16A16_SINT,
DXGI_FORMAT_R16G16B16A16_UINT,
};
let _serial = ONE_AT_A_TIME.lock().unwrap_or_else(|e| e.into_inner());
let mut body = Vec::new();
// s[8:11] = table[0] (src typed UAV), s[12:15] = table[1] (dst typed UAV),
// s[16:19] = table[2] (raw UAV dump of loaded v[2:3]).
body.extend_from_slice(&s_load_dwordx4_off(8, 4, 0));
body.extend_from_slice(&s_load_dwordx4_off(12, 4, 32));
body.extend_from_slice(&s_load_dwordx4_off(16, 4, 64));
// buffer_load_format_d16_xyzw v[2:3], v0, s[8:11], 0 idxen (op 0x83)
body.extend_from_slice(&mubuf_idxen(0x83, 2, 0, 8));
// buffer_store_format_d16_xyzw v[2:3], v0, s[12:15], 0 idxen (op 0x87)
body.extend_from_slice(&mubuf_idxen(0x87, 2, 0, 12));
// Also dump thread 0's loaded v[2:3] into raw UAV (table[2]) to verify the load itself.
// v4 = v0 << 3 (byte offset = thread * 8)
body.push(0x3408_0083); // v_lshlrev_b32 v4, 3, v0
// buffer_store_dwordx2 v[2:3], v4, s[16:19], 0 offen (op 0x1D, offen bit 12)
body.extend_from_slice(&[
0x38 << 26 | 0x1D << 18 | 1 << 12,
0x80 << 24 | (16u32 >> 2) << 16 | (2u32 << 8) | 4u32,
]);
let used = (0..3u32)
.map(|k| UsedResource {
kind: ResourceType::Uav,
root: RootType::Table,
table_offset_dwords: k * 8,
lower_bound: k,
stride: 4,
dwords: 4,
user_data: 4,
slot: 0,
})
.collect();
let shader = build_table_typed_cs(&body, used);
assert!(
shader.root_srvs.contains(&super::SLOT_TABLE_STRIDES),
"table typed d16 shader should request SLOT_TABLE_STRIDES"
);
assert!(
!shader.root_srvs.contains(&super::SLOT_STRIDES),
"table-only shader must not trigger the bindless SLOT_STRIDES sweep"
);
// 4 elements x 4 u16 channels = 8 u32 dwords.
// Includes FP16 subnormal (0x0001), -0.0 (0x8000), 1.0 (0x3C00), -1.0 (0xBC00),
// NaN (0x7E00), max u16 (0xFFFF), and arbitrary patterns.
let uint_bits: [u32; 8] = [
0x3C00_0001, 0x7E00_BC00,
0xFFFF_8000, 0xABCD_1234,
0x0002_0000, 0x7BFF_FBFF,
0xDEAD_BEEF, 0xCAFE_BABE,
];
let sint_bits: [u32; 8] = [
0xFFFF_8000, 0x7FFF_0001,
0xC000_0000, 0x8001_7FFE,
0xFFFF_FFFF, 0x0000_0000,
0xFEDC_BA98, 0x7654_3210,
];
// Normal finite FP16 values that round-trip cleanly through f32.
let float_bits: [u32; 8] = [
0x4000_3C00, 0x3800_BC00, // 1.0, 2.0, -1.0, 0.5
0xC200_3400, 0x4500_0000, // 0.25, -3.0, 0.0, 5.0
0x3E00_BE00, 0x4400_C400, // -1.5, 1.5, -4.0, 4.0
0x3C00_0000, 0x4200_C000, // 0.0, 1.0, -2.0, 3.0
];
let zeros = [0u32; 8];
let cases = [
("R16G16B16A16_UINT @0", DXGI_FORMAT_R16G16B16A16_UINT, 8 | super::VIEW_INTEGER, &uint_bits, 0u32),
("R16G16B16A16_UINT @3 (dynamic offset)", DXGI_FORMAT_R16G16B16A16_UINT, 8 | super::VIEW_INTEGER, &uint_bits, 3u32),
("R16G16B16A16_SINT @0", DXGI_FORMAT_R16G16B16A16_SINT, 8 | super::VIEW_INTEGER | super::VIEW_SIGNED, &sint_bits, 0u32),
("R16G16B16A16_FLOAT @0", DXGI_FORMAT_R16G16B16A16_FLOAT, 8, &float_bits, 0u32),
];
for (backend, warp) in [("hardware", false), ("warp", true)] {
let Ok(host) = Host::new(warp) else { continue };
let (root, pso) = host
.compute_pipeline(&shader)
.unwrap_or_else(|e| panic!("{backend}: compute_pipeline failed: {e}"));
for &(label, format, stride_word, input, base_slot) in &cases {
let mut views = Vec::new();
let mut strides = Vec::new();
for _ in 0..base_slot {
views.push(View::RawUav(1));
strides.push(0u32);
}
let uav_base = base_slot as usize;
views.push(View::TypedUav { data: input, format, elem_bytes: 8 });
strides.push(stride_word);
views.push(View::TypedUav { data: &zeros, format, elem_bytes: 8 });
strides.push(stride_word);
views.push(View::RawUav(8));
strides.push(1);
let mut ud = vec![0u32; shader.user_data_dwords().max(1) as usize];
for u in &shader.user_data {
if u.root == RootType::Table && u.slot == 0 {
ud[u.index as usize] = base_slot * 32;
}
}
let out = host
.dispatch(
&root,
&pso,
&Dispatch {
roots: vec![
(0, Root::Constants(ud)),
(1, Root::View { srv: true, data: strides }),
],
views: &views,
samplers: &[],
groups: [1, 1, 1],
},
)
.unwrap_or_else(|e| panic!("{backend} {label}: dispatch failed: {e}"));
assert_eq!(
out[uav_base + 2],
input,
"{backend} {label}: buffer_load_format_d16_xyzw mismatch"
);
assert_eq!(
out[uav_base + 1],
input,
"{backend} {label}: buffer_store_format_d16_xyzw mismatch"
);
}
}
}
/// Non-`d16` typed loads (`buffer_load_format_x`) are used by
/// `CS_BlendshapeTranslationsHSSGraphOutputExtract` (reading `HSSGraphOut`
/// `R16_UINT`) and `CS_PedStandardSkinning_*` (reading bone indices). Verify
/// exact integer bits for `R16_UINT`, `R16_SINT`, and `R32_UINT`.
#[test]
fn typed_non_d16_table_load_preserves_integer_bits() {
use windows::Win32::Graphics::Dxgi::Common::{
DXGI_FORMAT_R16_SINT, DXGI_FORMAT_R16_UINT, DXGI_FORMAT_R32_UINT,
};
let _serial = ONE_AT_A_TIME.lock().unwrap_or_else(|e| e.into_inner());
let mut body = Vec::new();
// s[8:11] = table[0] (src typed SRV), s[12:15] = table[1] (raw UAV out)
body.extend_from_slice(&s_load_dwordx4_off(8, 4, 0));
body.extend_from_slice(&s_load_dwordx4_off(12, 4, 32));
// buffer_load_format_x v2, v0, s[8:11], 0 idxen (op 0x00)
body.extend_from_slice(&mubuf_idxen(0x00, 2, 0, 8));
// v4 = v0 << 2 (byte offset = thread * 4)
body.push(0x3408_0082); // v_lshlrev_b32 v4, 2, v0
// buffer_store_dword v2, v4, s[12:15], 0 offen (op 0x1C, offen bit 12)
body.extend_from_slice(&[
0x38 << 26 | 0x1C << 18 | 1 << 12,
0x80 << 24 | (12u32 >> 2) << 16 | (2u32 << 8) | 4u32,
]);
let used = vec![
UsedResource {
kind: ResourceType::Srv,
root: RootType::Table,
table_offset_dwords: 0,
lower_bound: 0,
stride: 4,
dwords: 4,
user_data: 4,
slot: 0,
},
UsedResource {
kind: ResourceType::Uav,
root: RootType::Table,
table_offset_dwords: 8,
lower_bound: 1,
stride: 4,
dwords: 4,
user_data: 4,
slot: 0,
},
];
let shader = build_table_typed_cs(&body, used);
// Non-d16 typed loads stay untouched (no SLOT_TABLE_STRIDES root SRV, no
// CFG branches) so non-d16 pixel/mesh/particle/skinning shaders keep
// identical DXIL and pipeline cache keys while still preserving raw bits.
assert!(
!shader.root_srvs.contains(&super::SLOT_TABLE_STRIDES),
"non-d16 typed load should not add SLOT_TABLE_STRIDES"
);
let r16_data = [0x3C00_0001u32, 0xFFFF_BC00u32];
let r32_data = [0xDEAD_BEEFu32, 0x0000_0001, 0x8000_0000, 0x7FFF_FFFF];
let cases: [(&str, _, u32, &[u32], [u32; 4]); 3] = [
(
"R16_UINT",
DXGI_FORMAT_R16_UINT,
2,
&r16_data,
[0x0001, 0x3C00, 0xBC00, 0xFFFF],
),
(
"R16_SINT",
DXGI_FORMAT_R16_SINT,
2,
&r16_data,
[0x0001, 0x3C00, 0xFFFF_BC00, 0xFFFF_FFFF],
),
(
"R32_UINT",
DXGI_FORMAT_R32_UINT,
4,
&r32_data,
r32_data,
),
];
for (backend, warp) in [("hardware", false), ("warp", true)] {
let Ok(host) = Host::new(warp) else { continue };
let (root, pso) = host
.compute_pipeline(&shader)
.unwrap_or_else(|e| panic!("{backend}: compute_pipeline failed: {e}"));
for &(label, format, elem_bytes, input, want) in &cases {
let views = [
View::Buffer {
data: input,
stride: super::host::Stride::Format(format, elem_bytes),
},
View::RawUav(4),
];
let mut ud = vec![0u32; shader.user_data_dwords().max(1) as usize];
for u in &shader.user_data {
if u.root == RootType::Table && u.slot == 0 {
ud[u.index as usize] = 0;
}
}
let out = host
.dispatch(
&root,
&pso,
&Dispatch {
roots: vec![(0, Root::Constants(ud))],
views: &views,
samplers: &[],
groups: [1, 1, 1],
},
)
.unwrap_or_else(|e| panic!("{backend} {label}: dispatch failed: {e}"));
assert_eq!(out[0], want, "{backend} {label}: buffer_load_format_x mismatch");
}
}
}
+59 -9
View File
@@ -227,9 +227,9 @@ pub fn track(
let mut offset_at =
std::collections::BTreeMap::<usize, (Vec<usize>, Vec<Value>, Vec<Site>)>::new();
for (b, block) in p.blocks.iter().enumerate() {
t.at.set(Some(b));
for (i, inst) in block.insts.iter().enumerate() {
let site = (b, i);
t.at.set(Some(site));
if let Some(value) = t.restored(inst, Some(b)) {
out.restored_lanes.insert(site, value);
}
@@ -240,7 +240,7 @@ pub fn track(
let mut first_lane = Vec::new();
let mut offset = Vec::new();
let mut descriptor = |op: &Operand, role| -> Result<(), ShaderError> {
let source = t.descriptor(inst, op, b).map_err(fail)?;
let source = t.descriptor(inst, op, site).map_err(fail)?;
// A descriptor the code keeps per lane ([`Tracer::lane_copies`])
// is the same in every lane: its loop is lowered as it stands
// and needs no proof.
@@ -417,8 +417,8 @@ struct Tracer<'a> {
meets: std::cell::RefCell<Meets>,
/// Reverse-postorder index per block.
rpo: Vec<usize>,
/// The block of the access being traced ([`Self::live`]).
at: std::cell::Cell<Option<usize>>,
/// The instruction site of the access being traced ([`Self::live`]).
at: std::cell::Cell<Option<Site>>,
}
/// What lanes are known to satisfy: each [`Bool`] where its flag is set,
@@ -1119,8 +1119,8 @@ impl<'a> Tracer<'a> {
self.address(lo, hi, extra)
}
/// The source of the descriptor operand `op` of `inst`, in block `at`.
fn descriptor(&self, inst: &Inst, op: &Operand, at: usize) -> Result<Source, &'static str> {
/// The source of the descriptor operand `op` of `inst`, at `at`.
fn descriptor(&self, inst: &Inst, op: &Operand, at: Site) -> Result<Source, &'static str> {
let Operand::Scalar { code, dwords } = *op else {
return Err("a descriptor not in SGPRs");
};
@@ -1135,8 +1135,14 @@ impl<'a> Tracer<'a> {
{
words = raw.to_vec();
}
// Only the lanes that reach the access read the descriptor.
let mut known = Vec::from_iter(self.lanes.map(|l| (l.reach[at], true)));
// Only the lanes that reach and run the access read the descriptor.
let mut known = Vec::new();
if let Some(l) = self.lanes {
known.push((l.reach[at.0], true));
if let Some(guard) = l.guards[at.0][at.1] {
known.push((guard, true));
}
}
self.classify(&words, &mut Vec::new(), &mut known)
}
@@ -1288,7 +1294,10 @@ impl<'a> Tracer<'a> {
let (Some(at), Some(lanes)) = (self.at.get(), self.lanes) else {
return t;
};
let mut known = vec![(lanes.reach[at], true)];
let mut known = vec![(lanes.reach[at.0], true)];
if let Some(guard) = lanes.guards[at.0][at.1] {
known.push((guard, true));
}
for _ in 0..MAX_JOINS {
let Term::Value(v) = t else { break };
let Some((block, i)) = self.phis[v.0 as usize] else {
@@ -4098,4 +4107,45 @@ pub(crate) mod tests {
assert_eq!(r.waterfall.compares.len(), 2);
assert_eq!(r.waterfall.reads.len(), 4);
}
#[test]
fn a_guarded_access_excludes_dead_lane_edges_at_a_join() {
// Lanes failing `v_cmp_gt_u32` clear EXEC and take `s_cbranch_execz`
// directly to the join block without initializing the immediate
// sampler `s[8:11]`. The join's `image_sample_lz` is guarded by EXEC,
// so only the arm where `s[8:11]` was built can execute it.
let code: Vec<u8> = [
0xBE84_0300u32, // s_mov_b32 s4, s0
0xBE85_0380, // s_mov_b32 s5, 0
0xF40C_0302,
0xFA00_0000, // s_load_dwordx8 s[12:19], s[4:5], 0x0
0x7E04_0D00, // v_cvt_f32_u32 v2, v0
0x7E06_0302, // v_mov_b32 v3, v2
0x7D88_0090, // v_cmp_gt_u32 vcc_lo, 16, v0
0xBF8C_C07F, // s_waitcnt lgkmcnt(0)
0x877E_6A7E, // s_and_b32 exec_lo, exec_lo, vcc_lo
0xBF88_0004, // s_cbranch_execz -> join (skips 4 dwords)
0xBE88_0380, // s_mov_b32 s8, 0
0xBE89_0380, // s_mov_b32 s9, 0
0xBE8A_0380, // s_mov_b32 s10, 0
0xBE8B_0380, // s_mov_b32 s11, 0
0xF09C_0F08,
0x0043_0C02, // image_sample_lz v[12:15], v[2:3], s[12:19], s[8:11]
S_ENDPGM,
]
.iter()
.flat_map(|w| w.to_le_bytes())
.collect();
let p = crate::ir::build(&code, false, 256).unwrap();
let structured = lanes(&p).expect("structured form");
assert!(structured.guards[2][0].is_some(), "join access must carry an EXEC guard");
let r = track(&p, &[param(Table, 0, 1)], HwStage::Cs, Some(&structured)).unwrap();
assert!(
r.descriptors
.iter()
.any(|d| d.role == Role::Sampler && d.source == Source::Constant(vec![0; 4])),
"guarded join should resolve the immediate sampler from the live arm: {:?}",
r.descriptors
);
}
}