A GameCube/Wii emulator and debugger written in Rust.
remove non-xfb efb texture override
Layleac64fdb02c98
diff --git a/crates/backend-wgpu/src/action.rs b/crates/backend-wgpu/src/action.rsindex e2699c5..2c9d42b 100644--- a/crates/backend-wgpu/src/action.rs+++ b/crates/backend-wgpu/src/action.rs@@ -200,11 +200,6 @@ impl GxRenderer {self.scratch_draws.push((prev_len as u32, added as u32));}- GxAction::CopyEfb(copy) => {- self.flush_pending_draws(device, queue);- self.execute_efb_copy(device, queue, copy);- }-GxAction::CopyXfb {id,src_x,@@ -377,7 +372,13 @@ impl GxRenderer {if vp.x.is_finite() && vp.y.is_finite() && vp_w.is_finite() && vp_h.is_finite() {rpass.set_viewport(vp.x, vp.y, vp_w, vp_h, vp.min_depth, vp.max_depth);} else {- tracing::warn!(x = vp.x, y = vp.y, w = vp_w, h = vp_h, "non-finite viewport, skipping set_viewport");+ tracing::warn!(+ x = vp.x,+ y = vp.y,+ w = vp_w,+ h = vp_h,+ "non-finite viewport, skipping set_viewport"+ );}let sc = &self.draw_scissors[index];diff --git a/crates/backend-wgpu/src/lib.rs b/crates/backend-wgpu/src/lib.rsindex b187144..30fd473 100644--- a/crates/backend-wgpu/src/lib.rs+++ b/crates/backend-wgpu/src/lib.rs@@ -323,7 +323,6 @@ impl GxRenderer {let efb_depth_view = efb_depth_texture.create_view(&Default::default());// XFB accumulation texture. Holds the composited output of all- // CopyEfb(copy_to_xfb) ops for the current frame.let xfb_texture = device.create_texture(&wgpu::TextureDescriptor {label: Some("xfb_accum"),size: wgpu::Extent3d {diff --git a/crates/backend-wgpu/src/render.rs b/crates/backend-wgpu/src/render.rsindex 0e2e4e7..1201026 100644--- a/crates/backend-wgpu/src/render.rs+++ b/crates/backend-wgpu/src/render.rs@@ -1,8 +1,7 @@use crate::{FrameUniforms, GxRenderer};use crate::{GpuVertex, align_up};use encase::ShaderType as _;-use gecko::flipper::gx::draw::EfbCopyCmd;-use gecko::host::{TextureId, XfbPart};+use gecko::host::XfbPart;impl GxRenderer {pub(crate) fn upload_buffers(&mut self, device: &wgpu::Device, queue: &wgpu::Queue, frame_uniform_bytes: &[u8]) {@@ -39,79 +38,6 @@ impl GxRenderer {queue.write_buffer(&self.vertex_buffer, 0, bytemuck::cast_slice(&self.scratch_vertices));}- pub(crate) fn execute_efb_copy(&mut self, device: &wgpu::Device, queue: &wgpu::Queue, copy: &EfbCopyCmd) {- // Snapshot the EFB region into texture_cache so that a later- // SetTexture referencing dest_addr finds the GPU-side copy- // instead of stale/unwritten RAM data.- let width = copy.src_w.min(crate::EFB_WIDTH.saturating_sub(copy.src_x));- let height = copy.src_h.min(crate::EFB_HEIGHT.saturating_sub(copy.src_y));- if width > 0 && height > 0 {- let id = TextureId(copy.dest_addr);- let tex = device.create_texture(&wgpu::TextureDescriptor {- label: Some("efb_copy_tex"),- size: wgpu::Extent3d {- width,- height,- depth_or_array_layers: 1,- },- mip_level_count: 1,- sample_count: 1,- dimension: wgpu::TextureDimension::D2,- format: self.surface_format,- usage: wgpu::TextureUsages::COPY_DST | wgpu::TextureUsages::TEXTURE_BINDING,- view_formats: &[],- });- let mut encoder = device.create_command_encoder(&Default::default());- encoder.copy_texture_to_texture(- wgpu::TexelCopyTextureInfo {- texture: &self.efb_texture,- mip_level: 0,- origin: wgpu::Origin3d {- x: copy.src_x,- y: copy.src_y,- z: 0,- },- aspect: wgpu::TextureAspect::default(),- },- wgpu::TexelCopyTextureInfo {- texture: &tex,- mip_level: 0,- origin: wgpu::Origin3d::ZERO,- aspect: wgpu::TextureAspect::default(),- },- wgpu::Extent3d {- width,- height,- depth_or_array_layers: 1,- },- );- queue.submit([encoder.finish()]);-- let view = tex.create_view(&Default::default());- self.bind_group_cache- .retain(|key, _| !key.tex_keys.iter().any(|k| *k == Some(id)));- self.texture_cache.insert(id, (tex, view));- }-- if copy.clear {- self.efb_clear.clear_region(- device,- queue,- &self.efb_msaa_view,- &self.efb_view,- &self.efb_depth_view,- crate::EFB_WIDTH,- crate::EFB_HEIGHT,- copy.src_x,- copy.src_y,- copy.src_w,- copy.src_h,- copy.clear_color,- copy.clear_z,- );- }- }-pub(crate) fn execute_copy_xfb(&mut self,device: &wgpu::Device,@@ -128,9 +54,16 @@ impl GxRenderer {let width = src_w.min(crate::EFB_WIDTH.saturating_sub(src_x));let height = src_h.min(crate::EFB_HEIGHT.saturating_sub(src_y));if width == 0 || height == 0 {- tracing::warn!(src_x, src_y, src_w, src_h, "efb_copy: zero-area region after clamping, skipping");+ tracing::warn!(+ src_x,+ src_y,+ src_w,+ src_h,+ "efb_copy: zero-area region after clamping, skipping"+ );return;}+let entry = self.xfb_copies.entry(id).or_insert_with(|| {let tex = device.create_texture(&wgpu::TextureDescriptor {label: Some("xfb_copy_tmp"),diff --git a/crates/gecko/src/flipper/gx.rs b/crates/gecko/src/flipper/gx.rsindex acac938..f6fba6f 100644--- a/crates/gecko/src/flipper/gx.rs+++ b/crates/gecko/src/flipper/gx.rs@@ -10,8 +10,6 @@ pub mod texture;mod vertex;mod xf;-use std::collections::{HashMap, HashSet};-use crate::flipper::gx::constants::{BP_REG_SIZE, CP_REG_SIZE, XF_MEM_SIZE};use crate::flipper::gx::draw::Matrix4;use crate::flipper::gx::regs::{AlphaCompare, BlendMode, TevAlphaEnv, TevColorEnv, TevRegisterH, TevRegisterL, ZMode};@@ -19,6 +17,7 @@ use crate::gamecube::GameCube;use crate::host::{GxAction, RenderSink, XfbPart};use crate::mmio::Mmio;use fifo::FifoCmd;+use std::collections::HashMap;pub struct GraphicsProcessor {pub raise_interrupt: bool,@@ -58,11 +57,6 @@ pub struct GraphicsProcessor {// Hash of the raw texture data at each RAM address; used to detect when// texture content changes and avoid redundant decodes + LoadTexture sends.pub texture_hashes: HashMap<u32, u64>,- // RAM addresses that hold GPU-side EFB copy textures. When a texture is- // bound at one of these addresses, the renderer already has the correct- // content, so we skip the hash check and LoadTexture to avoid overwriting- // the GPU copy with stale RAM data.- pub efb_copy_addrs: HashSet<u32>,}/// A single EFB-to-XFB copy, stored until `present_xfb` computes the layout.@@ -103,7 +97,6 @@ impl GraphicsProcessor {cur_scissor_offset_y: 0,xfb_copies: Vec::new(),texture_hashes: HashMap::new(),- efb_copy_addrs: HashSet::new(),}}@@ -178,12 +171,14 @@ pub fn present_xfb(gc: &mut GameCube) {let delta_pixels = (delta_bytes / 2) as u32;let offset_x = delta_pixels % stride_in_pixels;let offset_y = delta_pixels / stride_in_pixels;+// Real XFB copies always land at row boundaries (offset_x == 0).// A non-zero offset_x means this copy belongs to a different// buffer that happens to sit nearby in memory, reject it? TODOif offset_x != 0 || offset_y >= frame_h as u32 {continue;}+parts.push(XfbPart {id: id as u32,offset_x,diff --git a/crates/gecko/src/flipper/gx/bp.rs b/crates/gecko/src/flipper/gx/bp.rsindex 0610279..09ab26e 100644--- a/crates/gecko/src/flipper/gx/bp.rs+++ b/crates/gecko/src/flipper/gx/bp.rs@@ -153,7 +153,7 @@ impl GraphicsProcessor {let height = (image0.height() + 1) as u32;let ram_addr = image3.ram_addr();let format = image0.format();- let id = TextureId(ram_addr as u32);+ let id = ram_addr as TextureId;tracing::debug!(slot,@@ -166,30 +166,25 @@ impl GraphicsProcessor {"texture descriptor updated");- // If the renderer already holds a GPU-side EFB copy for this- // address, skip the hash check and LoadTexture so we don't- // overwrite it with stale/unwritten RAM data.- if !self.efb_copy_addrs.contains(&(ram_addr as u32)) {- let changed = self::texture_data_changed(&mut self.texture_hashes, ram, ram_addr, width, height, format);-- if changed {- let desc = draw::TextureDescriptor {- ram_addr,- width,- height,- format,- wrap_s: mode0.wrap_s(),- wrap_t: mode0.wrap_t(),- mag_filter: mode0.mag_filter(),- min_filter: mode0.min_filter(),- };- renderer.exec(GxAction::LoadTexture {- id,- width,- height,- rgba: texture::decode_to_rgba(ram, &desc),- });- }+ let changed = self::texture_data_changed(&mut self.texture_hashes, ram, ram_addr, width, height, format);++ if changed {+ let desc = draw::TextureDescriptor {+ ram_addr,+ width,+ height,+ format,+ wrap_s: mode0.wrap_s(),+ wrap_t: mode0.wrap_t(),+ mag_filter: mode0.mag_filter(),+ min_filter: mode0.min_filter(),+ };+ renderer.exec(GxAction::LoadTexture {+ id,+ width,+ height,+ rgba: texture::decode_to_rgba(ram, &desc),+ });}self.cur_textures[slot] = Some(draw::TextureDescriptor {@@ -336,24 +331,7 @@ impl GraphicsProcessor {clear_z,});} else {- // Texture copy (non-XFB). Track the destination so that- // snapshot_texture skips the hash check / LoadTexture for- // this address (the renderer holds the real content).- self.efb_copy_addrs.insert(dest_addr);- let efb_cmd = draw::EfbCopyCmd {- src_x,- src_y,- src_w,- src_h,- dest_addr,- dest_stride,- copy_to_xfb: false,- clear,- clear_color: [r, g, b, a],- clear_z,- half,- };- renderer.exec(GxAction::CopyEfb(efb_cmd));+ let _ = (dest_addr, dest_stride, clear, half, r, g, b, a, clear_z);}}diff --git a/crates/gecko/src/flipper/gx/draw.rs b/crates/gecko/src/flipper/gx/draw.rsindex a32da68..0258bcc 100644--- a/crates/gecko/src/flipper/gx/draw.rs+++ b/crates/gecko/src/flipper/gx/draw.rs@@ -146,18 +146,3 @@ impl std::ops::Mul for Matrix4 {Matrix4(out)}}--#[derive(Debug, Clone)]-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,-}diff --git a/crates/gecko/src/host.rs b/crates/gecko/src/host.rsindex 2572669..4ff625d 100644--- a/crates/gecko/src/host.rs+++ b/crates/gecko/src/host.rs@@ -1,10 +1,6 @@-use crate::flipper::gx::draw::{EfbCopyCmd, Primitive, Scissor, Viewport};+use crate::flipper::gx::draw::{Primitive, Scissor, Viewport};use crate::flipper::gx::regs::{AlphaCompare, BlendMode, ChanCtrl, CullMode, MagFilter, MinFilter, WrapMode, ZMode};-/// Identifies a texture by its RAM base address.-#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]-pub struct TextureId(pub u32);-#[derive(Debug)]pub enum GxAction {// XF@@ -24,7 +20,7 @@ pub enum GxAction {/// Upload pre-decoded texture data. Emitted when texture content at a/// given address changes (detected by hash).LoadTexture {- id: TextureId,+ id: u32,width: u32,height: u32,rgba: Vec<u8>,@@ -33,7 +29,7 @@ pub enum GxAction {/// Bind a previously loaded texture to a TEV texture slot.SetTexture {slot: usize,- id: TextureId,+ id: u32,wrap_s: WrapMode,wrap_t: WrapMode,mag_filter: MagFilter,@@ -45,9 +41,6 @@ pub enum GxAction {/// TEV/lighting snapshot carried here.Draw(DrawData),- /// Trigger an EFB copy.- CopyEfb(EfbCopyCmd),-/// Copy the EFB source region to a temporary texture identified by `id`./// The renderer stores this until the next [`PresentXfb`] composites it/// into the output framebuffer.