A GameCube/Wii emulator and debugger written in Rust.
refactor cmd structure
Layleb1af410d0008
diff --git a/crates/backend-wgpu/src/render.rs b/crates/backend-wgpu/src/render.rsindex a29cd87..6b3e2d9 100644--- a/crates/backend-wgpu/src/render.rs+++ b/crates/backend-wgpu/src/render.rs@@ -3,7 +3,7 @@ use crate::pipeline::PipelineKey;use crate::triangulate::{self, GpuVertex, align_up};use crate::{DrawUniforms, FrameUniforms, GxRenderer, helpers, texture};use encase::{ShaderType as _, UniformBuffer};-use gecko::flipper::gx::draw::DrawCommands;+use gecko::flipper::gx::draw::{DrawCommands, GxCommand};use gecko::flipper::gx::regs::{MagFilter, MinFilter, WrapMode};use glam::{Mat4, UVec4, Vec4};@@ -37,7 +37,8 @@ impl GxRenderer {}fn prepare_resources(&mut self, device: &wgpu::Device, queue: &wgpu::Queue, commands: &DrawCommands, ram: &[u8]) {- for dc in &commands.commands {+ for cmd in &commands.commands {+ let GxCommand::Draw(dc) = cmd else { continue };for desc in dc.textures.iter().flatten() {let key = (desc.ram_addr, desc.width, desc.height, desc.format);self.texture_cache.entry(key).or_insert_with(|| {@@ -87,7 +88,8 @@ impl GxRenderer {let mut frame_uniform_bytes: Vec<u8> = Vec::new();let mut draw_call_indices: Vec<usize> = Vec::new();- for (dc_idx, dc) in commands.commands.iter().enumerate() {+ for (dc_idx, cmd) in commands.commands.iter().enumerate() {+ let GxCommand::Draw(dc) = cmd else { continue };let prev_len = self.scratch_vertices.len();triangulate::triangulate_into(dc, &mut self.scratch_vertices);let added = self.scratch_vertices.len() - prev_len;@@ -193,7 +195,7 @@ impl GxRenderer {// Pre-build bind groups for each unique texture/sampler configuration.for &dc_idx in draw_call_indices {- let dc = &commands.commands[dc_idx];+ let GxCommand::Draw(dc) = &commands.commands[dc_idx] else { continue };let mut tex_keys: [Option<_>; 8] = [None; 8];let mut sampler_keys: [Option<_>; 8] = [None; 8];@@ -279,7 +281,9 @@ impl GxRenderer {rpass.set_vertex_buffer(0, self.vertex_buffer.slice(..));for (index, (first_vertex, vertex_count)) in self.scratch_draws.iter().copied().enumerate() {- let dc = &commands.commands[draw_call_indices[index]];+ let GxCommand::Draw(dc) = &commands.commands[draw_call_indices[index]] else {+ continue;+ };let pipeline_key = PipelineKey::from_draw_call(dc);let pipeline = &self.pipeline_cache[&pipeline_key];rpass.set_pipeline(pipeline);diff --git a/crates/dbglib/src/windows/gx.rs b/crates/dbglib/src/windows/gx.rsindex 9cbc074..ee60e2a 100644--- a/crates/dbglib/src/windows/gx.rs+++ b/crates/dbglib/src/windows/gx.rs@@ -50,7 +50,11 @@ pub fn show_gx(ctx: &Context, open: &mut bool, gx: &GraphicsProcessor, mmio: &Mm.id_salt("draw_calls").max_height(500.0).show(ui, |ui| {- for (i, call) in dc.commands.iter().enumerate() {+ for (i, cmd) in dc.commands.iter().enumerate() {+ let gecko::flipper::gx::draw::GxCommand::Draw(call) = cmd else {+ ui.label(format!("[{i:>3}] EFB Copy"));+ continue;+ };let has_tex = call.textures[0].is_some();let heading = RichText::new(format!("[{i:>3}] {:?} x {} verts tev={} {}",diff --git a/crates/gecko/src/flipper/gx/draw.rs b/crates/gecko/src/flipper/gx/draw.rsindex 85084c5..675985a 100644--- a/crates/gecko/src/flipper/gx/draw.rs+++ b/crates/gecko/src/flipper/gx/draw.rs@@ -175,19 +175,40 @@ impl std::ops::Mul for Matrix4 {}}+pub enum GxCommand {+ Draw(DrawCall),+ CopyEfb(EfbCopyCmd),+}++pub struct EfbCopyCmd {+ pub src_x: u32,+ pub src_y: u32,+ pub src_w: u32,+ pub src_h: u32,+ pub dest_addr: u32,+ pub dest_stride: u32,+ pub copy_to_xfb: bool,+ pub clear: bool,+ pub clear_color: [f32; 4],+ pub clear_z: f32,+ pub half: bool,+}+#[derive(Default)]pub struct DrawCommands {pub projection: Matrix4,- pub commands: Vec<DrawCall>,+ pub commands: Vec<GxCommand>,vertex_pool: Vec<Vec<Vertex>>,}impl DrawCommands {pub fn recycle(&mut self) {- for dc in self.commands.drain(..) {- let mut buf = dc.vertices;- buf.clear();- self.vertex_pool.push(buf);+ for cmd in self.commands.drain(..) {+ if let GxCommand::Draw(dc) = cmd {+ let mut buf = dc.vertices;+ buf.clear();+ self.vertex_pool.push(buf);+ }}}diff --git a/crates/gecko/src/flipper/gx/vertex.rs b/crates/gecko/src/flipper/gx/vertex.rsindex d4e7187..565c0a7 100644--- a/crates/gecko/src/flipper/gx/vertex.rs+++ b/crates/gecko/src/flipper/gx/vertex.rs@@ -80,7 +80,7 @@ impl GraphicsProcessor {// Resolve TEV color registers to f32 arrays for the snapshotlet tev_color_regs = self.resolve_tev_color_regs();- self.draw_commands.commands.push(draw::DrawCall {+ self.draw_commands.commands.push(draw::GxCommand::Draw(draw::DrawCall {primitive,vertices,modelview,@@ -105,7 +105,7 @@ impl GraphicsProcessor {alpha_ctrl: regs::ChanCtrl::from_raw(self.xf_mem[XF_ALPHA_CTRL0]),ambient_color: unpack_rgba(self.xf_mem[XF_AMBIENT_COLOR0]),material_color: unpack_rgba(self.xf_mem[XF_MATERIAL_COLOR0]),- });+ }));}fn build_vertex_format(&self, cmd: u8) -> VertexFormat {