From fdc44fbd9fa569f1cf67ec91e1a97e5bb81b9826 Mon Sep 17 00:00:00 2001 From: PrivacyOnion Date: Wed, 25 Nov 2026 14:05:38 +0100 Subject: [PATCH 1/3] shader: fill GFX10 decoder gaps --- README.md | 5 + crates/xtp-shader/src/emit/image_tests.rs | 25 +++ crates/xtp-shader/src/emit/input_tests.rs | 18 ++ crates/xtp-shader/src/emit/lower/image.rs | 13 +- crates/xtp-shader/src/emit/lower/tests.rs | 18 ++ crates/xtp-shader/src/gfx10/fields.rs | 6 +- crates/xtp-shader/src/gfx10/mod.rs | 205 +++++++++++++++++++++- crates/xtp-shader/src/gfx10/opcodes.rs | 6 + crates/xtp-shader/src/gfx10/sp3.rs | 19 +- crates/xtp-shader/src/io.rs | 3 + 10 files changed, 306 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 8c3f9e5a..4ccdf645 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,11 @@ xtp run [--execute] [--unimplemented trap|zero] [--strict] xtp config ``` +`xtp shader-info --disasm` decodes the GFX10 e64 f32 interpolation forms, +`image_gather4h`, the four coarse gradient samples with `_g16`, and +`v_dot8_i32_i4`. Translating shaders that need these instructions still +requires DXIL lowering for them. + `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 diff --git a/crates/xtp-shader/src/emit/image_tests.rs b/crates/xtp-shader/src/emit/image_tests.rs index 64c2553a..ca52a300 100644 --- a/crates/xtp-shader/src/emit/image_tests.rs +++ b/crates/xtp-shader/src/emit/image_tests.rs @@ -1432,6 +1432,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_cd_g16", + false, + false, + "a sample with coarse packed derivatives", + ), + ( + "image_sample_cd_cl_g16", + false, + false, + "a sample with coarse packed derivatives", + ), ]; for &(name, zero_bias, zero_level, why) in cases { let dmask = if name.contains("_c") || name.starts_with("image_gather4") { diff --git a/crates/xtp-shader/src/emit/input_tests.rs b/crates/xtp-shader/src/emit/input_tests.rs index aa9e75a5..8100a737 100644 --- a/crates/xtp-shader/src/emit/input_tests.rs +++ b/crates/xtp-shader/src/emit/input_tests.rs @@ -102,6 +102,24 @@ fn emit_pixel(native: &NativeProgram) -> Result { 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) { let c = Container::parse(&shader.dxil).unwrap(); diff --git a/crates/xtp-shader/src/emit/lower/image.rs b/crates/xtp-shader/src/emit/lower/image.rs index 2becdded..190bac99 100644 --- a/crates/xtp-shader/src/emit/lower/image.rs +++ b/crates/xtp-shader/src/emit/lower/image.rs @@ -185,7 +185,7 @@ fn sample_form(name: &str) -> Option { 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, @@ -372,10 +372,19 @@ impl<'a> Lower<'a> { else { unreachable!() }; + let name = inst.name(); + match name { + "image_gather4h" => return Err(name), + "image_sample_cd_g16" | "image_sample_cd_cl_g16" => { + // SampleGrad selects a level per lane. The coarse form + // selects one level per quad. + return Err("a sample with coarse packed derivatives"); + } + _ => {} + } 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); diff --git a/crates/xtp-shader/src/emit/lower/tests.rs b/crates/xtp-shader/src/emit/lower/tests.rs index 407db438..94df0c19 100644 --- a/crates/xtp-shader/src/emit/lower/tests.rs +++ b/crates/xtp-shader/src/emit/lower/tests.rs @@ -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, diff --git a/crates/xtp-shader/src/gfx10/fields.rs b/crates/xtp-shader/src/gfx10/fields.rs index 3d9ec474..aba28837 100644 --- a/crates/xtp-shader/src/gfx10/fields.rs +++ b/crates/xtp-shader/src/gfx10/fields.rs @@ -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), @@ -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, }; @@ -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 { diff --git a/crates/xtp-shader/src/gfx10/mod.rs b/crates/xtp-shader/src/gfx10/mod.rs index 0c707837..a3f1cf94 100644 --- a/crates/xtp-shader/src/gfx10/mod.rs +++ b/crates/xtp-shader/src/gfx10/mod.rs @@ -254,7 +254,17 @@ fn instruction(code: &[u8], offset: usize) -> Result { match w >> 26 { 0x32 => (Encoding::Vintrp, (w >> 16) & 0x3, 1), 0x33 => (Encoding::Vop3p, (w >> 16) & 0x7F, vop3(word(1)?)), - 0x35 => (Encoding::Vop3, (w >> 16) & 0x3FF, vop3(word(1)?)), + 0x35 => { + let op = (w >> 16) & 0x3FF; + // The e64 interpolation forms cannot take a literal. Their + // attribute field is 0xFF for attr63.w. + let len = if matches!(op, 0x200..=0x202) { + 2 + } else { + vop3(word(1)?) + }; + (Encoding::Vop3, op, len) + } 0x36 => (Encoding::Ds, (w >> 18) & 0xFF, 2), 0x37 => { let encoding = match (w >> 14) & 3 { @@ -302,11 +312,12 @@ fn name(encoding: Encoding, opcode: u16) -> Option<&'static str> { Encoding::Vop2 => (t::VOP2, opcode), Encoding::Vop1 => (t::VOP1, opcode), Encoding::Vopc => (t::VOPC, opcode), - // VOP3 also encodes the VOPC, VOP2 and VOP1 opcodes at fixed bases. + // VOP3 also encodes the VOPC, VOP2, VOP1 and VINTRP opcodes at fixed bases. Encoding::Vop3 => match opcode { 0x000..0x100 => (t::VOPC, opcode), 0x100..0x140 => (t::VOP2, opcode - 0x100), 0x180..0x200 => (t::VOP1, opcode - 0x180), + 0x200..=0x202 => (t::VINTRP, opcode - 0x200), _ => (t::VOP3, opcode), }, Encoding::Vop3p => (t::VOP3P, opcode), @@ -408,6 +419,192 @@ mod tests { ); } + // Encoding fixtures from llvm-project llvmorg-19.1.7, Apache-2.0 WITH + // LLVM-exception. The interpolation modifier combination is synthetic. + #[test] + fn vop3_interpolation_operands_and_modifiers() { + // llvm/test/MC/AMDGPU/gfx10_asm_vop3.s + let vgpr = |reg| Operand::Vector { reg, dwords: 1 }; + let attr = Operand::Attr { + index: 0, + chan: 0, + high: false, + }; + for (op, name, w1, src) in [ + (0x200, "v_interp_p1_f32", 0x0002_0400, vgpr(2)), + (0x201, "v_interp_p2_f32", 0x0002_0400, vgpr(2)), + (0x202, "v_interp_mov_f32", 0, Operand::Const(0)), + (0x202, "v_interp_mov_f32", 0x400, Operand::Const(2)), + ] { + let words = [0xD400_0005 | op << 16, w1]; + let inst = instruction(&bytes(&words), 0).unwrap(); + assert_eq!(inst.words, words); + assert_eq!((inst.encoding, inst.opcode), (Encoding::Vop3, op as u16)); + assert_eq!(inst.name(), Some(name)); + assert_eq!( + inst.fields(false), + Fields::Valu(Valu { + dst: Some(vgpr(5)), + src: vec![attr, src], + ..Valu::default() + }) + ); + if src == Operand::Const(2) { + assert_eq!(inst.text(false), "v_interp_mov_f32 v5, p0, attr0.x"); + } + } + + // attr63.w occupies the same field value as a generic VOP3 literal. + let words = [0xD600_8205, 0x4802_04FF, S_ENDPGM]; + let decoded = decode(&bytes(&words)).unwrap(); + assert_eq!(decoded[1].offset, 8); + assert_eq!( + decoded[0].fields(false), + Fields::Valu(Valu { + dst: Some(vgpr(5)), + src: vec![ + Operand::Attr { + index: 63, + chan: 3, + high: false, + }, + vgpr(2), + ], + neg: 0b010, + abs: 0b010, + clamp: true, + omod: 1, + ..Valu::default() + }) + ); + } + + #[test] + fn mimg_gather4h_operands() { + // llvm/test/MC/AMDGPU/gfx10_asm_mimg.s + let words = [0xF184_021A, 0x0021_4020, 0x0000_2221]; + let inst = instruction(&bytes(&words), 0).unwrap(); + assert_eq!(inst.words, words); + assert_eq!((inst.encoding, inst.opcode), (Encoding::Mimg, 0x061)); + assert_eq!(inst.name(), Some("image_gather4h")); + assert_eq!( + inst.fields(false), + Fields::Image { + data: Operand::Vector { reg: 64, dwords: 4 }, + addr: (32..=34) + .map(|reg| Operand::Vector { reg, dwords: 1 }) + .collect(), + rsrc: Operand::Scalar { code: 4, dwords: 8 }, + sampler: Some(Operand::Scalar { code: 4, dwords: 4 }), + dmask: 2, + dim: 3, + unorm: false, + r128: false, + a16: false, + d16: false, + tfe: false, + lwe: false, + cache: Cache::default(), + } + ); + } + + #[test] + fn mimg_coarse_g16_sample_operands() { + // llvm/test/MC/AMDGPU/gfx10_asm_mimg.s has 1D sequential and 2D NSA + // encodings for each form. The comparison and clamp each add one dword. + let cases: [(&str, u32, &[u32], &[u8]); 4] = [ + ( + "image_sample_cd_g16", + 0xF1A0_0F01, + &[0xF1A0_0F0B, 0x0040_0000, 0x0005_0402], + &[0, 2, 4, 5], + ), + ( + "image_sample_cd_cl_g16", + 0xF1A4_0F01, + &[0xF1A4_0F0B, 0x0040_0000, 0x0605_0402], + &[0, 2, 4, 5, 6], + ), + ( + "image_sample_c_cd_g16", + 0xF1A8_0F01, + &[0xF1A8_0F0B, 0x0040_0000, 0x0605_0301], + &[0, 1, 3, 5, 6], + ), + ( + "image_sample_c_cd_cl_g16", + 0xF1AC_0F01, + &[0xF1AC_0F0D, 0x0040_0000, 0x0605_0301, 7], + &[0, 1, 3, 5, 6, 7], + ), + ]; + for (name, w0, nsa, regs) in cases { + let sequential = [w0, 0x0040_0000]; + for (words, dim, addr) in [ + ( + &sequential[..], + 0, + vec![Operand::Vector { + reg: 0, + dwords: regs.len() as u8 - 1, + }], + ), + ( + nsa, + 1, + regs.iter() + .map(|®| Operand::Vector { reg, dwords: 1 }) + .collect(), + ), + ] { + let inst = instruction(&bytes(words), 0).unwrap(); + assert_eq!(inst.words, words); + assert_eq!(inst.encoding, Encoding::Mimg); + assert_eq!(inst.name(), Some(name)); + assert_eq!( + inst.fields(false), + Fields::Image { + data: Operand::Vector { reg: 0, dwords: 4 }, + addr, + rsrc: Operand::Scalar { code: 0, dwords: 8 }, + sampler: Some(Operand::Scalar { code: 8, dwords: 4 }), + dmask: 0xF, + dim, + unorm: false, + r128: false, + a16: false, + d16: false, + tfe: false, + lwe: false, + cache: Cache::default(), + }, + "{name}" + ); + } + } + } + + #[test] + fn vop3p_signed_dot8_operands() { + // llvm/test/MC/AMDGPU/gfx1011_dlops.s + let words = [0xCC18_4000, 0x1C0E_0501]; + let inst = instruction(&bytes(&words), 0).unwrap(); + let vgpr = |reg| Operand::Vector { reg, dwords: 1 }; + assert_eq!(inst.words, words); + assert_eq!((inst.encoding, inst.opcode), (Encoding::Vop3p, 0x018)); + assert_eq!(inst.name(), Some("v_dot8_i32_i4")); + assert_eq!( + inst.fields(false), + Fields::Valu(Valu { + dst: Some(vgpr(0)), + src: vec![vgpr(1), vgpr(2), vgpr(3)], + opsel_hi: 0b111, + ..Valu::default() + }) + ); + } + #[test] fn image_address_dwords_by_form() { // 2D: offset, bias and reference a dword each; 16-bit derivatives @@ -422,6 +619,10 @@ mod tests { (0xA2, true, 3), // image_sample_d_g16, a16 (0xBB, false, 7), // image_sample_c_d_cl_o_g16 (0x33, true, 7), // image_sample_d_cl_o, a16 + (0xE8, true, 3), // image_sample_cd_g16, a16 + (0xE9, true, 4), // image_sample_cd_cl_g16, a16 + (0xEA, true, 4), // image_sample_c_cd_g16, a16 + (0xEB, true, 5), // image_sample_c_cd_cl_g16, a16 ] { let w0 = 0xF000_0000 | (op & 0x7F) << 18 | op >> 7 | 1 << 3 | 1 << 8; let d = decode(&bytes(&[w0, u32::from(a16) << 30, S_ENDPGM])).unwrap(); diff --git a/crates/xtp-shader/src/gfx10/opcodes.rs b/crates/xtp-shader/src/gfx10/opcodes.rs index d1ba275a..32c1d7c2 100644 --- a/crates/xtp-shader/src/gfx10/opcodes.rs +++ b/crates/xtp-shader/src/gfx10/opcodes.rs @@ -800,6 +800,7 @@ pub(super) const VOP3P: &[(u16, &str)] = &[ (0x015, "v_dot2_u32_u16"), (0x016, "v_dot4_i32_i8"), (0x017, "v_dot4_u32_u8"), + (0x018, "v_dot8_i32_i4"), (0x019, "v_dot8_u32_u4"), (0x020, "v_fma_mix_f32"), (0x021, "v_fma_mixlo_f16"), @@ -1151,6 +1152,7 @@ pub(super) const MIMG: &[(u16, &str)] = &[ (0x05e, "image_gather4_c_b_cl_o"), (0x05f, "image_gather4_c_lz_o"), (0x060, "image_get_lod"), + (0x061, "image_gather4h"), (0x068, "image_sample_cd"), (0x069, "image_sample_cd_cl"), (0x06a, "image_sample_c_cd"), @@ -1170,6 +1172,10 @@ pub(super) const MIMG: &[(u16, &str)] = &[ (0x0bb, "image_sample_c_d_cl_o_g16"), (0x0e6, "image_bvh_intersect_ray"), (0x0e7, "image_bvh64_intersect_ray"), + (0x0e8, "image_sample_cd_g16"), + (0x0e9, "image_sample_cd_cl_g16"), + (0x0ea, "image_sample_c_cd_g16"), + (0x0eb, "image_sample_c_cd_cl_g16"), ]; pub(super) const FLAT: &[(u16, &str)] = &[ diff --git a/crates/xtp-shader/src/gfx10/sp3.rs b/crates/xtp-shader/src/gfx10/sp3.rs index 0ca5ab41..e8bfe854 100644 --- a/crates/xtp-shader/src/gfx10/sp3.rs +++ b/crates/xtp-shader/src/gfx10/sp3.rs @@ -96,6 +96,16 @@ fn join(ops: impl IntoIterator) -> String { ops.into_iter().collect::>().join(", ") } +fn interp_src(name: &str, op: Operand) -> String { + match (name, op) { + ("v_interp_mov_f32", Operand::Const(p)) => ["p10", "p20", "p0"] + .get(usize::from(p)) + .unwrap_or(&"p?") + .to_string(), + _ => op.to_string(), + } +} + fn operands(inst: &Instruction, name: &str, fields: &Fields) -> String { let mut out = String::new(); match fields { @@ -151,12 +161,7 @@ fn operands(inst: &Instruction, name: &str, fields: &Fields) -> String { } Fields::Valu(v) => out = valu(name, v, inst.encoding), Fields::Vintrp { dst, src, attr } => { - let src = match (name, src) { - ("v_interp_mov_f32", Operand::Const(p)) => ["p10", "p20", "p0"] - .get(usize::from(*p)) - .map_or("p?".into(), |p| p.to_string()), - _ => src.to_string(), - }; + let src = interp_src(name, *src); out = format!("{dst}, {src}, {attr}"); } Fields::Ds { @@ -504,7 +509,7 @@ fn valu(name: &str, v: &Valu, encoding: Encoding) -> String { let mix = name.starts_with("v_fma_mix"); let src = |i: usize| { let o = v.src[i]; - let mut s = o.to_string(); + let mut s = interp_src(name, o); if let Some(sdwa) = v.sdwa && bit(sdwa.sext, i) { diff --git a/crates/xtp-shader/src/io.rs b/crates/xtp-shader/src/io.rs index 011d0198..2fd770f0 100644 --- a/crates/xtp-shader/src/io.rs +++ b/crates/xtp-shader/src/io.rs @@ -421,6 +421,9 @@ pub(crate) fn raise_inputs( } } Fields::Valu(v) if name.starts_with("v_interp_") => match name { + "v_interp_p1_f32" | "v_interp_p2_f32" | "v_interp_mov_f32" => { + return Err(unsupported(at, "an e64 f32 interpolation")); + } "v_interp_p1ll_f16" => { if read_first { first_halves.push((site, attribute(inst, &v.src[0])?)); From e75d274ea9b385c78b44368253fe429e9ac2b32e Mon Sep 17 00:00:00 2001 From: PrivacyOnion Date: Wed, 25 Nov 2026 14:51:58 +0100 Subject: [PATCH 2/3] shader, docs: lower packed coarse gradient samples --- README.md | 8 +++--- crates/xtp-shader/src/emit/image_tests.rs | 32 ++++++++++++++++++++--- crates/xtp-shader/src/emit/lower/image.rs | 16 ++++-------- crates/xtp-shader/src/gfx10/mod.rs | 22 +++++++++++++++- crates/xtp-shader/src/gfx10/opcodes.rs | 10 ++++++- 5 files changed, 68 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 4ccdf645..a7348815 100644 --- a/README.md +++ b/README.md @@ -124,9 +124,11 @@ xtp config ``` `xtp shader-info --disasm` decodes the GFX10 e64 f32 interpolation forms, -`image_gather4h`, the four coarse gradient samples with `_g16`, and -`v_dot8_i32_i4`. Translating shaders that need these instructions still -requires DXIL lowering for them. +`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 diff --git a/crates/xtp-shader/src/emit/image_tests.rs b/crates/xtp-shader/src/emit/image_tests.rs index ca52a300..7cd30633 100644 --- a/crates/xtp-shader/src/emit/image_tests.rs +++ b/crates/xtp-shader/src/emit/image_tests.rs @@ -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)] = &[ @@ -1446,16 +1470,16 @@ fn forms_without_an_sm_6_6_equivalent_name_why() { ), ("image_gather4h", false, false, "image_gather4h"), ( - "image_sample_cd_g16", + "image_sample_c_cd_o_g16", false, false, - "a sample with coarse packed derivatives", + "a comparison sample with explicit derivatives", ), ( - "image_sample_cd_cl_g16", + "image_sample_c_cd_cl_o_g16", false, false, - "a sample with coarse packed derivatives", + "a comparison sample with explicit derivatives", ), ]; for &(name, zero_bias, zero_level, why) in cases { diff --git a/crates/xtp-shader/src/emit/lower/image.rs b/crates/xtp-shader/src/emit/lower/image.rs index 190bac99..d26a7750 100644 --- a/crates/xtp-shader/src/emit/lower/image.rs +++ b/crates/xtp-shader/src/emit/lower/image.rs @@ -373,14 +373,8 @@ impl<'a> Lower<'a> { unreachable!() }; let name = inst.name(); - match name { - "image_gather4h" => return Err(name), - "image_sample_cd_g16" | "image_sample_cd_cl_g16" => { - // SampleGrad selects a level per lane. The coarse form - // selects one level per quad. - return Err("a sample with coarse packed derivatives"); - } - _ => {} + if name == "image_gather4h" { + return Err(name); } if *tfe || *lwe { return Err("an image access with tfe or lwe"); @@ -976,9 +970,9 @@ 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. + // 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 diff --git a/crates/xtp-shader/src/gfx10/mod.rs b/crates/xtp-shader/src/gfx10/mod.rs index a3f1cf94..24329262 100644 --- a/crates/xtp-shader/src/gfx10/mod.rs +++ b/crates/xtp-shader/src/gfx10/mod.rs @@ -541,9 +541,15 @@ mod tests { ]; for (name, w0, nsa, regs) in cases { let sequential = [w0, 0x0040_0000]; - for (words, dim, addr) in [ + // The coarse offset pairs in gfx10_asm_mimg.s add four to the + // opcode and put an offset dword first. Build the packed offset + // encodings from the sequential LLVM cases using that layout. + let offset = [w0 + (4 << 18), sequential[1]]; + let offset_name = format!("{}_o_g16", name.strip_suffix("_g16").unwrap()); + for (words, name, dim, addr) in [ ( &sequential[..], + name, 0, vec![Operand::Vector { reg: 0, @@ -552,11 +558,21 @@ mod tests { ), ( nsa, + name, 1, regs.iter() .map(|®| Operand::Vector { reg, dwords: 1 }) .collect(), ), + ( + &offset[..], + offset_name.as_str(), + 0, + vec![Operand::Vector { + reg: 0, + dwords: regs.len() as u8, + }], + ), ] { let inst = instruction(&bytes(words), 0).unwrap(); assert_eq!(inst.words, words); @@ -623,6 +639,10 @@ mod tests { (0xE9, true, 4), // image_sample_cd_cl_g16, a16 (0xEA, true, 4), // image_sample_c_cd_g16, a16 (0xEB, true, 5), // image_sample_c_cd_cl_g16, a16 + (0xEC, true, 4), // image_sample_cd_o_g16, a16 + (0xED, true, 5), // image_sample_cd_cl_o_g16, a16 + (0xEE, true, 5), // image_sample_c_cd_o_g16, a16 + (0xEF, true, 6), // image_sample_c_cd_cl_o_g16, a16 ] { let w0 = 0xF000_0000 | (op & 0x7F) << 18 | op >> 7 | 1 << 3 | 1 << 8; let d = decode(&bytes(&[w0, u32::from(a16) << 30, S_ENDPGM])).unwrap(); diff --git a/crates/xtp-shader/src/gfx10/opcodes.rs b/crates/xtp-shader/src/gfx10/opcodes.rs index 32c1d7c2..355a455f 100644 --- a/crates/xtp-shader/src/gfx10/opcodes.rs +++ b/crates/xtp-shader/src/gfx10/opcodes.rs @@ -1,4 +1,8 @@ -// GFX10 opcode names, generated from Mesa's src/amd/compiler/aco_opcodes.py +// LLVM MC encodings (llvm-project llvmorg-19.1.7, Apache-2.0 WITH +// LLVM-exception) supply VOP3P 0x018 and MIMG 0x061 and 0x0e8..=0x0eb. +// MIMG 0x0ec..=0x0ef are the offset forms identified in review, following +// the same opcode pattern as the coarse offset pairs in LLVM MC. +// The remaining rows come from Mesa's src/amd/compiler/aco_opcodes.py // (tag mesa-22.3.0, GFX10 column), which carries this notice: // // Copyright (c) 2018 Valve Corporation @@ -1176,6 +1180,10 @@ pub(super) const MIMG: &[(u16, &str)] = &[ (0x0e9, "image_sample_cd_cl_g16"), (0x0ea, "image_sample_c_cd_g16"), (0x0eb, "image_sample_c_cd_cl_g16"), + (0x0ec, "image_sample_cd_o_g16"), + (0x0ed, "image_sample_cd_cl_o_g16"), + (0x0ee, "image_sample_c_cd_o_g16"), + (0x0ef, "image_sample_c_cd_cl_o_g16"), ]; pub(super) const FLAT: &[(u16, &str)] = &[ From e8910747863bf976c0c9ad78a18a684202e05207 Mon Sep 17 00:00:00 2001 From: PrivacyOnion Date: Wed, 25 Nov 2026 15:16:37 +0100 Subject: [PATCH 3/3] shader: drop the decoder gap pins this change fixes With the conformance corpus on main, the nine names this change decodes would fail its stale-pin check. Also keep the shortcut: prefix on the coarse-form comment and cite LLVM's MIMG table for 0x0ec..=0x0ef. --- crates/xtp-shader/src/emit/lower/image.rs | 7 ++++--- crates/xtp-shader/src/gfx10/opcodes.rs | 4 ++-- crates/xtp-shader/tests/gfx10_conformance.rs | 15 +-------------- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/crates/xtp-shader/src/emit/lower/image.rs b/crates/xtp-shader/src/emit/lower/image.rs index d26a7750..cc888ae9 100644 --- a/crates/xtp-shader/src/emit/lower/image.rs +++ b/crates/xtp-shader/src/emit/lower/image.rs @@ -970,9 +970,10 @@ impl<'a> Lower<'a> { sampler.sample(self, "sampleBias.f32", 61, &mut args) } 63 => { - // 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. + // 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 diff --git a/crates/xtp-shader/src/gfx10/opcodes.rs b/crates/xtp-shader/src/gfx10/opcodes.rs index 355a455f..8e7f5f70 100644 --- a/crates/xtp-shader/src/gfx10/opcodes.rs +++ b/crates/xtp-shader/src/gfx10/opcodes.rs @@ -1,7 +1,7 @@ // LLVM MC encodings (llvm-project llvmorg-19.1.7, Apache-2.0 WITH // LLVM-exception) supply VOP3P 0x018 and MIMG 0x061 and 0x0e8..=0x0eb. -// MIMG 0x0ec..=0x0ef are the offset forms identified in review, following -// the same opcode pattern as the coarse offset pairs in LLVM MC. +// MIMG 0x0ec..=0x0ef (image_sample_*cd*_o_g16) are the GFX10 opcodes that +// LLVM's llvm/lib/Target/AMDGPU/MIMGInstructions.td gives at the same tag. // The remaining rows come from Mesa's src/amd/compiler/aco_opcodes.py // (tag mesa-22.3.0, GFX10 column), which carries this notice: // diff --git a/crates/xtp-shader/tests/gfx10_conformance.rs b/crates/xtp-shader/tests/gfx10_conformance.rs index 481c150b..3563fff5 100644 --- a/crates/xtp-shader/tests/gfx10_conformance.rs +++ b/crates/xtp-shader/tests/gfx10_conformance.rs @@ -25,20 +25,7 @@ const UNRESOLVED_LEGACY_NAMES: &[(&str, &str)] = &[ ]; /// Valid LLVM MC mnemonics for which XTP currently returns no name. -const KNOWN_DECODER_GAPS: &[&str] = &[ - // VOP3 0x200..=0x202 needs aliases to the VINTRP table. - "v_interp_p1_f32", - "v_interp_p2_f32", - "v_interp_mov_f32", - // MIMG 0x061 and 0x0e8..=0x0eb are missing from the opcode table. - "image_gather4h", - "image_sample_cd_g16", - "image_sample_cd_cl_g16", - "image_sample_c_cd_g16", - "image_sample_c_cd_cl_g16", - // VOP3P 0x018 is missing from the opcode table. - "v_dot8_i32_i4", -]; +const KNOWN_DECODER_GAPS: &[&str] = &[]; fn load_corpus() -> Vec<(String, Vec)> { let dir = Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/data");