Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

refactor a bit and get rid of debug tools i havent used in a while

Layleaba93f9ea71b
diff --git a/crates/gecko/src/flipper/gx/jit.rs b/crates/gecko/src/flipper/gx/jit.rs
index ebba208..6de7a28 100644
--- a/crates/gecko/src/flipper/gx/jit.rs
+++ b/crates/gecko/src/flipper/gx/jit.rs
@@ -296,10 +296,7 @@ impl JitVertexEngine {
self.ctx.func.signature = self.parser_sig.clone();
let pointer_ty = self.module.target_config().pointer_type();
- if !builder::build_parser(&mut self.ctx, &mut self.fn_ctx, &mut self.module, pointer_ty, key) {
- // Codegen refused (unsupported feature). Drop the in-progress fn.
- return None;
- }
+ builder::build_parser(&mut self.ctx, &mut self.fn_ctx, &mut self.module, pointer_ty, key);
self.module
.define_function(func_id, &mut self.ctx)
diff --git a/crates/gecko/src/flipper/gx/jit/builder.rs b/crates/gecko/src/flipper/gx/jit/builder.rs
index f575cd7..63f3b17 100644
--- a/crates/gecko/src/flipper/gx/jit/builder.rs
+++ b/crates/gecko/src/flipper/gx/jit/builder.rs
@@ -18,11 +18,7 @@ pub fn build_parser(
module: &mut JITModule,
pointer_ty: ir::Type,
key: VtxKey,
-) -> bool {
- if !self::is_supported() {
- return false;
- }
-
+) {
let isa = module.isa();
let mut bd = FunctionBuilder::new(&mut ctx.func, fn_ctx);
@@ -106,11 +102,6 @@ pub fn build_parser(
bd.ins().return_(&[]);
bd.finalize();
- true
-}
-
-fn is_supported() -> bool {
- std::env::var("GECKO_VTX_JIT_OFF").is_err()
}
pub mod offset {
diff --git a/crates/gecko/src/flipper/gx/jit/validate.rs b/crates/gecko/src/flipper/gx/jit/validate.rs
index ceafe03..9d85c6c 100644
--- a/crates/gecko/src/flipper/gx/jit/validate.rs
+++ b/crates/gecko/src/flipper/gx/jit/validate.rs
@@ -1,6 +1,5 @@
use rustc_hash::FxHashMap;
use std::path::PathBuf;
-use std::sync::OnceLock;
use super::VtxKey;
use crate::host::DrawVertex;
@@ -149,21 +148,17 @@ pub struct MismatchSummary {
}
pub struct VertexJitValidator {
- pub enabled: bool,
pub summary: FxHashMap<(VtxKey, Field), MismatchSummary>,
pub draw_seq: u64,
pub interp_scratch: Vec<DrawVertex>,
- pub use_jit_output_downstream: bool,
}
impl VertexJitValidator {
pub fn new() -> Self {
Self {
- enabled: env_validate_enabled(),
summary: FxHashMap::default(),
draw_seq: 0,
interp_scratch: Vec::with_capacity(256),
- use_jit_output_downstream: !env_use_interp_output(),
}
}
@@ -240,17 +235,3 @@ impl Default for VertexJitValidator {
Self::new()
}
}
-
-fn env_validate_enabled() -> bool {
- static CACHED: OnceLock<bool> = OnceLock::new();
- *CACHED.get_or_init(|| {
- std::env::var("GECKO_VTX_VALIDATE")
- .map(|v| !v.is_empty() && v != "0")
- .unwrap_or(true)
- })
-}
-
-fn env_use_interp_output() -> bool {
- static CACHED: OnceLock<bool> = OnceLock::new();
- *CACHED.get_or_init(|| matches!(std::env::var("GECKO_VTX_VALIDATE_USE").as_deref(), Ok("interp")))
-}
diff --git a/crates/gecko/src/flipper/gx/vertex.rs b/crates/gecko/src/flipper/gx/vertex.rs
index 697d65a..59fab4d 100644
--- a/crates/gecko/src/flipper/gx/vertex.rs
+++ b/crates/gecko/src/flipper/gx/vertex.rs
@@ -901,12 +901,23 @@ fn run_interpreter<const SYSTEM: SystemId>(
vertex_count: usize,
vf: &VertexFormat,
verts: &mut Vec<DrawVertex>,
+) {
+ self::decode_vertices(gp, mmio, data, vertex_count, vf, verts);
+}
+
+fn decode_vertices<const SYSTEM: SystemId>(
+ gp: &mut GraphicsProcessor,
+ mmio: &mut Mmio<SYSTEM>,
+ data: &[u8],
+ vertex_count: usize,
+ vf: &VertexFormat,
+ dest: &mut Vec<DrawVertex>,
) {
let view = mmio.ram_view();
let mut cur = Cursor::new(data);
for _ in 0..vertex_count {
let v = gp.decode_vertex(&mut cur, data, &view, vf);
- verts.push(v);
+ dest.push(v);
}
}
@@ -919,25 +930,14 @@ fn run_validator<const SYSTEM: SystemId>(
data: &[u8],
vertex_count: usize,
vf: &VertexFormat,
- verts: &mut Vec<DrawVertex>,
+ verts: &[DrawVertex],
base: usize,
) {
- if !gp.jit_vtx_validator.enabled {
- return;
- }
-
let mut interp_buf = std::mem::take(&mut gp.jit_vtx_validator.interp_scratch);
interp_buf.clear();
interp_buf.reserve(vertex_count);
- {
- let view = mmio.ram_view();
- let mut cur = Cursor::new(data);
- for _ in 0..vertex_count {
- let v = gp.decode_vertex(&mut cur, data, &view, vf);
- interp_buf.push(v);
- }
- }
+ self::decode_vertices(gp, mmio, data, vertex_count, vf, &mut interp_buf);
let ctx = jit::validate::CompareCtx {
key,
@@ -948,9 +948,5 @@ fn run_validator<const SYSTEM: SystemId>(
let mismatches = jit::validate::compare_draw_vertices(jit_slice, &interp_buf, &ctx);
gp.jit_vtx_validator.record(&ctx, &mismatches);
- if !gp.jit_vtx_validator.use_jit_output_downstream {
- verts[base..base + vertex_count].copy_from_slice(&interp_buf);
- }
-
gp.jit_vtx_validator.interp_scratch = interp_buf;
}
diff --git a/crates/gecko/src/gekko/jit.rs b/crates/gecko/src/gekko/jit.rs
index 2243a23..2296252 100644
--- a/crates/gecko/src/gekko/jit.rs
+++ b/crates/gecko/src/gekko/jit.rs
@@ -98,7 +98,6 @@ pub struct JitEngine<const SYSTEM: SystemId> {
trampoline_fn: TrampolineFn,
block_lookup_table_addr: usize,
block_seq: u64,
- dump_pc: Option<u32>,
}
impl<const SYSTEM: SystemId> JitEngine<SYSTEM> {
@@ -522,9 +521,6 @@ impl<const SYSTEM: SystemId> JitEngine<SYSTEM> {
trampoline_fn,
block_lookup_table_addr,
block_seq: 0,
- dump_pc: std::env::var("GECKO_DUMP_PC")
- .ok()
- .and_then(|s| u32::from_str_radix(s.trim().trim_start_matches("0x"), 16).ok()),
}
}
@@ -964,54 +960,10 @@ impl<const SYSTEM: SystemId> JitEngine<SYSTEM> {
drop(chain);
- let want_dump = self.dump_pc == Some(spec.start_pc);
- if want_dump {
- self.ctx.set_disasm(true);
- }
-
self.module
.define_function(func_id, &mut self.ctx)
.expect("define block");
- if want_dump {
- if let Some(cc) = self.ctx.compiled_code() {
- let path = format!("./profile-dumps/jit-disasm-{:08x}.txt", spec.start_pc);
- let mut s = String::new();
-
- use std::fmt::Write as _;
-
- let _ = writeln!(
- s,
- "; PPC block at {:#010x}, len={} instrs, terminator={:?}",
- spec.start_pc,
- spec.instrs.len(),
- spec.terminator
- );
-
- for (i, &raw) in spec.instrs.iter().enumerate() {
- let pc = spec.pc_of(i);
- let _ = writeln!(s, "; {:08x} {:08x}", pc, raw);
- }
-
- let _ = writeln!(s, "; --- cranelift vcode ---");
- if let Some(vcode) = cc.vcode.as_ref() {
- s.push_str(vcode);
- }
-
- let _ = writeln!(s, "\n; --- emitted bytes ({} bytes) ---", cc.code_buffer().len());
- for chunk in cc.code_buffer().chunks(16) {
- s.push_str("; ");
- for b in chunk {
- let _ = write!(s, "{:02x} ", b);
- }
- s.push('\n');
- }
-
- let _ = std::fs::write(&path, s);
- tracing::info!(pc = format_args!("{:#010x}", spec.start_pc).to_string(), %path, "dumped JIT disasm");
- }
- }
-
self.module.finalize_definitions().expect("finalize");
let entry = self.module.get_finalized_function(func_id) as usize;