mirror of
https://github.com/MacosPorters/betterxen.git
synced 2026-11-26 22:10:44 +00:00
isa: generate complete gfx1030 instruction metadata and identification
The decoder knew 25 hand-matched forms, so any other instruction stopped decoding with no record of what it was or how long it was. A two-stage generator now reduces AMD's public RDNA 2 XML to all 1,460 base forms, with a committed snapshot so CI can check the generated table offline. identify() finds any form's exact length, including literal, SDWA, DPP and NSA words, and the shaders CLI reports discovered against executable forms so metadata coverage is never read as GPU support. Signed-off-by: elforeign <324243036+elforeign@users.noreply.github.com>
This commit is contained in:
1 parent
c12ad2e2f8
commit
62c933051b
16 files changed
+7724
-1
No files matched your search
@@ -2,6 +2,7 @@
|
||||
|
||||
mod demo;
|
||||
mod runner;
|
||||
mod shaders;
|
||||
|
||||
use std::process::ExitCode;
|
||||
|
||||
@@ -40,6 +41,7 @@ fn main() -> ExitCode {
|
||||
},
|
||||
Some("run") => runner::command(std::env::args_os().skip(2)),
|
||||
Some("imports") => imports_command(std::env::args().skip(2).collect()),
|
||||
Some("shaders") => shaders::command(&std::env::args().skip(2).collect::<Vec<_>>()),
|
||||
Some("probe") => {
|
||||
let args: Vec<String> = std::env::args().collect();
|
||||
let mut pe_path: Option<String> = None;
|
||||
@@ -132,7 +134,7 @@ fn main() -> ExitCode {
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
eprintln!("usage: xenora <info|demo|inspect|probe|run|imports>");
|
||||
eprintln!("usage: xenora <info|demo|inspect|probe|run|imports|shaders>");
|
||||
ExitCode::from(2)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
//! `xenora shaders`: instruction inventory and stream inspection.
|
||||
|
||||
use std::process::ExitCode;
|
||||
|
||||
use xenora_decoder::{Architecture, SEMANTIC_FORMS, decode};
|
||||
use xenora_isa::meta::{self, EncodingFamily, FORMS, identify};
|
||||
|
||||
const USAGE: &str = "usage: xenora shaders <coverage [--json] | inspect <gfx1030.bin>>";
|
||||
|
||||
pub fn command(args: &[String]) -> ExitCode {
|
||||
match args.first().map(String::as_str) {
|
||||
Some("coverage") => coverage(args.get(1).map(String::as_str) == Some("--json")),
|
||||
Some("inspect") => match args.get(1) {
|
||||
Some(path) => inspect(path),
|
||||
None => usage(),
|
||||
},
|
||||
_ => usage(),
|
||||
}
|
||||
}
|
||||
|
||||
fn usage() -> ExitCode {
|
||||
eprintln!("{USAGE}");
|
||||
ExitCode::from(2)
|
||||
}
|
||||
|
||||
fn semantic(family: EncodingFamily) -> usize {
|
||||
SEMANTIC_FORMS
|
||||
.iter()
|
||||
.filter(|(_, form_family)| *form_family == family)
|
||||
.count()
|
||||
}
|
||||
|
||||
/// Per-family counts. "Discovered" forms come from AMD's XML and are identified
|
||||
/// with their length; "semantic" forms decode into executable instructions.
|
||||
/// Reference, Metal and native GPU evidence per form stays in docs/status.toml.
|
||||
fn coverage(json: bool) -> ExitCode {
|
||||
let rows: Vec<_> = meta::inventory()
|
||||
.into_iter()
|
||||
.map(|(family, discovered)| (family, discovered, semantic(family)))
|
||||
.collect();
|
||||
let total: usize = rows.iter().map(|row| row.1).sum();
|
||||
let supported: usize = rows.iter().map(|row| row.2).sum();
|
||||
if json {
|
||||
let families: Vec<String> = rows
|
||||
.iter()
|
||||
.map(|(family, discovered, semantic)| {
|
||||
format!(
|
||||
"{{\"family\":\"{}\",\"discovered\":{discovered},\"semantic\":{semantic}}}",
|
||||
family.name()
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
println!(
|
||||
"{{\"architecture\":\"gfx1030\",\"source_sha256\":\"{}\",\"discovered\":{total},\"semantic\":{supported},\"families\":[{}]}}",
|
||||
meta::SOURCE_SHA256,
|
||||
families.join(",")
|
||||
);
|
||||
} else {
|
||||
println!("{:<10} {:>10} {:>9}", "family", "discovered", "semantic");
|
||||
for (family, discovered, semantic) in &rows {
|
||||
println!("{:<10} {discovered:>10} {semantic:>9}", family.name());
|
||||
}
|
||||
println!("{:<10} {total:>10} {supported:>9}", "total");
|
||||
println!("Semantic forms decode for the operand subsets in docs/status.toml only.");
|
||||
}
|
||||
ExitCode::SUCCESS
|
||||
}
|
||||
|
||||
fn inspect(path: &str) -> ExitCode {
|
||||
let bytes = match std::fs::read(path) {
|
||||
Ok(bytes) => bytes,
|
||||
Err(error) => {
|
||||
eprintln!("{path}: {error}");
|
||||
return ExitCode::FAILURE;
|
||||
}
|
||||
};
|
||||
let mut offset = 0;
|
||||
let mut unsupported = 0;
|
||||
let mut count = 0;
|
||||
while offset < bytes.len() {
|
||||
let found = match identify(&bytes[offset..]) {
|
||||
Ok(found) => found,
|
||||
Err(error) => {
|
||||
println!("{offset:#06x} decode failure: {error}");
|
||||
return ExitCode::FAILURE;
|
||||
}
|
||||
};
|
||||
let words: Vec<String> = bytes[offset..offset + found.len]
|
||||
.chunks(4)
|
||||
.map(|chunk| format!("{:08x}", u32::from_le_bytes(chunk.try_into().unwrap())))
|
||||
.collect();
|
||||
let status = match decode(Architecture::Gfx1030, &bytes[offset..offset + found.len]) {
|
||||
Ok(_) => "semantic".to_owned(),
|
||||
Err(error) if SEMANTIC_FORMS.contains(&(found.form.name, found.form.family)) => {
|
||||
format!("unsupported operands: {error}")
|
||||
}
|
||||
Err(_) => "unsupported instruction semantics".to_owned(),
|
||||
};
|
||||
if status != "semantic" {
|
||||
unsupported += 1;
|
||||
}
|
||||
println!(
|
||||
"{offset:#06x} {:<8} {:<28} {:<26} {status}",
|
||||
found.form.family.name(),
|
||||
found.form.name.to_ascii_lowercase(),
|
||||
words.join(" ")
|
||||
);
|
||||
offset += found.len;
|
||||
count += 1;
|
||||
}
|
||||
println!(
|
||||
"{count} instructions inspected against {} gfx1030 forms; {unsupported} not executable",
|
||||
FORMS.len()
|
||||
);
|
||||
ExitCode::SUCCESS
|
||||
}
|
||||
Reference in new issue
Block a user