mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 15:30:43 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4c6242f086 | ||
|
|
6814d78230 | ||
|
|
0fdb995892 | ||
|
|
d7f7d586d3 |
No files matched your search
@@ -17,6 +17,18 @@ remains unsupported.
|
||||
- Extended the read-only RDNA2 planning CLI (`python3 -m qa rdna2`) with family/status filters, compact summaries, Codex-ready manifests under `artifacts/`, active-claim exclusion (family claims exclude those families; path-only claims block overlapping permitted files), coverage reconcile against `semantic_coverage` without inflating counts, and inventory diffs. Covered by `tests/qa/test_rdna2_plan.py`; planning only, no GPU production edits.
|
||||
|
||||
### Added
|
||||
- Added an opt-in, budgeted staged upload for RGBA8 textures (#144). `MetalRgba8Texture::upload_staged` fills a
|
||||
Private-storage texture through one reused Shared staging buffer that never exceeds a `StagingBudget`. It
|
||||
copies whole-row bands with a blit encoder and reuses the buffer only after the previous command buffer has
|
||||
completed with status Completed. `plan_staged_upload` rejects missing, duplicate or out-of-range mip levels,
|
||||
wrong mip sizes, short row pitches or byte buffers, and budgets smaller than one row, all before any Metal
|
||||
object is created. A blit `read_back` returns any mip as tight RGBA8 bytes. On one Apple M4 under Metal API
|
||||
validation, readback matched independently built patterns for every level of a padded 37×19, six-level
|
||||
texture under four budgets, and matched the existing direct `upload`. Staging is slower than the direct path
|
||||
(2048² with 12 mips, release build: 2.1 ms direct, 2.7 ms with a 4 MiB budget, 17.8 ms with 256 KiB), so
|
||||
`upload` and its callers are unchanged. Not yet independently accepted.
|
||||
- Added the VOP3A (`_e64`) encodings of eleven gfx1030 VOP2 integer forms (`v_mul_{i32_i24,hi_i32_i24,u32_u24,hi_u32_u24}`, `v_{min,max}_{i32,u32}`, `v_xnor_b32`, `v_sub_nc_u32`, `v_subrev_nc_u32`) and of the sixteen Wave32 integer compares (explicit SGPR mask destination, `s_cbranch_vccz` through `vcc_lo`, a translation error for reads of runtime-only SGPR results) as semantic-registry encoding variants, with VGPR sources only. New fixtures `vop3-integer` and `vop3-compare` with IR and MSL goldens, and an independent guide-derived oracle (`tests/validation/tests/vop3_{integer,compare}.rs`) that agrees on both reference interpreters and on native Metal. Part of #215.
|
||||
- Added guest texture binding through D3D12-style descriptor tables (#303): shader-visible CBV_SRV_UAV and sampler heaps, `CreateShaderResourceView` for one-level RGBA8 and BC1 2D textures, a point/clamp `CreateSampler`, a root signature with one pixel-stage SRV table and one sampler table, and `SetDescriptorHeaps`/`SetGraphicsRootDescriptorTable` in `crates/loader/src/graphics.rs`, plus `NativeCompute::render_rgba8_sampled_bc1`. Verified locally on an Apple M5 Pro under Metal validation: a guest draw with the translated `image_sample_lz` pixel stage matches the software reference and hand-derived images on 16 of 16 pixels for two RGBA8 textures and 64 of 64 for an 8×8 BC1 texture. A wrong descriptor slot changes the image, off-centre and out-of-range coordinates point-sample with clamping, and a rejected binding, draw shape or resource state never reaches the backend. The software reference samples BC1 with the spec-exact decoder, while Apple's hardware rounds BC1's interpolated palette entries differently (171/84 against 170/85), so the BC1 fixtures use only endpoint colours. Not yet reachable from guest imports. Not yet independently accepted.
|
||||
- Added four Wave32 gfx1030 VOP2 select and carry forms through the semantic registry. Conditional select, add with carry and both subtract orders with borrow use a per-lane VCC bit and have a guide-derived oracle that passes on both CPU interpreters and on native Metal (local Apple M5, API and shader validation); independent acceptance is pending. Part of #215.
|
||||
- Added decoding and Metal shader translation for twelve Wave32 VOPC 16-bit integer compares (#215). The signed and unsigned forms compare the low 16 bits of each source and write the Wave32 VCC mask. CPU verification covers 1,572 compiler acceptance cases and 408 rejections from the guide-derived oracle, which also passes on native Metal (1,572 cases in 1,420 programs on a local Apple M5 under API and shader validation); acceptance is pending.
|
||||
- Added MOVS and STOS for 8- to 64-bit elements, with and without REP, and the direction flag with CLD and STD (#129). A REP form runs one element per step and stays on the instruction until RCX is zero, so every element counts against the step budget, a repeat can stop part-way and resume, a zero count touches nothing, and a fault keeps the elements already done with RSI, RDI and RCX at the one that faulted. An FS or GS override applies to the MOVS source only. Both engines run these on the shared semantics with no bulk-copy path, so large copies are slow. LODS, CMPS, SCAS, REPE, REPNE and the address-size override stay rejected. Fourteen SDM-derived cases already in `cpu_known_answers.rs` moved from refused to verified, and `tests/cpu_rep.rs` adds a byte-array model over every form, direction and count; not compared with x86 hardware and awaiting independent review.
|
||||
|
||||
Generated
+1
@@ -204,6 +204,7 @@ dependencies = [
|
||||
"sha2",
|
||||
"xenora-metal",
|
||||
"xenora-shader",
|
||||
"xenora-texture",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
+41
-13
@@ -5,8 +5,8 @@ use std::fmt;
|
||||
pub use xenora_isa::{
|
||||
Architecture, CompareRelation, ExportTarget, Instruction, InterpolationPhase, ScalarAluOp,
|
||||
ScalarCompareOp, ScalarImmediateCompareOp, ScalarImmediateOp, ScalarSource, ScalarUnaryOp,
|
||||
SoppControlOp, VectorAluOp, VectorAluVop3Op, VectorCompareOp, VectorSource, VectorSwapOp,
|
||||
VectorUnaryOp,
|
||||
SoppControlOp, VectorAluOp, VectorAluVop3Op, VectorCompareOp, VectorCompareVop3Op,
|
||||
VectorSource, VectorSwapOp, VectorUnaryOp,
|
||||
};
|
||||
use xenora_isa::{
|
||||
BUFFER_LOAD_DWORD, BUFFER_STORE_DWORD, EXP, IMAGE_SAMPLE_LZ, S_WAITCNT_VSCNT, V_ADD_F32,
|
||||
@@ -330,6 +330,26 @@ fn decode_gfx1030(bytes: &[u8], offset: usize) -> Result<(Instruction, u8), Deco
|
||||
if let Some(op) = VectorCompareOp::from_word(first) {
|
||||
return vector_compare(op, first, bytes);
|
||||
}
|
||||
if let Some(op) = VectorCompareVop3Op::from_word(first) {
|
||||
let second = word(bytes, 8)?;
|
||||
let sdst = first as u8;
|
||||
if sdst > VCC_LO {
|
||||
return Err(unsupported(
|
||||
op.assembly_name(),
|
||||
"expected a destination of s0-s105 or vcc_lo",
|
||||
));
|
||||
}
|
||||
let (src0, src1) = vop3_vgpr2_sources(op.assembly_name(), first, second)?;
|
||||
return Ok((
|
||||
Instruction::VectorCompareVop3 {
|
||||
op,
|
||||
sdst,
|
||||
src0,
|
||||
src1,
|
||||
},
|
||||
8,
|
||||
));
|
||||
}
|
||||
if let Some(op) = VectorAluVop3Op::from_word(first) {
|
||||
let second = word(bytes, 8)?;
|
||||
return Ok((vop3_vgpr2(op, first, second)?, 8));
|
||||
@@ -723,29 +743,37 @@ fn move_b32(first: u32, bytes: &[u8]) -> Result<(Instruction, u8), DecodeErrorKi
|
||||
Ok((Instruction::MoveB32 { dst, src }, len))
|
||||
}
|
||||
|
||||
/// Operand rule `vop3_vgpr2`: VDST in bits 0-7 of the first word, SRC0 and SRC1
|
||||
/// in bits 0-8 and 9-17 of the second (RDNA 2 ISA section 13.3.4, VOP3A). Both sources
|
||||
/// are VGPRs, ABS, OP_SEL, CLAMP, OMOD and NEG are clear, and the unused SRC2 is
|
||||
/// the gfx1030 assembler's inline-zero operand encoding.
|
||||
fn vop3_vgpr2(
|
||||
op: VectorAluVop3Op,
|
||||
first: u32,
|
||||
second: u32,
|
||||
) -> Result<Instruction, DecodeErrorKind> {
|
||||
let (src0, src1) = vop3_vgpr2_sources(op.assembly_name(), first, second)?;
|
||||
Ok(Instruction::VectorAluVop3 {
|
||||
op,
|
||||
dst: first as u8,
|
||||
src0,
|
||||
src1,
|
||||
})
|
||||
}
|
||||
|
||||
/// Common VOP3A source and modifier checks (RDNA 2 ISA section 13.3.4).
|
||||
/// SRC0 and SRC1 are VGPRs, the unused SRC2 is inline zero, and ABS, OP_SEL,
|
||||
/// CLAMP, OMOD and NEG are clear.
|
||||
fn vop3_vgpr2_sources(
|
||||
mnemonic: &'static str,
|
||||
first: u32,
|
||||
second: u32,
|
||||
) -> Result<(u8, u8), DecodeErrorKind> {
|
||||
let src0 = second & 0x1ff;
|
||||
let src1 = (second >> 9) & 0x1ff;
|
||||
if first & 0xff00 != 0 || second >> 18 != 128 || src0 < 256 || src1 < 256 {
|
||||
return Err(unsupported(
|
||||
op.assembly_name(),
|
||||
mnemonic,
|
||||
"expected two VGPR sources and no modifiers",
|
||||
));
|
||||
}
|
||||
Ok(Instruction::VectorAluVop3 {
|
||||
op,
|
||||
dst: first as u8,
|
||||
src0: src0 as u8,
|
||||
src1: src1 as u8,
|
||||
})
|
||||
Ok((src0 as u8, src1 as u8))
|
||||
}
|
||||
|
||||
fn scalar_form(
|
||||
|
||||
+304
-36
@@ -5,7 +5,7 @@ use std::process::{Command, Stdio};
|
||||
use xenora_decoder::{
|
||||
Architecture, CompareRelation, DecodeError, DecodeErrorKind, DecodedInstruction, Instruction,
|
||||
ScalarAluOp, ScalarImmediateOp, ScalarSource, ScalarUnaryOp, VectorAluOp, VectorAluVop3Op,
|
||||
VectorSource, VectorUnaryOp, decode, decode_at,
|
||||
VectorCompareOp, VectorCompareVop3Op, VectorSource, VectorUnaryOp, decode, decode_at,
|
||||
};
|
||||
use xenora_isa::semantics::Signedness;
|
||||
use xenora_ref::{
|
||||
@@ -71,6 +71,127 @@ fn decodes_each_fixture_instruction_with_offset_and_length() {
|
||||
assert_eq!(instructions, wanted);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decodes_wave32_vop3_compares_from_llvm_words() {
|
||||
use VectorCompareVop3Op::*;
|
||||
|
||||
// llvm-mc -triple=amdgcn -mcpu=gfx1030 -mattr=+wavefrontsize32 -show-encoding
|
||||
let cases: [(u32, VectorCompareVop3Op, u8); 19] = [
|
||||
// v_cmp_lt_i32_e64 s4, v1, v2 ; encoding: [0x04,0x00,0x81,0xd4,0x01,0x05,0x02,0x02]
|
||||
(0xd481_0004, CmpLtI32, 4),
|
||||
// v_cmp_eq_i32_e64 s4, v1, v2 ; encoding: [0x04,0x00,0x82,0xd4,0x01,0x05,0x02,0x02]
|
||||
(0xd482_0004, CmpEqI32, 4),
|
||||
// v_cmp_le_i32_e64 s4, v1, v2 ; encoding: [0x04,0x00,0x83,0xd4,0x01,0x05,0x02,0x02]
|
||||
(0xd483_0004, CmpLeI32, 4),
|
||||
// v_cmp_gt_i32_e64 s4, v1, v2 ; encoding: [0x04,0x00,0x84,0xd4,0x01,0x05,0x02,0x02]
|
||||
(0xd484_0004, CmpGtI32, 4),
|
||||
// v_cmp_ne_i32_e64 s4, v1, v2 ; encoding: [0x04,0x00,0x85,0xd4,0x01,0x05,0x02,0x02]
|
||||
(0xd485_0004, CmpNeI32, 4),
|
||||
// v_cmp_ge_i32_e64 s4, v1, v2 ; encoding: [0x04,0x00,0x86,0xd4,0x01,0x05,0x02,0x02]
|
||||
(0xd486_0004, CmpGeI32, 4),
|
||||
// v_cmp_lt_u32_e64 s4, v1, v2 ; encoding: [0x04,0x00,0xc1,0xd4,0x01,0x05,0x02,0x02]
|
||||
(0xd4c1_0004, CmpLtU32, 4),
|
||||
// v_cmp_eq_u32_e64 s4, v1, v2 ; encoding: [0x04,0x00,0xc2,0xd4,0x01,0x05,0x02,0x02]
|
||||
(0xd4c2_0004, CmpEqU32, 4),
|
||||
// v_cmp_le_u32_e64 s4, v1, v2 ; encoding: [0x04,0x00,0xc3,0xd4,0x01,0x05,0x02,0x02]
|
||||
(0xd4c3_0004, CmpLeU32, 4),
|
||||
// v_cmp_gt_u32_e64 s4, v1, v2 ; encoding: [0x04,0x00,0xc4,0xd4,0x01,0x05,0x02,0x02]
|
||||
(0xd4c4_0004, CmpGtU32, 4),
|
||||
// v_cmp_ne_u32_e64 s4, v1, v2 ; encoding: [0x04,0x00,0xc5,0xd4,0x01,0x05,0x02,0x02]
|
||||
(0xd4c5_0004, CmpNeU32, 4),
|
||||
// v_cmp_ge_u32_e64 s4, v1, v2 ; encoding: [0x04,0x00,0xc6,0xd4,0x01,0x05,0x02,0x02]
|
||||
(0xd4c6_0004, CmpGeU32, 4),
|
||||
// v_cmp_f_i32_e64 s4, v1, v2 ; encoding: [0x04,0x00,0x80,0xd4,0x01,0x05,0x02,0x02]
|
||||
(0xd480_0004, CmpFI32, 4),
|
||||
// v_cmp_t_i32_e64 s4, v1, v2 ; encoding: [0x04,0x00,0x87,0xd4,0x01,0x05,0x02,0x02]
|
||||
(0xd487_0004, CmpTI32, 4),
|
||||
// v_cmp_f_u32_e64 s4, v1, v2 ; encoding: [0x04,0x00,0xc0,0xd4,0x01,0x05,0x02,0x02]
|
||||
(0xd4c0_0004, CmpFU32, 4),
|
||||
// v_cmp_t_u32_e64 s4, v1, v2 ; encoding: [0x04,0x00,0xc7,0xd4,0x01,0x05,0x02,0x02]
|
||||
(0xd4c7_0004, CmpTU32, 4),
|
||||
// v_cmp_eq_u32_e64 s0, v1, v2 ; encoding: [0x00,0x00,0xc2,0xd4,0x01,0x05,0x02,0x02]
|
||||
(0xd4c2_0000, CmpEqU32, 0),
|
||||
// v_cmp_eq_u32_e64 s105, v1, v2 ; encoding: [0x69,0x00,0xc2,0xd4,0x01,0x05,0x02,0x02]
|
||||
(0xd4c2_0069, CmpEqU32, 105),
|
||||
// v_cmp_eq_u32_e64 vcc_lo, v1, v2 ; encoding: [0x6a,0x00,0xc2,0xd4,0x01,0x05,0x02,0x02]
|
||||
(0xd4c2_006a, CmpEqU32, 106),
|
||||
];
|
||||
for (first, op, sdst) in cases {
|
||||
let code: Vec<_> = [first, 0x0202_0501]
|
||||
.into_iter()
|
||||
.flat_map(u32::to_le_bytes)
|
||||
.collect();
|
||||
let decoded = decode(Architecture::Gfx1030, &code).unwrap();
|
||||
let dst = if sdst == 106 {
|
||||
"vcc_lo".to_owned()
|
||||
} else {
|
||||
format!("s{sdst}")
|
||||
};
|
||||
assert_eq!(
|
||||
decoded,
|
||||
[DecodedInstruction {
|
||||
offset: 0,
|
||||
byte_len: 8,
|
||||
instruction: Instruction::VectorCompareVop3 {
|
||||
op,
|
||||
sdst,
|
||||
src0: 1,
|
||||
src1: 2
|
||||
},
|
||||
}],
|
||||
);
|
||||
assert_eq!(
|
||||
decoded[0].instruction.to_string(),
|
||||
format!("{} {dst}, v1, v2", op.assembly_name())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_noncanonical_wave32_vop3_compare_operands() {
|
||||
// v_cmp_eq_u32_e64 s4, v1, v2
|
||||
let first = 0xd4c2_0004;
|
||||
let second = 0x0202_0501;
|
||||
let rejects = |first, second| {
|
||||
let code: Vec<_> = [first, second]
|
||||
.into_iter()
|
||||
.flat_map(u32::to_le_bytes)
|
||||
.collect();
|
||||
let error = decode(Architecture::Gfx1030, &code).unwrap_err();
|
||||
assert_eq!(error.offset, 0);
|
||||
assert!(
|
||||
matches!(
|
||||
error.kind,
|
||||
DecodeErrorKind::UnsupportedForm {
|
||||
mnemonic: "v_cmp_eq_u32_e64",
|
||||
..
|
||||
}
|
||||
),
|
||||
"{first:#010x} {second:#010x}: {error}"
|
||||
);
|
||||
};
|
||||
|
||||
// Includes vcc_hi (107), TTMPs (108-123), null (124), m0 (125) and EXEC (126-127).
|
||||
for sdst in 107..=255 {
|
||||
rejects((first & !0xff) | sdst, second);
|
||||
}
|
||||
for bit in 8..=15 {
|
||||
// ABS, OP_SEL and CLAMP.
|
||||
rejects(first | (1 << bit), second);
|
||||
}
|
||||
for bit in 27..=31 {
|
||||
// OMOD and NEG.
|
||||
rejects(first, second | (1 << bit));
|
||||
}
|
||||
rejects(first, second ^ (1 << 18)); // SRC2 = 129 instead of 128.
|
||||
for shift in [0, 9] {
|
||||
for selector in [4, 106, 128, 240, 255] {
|
||||
// SGPR, VCC_LO, inline integer/float, literal.
|
||||
rejects(first, (second & !(0x1ff << shift)) | (selector << shift));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_non_boundary_prefix_reports_the_incomplete_instruction() {
|
||||
let lengths = [8, 4, 8, 8, 8, 4, 4];
|
||||
@@ -303,6 +424,44 @@ fn reference_scalar(scalar: ScalarSource) -> Source {
|
||||
}
|
||||
}
|
||||
|
||||
fn reference_comparison(op: VectorCompareOp) -> Comparison {
|
||||
Comparison {
|
||||
offset: match op.relation() {
|
||||
CompareRelation::Less => 1,
|
||||
CompareRelation::Equal => 2,
|
||||
CompareRelation::LessOrEqual => 3,
|
||||
CompareRelation::Greater => 4,
|
||||
CompareRelation::NotEqual => 5,
|
||||
CompareRelation::GreaterOrEqual => 6,
|
||||
CompareRelation::False => 0,
|
||||
CompareRelation::True => 7,
|
||||
},
|
||||
signed: op.signed(),
|
||||
}
|
||||
}
|
||||
|
||||
fn reference_vector_integer(op: VectorAluOp) -> VectorInteger {
|
||||
match op {
|
||||
VectorAluOp::CndmaskB32 => VectorInteger::Select,
|
||||
VectorAluOp::AddCoCiU32 => VectorInteger::AddCarry,
|
||||
VectorAluOp::SubCoCiU32 => VectorInteger::SubtractBorrow { reversed: false },
|
||||
VectorAluOp::SubrevCoCiU32 => VectorInteger::SubtractBorrow { reversed: true },
|
||||
VectorAluOp::MulI32I24 => VectorInteger::Multiply24 { signed: true },
|
||||
VectorAluOp::MulHiI32I24 => VectorInteger::MultiplyHigh24 { signed: true },
|
||||
VectorAluOp::MulU32U24 => VectorInteger::Multiply24 { signed: false },
|
||||
VectorAluOp::MulHiU32U24 => VectorInteger::MultiplyHigh24 { signed: false },
|
||||
VectorAluOp::MinI32 => VectorInteger::Minimum { signed: true },
|
||||
VectorAluOp::MaxI32 => VectorInteger::Maximum { signed: true },
|
||||
VectorAluOp::MinU32 => VectorInteger::Minimum { signed: false },
|
||||
VectorAluOp::MaxU32 => VectorInteger::Maximum { signed: false },
|
||||
VectorAluOp::XnorB32 => VectorInteger::Xnor,
|
||||
VectorAluOp::AddNcU32 => VectorInteger::Add,
|
||||
VectorAluOp::SubNcU32 => VectorInteger::Subtract,
|
||||
VectorAluOp::SubrevNcU32 => VectorInteger::SubtractReverse,
|
||||
_ => panic!("{op:?} decodes only with a VGPR SRC0 (operand rule vop2_vgpr2)"),
|
||||
}
|
||||
}
|
||||
|
||||
fn reference_op(instruction: Instruction) -> Op {
|
||||
match instruction {
|
||||
Instruction::BufferLoadDword {
|
||||
@@ -391,13 +550,23 @@ fn reference_op(instruction: Instruction) -> Op {
|
||||
reference_scalar(src0),
|
||||
reference_scalar(src1),
|
||||
),
|
||||
// The reference's VOP3 add; it is the only VOP3 variant so far.
|
||||
Instruction::VectorAluVop3 {
|
||||
op: VectorAluVop3Op::AddNcU32,
|
||||
dst,
|
||||
src0,
|
||||
src1,
|
||||
} => Op::Add(dst, src0, src1),
|
||||
Instruction::VectorAluVop3 {
|
||||
op,
|
||||
dst,
|
||||
src0,
|
||||
src1,
|
||||
} => Op::VectorInteger(
|
||||
reference_vector_integer(op.base()),
|
||||
dst,
|
||||
CompareSource::Vector(src0),
|
||||
src1,
|
||||
),
|
||||
Instruction::ScalarUnary { op, dst, src } => {
|
||||
let src = reference_scalar(src);
|
||||
let unary = match op {
|
||||
@@ -506,19 +675,7 @@ fn reference_op(instruction: Instruction) -> Op {
|
||||
}
|
||||
|
||||
Instruction::VectorCompare { op, src0, src1 } => {
|
||||
let comparison = Comparison {
|
||||
offset: match op.relation() {
|
||||
CompareRelation::Less => 1,
|
||||
CompareRelation::Equal => 2,
|
||||
CompareRelation::LessOrEqual => 3,
|
||||
CompareRelation::Greater => 4,
|
||||
CompareRelation::NotEqual => 5,
|
||||
CompareRelation::GreaterOrEqual => 6,
|
||||
CompareRelation::False => 0,
|
||||
CompareRelation::True => 7,
|
||||
},
|
||||
signed: op.signed(),
|
||||
};
|
||||
let comparison = reference_comparison(op);
|
||||
let src0 = match src0 {
|
||||
VectorSource::Register(reg) => CompareSource::Vector(reg),
|
||||
VectorSource::Scalar(reg) => CompareSource::Scalar(reg),
|
||||
@@ -531,31 +688,24 @@ fn reference_op(instruction: Instruction) -> Op {
|
||||
width => panic!("unexpected VOPC operand width {width}"),
|
||||
}
|
||||
}
|
||||
Instruction::VectorCompareVop3 {
|
||||
op,
|
||||
sdst,
|
||||
src0,
|
||||
src1,
|
||||
} => Op::CompareVop3(
|
||||
sdst,
|
||||
reference_comparison(op.base()),
|
||||
CompareSource::Vector(src0),
|
||||
src1,
|
||||
),
|
||||
Instruction::VectorAlu {
|
||||
op,
|
||||
dst,
|
||||
src0,
|
||||
src1,
|
||||
} => Op::VectorInteger(
|
||||
match op {
|
||||
VectorAluOp::CndmaskB32 => VectorInteger::Select,
|
||||
VectorAluOp::AddCoCiU32 => VectorInteger::AddCarry,
|
||||
VectorAluOp::SubCoCiU32 => VectorInteger::SubtractBorrow { reversed: false },
|
||||
VectorAluOp::SubrevCoCiU32 => VectorInteger::SubtractBorrow { reversed: true },
|
||||
VectorAluOp::MulI32I24 => VectorInteger::Multiply24 { signed: true },
|
||||
VectorAluOp::MulHiI32I24 => VectorInteger::MultiplyHigh24 { signed: true },
|
||||
VectorAluOp::MulU32U24 => VectorInteger::Multiply24 { signed: false },
|
||||
VectorAluOp::MulHiU32U24 => VectorInteger::MultiplyHigh24 { signed: false },
|
||||
VectorAluOp::MinI32 => VectorInteger::Minimum { signed: true },
|
||||
VectorAluOp::MaxI32 => VectorInteger::Maximum { signed: true },
|
||||
VectorAluOp::MinU32 => VectorInteger::Minimum { signed: false },
|
||||
VectorAluOp::MaxU32 => VectorInteger::Maximum { signed: false },
|
||||
VectorAluOp::XnorB32 => VectorInteger::Xnor,
|
||||
VectorAluOp::AddNcU32 => VectorInteger::Add,
|
||||
VectorAluOp::SubNcU32 => VectorInteger::Subtract,
|
||||
VectorAluOp::SubrevNcU32 => VectorInteger::SubtractReverse,
|
||||
_ => panic!("{op:?} decodes only with a VGPR SRC0 (operand rule vop2_vgpr2)"),
|
||||
},
|
||||
reference_vector_integer(op),
|
||||
dst,
|
||||
match src0 {
|
||||
VectorSource::Register(reg) => CompareSource::Vector(reg),
|
||||
@@ -596,12 +746,14 @@ fn compares_fixture_instructions_against_llvm() {
|
||||
include_bytes!("../../../fixtures/rdna2/vector-compare-ft.bin"),
|
||||
include_bytes!("../../../fixtures/rdna2/vector-unary.bin"),
|
||||
include_bytes!("../../../fixtures/rdna2/vector-compare-16.bin"),
|
||||
include_bytes!("../../../fixtures/rdna2/vop3-integer.bin"),
|
||||
include_bytes!("../../../fixtures/rdna2/vop3-compare.bin"),
|
||||
high_registers,
|
||||
&matrix,
|
||||
] {
|
||||
count += compare_against_llvm(fixture, &mut forms);
|
||||
}
|
||||
assert_eq!(forms.len(), 142, "forms compared: {forms:?}");
|
||||
assert_eq!(forms.len(), 169, "forms compared: {forms:?}");
|
||||
eprintln!(
|
||||
"{count} three-way instruction comparisons across {} forms",
|
||||
forms.len()
|
||||
@@ -829,7 +981,7 @@ fn distinguishes_llvm_invalid_encodings_from_xenora_subset_rejections() {
|
||||
let outside_subset: &[&[u32]] = &[
|
||||
&[0x7e04_026b], // VOP1 VCC_HI source
|
||||
&[0x7da2_0501], // v_cmpx_eq_u32_e32
|
||||
&[0xd482_006a, 0x0002_0501], // v_cmp_lt_i32_e64
|
||||
&[0xd482_006a, 0x0002_0501], // v_cmp_eq_i32_e64 with SRC2 = 0
|
||||
&[0x8788_0908], // s_and_b64
|
||||
&[0x8008_ffff, 0x1234_5678], // SOP2 with two literal sources
|
||||
&[0x806c_0908], // SOP2 TTMP destination
|
||||
@@ -1119,6 +1271,122 @@ fn decode_at_resolves_branch_targets_from_the_stream_offset() {
|
||||
);
|
||||
}
|
||||
|
||||
// llvm-mc -triple=amdgcn -mcpu=gfx1030 -show-encoding
|
||||
const VOP3_INTEGER_ENCODINGS: [(VectorAluVop3Op, u32); 11] = [
|
||||
// v_mul_i32_i24_e64 v255, v0, v127 ; encoding: [0xff,0x00,0x09,0xd5,0x00,0xff,0x02,0x02]
|
||||
(VectorAluVop3Op::MulI32I24, 0xd50900ff),
|
||||
// v_mul_hi_i32_i24_e64 v255, v0, v127 ; encoding: [0xff,0x00,0x0a,0xd5,0x00,0xff,0x02,0x02]
|
||||
(VectorAluVop3Op::MulHiI32I24, 0xd50a00ff),
|
||||
// v_mul_u32_u24_e64 v255, v0, v127 ; encoding: [0xff,0x00,0x0b,0xd5,0x00,0xff,0x02,0x02]
|
||||
(VectorAluVop3Op::MulU32U24, 0xd50b00ff),
|
||||
// v_mul_hi_u32_u24_e64 v255, v0, v127 ; encoding: [0xff,0x00,0x0c,0xd5,0x00,0xff,0x02,0x02]
|
||||
(VectorAluVop3Op::MulHiU32U24, 0xd50c00ff),
|
||||
// v_min_i32_e64 v255, v0, v127 ; encoding: [0xff,0x00,0x11,0xd5,0x00,0xff,0x02,0x02]
|
||||
(VectorAluVop3Op::MinI32, 0xd51100ff),
|
||||
// v_max_i32_e64 v255, v0, v127 ; encoding: [0xff,0x00,0x12,0xd5,0x00,0xff,0x02,0x02]
|
||||
(VectorAluVop3Op::MaxI32, 0xd51200ff),
|
||||
// v_min_u32_e64 v255, v0, v127 ; encoding: [0xff,0x00,0x13,0xd5,0x00,0xff,0x02,0x02]
|
||||
(VectorAluVop3Op::MinU32, 0xd51300ff),
|
||||
// v_max_u32_e64 v255, v0, v127 ; encoding: [0xff,0x00,0x14,0xd5,0x00,0xff,0x02,0x02]
|
||||
(VectorAluVop3Op::MaxU32, 0xd51400ff),
|
||||
// v_xnor_b32_e64 v255, v0, v127 ; encoding: [0xff,0x00,0x1e,0xd5,0x00,0xff,0x02,0x02]
|
||||
(VectorAluVop3Op::XnorB32, 0xd51e00ff),
|
||||
// v_sub_nc_u32_e64 v255, v0, v127 ; encoding: [0xff,0x00,0x26,0xd5,0x00,0xff,0x02,0x02]
|
||||
(VectorAluVop3Op::SubNcU32, 0xd52600ff),
|
||||
// v_subrev_nc_u32_e64 v255, v0, v127 ; encoding: [0xff,0x00,0x27,0xd5,0x00,0xff,0x02,0x02]
|
||||
(VectorAluVop3Op::SubrevNcU32, 0xd52700ff),
|
||||
];
|
||||
const VOP3_INTEGER_SOURCE_WORD: u32 = 0x0202_ff00;
|
||||
|
||||
#[test]
|
||||
fn decodes_registry_vop3_integer_encodings() {
|
||||
for (op, first) in VOP3_INTEGER_ENCODINGS {
|
||||
let bytes = [first.to_le_bytes(), VOP3_INTEGER_SOURCE_WORD.to_le_bytes()].concat();
|
||||
let decoded = decode(Architecture::Gfx1030, &bytes).unwrap();
|
||||
assert_eq!(decoded.len(), 1);
|
||||
assert_eq!(decoded[0].byte_len, 8);
|
||||
assert_eq!(
|
||||
decoded[0].instruction,
|
||||
Instruction::VectorAluVop3 {
|
||||
op,
|
||||
dst: 255,
|
||||
src0: 0,
|
||||
src1: 127,
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decodes_vop3_integer_fixture() {
|
||||
use VectorAluVop3Op::*;
|
||||
|
||||
let code = include_bytes!("../../../fixtures/rdna2/vop3-integer.bin");
|
||||
let decoded = decode(Architecture::Gfx1030, code).unwrap();
|
||||
let expected = [
|
||||
(MulI32I24, 2, 1, 1),
|
||||
(MulHiI32I24, 3, 2, 1),
|
||||
(MulU32U24, 4, 2, 1),
|
||||
(MulHiU32U24, 255, 4, 1),
|
||||
(MinI32, 6, 1, 2),
|
||||
(MaxI32, 7, 1, 4),
|
||||
(MinU32, 8, 3, 1),
|
||||
(MaxU32, 9, 255, 2),
|
||||
(XnorB32, 10, 1, 255),
|
||||
(SubNcU32, 11, 6, 10),
|
||||
(SubrevNcU32, 1, 1, 9),
|
||||
];
|
||||
let actual: Vec<_> = decoded
|
||||
.iter()
|
||||
.filter_map(|decoded| match decoded.instruction {
|
||||
Instruction::VectorAluVop3 {
|
||||
op,
|
||||
dst,
|
||||
src0,
|
||||
src1,
|
||||
} => Some((decoded.offset, decoded.byte_len, op, dst, src0, src1)),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
let expected: Vec<_> = expected
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(index, (op, dst, src0, src1))| (12 + 8 * index, 8, op, dst, src0, src1))
|
||||
.collect();
|
||||
assert_eq!(actual, expected);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_registry_vop3_integer_modifiers_and_other_sources() {
|
||||
for (op, first) in VOP3_INTEGER_ENCODINGS {
|
||||
let second = VOP3_INTEGER_SOURCE_WORD;
|
||||
let reject = |first: u32, second: u32| {
|
||||
let bytes = [first.to_le_bytes(), second.to_le_bytes()].concat();
|
||||
let error = decode(Architecture::Gfx1030, &bytes)
|
||||
.expect_err(&format!("{op:?} accepted {first:#010x} {second:#010x}"));
|
||||
assert_eq!(error.offset, 0);
|
||||
assert!(matches!(
|
||||
error.kind,
|
||||
DecodeErrorKind::UnsupportedForm { mnemonic, .. }
|
||||
if mnemonic == op.assembly_name()
|
||||
));
|
||||
};
|
||||
|
||||
// First word: ABS[10:8], OP_SEL[14:11], CLAMP[15].
|
||||
for bit in 8..=15 {
|
||||
reject(first | (1 << bit), second);
|
||||
}
|
||||
// Second word: OMOD[28:27], NEG[31:29].
|
||||
for bit in 27..=31 {
|
||||
reject(first, second | (1 << bit));
|
||||
}
|
||||
|
||||
reject(first, second & !0x1ff); // SRC0 = s0
|
||||
reject(first, (second & !(0x1ff << 9)) | (128 << 9)); // SRC1 = inline zero
|
||||
reject(first, second | (1 << 18)); // SRC2 = inline one
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn decodes_sopk_immediates_and_rejects_non_sgpr_operands() {
|
||||
use xenora_decoder::ScalarImmediateCompareOp;
|
||||
|
||||
@@ -44,7 +44,7 @@ TOP_KEYS = {
|
||||
# An encoding variant is another encoding of a form already in the registry (for
|
||||
# example the VOP3 `_e64` encoding of a VOP2 form): pure data that names the base
|
||||
# form, the encoding family, its opcode there and the operand rule of that
|
||||
# encoding. It inherits the base form's operation, signedness and effects.
|
||||
# encoding. The rule may redirect the base form's mask to an explicit destination.
|
||||
VARIANT_KEYS = {"of", "family", "opcode", "operands", "spec", "verify"}
|
||||
# The assembler suffix LLVM prints for a variant's encoding family.
|
||||
ASSEMBLY_SUFFIX = {"VOP3": "_e64"}
|
||||
@@ -151,8 +151,9 @@ SCC = {
|
||||
"selected_src0": "SelectedSrc0",
|
||||
}
|
||||
# lane_mask: the Wave32 compare or carry result written to VCC_LO.
|
||||
# sdst_lane_mask: the Wave32 compare result written to explicit VOP3A SDST.
|
||||
# EXEC writes such as v_cmpx have no contract, so exec must stay unchanged.
|
||||
MASK = {"unchanged": "Unchanged", "lane_mask": "LaneMask"}
|
||||
MASK = {"unchanged": "Unchanged", "lane_mask": "LaneMask", "sdst_lane_mask": "SdstLaneMask"}
|
||||
WAVE = {"any": "Any", "wave32": "Wave32"}
|
||||
# The synthetic compute fixture ABI fixes the wave size for these operand-rule
|
||||
# kinds and for the VCC-reading VOP2 rule. Other forms declare "any".
|
||||
@@ -275,7 +276,12 @@ UNSUPPORTED_COMBOS = {
|
||||
# which SOP2 groups under src_vcc and src_special).
|
||||
# VOP3 rules also name source classes and encoding fields they refuse.
|
||||
VOP3_COMBOS = {"src_sgpr", "src_inline", "src_literal", "modifiers", "src2"}
|
||||
ALL_COMBOS = UNSUPPORTED_COMBOS | {"src_vcc_hi", "src_null"} | VOP3_COMBOS
|
||||
ALL_COMBOS = UNSUPPORTED_COMBOS | {"src_vcc_hi", "src_null", "dst_vcc_hi"} | VOP3_COMBOS
|
||||
VOP3_VGPR2_UNSUPPORTED = {
|
||||
"src_sgpr", "src_vcc", "src_exec", "src_m0", "src_ttmp", "src_null", "src_inline",
|
||||
"src_float_inline", "src_special", "src_literal", "modifiers", "src2",
|
||||
}
|
||||
|
||||
VECTOR_UNARY_PRIMITIVES = {
|
||||
("not", "bitwise"): "Not",
|
||||
("brev", "bitwise"): "ReverseBits",
|
||||
@@ -495,16 +501,34 @@ OPERAND_RULES = {
|
||||
},
|
||||
# Two VGPR sources only, with ABS, OP_SEL, CLAMP, OMOD and NEG clear and
|
||||
# SRC2 the assembler's unused inline zero; the decoder rejects the rest.
|
||||
"unsupported": {
|
||||
"src_sgpr", "src_vcc", "src_exec", "src_m0", "src_ttmp", "src_null", "src_inline",
|
||||
"src_float_inline", "src_special", "src_literal", "modifiers", "src2",
|
||||
},
|
||||
"unsupported": VOP3_VGPR2_UNSUPPORTED,
|
||||
"kind": "vector_vop3",
|
||||
# Only encoding variants of forms whose rule has this kind may use it.
|
||||
"variant_of": "vector",
|
||||
# The generated enum of this rule's variants; base() maps to "enum".
|
||||
"variant_enum": "VectorAluVop3Op",
|
||||
},
|
||||
"vop3_cmp_vgpr2": {
|
||||
"rust": "Vop3CmpVgpr2",
|
||||
"enum": "VectorCompareOp",
|
||||
"shape": {
|
||||
"family": "VOP3",
|
||||
"dst": {"field": "VDST", "class": "sgpr", "min": 0, "max": 106},
|
||||
"src": [
|
||||
{"field": "SRC0", "class": "vgpr"},
|
||||
{"field": "SRC1", "class": "vgpr"},
|
||||
],
|
||||
"max_literals": 0,
|
||||
"variant_only": True,
|
||||
},
|
||||
"unsupported": VOP3_VGPR2_UNSUPPORTED | {
|
||||
"dst_vcc_hi", "dst_exec", "dst_ttmp", "dst_m0", "dst_null",
|
||||
},
|
||||
"kind": "vector_compare_vop3",
|
||||
"variant_of": "vector_compare",
|
||||
"variant_enum": "VectorCompareVop3Op",
|
||||
"vcc_transition": ("lane_mask", "sdst_lane_mask"),
|
||||
},
|
||||
"vop2_vgpr": {
|
||||
"rust": "Vop2Vgpr",
|
||||
"enum": "VectorAluOp",
|
||||
@@ -744,18 +768,18 @@ def _check_xml(form, rule, snapshot, errors):
|
||||
):
|
||||
mask_inputs += 1
|
||||
elif field:
|
||||
operands[field] = (data_format, size, is_input, is_output)
|
||||
operands[field] = (data_format, kind, size, is_input, is_output)
|
||||
elif kind == "OPR_VCC":
|
||||
vcc_operands.append((is_input, is_output))
|
||||
vcc_operands.append((data_format, size, is_input, is_output))
|
||||
else:
|
||||
implicit.add(kind)
|
||||
if form["carry_in"] == "vcc":
|
||||
if vcc_operands.count((True, False)) != 1:
|
||||
if vcc_operands.count(("FMT_NUM_M64", 64, True, False)) != 1:
|
||||
errors.append(f"{label}: carry_in vcc requires one implicit XML VCC input")
|
||||
if (True, False) in vcc_operands:
|
||||
vcc_operands.remove((True, False))
|
||||
if ("FMT_NUM_M64", 64, True, False) in vcc_operands:
|
||||
vcc_operands.remove(("FMT_NUM_M64", 64, True, False))
|
||||
if form["vcc"] == "lane_mask":
|
||||
if vcc_operands != [(False, True)]:
|
||||
if vcc_operands != [("FMT_NUM_M64", 64, False, True)]:
|
||||
errors.append(f"{label}: vcc lane_mask but the XML has no implicit VCC output")
|
||||
elif vcc_operands:
|
||||
implicit.add("OPR_VCC")
|
||||
@@ -780,7 +804,7 @@ def _check_xml(form, rule, snapshot, errors):
|
||||
if field not in operands:
|
||||
errors.append(f"{label}: XML has no operand {field}")
|
||||
continue
|
||||
data_format, size, is_input, is_output = operands[field]
|
||||
data_format, kind, size, is_input, is_output = operands[field]
|
||||
if field == "SIMM16" and _rule_kind(form) == "control":
|
||||
expected_kind, expected_format = (
|
||||
("OPR_LABEL", "FMT_NUM_I16") if form["operands"] == "sopp_branch"
|
||||
@@ -800,6 +824,11 @@ def _check_xml(form, rule, snapshot, errors):
|
||||
continue
|
||||
bits = form.get(SOURCE_BITS_KEY) if is_source else None
|
||||
expected = bits if type(bits) is int else form["width"]
|
||||
if not is_source and form["vcc"] == "sdst_lane_mask":
|
||||
# The XML describes the Wave64 pair. The Wave32 ABI writes one SGPR.
|
||||
expected = 64
|
||||
if (kind, data_format) != ("OPR_SREG", "FMT_NUM_M64"):
|
||||
errors.append(f"{label}: {field} is not a scalar mask destination in the XML")
|
||||
if size != expected:
|
||||
errors.append(f"{label}: {field} is {size} bits in the XML, declared {expected}")
|
||||
# The XML marks both swap operands as outputs. Guide 12.8 also
|
||||
@@ -896,10 +925,11 @@ def validate(registry, snapshot):
|
||||
if form["wave"] in WAVE and form["wave"] != wave:
|
||||
errors.append(f"{label}: wave {form['wave']} is not enforced for this rule (requires {wave})")
|
||||
lane_mask = _rule_kind(form) == "vector_compare" or (reads_vcc and form["operation"] != "cselect")
|
||||
if form["vcc"] in MASK and (form["vcc"] == "lane_mask") != lane_mask:
|
||||
vcc = "lane_mask" if lane_mask else "unchanged"
|
||||
if form["vcc"] in MASK and form["vcc"] != vcc:
|
||||
errors.append(
|
||||
f"{label}: vcc {form['vcc']} contradicts rule {form['operands']} "
|
||||
f"(requires {'lane_mask' if lane_mask else 'unchanged'})"
|
||||
f"(requires {vcc})"
|
||||
)
|
||||
if form["exec"] != "unchanged":
|
||||
errors.append(f"{label}: exec {form['exec']} has no contract (requires unchanged)")
|
||||
@@ -1070,9 +1100,10 @@ def variant_row(registry, variant, base=None):
|
||||
"""The base form re-encoded: its declaration with the variant's identity."""
|
||||
if base is None:
|
||||
base = next(form for form in registry["form"] if form.get("name") == variant["of"])
|
||||
_, vcc = OPERAND_RULES[variant["operands"]].get("vcc_transition", ("unchanged", "unchanged"))
|
||||
return dict(
|
||||
base, family=variant["family"], opcode=variant["opcode"], operands=variant["operands"],
|
||||
spec=variant["spec"], verify=variant["verify"],
|
||||
vcc=vcc, spec=variant["spec"], verify=variant["verify"],
|
||||
)
|
||||
|
||||
|
||||
@@ -1142,24 +1173,32 @@ def _check_variants(registry, rules, documents, snapshot, seen, errors):
|
||||
if FORM_KEYS - set(base):
|
||||
errors.append(f"{label}: not checked, its form {variant['of']} is incomplete")
|
||||
continue
|
||||
base_vcc, _ = implemented.get("vcc_transition", ("unchanged", "unchanged"))
|
||||
if base["vcc"] != base_vcc:
|
||||
errors.append(
|
||||
f"{label}: operand rule {variant['operands']} requires a base "
|
||||
f"destination contract of {base_vcc}, got {base['vcc']}"
|
||||
)
|
||||
# The same base row as the completeness check above (with duplicate
|
||||
# declarations, the dict keeps the last one).
|
||||
_check_xml(variant_row(registry, variant, base), rule, snapshot, errors)
|
||||
# Every explicit operand, destination included, has the base encoding's
|
||||
# data format, in the same order (VSRC1 of VOP2 is SRC1 of VOP3).
|
||||
# Explicit destinations and sources keep the base encoding's data format
|
||||
# in the same role. The implicit-to-explicit mask transition is checked
|
||||
# above and in _check_xml for each encoding.
|
||||
base_xml = snapshot["variants"].get((base["name"], _family_encoding(base["family"])))
|
||||
own_xml = snapshot["variants"].get((variant["of"], _family_encoding(variant["family"])))
|
||||
base_rule = rules.get(base.get("operands"))
|
||||
if base_xml and own_xml and _well_formed(base_rule) and _well_formed(rule):
|
||||
# Operands correspond by role, in rule order: the destination, then
|
||||
# each source (VSRC1 of VOP2 is SRC1 of VOP3).
|
||||
def roles(rule, record):
|
||||
def roles(rule, record, explicit_dst):
|
||||
by_field = {row[0]: row[1] for row in record["operands"] if row[0]}
|
||||
fields = ([rule["dst"]["field"]] if "dst" in rule else [])
|
||||
fields = [rule["dst"]["field"]] if explicit_dst else []
|
||||
fields += [src["field"] for src in rule.get("src", [])]
|
||||
return [(field, by_field.get(field)) for field in fields]
|
||||
|
||||
pairs = list(zip(roles(base_rule, base_xml), roles(rule, own_xml)))
|
||||
explicit_dst = "dst" in base_rule and "dst" in rule
|
||||
pairs = zip(roles(base_rule, base_xml, explicit_dst), roles(rule, own_xml, explicit_dst))
|
||||
for (base_field, base_format), (field, data_format) in pairs:
|
||||
if base_format != data_format:
|
||||
errors.append(
|
||||
|
||||
@@ -49,6 +49,7 @@ file = "amdgpu_isa_rdna2.xml"
|
||||
# width operand and result width in bits
|
||||
# scc unchanged | carry_out | borrow | signed_overflow | nonzero | relation | selected_src0
|
||||
# vcc, exec unchanged (stated, not implied) | lane_mask (Wave32 VOPC compare or VOP2 carry output)
|
||||
# VOP3A compare variant rows derive sdst_lane_mask from their operand rule.
|
||||
# wave any | wave32 (wave32 for VOPC compares, VOP1 integer forms and VCC-reading VOP2 forms)
|
||||
# operands a key of [operand_rules]
|
||||
# spec references; at least one guide section with a page
|
||||
|
||||
@@ -1,6 +1,202 @@
|
||||
# VOP3 encodings of the gfx1030 semantic registry; included by ../rdna2.toml.
|
||||
# Data only; see the root file for the field meanings.
|
||||
|
||||
# ---- Wave32 VOPC compares in VOP3A (#215) ----
|
||||
|
||||
# VDST encodes the scalar lane-mask destination, including vcc_lo (selector 106).
|
||||
# The two sources are VGPRs. Modifiers are clear and SRC2 is inline zero.
|
||||
[operand_rules.vop3_cmp_vgpr2]
|
||||
family = "VOP3"
|
||||
dst = { field = "VDST", class = "sgpr", min = 0, max = 106 }
|
||||
src = [
|
||||
{ field = "SRC0", class = "vgpr" },
|
||||
{ field = "SRC1", class = "vgpr" },
|
||||
]
|
||||
max_literals = 0
|
||||
variant_only = true
|
||||
unsupported = [
|
||||
"dst_vcc_hi", "dst_exec", "dst_ttmp", "dst_m0", "dst_null",
|
||||
"src_sgpr", "src_vcc", "src_exec", "src_m0", "src_ttmp", "src_null", "src_inline",
|
||||
"src_float_inline", "src_special", "src_literal", "modifiers", "src2",
|
||||
]
|
||||
|
||||
# Opcodes come from the pinned XML's default ENC_VOP3 records.
|
||||
[[encoding_variant]]
|
||||
of = "V_CMP_LT_I32"
|
||||
family = "VOP3"
|
||||
opcode = 129
|
||||
operands = "vop3_cmp_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "3.9", page = 19 },
|
||||
{ document = "guide", section = "13.3.4", page = 257 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_CMP_EQ_I32"
|
||||
family = "VOP3"
|
||||
opcode = 130
|
||||
operands = "vop3_cmp_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "3.9", page = 19 },
|
||||
{ document = "guide", section = "13.3.4", page = 257 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_CMP_LE_I32"
|
||||
family = "VOP3"
|
||||
opcode = 131
|
||||
operands = "vop3_cmp_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "3.9", page = 19 },
|
||||
{ document = "guide", section = "13.3.4", page = 257 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_CMP_GT_I32"
|
||||
family = "VOP3"
|
||||
opcode = 132
|
||||
operands = "vop3_cmp_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "3.9", page = 19 },
|
||||
{ document = "guide", section = "13.3.4", page = 257 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_CMP_NE_I32"
|
||||
family = "VOP3"
|
||||
opcode = 133
|
||||
operands = "vop3_cmp_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "3.9", page = 19 },
|
||||
{ document = "guide", section = "13.3.4", page = 257 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_CMP_GE_I32"
|
||||
family = "VOP3"
|
||||
opcode = 134
|
||||
operands = "vop3_cmp_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "3.9", page = 19 },
|
||||
{ document = "guide", section = "13.3.4", page = 257 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_CMP_LT_U32"
|
||||
family = "VOP3"
|
||||
opcode = 193
|
||||
operands = "vop3_cmp_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "3.9", page = 19 },
|
||||
{ document = "guide", section = "13.3.4", page = 257 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_CMP_EQ_U32"
|
||||
family = "VOP3"
|
||||
opcode = 194
|
||||
operands = "vop3_cmp_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "3.9", page = 19 },
|
||||
{ document = "guide", section = "13.3.4", page = 257 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_CMP_LE_U32"
|
||||
family = "VOP3"
|
||||
opcode = 195
|
||||
operands = "vop3_cmp_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "3.9", page = 19 },
|
||||
{ document = "guide", section = "13.3.4", page = 257 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_CMP_GT_U32"
|
||||
family = "VOP3"
|
||||
opcode = 196
|
||||
operands = "vop3_cmp_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "3.9", page = 19 },
|
||||
{ document = "guide", section = "13.3.4", page = 257 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_CMP_NE_U32"
|
||||
family = "VOP3"
|
||||
opcode = 197
|
||||
operands = "vop3_cmp_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "3.9", page = 19 },
|
||||
{ document = "guide", section = "13.3.4", page = 257 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_CMP_GE_U32"
|
||||
family = "VOP3"
|
||||
opcode = 198
|
||||
operands = "vop3_cmp_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "3.9", page = 19 },
|
||||
{ document = "guide", section = "13.3.4", page = 257 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_CMP_F_I32"
|
||||
family = "VOP3"
|
||||
opcode = 128
|
||||
operands = "vop3_cmp_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "3.9", page = 19 },
|
||||
{ document = "guide", section = "13.3.4", page = 257 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_CMP_T_I32"
|
||||
family = "VOP3"
|
||||
opcode = 135
|
||||
operands = "vop3_cmp_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "3.9", page = 19 },
|
||||
{ document = "guide", section = "13.3.4", page = 257 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_CMP_F_U32"
|
||||
family = "VOP3"
|
||||
opcode = 192
|
||||
operands = "vop3_cmp_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "3.9", page = 19 },
|
||||
{ document = "guide", section = "13.3.4", page = 257 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_CMP_T_U32"
|
||||
family = "VOP3"
|
||||
opcode = 199
|
||||
operands = "vop3_cmp_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "3.9", page = 19 },
|
||||
{ document = "guide", section = "13.3.4", page = 257 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
# ---- VOP3 encoding variants of registry forms (#215) ----
|
||||
# An [[encoding_variant]] re-encodes a form declared in another family file: it
|
||||
# names the form (`of`), this family, the XML opcode here and the operand rule
|
||||
@@ -37,3 +233,130 @@ spec = [
|
||||
{ document = "guide", section = "12.7", page = 134 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
# ABS and NEG apply to floating-point inputs (guide 6.2.1) and OMOD
|
||||
# applies to floating-point results (6.2.2). These integer forms use neither.
|
||||
# OP_SEL selects 16-bit halves (13.3.4). CLAMP saturates integer results
|
||||
# (6.5), which these registry forms do not declare. SGPR, inline and literal
|
||||
# sources remain outside this operand rule.
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_MUL_I32_I24"
|
||||
family = "VOP3"
|
||||
opcode = 265
|
||||
operands = "vop3_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "12.12", page = 167 },
|
||||
{ document = "guide", section = "12.7", page = 131 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_MUL_HI_I32_I24"
|
||||
family = "VOP3"
|
||||
opcode = 266
|
||||
operands = "vop3_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "12.12", page = 167 },
|
||||
{ document = "guide", section = "12.7", page = 132 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_MUL_U32_U24"
|
||||
family = "VOP3"
|
||||
opcode = 267
|
||||
operands = "vop3_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "12.12", page = 167 },
|
||||
{ document = "guide", section = "12.7", page = 132 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_MUL_HI_U32_U24"
|
||||
family = "VOP3"
|
||||
opcode = 268
|
||||
operands = "vop3_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "12.12", page = 167 },
|
||||
{ document = "guide", section = "12.7", page = 132 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_MIN_I32"
|
||||
family = "VOP3"
|
||||
opcode = 273
|
||||
operands = "vop3_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "12.12", page = 167 },
|
||||
{ document = "guide", section = "12.7", page = 133 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_MAX_I32"
|
||||
family = "VOP3"
|
||||
opcode = 274
|
||||
operands = "vop3_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "12.12", page = 167 },
|
||||
{ document = "guide", section = "12.7", page = 133 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_MIN_U32"
|
||||
family = "VOP3"
|
||||
opcode = 275
|
||||
operands = "vop3_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "12.12", page = 167 },
|
||||
{ document = "guide", section = "12.7", page = 133 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_MAX_U32"
|
||||
family = "VOP3"
|
||||
opcode = 276
|
||||
operands = "vop3_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "12.12", page = 167 },
|
||||
{ document = "guide", section = "12.7", page = 133 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_XNOR_B32"
|
||||
family = "VOP3"
|
||||
opcode = 286
|
||||
operands = "vop3_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "12.12", page = 167 },
|
||||
{ document = "guide", section = "12.7", page = 134 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_SUB_NC_U32"
|
||||
family = "VOP3"
|
||||
opcode = 294
|
||||
operands = "vop3_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "12.12", page = 167 },
|
||||
{ document = "guide", section = "12.7", page = 134 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
|
||||
[[encoding_variant]]
|
||||
of = "V_SUBREV_NC_U32"
|
||||
family = "VOP3"
|
||||
opcode = 295
|
||||
operands = "vop3_vgpr2"
|
||||
spec = [
|
||||
{ document = "guide", section = "12.12", page = 167 },
|
||||
{ document = "guide", section = "12.7", page = 134 },
|
||||
]
|
||||
verify = ["reference", "independent", "metal", "llvm_encoding"]
|
||||
+14
-1
@@ -20,7 +20,8 @@ pub use rdna2::{
|
||||
};
|
||||
pub use semantics_gen::{
|
||||
ScalarAluOp, ScalarCompareOp, ScalarImmediateCompareOp, ScalarImmediateOp, ScalarUnaryOp,
|
||||
SoppControlOp, VectorAluOp, VectorAluVop3Op, VectorCompareOp, VectorSwapOp, VectorUnaryOp,
|
||||
SoppControlOp, VectorAluOp, VectorAluVop3Op, VectorCompareOp, VectorCompareVop3Op,
|
||||
VectorSwapOp, VectorUnaryOp,
|
||||
};
|
||||
|
||||
impl VectorAluOp {
|
||||
@@ -227,6 +228,14 @@ pub enum Instruction {
|
||||
src0: VectorSource,
|
||||
src1: u8,
|
||||
},
|
||||
/// VOP3A 32-bit integer compare writing a Wave32 mask to s0-s105 or `vcc_lo`.
|
||||
/// Both sources are VGPR indices.
|
||||
VectorCompareVop3 {
|
||||
op: VectorCompareVop3Op,
|
||||
sdst: u8,
|
||||
src0: u8,
|
||||
src1: u8,
|
||||
},
|
||||
/// VOP2 32-bit per-lane integer operation from the semantic registry.
|
||||
/// `src0` is a VGPR, `s0-s105`, `vcc_lo`, an inline integer or a literal;
|
||||
/// `src1` is a VGPR. Inactive lanes keep `dst`.
|
||||
@@ -309,6 +318,7 @@ impl Instruction {
|
||||
Self::ScalarImmediate { op, .. } => op.mnemonic(),
|
||||
Self::ScalarImmediateCompare { op, .. } => op.mnemonic(),
|
||||
Self::VectorCompare { op, .. } => op.assembly_name(),
|
||||
Self::VectorCompareVop3 { op, .. } => op.assembly_name(),
|
||||
Self::VectorAlu { op, .. } => op.assembly_name(),
|
||||
Self::BranchSccZero { .. } => "s_cbranch_scc0",
|
||||
Self::BranchExecZero { .. } => "s_cbranch_execz",
|
||||
@@ -393,6 +403,9 @@ impl fmt::Display for Instruction {
|
||||
Self::VectorCompare { src0, src1, .. } => {
|
||||
write!(formatter, " vcc_lo, {src0}, v{src1}")
|
||||
}
|
||||
Self::VectorCompareVop3 {
|
||||
sdst, src0, src1, ..
|
||||
} => write!(formatter, " {}, v{src0}, v{src1}", ScalarDestination(sdst)),
|
||||
Self::VectorAlu {
|
||||
op,
|
||||
dst,
|
||||
|
||||
@@ -47,7 +47,7 @@ pub enum Operation {
|
||||
LogicalShiftRight,
|
||||
/// Shift S0 right by the masked count in S1, filling with its sign bit.
|
||||
ArithmeticShiftRight,
|
||||
/// Compare S0 with S1 under the form's relation; writes only SCC.
|
||||
/// Compare S0 with S1 under the form's relation, producing SCC or a lane mask.
|
||||
Compare,
|
||||
/// Bitwise complement of S0.
|
||||
Not,
|
||||
@@ -227,7 +227,7 @@ pub enum SccEffect {
|
||||
SelectedSrc0,
|
||||
}
|
||||
|
||||
/// What a form writes to VCC or EXEC.
|
||||
/// Where a form writes its lane mask, if any.
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum MaskEffect {
|
||||
/// Not written.
|
||||
@@ -236,6 +236,8 @@ pub enum MaskEffect {
|
||||
/// exists) & test(lane n), fully written; `VCC_HI` has no known value after
|
||||
/// it (docs/shaders/vector-compare.md section 3).
|
||||
LaneMask,
|
||||
/// Wave32 VOP3A compare mask written to SDST, which may be `vcc_lo`.
|
||||
SdstLaneMask,
|
||||
}
|
||||
|
||||
/// Wave-size restriction.
|
||||
@@ -288,6 +290,9 @@ pub enum OperandRule {
|
||||
/// VGPRs, no input or output modifiers, SRC2 unused. Everything else is
|
||||
/// rejected as unsupported.
|
||||
Vop3Vgpr2,
|
||||
/// VOP3A compare: VDST encodes s0-s105 or `vcc_lo`; SRC0 and SRC1 are
|
||||
/// VGPRs, SRC2 is unused and all modifiers are clear.
|
||||
Vop3CmpVgpr2,
|
||||
/// VOP2 vector: VDST is v0-v255; SRC0 is a VGPR, s0-s105, `vcc_lo`, an inline
|
||||
/// integer -16..64 or a literal word; VSRC1 is a VGPR. Everything else is
|
||||
/// rejected as unsupported.
|
||||
@@ -365,7 +370,7 @@ pub struct FormSemantics {
|
||||
pub relation: Option<CompareRelation>,
|
||||
/// SCC write.
|
||||
pub scc: SccEffect,
|
||||
/// VCC write.
|
||||
/// Implicit VCC write or explicit scalar destination for a compare mask.
|
||||
pub vcc: MaskEffect,
|
||||
/// EXEC write.
|
||||
pub exec: MaskEffect,
|
||||
|
||||
+834
-10
@@ -3421,17 +3421,62 @@ impl VectorCompareOp {
|
||||
}
|
||||
}
|
||||
|
||||
/// VOP3 encodings of registry forms (operand rule `vop3_vgpr2`).
|
||||
/// VOP3 encodings of registry forms (operand rule `vop3_cmp_vgpr2`).
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum VectorAluVop3Op {
|
||||
/// `v_add_nc_u32_e64` (VOP3 opcode 293).
|
||||
AddNcU32,
|
||||
pub enum VectorCompareVop3Op {
|
||||
/// `v_cmp_lt_i32_e64` (VOP3 opcode 129).
|
||||
CmpLtI32,
|
||||
/// `v_cmp_eq_i32_e64` (VOP3 opcode 130).
|
||||
CmpEqI32,
|
||||
/// `v_cmp_le_i32_e64` (VOP3 opcode 131).
|
||||
CmpLeI32,
|
||||
/// `v_cmp_gt_i32_e64` (VOP3 opcode 132).
|
||||
CmpGtI32,
|
||||
/// `v_cmp_ne_i32_e64` (VOP3 opcode 133).
|
||||
CmpNeI32,
|
||||
/// `v_cmp_ge_i32_e64` (VOP3 opcode 134).
|
||||
CmpGeI32,
|
||||
/// `v_cmp_lt_u32_e64` (VOP3 opcode 193).
|
||||
CmpLtU32,
|
||||
/// `v_cmp_eq_u32_e64` (VOP3 opcode 194).
|
||||
CmpEqU32,
|
||||
/// `v_cmp_le_u32_e64` (VOP3 opcode 195).
|
||||
CmpLeU32,
|
||||
/// `v_cmp_gt_u32_e64` (VOP3 opcode 196).
|
||||
CmpGtU32,
|
||||
/// `v_cmp_ne_u32_e64` (VOP3 opcode 197).
|
||||
CmpNeU32,
|
||||
/// `v_cmp_ge_u32_e64` (VOP3 opcode 198).
|
||||
CmpGeU32,
|
||||
/// `v_cmp_f_i32_e64` (VOP3 opcode 128).
|
||||
CmpFI32,
|
||||
/// `v_cmp_t_i32_e64` (VOP3 opcode 135).
|
||||
CmpTI32,
|
||||
/// `v_cmp_f_u32_e64` (VOP3 opcode 192).
|
||||
CmpFU32,
|
||||
/// `v_cmp_t_u32_e64` (VOP3 opcode 199).
|
||||
CmpTU32,
|
||||
}
|
||||
|
||||
impl VectorAluVop3Op {
|
||||
impl VectorCompareVop3Op {
|
||||
/// Every variant, in registry order.
|
||||
pub const ALL: [Self; 1] = [
|
||||
Self::AddNcU32,
|
||||
pub const ALL: [Self; 16] = [
|
||||
Self::CmpLtI32,
|
||||
Self::CmpEqI32,
|
||||
Self::CmpLeI32,
|
||||
Self::CmpGtI32,
|
||||
Self::CmpNeI32,
|
||||
Self::CmpGeI32,
|
||||
Self::CmpLtU32,
|
||||
Self::CmpEqU32,
|
||||
Self::CmpLeU32,
|
||||
Self::CmpGtU32,
|
||||
Self::CmpNeU32,
|
||||
Self::CmpGeU32,
|
||||
Self::CmpFI32,
|
||||
Self::CmpTI32,
|
||||
Self::CmpFU32,
|
||||
Self::CmpTU32,
|
||||
];
|
||||
|
||||
/// Selects the variant from the first word of its VOP3 encoding: the
|
||||
@@ -3442,7 +3487,159 @@ impl VectorAluVop3Op {
|
||||
return None;
|
||||
}
|
||||
match (word >> 16) & 0x3ff {
|
||||
128 => Some(Self::CmpFI32),
|
||||
129 => Some(Self::CmpLtI32),
|
||||
130 => Some(Self::CmpEqI32),
|
||||
131 => Some(Self::CmpLeI32),
|
||||
132 => Some(Self::CmpGtI32),
|
||||
133 => Some(Self::CmpNeI32),
|
||||
134 => Some(Self::CmpGeI32),
|
||||
135 => Some(Self::CmpTI32),
|
||||
192 => Some(Self::CmpFU32),
|
||||
193 => Some(Self::CmpLtU32),
|
||||
194 => Some(Self::CmpEqU32),
|
||||
195 => Some(Self::CmpLeU32),
|
||||
196 => Some(Self::CmpGtU32),
|
||||
197 => Some(Self::CmpNeU32),
|
||||
198 => Some(Self::CmpGeU32),
|
||||
199 => Some(Self::CmpTU32),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The form this encodes, whose declaration it inherits.
|
||||
pub const fn base(self) -> VectorCompareOp {
|
||||
match self {
|
||||
Self::CmpLtI32 => VectorCompareOp::CmpLtI32,
|
||||
Self::CmpEqI32 => VectorCompareOp::CmpEqI32,
|
||||
Self::CmpLeI32 => VectorCompareOp::CmpLeI32,
|
||||
Self::CmpGtI32 => VectorCompareOp::CmpGtI32,
|
||||
Self::CmpNeI32 => VectorCompareOp::CmpNeI32,
|
||||
Self::CmpGeI32 => VectorCompareOp::CmpGeI32,
|
||||
Self::CmpLtU32 => VectorCompareOp::CmpLtU32,
|
||||
Self::CmpEqU32 => VectorCompareOp::CmpEqU32,
|
||||
Self::CmpLeU32 => VectorCompareOp::CmpLeU32,
|
||||
Self::CmpGtU32 => VectorCompareOp::CmpGtU32,
|
||||
Self::CmpNeU32 => VectorCompareOp::CmpNeU32,
|
||||
Self::CmpGeU32 => VectorCompareOp::CmpGeU32,
|
||||
Self::CmpFI32 => VectorCompareOp::CmpFI32,
|
||||
Self::CmpTI32 => VectorCompareOp::CmpTI32,
|
||||
Self::CmpFU32 => VectorCompareOp::CmpFU32,
|
||||
Self::CmpTU32 => VectorCompareOp::CmpTU32,
|
||||
}
|
||||
}
|
||||
|
||||
/// Assembler name of the VOP3 encoding, as LLVM prints it.
|
||||
pub const fn assembly_name(self) -> &'static str {
|
||||
match self {
|
||||
Self::CmpLtI32 => "v_cmp_lt_i32_e64",
|
||||
Self::CmpEqI32 => "v_cmp_eq_i32_e64",
|
||||
Self::CmpLeI32 => "v_cmp_le_i32_e64",
|
||||
Self::CmpGtI32 => "v_cmp_gt_i32_e64",
|
||||
Self::CmpNeI32 => "v_cmp_ne_i32_e64",
|
||||
Self::CmpGeI32 => "v_cmp_ge_i32_e64",
|
||||
Self::CmpLtU32 => "v_cmp_lt_u32_e64",
|
||||
Self::CmpEqU32 => "v_cmp_eq_u32_e64",
|
||||
Self::CmpLeU32 => "v_cmp_le_u32_e64",
|
||||
Self::CmpGtU32 => "v_cmp_gt_u32_e64",
|
||||
Self::CmpNeU32 => "v_cmp_ne_u32_e64",
|
||||
Self::CmpGeU32 => "v_cmp_ge_u32_e64",
|
||||
Self::CmpFI32 => "v_cmp_f_i32_e64",
|
||||
Self::CmpTI32 => "v_cmp_t_i32_e64",
|
||||
Self::CmpFU32 => "v_cmp_f_u32_e64",
|
||||
Self::CmpTU32 => "v_cmp_t_u32_e64",
|
||||
}
|
||||
}
|
||||
|
||||
/// The validated registry row of this encoding.
|
||||
pub fn semantics(self) -> &'static FormSemantics {
|
||||
&FORMS[match self {
|
||||
Self::CmpLtI32 => 151,
|
||||
Self::CmpEqI32 => 152,
|
||||
Self::CmpLeI32 => 153,
|
||||
Self::CmpGtI32 => 154,
|
||||
Self::CmpNeI32 => 155,
|
||||
Self::CmpGeI32 => 156,
|
||||
Self::CmpLtU32 => 157,
|
||||
Self::CmpEqU32 => 158,
|
||||
Self::CmpLeU32 => 159,
|
||||
Self::CmpGtU32 => 160,
|
||||
Self::CmpNeU32 => 161,
|
||||
Self::CmpGeU32 => 162,
|
||||
Self::CmpFI32 => 163,
|
||||
Self::CmpTI32 => 164,
|
||||
Self::CmpFU32 => 165,
|
||||
Self::CmpTU32 => 166,
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
/// VOP3 encodings of registry forms (operand rule `vop3_vgpr2`).
|
||||
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
||||
pub enum VectorAluVop3Op {
|
||||
/// `v_add_nc_u32_e64` (VOP3 opcode 293).
|
||||
AddNcU32,
|
||||
/// `v_mul_i32_i24_e64` (VOP3 opcode 265).
|
||||
MulI32I24,
|
||||
/// `v_mul_hi_i32_i24_e64` (VOP3 opcode 266).
|
||||
MulHiI32I24,
|
||||
/// `v_mul_u32_u24_e64` (VOP3 opcode 267).
|
||||
MulU32U24,
|
||||
/// `v_mul_hi_u32_u24_e64` (VOP3 opcode 268).
|
||||
MulHiU32U24,
|
||||
/// `v_min_i32_e64` (VOP3 opcode 273).
|
||||
MinI32,
|
||||
/// `v_max_i32_e64` (VOP3 opcode 274).
|
||||
MaxI32,
|
||||
/// `v_min_u32_e64` (VOP3 opcode 275).
|
||||
MinU32,
|
||||
/// `v_max_u32_e64` (VOP3 opcode 276).
|
||||
MaxU32,
|
||||
/// `v_xnor_b32_e64` (VOP3 opcode 286).
|
||||
XnorB32,
|
||||
/// `v_sub_nc_u32_e64` (VOP3 opcode 294).
|
||||
SubNcU32,
|
||||
/// `v_subrev_nc_u32_e64` (VOP3 opcode 295).
|
||||
SubrevNcU32,
|
||||
}
|
||||
|
||||
impl VectorAluVop3Op {
|
||||
/// Every variant, in registry order.
|
||||
pub const ALL: [Self; 12] = [
|
||||
Self::AddNcU32,
|
||||
Self::MulI32I24,
|
||||
Self::MulHiI32I24,
|
||||
Self::MulU32U24,
|
||||
Self::MulHiU32U24,
|
||||
Self::MinI32,
|
||||
Self::MaxI32,
|
||||
Self::MinU32,
|
||||
Self::MaxU32,
|
||||
Self::XnorB32,
|
||||
Self::SubNcU32,
|
||||
Self::SubrevNcU32,
|
||||
];
|
||||
|
||||
/// Selects the variant from the first word of its VOP3 encoding: the
|
||||
/// encoding bits (mask 0xfc00_0000) and then the OP field (bits
|
||||
/// 16-25). `None` for undeclared opcodes.
|
||||
pub const fn from_word(word: u32) -> Option<Self> {
|
||||
if word & 0xfc00_0000 != 0xd400_0000 {
|
||||
return None;
|
||||
}
|
||||
match (word >> 16) & 0x3ff {
|
||||
265 => Some(Self::MulI32I24),
|
||||
266 => Some(Self::MulHiI32I24),
|
||||
267 => Some(Self::MulU32U24),
|
||||
268 => Some(Self::MulHiU32U24),
|
||||
273 => Some(Self::MinI32),
|
||||
274 => Some(Self::MaxI32),
|
||||
275 => Some(Self::MinU32),
|
||||
276 => Some(Self::MaxU32),
|
||||
286 => Some(Self::XnorB32),
|
||||
293 => Some(Self::AddNcU32),
|
||||
294 => Some(Self::SubNcU32),
|
||||
295 => Some(Self::SubrevNcU32),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -3451,6 +3648,17 @@ impl VectorAluVop3Op {
|
||||
pub const fn base(self) -> VectorAluOp {
|
||||
match self {
|
||||
Self::AddNcU32 => VectorAluOp::AddNcU32,
|
||||
Self::MulI32I24 => VectorAluOp::MulI32I24,
|
||||
Self::MulHiI32I24 => VectorAluOp::MulHiI32I24,
|
||||
Self::MulU32U24 => VectorAluOp::MulU32U24,
|
||||
Self::MulHiU32U24 => VectorAluOp::MulHiU32U24,
|
||||
Self::MinI32 => VectorAluOp::MinI32,
|
||||
Self::MaxI32 => VectorAluOp::MaxI32,
|
||||
Self::MinU32 => VectorAluOp::MinU32,
|
||||
Self::MaxU32 => VectorAluOp::MaxU32,
|
||||
Self::XnorB32 => VectorAluOp::XnorB32,
|
||||
Self::SubNcU32 => VectorAluOp::SubNcU32,
|
||||
Self::SubrevNcU32 => VectorAluOp::SubrevNcU32,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3458,19 +3666,41 @@ impl VectorAluVop3Op {
|
||||
pub const fn assembly_name(self) -> &'static str {
|
||||
match self {
|
||||
Self::AddNcU32 => "v_add_nc_u32_e64",
|
||||
Self::MulI32I24 => "v_mul_i32_i24_e64",
|
||||
Self::MulHiI32I24 => "v_mul_hi_i32_i24_e64",
|
||||
Self::MulU32U24 => "v_mul_u32_u24_e64",
|
||||
Self::MulHiU32U24 => "v_mul_hi_u32_u24_e64",
|
||||
Self::MinI32 => "v_min_i32_e64",
|
||||
Self::MaxI32 => "v_max_i32_e64",
|
||||
Self::MinU32 => "v_min_u32_e64",
|
||||
Self::MaxU32 => "v_max_u32_e64",
|
||||
Self::XnorB32 => "v_xnor_b32_e64",
|
||||
Self::SubNcU32 => "v_sub_nc_u32_e64",
|
||||
Self::SubrevNcU32 => "v_subrev_nc_u32_e64",
|
||||
}
|
||||
}
|
||||
|
||||
/// The validated registry row of this encoding.
|
||||
pub fn semantics(self) -> &'static FormSemantics {
|
||||
&FORMS[match self {
|
||||
Self::AddNcU32 => 151,
|
||||
Self::AddNcU32 => 167,
|
||||
Self::MulI32I24 => 168,
|
||||
Self::MulHiI32I24 => 169,
|
||||
Self::MulU32U24 => 170,
|
||||
Self::MulHiU32U24 => 171,
|
||||
Self::MinI32 => 172,
|
||||
Self::MaxI32 => 173,
|
||||
Self::MinU32 => 174,
|
||||
Self::MaxU32 => 175,
|
||||
Self::XnorB32 => 176,
|
||||
Self::SubNcU32 => 177,
|
||||
Self::SubrevNcU32 => 178,
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
||||
/// Identity of every registry form and encoding variant, in registry order.
|
||||
pub const FORM_IDS: [(&str, EncodingFamily); 152] = [
|
||||
pub const FORM_IDS: [(&str, EncodingFamily); 179] = [
|
||||
("S_ADD_U32", EncodingFamily::Sop2),
|
||||
("S_SUB_U32", EncodingFamily::Sop2),
|
||||
("S_ADD_I32", EncodingFamily::Sop2),
|
||||
@@ -3622,11 +3852,38 @@ pub const FORM_IDS: [(&str, EncodingFamily); 152] = [
|
||||
("S_CBRANCH_VCCZ", EncodingFamily::Sopp),
|
||||
("S_CBRANCH_EXECZ", EncodingFamily::Sopp),
|
||||
("S_WAITCNT", EncodingFamily::Sopp),
|
||||
("V_CMP_LT_I32", EncodingFamily::Vop3),
|
||||
("V_CMP_EQ_I32", EncodingFamily::Vop3),
|
||||
("V_CMP_LE_I32", EncodingFamily::Vop3),
|
||||
("V_CMP_GT_I32", EncodingFamily::Vop3),
|
||||
("V_CMP_NE_I32", EncodingFamily::Vop3),
|
||||
("V_CMP_GE_I32", EncodingFamily::Vop3),
|
||||
("V_CMP_LT_U32", EncodingFamily::Vop3),
|
||||
("V_CMP_EQ_U32", EncodingFamily::Vop3),
|
||||
("V_CMP_LE_U32", EncodingFamily::Vop3),
|
||||
("V_CMP_GT_U32", EncodingFamily::Vop3),
|
||||
("V_CMP_NE_U32", EncodingFamily::Vop3),
|
||||
("V_CMP_GE_U32", EncodingFamily::Vop3),
|
||||
("V_CMP_F_I32", EncodingFamily::Vop3),
|
||||
("V_CMP_T_I32", EncodingFamily::Vop3),
|
||||
("V_CMP_F_U32", EncodingFamily::Vop3),
|
||||
("V_CMP_T_U32", EncodingFamily::Vop3),
|
||||
("V_ADD_NC_U32", EncodingFamily::Vop3),
|
||||
("V_MUL_I32_I24", EncodingFamily::Vop3),
|
||||
("V_MUL_HI_I32_I24", EncodingFamily::Vop3),
|
||||
("V_MUL_U32_U24", EncodingFamily::Vop3),
|
||||
("V_MUL_HI_U32_U24", EncodingFamily::Vop3),
|
||||
("V_MIN_I32", EncodingFamily::Vop3),
|
||||
("V_MAX_I32", EncodingFamily::Vop3),
|
||||
("V_MIN_U32", EncodingFamily::Vop3),
|
||||
("V_MAX_U32", EncodingFamily::Vop3),
|
||||
("V_XNOR_B32", EncodingFamily::Vop3),
|
||||
("V_SUB_NC_U32", EncodingFamily::Vop3),
|
||||
("V_SUBREV_NC_U32", EncodingFamily::Vop3),
|
||||
];
|
||||
|
||||
/// One validated row per registry form, in registry order.
|
||||
pub static FORMS: [FormSemantics; 152] = [
|
||||
pub static FORMS: [FormSemantics; 179] = [
|
||||
FormSemantics {
|
||||
name: "S_ADD_U32",
|
||||
family: EncodingFamily::Sop2,
|
||||
@@ -6798,6 +7055,342 @@ pub static FORMS: [FormSemantics; 152] = [
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.5", page: 125 }, SpecRef { document: Document::Guide, section: "13.1.5", page: 245 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_CMP_LT_I32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 129,
|
||||
operation: Operation::Compare,
|
||||
signedness: Signedness::Signed,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: Some(CompareRelation::Less),
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::SdstLaneMask,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Wave32,
|
||||
operands: OperandRule::Vop3CmpVgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "3.9", page: 19 }, SpecRef { document: Document::Guide, section: "13.3.4", page: 257 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_CMP_EQ_I32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 130,
|
||||
operation: Operation::Compare,
|
||||
signedness: Signedness::Signed,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: Some(CompareRelation::Equal),
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::SdstLaneMask,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Wave32,
|
||||
operands: OperandRule::Vop3CmpVgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "3.9", page: 19 }, SpecRef { document: Document::Guide, section: "13.3.4", page: 257 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_CMP_LE_I32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 131,
|
||||
operation: Operation::Compare,
|
||||
signedness: Signedness::Signed,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: Some(CompareRelation::LessOrEqual),
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::SdstLaneMask,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Wave32,
|
||||
operands: OperandRule::Vop3CmpVgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "3.9", page: 19 }, SpecRef { document: Document::Guide, section: "13.3.4", page: 257 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_CMP_GT_I32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 132,
|
||||
operation: Operation::Compare,
|
||||
signedness: Signedness::Signed,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: Some(CompareRelation::Greater),
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::SdstLaneMask,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Wave32,
|
||||
operands: OperandRule::Vop3CmpVgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "3.9", page: 19 }, SpecRef { document: Document::Guide, section: "13.3.4", page: 257 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_CMP_NE_I32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 133,
|
||||
operation: Operation::Compare,
|
||||
signedness: Signedness::Signed,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: Some(CompareRelation::NotEqual),
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::SdstLaneMask,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Wave32,
|
||||
operands: OperandRule::Vop3CmpVgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "3.9", page: 19 }, SpecRef { document: Document::Guide, section: "13.3.4", page: 257 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_CMP_GE_I32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 134,
|
||||
operation: Operation::Compare,
|
||||
signedness: Signedness::Signed,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: Some(CompareRelation::GreaterOrEqual),
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::SdstLaneMask,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Wave32,
|
||||
operands: OperandRule::Vop3CmpVgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "3.9", page: 19 }, SpecRef { document: Document::Guide, section: "13.3.4", page: 257 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_CMP_LT_U32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 193,
|
||||
operation: Operation::Compare,
|
||||
signedness: Signedness::Unsigned,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: Some(CompareRelation::Less),
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::SdstLaneMask,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Wave32,
|
||||
operands: OperandRule::Vop3CmpVgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "3.9", page: 19 }, SpecRef { document: Document::Guide, section: "13.3.4", page: 257 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_CMP_EQ_U32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 194,
|
||||
operation: Operation::Compare,
|
||||
signedness: Signedness::Unsigned,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: Some(CompareRelation::Equal),
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::SdstLaneMask,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Wave32,
|
||||
operands: OperandRule::Vop3CmpVgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "3.9", page: 19 }, SpecRef { document: Document::Guide, section: "13.3.4", page: 257 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_CMP_LE_U32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 195,
|
||||
operation: Operation::Compare,
|
||||
signedness: Signedness::Unsigned,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: Some(CompareRelation::LessOrEqual),
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::SdstLaneMask,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Wave32,
|
||||
operands: OperandRule::Vop3CmpVgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "3.9", page: 19 }, SpecRef { document: Document::Guide, section: "13.3.4", page: 257 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_CMP_GT_U32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 196,
|
||||
operation: Operation::Compare,
|
||||
signedness: Signedness::Unsigned,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: Some(CompareRelation::Greater),
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::SdstLaneMask,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Wave32,
|
||||
operands: OperandRule::Vop3CmpVgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "3.9", page: 19 }, SpecRef { document: Document::Guide, section: "13.3.4", page: 257 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_CMP_NE_U32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 197,
|
||||
operation: Operation::Compare,
|
||||
signedness: Signedness::Unsigned,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: Some(CompareRelation::NotEqual),
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::SdstLaneMask,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Wave32,
|
||||
operands: OperandRule::Vop3CmpVgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "3.9", page: 19 }, SpecRef { document: Document::Guide, section: "13.3.4", page: 257 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_CMP_GE_U32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 198,
|
||||
operation: Operation::Compare,
|
||||
signedness: Signedness::Unsigned,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: Some(CompareRelation::GreaterOrEqual),
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::SdstLaneMask,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Wave32,
|
||||
operands: OperandRule::Vop3CmpVgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "3.9", page: 19 }, SpecRef { document: Document::Guide, section: "13.3.4", page: 257 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_CMP_F_I32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 128,
|
||||
operation: Operation::Compare,
|
||||
signedness: Signedness::Signed,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: Some(CompareRelation::False),
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::SdstLaneMask,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Wave32,
|
||||
operands: OperandRule::Vop3CmpVgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "3.9", page: 19 }, SpecRef { document: Document::Guide, section: "13.3.4", page: 257 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_CMP_T_I32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 135,
|
||||
operation: Operation::Compare,
|
||||
signedness: Signedness::Signed,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: Some(CompareRelation::True),
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::SdstLaneMask,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Wave32,
|
||||
operands: OperandRule::Vop3CmpVgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "3.9", page: 19 }, SpecRef { document: Document::Guide, section: "13.3.4", page: 257 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_CMP_F_U32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 192,
|
||||
operation: Operation::Compare,
|
||||
signedness: Signedness::Unsigned,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: Some(CompareRelation::False),
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::SdstLaneMask,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Wave32,
|
||||
operands: OperandRule::Vop3CmpVgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "3.9", page: 19 }, SpecRef { document: Document::Guide, section: "13.3.4", page: 257 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_CMP_T_U32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 199,
|
||||
operation: Operation::Compare,
|
||||
signedness: Signedness::Unsigned,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: Some(CompareRelation::True),
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::SdstLaneMask,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Wave32,
|
||||
operands: OperandRule::Vop3CmpVgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "3.9", page: 19 }, SpecRef { document: Document::Guide, section: "13.3.4", page: 257 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_ADD_NC_U32",
|
||||
family: EncodingFamily::Vop3,
|
||||
@@ -6819,4 +7412,235 @@ pub static FORMS: [FormSemantics; 152] = [
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 134 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_MUL_I32_I24",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 265,
|
||||
operation: Operation::Multiply24,
|
||||
signedness: Signedness::Signed,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Vop3Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 131 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_MUL_HI_I32_I24",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 266,
|
||||
operation: Operation::MultiplyHigh24,
|
||||
signedness: Signedness::Signed,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Vop3Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 132 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_MUL_U32_U24",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 267,
|
||||
operation: Operation::Multiply24,
|
||||
signedness: Signedness::Unsigned,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Vop3Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 132 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_MUL_HI_U32_U24",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 268,
|
||||
operation: Operation::MultiplyHigh24,
|
||||
signedness: Signedness::Unsigned,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Vop3Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 132 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_MIN_I32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 273,
|
||||
operation: Operation::Minimum,
|
||||
signedness: Signedness::Signed,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Vop3Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 133 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_MAX_I32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 274,
|
||||
operation: Operation::Maximum,
|
||||
signedness: Signedness::Signed,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Vop3Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 133 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_MIN_U32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 275,
|
||||
operation: Operation::Minimum,
|
||||
signedness: Signedness::Unsigned,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Vop3Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 133 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_MAX_U32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 276,
|
||||
operation: Operation::Maximum,
|
||||
signedness: Signedness::Unsigned,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Vop3Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 133 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_XNOR_B32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 286,
|
||||
operation: Operation::Xnor,
|
||||
signedness: Signedness::Bitwise,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Vop3Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 134 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_SUB_NC_U32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 294,
|
||||
operation: Operation::Sub,
|
||||
signedness: Signedness::Unsigned,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: false,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Vop3Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 134 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
FormSemantics {
|
||||
name: "V_SUBREV_NC_U32",
|
||||
family: EncodingFamily::Vop3,
|
||||
opcode: 295,
|
||||
operation: Operation::Sub,
|
||||
signedness: Signedness::Unsigned,
|
||||
carry_in: CarryIn::None,
|
||||
width: 32,
|
||||
shift_count_bits: 0,
|
||||
shift_amount: 0,
|
||||
swap_sources: true,
|
||||
source_bits: 32,
|
||||
relation: None,
|
||||
scc: SccEffect::Unchanged,
|
||||
vcc: MaskEffect::Unchanged,
|
||||
exec: MaskEffect::Unchanged,
|
||||
wave: Wave::Any,
|
||||
operands: OperandRule::Vop3Vgpr2,
|
||||
spec: &[SpecRef { document: Document::Guide, section: "12.12", page: 167 }, SpecRef { document: Document::Guide, section: "12.7", page: 134 }],
|
||||
verify: &[Evidence::Reference, Evidence::Independent, Evidence::Metal, Evidence::LlvmEncoding],
|
||||
},
|
||||
];
|
||||
@@ -2,11 +2,12 @@
|
||||
|
||||
use xenora_isa::meta::{EncodingFamily, FORMS as META_FORMS};
|
||||
use xenora_isa::semantics::{
|
||||
CarryIn, FORM_IDS, FORMS, GENERATED_SCHEMA, MaskEffect, SCHEMA, SccEffect, Signedness, Wave,
|
||||
CarryIn, FORM_IDS, FORMS, GENERATED_SCHEMA, MaskEffect, OperandRule, SCHEMA, SccEffect,
|
||||
Signedness, Wave,
|
||||
};
|
||||
use xenora_isa::{
|
||||
CompareRelation, ScalarAluOp, ScalarCompareOp, ScalarImmediateCompareOp, ScalarImmediateOp,
|
||||
ScalarUnaryOp, VectorAluOp, VectorAluVop3Op, VectorCompareOp,
|
||||
ScalarUnaryOp, VectorAluOp, VectorAluVop3Op, VectorCompareOp, VectorCompareVop3Op,
|
||||
};
|
||||
|
||||
#[test]
|
||||
@@ -261,8 +262,38 @@ fn vop3_variant_dispatch_selects_exactly_the_registry_vop3_rows() {
|
||||
assert_eq!(row.swap_sources, base.swap_sources);
|
||||
assert_eq!(op.assembly_name(), format!("{}_e64", op.base().mnemonic()));
|
||||
}
|
||||
for base_op in VectorCompareOp::ALL {
|
||||
let base = base_op.semantics();
|
||||
let mut variants = VectorCompareVop3Op::ALL
|
||||
.into_iter()
|
||||
.filter(|op| op.base() == base_op);
|
||||
if base.width != 32 {
|
||||
assert_eq!(variants.next(), None, "{}", base.name);
|
||||
continue;
|
||||
}
|
||||
let op = variants
|
||||
.next()
|
||||
.expect("32-bit VOPC form must have a VOP3A encoding");
|
||||
assert_eq!(variants.next(), None);
|
||||
let row = op.semantics();
|
||||
assert_eq!((row.name, row.family), (base.name, EncodingFamily::Vop3));
|
||||
assert_eq!(row.operation, base.operation);
|
||||
assert_eq!(row.signedness, base.signedness);
|
||||
assert_eq!(row.relation, base.relation);
|
||||
assert_eq!(row.scc, SccEffect::Unchanged);
|
||||
assert_eq!(row.exec, MaskEffect::Unchanged);
|
||||
assert_eq!(row.wave, Wave::Wave32);
|
||||
assert_eq!(row.width, 32);
|
||||
assert_eq!(row.vcc, MaskEffect::SdstLaneMask);
|
||||
assert_eq!(row.operands, OperandRule::Vop3CmpVgpr2);
|
||||
assert_eq!(op.assembly_name(), format!("{}_e64", base_op.mnemonic()));
|
||||
}
|
||||
dispatch_selects_exactly(EncodingFamily::Vop3, |word| {
|
||||
VectorAluVop3Op::from_word(word).map(|op| op.semantics().name)
|
||||
let alu = VectorAluVop3Op::from_word(word);
|
||||
let compare = VectorCompareVop3Op::from_word(word);
|
||||
assert!(alu.is_none() || compare.is_none(), "{word:#x}");
|
||||
alu.map(|op| op.semantics().name)
|
||||
.or_else(|| compare.map(|op| op.semantics().name))
|
||||
});
|
||||
// No first word of the other 64-bit families (VOP3B shares VOP3's
|
||||
// encoding bits) selects a variant.
|
||||
@@ -276,5 +307,11 @@ fn vop3_variant_dispatch_selects_exactly_the_registry_vop3_rows() {
|
||||
"{}",
|
||||
meta.name
|
||||
);
|
||||
assert_eq!(
|
||||
VectorCompareVop3Op::from_word(meta.bits as u32),
|
||||
None,
|
||||
"{}",
|
||||
meta.name
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,7 @@ gpu-tests = []
|
||||
[dependencies]
|
||||
libc = "0.2"
|
||||
sha2 = "0.10"
|
||||
xenora-texture = { path = "../texture" }
|
||||
|
||||
[dev-dependencies]
|
||||
xenora-metal = { path = "../metal" }
|
||||
|
||||
+1030
-2
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -33,6 +33,7 @@ objc2-metal = { version = "=0.3.2", default-features = false, features = [
|
||||
"std",
|
||||
"MTLAllocation",
|
||||
"MTLArgument",
|
||||
"MTLBlitCommandEncoder",
|
||||
"MTLBuffer",
|
||||
"MTLCommandBuffer",
|
||||
"MTLCommandEncoder",
|
||||
|
||||
@@ -101,7 +101,43 @@ impl NativeCompute {
|
||||
colors,
|
||||
[width, height],
|
||||
clear,
|
||||
sampled,
|
||||
sampled.map(|(texture, sampler)| (texture.raw(), sampler)),
|
||||
)
|
||||
.map(|(pixels, _)| pixels)
|
||||
}
|
||||
|
||||
/// As [`Self::render_rgba8_sampled`], with level 0 of a BC1 upload bound
|
||||
/// natively as a `BC1_RGBA` texture to fragment texture slot 0 and the
|
||||
/// sampler to fragment sampler slot 0.
|
||||
///
|
||||
/// # Errors
|
||||
///
|
||||
/// As [`Self::render_rgba8_sampled`], and for an invalid BC1 level.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn render_rgba8_sampled_bc1(
|
||||
&self,
|
||||
source: &str,
|
||||
entries: [&str; 2],
|
||||
vertices: &[[f32; 4]; 3],
|
||||
colors: &[[f32; 4]; 3],
|
||||
extent: [usize; 2],
|
||||
clear: [u8; 4],
|
||||
texture: &Bc1Upload<'_>,
|
||||
sampler: &crate::sampler::MetalSampler,
|
||||
) -> Result<Vec<u8>, MetalError> {
|
||||
let level = texture
|
||||
.subresource(0, 0)
|
||||
.map_err(|error| MetalError::new("texture subresource", format!("{error:?}")))?;
|
||||
self.validate_bc_extent(level.width, level.height, "BC1")?;
|
||||
let bc1 = self.new_bc1_texture(&level)?;
|
||||
self.render_rgba8_internal(
|
||||
source,
|
||||
entries,
|
||||
vertices,
|
||||
colors,
|
||||
extent,
|
||||
clear,
|
||||
Some((&bc1, sampler)),
|
||||
)
|
||||
.map(|(pixels, _)| pixels)
|
||||
}
|
||||
@@ -116,7 +152,7 @@ impl NativeCompute {
|
||||
[width, height]: [usize; 2],
|
||||
clear: [u8; 4],
|
||||
sampled: Option<(
|
||||
&crate::texture_pipeline::MetalRgba8Texture,
|
||||
&ProtocolObject<dyn MTLTexture>,
|
||||
&crate::sampler::MetalSampler,
|
||||
)>,
|
||||
) -> Result<(Vec<u8>, Option<f64>), MetalError> {
|
||||
@@ -228,7 +264,7 @@ impl NativeCompute {
|
||||
encoder.setVertexBuffer_offset_atIndex(Some(&positions), 0, 0);
|
||||
encoder.setVertexBuffer_offset_atIndex(Some(&colors), 0, 1);
|
||||
if let Some((tex, samp)) = sampled {
|
||||
encoder.setFragmentTexture_atIndex(Some(tex.raw()), 0);
|
||||
encoder.setFragmentTexture_atIndex(Some(tex), 0);
|
||||
encoder.setFragmentSamplerState_atIndex(Some(samp.raw()), 0);
|
||||
}
|
||||
encoder.drawPrimitives_vertexStart_vertexCount(MTLPrimitiveType::Triangle, 0, 3);
|
||||
|
||||
@@ -11,8 +11,9 @@ use std::ptr::NonNull;
|
||||
use objc2::rc::{Retained, autoreleasepool};
|
||||
use objc2::runtime::ProtocolObject;
|
||||
use objc2_metal::{
|
||||
MTLDevice, MTLOrigin, MTLPixelFormat, MTLRegion, MTLResourceOptions, MTLSize, MTLStorageMode,
|
||||
MTLTexture, MTLTextureDescriptor, MTLTextureUsage,
|
||||
MTLBlitCommandEncoder, MTLBuffer, MTLCommandBuffer, MTLCommandBufferStatus, MTLCommandEncoder,
|
||||
MTLCommandQueue, MTLDevice, MTLOrigin, MTLPixelFormat, MTLRegion, MTLResourceOptions, MTLSize,
|
||||
MTLStorageMode, MTLTexture, MTLTextureDescriptor, MTLTextureUsage,
|
||||
};
|
||||
use xenora_texture::{SamplerError, TextureMetadata};
|
||||
|
||||
@@ -100,6 +101,9 @@ impl Rgba8TextureDesc {
|
||||
pub struct MetalRgba8Texture {
|
||||
texture: Retained<ProtocolObject<dyn MTLTexture>>,
|
||||
desc: Rgba8TextureDesc,
|
||||
/// Shared storage, which `replaceRegion` may write. Private textures are
|
||||
/// filled only through `upload_staged`.
|
||||
cpu_writable: bool,
|
||||
}
|
||||
|
||||
impl MetalRgba8Texture {
|
||||
@@ -108,6 +112,19 @@ impl MetalRgba8Texture {
|
||||
device: &ProtocolObject<dyn MTLDevice>,
|
||||
desc: Rgba8TextureDesc,
|
||||
) -> Result<Self, MetalError> {
|
||||
Self::allocate_with_storage(device, desc, MTLStorageMode::Shared)
|
||||
}
|
||||
|
||||
fn allocate_with_storage(
|
||||
device: &ProtocolObject<dyn MTLDevice>,
|
||||
desc: Rgba8TextureDesc,
|
||||
storage: MTLStorageMode,
|
||||
) -> Result<Self, MetalError> {
|
||||
let options = if storage == MTLStorageMode::Private {
|
||||
MTLResourceOptions::StorageModePrivate
|
||||
} else {
|
||||
MTLResourceOptions::StorageModeShared
|
||||
};
|
||||
autoreleasepool(|_| {
|
||||
// SAFETY: Validated non-zero dimensions within MAX_TEXTURE_PIXELS and RGBA8Unorm format.
|
||||
let descriptor = unsafe {
|
||||
@@ -124,8 +141,8 @@ impl MetalRgba8Texture {
|
||||
descriptor.setMipmapLevelCount(desc.mips as usize);
|
||||
}
|
||||
}
|
||||
descriptor.setStorageMode(MTLStorageMode::Shared);
|
||||
descriptor.setResourceOptions(MTLResourceOptions::StorageModeShared);
|
||||
descriptor.setStorageMode(storage);
|
||||
descriptor.setResourceOptions(options);
|
||||
descriptor.setUsage(MTLTextureUsage::ShaderRead);
|
||||
|
||||
let texture = device
|
||||
@@ -137,51 +154,25 @@ impl MetalRgba8Texture {
|
||||
)
|
||||
})?;
|
||||
|
||||
Ok(Self { texture, desc })
|
||||
Ok(Self {
|
||||
texture,
|
||||
desc,
|
||||
cpu_writable: storage == MTLStorageMode::Shared,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/// Upload a single validated mip level into this texture.
|
||||
///
|
||||
/// Only Shared-storage textures from `allocate` or `upload` accept CPU writes.
|
||||
pub fn upload_mip(&self, mip: &Rgba8MipLevel<'_>) -> Result<(), MetalError> {
|
||||
let (expected_w, expected_h) = self.desc.mip_extent(mip.level)?;
|
||||
if mip.width != expected_w || mip.height != expected_h {
|
||||
if !self.cpu_writable {
|
||||
return Err(MetalError::new(
|
||||
"mip dimensions",
|
||||
format!(
|
||||
"mip level {} expected {}x{}, got {}x{}",
|
||||
mip.level, expected_w, expected_h, mip.width, mip.height
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
let tight_pitch = mip
|
||||
.width
|
||||
.checked_mul(RGBA8_TEXEL_BYTES)
|
||||
.ok_or_else(|| MetalError::new("row pitch", "row pitch overflow"))?;
|
||||
if mip.row_pitch < tight_pitch {
|
||||
return Err(MetalError::new(
|
||||
"row pitch",
|
||||
format!(
|
||||
"row pitch {} smaller than tight pitch {}",
|
||||
mip.row_pitch, tight_pitch
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
let min_bytes = mip
|
||||
.row_pitch
|
||||
.checked_mul(mip.height)
|
||||
.ok_or_else(|| MetalError::new("mip bytes", "byte length calculation overflow"))?;
|
||||
if mip.bytes.len() < min_bytes {
|
||||
return Err(MetalError::new(
|
||||
"mip buffer bounds",
|
||||
format!(
|
||||
"buffer length {} is less than required {}",
|
||||
mip.bytes.len(),
|
||||
min_bytes
|
||||
),
|
||||
"texture storage",
|
||||
"a Private-storage texture is filled only by upload_staged",
|
||||
));
|
||||
}
|
||||
validate_mip(&self.desc, mip)?;
|
||||
|
||||
autoreleasepool(|_| {
|
||||
let region = MTLRegion {
|
||||
@@ -227,6 +218,148 @@ impl MetalRgba8Texture {
|
||||
Ok(texture)
|
||||
}
|
||||
|
||||
/// Allocate a Private-storage RGBA8 texture and fill every mip level through
|
||||
/// a reused Shared staging buffer that never exceeds `budget`.
|
||||
///
|
||||
/// The plan from [`plan_staged_upload`] is built, and every input checked,
|
||||
/// before any Metal object is created. Each submission copies its rows into
|
||||
/// the staging buffer, blits them into the texture and waits until the
|
||||
/// command buffer has completed. Only a `Completed` status lets the buffer be
|
||||
/// reused; any other status is returned as an error.
|
||||
pub fn upload_staged(
|
||||
device: &ProtocolObject<dyn MTLDevice>,
|
||||
queue: &ProtocolObject<dyn MTLCommandQueue>,
|
||||
desc: Rgba8TextureDesc,
|
||||
mips: &[Rgba8MipLevel<'_>],
|
||||
budget: StagingBudget,
|
||||
) -> Result<(Self, StagedUploadReport), MetalError> {
|
||||
let plan = plan_staged_upload(&desc, mips, budget)?;
|
||||
let staging_len = plan.iter().map(|s| s.staging_bytes).max().unwrap_or(0);
|
||||
let texture = Self::allocate_with_storage(device, desc, MTLStorageMode::Private)?;
|
||||
let staging = device
|
||||
.newBufferWithLength_options(staging_len, MTLResourceOptions::StorageModeShared)
|
||||
.ok_or_else(|| MetalError::new("newBufferWithLength", "staging allocation failed"))?;
|
||||
let mut copied = 0;
|
||||
for submission in &plan {
|
||||
for copy in &submission.copies {
|
||||
let mip = mips
|
||||
.iter()
|
||||
.find(|mip| mip.level == copy.level)
|
||||
.ok_or_else(|| MetalError::new("staged upload", "planned level missing"))?;
|
||||
let tight = mip.width * RGBA8_TEXEL_BYTES;
|
||||
for row in 0..copy.rows {
|
||||
let src = &mip.bytes[(copy.first_row + row) * mip.row_pitch..][..tight];
|
||||
let offset = copy.staging_offset + row * tight;
|
||||
// SAFETY: The plan keeps offset + tight within staging_len, the
|
||||
// buffer is Shared and CPU-visible, and the previous submission
|
||||
// has completed, so the GPU no longer reads these bytes.
|
||||
unsafe {
|
||||
let dst = staging.contents().cast::<u8>().as_ptr().add(offset);
|
||||
std::ptr::copy_nonoverlapping(src.as_ptr(), dst, tight);
|
||||
}
|
||||
}
|
||||
copied += copy.rows * tight;
|
||||
}
|
||||
autoreleasepool(|_| texture.encode_staged(queue, &staging, submission))?;
|
||||
}
|
||||
let report = StagedUploadReport {
|
||||
submissions: plan.len(),
|
||||
peak_staging_bytes: staging_len,
|
||||
bytes_copied: copied,
|
||||
};
|
||||
Ok((texture, report))
|
||||
}
|
||||
|
||||
fn encode_staged(
|
||||
&self,
|
||||
queue: &ProtocolObject<dyn MTLCommandQueue>,
|
||||
staging: &ProtocolObject<dyn MTLBuffer>,
|
||||
submission: &StagedSubmission,
|
||||
) -> Result<(), MetalError> {
|
||||
let command = queue
|
||||
.commandBuffer()
|
||||
.ok_or_else(|| MetalError::new("commandBuffer", "command buffer creation failed"))?;
|
||||
let blit = command
|
||||
.blitCommandEncoder()
|
||||
.ok_or_else(|| MetalError::new("blitCommandEncoder", "blit encoder creation failed"))?;
|
||||
for copy in &submission.copies {
|
||||
let (width, _) = self.desc.mip_extent(copy.level)?;
|
||||
let pitch = width * RGBA8_TEXEL_BYTES;
|
||||
// SAFETY: The plan validated the level, the row range within the mip and
|
||||
// the staging range within the buffer. The command buffer retains both
|
||||
// resources, and the caller waits for completion before reusing staging.
|
||||
unsafe {
|
||||
blit.copyFromBuffer_sourceOffset_sourceBytesPerRow_sourceBytesPerImage_sourceSize_toTexture_destinationSlice_destinationLevel_destinationOrigin(
|
||||
staging,
|
||||
copy.staging_offset,
|
||||
pitch,
|
||||
pitch * copy.rows,
|
||||
MTLSize { width, height: copy.rows, depth: 1 },
|
||||
&self.texture,
|
||||
0,
|
||||
copy.level as usize,
|
||||
MTLOrigin { x: 0, y: copy.first_row, z: 0 },
|
||||
);
|
||||
}
|
||||
}
|
||||
blit.endEncoding();
|
||||
command.commit();
|
||||
command.waitUntilCompleted();
|
||||
check_completed(&command)
|
||||
}
|
||||
|
||||
/// Copy one mip level back into tightly packed RGBA8 bytes through a blit.
|
||||
///
|
||||
/// Works for Shared and Private textures and shares no code with the upload
|
||||
/// paths, so tests can compare its output with independently built pixels.
|
||||
pub fn read_back(
|
||||
&self,
|
||||
device: &ProtocolObject<dyn MTLDevice>,
|
||||
queue: &ProtocolObject<dyn MTLCommandQueue>,
|
||||
level: u32,
|
||||
) -> Result<Vec<u8>, MetalError> {
|
||||
let (width, height) = self.desc.mip_extent(level)?;
|
||||
let pitch = width * RGBA8_TEXEL_BYTES;
|
||||
let len = pitch * height;
|
||||
autoreleasepool(|_| {
|
||||
let buffer = device
|
||||
.newBufferWithLength_options(len, MTLResourceOptions::StorageModeShared)
|
||||
.ok_or_else(|| {
|
||||
MetalError::new("newBufferWithLength", "readback allocation failed")
|
||||
})?;
|
||||
let command = queue.commandBuffer().ok_or_else(|| {
|
||||
MetalError::new("commandBuffer", "command buffer creation failed")
|
||||
})?;
|
||||
let blit = command.blitCommandEncoder().ok_or_else(|| {
|
||||
MetalError::new("blitCommandEncoder", "blit encoder creation failed")
|
||||
})?;
|
||||
// SAFETY: The level is in range, the source region is the whole mip and
|
||||
// the destination buffer holds exactly pitch * height bytes.
|
||||
unsafe {
|
||||
blit.copyFromTexture_sourceSlice_sourceLevel_sourceOrigin_sourceSize_toBuffer_destinationOffset_destinationBytesPerRow_destinationBytesPerImage(
|
||||
&self.texture,
|
||||
0,
|
||||
level as usize,
|
||||
MTLOrigin { x: 0, y: 0, z: 0 },
|
||||
MTLSize { width, height, depth: 1 },
|
||||
&buffer,
|
||||
0,
|
||||
pitch,
|
||||
len,
|
||||
);
|
||||
}
|
||||
blit.endEncoding();
|
||||
command.commit();
|
||||
command.waitUntilCompleted();
|
||||
check_completed(&command)?;
|
||||
// SAFETY: The command buffer completed, so the Shared buffer holds len
|
||||
// initialized bytes and the GPU no longer writes it.
|
||||
let bytes =
|
||||
unsafe { std::slice::from_raw_parts(buffer.contents().cast::<u8>().as_ptr(), len) };
|
||||
Ok(bytes.to_vec())
|
||||
})
|
||||
}
|
||||
|
||||
/// Access the underlying native Metal texture protocol object.
|
||||
#[inline]
|
||||
pub fn raw(&self) -> &ProtocolObject<dyn MTLTexture> {
|
||||
@@ -240,6 +373,198 @@ impl MetalRgba8Texture {
|
||||
}
|
||||
}
|
||||
|
||||
/// Upper bound on the staging bytes one staged upload holds at a time.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct StagingBudget {
|
||||
max_bytes: usize,
|
||||
}
|
||||
|
||||
impl StagingBudget {
|
||||
/// A budget of `max_bytes`, which must be a non-zero multiple of the RGBA8
|
||||
/// texel size so every staged row starts on a texel boundary.
|
||||
pub fn new(max_bytes: usize) -> Result<Self, MetalError> {
|
||||
if max_bytes == 0 || !max_bytes.is_multiple_of(RGBA8_TEXEL_BYTES) {
|
||||
return Err(MetalError::new(
|
||||
"staging budget",
|
||||
format!("budget {max_bytes} must be a non-zero multiple of {RGBA8_TEXEL_BYTES}"),
|
||||
));
|
||||
}
|
||||
Ok(Self { max_bytes })
|
||||
}
|
||||
|
||||
/// The largest staging allocation this budget allows.
|
||||
#[must_use]
|
||||
pub fn max_bytes(&self) -> usize {
|
||||
self.max_bytes
|
||||
}
|
||||
}
|
||||
|
||||
/// One blit of whole rows of one mip level from the staging buffer.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct StagedCopy {
|
||||
pub level: u32,
|
||||
pub first_row: usize,
|
||||
pub rows: usize,
|
||||
/// Byte offset of the first row in the staging buffer. Rows are packed tightly.
|
||||
pub staging_offset: usize,
|
||||
}
|
||||
|
||||
/// The copies that share one staging fill and one command buffer.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct StagedSubmission {
|
||||
pub copies: Vec<StagedCopy>,
|
||||
/// Staging bytes this submission uses, never more than the budget.
|
||||
pub staging_bytes: usize,
|
||||
}
|
||||
|
||||
/// What a staged upload did, measured from the executed plan.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct StagedUploadReport {
|
||||
/// Command buffers committed and completed.
|
||||
pub submissions: usize,
|
||||
/// Size of the one staging buffer, the most staging memory held at once.
|
||||
pub peak_staging_bytes: usize,
|
||||
/// Texel bytes copied into the texture.
|
||||
pub bytes_copied: usize,
|
||||
}
|
||||
|
||||
/// Split a full RGBA8 upload into budget-sized submissions of whole rows.
|
||||
///
|
||||
/// Every level `0..desc.mips` must appear exactly once, because a Private
|
||||
/// texture has no defined contents for a level nobody writes. Each mip is
|
||||
/// checked like [`MetalRgba8Texture::upload_mip`] checks it. The budget must hold
|
||||
/// at least one row of the widest level. Rows are packed in level order, and a
|
||||
/// submission closes when the next row would exceed the budget.
|
||||
pub fn plan_staged_upload(
|
||||
desc: &Rgba8TextureDesc,
|
||||
mips: &[Rgba8MipLevel<'_>],
|
||||
budget: StagingBudget,
|
||||
) -> Result<Vec<StagedSubmission>, MetalError> {
|
||||
let mut by_level: Vec<Option<&Rgba8MipLevel<'_>>> = vec![None; desc.mips as usize];
|
||||
for mip in mips {
|
||||
validate_mip(desc, mip)?;
|
||||
let slot = &mut by_level[mip.level as usize];
|
||||
if slot.is_some() {
|
||||
return Err(MetalError::new(
|
||||
"staged upload",
|
||||
format!("mip level {} appears more than once", mip.level),
|
||||
));
|
||||
}
|
||||
*slot = Some(mip);
|
||||
}
|
||||
let mut plan = Vec::new();
|
||||
let mut current = StagedSubmission {
|
||||
copies: Vec::new(),
|
||||
staging_bytes: 0,
|
||||
};
|
||||
for (level, mip) in by_level.iter().enumerate() {
|
||||
let mip = mip.ok_or_else(|| {
|
||||
MetalError::new("staged upload", format!("mip level {level} is missing"))
|
||||
})?;
|
||||
let pitch = mip.width * RGBA8_TEXEL_BYTES;
|
||||
if pitch > budget.max_bytes {
|
||||
return Err(MetalError::new(
|
||||
"staging budget",
|
||||
format!(
|
||||
"budget {} is smaller than one {pitch}-byte row of mip level {level}",
|
||||
budget.max_bytes
|
||||
),
|
||||
));
|
||||
}
|
||||
let mut row = 0;
|
||||
while row < mip.height {
|
||||
let fit = (budget.max_bytes - current.staging_bytes) / pitch;
|
||||
if fit == 0 {
|
||||
// Unreachable after the row check above, but an empty submission
|
||||
// that cannot take one row must never loop.
|
||||
if current.copies.is_empty() {
|
||||
return Err(MetalError::new(
|
||||
"staging budget",
|
||||
"a row does not fit an empty staging buffer",
|
||||
));
|
||||
}
|
||||
plan.push(std::mem::replace(
|
||||
&mut current,
|
||||
StagedSubmission {
|
||||
copies: Vec::new(),
|
||||
staging_bytes: 0,
|
||||
},
|
||||
));
|
||||
continue;
|
||||
}
|
||||
let rows = fit.min(mip.height - row);
|
||||
current.copies.push(StagedCopy {
|
||||
level: mip.level,
|
||||
first_row: row,
|
||||
rows,
|
||||
staging_offset: current.staging_bytes,
|
||||
});
|
||||
current.staging_bytes += rows * pitch;
|
||||
row += rows;
|
||||
}
|
||||
}
|
||||
if !current.copies.is_empty() {
|
||||
plan.push(current);
|
||||
}
|
||||
Ok(plan)
|
||||
}
|
||||
|
||||
fn check_completed(command: &ProtocolObject<dyn MTLCommandBuffer>) -> Result<(), MetalError> {
|
||||
let status = command.status();
|
||||
if status != MTLCommandBufferStatus::Completed {
|
||||
let detail = command.error().map_or_else(
|
||||
|| format!("unexpected command status {status:?}"),
|
||||
|error| error.localizedDescription().to_string(),
|
||||
);
|
||||
return Err(MetalError::new("waitUntilCompleted", detail));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Check one mip level against the texture description and return its tight row pitch.
|
||||
fn validate_mip(desc: &Rgba8TextureDesc, mip: &Rgba8MipLevel<'_>) -> Result<usize, MetalError> {
|
||||
let (expected_w, expected_h) = desc.mip_extent(mip.level)?;
|
||||
if mip.width != expected_w || mip.height != expected_h {
|
||||
return Err(MetalError::new(
|
||||
"mip dimensions",
|
||||
format!(
|
||||
"mip level {} expected {}x{}, got {}x{}",
|
||||
mip.level, expected_w, expected_h, mip.width, mip.height
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
let tight_pitch = mip
|
||||
.width
|
||||
.checked_mul(RGBA8_TEXEL_BYTES)
|
||||
.ok_or_else(|| MetalError::new("row pitch", "row pitch overflow"))?;
|
||||
if mip.row_pitch < tight_pitch {
|
||||
return Err(MetalError::new(
|
||||
"row pitch",
|
||||
format!(
|
||||
"row pitch {} smaller than tight pitch {}",
|
||||
mip.row_pitch, tight_pitch
|
||||
),
|
||||
));
|
||||
}
|
||||
|
||||
let min_bytes = mip
|
||||
.row_pitch
|
||||
.checked_mul(mip.height)
|
||||
.ok_or_else(|| MetalError::new("mip bytes", "byte length calculation overflow"))?;
|
||||
if mip.bytes.len() < min_bytes {
|
||||
return Err(MetalError::new(
|
||||
"mip buffer bounds",
|
||||
format!(
|
||||
"buffer length {} is less than required {}",
|
||||
mip.bytes.len(),
|
||||
min_bytes
|
||||
),
|
||||
));
|
||||
}
|
||||
Ok(tight_pitch)
|
||||
}
|
||||
|
||||
/// Resource binding indices and lifetime conventions for sampling pipelines.
|
||||
///
|
||||
/// In the Xenora fixture ABI and translated shader conventions:
|
||||
@@ -328,3 +653,150 @@ impl BoundSampledTexture {
|
||||
self.sampler_slot
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn copy(level: u32, first_row: usize, rows: usize, staging_offset: usize) -> StagedCopy {
|
||||
StagedCopy {
|
||||
level,
|
||||
first_row,
|
||||
rows,
|
||||
staging_offset,
|
||||
}
|
||||
}
|
||||
|
||||
fn levels<'a>(desc: &Rgba8TextureDesc, bytes: &'a [u8]) -> Vec<Rgba8MipLevel<'a>> {
|
||||
(0..desc.mips)
|
||||
.map(|level| {
|
||||
let (w, h) = desc.mip_extent(level).unwrap();
|
||||
Rgba8MipLevel::new_packed(level, w, h, &bytes[..w * h * RGBA8_TEXEL_BYTES])
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn plan(desc: Rgba8TextureDesc, budget: usize) -> Vec<StagedSubmission> {
|
||||
let bytes = vec![0; desc.width * desc.height * RGBA8_TEXEL_BYTES];
|
||||
plan_staged_upload(
|
||||
&desc,
|
||||
&levels(&desc, &bytes),
|
||||
StagingBudget::new(budget).unwrap(),
|
||||
)
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn error(desc: Rgba8TextureDesc, mips: &[Rgba8MipLevel<'_>], budget: usize) -> String {
|
||||
plan_staged_upload(&desc, mips, StagingBudget::new(budget).unwrap())
|
||||
.unwrap_err()
|
||||
.to_string()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn budget_must_be_a_non_zero_texel_multiple() {
|
||||
assert!(StagingBudget::new(0).is_err());
|
||||
assert!(StagingBudget::new(6).is_err());
|
||||
assert_eq!(StagingBudget::new(8).unwrap().max_bytes(), 8);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rows_split_into_budget_sized_submissions() {
|
||||
// 8 texels × 4 bytes = 32 bytes per row; a 64-byte budget holds two rows.
|
||||
let desc = Rgba8TextureDesc::new(8, 4, 1).unwrap();
|
||||
let plan = plan(desc, 64);
|
||||
assert_eq!(plan.len(), 2);
|
||||
assert_eq!(plan[0].copies, [copy(0, 0, 2, 0)]);
|
||||
assert_eq!(plan[1].copies, [copy(0, 2, 2, 0)]);
|
||||
assert!(plan.iter().all(|s| s.staging_bytes == 64));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn one_submission_packs_every_level_when_it_fits() {
|
||||
// Levels 8×4, 4×2, 2×1: 128 + 32 + 8 = 168 bytes.
|
||||
let desc = Rgba8TextureDesc::new(8, 4, 3).unwrap();
|
||||
let plan = plan(desc, 168);
|
||||
assert_eq!(plan.len(), 1);
|
||||
assert_eq!(
|
||||
plan[0].copies,
|
||||
[copy(0, 0, 4, 0), copy(1, 0, 2, 128), copy(2, 0, 1, 160)]
|
||||
);
|
||||
assert_eq!(plan[0].staging_bytes, 168);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_submission_closes_when_the_next_row_does_not_fit() {
|
||||
// A 40-byte budget holds one 32-byte row of level 0, then two 16-byte rows of
|
||||
// level 1 and the single 8-byte row of level 2 together.
|
||||
let desc = Rgba8TextureDesc::new(8, 4, 3).unwrap();
|
||||
let plan = plan(desc, 40);
|
||||
assert_eq!(plan.len(), 5);
|
||||
for (row, submission) in plan[..4].iter().enumerate() {
|
||||
assert_eq!(submission.copies, [copy(0, row, 1, 0)]);
|
||||
assert_eq!(submission.staging_bytes, 32);
|
||||
}
|
||||
assert_eq!(plan[4].copies, [copy(1, 0, 2, 0), copy(2, 0, 1, 32)]);
|
||||
assert_eq!(plan[4].staging_bytes, 40);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_row_is_planned_once_within_budget() {
|
||||
for (w, h, mips) in [(1, 1, 1), (37, 19, 6), (64, 3, 7), (5, 128, 8)] {
|
||||
let desc = Rgba8TextureDesc::new(w, h, mips).unwrap();
|
||||
let widest = w * RGBA8_TEXEL_BYTES;
|
||||
for budget in [
|
||||
widest,
|
||||
widest + 4,
|
||||
3 * widest,
|
||||
w * h * RGBA8_TEXEL_BYTES * 2,
|
||||
] {
|
||||
let mut next_row = vec![0; mips as usize];
|
||||
for submission in plan(desc, budget) {
|
||||
assert!(submission.staging_bytes <= budget);
|
||||
let mut offset = 0;
|
||||
for c in &submission.copies {
|
||||
let (mw, _) = desc.mip_extent(c.level).unwrap();
|
||||
assert_eq!(c.first_row, next_row[c.level as usize]);
|
||||
assert_eq!(c.staging_offset, offset);
|
||||
assert!(c.rows > 0);
|
||||
offset += c.rows * mw * RGBA8_TEXEL_BYTES;
|
||||
next_row[c.level as usize] += c.rows;
|
||||
}
|
||||
assert_eq!(offset, submission.staging_bytes);
|
||||
}
|
||||
for level in 0..mips {
|
||||
assert_eq!(next_row[level as usize], desc.mip_extent(level).unwrap().1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_partial_and_malformed_uploads_before_planning() {
|
||||
let desc = Rgba8TextureDesc::new(8, 4, 2).unwrap();
|
||||
let bytes = vec![0; 8 * 4 * RGBA8_TEXEL_BYTES];
|
||||
let mips = levels(&desc, &bytes);
|
||||
|
||||
let missing = error(desc, &mips[..1], 1024);
|
||||
assert!(missing.contains("mip level 1 is missing"), "{missing}");
|
||||
|
||||
let duplicate = error(desc, &[mips[0], mips[1], mips[1]], 1024);
|
||||
assert!(duplicate.contains("more than once"), "{duplicate}");
|
||||
|
||||
let out_of_range = Rgba8MipLevel::new_packed(2, 2, 1, &bytes[..8]);
|
||||
let range = error(desc, &[mips[0], mips[1], out_of_range], 1024);
|
||||
assert!(range.contains("out of bounds"), "{range}");
|
||||
|
||||
let wrong_size = Rgba8MipLevel::new_packed(1, 4, 1, &bytes[..16]);
|
||||
assert!(error(desc, &[mips[0], wrong_size], 1024).contains("expected 4x2"));
|
||||
|
||||
let mut short_pitch = mips[0];
|
||||
short_pitch.row_pitch = 28;
|
||||
assert!(error(desc, &[short_pitch, mips[1]], 1024).contains("row pitch"));
|
||||
|
||||
let short_bytes = Rgba8MipLevel::new_packed(0, 8, 4, &bytes[..127]);
|
||||
assert!(error(desc, &[short_bytes, mips[1]], 1024).contains("buffer length"));
|
||||
|
||||
let small = error(desc, &mips, 28);
|
||||
assert!(small.contains("smaller than one 32-byte row"), "{small}");
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
use xenora_metal::texture_pipeline::{Rgba8TextureDesc, StagingBudget, plan_staged_upload};
|
||||
use xenora_metal::{MetalRgba8Texture, Rgba8MipLevel};
|
||||
use xenora_texture::{Bc1Upload, Bc1UploadDesc, TiledBc1};
|
||||
|
||||
use super::context;
|
||||
@@ -133,3 +135,162 @@ fn samples_pitched_bc1_upload_across_mips_and_layers() {
|
||||
);
|
||||
println!("checked 33 RGBA8 texels from pitched BC1 subresources");
|
||||
}
|
||||
|
||||
/// Texel bytes chosen so neighbouring texels, rows and levels all differ, built
|
||||
/// without any Xenora code so the readback has an independent expectation.
|
||||
fn pattern_texel(level: u32, x: usize, y: usize) -> [u8; 4] {
|
||||
let level = level as usize;
|
||||
[
|
||||
(x * 7 + level * 50) as u8,
|
||||
(y * 13 + level) as u8,
|
||||
((x ^ y) * 3) as u8,
|
||||
(255 - level * 9) as u8,
|
||||
]
|
||||
}
|
||||
|
||||
fn tight_pattern(level: u32, width: usize, height: usize) -> Vec<u8> {
|
||||
(0..height)
|
||||
.flat_map(|y| (0..width).flat_map(move |x| pattern_texel(level, x, y)))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Each row padded by `pad` bytes of 0xEE, which must never reach the texture.
|
||||
fn padded_pattern(level: u32, width: usize, height: usize, pad: usize) -> Vec<u8> {
|
||||
let tight = tight_pattern(level, width, height);
|
||||
tight
|
||||
.chunks(width * 4)
|
||||
.flat_map(|row| row.iter().copied().chain(std::iter::repeat_n(0xEE, pad)))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn padded_levels(desc: Rgba8TextureDesc, pad: usize) -> Vec<(usize, usize, Vec<u8>)> {
|
||||
(0..desc.mips)
|
||||
.map(|level| {
|
||||
let (w, h) = desc.mip_extent(level).unwrap();
|
||||
(w, h, padded_pattern(level, w, h, pad))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn mip_views(levels: &[(usize, usize, Vec<u8>)], pad: usize) -> Vec<Rgba8MipLevel<'_>> {
|
||||
levels
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(level, (w, h, bytes))| Rgba8MipLevel {
|
||||
level: level as u32,
|
||||
width: *w,
|
||||
height: *h,
|
||||
row_pitch: w * 4 + pad,
|
||||
bytes,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn staged_upload_matches_the_source_under_every_budget() {
|
||||
let gpu = context();
|
||||
// 37×19 has six levels, down to 1×1, and odd sizes at every level.
|
||||
let desc = Rgba8TextureDesc::new(37, 19, 6).unwrap();
|
||||
let pad = 12;
|
||||
let levels = padded_levels(desc, pad);
|
||||
let mips = mip_views(&levels, pad);
|
||||
let total: usize = levels.iter().map(|(w, h, _)| w * h * 4).sum();
|
||||
let widest_row = 37 * 4;
|
||||
// One submission, several bands, a single row per band, and a budget that
|
||||
// leaves a remainder at every level.
|
||||
for budget in [total, 3 * widest_row, widest_row, widest_row + 4] {
|
||||
let budget = StagingBudget::new(budget).unwrap();
|
||||
let plan = plan_staged_upload(&desc, &mips, budget).unwrap();
|
||||
let (texture, report) =
|
||||
MetalRgba8Texture::upload_staged(gpu.device(), gpu.queue(), desc, &mips, budget)
|
||||
.unwrap();
|
||||
assert_eq!(report.submissions, plan.len());
|
||||
assert!(report.peak_staging_bytes <= budget.max_bytes());
|
||||
assert_eq!(report.bytes_copied, total);
|
||||
if budget.max_bytes() == total {
|
||||
assert_eq!(report.submissions, 1);
|
||||
} else {
|
||||
assert!(report.submissions > 1);
|
||||
}
|
||||
for level in 0..desc.mips {
|
||||
let (w, h) = desc.mip_extent(level).unwrap();
|
||||
let actual = texture.read_back(gpu.device(), gpu.queue(), level).unwrap();
|
||||
assert_eq!(
|
||||
actual,
|
||||
tight_pattern(level, w, h),
|
||||
"budget {} level {level}",
|
||||
budget.max_bytes()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn staged_and_direct_uploads_produce_the_same_texels() {
|
||||
let gpu = context();
|
||||
let desc = Rgba8TextureDesc::new(16, 9, 5).unwrap();
|
||||
let levels = padded_levels(desc, 0);
|
||||
let mips = mip_views(&levels, 0);
|
||||
let direct = MetalRgba8Texture::upload(gpu.device(), desc, &mips).unwrap();
|
||||
let budget = StagingBudget::new(16 * 4 * 2).unwrap();
|
||||
let (staged, _) =
|
||||
MetalRgba8Texture::upload_staged(gpu.device(), gpu.queue(), desc, &mips, budget).unwrap();
|
||||
for level in 0..desc.mips {
|
||||
let (w, h) = desc.mip_extent(level).unwrap();
|
||||
let expected = tight_pattern(level, w, h);
|
||||
assert_eq!(
|
||||
direct.read_back(gpu.device(), gpu.queue(), level).unwrap(),
|
||||
expected
|
||||
);
|
||||
assert_eq!(
|
||||
staged.read_back(gpu.device(), gpu.queue(), level).unwrap(),
|
||||
expected
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn staged_upload_handles_a_single_texel() {
|
||||
let gpu = context();
|
||||
let desc = Rgba8TextureDesc::new(1, 1, 1).unwrap();
|
||||
let texel = pattern_texel(0, 0, 0);
|
||||
let mips = [Rgba8MipLevel::new_packed(0, 1, 1, &texel)];
|
||||
let budget = StagingBudget::new(4).unwrap();
|
||||
let (texture, report) =
|
||||
MetalRgba8Texture::upload_staged(gpu.device(), gpu.queue(), desc, &mips, budget).unwrap();
|
||||
assert_eq!((report.submissions, report.peak_staging_bytes), (1, 4));
|
||||
assert_eq!(
|
||||
texture.read_back(gpu.device(), gpu.queue(), 0).unwrap(),
|
||||
texel
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn staged_upload_rejects_bad_input_before_touching_the_gpu() {
|
||||
let gpu = context();
|
||||
let desc = Rgba8TextureDesc::new(8, 4, 2).unwrap();
|
||||
let levels = padded_levels(desc, 0);
|
||||
let mips = mip_views(&levels, 0);
|
||||
let small = StagingBudget::new(28).unwrap();
|
||||
let error = MetalRgba8Texture::upload_staged(gpu.device(), gpu.queue(), desc, &mips, small)
|
||||
.unwrap_err();
|
||||
assert!(!error.is_capability_unavailable());
|
||||
assert!(
|
||||
error.to_string().contains("smaller than one 32-byte row"),
|
||||
"{error}"
|
||||
);
|
||||
let budget = StagingBudget::new(1024).unwrap();
|
||||
let missing =
|
||||
MetalRgba8Texture::upload_staged(gpu.device(), gpu.queue(), desc, &mips[..1], budget)
|
||||
.unwrap_err();
|
||||
assert!(
|
||||
missing.to_string().contains("mip level 1 is missing"),
|
||||
"{missing}"
|
||||
);
|
||||
|
||||
// A Private texture refuses CPU writes instead of failing inside Metal.
|
||||
let (texture, _) =
|
||||
MetalRgba8Texture::upload_staged(gpu.device(), gpu.queue(), desc, &mips, budget).unwrap();
|
||||
let refused = texture.upload_mip(&mips[0]).unwrap_err();
|
||||
assert!(refused.to_string().contains("Private-storage"), "{refused}");
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
use xenora_shader::{Architecture, PIXEL_ENTRY_POINT, VERTEX_ENTRY_POINT, compile_graphics};
|
||||
use xenora_texture::{Bc1Upload, Bc1UploadDesc, SamplerDesc, decode_bc1};
|
||||
|
||||
use super::{context, native};
|
||||
|
||||
/// The translated `image_sample_lz` pixel stage samples a native BC1
|
||||
/// texture bound by `render_rgba8_sampled_bc1`. Each of the 8×8 texture's
|
||||
/// four blocks selects only its two endpoints, which expand exactly to 0 or
|
||||
/// 255, so the image is known without a decoder: selector 1 (the second
|
||||
/// endpoint) where `x == 0 || y == 3` within a block, else selector 0.
|
||||
#[test]
|
||||
fn translated_image_sample_lz_reads_bound_bc1_texture() {
|
||||
let blocks: [[u8; 8]; 4] = [
|
||||
[0x00, 0xF8, 0x1F, 0x00, 0x01, 0x01, 0x01, 0x55], // red, blue
|
||||
[0xE0, 0x07, 0x00, 0x00, 0x01, 0x01, 0x01, 0x55], // green, black
|
||||
[0xFF, 0xFF, 0x1F, 0xF8, 0x01, 0x01, 0x01, 0x55], // white, magenta
|
||||
[0xE0, 0xFF, 0xFF, 0x07, 0x01, 0x01, 0x01, 0x55], // yellow, cyan
|
||||
];
|
||||
let endpoints: [[[u8; 4]; 2]; 4] = [
|
||||
[[255, 0, 0, 255], [0, 0, 255, 255]],
|
||||
[[0, 255, 0, 255], [0, 0, 0, 255]],
|
||||
[[255, 255, 255, 255], [255, 0, 255, 255]],
|
||||
[[255, 255, 0, 255], [0, 255, 255, 255]],
|
||||
];
|
||||
let mut expected = Vec::new();
|
||||
for y in 0..8 {
|
||||
for x in 0..8 {
|
||||
let selector = usize::from(x % 4 == 0 || y % 4 == 3);
|
||||
expected.extend(endpoints[(y / 4) * 2 + x / 4][selector]);
|
||||
}
|
||||
}
|
||||
for (index, block) in blocks.into_iter().enumerate() {
|
||||
let (bx, by) = (index % 2 * 4, index / 2 * 4);
|
||||
for (i, texel) in decode_bc1(block).iter().enumerate() {
|
||||
let at = ((by + i / 4) * 8 + bx + i % 4) * 4;
|
||||
assert_eq!(texel, &expected[at..at + 4], "decoder, block {index}");
|
||||
}
|
||||
}
|
||||
|
||||
let ps: Vec<u8> = [
|
||||
&[0x00, 0x00, 0x08, 0xc8][..], // v_interp_p1_f32 v2, v0, attr0.x
|
||||
&[0x01, 0x00, 0x09, 0xc8], // v_interp_p2_f32 v2, v1, attr0.x
|
||||
&[0x00, 0x01, 0x0c, 0xc8], // v_interp_p1_f32 v3, v0, attr0.y
|
||||
&[0x01, 0x01, 0x0d, 0xc8], // v_interp_p2_f32 v3, v1, attr0.y
|
||||
&[0x08, 0x0f, 0x9c, 0xf0, 0x02, 0x04, 0x40, 0x00], // image_sample_lz
|
||||
&[0x0f, 0x18, 0x00, 0xf8, 0x04, 0x05, 0x06, 0x07], // exp mrt0
|
||||
&[0x00, 0x00, 0x81, 0xbf], // s_endpgm
|
||||
]
|
||||
.concat();
|
||||
let compiled = compile_graphics(
|
||||
Architecture::Gfx1030,
|
||||
include_bytes!("../../../../fixtures/rdna2/x9-varying-vs.bin"),
|
||||
&ps,
|
||||
)
|
||||
.expect("compile translated image_sample_lz shader");
|
||||
let gpu = context();
|
||||
let upload = Bc1Upload::new(
|
||||
blocks.as_flattened(),
|
||||
Bc1UploadDesc {
|
||||
width: 8,
|
||||
height: 8,
|
||||
mips: 1,
|
||||
layers: 1,
|
||||
format: 1,
|
||||
usage: 1,
|
||||
row_pitch: 16,
|
||||
slice_pitch: 32,
|
||||
},
|
||||
)
|
||||
.expect("valid BC1 upload");
|
||||
let sampler = native(xenora_metal::sampler::MetalSampler::new(
|
||||
gpu.device(),
|
||||
SamplerDesc::nearest_clamp(),
|
||||
));
|
||||
// Pixel (x, y) of the 8×8 target samples uv ((x + 0.5) / 8, (y + 0.5) / 8).
|
||||
let positions = [
|
||||
[-1.0, -1.0, 0.5, 1.0],
|
||||
[3.0, -1.0, 0.5, 1.0],
|
||||
[-1.0, 3.0, 0.5, 1.0],
|
||||
];
|
||||
let uvs = [
|
||||
[0.0, 1.0, 0.0, 1.0],
|
||||
[2.0, 1.0, 0.0, 1.0],
|
||||
[0.0, -1.0, 0.0, 1.0],
|
||||
];
|
||||
let pixels = native(gpu.render_rgba8_sampled_bc1(
|
||||
&compiled.msl,
|
||||
[VERTEX_ENTRY_POINT, PIXEL_ENTRY_POINT],
|
||||
&positions,
|
||||
&uvs,
|
||||
[8, 8],
|
||||
[19, 43, 93, 251],
|
||||
&upload,
|
||||
&sampler,
|
||||
));
|
||||
assert_eq!(pixels, expected);
|
||||
}
|
||||
@@ -26,6 +26,8 @@ mod texture_bc_alpha;
|
||||
mod texture_bc_channel;
|
||||
#[path = "native/texture_sampling.rs"]
|
||||
mod texture_sampling;
|
||||
#[path = "native/translated_bc1.rs"]
|
||||
mod translated_bc1;
|
||||
#[path = "native/translated_render.rs"]
|
||||
mod translated_render;
|
||||
|
||||
|
||||
+74
-12
@@ -57,6 +57,8 @@ pub enum Op {
|
||||
MoveScalar(u8, u8),
|
||||
/// VOPC 32-bit integer compare writing the Wave32 mask to `vcc_lo`.
|
||||
Compare(Comparison, CompareSource, u8),
|
||||
/// VOP3A integer compare writing a Wave32 mask to SDST.
|
||||
CompareVop3(u8, Comparison, CompareSource, u8),
|
||||
/// VOPC 16- or 64-bit integer compare writing the Wave32 mask to
|
||||
/// `vcc_lo`. For 64-bit forms a `Vector` or `Scalar` source and VSRC1 name
|
||||
/// the low register of a pair.
|
||||
@@ -187,6 +189,8 @@ pub enum BranchCondition {
|
||||
SccZero,
|
||||
/// Take the branch when the low half of VCC is clear.
|
||||
VccZero,
|
||||
/// Take the branch when the low half of VCC is nonzero.
|
||||
VccNonzero,
|
||||
/// Take the branch when the low half of EXEC is clear.
|
||||
ExecZero,
|
||||
}
|
||||
@@ -719,7 +723,13 @@ pub fn decode(code: &[u8]) -> Result<Vec<DecodedInstruction>, ReferenceError> {
|
||||
left_length.max(right_length),
|
||||
)
|
||||
}
|
||||
[lo, hi, opcode @ (0x82 | 0x84 | 0x86 | 0x88), 0xbf, ..] => {
|
||||
[
|
||||
lo,
|
||||
hi,
|
||||
opcode @ (0x82 | 0x84 | 0x86 | 0x87 | 0x88),
|
||||
0xbf,
|
||||
..,
|
||||
] => {
|
||||
let words = i16::from_le_bytes([*lo, *hi]);
|
||||
let words = usize::try_from(words).map_err(|_| error(offset, "backward branch"))?;
|
||||
(
|
||||
@@ -728,6 +738,7 @@ pub fn decode(code: &[u8]) -> Result<Vec<DecodedInstruction>, ReferenceError> {
|
||||
condition: match opcode {
|
||||
0x84 => BranchCondition::SccZero,
|
||||
0x86 => BranchCondition::VccZero,
|
||||
0x87 => BranchCondition::VccNonzero,
|
||||
0x88 => BranchCondition::ExecZero,
|
||||
_ => BranchCondition::Always,
|
||||
},
|
||||
@@ -755,9 +766,50 @@ pub fn decode(code: &[u8]) -> Result<Vec<DecodedInstruction>, ReferenceError> {
|
||||
let src1 = (second >> 1) | ((third & 1) << 7);
|
||||
(Op::Vector(kind, dst, *first, src1), 4)
|
||||
}
|
||||
[dst, 0, 0x25, 0xd5, lo, middle, hi @ 2..=3, 0x02, ..] if middle & 1 == 1 => {
|
||||
// Guide §§12.7.1, 12.9.1, 12.12 and 13.3.4: VOP3A extends
|
||||
// VOP2 by 0x100 and preserves the VOPC opcode. This subset
|
||||
// fixes unused SRC2 to inline 0 and excludes FP ABS/NEG/OMOD,
|
||||
// halfword OP_SEL, and CLAMP (integer saturation or FP compare
|
||||
// exceptions, §6.5).
|
||||
[
|
||||
dst,
|
||||
0,
|
||||
op,
|
||||
tag @ (0xd4 | 0xd5),
|
||||
lo,
|
||||
middle,
|
||||
hi @ 2..=3,
|
||||
0x02,
|
||||
..,
|
||||
] if middle & 1 != 0 => {
|
||||
let src0 = CompareSource::Vector(*lo);
|
||||
let src1 = (middle >> 1) | ((hi & 1) << 7);
|
||||
(Op::Add(*dst, *lo, src1), 8)
|
||||
match tag {
|
||||
0xd4 if matches!(op, 128..=135 | 192..=199) && *dst <= 106 => (
|
||||
Op::CompareVop3(
|
||||
*dst,
|
||||
Comparison {
|
||||
offset: op & 7,
|
||||
signed: *op < 192,
|
||||
},
|
||||
src0,
|
||||
src1,
|
||||
),
|
||||
8,
|
||||
),
|
||||
0xd5 if *op == 37 => (Op::Add(*dst, *lo, src1), 8),
|
||||
0xd5 => (
|
||||
Op::VectorInteger(
|
||||
VectorInteger::from_opcode(*op)
|
||||
.ok_or_else(|| error(offset, "unsupported VOP3 opcode"))?,
|
||||
*dst,
|
||||
src0,
|
||||
src1,
|
||||
),
|
||||
8,
|
||||
),
|
||||
_ => return Err(error(offset, "unsupported VOP3 opcode or destination")),
|
||||
}
|
||||
}
|
||||
// VOPC (bits 31-25 = 0b0111110): SRC0 bits 0-8, VSRC1 bits 9-16, OP bits 17-24.
|
||||
[lo, packed, upper, tag @ 0x7c..=0x7d, tail @ ..]
|
||||
@@ -1434,13 +1486,16 @@ fn execute_wave(program: &[DecodedInstruction], input: &[u32]) -> Result<Vec<u32
|
||||
}
|
||||
}
|
||||
// RDNA 2 ISA section 3.9: VCC[n] = EXEC[n] & test(n), fully written.
|
||||
Op::Compare(..) | Op::WideCompare(..) => {
|
||||
let (comparison, width, src0, src1) = match op {
|
||||
Op::Compare(..) | Op::WideCompare(..) | Op::CompareVop3(..) => {
|
||||
let (dst, comparison, width, src0, src1) = match op {
|
||||
Op::Compare(comparison, src0, src1) => {
|
||||
(comparison, CompareWidth::Word, src0, src1)
|
||||
(VCC_LO, comparison, CompareWidth::Word, src0, src1)
|
||||
}
|
||||
Op::CompareVop3(dst, comparison, src0, src1) => {
|
||||
(usize::from(dst), comparison, CompareWidth::Word, src0, src1)
|
||||
}
|
||||
Op::WideCompare(comparison, width, src0, src1) => {
|
||||
(comparison, width, src0, src1)
|
||||
(VCC_LO, comparison, width, src0, src1)
|
||||
}
|
||||
_ => unreachable!(),
|
||||
};
|
||||
@@ -1501,18 +1556,24 @@ fn execute_wave(program: &[DecodedInstruction], input: &[u32]) -> Result<Vec<u32
|
||||
}
|
||||
}
|
||||
}
|
||||
scalars[VCC_LO] = Some(mask);
|
||||
scalars[VCC_HI] = None;
|
||||
lane_derived_vcc = exec != 0;
|
||||
scalars[dst] = Some(mask);
|
||||
if dst == VCC_LO {
|
||||
scalars[VCC_HI] = None;
|
||||
lane_derived_vcc = exec != 0;
|
||||
}
|
||||
}
|
||||
Op::Branch {
|
||||
target: destination,
|
||||
condition,
|
||||
} => {
|
||||
if condition == BranchCondition::VccZero && scalars[VCC_LO].is_none() {
|
||||
let tests_vcc = matches!(
|
||||
condition,
|
||||
BranchCondition::VccZero | BranchCondition::VccNonzero
|
||||
);
|
||||
if tests_vcc && scalars[VCC_LO].is_none() {
|
||||
return Err(error(offset, "branch with uninitialized VCC_LO"));
|
||||
}
|
||||
if condition == BranchCondition::VccZero && lane_derived_vcc {
|
||||
if tests_vcc && lane_derived_vcc {
|
||||
check_runtime_region(
|
||||
&program[position + 1..],
|
||||
destination,
|
||||
@@ -1529,6 +1590,7 @@ fn execute_wave(program: &[DecodedInstruction], input: &[u32]) -> Result<Vec<u32
|
||||
!scc.ok_or_else(|| error(offset, "branch with uninitialized SCC"))?
|
||||
}
|
||||
BranchCondition::VccZero => scalars[VCC_LO] == Some(0),
|
||||
BranchCondition::VccNonzero => scalars[VCC_LO] != Some(0),
|
||||
BranchCondition::ExecZero => exec == 0,
|
||||
};
|
||||
if take_branch {
|
||||
|
||||
+115
-35
@@ -120,6 +120,10 @@ enum Op {
|
||||
/// The value is wave-uniform; every thread computes it for its own wave.
|
||||
LaneMask {
|
||||
op: VectorCompareOp,
|
||||
/// Assembly name of the decoded encoding (`_e32` or `_e64`).
|
||||
name: &'static str,
|
||||
/// The explicit SGPR destination of the VOP3A encoding (IR text only).
|
||||
sdst: Option<usize>,
|
||||
src0: Value,
|
||||
src1: Value,
|
||||
high: Option<(Value, Value)>,
|
||||
@@ -600,11 +604,18 @@ pub fn compile(architecture: Architecture, bytes: &[u8]) -> Result<CompiledShade
|
||||
}
|
||||
Op::LaneMask {
|
||||
op,
|
||||
name,
|
||||
sdst,
|
||||
src0,
|
||||
src1,
|
||||
high,
|
||||
exec,
|
||||
} => {
|
||||
let target = match sdst {
|
||||
None => String::new(),
|
||||
Some(VCC_LO) => " -> vcc_lo".to_string(),
|
||||
Some(register) => format!(" -> s{register}"),
|
||||
};
|
||||
let (left, right) = if let Some((hi0, hi1)) = high {
|
||||
(format!("{src0}:{hi0}"), format!("{src1}:{hi1}"))
|
||||
} else {
|
||||
@@ -612,8 +623,7 @@ pub fn compile(architecture: Architecture, bytes: &[u8]) -> Result<CompiledShade
|
||||
};
|
||||
let _ = writeln!(
|
||||
ir,
|
||||
"{offset:04x}: {dest} = wave.mask {} {left}, {right} exec=0x{exec:08x}",
|
||||
op.assembly_name()
|
||||
"{offset:04x}: {dest} = wave.mask {name} {left}, {right}{target} exec=0x{exec:08x}"
|
||||
);
|
||||
let inputs = if matches!(
|
||||
op.relation(),
|
||||
@@ -721,6 +731,13 @@ fn decode_fixture(
|
||||
xenora_decoder::decode(architecture, bytes).map_err(CompileError::Decode)
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
enum ScalarValue {
|
||||
Uninitialized,
|
||||
Known(u32),
|
||||
RuntimeMask,
|
||||
}
|
||||
|
||||
fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, Op)>, CompileError> {
|
||||
let mut operations = Vec::new();
|
||||
let mut registers = [None::<Value>; 256];
|
||||
@@ -728,12 +745,12 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
let mut pending_load = None;
|
||||
let mut stored = false;
|
||||
let mut store_pending = false;
|
||||
let mut scalars = [None; 128];
|
||||
let mut scalars = [ScalarValue::Uninitialized; 128];
|
||||
let mut exec = u32::MAX; // The fixture starts with full Wave32 EXEC.
|
||||
scalars[126] = Some(exec);
|
||||
scalars[126] = ScalarValue::Known(exec);
|
||||
let mut scc = None;
|
||||
let mut skip_before = 0;
|
||||
// Set while VCC_LO holds a lane-derived compare mask (scalars[VCC_LO] is then None).
|
||||
// VCC_LO can forward a lane-derived mask to its supported runtime consumers.
|
||||
let mut lane_vcc: Option<Value> = None;
|
||||
// An open runtime `s_cbranch_vccz` region: its end, mask and the VGPRs at the branch.
|
||||
let mut region: Option<(usize, Value, [Option<Value>; 256])> = None;
|
||||
@@ -865,11 +882,15 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
}
|
||||
let read_scalar = |source| match source {
|
||||
ScalarSource::Immediate(value) => Ok(value),
|
||||
ScalarSource::Register(register) => scalars
|
||||
.get(usize::from(register))
|
||||
.copied()
|
||||
.flatten()
|
||||
.ok_or_else(|| error("scalar source has no known value")),
|
||||
ScalarSource::Register(register) => match scalars.get(usize::from(register)) {
|
||||
Some(ScalarValue::Known(value)) => Ok(*value),
|
||||
Some(ScalarValue::RuntimeMask) => Err(error(
|
||||
"scalar source reads a runtime-only SGPR compare mask",
|
||||
)),
|
||||
Some(ScalarValue::Uninitialized) | None => {
|
||||
Err(error("scalar source has no known value"))
|
||||
}
|
||||
},
|
||||
};
|
||||
let read_vector = |source, operations: &mut Vec<_>, facts: &mut Vec<_>| {
|
||||
Ok(match source {
|
||||
@@ -877,8 +898,10 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
VectorSource::Scalar(register) if usize::from(register) == VCC_LO => {
|
||||
match (lane_vcc, scalars[VCC_LO]) {
|
||||
(Some(mask), _) => mask,
|
||||
(None, Some(bits)) => constant(operations, facts, offset, bits),
|
||||
(None, None) => {
|
||||
(None, ScalarValue::Known(bits)) => {
|
||||
constant(operations, facts, offset, bits)
|
||||
}
|
||||
(None, _) => {
|
||||
return Err(error("vector ALU reads uninitialized VCC_LO"));
|
||||
}
|
||||
}
|
||||
@@ -896,8 +919,8 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
Instruction::VectorAlu { op, .. } if op.writes_vcc() => {
|
||||
// Guide 3.9: inactive lanes contribute zero to carry-out.
|
||||
lane_vcc = None;
|
||||
scalars[VCC_LO] = Some(0);
|
||||
scalars[VCC_HI] = None;
|
||||
scalars[VCC_LO] = ScalarValue::Known(0);
|
||||
scalars[VCC_HI] = ScalarValue::Uninitialized;
|
||||
continue;
|
||||
}
|
||||
Instruction::MoveB32 { .. }
|
||||
@@ -918,6 +941,19 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
{
|
||||
return Err(error("vector memory requires full Wave32 EXEC"));
|
||||
}
|
||||
if let Instruction::BufferLoadDword { resource, .. }
|
||||
| Instruction::BufferStoreDword { resource, .. } = instruction.instruction
|
||||
{
|
||||
let start = usize::from(resource);
|
||||
if scalars[start..start + 4]
|
||||
.iter()
|
||||
.any(|value| matches!(value, ScalarValue::RuntimeMask))
|
||||
{
|
||||
return Err(error(
|
||||
"resource descriptor reads a runtime-only SGPR compare mask",
|
||||
));
|
||||
}
|
||||
}
|
||||
let next = Value(operations.len());
|
||||
let (dest, operation) = match instruction.instruction {
|
||||
Instruction::BufferLoadDword { data, .. } => {
|
||||
@@ -1033,7 +1069,7 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
let slot = scalars
|
||||
.get_mut(usize::from(dst))
|
||||
.ok_or_else(|| error("scalar destination exceeds the fixture register file"))?;
|
||||
*slot = Some(value);
|
||||
*slot = ScalarValue::Known(value);
|
||||
continue;
|
||||
}
|
||||
Instruction::ScalarUnary { op, dst, src } => {
|
||||
@@ -1045,7 +1081,7 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
let slot = scalars
|
||||
.get_mut(usize::from(dst))
|
||||
.ok_or_else(|| error("scalar destination exceeds the fixture register file"))?;
|
||||
*slot = Some(value);
|
||||
*slot = ScalarValue::Known(value);
|
||||
if let Some(flag) = flag {
|
||||
scc = Some(flag);
|
||||
}
|
||||
@@ -1070,7 +1106,7 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
let slot = scalars
|
||||
.get_mut(usize::from(dst))
|
||||
.ok_or_else(|| error("scalar destination exceeds the fixture register file"))?;
|
||||
*slot = Some(value);
|
||||
*slot = ScalarValue::Known(value);
|
||||
if let Some(flag) = flag {
|
||||
scc = Some(flag);
|
||||
}
|
||||
@@ -1094,13 +1130,21 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
.get_mut(usize::from(dst))
|
||||
.ok_or_else(|| error("scalar destination exceeds the fixture register file"))?;
|
||||
let old = if op.reads_dst() {
|
||||
slot.ok_or_else(|| error("SOPK reads an uninitialized SGPR"))?
|
||||
match *slot {
|
||||
ScalarValue::Known(value) => value,
|
||||
ScalarValue::RuntimeMask => {
|
||||
return Err(error("SOPK reads a runtime-only SGPR compare mask"));
|
||||
}
|
||||
ScalarValue::Uninitialized => {
|
||||
return Err(error("SOPK reads an uninitialized SGPR"));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
0
|
||||
};
|
||||
let (value, flag) = op.evaluate(old, simm16, scc_in);
|
||||
if let Some(value) = value {
|
||||
*slot = Some(value);
|
||||
*slot = ScalarValue::Known(value);
|
||||
}
|
||||
if let Some(flag) = flag {
|
||||
scc = Some(flag);
|
||||
@@ -1112,11 +1156,36 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
continue;
|
||||
}
|
||||
// docs/shaders/vector-compare.md sections 3 and 5.
|
||||
Instruction::VectorCompare { op, src0, src1 } => {
|
||||
// Both encodings share the Wave32 lane mask implementation.
|
||||
compare @ (Instruction::VectorCompare { .. }
|
||||
| Instruction::VectorCompareVop3 { .. }) => {
|
||||
let (op, name, explicit, sdst, src0, src1) = match compare {
|
||||
Instruction::VectorCompare { op, src0, src1 } => {
|
||||
(op, op.assembly_name(), false, VCC_LO, src0, src1)
|
||||
}
|
||||
Instruction::VectorCompareVop3 {
|
||||
op,
|
||||
sdst,
|
||||
src0,
|
||||
src1,
|
||||
} => (
|
||||
op.base(),
|
||||
op.assembly_name(),
|
||||
true,
|
||||
usize::from(sdst),
|
||||
VectorSource::Register(src0),
|
||||
src1,
|
||||
),
|
||||
_ => unreachable!("only vector compares reach this arm"),
|
||||
};
|
||||
if exec == 0 {
|
||||
scalars[VCC_HI] = None;
|
||||
scalars[VCC_LO] = Some(0);
|
||||
lane_vcc = None;
|
||||
if sdst == VCC_LO {
|
||||
scalars[VCC_HI] = ScalarValue::Uninitialized;
|
||||
scalars[VCC_LO] = ScalarValue::Known(0);
|
||||
lane_vcc = None;
|
||||
} else {
|
||||
scalars[sdst] = ScalarValue::RuntimeMask;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
let constant =
|
||||
@@ -1148,8 +1217,10 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
VectorSource::Scalar(register) if usize::from(register) == VCC_LO => {
|
||||
match (lane_vcc, scalars[VCC_LO]) {
|
||||
(Some(mask), _) => mask,
|
||||
(None, Some(bits)) => constant(&mut operations, &mut facts, bits),
|
||||
(None, None) => {
|
||||
(None, ScalarValue::Known(bits)) => {
|
||||
constant(&mut operations, &mut facts, bits)
|
||||
}
|
||||
(None, _) => {
|
||||
return Err(error("compare reads uninitialized VCC_LO"));
|
||||
}
|
||||
}
|
||||
@@ -1166,6 +1237,8 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
offset,
|
||||
Op::LaneMask {
|
||||
op,
|
||||
name,
|
||||
sdst: explicit.then_some(sdst),
|
||||
src0,
|
||||
src1,
|
||||
high,
|
||||
@@ -1173,9 +1246,13 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
},
|
||||
));
|
||||
facts.push(KnownBits::UNKNOWN);
|
||||
scalars[VCC_LO] = None;
|
||||
scalars[VCC_HI] = None;
|
||||
lane_vcc = Some(mask);
|
||||
if sdst == VCC_LO {
|
||||
scalars[VCC_LO] = ScalarValue::Uninitialized;
|
||||
scalars[VCC_HI] = ScalarValue::Uninitialized;
|
||||
lane_vcc = Some(mask);
|
||||
} else {
|
||||
scalars[sdst] = ScalarValue::RuntimeMask;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
Instruction::Branch { .. }
|
||||
@@ -1222,9 +1299,12 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
error("conditional branch reads uninitialized SCC")
|
||||
})?,
|
||||
SoppControlOp::BranchVccZero => {
|
||||
scalars[106].ok_or_else(|| {
|
||||
error("conditional branch reads uninitialized VCC_LO")
|
||||
})? == 0
|
||||
let ScalarValue::Known(bits) = scalars[VCC_LO] else {
|
||||
return Err(error(
|
||||
"conditional branch reads uninitialized VCC_LO",
|
||||
));
|
||||
};
|
||||
bits == 0
|
||||
}
|
||||
SoppControlOp::BranchExecZero => exec == 0,
|
||||
SoppControlOp::WaitLoad | SoppControlOp::EndProgram => {
|
||||
@@ -1259,10 +1339,10 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
VectorLowering::Vcc(primitive) => {
|
||||
let mask = match (lane_vcc, scalars[VCC_LO]) {
|
||||
(Some(mask), _) => mask,
|
||||
(None, Some(bits)) => {
|
||||
(None, ScalarValue::Known(bits)) => {
|
||||
constant(&mut operations, &mut facts, offset, bits)
|
||||
}
|
||||
(None, None) => {
|
||||
(None, _) => {
|
||||
return Err(error("vector ALU reads uninitialized VCC_LO"));
|
||||
}
|
||||
};
|
||||
@@ -1282,8 +1362,8 @@ fn lift(decoded: &[DecodedInstruction], code_len: usize) -> Result<Vec<(usize, O
|
||||
lane_vcc = Some(Value(operations.len()));
|
||||
operations.push((offset, Op::CarryMask { flag, exec }));
|
||||
facts.push(KnownBits::UNKNOWN);
|
||||
scalars[VCC_LO] = None;
|
||||
scalars[VCC_HI] = None;
|
||||
scalars[VCC_LO] = ScalarValue::Uninitialized;
|
||||
scalars[VCC_HI] = ScalarValue::Uninitialized;
|
||||
}
|
||||
(
|
||||
Some(dst),
|
||||
|
||||
@@ -14,6 +14,110 @@ fn compiles_original_fixture() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vop3_compare_to_vcc_lo_drives_a_runtime_vccz_branch() {
|
||||
let code: Vec<_> = [
|
||||
0x7e02_0281u32, // v_mov_b32_e32 v1, 1
|
||||
0x7e04_0282, // v_mov_b32_e32 v2, 2
|
||||
0xd4c2_006a, // v_cmp_eq_u32_e64 vcc_lo, v1, v2
|
||||
0x0202_0501,
|
||||
0xbf86_0001, // s_cbranch_vccz 1
|
||||
0x7e02_0302, // v_mov_b32_e32 v1, v2
|
||||
]
|
||||
.into_iter()
|
||||
.flat_map(u32::to_le_bytes)
|
||||
.chain(FIXTURE[28..].iter().copied())
|
||||
.collect();
|
||||
let shader = compile(Architecture::Gfx1030, &code).unwrap();
|
||||
assert!(
|
||||
shader
|
||||
.disassembly
|
||||
.contains("v_cmp_eq_u32_e64 vcc_lo, v1, v2")
|
||||
);
|
||||
assert!(shader.ir.contains("0008: t2 = wave.mask"));
|
||||
assert!(shader.ir.contains("0010: branch.vccz t2 -> 0x0018"));
|
||||
assert!(shader.ir.contains("join.vccz t2"));
|
||||
assert!(shader.msl.contains("lane_index >= grid"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vop3_compare_to_s4_rejects_later_scalar_reads() {
|
||||
for (setup, offset) in [
|
||||
(&[0x7e02_0281u32, 0x7e04_0282][..], 16), // Initialize both VGPRs.
|
||||
(&[0xbefe_0380][..], 12), // Empty EXEC. The VGPRs need not be initialized.
|
||||
] {
|
||||
let code: Vec<_> = setup
|
||||
.iter()
|
||||
.copied()
|
||||
.chain([
|
||||
0xd4c2_0004, // v_cmp_eq_u32_e64 s4, v1, v2
|
||||
0x0202_0501,
|
||||
0xbf06_8004, // s_cmp_eq_u32 s4, 0
|
||||
0xbefe_03c1, // s_mov_b32 exec_lo, -1
|
||||
0x7e02_0281, // v_mov_b32_e32 v1, 1
|
||||
])
|
||||
.flat_map(u32::to_le_bytes)
|
||||
.chain(FIXTURE[28..].iter().copied())
|
||||
.collect();
|
||||
let error = compile(Architecture::Gfx1030, &code).unwrap_err();
|
||||
assert!(
|
||||
matches!(
|
||||
error,
|
||||
CompileError::Verify {
|
||||
offset: actual,
|
||||
reason: "scalar source reads a runtime-only SGPR compare mask",
|
||||
} if actual == offset
|
||||
),
|
||||
"{error}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vop3_compare_mask_cannot_be_read_as_a_buffer_descriptor() {
|
||||
let code: Vec<_> = [
|
||||
0x7e02_0281u32, // v_mov_b32_e32 v1, 1
|
||||
0x7e04_0282, // v_mov_b32_e32 v2, 2
|
||||
0xd4c2_0004, // v_cmp_eq_u32_e64 s4, v1, v2
|
||||
0x0202_0501,
|
||||
]
|
||||
.into_iter()
|
||||
.flat_map(u32::to_le_bytes)
|
||||
.chain(FIXTURE[28..].iter().copied())
|
||||
.collect();
|
||||
assert!(matches!(
|
||||
compile(Architecture::Gfx1030, &code),
|
||||
Err(CompileError::Verify {
|
||||
offset: 16,
|
||||
reason: "resource descriptor reads a runtime-only SGPR compare mask",
|
||||
})
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vop3_compare_to_normal_sgpr_preserves_vcc_and_can_be_overwritten() {
|
||||
let code: Vec<_> = [
|
||||
0x7e02_0281u32, // v_mov_b32_e32 v1, 1
|
||||
0x7e04_0282, // v_mov_b32_e32 v2, 2
|
||||
0xbeea_0381, // s_mov_b32 vcc_lo, 1
|
||||
0xd4c2_0008, // v_cmp_eq_u32_e64 s8, v1, v2
|
||||
0x0202_0501,
|
||||
0xbf86_0001, // s_cbranch_vccz 1
|
||||
0xbe88_0381, // s_mov_b32 s8, 1
|
||||
0xbf06_8008, // s_cmp_eq_u32 s8, 0
|
||||
]
|
||||
.into_iter()
|
||||
.flat_map(u32::to_le_bytes)
|
||||
.chain(FIXTURE[28..].iter().copied())
|
||||
.collect();
|
||||
let shader = compile(Architecture::Gfx1030, &code).unwrap();
|
||||
assert!(
|
||||
shader
|
||||
.ir
|
||||
.contains("0014: branch.uniform 0x001c taken=false")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn load_wait_is_required_before_using_loaded_data() {
|
||||
let mut code = FIXTURE.to_vec();
|
||||
@@ -364,6 +468,20 @@ fn vector_integer_forms_lower_to_per_lane_templates() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vop3_integer_forms_lower_to_per_lane_templates() {
|
||||
let code = include_bytes!("../../../fixtures/rdna2/vop3-integer.bin");
|
||||
let compiled = compile(Architecture::Gfx1030, code).unwrap();
|
||||
assert_eq!(
|
||||
compiled.ir,
|
||||
include_str!("../../../fixtures/golden/vop3-integer.ir")
|
||||
);
|
||||
assert_eq!(
|
||||
compiled.msl,
|
||||
include_str!("../../../fixtures/golden/vop3-integer.metal")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vector_f_and_t_compares_lower_to_operand_free_wave_masks() {
|
||||
let code = include_bytes!("../../../fixtures/rdna2/vector-compare-ft.bin");
|
||||
@@ -392,6 +510,20 @@ fn vector_compares_lower_to_per_thread_wave_masks_and_selects() {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vop3_compare_forms_lower_to_wave_masks() {
|
||||
let code = include_bytes!("../../../fixtures/rdna2/vop3-compare.bin");
|
||||
let compiled = compile(Architecture::Gfx1030, code).unwrap();
|
||||
assert_eq!(
|
||||
compiled.ir,
|
||||
include_str!("../../../fixtures/golden/vop3-compare.ir")
|
||||
);
|
||||
assert_eq!(
|
||||
compiled.msl,
|
||||
include_str!("../../../fixtures/golden/vop3-compare.metal")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vector_vcc_fixture_matches_ir_and_msl_goldens() {
|
||||
let code = include_bytes!("../../../fixtures/rdna2/vector-vcc.bin");
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="530" height="185" viewBox="0 0 530 185" role="img" aria-labelledby="title description">
|
||||
<title id="title">Xenora · recorded progress</title>
|
||||
<desc id="description">Decoded gfx1030 forms: 158 of 158. Accepted Metal forms · Apple M5: 18 of 158. Accepted guest milestones · X1–X4: 4 of 4</desc>
|
||||
<desc id="description">Decoded gfx1030 forms: 185 of 185. Accepted Metal forms · Apple M5: 18 of 185. Accepted guest milestones · X1–X4: 4 of 4</desc>
|
||||
<rect x="1" y="1" width="528" height="183" rx="10" fill="#18212a" stroke="#516171"/>
|
||||
<g font-family="system-ui,sans-serif" fill="#eaf0f5">
|
||||
<text x="20" y="29" font-size="13" font-weight="700">RECORDED FIXTURE PROGRESS</text>
|
||||
<text x="20" y="58" font-size="13">Decoded gfx1030 forms</text>
|
||||
<text x="510" y="58" font-size="13" text-anchor="end">158 / 158</text>
|
||||
<text x="510" y="58" font-size="13" text-anchor="end">185 / 185</text>
|
||||
<rect x="20" y="65" width="490" height="4" rx="2" fill="#3c4a58"/>
|
||||
<rect x="20" y="65" width="490.00" height="4" rx="2" fill="#88c6bd"/>
|
||||
<text x="20" y="96" font-size="13">Accepted Metal forms · Apple M5</text>
|
||||
<text x="510" y="96" font-size="13" text-anchor="end">18 / 158</text>
|
||||
<text x="510" y="96" font-size="13" text-anchor="end">18 / 185</text>
|
||||
<rect x="20" y="103" width="490" height="4" rx="2" fill="#3c4a58"/>
|
||||
<rect x="20" y="103" width="55.82" height="4" rx="2" fill="#88c6bd"/>
|
||||
<rect x="20" y="103" width="47.68" height="4" rx="2" fill="#88c6bd"/>
|
||||
<text x="20" y="134" font-size="13">Accepted guest milestones · X1–X4</text>
|
||||
<text x="510" y="134" font-size="13" text-anchor="end">4 / 4</text>
|
||||
<rect x="20" y="141" width="490" height="4" rx="2" fill="#3c4a58"/>
|
||||
|
||||
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
@@ -498,3 +498,47 @@ compare function. Colour and the stored depth are both read back.
|
||||
|
||||
These passes are checked on the GPU with Metal validation against expectations
|
||||
derived independently from the public semantics; synthetic fixtures only.
|
||||
|
||||
### Guest texture binding (descriptor tables)
|
||||
|
||||
`GraphicsContext` lets a guest command list sample one texture in the pixel
|
||||
stage through a D3D12-shaped binding. A draw samples only if a root signature
|
||||
is bound. Draws without one keep the flat-colour path. The supported subset
|
||||
is fixed. Anything outside it fails with `GraphicsError::Unsupported` when the
|
||||
object is created, or with an error at execution. A rejected draw never
|
||||
reaches the backend. Draws recorded before it in the same list have already
|
||||
run.
|
||||
|
||||
| Object | Supported |
|
||||
| --- | --- |
|
||||
| `create_descriptor_heap` | Shader-visible `CBV_SRV_UAV` (0) or `SAMPLER` (1) heaps of 1–64 descriptors. RTV, DSV and CPU-only heaps are unsupported. |
|
||||
| `create_committed_texture2d` | One level of `R8G8B8A8_UNORM` (28) or `BC1_UNORM` (71), 1–64 texels per side. BC1 sizes must be multiples of four. Rows are linear: 4 bytes per texel, or 8 bytes per 4×4 block. Xbox tiling is not handled. |
|
||||
| `create_shader_resource_view` | A `Texture2D` view of mip 0 of a single-level, single-slice 2D texture, in the resource's own format. |
|
||||
| `create_sampler` | Point filtering (`MIN_MAG_MIP_POINT`), clamp addressing on U, V and W, no LOD bias and a minimum LOD of 0. |
|
||||
| `create_root_signature` | Exactly two pixel-visibility descriptor tables, in either order: one with a single SRV range for `t0`, and one with a single sampler range for `s0` (one descriptor each, space 0). Root constants, root descriptors, CBV and UAV ranges, extra tables or ranges and static samplers are unsupported. |
|
||||
| `cmd_set_descriptor_heaps` | At most one heap of each type. |
|
||||
| `cmd_set_graphics_root_descriptor_table` | The base must be a GPU handle to a slot of the bound heap of the table's type. The slot must hold a descriptor when a draw reads it. Changing the heaps or binding a different root signature clears every table. Setting the same heaps or the same root signature again keeps them. |
|
||||
|
||||
Descriptor handles follow D3D12 pointer arithmetic: the heap start plus
|
||||
`index × GetDescriptorHandleIncrementSize` (32 here; guests must query the
|
||||
value). `offset` returns `None` rather than carry into the next heap. CPU and
|
||||
GPU handles are separate spaces. A textured draw is a `DrawInstanced` of
|
||||
one instance of three vertices with start instance 0, starting at any vertex. Zero vertices or
|
||||
instances draw nothing. The sampled texture must be in `COMMON` or a read-only state that includes
|
||||
`PIXEL_SHADER_RESOURCE`. The software reference draws at most 4096 pixels. Each vertex record holds a float4 position
|
||||
at byte 0 and a float4 texture coordinate at byte 16, with a stride of at
|
||||
least 32. Textured indexed draws are unsupported.
|
||||
|
||||
The native backend receives a `TexturedDraw` with the bound level and must
|
||||
bind it to fragment texture 0 and sampler 0, which are the `tex0` and `samp0` arguments of
|
||||
the translated `image_sample_lz` pixel stage. `NativeCompute::render_rgba8_sampled_bc1`
|
||||
binds a BC1 level natively for that purpose. The software reference has no
|
||||
clipping or depth test. A pixel is covered when its centre lies inside or on
|
||||
an edge of the triangle. The texture coordinate is interpolated affinely, so
|
||||
`w = 1` is required, and point sampled with
|
||||
`min(floor(clamp(u, 0, 1) × width), width − 1)`. It decodes BC1 with the
|
||||
spec-exact `xenora_texture::decode_bc1`. Apple's hardware rounds BC1's two
|
||||
interpolated palette entries differently (171/84 against 170/85, measured
|
||||
on an M5 Pro), so the tests use endpoint colours only. Pipeline
|
||||
state objects do not exist yet, so the backend, not the guest, chooses the
|
||||
pixel shader. These entry points are not yet wired to guest imports.
|
||||
@@ -17,6 +17,33 @@ The wider LLVM operand matrix exercises decoding only. ABI means application bin
|
||||
| `s_waitcnt vmcnt(0)` | SOPP, exact immediate `0x3f70`; other counters disabled by their maximum values (semantic registry) | 4 B | yes | yes | three-way passed | verified load wait | implemented | fixture verified | fixture verified |
|
||||
| `v_mov_b32_e32` | VOP1, VGPR destination, VGPR, normal SGPR (wave-uniform, known during translation), vcc_lo (known or a compare mask) or inline integer or literal source, plus the inline bit pattern for +1.0f | 4 or 8 B | yes | yes | three-way passed | constant or register value | implemented | fixture verified | fixture verified |
|
||||
| `v_add_nc_u32_e64` | VOP3, VGPR destination and two VGPR inputs, modifier fields clear, third source field encoded as inline zero | 8 B | yes | yes | three-way passed | MSL unsigned add | implemented | fixture verified | fixture verified |
|
||||
| `v_mul_i32_i24_e64` | VOP3A, Wave32; VGPR destination and two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; inactive lanes keep VDST; the operation of `v_mul_i32_i24_e32` | 8 B | yes | yes | three-way passed | per-thread typed integer template of the VOP2 form | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_mul_hi_i32_i24_e64` | VOP3A, Wave32; VGPR destination and two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; inactive lanes keep VDST; the operation of `v_mul_hi_i32_i24_e32` | 8 B | yes | yes | three-way passed | per-thread typed integer template of the VOP2 form | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_mul_u32_u24_e64` | VOP3A, Wave32; VGPR destination and two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; inactive lanes keep VDST; the operation of `v_mul_u32_u24_e32` | 8 B | yes | yes | three-way passed | per-thread typed integer template of the VOP2 form | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_mul_hi_u32_u24_e64` | VOP3A, Wave32; VGPR destination and two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; inactive lanes keep VDST; the operation of `v_mul_hi_u32_u24_e32` | 8 B | yes | yes | three-way passed | per-thread typed integer template of the VOP2 form | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_min_i32_e64` | VOP3A, Wave32; VGPR destination and two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; inactive lanes keep VDST; the operation of `v_min_i32_e32` | 8 B | yes | yes | three-way passed | per-thread typed integer template of the VOP2 form | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_max_i32_e64` | VOP3A, Wave32; VGPR destination and two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; inactive lanes keep VDST; the operation of `v_max_i32_e32` | 8 B | yes | yes | three-way passed | per-thread typed integer template of the VOP2 form | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_min_u32_e64` | VOP3A, Wave32; VGPR destination and two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; inactive lanes keep VDST; the operation of `v_min_u32_e32` | 8 B | yes | yes | three-way passed | per-thread typed integer template of the VOP2 form | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_max_u32_e64` | VOP3A, Wave32; VGPR destination and two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; inactive lanes keep VDST; the operation of `v_max_u32_e32` | 8 B | yes | yes | three-way passed | per-thread typed integer template of the VOP2 form | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_xnor_b32_e64` | VOP3A, Wave32; VGPR destination and two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; inactive lanes keep VDST; the operation of `v_xnor_b32_e32` | 8 B | yes | yes | three-way passed | per-thread typed integer template of the VOP2 form | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_sub_nc_u32_e64` | VOP3A, Wave32; VGPR destination and two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; inactive lanes keep VDST; the operation of `v_sub_nc_u32_e32` | 8 B | yes | yes | three-way passed | per-thread typed integer template of the VOP2 form | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_subrev_nc_u32_e64` | VOP3A, Wave32; VGPR destination and two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; inactive lanes keep VDST; the operation of `v_subrev_nc_u32_e32` | 8 B | yes | yes | three-way passed | per-thread typed integer template of the VOP2 form | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_cmp_lt_i32_e64` | VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_lt_i32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error | 8 B | yes | yes | three-way passed | per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_cmp_eq_i32_e64` | VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_eq_i32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error | 8 B | yes | yes | three-way passed | per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_cmp_le_i32_e64` | VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_le_i32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error | 8 B | yes | yes | three-way passed | per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_cmp_gt_i32_e64` | VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_gt_i32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error | 8 B | yes | yes | three-way passed | per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_cmp_ne_i32_e64` | VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_ne_i32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error | 8 B | yes | yes | three-way passed | per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_cmp_ge_i32_e64` | VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_ge_i32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error | 8 B | yes | yes | three-way passed | per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_cmp_f_i32_e64` | VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_f_i32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error | 8 B | yes | yes | three-way passed | per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_cmp_t_i32_e64` | VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_t_i32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error | 8 B | yes | yes | three-way passed | per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_cmp_lt_u32_e64` | VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_lt_u32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error | 8 B | yes | yes | three-way passed | per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_cmp_eq_u32_e64` | VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_eq_u32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error | 8 B | yes | yes | three-way passed | per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_cmp_le_u32_e64` | VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_le_u32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error | 8 B | yes | yes | three-way passed | per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_cmp_gt_u32_e64` | VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_gt_u32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error | 8 B | yes | yes | three-way passed | per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_cmp_ne_u32_e64` | VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_ne_u32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error | 8 B | yes | yes | three-way passed | per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_cmp_ge_u32_e64` | VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_ge_u32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error | 8 B | yes | yes | three-way passed | per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_cmp_f_u32_e64` | VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_f_u32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error | 8 B | yes | yes | three-way passed | per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `v_cmp_t_u32_e64` | VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_t_u32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error | 8 B | yes | yes | three-way passed | per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo | implemented | local known-answer test passed | local Apple M5 readback passed; acceptance pending |
|
||||
| `buffer_store_dword` | MUBUF, VGPR data/index, four normal SGPRs, `idxen`, zero offsets and remaining flags | 8 B | yes | yes | three-way passed | MSL store | implemented | fixture verified | fixture verified |
|
||||
| `s_waitcnt_vscnt null, 0` | SOPK, exact null source and zero immediate | 4 B | yes | yes | three-way passed | verified store wait | implemented | fixture verified | fixture verified |
|
||||
| `s_endpgm` | SOPP, zero immediate (semantic registry) | 4 B | yes | yes | three-way passed | verified termination | implemented | fixture verified | fixture verified |
|
||||
|
||||
@@ -32,11 +32,11 @@ acceptance remain outside the verified count. All results concern synthetic fixt
|
||||
| VINTRP | 3 | 0 | 0 | 2 | 0 | 0 | 0 | 0 | 0 |
|
||||
| VOP1 | 81 | 7 | 6 | 7 | 7 | 7 | 1 | 1 | 11 |
|
||||
| VOP2 | 47 | 24 | 22 | 24 | 24 | 24 | 7 | 7 | 11 |
|
||||
| VOP3 | 416 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 12 |
|
||||
| VOP3 | 416 | 28 | 28 | 28 | 28 | 28 | 1 | 1 | 17 |
|
||||
| VOP3P | 29 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| VOP3SDST | 10 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
|
||||
| VOPC | 190 | 28 | 44 | 44 | 44 | 44 | 0 | 0 | 9 |
|
||||
| **Total** | 1465 | 142 | 152 | 162 | 158 | 158 | 18 | 18 | 78 |
|
||||
| **Total** | 1465 | 169 | 179 | 189 | 185 | 185 | 18 | 18 | 83 |
|
||||
|
||||
## Unsupported operand variants
|
||||
|
||||
@@ -58,6 +58,7 @@ The table counts distinct variant names per family across registry operand rules
|
||||
| VOP2 | `vop2_vcc` | `src_exec`, `src_float_inline`, `src_m0`, `src_null`, `src_special`, `src_ttmp`, `src_vcc_hi` |
|
||||
| VOP2 | `vop2_vgpr` | `src_exec`, `src_float_inline`, `src_m0`, `src_null`, `src_special`, `src_ttmp`, `src_vcc_hi` |
|
||||
| VOP2 | `vop2_vgpr2` | `src_exec`, `src_float_inline`, `src_inline`, `src_literal`, `src_m0`, `src_null`, `src_sgpr`, `src_special`, `src_ttmp`, `src_vcc` |
|
||||
| VOP3 | `vop3_cmp_vgpr2` | `dst_exec`, `dst_m0`, `dst_null`, `dst_ttmp`, `dst_vcc_hi`, `modifiers`, `src2`, `src_exec`, `src_float_inline`, `src_inline`, `src_literal`, `src_m0`, `src_null`, `src_sgpr`, `src_special`, `src_ttmp`, `src_vcc` |
|
||||
| VOP3 | `vop3_vgpr2` | `modifiers`, `src2`, `src_exec`, `src_float_inline`, `src_inline`, `src_literal`, `src_m0`, `src_null`, `src_sgpr`, `src_special`, `src_ttmp`, `src_vcc` |
|
||||
| VOPC | `vopc_vcc` | `src_exec`, `src_float_inline`, `src_m0`, `src_null`, `src_special`, `src_ttmp`, `src_vcc_hi` |
|
||||
| VOPC | `vopc_vcc_half` | `src_exec`, `src_float_inline`, `src_literal`, `src_m0`, `src_null`, `src_special`, `src_ttmp`, `src_vcc_hi` |
|
||||
|
||||
@@ -48,20 +48,19 @@ file of its encoding (`rdna2/vop3.toml`) and has exactly these fields:
|
||||
| `of` | The `name` of the declared base form |
|
||||
| `family` | The encoding family of this variant; must differ from the form's |
|
||||
| `opcode` | The XML opcode in that family |
|
||||
| `operands` | An operand rule of that family whose kind can encode the base form (today `vop3_vgpr2` for VOP2 vector forms) |
|
||||
| `operands` | An operand rule of that family that can encode the base form (`vop3_vgpr2` for VOP2 vector forms, `vop3_cmp_vgpr2` for VOPC integer compares) |
|
||||
| `spec`, `verify` | As for a form |
|
||||
|
||||
Everything else (operation, signedness, effects, source order) is inherited
|
||||
from the base form, and the XML check runs on that inherited declaration with
|
||||
the variant's family, opcode and operand rule, so the VOP3 operand widths and
|
||||
formats must agree with it. The generator emits one enum per variant rule (`VectorAluVop3Op` for
|
||||
`vop3_vgpr2`) holding exactly the declared variants, with `from_word` (encoding
|
||||
The variant inherits the operation, signedness, source order and SCC and EXEC
|
||||
effects. Its operand rule determines where the result is written. The XML
|
||||
check uses the variant's family, opcode and operand rule to validate the
|
||||
inherited declaration. The generator emits one enum per variant rule
|
||||
(`VectorAluVop3Op` or `VectorCompareVop3Op`) with `from_word` (encoding
|
||||
bits, then an explicit match on the OP field), `base()` (the inherited form),
|
||||
`assembly_name()` and `semantics()`, and one `FORMS` row per variant after the
|
||||
forms. Because the enum has no undeclared members, an instruction cannot name a
|
||||
VOP3 encoding that does not exist. Every explicit XML operand of the variant,
|
||||
destination included, must have the data format of the base operand in the same
|
||||
role (destination, then the sources in rule order). A variant-only rule says so
|
||||
VOP3 encoding that does not exist. Corresponding explicit XML operands must
|
||||
have the same data format by role. A variant-only rule says so
|
||||
in the data (`variant_only = true`), so the RDNA2 planner does not count it as a
|
||||
rule that can host new forms. A
|
||||
variant-only rule (one marked `variant_of` in the generator) cannot be used by a
|
||||
@@ -75,7 +74,15 @@ the registry: VGPR destination, two VGPR sources, ABS, OP_SEL, CLAMP, OMOD and
|
||||
NEG clear, and SRC2 the assembler's unused inline zero. `v_add_nc_u32_e64` is its
|
||||
first variant; adding the VOP3 encoding of another VOP2 form under this rule is
|
||||
one `[[encoding_variant]]` entry. Wider VOP3 operand rules (scalar and inline
|
||||
sources, legal modifiers) come with the VOP3 batch.
|
||||
sources, legal modifiers) need separate rules.
|
||||
|
||||
`vop3_cmp_vgpr2` uses the same VGPR source and modifier restrictions and
|
||||
specifies a scalar destination. It requires a base form with a `lane_mask`
|
||||
write to implicit VCC, and generates an `sdst_lane_mask` effect on the
|
||||
variant row. The generator checks the base VCC output and the variant's
|
||||
explicit scalar mask destination against the XML. An SDST of 106 selects
|
||||
`vcc_lo`. See [the compare contract](vector-compare.md#11-vop3a-encoding-_e64)
|
||||
for Wave32 lowering and allowed consumers.
|
||||
|
||||
## Fields
|
||||
|
||||
@@ -199,7 +206,8 @@ integer as SRC0 and a VGPR pair as VSRC1. All three declare a `relation`,
|
||||
`scc = "unchanged"`, `vcc = "lane_mask"` and `wave = "wave32"`. The XML's implicit
|
||||
64-bit VCC output must be present and is accounted for by `lane_mask`. Signedness
|
||||
still matters for `eq` and `lg`, because the MSL lowering casts signed operands.
|
||||
`v_cmpx_*` (EXEC writes), the VOP3 encoding and Wave64 stay unsupported.
|
||||
The VOP3A variants redirect the same Wave32 mask to SDST. EXEC-writing
|
||||
compares (`v_cmpx_*`) and Wave64 stay unsupported.
|
||||
|
||||
A SOPC compare must use an operand rule of the compare kind (`sopc_scalar`: two
|
||||
sources, no destination), a unary operation one of the unary kind (`sop1_sgpr`:
|
||||
|
||||
@@ -122,7 +122,7 @@ this wave (all 32 except in a final partial wave, see 7). As an unsigned
|
||||
## 4. Rejected (controlled translation/reference error, never a silent no-op)
|
||||
|
||||
- V_CMPX_* (writes EXEC: divergent execution; needs its own contract).
|
||||
- The VOP3 encoding of any compare (arbitrary SGPR destination, modifiers).
|
||||
- VOP3A compares outside the integer subset in section 11.
|
||||
- SDWA and DPP forms; float compares; v_cmp_class.
|
||||
- 16-bit compares in the decoder and translator (the reference interpreters
|
||||
accept the subset in 2a).
|
||||
@@ -275,12 +275,11 @@ swapped signedness, without the EXEC mask, without the absent-lane bound
|
||||
(shader validation aborts on the out-of-range read) or with an inverted join.
|
||||
|
||||
The 32-bit readback evidence is local agreement with a specification-derived
|
||||
reference on Apple M5 Pro. The 16-bit compiler evidence is CPU-only.
|
||||
There is no RDNA 2 or Xbox hardware evidence.
|
||||
reference on Apple M5 Pro. There is no RDNA 2 or Xbox hardware evidence.
|
||||
|
||||
## 10. Limitations
|
||||
|
||||
- Wave32 only. No `v_cmpx`, VOP3, SDWA, DPP or float compares.
|
||||
- Wave32 only. No `v_cmpx`, SDWA, DPP or float compares. VOP3 encodings cover the 32-bit compares only.
|
||||
- A lane-derived VCC_LO cannot reach EXEC or any scalar instruction, so there
|
||||
is no divergent execution. That needs its own contract.
|
||||
- The skipped region of a runtime `s_cbranch_vccz` holds only integer vector
|
||||
@@ -289,3 +288,38 @@ There is no RDNA 2 or Xbox hardware evidence.
|
||||
- Each thread recomputes up to 32 lanes per compare. The cost grows with the
|
||||
compare's dependency chain. That is fine for fixtures, and no performance is
|
||||
claimed.
|
||||
|
||||
## 11. VOP3A encoding (`_e64`)
|
||||
|
||||
All sixteen 32-bit signed and unsigned compares in section 2 also have a 64-bit
|
||||
VOP3A encoding. The pinned AMD XML supplies each opcode. Bits 7:0 of the first
|
||||
word are the scalar destination selector (SDST), in the field named VDST.
|
||||
Selectors 0–105 name scalar general-purpose registers (SGPRs), and 106 names
|
||||
`vcc_lo`. All other destinations are rejected. Both SRC0 and SRC1 must name
|
||||
vector general-purpose registers (VGPRs), and the unused SRC2 must be the
|
||||
assembler's inline-zero selector (128). ABS, OP_SEL, CLAMP, OMOD and NEG must
|
||||
be clear. The guide describes CLAMP on compares as enabling floating-point
|
||||
exception signaling (§6.5, p. 48 and §12.9.1, p. 162).
|
||||
|
||||
The AMD guide's compare-specific text (§3.9, pp. 19–20 and §13.3.3, p. 252)
|
||||
specifies an SGPR destination for this encoding. The generic VDST label in
|
||||
§12.9.1 (p. 162) and §13.3.4 Table 82 (pp. 257–258) describes the VOP3A field
|
||||
as a VGPR destination. The pinned XML identifies VDST for these compares as
|
||||
`OPR_SREG`, with the Wave64 pair described by `FMT_NUM_M64`. The Wave32 write
|
||||
occupies one 32-bit SGPR. The guide defines 32 work-items in §2.1 (pp. 7–8),
|
||||
32-bit SGPRs in §3.1 Table 2 (p. 12) and one compare result bit per lane in
|
||||
§12.9 (p. 150). Wave64 stays unsupported.
|
||||
|
||||
LLVM 23 `llvm-mc` for gfx1030 with `+wavefrontsize32` assembles
|
||||
`v_cmp_eq_u32_e64 s4, v1, v2` as bytes `04 00 c2 d4 01 05 02 02`.
|
||||
Selecting `vcc_lo` changes the first byte to `6a`. The decoder tests cover
|
||||
the assembler's words for all sixteen forms. This is encoding evidence.
|
||||
|
||||
The compare replaces all 32 bits of SDST with the lane mask from section 3,
|
||||
including zero bits for inactive and absent lanes. It leaves SCC and EXEC
|
||||
unchanged. VCC is written only when SDST selects `vcc_lo`, which uses the
|
||||
same lowering and consumers as the VOPC form, including `s_cbranch_vccz`.
|
||||
Every other SDST is tracked as a runtime-only SGPR result, including under
|
||||
empty EXEC. Translation rejects later reads of that result, including reads
|
||||
through resource descriptors. The runtime branch region rules in section 6
|
||||
also apply here.
|
||||
@@ -87,6 +87,330 @@ recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_mul_i32_i24_e64"
|
||||
encoding = "VOP3A, Wave32; VGPR destination and two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; inactive lanes keep VDST; the operation of `v_mul_i32_i24_e32`"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread typed integer template of the VOP2 form"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_mul_hi_i32_i24_e64"
|
||||
encoding = "VOP3A, Wave32; VGPR destination and two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; inactive lanes keep VDST; the operation of `v_mul_hi_i32_i24_e32`"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread typed integer template of the VOP2 form"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_mul_u32_u24_e64"
|
||||
encoding = "VOP3A, Wave32; VGPR destination and two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; inactive lanes keep VDST; the operation of `v_mul_u32_u24_e32`"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread typed integer template of the VOP2 form"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_mul_hi_u32_u24_e64"
|
||||
encoding = "VOP3A, Wave32; VGPR destination and two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; inactive lanes keep VDST; the operation of `v_mul_hi_u32_u24_e32`"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread typed integer template of the VOP2 form"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_min_i32_e64"
|
||||
encoding = "VOP3A, Wave32; VGPR destination and two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; inactive lanes keep VDST; the operation of `v_min_i32_e32`"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread typed integer template of the VOP2 form"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_max_i32_e64"
|
||||
encoding = "VOP3A, Wave32; VGPR destination and two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; inactive lanes keep VDST; the operation of `v_max_i32_e32`"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread typed integer template of the VOP2 form"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_min_u32_e64"
|
||||
encoding = "VOP3A, Wave32; VGPR destination and two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; inactive lanes keep VDST; the operation of `v_min_u32_e32`"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread typed integer template of the VOP2 form"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_max_u32_e64"
|
||||
encoding = "VOP3A, Wave32; VGPR destination and two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; inactive lanes keep VDST; the operation of `v_max_u32_e32`"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread typed integer template of the VOP2 form"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_xnor_b32_e64"
|
||||
encoding = "VOP3A, Wave32; VGPR destination and two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; inactive lanes keep VDST; the operation of `v_xnor_b32_e32`"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread typed integer template of the VOP2 form"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_sub_nc_u32_e64"
|
||||
encoding = "VOP3A, Wave32; VGPR destination and two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; inactive lanes keep VDST; the operation of `v_sub_nc_u32_e32`"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread typed integer template of the VOP2 form"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_subrev_nc_u32_e64"
|
||||
encoding = "VOP3A, Wave32; VGPR destination and two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; inactive lanes keep VDST; the operation of `v_subrev_nc_u32_e32`"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread typed integer template of the VOP2 form"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_cmp_lt_i32_e64"
|
||||
encoding = "VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_lt_i32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_cmp_eq_i32_e64"
|
||||
encoding = "VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_eq_i32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_cmp_le_i32_e64"
|
||||
encoding = "VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_le_i32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_cmp_gt_i32_e64"
|
||||
encoding = "VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_gt_i32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_cmp_ne_i32_e64"
|
||||
encoding = "VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_ne_i32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_cmp_ge_i32_e64"
|
||||
encoding = "VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_ge_i32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_cmp_f_i32_e64"
|
||||
encoding = "VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_f_i32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_cmp_t_i32_e64"
|
||||
encoding = "VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_t_i32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_cmp_lt_u32_e64"
|
||||
encoding = "VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_lt_u32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_cmp_eq_u32_e64"
|
||||
encoding = "VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_eq_u32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_cmp_le_u32_e64"
|
||||
encoding = "VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_le_u32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_cmp_gt_u32_e64"
|
||||
encoding = "VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_gt_u32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_cmp_ne_u32_e64"
|
||||
encoding = "VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_ne_u32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_cmp_ge_u32_e64"
|
||||
encoding = "VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_ge_u32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_cmp_f_u32_e64"
|
||||
encoding = "VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_f_u32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "v_cmp_t_u32_e64"
|
||||
encoding = "VOP3A, Wave32; SGPR destination s0-s105 or vcc_lo, D[n] = EXEC_LO[n] & test, fully written; two VGPR inputs, modifier fields clear, SRC2 encoded as inline zero; the relation of `v_cmp_t_u32_e32`; reading a lane-derived mask from an SGPR other than vcc_lo is a translation error"
|
||||
representation = "8 B"
|
||||
lowering = "per-thread Wave32 mask, as the VOPC form; runtime s_cbranch_vccz through vcc_lo"
|
||||
reference = "implemented"
|
||||
cpu = "local known-answer test passed"
|
||||
gpu = "local Apple M5 readback passed; acceptance pending"
|
||||
recognized = true
|
||||
decoded = true
|
||||
llvm = "three-way passed"
|
||||
|
||||
[[instruction]]
|
||||
form = "buffer_store_dword"
|
||||
encoding = "MUBUF, VGPR data/index, four normal SGPRs, `idxen`, zero offsets and remaining flags"
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
0000: t0 = load.u32 input[index]
|
||||
000c: t1 = const.u32 0x00000000
|
||||
0010: t2 = const.u32 0x00000001
|
||||
0014: t3 = const.u32 0x40000001
|
||||
001c: t4 = const.u32 0x00000001
|
||||
0020: t5 = wave.mask v_cmp_f_i32_e64 t0, t3 -> vcc_lo exec=0xffffffff
|
||||
002c: t6 = lshl.b32 t1, t2
|
||||
0030: t7 = xor.b32 t6, t5
|
||||
0034: t8 = wave.mask v_cmp_lt_i32_e64 t0, t3 -> vcc_lo exec=0xffffffff
|
||||
0040: t9 = lshl.b32 t7, t2
|
||||
0044: t10 = xor.b32 t9, t8
|
||||
0048: t11 = wave.mask v_cmp_eq_i32_e64 t0, t3 -> vcc_lo exec=0xffffffff
|
||||
0054: t12 = lshl.b32 t10, t2
|
||||
0058: t13 = xor.b32 t12, t11
|
||||
005c: t14 = wave.mask v_cmp_le_i32_e64 t0, t3 -> vcc_lo exec=0xffffffff
|
||||
0068: t15 = lshl.b32 t13, t2
|
||||
006c: t16 = xor.b32 t15, t14
|
||||
0070: t17 = wave.mask v_cmp_gt_i32_e64 t0, t3 -> vcc_lo exec=0xffffffff
|
||||
007c: t18 = lshl.b32 t16, t2
|
||||
0080: t19 = xor.b32 t18, t17
|
||||
0084: t20 = wave.mask v_cmp_ne_i32_e64 t0, t3 -> vcc_lo exec=0xffffffff
|
||||
0090: t21 = lshl.b32 t19, t2
|
||||
0094: t22 = xor.b32 t21, t20
|
||||
0098: t23 = wave.mask v_cmp_ge_i32_e64 t0, t3 -> vcc_lo exec=0xffffffff
|
||||
00a4: t24 = lshl.b32 t22, t2
|
||||
00a8: t25 = xor.b32 t24, t23
|
||||
00ac: t26 = wave.mask v_cmp_t_i32_e64 t0, t3 -> vcc_lo exec=0xffffffff
|
||||
00b8: t27 = lshl.b32 t25, t2
|
||||
00bc: t28 = xor.b32 t27, t26
|
||||
00c0: t29 = wave.mask v_cmp_f_u32_e64 t0, t3 -> vcc_lo exec=0xffffffff
|
||||
00cc: t30 = lshl.b32 t28, t2
|
||||
00d0: t31 = xor.b32 t30, t29
|
||||
00d4: t32 = wave.mask v_cmp_lt_u32_e64 t0, t3 -> vcc_lo exec=0xffffffff
|
||||
00e0: t33 = lshl.b32 t31, t2
|
||||
00e4: t34 = xor.b32 t33, t32
|
||||
00e8: t35 = wave.mask v_cmp_eq_u32_e64 t0, t3 -> vcc_lo exec=0xffffffff
|
||||
00f4: t36 = lshl.b32 t34, t2
|
||||
00f8: t37 = xor.b32 t36, t35
|
||||
00fc: t38 = wave.mask v_cmp_le_u32_e64 t0, t3 -> vcc_lo exec=0xffffffff
|
||||
0108: t39 = lshl.b32 t37, t2
|
||||
010c: t40 = xor.b32 t39, t38
|
||||
0110: t41 = wave.mask v_cmp_gt_u32_e64 t0, t3 -> vcc_lo exec=0xffffffff
|
||||
011c: t42 = lshl.b32 t40, t2
|
||||
0120: t43 = xor.b32 t42, t41
|
||||
0124: t44 = wave.mask v_cmp_ne_u32_e64 t0, t3 -> vcc_lo exec=0xffffffff
|
||||
0130: t45 = lshl.b32 t43, t2
|
||||
0134: t46 = xor.b32 t45, t44
|
||||
0138: t47 = wave.mask v_cmp_ge_u32_e64 t0, t3 -> vcc_lo exec=0xffffffff
|
||||
0144: t48 = lshl.b32 t46, t2
|
||||
0148: t49 = xor.b32 t48, t47
|
||||
014c: t50 = wave.mask v_cmp_t_u32_e64 t0, t3 -> vcc_lo exec=0xffffffff
|
||||
0158: t51 = lshl.b32 t49, t2
|
||||
015c: t52 = xor.b32 t51, t50
|
||||
0160: t53 = wave.mask v_cmp_eq_u32_e64 t0, t3 -> s8 exec=0xffffffff
|
||||
0168: t54 = wave.mask v_cmp_gt_u32_e64 t3, t0 -> vcc_lo exec=0xffffffff
|
||||
0170: branch.vccz t54 -> 0x0178
|
||||
0174: t56 = xor.b32 t4, t52
|
||||
0178: t57 = join.vccz t54, t56, t52
|
||||
0178: store.u32 output[index], t57
|
||||
@@ -0,0 +1,188 @@
|
||||
#include <metal_stdlib>
|
||||
using namespace metal;
|
||||
kernel void xenora_compute(
|
||||
device const uint* input [[buffer(0)]],
|
||||
device uint* output [[buffer(1)]],
|
||||
uint index [[thread_position_in_grid]],
|
||||
uint grid [[threads_per_grid]]) {
|
||||
uint t0 = input[index];
|
||||
uint t1 = 0x00000000u;
|
||||
uint t2 = 0x00000001u;
|
||||
uint t3 = 0x40000001u;
|
||||
uint t4 = 0x00000001u;
|
||||
uint t5 = 0u;
|
||||
for (uint lane = 0u; lane < 32u; ++lane) {
|
||||
uint lane_index = (index & ~31u) + lane;
|
||||
if (lane_index >= grid) { break; }
|
||||
uint pass = (false) ? 1u : 0u;
|
||||
t5 |= ((0xffffffffu >> lane) & pass) << lane;
|
||||
}
|
||||
uint t6 = t1 << (t2 & 31u);
|
||||
uint t7 = t6 ^ t5;
|
||||
uint t8 = 0u;
|
||||
for (uint lane = 0u; lane < 32u; ++lane) {
|
||||
uint lane_index = (index & ~31u) + lane;
|
||||
if (lane_index >= grid) { break; }
|
||||
uint l0 = input[lane_index];
|
||||
uint pass = (as_type<int>(l0) < as_type<int>(t3)) ? 1u : 0u;
|
||||
t8 |= ((0xffffffffu >> lane) & pass) << lane;
|
||||
}
|
||||
uint t9 = t7 << (t2 & 31u);
|
||||
uint t10 = t9 ^ t8;
|
||||
uint t11 = 0u;
|
||||
for (uint lane = 0u; lane < 32u; ++lane) {
|
||||
uint lane_index = (index & ~31u) + lane;
|
||||
if (lane_index >= grid) { break; }
|
||||
uint l0 = input[lane_index];
|
||||
uint pass = (as_type<int>(l0) == as_type<int>(t3)) ? 1u : 0u;
|
||||
t11 |= ((0xffffffffu >> lane) & pass) << lane;
|
||||
}
|
||||
uint t12 = t10 << (t2 & 31u);
|
||||
uint t13 = t12 ^ t11;
|
||||
uint t14 = 0u;
|
||||
for (uint lane = 0u; lane < 32u; ++lane) {
|
||||
uint lane_index = (index & ~31u) + lane;
|
||||
if (lane_index >= grid) { break; }
|
||||
uint l0 = input[lane_index];
|
||||
uint pass = (as_type<int>(l0) <= as_type<int>(t3)) ? 1u : 0u;
|
||||
t14 |= ((0xffffffffu >> lane) & pass) << lane;
|
||||
}
|
||||
uint t15 = t13 << (t2 & 31u);
|
||||
uint t16 = t15 ^ t14;
|
||||
uint t17 = 0u;
|
||||
for (uint lane = 0u; lane < 32u; ++lane) {
|
||||
uint lane_index = (index & ~31u) + lane;
|
||||
if (lane_index >= grid) { break; }
|
||||
uint l0 = input[lane_index];
|
||||
uint pass = (as_type<int>(l0) > as_type<int>(t3)) ? 1u : 0u;
|
||||
t17 |= ((0xffffffffu >> lane) & pass) << lane;
|
||||
}
|
||||
uint t18 = t16 << (t2 & 31u);
|
||||
uint t19 = t18 ^ t17;
|
||||
uint t20 = 0u;
|
||||
for (uint lane = 0u; lane < 32u; ++lane) {
|
||||
uint lane_index = (index & ~31u) + lane;
|
||||
if (lane_index >= grid) { break; }
|
||||
uint l0 = input[lane_index];
|
||||
uint pass = (as_type<int>(l0) != as_type<int>(t3)) ? 1u : 0u;
|
||||
t20 |= ((0xffffffffu >> lane) & pass) << lane;
|
||||
}
|
||||
uint t21 = t19 << (t2 & 31u);
|
||||
uint t22 = t21 ^ t20;
|
||||
uint t23 = 0u;
|
||||
for (uint lane = 0u; lane < 32u; ++lane) {
|
||||
uint lane_index = (index & ~31u) + lane;
|
||||
if (lane_index >= grid) { break; }
|
||||
uint l0 = input[lane_index];
|
||||
uint pass = (as_type<int>(l0) >= as_type<int>(t3)) ? 1u : 0u;
|
||||
t23 |= ((0xffffffffu >> lane) & pass) << lane;
|
||||
}
|
||||
uint t24 = t22 << (t2 & 31u);
|
||||
uint t25 = t24 ^ t23;
|
||||
uint t26 = 0u;
|
||||
for (uint lane = 0u; lane < 32u; ++lane) {
|
||||
uint lane_index = (index & ~31u) + lane;
|
||||
if (lane_index >= grid) { break; }
|
||||
uint pass = (true) ? 1u : 0u;
|
||||
t26 |= ((0xffffffffu >> lane) & pass) << lane;
|
||||
}
|
||||
uint t27 = t25 << (t2 & 31u);
|
||||
uint t28 = t27 ^ t26;
|
||||
uint t29 = 0u;
|
||||
for (uint lane = 0u; lane < 32u; ++lane) {
|
||||
uint lane_index = (index & ~31u) + lane;
|
||||
if (lane_index >= grid) { break; }
|
||||
uint pass = (false) ? 1u : 0u;
|
||||
t29 |= ((0xffffffffu >> lane) & pass) << lane;
|
||||
}
|
||||
uint t30 = t28 << (t2 & 31u);
|
||||
uint t31 = t30 ^ t29;
|
||||
uint t32 = 0u;
|
||||
for (uint lane = 0u; lane < 32u; ++lane) {
|
||||
uint lane_index = (index & ~31u) + lane;
|
||||
if (lane_index >= grid) { break; }
|
||||
uint l0 = input[lane_index];
|
||||
uint pass = (l0 < t3) ? 1u : 0u;
|
||||
t32 |= ((0xffffffffu >> lane) & pass) << lane;
|
||||
}
|
||||
uint t33 = t31 << (t2 & 31u);
|
||||
uint t34 = t33 ^ t32;
|
||||
uint t35 = 0u;
|
||||
for (uint lane = 0u; lane < 32u; ++lane) {
|
||||
uint lane_index = (index & ~31u) + lane;
|
||||
if (lane_index >= grid) { break; }
|
||||
uint l0 = input[lane_index];
|
||||
uint pass = (l0 == t3) ? 1u : 0u;
|
||||
t35 |= ((0xffffffffu >> lane) & pass) << lane;
|
||||
}
|
||||
uint t36 = t34 << (t2 & 31u);
|
||||
uint t37 = t36 ^ t35;
|
||||
uint t38 = 0u;
|
||||
for (uint lane = 0u; lane < 32u; ++lane) {
|
||||
uint lane_index = (index & ~31u) + lane;
|
||||
if (lane_index >= grid) { break; }
|
||||
uint l0 = input[lane_index];
|
||||
uint pass = (l0 <= t3) ? 1u : 0u;
|
||||
t38 |= ((0xffffffffu >> lane) & pass) << lane;
|
||||
}
|
||||
uint t39 = t37 << (t2 & 31u);
|
||||
uint t40 = t39 ^ t38;
|
||||
uint t41 = 0u;
|
||||
for (uint lane = 0u; lane < 32u; ++lane) {
|
||||
uint lane_index = (index & ~31u) + lane;
|
||||
if (lane_index >= grid) { break; }
|
||||
uint l0 = input[lane_index];
|
||||
uint pass = (l0 > t3) ? 1u : 0u;
|
||||
t41 |= ((0xffffffffu >> lane) & pass) << lane;
|
||||
}
|
||||
uint t42 = t40 << (t2 & 31u);
|
||||
uint t43 = t42 ^ t41;
|
||||
uint t44 = 0u;
|
||||
for (uint lane = 0u; lane < 32u; ++lane) {
|
||||
uint lane_index = (index & ~31u) + lane;
|
||||
if (lane_index >= grid) { break; }
|
||||
uint l0 = input[lane_index];
|
||||
uint pass = (l0 != t3) ? 1u : 0u;
|
||||
t44 |= ((0xffffffffu >> lane) & pass) << lane;
|
||||
}
|
||||
uint t45 = t43 << (t2 & 31u);
|
||||
uint t46 = t45 ^ t44;
|
||||
uint t47 = 0u;
|
||||
for (uint lane = 0u; lane < 32u; ++lane) {
|
||||
uint lane_index = (index & ~31u) + lane;
|
||||
if (lane_index >= grid) { break; }
|
||||
uint l0 = input[lane_index];
|
||||
uint pass = (l0 >= t3) ? 1u : 0u;
|
||||
t47 |= ((0xffffffffu >> lane) & pass) << lane;
|
||||
}
|
||||
uint t48 = t46 << (t2 & 31u);
|
||||
uint t49 = t48 ^ t47;
|
||||
uint t50 = 0u;
|
||||
for (uint lane = 0u; lane < 32u; ++lane) {
|
||||
uint lane_index = (index & ~31u) + lane;
|
||||
if (lane_index >= grid) { break; }
|
||||
uint pass = (true) ? 1u : 0u;
|
||||
t50 |= ((0xffffffffu >> lane) & pass) << lane;
|
||||
}
|
||||
uint t51 = t49 << (t2 & 31u);
|
||||
uint t52 = t51 ^ t50;
|
||||
uint t53 = 0u;
|
||||
for (uint lane = 0u; lane < 32u; ++lane) {
|
||||
uint lane_index = (index & ~31u) + lane;
|
||||
if (lane_index >= grid) { break; }
|
||||
uint l0 = input[lane_index];
|
||||
uint pass = (l0 == t3) ? 1u : 0u;
|
||||
t53 |= ((0xffffffffu >> lane) & pass) << lane;
|
||||
}
|
||||
uint t54 = 0u;
|
||||
for (uint lane = 0u; lane < 32u; ++lane) {
|
||||
uint lane_index = (index & ~31u) + lane;
|
||||
if (lane_index >= grid) { break; }
|
||||
uint l0 = input[lane_index];
|
||||
uint pass = (t3 > l0) ? 1u : 0u;
|
||||
t54 |= ((0xffffffffu >> lane) & pass) << lane;
|
||||
}
|
||||
uint t56 = t4 ^ t52;
|
||||
uint t57 = t54 != 0u ? t56 : t52;
|
||||
output[index] = t57;
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
0000: t0 = load.u32 input[index]
|
||||
000c: t1 = mul24.i32 t0, t0
|
||||
0014: t2 = mulhi24.i32 t1, t0
|
||||
001c: t3 = mul24.u32 t1, t0
|
||||
0024: t4 = mulhi24.u32 t3, t0
|
||||
002c: t5 = min.i32 t0, t1
|
||||
0034: t6 = max.i32 t0, t3
|
||||
003c: t7 = min.u32 t2, t0
|
||||
0044: t8 = max.u32 t4, t1
|
||||
004c: t9 = xnor.b32 t0, t4
|
||||
0054: t10 = sub.u32 t5, t9
|
||||
005c: t11 = sub.u32 t8, t0
|
||||
0064: t12 = xor.b32 t1, t2
|
||||
0068: t13 = xor.b32 t3, t12
|
||||
006c: t14 = xor.b32 t4, t13
|
||||
0070: t15 = xor.b32 t5, t14
|
||||
0074: t16 = xor.b32 t6, t15
|
||||
0078: t17 = xor.b32 t7, t16
|
||||
007c: t18 = xor.b32 t8, t17
|
||||
0080: t19 = xor.b32 t9, t18
|
||||
0084: t20 = xor.b32 t10, t19
|
||||
0088: t21 = xor.b32 t11, t20
|
||||
008c: store.u32 output[index], t21
|
||||
@@ -0,0 +1,30 @@
|
||||
#include <metal_stdlib>
|
||||
using namespace metal;
|
||||
kernel void xenora_compute(
|
||||
device const uint* input [[buffer(0)]],
|
||||
device uint* output [[buffer(1)]],
|
||||
uint index [[thread_position_in_grid]]) {
|
||||
uint t0 = input[index];
|
||||
uint t1 = as_type<uint>((as_type<int>(t0 << 8u) >> 8)) * as_type<uint>((as_type<int>(t0 << 8u) >> 8));
|
||||
uint t2 = as_type<uint>(mulhi((as_type<int>(t1 << 8u) >> 8), (as_type<int>(t0 << 8u) >> 8)));
|
||||
uint t3 = (t1 & 0x00ffffffu) * (t0 & 0x00ffffffu);
|
||||
uint t4 = mulhi((t3 & 0x00ffffffu), (t0 & 0x00ffffffu));
|
||||
uint t5 = as_type<uint>(min(as_type<int>(t0), as_type<int>(t1)));
|
||||
uint t6 = as_type<uint>(max(as_type<int>(t0), as_type<int>(t3)));
|
||||
uint t7 = min(t2, t0);
|
||||
uint t8 = max(t4, t1);
|
||||
uint t9 = ~(t0 ^ t4);
|
||||
uint t10 = t5 - t9;
|
||||
uint t11 = t8 - t0;
|
||||
uint t12 = t1 ^ t2;
|
||||
uint t13 = t3 ^ t12;
|
||||
uint t14 = t4 ^ t13;
|
||||
uint t15 = t5 ^ t14;
|
||||
uint t16 = t6 ^ t15;
|
||||
uint t17 = t7 ^ t16;
|
||||
uint t18 = t8 ^ t17;
|
||||
uint t19 = t9 ^ t18;
|
||||
uint t20 = t10 ^ t19;
|
||||
uint t21 = t11 ^ t20;
|
||||
output[index] = t21;
|
||||
}
|
||||
Binary file not shown.
@@ -0,0 +1,85 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Original Wave32 VOP3A vectors for the sixteen integer compare encoding variants.
|
||||
// Each compare writes vcc_lo through the explicit 64-bit destination field
|
||||
// (one writes s8), and each wave folds the masks into v2 as
|
||||
// v2 = (v2 << 1) ^ mask. Sources are VGPRs. This fixture is checked through
|
||||
// its IR and MSL goldens; the per-lane expected values for these forms are in
|
||||
// tests/validation/tests/vop3_compare.rs.
|
||||
.text
|
||||
buffer_load_dword v1, v0, s[0:3], 0 idxen // Load the lane's input word.
|
||||
s_waitcnt vmcnt(0) // Wait for the load.
|
||||
v_mov_b32_e32 v2, 0 // Clear the accumulator.
|
||||
v_mov_b32_e32 v5, 1 // Shift count for the fold.
|
||||
v_mov_b32_e32 v3, 0x40000001 // Second source: inputs fall below, on and above it.
|
||||
v_mov_b32_e32 v6, 1 // Low bit for the branch fold.
|
||||
v_cmp_f_i32_e64 vcc_lo, v1, v3 // Compare the input with 0x40000001.
|
||||
v_mov_b32_e32 v4, vcc_lo // Move the mask into a VGPR.
|
||||
v_lshlrev_b32_e32 v2, v5, v2 // Shift the accumulator.
|
||||
v_xor_b32_e32 v2, v2, v4 // Fold the mask.
|
||||
v_cmp_lt_i32_e64 vcc_lo, v1, v3 // Compare the input with 0x40000001.
|
||||
v_mov_b32_e32 v4, vcc_lo // Move the mask into a VGPR.
|
||||
v_lshlrev_b32_e32 v2, v5, v2 // Shift the accumulator.
|
||||
v_xor_b32_e32 v2, v2, v4 // Fold the mask.
|
||||
v_cmp_eq_i32_e64 vcc_lo, v1, v3 // Compare the input with 0x40000001.
|
||||
v_mov_b32_e32 v4, vcc_lo // Move the mask into a VGPR.
|
||||
v_lshlrev_b32_e32 v2, v5, v2 // Shift the accumulator.
|
||||
v_xor_b32_e32 v2, v2, v4 // Fold the mask.
|
||||
v_cmp_le_i32_e64 vcc_lo, v1, v3 // Compare the input with 0x40000001.
|
||||
v_mov_b32_e32 v4, vcc_lo // Move the mask into a VGPR.
|
||||
v_lshlrev_b32_e32 v2, v5, v2 // Shift the accumulator.
|
||||
v_xor_b32_e32 v2, v2, v4 // Fold the mask.
|
||||
v_cmp_gt_i32_e64 vcc_lo, v1, v3 // Compare the input with 0x40000001.
|
||||
v_mov_b32_e32 v4, vcc_lo // Move the mask into a VGPR.
|
||||
v_lshlrev_b32_e32 v2, v5, v2 // Shift the accumulator.
|
||||
v_xor_b32_e32 v2, v2, v4 // Fold the mask.
|
||||
v_cmp_ne_i32_e64 vcc_lo, v1, v3 // Compare the input with 0x40000001.
|
||||
v_mov_b32_e32 v4, vcc_lo // Move the mask into a VGPR.
|
||||
v_lshlrev_b32_e32 v2, v5, v2 // Shift the accumulator.
|
||||
v_xor_b32_e32 v2, v2, v4 // Fold the mask.
|
||||
v_cmp_ge_i32_e64 vcc_lo, v1, v3 // Compare the input with 0x40000001.
|
||||
v_mov_b32_e32 v4, vcc_lo // Move the mask into a VGPR.
|
||||
v_lshlrev_b32_e32 v2, v5, v2 // Shift the accumulator.
|
||||
v_xor_b32_e32 v2, v2, v4 // Fold the mask.
|
||||
v_cmp_t_i32_e64 vcc_lo, v1, v3 // Compare the input with 0x40000001.
|
||||
v_mov_b32_e32 v4, vcc_lo // Move the mask into a VGPR.
|
||||
v_lshlrev_b32_e32 v2, v5, v2 // Shift the accumulator.
|
||||
v_xor_b32_e32 v2, v2, v4 // Fold the mask.
|
||||
v_cmp_f_u32_e64 vcc_lo, v1, v3 // Compare the input with 0x40000001.
|
||||
v_mov_b32_e32 v4, vcc_lo // Move the mask into a VGPR.
|
||||
v_lshlrev_b32_e32 v2, v5, v2 // Shift the accumulator.
|
||||
v_xor_b32_e32 v2, v2, v4 // Fold the mask.
|
||||
v_cmp_lt_u32_e64 vcc_lo, v1, v3 // Compare the input with 0x40000001.
|
||||
v_mov_b32_e32 v4, vcc_lo // Move the mask into a VGPR.
|
||||
v_lshlrev_b32_e32 v2, v5, v2 // Shift the accumulator.
|
||||
v_xor_b32_e32 v2, v2, v4 // Fold the mask.
|
||||
v_cmp_eq_u32_e64 vcc_lo, v1, v3 // Compare the input with 0x40000001.
|
||||
v_mov_b32_e32 v4, vcc_lo // Move the mask into a VGPR.
|
||||
v_lshlrev_b32_e32 v2, v5, v2 // Shift the accumulator.
|
||||
v_xor_b32_e32 v2, v2, v4 // Fold the mask.
|
||||
v_cmp_le_u32_e64 vcc_lo, v1, v3 // Compare the input with 0x40000001.
|
||||
v_mov_b32_e32 v4, vcc_lo // Move the mask into a VGPR.
|
||||
v_lshlrev_b32_e32 v2, v5, v2 // Shift the accumulator.
|
||||
v_xor_b32_e32 v2, v2, v4 // Fold the mask.
|
||||
v_cmp_gt_u32_e64 vcc_lo, v1, v3 // Compare the input with 0x40000001.
|
||||
v_mov_b32_e32 v4, vcc_lo // Move the mask into a VGPR.
|
||||
v_lshlrev_b32_e32 v2, v5, v2 // Shift the accumulator.
|
||||
v_xor_b32_e32 v2, v2, v4 // Fold the mask.
|
||||
v_cmp_ne_u32_e64 vcc_lo, v1, v3 // Compare the input with 0x40000001.
|
||||
v_mov_b32_e32 v4, vcc_lo // Move the mask into a VGPR.
|
||||
v_lshlrev_b32_e32 v2, v5, v2 // Shift the accumulator.
|
||||
v_xor_b32_e32 v2, v2, v4 // Fold the mask.
|
||||
v_cmp_ge_u32_e64 vcc_lo, v1, v3 // Compare the input with 0x40000001.
|
||||
v_mov_b32_e32 v4, vcc_lo // Move the mask into a VGPR.
|
||||
v_lshlrev_b32_e32 v2, v5, v2 // Shift the accumulator.
|
||||
v_xor_b32_e32 v2, v2, v4 // Fold the mask.
|
||||
v_cmp_t_u32_e64 vcc_lo, v1, v3 // Compare the input with 0x40000001.
|
||||
v_mov_b32_e32 v4, vcc_lo // Move the mask into a VGPR.
|
||||
v_lshlrev_b32_e32 v2, v5, v2 // Shift the accumulator.
|
||||
v_xor_b32_e32 v2, v2, v4 // Fold the mask.
|
||||
v_cmp_eq_u32_e64 s8, v1, v3 // A mask into a plain SGPR, never read.
|
||||
v_cmp_gt_u32_e64 vcc_lo, v3, v1 // Unsigned 0x40000001 > input.
|
||||
s_cbranch_vccz 1 // Skip the next fold when no lane passed.
|
||||
v_xor_b32_e32 v2, v6, v2 // Flip the low bit when some lane passed.
|
||||
buffer_store_dword v2, v0, s[4:7], 0 idxen // Store the folded word.
|
||||
s_waitcnt_vscnt null, 0 // Wait for the store.
|
||||
s_endpgm // End the program.
|
||||
Binary file not shown.
@@ -0,0 +1,31 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
// Original VOP3A vectors for the eleven per-lane integer encoding variants.
|
||||
// All arithmetic operands are vector general-purpose registers (VGPRs) and every result
|
||||
// depends on the lane's own input word. XOR folds the results into one word.
|
||||
.text
|
||||
buffer_load_dword v1, v0, s[0:3], 0 idxen // Load the lane's input word.
|
||||
s_waitcnt vmcnt(0) // Wait for the load.
|
||||
v_mul_i32_i24_e64 v2, v1, v1 // Multiply signed 24-bit inputs and keep the low word.
|
||||
v_mul_hi_i32_i24_e64 v3, v2, v1 // Multiply signed 24-bit inputs and keep the high word.
|
||||
v_mul_u32_u24_e64 v4, v2, v1 // Multiply unsigned 24-bit inputs and keep the low word.
|
||||
v_mul_hi_u32_u24_e64 v255, v4, v1 // Multiply unsigned 24-bit inputs and keep the high word.
|
||||
v_min_i32_e64 v6, v1, v2 // Select the signed minimum.
|
||||
v_max_i32_e64 v7, v1, v4 // Select the signed maximum.
|
||||
v_min_u32_e64 v8, v3, v1 // Select the unsigned minimum.
|
||||
v_max_u32_e64 v9, v255, v2 // Select the unsigned maximum.
|
||||
v_xnor_b32_e64 v10, v1, v255 // Complement the XOR.
|
||||
v_sub_nc_u32_e64 v11, v6, v10 // Subtract the second source from the first.
|
||||
v_subrev_nc_u32_e64 v1, v1, v9 // Subtract the first source from the second, overwriting the first.
|
||||
v_xor_b32_e32 v13, v2, v3 // Start the XOR fold.
|
||||
v_xor_b32_e32 v13, v4, v13 // Fold the unsigned product low word.
|
||||
v_xor_b32_e32 v13, v255, v13 // Fold the unsigned product high word.
|
||||
v_xor_b32_e32 v13, v6, v13 // Fold the signed minimum.
|
||||
v_xor_b32_e32 v13, v7, v13 // Fold the signed maximum.
|
||||
v_xor_b32_e32 v13, v8, v13 // Fold the unsigned minimum.
|
||||
v_xor_b32_e32 v13, v9, v13 // Fold the unsigned maximum.
|
||||
v_xor_b32_e32 v13, v10, v13 // Fold the XNOR result.
|
||||
v_xor_b32_e32 v13, v11, v13 // Fold the subtraction result.
|
||||
v_xor_b32_e32 v13, v1, v13 // Fold the reverse subtraction result.
|
||||
buffer_store_dword v13, v0, s[4:7], 0 idxen // Store the folded word.
|
||||
s_waitcnt_vscnt null, 0 // Wait for the store.
|
||||
s_endpgm // End the program.
|
||||
@@ -12,7 +12,7 @@ case "${1:-}" in
|
||||
esac
|
||||
|
||||
for name in add bitwise-branch float-exact or shifts ashr \
|
||||
x9-constant-vs x9-constant-ps x9-varying-vs x9-varying-ps x9-transform-vs scalar-alu vector-compare scalar-logic scalar-compare scalar-unary scalar-arith scalar-immediate vector-integer vector-compare-ft vector-vcc vector-unary vector-compare-64 vector-compare-16; do
|
||||
x9-constant-vs x9-constant-ps x9-varying-vs x9-varying-ps x9-transform-vs scalar-alu vector-compare scalar-logic scalar-compare scalar-unary scalar-arith scalar-immediate vector-integer vector-compare-ft vector-vcc vop3-integer vop3-compare vector-unary vector-compare-64 vector-compare-16; do
|
||||
"$llvm_bin/llvm-mc" -triple=amdgcn-amd-amdhsa -mcpu=gfx1030 -mattr=+wavefrontsize32 \
|
||||
-filetype=obj "fixtures/rdna2/$name.s" -o "$scratch/$name.o"
|
||||
"$llvm_bin/llvm-objcopy" -O binary --only-section=.text "$scratch/$name.o" "$scratch/$name.bin"
|
||||
|
||||
@@ -25,6 +25,11 @@ cargo test --locked -p xenora-loader --features gpu-tests --test graphics_d3d12
|
||||
timeout 30s cargo test --locked -p xenora-loader --features gpu-tests --test graphics_d3d12 -- \
|
||||
--nocapture --test-threads=1
|
||||
|
||||
# Guest draws sample textures bound through descriptor tables (#303).
|
||||
cargo test --locked -p xenora-loader --features gpu-tests --test graphics_textures --no-run
|
||||
timeout 30s cargo test --locked -p xenora-loader --features gpu-tests --test graphics_textures -- \
|
||||
--nocapture --test-threads=1
|
||||
|
||||
# The native app interface runs the trusted fixture's guest draw on Metal.
|
||||
cargo test --locked -p xenora-ffi --features gpu-tests --test native_frame --no-run
|
||||
timeout 30s cargo test --locked -p xenora-ffi --features gpu-tests --test native_frame -- \
|
||||
|
||||
@@ -177,7 +177,7 @@ def snapshot():
|
||||
["SRC2", [[50, 9]]], ["OMOD", [[59, 2]]], ["NEG", [[61, 3]]],
|
||||
],
|
||||
"identifier_mask": 0xFFFF0000,
|
||||
"identifiers": [0xD4000000 | (op << 16) for op in (265, 273, 295)],
|
||||
"identifiers": [0xD4000000 | (op << 16) for op in (129, 265, 273, 295)],
|
||||
}
|
||||
# Values copied from the AMD XML snapshot: VOP3 encodings of VOP2 forms.
|
||||
for name, opcode, data_format in (
|
||||
@@ -191,6 +191,14 @@ def snapshot():
|
||||
["SRC1", data_format, "OPR_SRC_NOLDS", 32, True, False, False, True],
|
||||
],
|
||||
}
|
||||
variants[("V_CMP_LT_I32", "ENC_VOP3")] = {
|
||||
"instruction": "V_CMP_LT_I32", "encoding": "ENC_VOP3", "opcode": 129,
|
||||
"operands": [
|
||||
["VDST", "FMT_NUM_M64", "OPR_SREG", 64, False, True, False, True],
|
||||
["SRC0", I32, "OPR_SRC", 32, True, False, False, True],
|
||||
["SRC1", I32, "OPR_SRC_NOLDS", 32, True, False, False, True],
|
||||
],
|
||||
}
|
||||
return {
|
||||
"source": {"sha256": SHA},
|
||||
"encodings": {
|
||||
@@ -309,6 +317,18 @@ def _variant(of, opcode):
|
||||
}
|
||||
|
||||
|
||||
def compare_variants():
|
||||
reg = vector_compares()
|
||||
rule = gen.OPERAND_RULES["vop3_cmp_vgpr2"]
|
||||
reg["operand_rules"]["vop3_cmp_vgpr2"] = dict(
|
||||
copy.deepcopy(rule["shape"]), unsupported=sorted(rule["unsupported"])
|
||||
)
|
||||
reg["encoding_variant"] = [
|
||||
dict(_variant("V_CMP_LT_I32", 129), operands="vop3_cmp_vgpr2")
|
||||
]
|
||||
return reg
|
||||
|
||||
|
||||
def compares():
|
||||
reg = registry()
|
||||
reg["form"] += [
|
||||
@@ -860,6 +880,25 @@ class Validate(unittest.TestCase):
|
||||
def test_accepts_encoding_variants(self):
|
||||
self.assertEqual(self.errors(variants()), [])
|
||||
|
||||
def test_compare_variant_routes_mask_to_sdst(self):
|
||||
reg = compare_variants()
|
||||
self.assertEqual(self.errors(reg), [])
|
||||
row = gen.variant_row(reg, reg["encoding_variant"][0])
|
||||
self.assertEqual((row["vcc"], row["width"], row["wave"]), ("sdst_lane_mask", 32, "wave32"))
|
||||
|
||||
def test_rejects_mismatched_compare_variant_destination(self):
|
||||
reg = compare_variants()
|
||||
form(reg, "V_CMP_LT_I32")["vcc"] = "unchanged"
|
||||
self.rejects(reg, "requires a base destination contract of lane_mask, got unchanged")
|
||||
|
||||
reg = compare_variants()
|
||||
reg["operand_rules"]["vop3_cmp_vgpr2"]["dst"]["class"] = "vgpr"
|
||||
self.rejects(reg, "operand rule vop3_cmp_vgpr2: declaration differs")
|
||||
|
||||
snap = snapshot()
|
||||
snap["variants"][("V_CMP_LT_I32", "ENC_VOP3")]["operands"][0][2] = "OPR_VGPR"
|
||||
self.rejects(compare_variants(), "VDST is not a scalar mask destination in the XML", snap)
|
||||
|
||||
def test_rejects_a_variant_of_an_undeclared_form(self):
|
||||
reg = variants()
|
||||
reg["encoding_variant"].append(_variant("V_MUL_HI_I32_I24", 266))
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
//! MUL_I32_I24, MUL_HI_I32_I24, MUL_U32_U24, MUL_HI_U32_U24, MIN/MAX (I32,
|
||||
//! U32), XNOR and ADD/SUB/SUBREV_NC_U32 (any SRC0 a VOPC compare takes; a
|
||||
//! shift-and-add multiplier and floor division for the high half, the ripple
|
||||
//! adder for add and subtract), VOP3 add-no-carry, MUBUF
|
||||
//! adder for add and subtract), VOP3A integer arithmetic and compares, MUBUF
|
||||
//! load/store and the two waits plus `s_endpgm`. Anything else is a controlled
|
||||
//! error. The arithmetic shift is evaluated as a floor division by a power of
|
||||
//! two rather than with a host signed shift, so the oracle does not share the
|
||||
@@ -72,18 +72,20 @@ enum Insn {
|
||||
/// SOPK opcode 0 or 2-16 on SGPR `SDST` (s0-s105) with the raw SIMM16.
|
||||
SImm(u32, u8, u16),
|
||||
BranchScc0(usize),
|
||||
BranchMaskZero {
|
||||
BranchMask {
|
||||
target: usize,
|
||||
register: usize,
|
||||
nonzero: bool,
|
||||
},
|
||||
Branch(usize),
|
||||
VMov(u8, Src),
|
||||
VMovFromSgpr(u8, u8),
|
||||
/// `v_mov_b32_e32 vD, vcc_lo`.
|
||||
VMovFromVcc(u8),
|
||||
/// VOPC compare into VCC_LO: relation 0 f, 1 lt, 2 eq, 3 le, 4 gt, 5 ne, 6 ge, 7 t.
|
||||
/// Integer vector compare into `dst`: relation 0 f, 1 lt, 2 eq, 3 le, 4 gt, 5 ne, 6 ge, 7 t.
|
||||
/// `bits` is 16, 32 or 64; 64-bit register operands name the low register of a pair.
|
||||
VCmp {
|
||||
dst: u8,
|
||||
relation: u8,
|
||||
signed: bool,
|
||||
bits: u32,
|
||||
@@ -207,6 +209,7 @@ fn run_wave(program: &[(usize, Insn)], wave: &[u32]) -> Result<Vec<u32>, String>
|
||||
return Ok(lanes.iter().map(|lane| lane.written.unwrap()).collect());
|
||||
}
|
||||
Insn::VCmp {
|
||||
dst,
|
||||
relation,
|
||||
signed,
|
||||
bits,
|
||||
@@ -226,10 +229,12 @@ fn run_wave(program: &[(usize, Insn)], wave: &[u32]) -> Result<Vec<u32>, String>
|
||||
offset,
|
||||
)
|
||||
.map(|mask| {
|
||||
sgpr[106] = Some(mask);
|
||||
// VCC_HI has no known value after a compare (contract 3).
|
||||
sgpr[107] = None;
|
||||
vcc_lane_derived = execution_mask != 0;
|
||||
sgpr[usize::from(dst)] = Some(mask);
|
||||
if dst == 106 {
|
||||
// VCC_HI has no known value after a VCC compare (contract 3).
|
||||
sgpr[107] = None;
|
||||
vcc_lane_derived = execution_mask != 0;
|
||||
}
|
||||
None
|
||||
})
|
||||
}
|
||||
@@ -301,12 +306,17 @@ fn run_wave(program: &[(usize, Insn)], wave: &[u32]) -> Result<Vec<u32>, String>
|
||||
index_of(program, target, offset).map(Some)
|
||||
}
|
||||
}),
|
||||
Insn::BranchMaskZero { target, register } => {
|
||||
Insn::BranchMask {
|
||||
target,
|
||||
register,
|
||||
nonzero,
|
||||
} => {
|
||||
let takes = |mask| (mask != 0) == nonzero;
|
||||
if register == 106 && vcc_lane_derived {
|
||||
let live = lanes.iter().find(|lane| lane.error.is_none()).unwrap();
|
||||
check_runtime_region(program, pc, target, live, &sgpr, execution_mask, offset)
|
||||
.and_then(|()| {
|
||||
if sgpr[106] == Some(0) {
|
||||
if takes(sgpr[106].unwrap()) {
|
||||
index_of(program, target, offset).map(Some)
|
||||
} else {
|
||||
Ok(None)
|
||||
@@ -316,7 +326,7 @@ fn run_wave(program: &[(usize, Insn)], wave: &[u32]) -> Result<Vec<u32>, String>
|
||||
sgpr[register]
|
||||
.ok_or_else(|| format!("{offset:#x}: uninitialized mask"))
|
||||
.and_then(|mask| {
|
||||
if mask == 0 {
|
||||
if takes(mask) {
|
||||
index_of(program, target, offset).map(Some)
|
||||
} else {
|
||||
Ok(None)
|
||||
@@ -690,7 +700,7 @@ fn read_vgpr(lane: &Lane, reg: u8, offset: usize) -> Result<u32, String> {
|
||||
lane.vgpr[reg as usize].ok_or_else(|| format!("{offset:#x}: uninitialized v{reg}"))
|
||||
}
|
||||
|
||||
/// Evaluate one VOPC compare for the whole wave and return the new VCC_LO.
|
||||
/// Evaluate one integer vector compare for the whole wave and return its mask.
|
||||
fn compare(
|
||||
lanes: &[Lane],
|
||||
sgpr: &[Option<u32>; 128],
|
||||
@@ -1214,7 +1224,7 @@ fn decode(code: &[u8]) -> Result<Vec<(usize, Insn)>, String> {
|
||||
offset += len;
|
||||
}
|
||||
for &(at, insn) in &program {
|
||||
if let Insn::Branch(target) | Insn::BranchScc0(target) | Insn::BranchMaskZero { target, .. } =
|
||||
if let Insn::Branch(target) | Insn::BranchScc0(target) | Insn::BranchMask { target, .. } =
|
||||
insn
|
||||
&& !program.iter().any(|(boundary, _)| *boundary == target)
|
||||
{
|
||||
@@ -1315,6 +1325,7 @@ fn decode_one(code: &[u8], offset: usize) -> Result<(Insn, usize), String> {
|
||||
return Err(fail("unsupported VOPC operand"));
|
||||
}
|
||||
let insn = Insn::VCmp {
|
||||
dst: 106,
|
||||
relation: relation as u8,
|
||||
signed,
|
||||
bits,
|
||||
@@ -1337,14 +1348,34 @@ fn decode_one(code: &[u8], offset: usize) -> Result<(Insn, usize), String> {
|
||||
let insn = Insn::VInt(vop2_op, (first >> 17) as u8, src0, (first >> 9) as u8);
|
||||
return Ok((insn, len));
|
||||
}
|
||||
if first & 0xffff_0000 == 0xd525_0000 {
|
||||
let second = word(code, offset + 4)?;
|
||||
if first >> 26 == 0b110101 {
|
||||
let dst = first as u8;
|
||||
let opcode = (first >> 16) & 0x3ff;
|
||||
let second = word(code, offset + 4).map_err(|_| fail("truncated VOP3A"))?;
|
||||
let src0 = second & 0x1ff;
|
||||
let src1 = (second >> 9) & 0x1ff;
|
||||
if first & 0xff00 != 0 || second >> 18 != 128 || src0 < 256 || src1 < 256 {
|
||||
return Err(fail("bad VOP3 add form"));
|
||||
return Err(fail("unsupported VOP3A modifiers or sources"));
|
||||
}
|
||||
return Ok((Insn::VAddNc(first as u8, src0 as u8, src1 as u8), 8));
|
||||
// Guide §§3.9, 12.7.1 and 12.9.1: re-encoded VOP2 writes a VGPR,
|
||||
// while VOPC uses the destination field for the scalar mask.
|
||||
let (src0, src1) = (src0 as u8, src1 as u8);
|
||||
let insn = match opcode {
|
||||
128..=135 | 192..=199 if dst <= 106 => Insn::VCmp {
|
||||
dst,
|
||||
relation: (opcode % 8) as u8,
|
||||
signed: opcode < 192,
|
||||
bits: 32,
|
||||
src0: CmpSrc::Vgpr(src0),
|
||||
src1,
|
||||
},
|
||||
293 => Insn::VAddNc(dst, src0, src1),
|
||||
265..=268 | 273..=276 | 286 | 294..=295 => {
|
||||
Insn::VInt(opcode - 256, dst, CmpSrc::Vgpr(src0), src1)
|
||||
}
|
||||
_ => return Err(fail("unsupported VOP3A opcode or destination")),
|
||||
};
|
||||
return Ok((insn, 8));
|
||||
}
|
||||
// SOP1: ENCODING 0b10_1111101 in bits 23-31, SDST 16-22, OP 8-15.
|
||||
let sop1_op = (first >> 8) & 0xff;
|
||||
@@ -1429,15 +1460,16 @@ fn decode_one(code: &[u8], offset: usize) -> Result<(Insn, usize), String> {
|
||||
return Ok((Insn::BranchScc0(branch_target(first, offset)?), 4));
|
||||
}
|
||||
let tested_register = match first >> 16 {
|
||||
0xbf86 => Some(106),
|
||||
0xbf86 | 0xbf87 => Some(106),
|
||||
0xbf88 => Some(126),
|
||||
_ => None,
|
||||
};
|
||||
if let Some(register) = tested_register {
|
||||
return Ok((
|
||||
Insn::BranchMaskZero {
|
||||
Insn::BranchMask {
|
||||
target: branch_target(first, offset)?,
|
||||
register,
|
||||
nonzero: first >> 16 == 0xbf87,
|
||||
},
|
||||
4,
|
||||
));
|
||||
|
||||
@@ -0,0 +1,302 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
//! Wave32 VOP3A integer compares. Guide §3.9 permits an SGPR destination in
|
||||
//! the 64-bit encoding and describes the fully rewritten per-lane mask.
|
||||
//! A Wave32 mask has 32 bits (§2.1), so SDST consumes one 32-bit SGPR (§5.2).
|
||||
//! The opcode relations are in §12.9, the re-encoding in §12.9.1, and the
|
||||
//! VOP3A fields in §13.3.4. These are spec-derived expectations.
|
||||
|
||||
#[path = "operand_domains/harness.rs"]
|
||||
#[allow(dead_code)]
|
||||
mod harness;
|
||||
#[path = "../independent_ref.rs"]
|
||||
mod independent_ref;
|
||||
|
||||
use harness::{Case, words};
|
||||
|
||||
const FORMS: [(u32, &str); 16] = [
|
||||
(128, "v_cmp_f_i32"),
|
||||
(129, "v_cmp_lt_i32"),
|
||||
(130, "v_cmp_eq_i32"),
|
||||
(131, "v_cmp_le_i32"),
|
||||
(132, "v_cmp_gt_i32"),
|
||||
(133, "v_cmp_ne_i32"),
|
||||
(134, "v_cmp_ge_i32"),
|
||||
(135, "v_cmp_t_i32"),
|
||||
(192, "v_cmp_f_u32"),
|
||||
(193, "v_cmp_lt_u32"),
|
||||
(194, "v_cmp_eq_u32"),
|
||||
(195, "v_cmp_le_u32"),
|
||||
(196, "v_cmp_gt_u32"),
|
||||
(197, "v_cmp_ne_u32"),
|
||||
(198, "v_cmp_ge_u32"),
|
||||
(199, "v_cmp_t_u32"),
|
||||
];
|
||||
const VALUES: [u32; 10] = [
|
||||
0,
|
||||
1,
|
||||
0x7fff_ffff,
|
||||
0x8000_0000,
|
||||
u32::MAX,
|
||||
0x00ff_ffff,
|
||||
0x0080_0000,
|
||||
0xff80_0000,
|
||||
0x0100_0001,
|
||||
0xff00_0003,
|
||||
];
|
||||
const MASKS: [u32; 4] = [u32::MAX, 0x5555_5555, 0x8000_0001, 0];
|
||||
|
||||
fn passes(op: u32, a: u32, b: u32) -> bool {
|
||||
let operand = |value: u32| {
|
||||
if op < 192 {
|
||||
i64::from(value as i32)
|
||||
} else {
|
||||
i64::from(value)
|
||||
}
|
||||
};
|
||||
let (a, b) = (operand(a), operand(b));
|
||||
match op & 7 {
|
||||
// D[threadId] = 0.
|
||||
0 => false,
|
||||
// D[threadId] = (S0 < S1).
|
||||
1 => a < b,
|
||||
// D[threadId] = (S0 == S1).
|
||||
2 => a == b,
|
||||
// D[threadId] = (S0 <= S1).
|
||||
3 => a <= b,
|
||||
// D[threadId] = (S0 > S1).
|
||||
4 => a > b,
|
||||
// D[threadId] = (S0 <> S1).
|
||||
5 => a != b,
|
||||
// D[threadId] = (S0 >= S1).
|
||||
6 => a >= b,
|
||||
// D[threadId] = 1.
|
||||
_ => true,
|
||||
}
|
||||
}
|
||||
|
||||
fn expected_mask(op: u32, exec: u32, wave: &[u32], bound: u32, reverse: bool) -> u32 {
|
||||
// §3.9: VCC[n] = EXEC[n] & (test passed for thread[n]).
|
||||
// §3.9 uses the same result for the alternate scalar destination.
|
||||
wave.iter().enumerate().fold(0, |mask, (n, &x)| {
|
||||
let (a, b) = if reverse { (bound, x) } else { (x, bound) };
|
||||
mask | (exec & (u32::from(passes(op, a, b)) << n))
|
||||
})
|
||||
}
|
||||
|
||||
fn vop3(op: u32, dst: u32, reverse: bool) -> [u32; 2] {
|
||||
let (a, b) = if reverse { (511, 257) } else { (257, 511) };
|
||||
[0xd400_0000 | op << 16 | dst, a | b << 9 | 128 << 18]
|
||||
}
|
||||
|
||||
fn smov(dst: u32, value: u32) -> [u32; 2] {
|
||||
[0xbe80_03ff | dst << 16, value]
|
||||
}
|
||||
|
||||
fn setup(bound: u32, exec: u32) -> Vec<u32> {
|
||||
let mut code = vec![0xe030_2000, 0x8000_0100, 0xbf8c_3f70]; // load v1
|
||||
code.extend([0x7ffe_02ff, bound]); // v255 = literal
|
||||
code.extend(smov(126, exec));
|
||||
code
|
||||
}
|
||||
|
||||
fn store(mut code: Vec<u32>) -> Vec<u8> {
|
||||
code.extend([0xe070_2000, 0x8001_0200, 0xbbfd_0000, 0xbf81_0000]);
|
||||
words(&code)
|
||||
}
|
||||
|
||||
fn mask_cases() -> Vec<Case> {
|
||||
let mut cases = Vec::new();
|
||||
for (op, name) in FORMS {
|
||||
for bound in VALUES {
|
||||
for reverse in [false, true] {
|
||||
for exec in MASKS {
|
||||
for (lanes, dst) in [(7, 106), (32, 106), (45, 106), (45, 0), (45, 105)] {
|
||||
let mut code = setup(bound, exec);
|
||||
// Give the old VCC bits on both sides of EXEC.
|
||||
code.extend(smov(106, 0xa5a5_5a5a));
|
||||
code.extend(vop3(op, dst, reverse));
|
||||
code.extend([0xbefe_03c1, 0x7e04_0200 | dst]);
|
||||
let input: Vec<_> = VALUES.into_iter().cycle().take(lanes).collect();
|
||||
let expected = input
|
||||
.chunks(32)
|
||||
.flat_map(|wave| {
|
||||
let mask = expected_mask(op, exec, wave, bound, reverse);
|
||||
std::iter::repeat_n(mask, wave.len())
|
||||
})
|
||||
.collect();
|
||||
cases.push(Case {
|
||||
form: name,
|
||||
family: if dst == 106 { "vcc_lo" } else { "sgpr" },
|
||||
label: format!("{name} s{dst}, bound={bound:#x}, reverse={reverse}, EXEC={exec:#x}, {lanes} lanes"),
|
||||
code: store(code),
|
||||
input,
|
||||
expected,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cases
|
||||
}
|
||||
|
||||
fn branch_cases() -> Vec<Case> {
|
||||
let mut cases = Vec::new();
|
||||
for (op, name) in FORMS {
|
||||
for dst in [0, 105, 106] {
|
||||
for exec in MASKS {
|
||||
for old_vcc in [0, 0xa5a5_5a5a] {
|
||||
for nonzero in [false, true] {
|
||||
let scc = old_vcc != 0;
|
||||
let mut code = setup(0, u32::MAX);
|
||||
// Seed s1 to detect an accidental second SGPR write to s0:s1.
|
||||
code.extend(vop3(199, 1, false));
|
||||
code.extend(smov(106, old_vcc));
|
||||
code.push(if scc { 0xbf06_8080 } else { 0xbf06_8180 });
|
||||
code.extend([0x7e04_0280, 0x7e08_0280, 0x7e0c_0284]); // v2 = v4 = 0, v6 = 4
|
||||
code.extend(smov(126, exec));
|
||||
code.extend(vop3(op, dst, false));
|
||||
code.extend([
|
||||
0x7e08_0281, // v4 = 1 only where EXEC was set
|
||||
0xbefe_03c1,
|
||||
// Independent bits for the VCC edge, SCC, and EXEC.
|
||||
if nonzero { 0xbf87_0001 } else { 0xbf86_0001 },
|
||||
0x7e04_0282, // v2 = 2 on fallthrough
|
||||
0xbf84_0001,
|
||||
0x3a04_0d02, // v2 ^= 4 if SCC = 1
|
||||
0x3a04_0902, // v2 ^= v4
|
||||
0x7e06_0201,
|
||||
0x3a04_0702, // v2 ^= s1
|
||||
0x7e06_026a,
|
||||
0x3a04_0702, // v2 ^= VCC_LO
|
||||
]);
|
||||
// The two waves give opposite results for several relations.
|
||||
let input: Vec<_> = std::iter::repeat_n(1, 32)
|
||||
.chain(std::iter::repeat_n(u32::MAX, 13))
|
||||
.collect();
|
||||
let mut expected = Vec::new();
|
||||
for wave in input.chunks(32) {
|
||||
let mask = expected_mask(op, exec, wave, 0, false);
|
||||
let vcc = if dst == 106 { mask } else { old_vcc };
|
||||
// §12.5: if (VCC == 0) / if (VCC != 0), PC = PC + signext(SIMM16 * 4) + 4.
|
||||
let taken = (vcc != 0) == nonzero;
|
||||
let s1 = u32::MAX >> (32 - wave.len());
|
||||
let marker = (u32::from(scc) << 2) | (u32::from(!taken) << 1);
|
||||
expected.extend(
|
||||
wave.iter()
|
||||
.enumerate()
|
||||
.map(|(n, _)| marker ^ ((exec >> n) & 1) ^ s1 ^ vcc),
|
||||
);
|
||||
}
|
||||
cases.push(Case {
|
||||
form: name,
|
||||
family: "vcc branch and flags",
|
||||
label: format!(
|
||||
"{name} s{dst}, EXEC={exec:#x}, VCC={old_vcc:#x}, NZ={nonzero}"
|
||||
),
|
||||
code: store(code),
|
||||
input,
|
||||
expected,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cases
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vop3_compare_matches_the_guide() {
|
||||
let masks = mask_cases();
|
||||
let branches = branch_cases();
|
||||
assert_eq!(masks.len(), 16 * 10 * 2 * 4 * 5);
|
||||
assert_eq!(branches.len(), 16 * 3 * 4 * 2 * 2);
|
||||
for case in masks.iter().chain(&branches) {
|
||||
assert_eq!(
|
||||
xenora_ref::execute(&case.code, &case.input).unwrap(),
|
||||
case.expected,
|
||||
"reference: {}",
|
||||
case.label
|
||||
);
|
||||
assert_eq!(
|
||||
independent_ref::execute(&case.code, &case.input).unwrap(),
|
||||
case.expected,
|
||||
"independent: {}",
|
||||
case.label
|
||||
);
|
||||
}
|
||||
eprintln!(
|
||||
"vop3_compare: {} mask and {} branch/flag cases per CPU interpreter",
|
||||
masks.len(),
|
||||
branches.len()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vop3_compare_rejects_excluded_operands_and_modifiers() {
|
||||
let mut count = 0;
|
||||
for (op, name) in FORMS {
|
||||
let setup = setup(7, u32::MAX);
|
||||
let offset = setup.len() * 4;
|
||||
let [head, tail] = vop3(op, 106, false);
|
||||
let mut check = |alu: &[u32]| {
|
||||
let mut code = setup.clone();
|
||||
code.extend(alu);
|
||||
let code = if alu.len() == 1 {
|
||||
words(&code)
|
||||
} else {
|
||||
// A successful decode would read its mask here and complete.
|
||||
code.push(0x7e04_026a);
|
||||
store(code)
|
||||
};
|
||||
let input = [1, 2];
|
||||
let err = xenora_ref::execute(&code, &input).expect_err(name);
|
||||
assert_eq!(err.offset, offset, "{name}: {alu:08x?} {err:?}");
|
||||
let err = independent_ref::execute(&code, &input).expect_err(name);
|
||||
assert!(
|
||||
err.starts_with(&format!("{offset:#x}:")),
|
||||
"{name}: {alu:08x?} {err}"
|
||||
);
|
||||
count += 1;
|
||||
};
|
||||
// ABS, OP_SEL and CLAMP in word 0. OMOD and NEG in word 1.
|
||||
for bit in 8..16 {
|
||||
check(&[head | 1 << bit, tail]);
|
||||
}
|
||||
for bit in 27..32 {
|
||||
check(&[head, tail | 1 << bit]);
|
||||
}
|
||||
for selector in 0..256 {
|
||||
check(&[head, (tail & !511) | selector]);
|
||||
check(&[head, (tail & !(511 << 9)) | selector << 9]);
|
||||
}
|
||||
for selector in (0..512).filter(|&s| s != 128) {
|
||||
check(&[head, (tail & !(511 << 18)) | selector << 18]);
|
||||
}
|
||||
for dst in 107..=255 {
|
||||
check(&[(head & !255) | dst, tail]);
|
||||
}
|
||||
check(&[head]);
|
||||
}
|
||||
assert_eq!(count, 16 * (13 + 512 + 511 + 149 + 1));
|
||||
eprintln!("vop3_compare: {count} rejections per CPU interpreter");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "requires a native Metal device with API and shader validation"]
|
||||
fn vop3_vcc_compare_matches_the_guide_on_native_metal() {
|
||||
assert_eq!(std::env::var("MTL_DEBUG_LAYER").as_deref(), Ok("1"));
|
||||
assert_eq!(std::env::var("MTL_SHADER_VALIDATION").as_deref(), Ok("1"));
|
||||
let cases: Vec<_> = mask_cases()
|
||||
.into_iter()
|
||||
.filter(|case| case.family == "vcc_lo")
|
||||
.collect();
|
||||
let (failures, programs) = harness::check_metal(&cases);
|
||||
failures.assert_none("native Metal disagrees with the guide");
|
||||
eprintln!(
|
||||
"vop3_compare: {} Metal cases in {programs} programs",
|
||||
cases.len()
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,246 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
//! Wave32 VOP3A integer ALU forms. AMD RDNA 2 ISA guide §§12.7, 12.7.1,
|
||||
//! 12.12 and 13.3.4. The expectations use the guide's arithmetic per lane.
|
||||
|
||||
#[path = "operand_domains/harness.rs"]
|
||||
#[allow(dead_code)]
|
||||
mod harness;
|
||||
#[path = "../independent_ref.rs"]
|
||||
mod independent_ref;
|
||||
|
||||
use harness::{Case, words};
|
||||
|
||||
const FORMS: [(u32, &str); 11] = [
|
||||
(265, "v_mul_i32_i24"),
|
||||
(266, "v_mul_hi_i32_i24"),
|
||||
(267, "v_mul_u32_u24"),
|
||||
(268, "v_mul_hi_u32_u24"),
|
||||
(273, "v_min_i32"),
|
||||
(274, "v_max_i32"),
|
||||
(275, "v_min_u32"),
|
||||
(276, "v_max_u32"),
|
||||
(286, "v_xnor_b32"),
|
||||
(294, "v_sub_nc_u32"),
|
||||
(295, "v_subrev_nc_u32"),
|
||||
];
|
||||
const VALUES: [u32; 12] = [
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
0x007f_ffff,
|
||||
0x0080_0000,
|
||||
0x0080_0001,
|
||||
0x00ff_ffff,
|
||||
0xff80_0000,
|
||||
0xff00_0003,
|
||||
0x7fff_ffff,
|
||||
0x8000_0000,
|
||||
u32::MAX,
|
||||
];
|
||||
const MASKS: [u32; 4] = [u32::MAX, 0x5555_5555, 0x8000_0001, 0];
|
||||
|
||||
fn expected(op: u32, a: u32, b: u32) -> u32 {
|
||||
// S.i24 is bits 23:0 sign-extended from bit 23; S.u24 is zero-extended.
|
||||
let i24 = |x: u32| (i64::from(x & 0x7f_ffff)) - i64::from(x & 0x80_0000);
|
||||
let u24 = |x: u32| i64::from(x & 0xff_ffff);
|
||||
match op {
|
||||
// D.i32 = S0.i24 * S1.i24.
|
||||
265 => (i24(a) * i24(b)) as u32,
|
||||
// D.i32 = (S0.i24 * S1.i24)>>32.
|
||||
266 => (i24(a) * i24(b)).div_euclid(1 << 32) as u32,
|
||||
// D.u32 = S0.u24 * S1.u24.
|
||||
267 => (u24(a) * u24(b)) as u32,
|
||||
// D.u32 = (S0.u24 * S1.u24)>>32.
|
||||
268 => (u24(a) * u24(b)).div_euclid(1 << 32) as u32,
|
||||
// D.i32 = (S0.i32 < S1.i32 ? S0.i32 : S1.i32).
|
||||
273 => (a as i32).min(b as i32) as u32,
|
||||
// D.i32 = (S0.i32 >= S1.i32 ? S0.i32 : S1.i32).
|
||||
274 => (a as i32).max(b as i32) as u32,
|
||||
// D.u32 = (S0.u32 < S1.u32 ? S0.u32 : S1.u32).
|
||||
275 => a.min(b),
|
||||
// D.u32 = (S0.u32 >= S1.u32 ? S0.u32 : S1.u32).
|
||||
276 => a.max(b),
|
||||
// D.u32 = ~(S0.u32 ^ S1.u32).
|
||||
286 => !(a ^ b),
|
||||
// D.u32 = S0.u32 - S1.u32.
|
||||
294 => (i64::from(a) - i64::from(b)) as u32,
|
||||
// D.u32 = S1.u32 - S0.u32.
|
||||
295 => (i64::from(b) - i64::from(a)) as u32,
|
||||
_ => unreachable!("test only uses the listed forms"),
|
||||
}
|
||||
}
|
||||
|
||||
/// VOP3A: OP 25:16, VDST 7:0, three 9-bit sources, inline zero at SRC2.
|
||||
fn vop3(op: u32, dst: u32, a: u32, b: u32) -> [u32; 2] {
|
||||
[
|
||||
0xd400_0000 | op << 16 | dst,
|
||||
(256 + a) | (256 + b) << 9 | 128 << 18,
|
||||
]
|
||||
}
|
||||
|
||||
fn vmov(dst: u32, value: u32) -> [u32; 2] {
|
||||
[0x7e00_02ff | dst << 17, value]
|
||||
}
|
||||
|
||||
fn smov(dst: u32, value: u32) -> [u32; 2] {
|
||||
[0xbe80_03ff | dst << 16, value]
|
||||
}
|
||||
|
||||
fn setup(b: u32, exec: u32, scc: bool) -> Vec<u32> {
|
||||
let mut code = vec![0xe030_2000, 0x8000_0100, 0xbf8c_3f70]; // load v1
|
||||
code.extend(vmov(255, b));
|
||||
code.extend(vmov(2, 0xabad_1dea));
|
||||
code.extend(smov(106, 0x1357_9bdf));
|
||||
code.push(if scc { 0xbf06_8080 } else { 0xbf06_8180 });
|
||||
code.extend(smov(126, exec));
|
||||
code
|
||||
}
|
||||
|
||||
fn finish(mut code: Vec<u32>, dst: u32) -> Vec<u8> {
|
||||
// Restore EXEC, read D and VCC_LO, and XOR in v1 when SCC is set.
|
||||
code.extend([
|
||||
0xbefe_03c1,
|
||||
0x7e04_0300 | dst,
|
||||
0x7e0c_026a,
|
||||
0x3a04_0506,
|
||||
0xbf84_0001,
|
||||
0x3a04_0501,
|
||||
0xe070_2000,
|
||||
0x8001_0200,
|
||||
0xbbfd_0000,
|
||||
0xbf81_0000,
|
||||
]);
|
||||
words(&code)
|
||||
}
|
||||
|
||||
fn cases() -> Vec<Case> {
|
||||
let mut cases = Vec::new();
|
||||
for (op, name) in FORMS {
|
||||
for b in VALUES {
|
||||
for (dst, src0, src1) in [
|
||||
(2, 1, 255),
|
||||
(2, 255, 1),
|
||||
(1, 1, 255),
|
||||
(255, 1, 255),
|
||||
(255, 255, 255),
|
||||
] {
|
||||
for exec in MASKS {
|
||||
for lanes in [7, 32, 45] {
|
||||
let scc = dst == 255;
|
||||
let mut code = setup(b, exec, scc);
|
||||
code.extend(vop3(op, dst, src0, src1));
|
||||
let input: Vec<_> = VALUES.into_iter().cycle().take(lanes).collect();
|
||||
let expected = input
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(lane, &x)| {
|
||||
let read = |reg| if reg == 1 { x } else { b };
|
||||
// Guide §3.3: a disabled lane retains its previous VGPR.
|
||||
let d = if exec & (1 << (lane % 32)) != 0 {
|
||||
expected(op, read(src0), read(src1))
|
||||
} else {
|
||||
match dst {
|
||||
1 => x,
|
||||
255 => b,
|
||||
_ => 0xabad_1dea,
|
||||
}
|
||||
};
|
||||
d ^ 0x1357_9bdf ^ if scc { x } else { 0 }
|
||||
})
|
||||
.collect();
|
||||
cases.push(Case {
|
||||
form: name,
|
||||
family: "vop3 integer",
|
||||
label: format!("{name} v{dst}, v{src0}, v{src1} ({b:#x}), EXEC={exec:#x}, {lanes} lanes"),
|
||||
code: finish(code, dst),
|
||||
input,
|
||||
expected,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
cases
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vop3_integer_matches_the_guide() {
|
||||
let cases = cases();
|
||||
assert_eq!(cases.len(), 11 * 12 * 5 * 4 * 3);
|
||||
for case in &cases {
|
||||
assert_eq!(
|
||||
xenora_ref::execute(&case.code, &case.input).unwrap(),
|
||||
case.expected,
|
||||
"reference: {}",
|
||||
case.label
|
||||
);
|
||||
assert_eq!(
|
||||
independent_ref::execute(&case.code, &case.input).unwrap(),
|
||||
case.expected,
|
||||
"independent: {}",
|
||||
case.label
|
||||
);
|
||||
}
|
||||
eprintln!("vop3_integer: {} cases per CPU interpreter", cases.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn vop3_integer_rejects_excluded_operands_and_modifiers() {
|
||||
let mut count = 0;
|
||||
for (op, name) in FORMS {
|
||||
let setup = setup(7, u32::MAX, false);
|
||||
let offset = setup.len() * 4;
|
||||
let [head, tail] = vop3(op, 2, 1, 255);
|
||||
let mut check = |alu: &[u32]| {
|
||||
let mut code = setup.clone();
|
||||
code.extend(alu);
|
||||
let code = if alu.len() == 1 {
|
||||
words(&code)
|
||||
} else {
|
||||
finish(code, 2)
|
||||
};
|
||||
let input = [1, 2];
|
||||
let err = xenora_ref::execute(&code, &input).expect_err(name);
|
||||
assert_eq!(err.offset, offset, "{name}: {alu:08x?} {err:?}");
|
||||
let err = independent_ref::execute(&code, &input).expect_err(name);
|
||||
assert!(
|
||||
err.starts_with(&format!("{offset:#x}:")),
|
||||
"{name}: {alu:08x?} {err}"
|
||||
);
|
||||
count += 1;
|
||||
};
|
||||
// ABS, OP_SEL and CLAMP in word 0. OMOD and NEG in word 1.
|
||||
for bit in 8..16 {
|
||||
check(&[head | 1 << bit, tail]);
|
||||
}
|
||||
for bit in 27..32 {
|
||||
check(&[head, tail | 1 << bit]);
|
||||
}
|
||||
for selector in 0..256 {
|
||||
check(&[head, (tail & !511) | selector]);
|
||||
check(&[head, (tail & !(511 << 9)) | selector << 9]);
|
||||
}
|
||||
for selector in (0..512).filter(|&s| s != 128) {
|
||||
check(&[head, (tail & !(511 << 18)) | selector << 18]);
|
||||
}
|
||||
check(&[head]);
|
||||
}
|
||||
assert_eq!(count, 11 * (13 + 512 + 511 + 1));
|
||||
eprintln!("vop3_integer: {count} rejections per CPU interpreter");
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "requires a native Metal device with API and shader validation"]
|
||||
fn vop3_integer_matches_the_guide_on_native_metal() {
|
||||
assert_eq!(std::env::var("MTL_DEBUG_LAYER").as_deref(), Ok("1"));
|
||||
assert_eq!(std::env::var("MTL_SHADER_VALIDATION").as_deref(), Ok("1"));
|
||||
let cases = cases();
|
||||
let (failures, programs) = harness::check_metal(&cases);
|
||||
failures.assert_none("native Metal disagrees with the guide");
|
||||
eprintln!(
|
||||
"vop3_integer: {} Metal cases in {programs} programs",
|
||||
cases.len()
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user