A GameCube/Wii emulator and debugger written in Rust.
renderdoc markers
Layledadc7dc95df4
diff --git a/crates/backend-wgpu/src/action.rs b/crates/backend-wgpu/src/action.rsindex b6ad77d..bb75383 100644--- a/crates/backend-wgpu/src/action.rs+++ b/crates/backend-wgpu/src/action.rs@@ -76,8 +76,9 @@ impl GxRenderer {height,rgba,} => {+ let texture_label = format!("gx_tex addr={:#010x} size={}x{}", *id, *width, *height);let tex = device.create_texture(&wgpu::TextureDescriptor {- label: Some("gx_tex"),+ label: Some(&texture_label),size: wgpu::Extent3d {width: *width,height: *height,@@ -395,7 +396,15 @@ impl GxRenderer {});}- let mut encoder = device.create_command_encoder(&Default::default());+ let group_label = format!(+ "GX Draw Flush: draws={} vertices={}",+ self.scratch_draws.len(),+ self.scratch_vertices.len()+ );+ let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {+ label: Some("gx_draw_flush_encoder"),+ });+ encoder.push_debug_group(&group_label);{let needs_initial_clear = self.efb_needs_clear;self.efb_needs_clear = false;@@ -442,11 +451,32 @@ impl GxRenderer {multiview_mask: None,});rpass.set_vertex_buffer(0, self.vertex_buffer.slice(..));+ if needs_initial_clear {+ rpass.insert_debug_marker("EFB initial clear: color=black depth=1.0");+ } else {+ rpass.insert_debug_marker("EFB load existing color/depth");+ }+ if crate::EFB_SAMPLE_COUNT == 1 {+ rpass.insert_debug_marker("EFB target: resolved color, no MSAA resolve");+ } else {+ rpass.insert_debug_marker("EFB target: MSAA color, resolve to efb_color_resolved");+ }for (index, (first_vertex, vertex_count)) in self.scratch_draws.iter().copied().enumerate() {+ let draw_label = format!("GX Draw {index}: first_vertex={first_vertex} vertex_count={vertex_count}");+ rpass.push_debug_group(&draw_label);let pipeline_key = &self.draw_pipeline_keys[index];let pipeline = &self.pipeline_cache[pipeline_key];rpass.set_pipeline(pipeline);+ let pipeline_marker = format!(+ "Pipeline: blend={} z={} z_write={} color_update={} alpha_update={}",+ pipeline_key.blend_enable,+ pipeline_key.z_enable,+ pipeline_key.z_write,+ pipeline_key.color_update,+ pipeline_key.alpha_update+ );+ rpass.insert_debug_marker(&pipeline_marker);let bg_key = &self.draw_bg_keys[index];let bind_group = &self.bind_group_cache[bg_key];@@ -454,6 +484,8 @@ impl GxRenderer {let frame_offset = (index * frame_stride) as u32;let draw_offset = (index as u64 * self.draw_uniform_stride) as u32;rpass.set_bind_group(0, bind_group, &[frame_offset, draw_offset]);+ let bind_marker = format!("Bind group offsets: frame={frame_offset} draw={draw_offset}");+ rpass.insert_debug_marker(&bind_marker);let vp = &self.draw_viewports[index];let max_dim = target_width.max(target_height) as f32;@@ -475,10 +507,17 @@ impl GxRenderer {let sc_w = sc.w.max(1).min(target_width.saturating_sub(sc.x));let sc_h = sc.h.max(1).min(target_height.saturating_sub(sc.y));rpass.set_scissor_rect(sc.x, sc.y, sc_w, sc_h);+ let raster_marker = format!(+ "Raster state: viewport=({:.1},{:.1} {:.1}x{:.1}) scissor=({},{} {}x{})",+ vp.x, vp.y, vp_w, vp_h, sc.x, sc.y, sc_w, sc_h+ );+ rpass.insert_debug_marker(&raster_marker);rpass.draw(first_vertex..first_vertex + vertex_count, 0..1);+ rpass.pop_debug_group();}}+ encoder.pop_debug_group();queue.submit([encoder.finish()]);}diff --git a/crates/backend-wgpu/src/clear.rs b/crates/backend-wgpu/src/clear.rsindex 824af46..ce0e0f2 100644--- a/crates/backend-wgpu/src/clear.rs+++ b/crates/backend-wgpu/src/clear.rs@@ -6,6 +6,19 @@ struct ClearUniforms {_pad: [f32; 3],}+fn clear_mask_label(color_update: bool, alpha_update: bool, z_update: bool) -> &'static str {+ match (color_update, alpha_update, z_update) {+ (true, true, true) => "rgba+z",+ (true, false, true) => "rgb+z",+ (false, true, true) => "alpha+z",+ (false, false, true) => "z",+ (true, true, false) => "rgba",+ (true, false, false) => "rgb",+ (false, true, false) => "alpha",+ (false, false, false) => "none",+ }+}+pub(crate) struct EfbClear {pipeline_all_depth: wgpu::RenderPipeline,pipeline_rgb_depth: wgpu::RenderPipeline,@@ -238,14 +251,14 @@ impl EfbClear {}// im gonna vomit- let pipeline = match (color_update, alpha_update, z_update) {- (true, true, true) => &self.pipeline_all_depth,- (true, false, true) => &self.pipeline_rgb_depth,- (false, true, true) => &self.pipeline_alpha_depth,- (false, false, true) => &self.pipeline_none_depth,- (true, true, false) => &self.pipeline_all,- (true, false, false) => &self.pipeline_rgb,- (false, true, false) => &self.pipeline_alpha,+ let (pipeline, pipeline_label) = match (color_update, alpha_update, z_update) {+ (true, true, true) => (&self.pipeline_all_depth, "all+depth"),+ (true, false, true) => (&self.pipeline_rgb_depth, "rgb+depth"),+ (false, true, true) => (&self.pipeline_alpha_depth, "alpha+depth"),+ (false, false, true) => (&self.pipeline_none_depth, "depth-only"),+ (true, true, false) => (&self.pipeline_all, "all"),+ (true, false, false) => (&self.pipeline_rgb, "rgb"),+ (false, true, false) => (&self.pipeline_alpha, "alpha"),(false, false, false) => unreachable!(),};@@ -256,7 +269,18 @@ impl EfbClear {};queue.write_buffer(&self.uniform_buffer, 0, bytemuck::bytes_of(&uniforms));- let mut encoder = device.create_command_encoder(&Default::default());+ let group_label = format!(+ "EFB Clear rect=({},{} {}x{}) masks={}",+ x,+ y,+ w,+ h,+ clear_mask_label(color_update, alpha_update, z_update)+ );+ let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {+ label: Some("efb_clear_encoder"),+ });+ encoder.push_debug_group(&group_label);{let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {label: Some("efb_clear_region"),@@ -291,10 +315,18 @@ impl EfbClear {});rpass.set_pipeline(pipeline);+ let pipeline_marker = format!("Clear pipeline: {pipeline_label}");+ rpass.insert_debug_marker(&pipeline_marker);rpass.set_bind_group(0, &self.bind_group, &[]);rpass.set_scissor_rect(x, y, w, h);+ let values_marker = format!(+ "Clear values: color=({:.3},{:.3},{:.3},{:.3}) depth={:.6}",+ color[0], color[1], color[2], color[3], depth+ );+ rpass.insert_debug_marker(&values_marker);rpass.draw(0..3, 0..1);}+ encoder.pop_debug_group();queue.submit([encoder.finish()]);}}diff --git a/crates/backend-wgpu/src/lib.rs b/crates/backend-wgpu/src/lib.rsindex ec6b9d5..ff2d0e4 100644--- a/crates/backend-wgpu/src/lib.rs+++ b/crates/backend-wgpu/src/lib.rs@@ -217,12 +217,12 @@ impl GxRenderer {});}let bind_group_layout = device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {- label: None,+ label: Some("gx_bind_group_layout"),entries: &layout_entries,});let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {- label: None,+ label: Some("gx_pipeline_layout"),bind_group_layouts: &[&bind_group_layout],immediate_size: 0,});diff --git a/crates/backend-wgpu/src/render.rs b/crates/backend-wgpu/src/render.rsindex 4aac952..ebc5aad 100644--- a/crates/backend-wgpu/src/render.rs+++ b/crates/backend-wgpu/src/render.rs@@ -87,8 +87,9 @@ impl GxRenderer {}let entry = self.xfb_copies.entry(id).or_insert_with(|| {+ let texture_label = format!("xfb_copy_tmp id={id} size={width}x{dst_h}");let tex = device.create_texture(&wgpu::TextureDescriptor {- label: Some("xfb_copy_tmp"),+ label: Some(&texture_label),size: wgpu::Extent3d {width,height: dst_h,@@ -110,8 +111,9 @@ impl GxRenderer {// Recreate if size changed.let existing_size = entry.0.size();if existing_size.width != width || existing_size.height != dst_h {+ let texture_label = format!("xfb_copy_tmp id={id} size={width}x{dst_h}");let tex = device.create_texture(&wgpu::TextureDescriptor {- label: Some("xfb_copy_tmp"),+ label: Some(&texture_label),size: wgpu::Extent3d {width,height: dst_h,@@ -131,9 +133,16 @@ impl GxRenderer {*entry = (tex, view);}- let mut encoder = device.create_command_encoder(&Default::default());let needs_shader_copy = dst_h != height || (gamma - 1.0).abs() > f32::EPSILON;+ let group_label = format!(+ "CopyXfb id={id} src=({src_x},{src_y} {width}x{height}) dst_h={dst_h} gamma={gamma:.3} clear={clear}"+ );+ let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {+ label: Some("copy_xfb_encoder"),+ });+ encoder.push_debug_group(&group_label);if needs_shader_copy {+ encoder.insert_debug_marker("CopyXfb path: shader copy for scale/gamma");let uniforms = XfbCopyUniforms {src_rect: [src_x as f32, src_y as f32, width as f32, height as f32],dst_size: [width as f32, dst_h as f32],@@ -180,6 +189,10 @@ impl GxRenderer {});rpass.set_pipeline(&self.xfb_copy_pipeline);rpass.set_bind_group(0, &bind_group, &[]);+ let marker = format!(+ "XFB shader uniforms: src=({src_x},{src_y} {width}x{height}) dst={width}x{dst_h} gamma={gamma:.3}"+ );+ rpass.insert_debug_marker(&marker);rpass.draw(0..3, 0..1);}} else {@@ -188,6 +201,7 @@ impl GxRenderer {// the image even when no scaling or gamma is requested.// TODO: We could just call it a trade-off and just have it all go// through? It looks a bit fuzzy, has it's own charm.+ encoder.insert_debug_marker("CopyXfb path: raw texture copy");encoder.copy_texture_to_texture(wgpu::TexelCopyTextureInfo {texture: &self.efb_texture,@@ -212,6 +226,7 @@ impl GxRenderer {},);}+ encoder.pop_debug_group();queue.submit([encoder.finish()]);// Region-scoped EFB clear after copy (if requested).@@ -251,8 +266,9 @@ impl GxRenderer {// Resize the XFB output texture if the frame dimensions changed.let cur = self.xfb_texture.size();if cur.width != width || cur.height != height {+ let texture_label = format!("xfb_accum size={width}x{height}");self.xfb_texture = device.create_texture(&wgpu::TextureDescriptor {- label: Some("xfb_accum"),+ label: Some(&texture_label),size: wgpu::Extent3d {width,height,@@ -270,7 +286,11 @@ impl GxRenderer {self.xfb_view = self.xfb_texture.create_view(&Default::default());}- let mut encoder = device.create_command_encoder(&Default::default());+ let group_label = format!("PresentXfb size={width}x{height} parts={}", parts.len());+ let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {+ label: Some("present_xfb_encoder"),+ });+ encoder.push_debug_group(&group_label);// Don't clear the XFB: let previous content persist so partial// frames show the last valid content instead of a black flash.@@ -280,6 +300,8 @@ impl GxRenderer {for part in parts {let Some((tex, _)) = self.xfb_copies.get(&part.id) else {tracing::warn!(id = part.id, "present_xfb: XFB copy not found in cache, skipping part");+ let marker = format!("PresentXfb skip: missing part id={}", part.id);+ encoder.insert_debug_marker(&marker);continue;};let src_size = tex.size();@@ -287,8 +309,15 @@ impl GxRenderer {let height = src_size.height.min(xfb_size.height.saturating_sub(part.offset_y));if width == 0 || height == 0 {tracing::warn!(id = part.id, "present_xfb: zero-area XFB part after clamping, skipping");+ let marker = format!("PresentXfb skip: zero-area part id={}", part.id);+ encoder.insert_debug_marker(&marker);continue;}+ let marker = format!(+ "XFB part id={} dst=({},{} {}x{})",+ part.id, part.offset_x, part.offset_y, width, height+ );+ encoder.insert_debug_marker(&marker);encoder.copy_texture_to_texture(wgpu::TexelCopyTextureInfo {texture: tex,@@ -314,6 +343,7 @@ impl GxRenderer {);}+ encoder.pop_debug_group();queue.submit([encoder.finish()]);self.xfb_has_content = true;}@@ -445,9 +475,18 @@ impl GxRenderer {let staging = self.efb_readback_staging.as_ref().unwrap();// Submit the EFB -> staging copy.+ let group_label = format!(+ "CopyEfbToTexture addr={dest_addr:#010x} src=({src_x},{src_y} {width}x{height}) fmt={copy_format_enum:?} mip={mipmap} stride={stride} depth={depth_copy}"+ );let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor {- label: Some("efb_to_texture_copy"),+ label: Some("efb_to_texture_copy_encoder"),});+ encoder.push_debug_group(&group_label);+ let copy_marker = format!(+ "EFB readback copy: bytes_per_row={} staging_size={}",+ bytes_per_row, staging_size+ );+ encoder.insert_debug_marker(©_marker);encoder.copy_texture_to_buffer(wgpu::TexelCopyTextureInfo {texture: &self.efb_texture,@@ -473,6 +512,7 @@ impl GxRenderer {depth_or_array_layers: 1,},);+ encoder.pop_debug_group();queue.submit([encoder.finish()]);// Map and wait. This stalls the renderer worker (not the emudiff --git a/crates/backend-wgpu/src/sink.rs b/crates/backend-wgpu/src/sink.rsindex aa2c9c4..68c54b1 100644--- a/crates/backend-wgpu/src/sink.rs+++ b/crates/backend-wgpu/src/sink.rs@@ -94,7 +94,7 @@ impl Renderer {],});let blit_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {- label: None,+ label: Some("blit_layout"),bind_group_layouts: &[&blit_bind_group_layout],immediate_size: 0,});@@ -185,7 +185,10 @@ impl Renderer {});drop(output);- let mut encoder = self.device.create_command_encoder(&Default::default());+ let mut encoder = self.device.create_command_encoder(&wgpu::CommandEncoderDescriptor {+ label: Some("xfb_blit_encoder"),+ });+ encoder.push_debug_group("XFB Blit To Surface");{let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {label: Some("xfb_blit"),@@ -205,8 +208,10 @@ impl Renderer {});rpass.set_pipeline(&self.blit_pipeline);rpass.set_bind_group(0, &bind_group, &[]);+ rpass.insert_debug_marker("Draw fullscreen XFB blit");rpass.draw(0..3, 0..1);}+ encoder.pop_debug_group();queue.submit([encoder.finish()]);}}