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
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ xtp run <exe|folder> [--execute] [--unimplemented trap|zero] [--strict]
xtp config
```

`xtp shader-info --disasm` decodes the GFX10 e64 f32 interpolation forms,
`image_gather4h`, the eight coarse gradient sample forms with `_g16`, and
`v_dot8_i32_i4`. The four non-comparison samples translate through
`SampleGrad`, which selects a level per lane. The comparison samples with
explicit gradients require SM 6.8. The interpolation, gather and signed dot
forms still need DXIL lowering.

`xtp inspect --json` emits a stable JSON object (`"format": "xtp-inspect 1"`)
with string fields `file`, `blake3`, `kind` (`"exe"` or `"dll"`), hex-string
fields `machine`, `image_base` and `entry_rva`, numeric fields `subsystem` and
Expand Down
49 changes: 49 additions & 0 deletions crates/xtp-shader/src/emit/image_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,30 @@ fn sample_and_gather_forms_lower_to_valid_dxil() {
assert!(failures.is_empty(), "{failures:#?}");
}

#[test]
fn coarse_g16_samples_lower_to_sample_grad() {
for suffix in ["_g16", "_cl_g16", "_o_g16", "_cl_o_g16"] {
let coarse = format!("image_sample_cd{suffix}");
let fine = format!("image_sample_d{suffix}");
let lits = literals(&coarse, false, false);
for a16 in [false, true] {
let emit_sample = |name| {
let mut inst = mimg(name, 0xF);
inst.a16 = a16;
translate(inst, &lits).unwrap_or_else(|e| panic!("{name}, a16={a16}: {e}"))
};
let coarse_dxil = emit_sample(&coarse).dxil;
let summary = super::last_module_summary();
assert!(summary.contains("sampleGrad"), "{coarse}: {summary}");
assert!(summary.contains("legacyF16ToF32"), "{coarse}: {summary}");
assert!(
coarse_dxil == emit_sample(&fine).dxil,
"{coarse}, a16={a16}"
);
}
}
}

#[test]
fn forms_without_an_sm_6_6_equivalent_name_why() {
let cases: &[(&str, bool, bool, &str)] = &[
Expand Down Expand Up @@ -1432,6 +1456,31 @@ fn forms_without_an_sm_6_6_equivalent_name_why() {
false,
"a comparison sample with explicit derivatives",
),
(
"image_sample_c_cd_g16",
false,
false,
"a comparison sample with explicit derivatives",
),
(
"image_sample_c_cd_cl_g16",
false,
false,
"a comparison sample with explicit derivatives",
),
("image_gather4h", false, false, "image_gather4h"),
(
"image_sample_c_cd_o_g16",
false,
false,
"a comparison sample with explicit derivatives",
),
(
"image_sample_c_cd_cl_o_g16",
false,
false,
"a comparison sample with explicit derivatives",
),
];
for &(name, zero_bias, zero_level, why) in cases {
let dmask = if name.contains("_c") || name.starts_with("image_gather4") {
Expand Down
18 changes: 18 additions & 0 deletions crates/xtp-shader/src/emit/input_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,24 @@ fn emit_pixel(native: &NativeProgram) -> Result<HostShader, ShaderError> {
emit(&c, native, &p, &st, &io, &res)
}

#[test]
fn e64_f32_interpolation_reports_unsupported() {
for (w0, w1) in [
(0xD600_0005, 0x0002_0400),
(0xD601_0005, 0x0002_0400),
(0xD602_0005, 0),
] {
let [e0, e1] = exp_mrt0(5);
assert!(matches!(
pixel(&[w0, w1, e0, e1, S_ENDPGM], PERSP_CENTER),
Err(ShaderError::Unsupported {
offset: 0,
what: "an e64 f32 interpolation"
})
));
}
}

/// The translation's `SFI0` features and `ISG1` rows.
fn parts(shader: &HostShader) -> (u64, Vec<SigElement>) {
let c = Container::parse(&shader.dxil).unwrap();
Expand Down
14 changes: 9 additions & 5 deletions crates/xtp-shader/src/emit/lower/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ fn sample_form(name: &str) -> Option<SampleForm> {
gather,
..SampleForm::default()
};
for token in rest.split('_').skip(1) {
for token in rest.strip_prefix('_').unwrap_or(rest).split_terminator('_') {
let flag = match token {
"c" => &mut f.c,
"d" | "cd" => &mut f.d,
Expand Down Expand Up @@ -372,10 +372,13 @@ impl<'a> Lower<'a> {
else {
unreachable!()
};
let name = inst.name();
if name == "image_gather4h" {
return Err(name);
}
if *tfe || *lwe {
return Err("an image access with tfe or lwe");
}
let name = inst.name();
// A load or sample with no channel enabled returns the first.
let dmask = if *dmask == 0 { &1 } else { dmask };
let site = (b, i);
Expand Down Expand Up @@ -967,9 +970,10 @@ impl<'a> Lower<'a> {
sampler.sample(self, "sampleBias.f32", 61, &mut args)
}
63 => {
// shortcut: the coarse forms (`_cd`) compute one level
// per quad; the host's per pixel is the same when the
// gradients agree across the quad.
// shortcut: the coarse forms (`_cd`, including `_g16`)
// compute one level per quad; SampleGrad selects a level
// per lane, which agrees when the gradients match across
// the quad.
let mut g = vec![fu; 6];
if let Some(face) = cube_face {
// The face coordinates' derivatives, as the
Expand Down
18 changes: 18 additions & 0 deletions crates/xtp-shader/src/emit/lower/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,24 @@ fn a_missing_value_stays_missing_through_two_live_joins() {
lowers(&words, group_ids_xy).expect("dead timestamp");
}

#[test]
fn signed_packed_dot_reports_unsupported() {
let words = [
0xCC18_4000,
0x1C0E_0501, // v_dot8_i32_i4 v0, v1, v2, v3
0xD834_0000,
0, // ds_write_b32 v0, v0
S_ENDPGM,
];
assert!(matches!(
lower_with(&words, vec![], vec![]),
Err(crate::ShaderError::Unsupported {
what: "v_dot8_i32_i4",
..
})
));
}

#[test]
fn buffer_formats_by_number() {
// The numbers the disassembler names 8_8_8_8_UNORM, 16_16_SNORM,
Expand Down
6 changes: 5 additions & 1 deletion crates/xtp-shader/src/gfx10/fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ pub enum Operand {
},
/// Inline constant or read-only special source, by operand code
/// (128-192: 0-64, 193-208: -1 to -16, 240-248: floats, 251-254: vccz,
/// execz, scc, lds_direct).
/// execz, scc, lds_direct). For `v_interp_mov_f32`, a parameter selector
/// (0 `p10`, 1 `p20`, 2 `p0`).
Const(u8),
/// The 32-bit literal that follows the instruction.
Literal(u32),
Expand Down Expand Up @@ -552,6 +553,7 @@ impl Instruction {
0x000..0x100 => 2,
0x100..0x140 => 2 + usize::from(carry_in),
0x180..0x200 => 1,
0x200..=0x202 => 2,
_ if VOP3_TWO_SOURCES.contains(&name) => 2,
_ => 3,
};
Expand All @@ -564,6 +566,8 @@ impl Instruction {
chan: (code >> 6 & 3) as u8,
high: code >> 8 & 1 == 1,
}
} else if i == 1 && name == "v_interp_mov_f32" {
Operand::Const(code as u8)
} else if i == 2 && carry_in {
source(code, lanes, w(2))
} else {
Expand Down
Loading
Loading