Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
81 commits
Select commit Hold shift + click to select a range
c3d350a
D3D12.X: promote R9G9B9E5_SHAREDEXP render/UAV targets to R11G11B10_F…
0x6461726B Nov 24, 2026
9683e7a
Scripts: smoke blocks name the game folder by a hash, not its name
grahamster2 Nov 24, 2026
b07fbab
dxil: geometry mode (ES+GS) in the direct translator
bmjask Nov 24, 2026
2dcc926
dxil: Texture2DMS / Texture2DMSArray ops, MSAA image loads in the dir…
bmjask Nov 24, 2026
65154b3
dxil: directed f32 rounding (MODE round toward +inf / -inf / zero)
bmjask Nov 24, 2026
f458b55
dxil: fuzz tests (random programs, direct vs HLSL on the GPU)
bmjask Nov 24, 2026
210f773
dxil fuzz: amd_reduced_seeds (ignored) for seeds 722 / 1599; debug_se…
bmjask Nov 24, 2026
ee85bc2
dxil: geometry GPU record test (loops, cuts), CfgBlock::pc for split …
bmjask Nov 24, 2026
69a892c
Recompiler: oversized structured code falls back to pc blocks (#1307)
Nov 24, 2026
fa78c6f
Merge origin/main (heap windows) into the direct DXIL follow-up; TRAN…
bmjask Nov 24, 2026
4c64cc4
Merge remote-tracking branch 'origin/main' into shaders/direct-dxil-f…
bmjask Nov 24, 2026
0b64aa0
dxil: eliminate giant-shader IR and CFG blowup in FormatLoad and mult…
raylitebull Nov 24, 2026
2a2d54b
dxil: geometry record test also compares the HLSL split form (fixed b…
bmjask Nov 24, 2026
4178e88
Merge pull request #1748 from raylitebull/fix/direct-dxil-size-oom
raylitebull Nov 24, 2026
7a84e7a
Direct DXIL: image_get_lod with a static sampler; slowest programs in…
bmjask Nov 24, 2026
758e341
Merge origin/main (#1748, #819); TRANSLATOR_VERSION 7
bmjask Nov 24, 2026
9486494
D3D12.X: an ExecuteIndirect reads the arguments written before it
wondercrash Nov 24, 2026
1bab757
Recompiler: per-lane lane-mask analysis for a direct DXIL backend
gefydev Nov 24, 2026
9b8db83
Recompiler: assemble and sign a DXIL module from LLVM IR text
Sr-0w Nov 24, 2026
b3c0b37
Recompiler: lower kernel programs to DXIL-shaped IR on the lane masks
gefydev Nov 24, 2026
430f0a3
Recompiler: scalar and vector memory in the direct lowering
gefydev Nov 24, 2026
f33f640
Recompiler: compute mode in the direct lowering
gefydev Nov 24, 2026
511eadd
Recompiler: write the direct lowering through gpu::dxil's module builder
gefydev Nov 24, 2026
ac34cb6
Recompiler: refuse scalar values a lane kept from before a write it s…
gefydev Nov 24, 2026
13ac196
Recompiler: report both halves of a stale wave64 mask in the lowering
Frtuchinno Nov 24, 2026
f90033c
Recompiler: cross-lane operations in the lowering
Sr-0w Nov 24, 2026
ac8f8b6
Recompiler: lane reads and bit counts through gpu::dxil in the direct…
gefydev Nov 24, 2026
f5d3e05
Recompiler: per-lane coverage survey and the first coverage gaps
gefydev Nov 24, 2026
45025eb
Recompiler: half-local wave operations in the lowering's Ir
Sr-0w Nov 24, 2026
fbb3a7b
Recompiler: name the hardware register of a refused s_setreg in the c…
gefydev Nov 24, 2026
a5311f7
Recompiler: thread ids of any compute group shape in the lowering's Ir
Sr-0w Nov 24, 2026
9816a85
Recompiler: drop trivial phis through Module::replace_all_uses in the…
gefydev Nov 24, 2026
6bdef80
Tests: the IR assemble test skips without dxil.dll; survey sizes in KB
gefydev Nov 24, 2026
8593700
Recompiler: survey every per-lane refusal, and the mesh pass both ways
Kalmarv Nov 24, 2026
f9be7cc
Recompiler: an unsupported VALU opcode is refused before its sources …
gefydev Nov 24, 2026
acdf922
Recompiler: whole-wave mask reads need every lane where an Ir meets a…
upipibi Nov 24, 2026
9231d48
Tests: f32 programs for the per-lane lowering, on the HLSL path and p…
vladbondarenko97 Nov 24, 2026
ea683a0
Merge pull request #689 from grahamster2/scripts-smoke-title-hash
raylitebull Nov 24, 2026
ad39e4d
Direct DXIL: Lw::new and Lw::finish out of the kernel translator
Sr-0w Nov 24, 2026
77db49c
Recompiler: the DXIL adapter holds #1426's Lw; 2-D / 3-D compute groups
Sr-0w Nov 24, 2026
878afda
Recompiler: the per-lane form lowers unknown instructions with #1426'…
gefydev Nov 24, 2026
ddfbf39
Recompiler: the per-lane form in the runtime behind XCL_PER_LANE=1
gefydev Nov 24, 2026
5963c26
Recompiler: far jumps in the per-lane form
gefydev Nov 24, 2026
bc0d77c
Recompiler: xcl shaders --direct --lanes measures the per-lane form
gefydev Nov 24, 2026
372be9d
Recompiler: s_cselect, s_wqm and v_cmpx in the per-lane form
gefydev Nov 24, 2026
77a5eee
Recompiler: the split wave64 form in the direct lowering, through #14…
upipibi Nov 24, 2026
d2cc6ff
Recompiler: the lane-mask analysis can start from an unknown EXEC
teidenzero Nov 24, 2026
27d28ce
Recompiler: lane masks follow s_wqm of the launch EXEC
teidenzero Nov 24, 2026
a24899e
Recompiler: VS / PS stages in the per-lane lowering
teidenzero Nov 24, 2026
5d2d65c
Recompiler: s_wqm in a VS / PS keeps the launch-EXEC rule
gefydev Nov 24, 2026
b1bfd1e
Tests: the f32 reference keeps signed zeros on every driver
gefydev Nov 24, 2026
3aea7a9
Tests: f64 programs for the per-lane lowering, on the HLSL path and p…
vladbondarenko97 Nov 24, 2026
82c875d
Tests: integer programs for the per-lane lowering, on the HLSL path a…
vladbondarenko97 Nov 24, 2026
188ee17
Recompiler: carry-ins and v_cndmask through #1426 read the right lane…
gefydev Nov 24, 2026
fe8dc84
Recompiler: f16 products stay on the fallback until #1426 rounds them
gefydev Nov 24, 2026
27751a0
Tests: f16 and packed programs for the per-lane lowering, on the HLSL…
vladbondarenko97 Nov 24, 2026
3827fb5
Recompiler: coalesce straight-line guarded runs in the per-lane lowering
MiguelMachado-dev Nov 24, 2026
e9e94ce
Merge PR #1321
ivall Nov 24, 2026
a23b6ff
Recompiler: a value copied where some lanes are elsewhere is that blo…
gefydev Nov 24, 2026
dd566c0
Recompiler: no r - 1 for s0 in the mask-pair check of cross-lane ops
gefydev Nov 24, 2026
fdb4c10
Recompiler: --lanes runs the per-lane form under the sweep's timeout
gefydev Nov 24, 2026
e40ac38
Recompiler: the runtime's split compute programs ask for 32-lane waves
gefydev Nov 24, 2026
14e367e
Recompiler: a VS starts with every lane in EXEC in the per-lane form
teidenzero Nov 24, 2026
29eccc0
Recompiler: replace the per-lane form's trivial phis in one pass
Itsmetibo Nov 24, 2026
f251762
Recompiler: the per-lane form takes heap memory windows
gefydev Nov 24, 2026
4e057cb
Tests: cover split wave64 coalesced runs on the GPU
MiguelMachado-dev Nov 24, 2026
9e27370
Tests: the per-lane GPU tests skip on adapters without 32-lane waves
gefydev Nov 24, 2026
66879ef
Recompiler: the per-lane form refuses whole-wave mask decisions and m…
gefydev Nov 24, 2026
9dcf2f6
Recompiler: a mask op's SCC carried around a loop stays a lane's
gefydev Nov 24, 2026
bfb8133
Recompiler: per-lane cache entries change when the per-lane sources do
gefydev Nov 24, 2026
7f7e768
Merge pull request #1745 from gefydev/direct-on-1426
raylitebull Nov 24, 2026
3bc7143
D3D12.X: keep vram::Pages tile mappings contiguous per heap
raylitebull Nov 24, 2026
266b845
Merge pull request #1806 from bmjask/dxil/coverage-full
raylitebull Nov 24, 2026
177cd40
Merge pull request #605 from 0x6461726B/d3d12x-r9g9b9e5-target
raylitebull Nov 24, 2026
4e3515e
Merge pull request #1791 from wondercrash/pr/ei-arg-order
raylitebull Nov 24, 2026
c4d37be
Merge pull request #1747 from raylitebull/fix/world-freeze-180s
raylitebull Nov 24, 2026
281fc7d
Merge origin/main into shaders/direct-dxil-followup
bmjask Nov 24, 2026
1d027e5
CI: mark PRs idle for 3 days stale and close them after a week
ivall Nov 24, 2026
e9ac9f0
Merge origin/main (CI stale workflow)
bmjask Nov 24, 2026
689f2db
Merge pull request #1679 from bmjask/shaders/direct-dxil-followup
raylitebull Nov 24, 2026
201d67d
D3D12.X: ExecuteIndirect's records are bounded on the GPU before the …
mastrr9 Nov 24, 2026
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
46 changes: 46 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# A pull request with no activity for 3 days gets the `stale` label and a comment, and is closed
# 4 days later (a week in all, as in CONTRIBUTING.md) unless something happens on it. Issues are
# left alone. PRs labelled `goal:world-load` or `keep-open` are never touched.
name: Stale PRs

on:
schedule:
- cron: "17 */6 * * *"
workflow_dispatch:
inputs:
dry_run:
description: Only log what would be done
type: boolean
default: true

permissions:
actions: write # where the last run stopped is kept in the cache
issues: read
pull-requests: write

concurrency:
group: stale

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@4391f3da665fdf50b6810c1a66712fb9ba21aa93 # v11.0.0
with:
days-before-issue-stale: -1
days-before-issue-close: -1
days-before-pr-stale: 3
days-before-pr-close: 4
stale-pr-label: stale
exempt-pr-labels: goal:world-load,keep-open
sort-by: updated
ascending: true
operations-per-run: 300
debug-only: ${{ github.event_name == 'workflow_dispatch' && inputs.dry_run }}
stale-pr-message: >-
Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in
4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and
say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
close-pr-message: >-
Closed after a week with no activity. This is not a verdict on the code: if it still applies to
`main`, rebase it, say so here and it can be reopened.
19 changes: 19 additions & 0 deletions crates/xcl/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ const TRANSLATOR_SOURCES: &[&str] = &[
"src/gpu/xbox.rs",
];

/// The per-lane form's sources (`XCL_PER_LANE`): part of only its own cache entries' identity,
/// so editing them does not invalidate the HLSL path's.
const PER_LANE_SOURCES: &[&str] = &[
"src/gpu/recomp/lane_masks.rs",
"src/gpu/recomp/lower.rs",
"src/gpu/recomp/lower/wave.rs",
"src/gpu/recomp/lower_dxil.rs",
"src/gpu/recomp/ssa.rs",
];

fn add(h: &mut u64, bytes: &[u8]) {
for &byte in bytes {
*h ^= byte as u64;
Expand Down Expand Up @@ -48,4 +58,13 @@ fn main() {
add(&mut h, &[0]);
}
println!("cargo:rustc-env=XCL_TRANSLATOR_SOURCE_ID={h:016x}");
let mut p = 0xcbf2_9ce4_8422_2325u64;
for relative in PER_LANE_SOURCES {
println!("cargo:rerun-if-changed={relative}");
add(&mut p, relative.as_bytes());
add(&mut p, &[0]);
add(&mut p, &std::fs::read(root.join(relative)).expect("read per-lane source"));
add(&mut p, &[0]);
}
println!("cargo:rustc-env=XCL_PER_LANE_SOURCE_ID={p:016x}");
}
37 changes: 34 additions & 3 deletions crates/xcl/src/gpu/dxil/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub enum Term {
}

pub struct CfgBlock {
/// byte offset of the block's first instruction
pub pc: u64,
/// instruction indices (the terminating branch excluded for `Cond`/`Jump` by branch)
pub insts: Vec<usize>,
pub term: Term,
Expand All @@ -38,6 +40,16 @@ fn is_end(name: &str) -> bool {

impl Cfg {
pub fn build(code: &[u8]) -> Result<Cfg, String> {
Self::build_with(code, None)
}

/// Geometry mode: the ES's `s_setpc_b64` continues at `gs_start` (the GS code) when
/// that is past the start, else ends the program (`recomp::Mode::Geometry`).
pub fn build_geometry(code: &[u8], gs_start: Option<u64>) -> Result<Cfg, String> {
Self::build_with(code, Some(gs_start.filter(|&s| s > 0)))
}

fn build_with(code: &[u8], setpc: Option<Option<u64>>) -> Result<Cfg, String> {
let mut insts: Vec<Decoded> = Vec::new();
let mut off = 0usize;
while off + 4 <= code.len() {
Expand All @@ -48,7 +60,19 @@ impl Cfg {
rdna2::resolve_far_jumps(&mut insts);
let index: BTreeMap<u64, usize> = insts.iter().enumerate().map(|(i, d)| (d.pc, i)).collect();
let mut leaders: BTreeSet<usize> = BTreeSet::from([0]);
let is_setpc = |d: &Decoded| setpc.is_some() && d.inst.name == "S_SETPC_B64" && d.far_target.is_none();
let setpc_target = match setpc {
Some(Some(t)) => Some(*index.get(&t).ok_or_else(|| format!("GS start {t:#x} is not the start of an instruction"))?),
_ => None,
};
if let Some(t) = setpc_target {
leaders.insert(t);
}
for (i, d) in insts.iter().enumerate() {
if is_setpc(d) {
leaders.insert(i + 1);
continue;
}
if let Some(t) = rdna2::branch_target(d) {
let ti = *index.get(&t).ok_or_else(|| format!("+{:#x}: branch to {t:#x}, which is not the start of an instruction", d.pc))?;
leaders.insert(ti);
Expand All @@ -70,6 +94,13 @@ impl Cfg {
term = Term::End;
break;
}
if is_setpc(d) {
term = match setpc_target {
Some(t) => Term::Jump(block_of[&t]),
None => Term::End,
};
break;
}
if let Some(t) = rdna2::branch_target(d) {
let tb = block_of[&index[&t]];
let name = d.inst.name;
Expand All @@ -86,7 +117,7 @@ impl Cfg {
}
list.push(i);
}
blocks.push(CfgBlock { insts: list, term, preds: Vec::new() });
blocks.push(CfgBlock { pc: insts[s].pc, insts: list, term, preds: Vec::new() });
}
// a conditional branch whose both edges meet is a jump
for b in &mut blocks {
Expand Down Expand Up @@ -172,7 +203,7 @@ fn make_reducible(blocks: &mut Vec<CfgBlock>) -> Result<(Vec<usize>, BTreeSet<us
let mut copy = vec![usize::MAX; n];
for b in (0..n).filter(|&b| region[b] && b != h) {
copy[b] = blocks.len();
blocks.push(CfgBlock { insts: blocks[b].insts.clone(), term: blocks[b].term.clone(), preds: Vec::new() });
blocks.push(CfgBlock { pc: blocks[b].pc, insts: blocks[b].insts.clone(), term: blocks[b].term.clone(), preds: Vec::new() });
}
let redirect = |term: &mut Term, to: &dyn Fn(usize) -> usize| match term {
Term::Jump(x) => *x = to(*x),
Expand Down Expand Up @@ -299,7 +330,7 @@ mod tests {
use super::*;

fn blk(term: Term) -> CfgBlock {
CfgBlock { insts: Vec::new(), term, preds: Vec::new() }
CfgBlock { pc: 0, insts: Vec::new(), term, preds: Vec::new() }
}

/// The console's loop entered in the middle (`62b584e061c05fc5`'s shape): 0 → {1 | 3},
Expand Down
158 changes: 158 additions & 0 deletions crates/xcl/src/gpu/dxil/core_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,3 +279,161 @@ fn graphics_stages_with_a_branch_before_their_exports() {
assert_eq!(draw(&dvs, &dps, 0), cleared, "branch not taken");
assert_eq!(draw(&dvs, &dps, 1), kept, "branch taken");
}

/// Geometry mode (ES+GS, the compute pass of `recomp::Mode::Geometry`): an ES that writes
/// its vertex to the LDS ring, the GS that reads its triangle's vertices, writes them to
/// its output area and emits a strip; split and native forms validate (also the ES or GS
/// alone, as the coverage sweep translates them).
#[test]
fn geometry_mode_validates() {
use crate::gpu::recomp::GsInterface;
let e = |n: &str, enc: &str, f: &[(&str, u64)]| encode(n, enc, f, None).unwrap_or_else(|x| panic!("{n}: {x}"));
let mut es = Vec::new();
// v20 = lane * ES item (16 B), ring[v20] = v9 (a fetched input)
es.extend(e("V_MBCNT_LO_U32_B32", "ENC_VOP3", &[("VDST", 20), ("SRC0", 193), ("SRC1", 128)]));
es.extend(e("V_MBCNT_HI_U32_B32", "ENC_VOP3", &[("VDST", 20), ("SRC0", 193), ("SRC1", 256 + 20)]));
es.extend(e("V_LSHLREV_B32", "ENC_VOP2", &[("VDST", 20), ("SRC0", 132), ("VSRC1", 20)]));
es.extend(e("DS_WRITE_B32", "ENC_DS", &[("ADDR", 20), ("DATA0", 9)]));
es.extend(e("S_BARRIER", "ENC_SOPP", &[]));
es.extend(e("S_SETPC_B64", "ENC_SOP1", &[("SSRC0", 6)]));
let mut gs = Vec::new();
// v0 = vertex 0's dword offset: read it, write 3 output vertices at s2 + lane * 48
gs.extend(e("V_LSHLREV_B32", "ENC_VOP2", &[("VDST", 30), ("SRC0", 130), ("VSRC1", 0)]));
gs.extend(e("DS_READ_B32", "ENC_DS", &[("ADDR", 30), ("VDST", 31)]));
gs.extend(e("V_MBCNT_LO_U32_B32", "ENC_VOP3", &[("VDST", 32), ("SRC0", 193), ("SRC1", 128)]));
gs.extend(e("V_MUL_U32_U24", "ENC_VOP2", &[("VDST", 32), ("SRC0", 176), ("VSRC1", 32)]));
gs.extend(e("V_ADD_NC_U32", "ENC_VOP2", &[("VDST", 32), ("SRC0", 2), ("VSRC1", 32)]));
for k in 0..3u64 {
gs.extend(e("DS_WRITE_B32", "ENC_DS", &[("ADDR", 32), ("DATA0", 31), ("OFFSET0", 16 * k)]));
gs.extend(e("S_SENDMSG", "ENC_SOPP", &[("SIMM16", 0x22)]));
}
gs.extend(e("S_SENDMSG", "ENC_SOPP", &[("SIMM16", 0x12)]));
gs.extend(e("S_ENDPGM", "ENC_SOPP", &[]));
let sig = |name: &str, sv: u32, reg: u32| crate::gpu::dxbc::SigElement { name: name.into(), index: 0, system_value: sv, component_type: 3, register: reg, mask: 0xF, rw_mask: 0xF, stream: 0 };
let g = GsInterface {
es_inputs: vec![sig("POSITION", 0, 0)],
es_outputs: vec![sig("SV_Position", 1, 0)],
outputs: vec![sig("SV_Position", 1, 0)],
max_vertex_count: 3,
gs_start: Some(es.len() as u64),
};
let mut code = es.clone();
code.extend_from_slice(&gs);
let mut es_end = es;
es_end.extend(e("S_ENDPGM", "ENC_SOPP", &[]));
let cases = [
("ES+GS", code, g.clone()),
("ES alone", es_end, GsInterface { gs_start: None, ..g.clone() }),
("GS alone", gs, GsInterface { gs_start: Some(0), ..g }),
];
for (name, code, g) in cases {
for split in [true, false] {
let o = KernelOptions { wave64: true, split, mem_windows: 1, sampler_base: 0 };
super::kernel::translate_geometry(&code, o, &g).unwrap_or_else(|e| panic!("{name} split {split}: {}", &e[..e.len().min(3000)]));
}
}
}

/// Exhaustive bit-exact check of the IEEE-754 bit-manipulation formula used by
/// `lower_mem::uf_small_bits` for all 10-bit (mb=5) and 11-bit (mb=6) float inputs.
#[test]
fn uf_small_ieee_bit_math_matches_exact_formula() {
for mb in [5u32, 6u32] {
let p = 1u32 << mb;
let mmask = p - 1;
let mshift = 23 - mb;
let den_scale = f32::from_bits(if mb == 6 { 0x3580_0000 } else { 0x3600_0000 });
for v in 0..(1u32 << (mb + 5)) {
let e = v >> mb;
let m = v & mmask;
// Reference formula (matching HLSL `uf_small`)
let fm = (m as f32) / (p as f32);
let ref_f = if e == 31 {
f32::from_bits(if m != 0 { 0x7FC0_0000 } else { 0x7F80_0000 })
} else if e == 0 {
fm * (-14.0f32).exp2()
} else {
((e as f32) - 15.0).exp2() * (1.0 + fm)
};
// Exact IEEE bit math
let got_bits = if e == 31 {
if m != 0 { 0x7FC0_0000 } else { 0x7F80_0000 }
} else if e == 0 {
((m as f32) * den_scale).to_bits()
} else {
((e + 112) << 23) | (m << mshift)
};
assert_eq!(got_bits, ref_f.to_bits(), "mb={mb} v={v:#x} (e={e} m={m})");
}
}
}

/// Multi-window switch dispatch, vector rawBufferLoad/Store, hoisted FormatLoad
/// descriptors, single/multi-component FormatLoad, and hoisted BVH loads all pass
/// DXIL validation across 1..=4 memory windows and wave configurations.
#[test]
fn multi_window_mem_format_and_bvh_validate() {
let code = prog(&[
// Load descriptor s[12:15] once, then reuse across repeated BUFFER_LOAD_FORMAT_X
("S_LOAD_DWORDX4", "ENC_SMEM", &[("SDATA", 12), ("SBASE", 0), ("OFFSET", 0x40), ("SOFFSET", 125)], None),
("S_LOAD_DWORDX8", "ENC_SMEM", &[("SDATA", 16), ("SBASE", 0), ("OFFSET", 0x80), ("SOFFSET", 125)], None),
("S_BUFFER_LOAD_DWORDX4", "ENC_SMEM", &[("SDATA", 24), ("SBASE", 12), ("OFFSET", 0x10), ("SOFFSET", 125)], None),
// Divergent EXEC so lane guards are active (non-constant `act`)
("V_CMPX_LT_U32", "ENC_VOPC", &[("SRC0", 160), ("VSRC1", 0)], None),
// Repeated single-component format loads sharing s[12:15] (exercises hoisted FmtComp1 + Load2)
("BUFFER_LOAD_FORMAT_X", "ENC_MUBUF", &[("VDATA", 4), ("VADDR", 0), ("SRSRC", 3), ("SOFFSET", 128), ("IDXEN", 1)], None),
("BUFFER_LOAD_FORMAT_X", "ENC_MUBUF", &[("VDATA", 5), ("VADDR", 1), ("SRSRC", 3), ("SOFFSET", 128), ("IDXEN", 1)], None),
// Sub-4 and full-4 component format loads + D16 + static MTBUF + small byte load
("BUFFER_LOAD_FORMAT_XY", "ENC_MUBUF", &[("VDATA", 6), ("VADDR", 0), ("SRSRC", 3), ("SOFFSET", 128), ("IDXEN", 1)], None),
("BUFFER_LOAD_FORMAT_XYZW", "ENC_MUBUF", &[("VDATA", 8), ("VADDR", 0), ("SRSRC", 3), ("SOFFSET", 128), ("IDXEN", 1)], None),
("BUFFER_LOAD_FORMAT_D16_X", "ENC_MUBUF", &[("VDATA", 12), ("VADDR", 0), ("SRSRC", 3), ("SOFFSET", 128), ("IDXEN", 1)], None),
("BUFFER_LOAD_FORMAT_D16_HI_X", "ENC_MUBUF", &[("VDATA", 12), ("VADDR", 0), ("SRSRC", 3), ("SOFFSET", 128), ("IDXEN", 1)], None),
("TBUFFER_LOAD_FORMAT_X", "ENC_MTBUF", &[("VDATA", 13), ("VADDR", 0), ("SRSRC", 3), ("SOFFSET", 128), ("FORMAT", 28), ("IDXEN", 1)], None),
("BUFFER_LOAD_UBYTE", "ENC_MUBUF", &[("VDATA", 14), ("VADDR", 0), ("SRSRC", 3), ("SOFFSET", 128), ("IDXEN", 1)], None),
// Vector MUBUF & FLAT loads/stores
("BUFFER_LOAD_DWORDX4", "ENC_MUBUF", &[("VDATA", 16), ("VADDR", 0), ("SRSRC", 3), ("SOFFSET", 128), ("IDXEN", 1)], None),
("BUFFER_STORE_DWORDX4", "ENC_MUBUF", &[("VDATA", 16), ("VADDR", 0), ("SRSRC", 3), ("SOFFSET", 128), ("IDXEN", 1)], None),
("GLOBAL_LOAD_DWORDX4", "ENC_FLAT_GLBL", &[("VDST", 20), ("ADDR", 0), ("SADDR", 0x7D), ("OFFSET", 0)], None),
("GLOBAL_STORE_DWORDX4", "ENC_FLAT_GLBL", &[("DATA", 20), ("ADDR", 0), ("SADDR", 0x7D), ("OFFSET", 16)], None),
("GLOBAL_LOAD_USHORT", "ENC_FLAT_GLBL", &[("VDST", 24), ("ADDR", 0), ("SADDR", 0x7D), ("OFFSET", 4)], None),
// BVH node intersection (box32 / box16 / tri hoisted vector loads)
("IMAGE_BVH_INTERSECT_RAY", "ENC_MIMG", &[("VDATA", 28), ("VADDR", 0), ("SRSRC", 3), ("DMASK", 0xF)], None),
]);
for windows in [1u32, 2, 3, 4] {
for (wave64, split) in [(true, false), (false, false)] {
translate(&code, KernelOptions { wave64, split, mem_windows: windows, sampler_base: 0 })
.unwrap_or_else(|e| panic!("w={windows} wave64={wave64}: {}", &e[..e.len().min(800)]));
if windows > 1 {
translate(&code, KernelOptions { wave64, split, mem_windows: windows | crate::gpu::recomp::HEAP_WINDOWS, sampler_base: 0 })
.unwrap_or_else(|e| panic!("heap w={windows} wave64={wave64}: {}", &e[..e.len().min(800)]));
}
}
}
}

/// `image_get_lod` with a static sampler (an S# built from constants in the code) translates
/// to `CalculateLevelOfDetail` on the sampler bound at `s<i>, space1`, shared with a sample of
/// the same S#, and validates.
#[test]
fn ps_get_lod_with_a_static_sampler() {
use crate::gpu::recomp::{Mode, PsInterface};
let clamp = 2 | 2 << 3 | 2 << 6;
let linear = [clamp, 0x00FF_F000u32, 1 << 20 | 1 << 22, 0];
let mut list: Vec<(&str, &str, Vec<(&str, u64)>, Option<u32>)> = Vec::new();
for (k, &w) in linear.iter().enumerate() {
list.push(if w == 0 { ("S_MOV_B32", "ENC_SOP1", vec![("SDST", 24 + k as u64), ("SSRC0", 128)], None) } else { ("S_MOV_B32", "ENC_SOP1", vec![("SDST", 24 + k as u64), ("SSRC0", 255)], Some(w)) });
}
// uv = (I, J) of the first barycentric pair (v0, v1); T# s[16:23], S# s[24:27]
list.push(("IMAGE_GET_LOD", "ENC_MIMG", vec![("VDATA", 4), ("VADDR", 0), ("SRSRC", 4), ("SSAMP", 6), ("DMASK", 0x3), ("DIM", 1)], None));
list.push(("IMAGE_SAMPLE", "ENC_MIMG", vec![("VDATA", 6), ("VADDR", 0), ("SRSRC", 4), ("SSAMP", 6), ("DMASK", 0x3), ("DIM", 1)], None));
list.push(("EXP", "ENC_EXP", vec![("TGT", 0), ("EN", 0xF), ("VSRC0", 4), ("VSRC1", 5), ("VSRC2", 6), ("VSRC3", 7), ("DONE", 1), ("VM", 1)], None));
let refs: Vec<(&str, &str, &[(&str, u64)], Option<u32>)> = list.iter().map(|(a, b, c, d)| (*a, *b, c.as_slice(), *d)).collect();
let code = prog(&refs);
let psi = PsInterface { inputs: vec![sig("SV_Position", 0, 1, 3, 0, 0xF)], outputs: vec![sig("SV_Target", 0, 64, 3, 0, 0xF)], input_ena: 0x2, attrs: None };
let ko = KernelOptions { wave64: true, split: false, mem_windows: 1, sampler_base: 0 };
let k = super::kernel::translate_pixel(&code, ko, &psi).unwrap_or_else(|e| panic!("{}", &e[..e.len().min(800)]));
assert_eq!(k.static_samplers, vec![(linear, false)], "one static sampler, shared by get_lod and sample");
if crate::gpu::recomp::dxc::location().is_ok() {
super::coverage::translate_mode(&code, &Mode::Pixel(psi), ko, true).unwrap_or_else(|e| panic!("{}", &e[..e.len().min(800)]));
}
}
22 changes: 18 additions & 4 deletions crates/xcl/src/gpu/dxil/coverage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,23 @@ pub struct Report {
pub times_us: Vec<u64>,
/// (direct DXIL bytes, HLSL-path DXIL bytes) for programs both paths produced
pub sizes: Vec<(usize, usize)>,
/// the slowest programs: (microseconds, program), slowest first, at most [`SLOWEST`]
pub slowest: Vec<(u64, String)>,
}

/// How many of the slowest programs a [`Report`] keeps.
pub const SLOWEST: usize = 10;

impl Report {
pub fn add(&mut self, name: &str, s: &Sample) {
let c = self.stages.entry(s.stage).or_default();
self.times_us.push(s.time.as_micros() as u64);
let us = s.time.as_micros() as u64;
self.times_us.push(us);
if self.slowest.len() < SLOWEST || self.slowest.last().is_some_and(|l| l.0 < us) {
let at = self.slowest.partition_point(|l| l.0 >= us);
self.slowest.insert(at, (us, name.to_string()));
self.slowest.truncate(SLOWEST);
}
match &s.result {
Ok(size) => {
c.translated += 1;
Expand Down Expand Up @@ -186,6 +197,10 @@ impl Report {
row(&mut s, "all", &self.total());
let (p50, p95, max) = self.time_percentiles();
s.push_str(&format!(" translation time per program: p50 {:.2} ms, p95 {:.2} ms, max {:.2} ms\n", p50 as f64 / 1e3, p95 as f64 / 1e3, max as f64 / 1e3));
for (us, name) in &self.slowest {
s.push_str(&format!(" slow: {:>9.2} ms {name}
", *us as f64 / 1e3));
}
if !self.sizes.is_empty() {
let (d, h): (usize, usize) = self.sizes.iter().fold((0, 0), |a, b| (a.0 + b.0, a.1 + b.1));
s.push_str(&format!(" DXIL size, {} programs: direct {} B, HLSL+DXC {} B (direct/HLSL {:.2})\n", self.sizes.len(), d, h, d as f64 / h.max(1) as f64));
Expand Down Expand Up @@ -239,7 +254,7 @@ pub fn translate_mode(code: &[u8], mode: &Mode, o: KernelOptions, validate: bool
Mode::Vertex(vs) => kernel::translate_vertex(code, KernelOptions { split: false, ..o }, vs),
Mode::Pixel(ps) => kernel::translate_pixel(code, KernelOptions { split: false, ..o }, ps),
Mode::Mesh(ms) => kernel::translate_mesh(code, o, ms),
Mode::Geometry(_) => Err("geometry mode (ES+GS): not supported by the direct translator".into()),
Mode::Geometry(g) => kernel::translate_geometry(code, o, g),
}));
let k = match r {
Ok(r) => r?,
Expand Down Expand Up @@ -394,8 +409,7 @@ mod tests {
r.add(name, &Sample { stage: stage_name(&mode), result: res, time: t0.elapsed(), hlsl_size: None });
}
assert_eq!(r.stages["kernel"].translated, 1, "{}", r.text(5));
assert_eq!(r.stages["GS"].unsupported, 1);
assert!(r.ranked()[0].0.starts_with("geometry mode"));
assert_eq!(r.stages["GS"].translated, 1, "{}", r.text(5));
}

#[test]
Expand Down
Loading
Loading