Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

pokepark uses fb format with no alpha channel, force to 255

Layle321367b180d7
diff --git a/crates/backend-wgpu/src/action.rs b/crates/backend-wgpu/src/action.rs
index 31860b3..f9c47f6 100644
--- a/crates/backend-wgpu/src/action.rs
+++ b/crates/backend-wgpu/src/action.rs
@@ -667,6 +667,7 @@ impl GxRenderer {
*stride,
*depth_copy,
*is_intensity,
+ *alpha_supported,
);
if *clear {
diff --git a/crates/backend-wgpu/src/lib.rs b/crates/backend-wgpu/src/lib.rs
index 07af1ac..f843a5f 100644
--- a/crates/backend-wgpu/src/lib.rs
+++ b/crates/backend-wgpu/src/lib.rs
@@ -421,6 +421,7 @@ pub(crate) struct PendingWriteback {
pub copy_format: gecko::flipper::gx::texture::CopyFormat,
pub stride: u32,
pub swap_bgra: bool,
+ pub force_opaque: bool,
}
impl GxRenderer {
diff --git a/crates/backend-wgpu/src/render.rs b/crates/backend-wgpu/src/render.rs
index d39fc0e..6561c2e 100644
--- a/crates/backend-wgpu/src/render.rs
+++ b/crates/backend-wgpu/src/render.rs
@@ -10,6 +10,8 @@ pub(crate) struct XfbCopyUniforms {
dst_size: [f32; 2],
gamma: f32,
filter_mode: u32,
+ force_opaque: u32,
+ _pad: [u32; 3],
}
pub(crate) struct EfbPackPipelines {
@@ -64,7 +66,7 @@ pub(crate) struct EfbDepthPackPipelines {
#[derive(Clone, Copy)]
enum EfbCopySource {
- Color { intensity: bool },
+ Color { intensity: bool, alpha_supported: bool },
Depth,
}
@@ -277,6 +279,8 @@ impl GxRenderer {
dst_size: [scaled_w as f32, scaled_dst_h as f32],
gamma,
filter_mode: 0,
+ force_opaque: 0,
+ _pad: [0; 3],
};
queue.write_buffer(&self.xfb_copy_uniform_buffer, 0, bytemuck::bytes_of(&uniforms));
@@ -375,7 +379,7 @@ impl GxRenderer {
copy_format: CopyFormat,
source: EfbCopySource,
) {
- if let EfbCopySource::Color { intensity } = source {
+ if let EfbCopySource::Color { intensity, .. } = source {
debug_assert!(
self.efb_pack_pipelines.for_color(copy_format, intensity).is_some(),
"cache_efb_copy called with depth-only copy format {copy_format:?}",
@@ -405,6 +409,14 @@ impl GxRenderer {
EfbCopySource::Color { .. } => u32::from(half),
EfbCopySource::Depth => 0,
},
+ force_opaque: u32::from(matches!(
+ source,
+ EfbCopySource::Color {
+ alpha_supported: false,
+ ..
+ }
+ )),
+ _pad: [0; 3],
};
let uniform_buffer = match source {
EfbCopySource::Color { .. } => &self.xfb_copy_uniform_buffer,
@@ -439,7 +451,7 @@ impl GxRenderer {
multiview_mask: None,
});
let (pipeline, bind_group) = match source {
- EfbCopySource::Color { intensity } => (
+ EfbCopySource::Color { intensity, .. } => (
self.efb_pack_pipelines.for_color(copy_format, intensity).unwrap(),
&self.xfb_copy_bind_group,
),
@@ -710,6 +722,7 @@ impl GxRenderer {
stride: u32,
depth_copy: bool,
is_intensity: bool,
+ alpha_supported: bool,
) {
tracing::debug!(
dest_addr = format!("{dest_addr:#010X}"),
@@ -808,6 +821,8 @@ impl GxRenderer {
dst_size: [readback_width as f32, readback_height as f32],
gamma: 1.0,
filter_mode: if mipmap { 2 } else { 0 },
+ force_opaque: 0,
+ _pad: [0; 3],
};
queue.write_buffer(
&self.efb_color_readback_uniform_buffer,
@@ -901,6 +916,7 @@ impl GxRenderer {
copy_format: copy_format_enum,
stride,
swap_bgra,
+ force_opaque: !alpha_supported,
});
self.cache_efb_copy(
@@ -915,6 +931,7 @@ impl GxRenderer {
copy_format_enum,
EfbCopySource::Color {
intensity: is_intensity,
+ alpha_supported,
},
);
}
@@ -952,6 +969,7 @@ impl GxRenderer {
copy_format: copy_format_enum,
stride,
swap_bgra: false,
+ force_opaque: false,
});
}
@@ -980,6 +998,8 @@ impl GxRenderer {
dst_size: [encode_w as f32, encode_h as f32],
gamma: 1.0,
filter_mode: 0,
+ force_opaque: 0,
+ _pad: [0; 3],
};
queue.write_buffer(&self.efb_depth_resolve_uniform_buffer, 0, bytemuck::bytes_of(&uniforms));
self.efb_depth_resolve_uniform_write_pending = true;
@@ -1223,6 +1243,12 @@ impl GxRenderer {
}
w.staging.unmap();
+ if w.force_opaque {
+ for pixel in rgba.chunks_exact_mut(4) {
+ pixel[3] = 255;
+ }
+ }
+
let encoded = texture::encode_from_rgba(&rgba, w.width as usize, w.height as usize, w.copy_format);
let row_bytes = texture::encoded_row_bytes(w.width, w.copy_format);
let row_count = texture::encoded_row_count(w.height, w.copy_format);
diff --git a/crates/backend-wgpu/src/shaders/efb_pack.wgsl b/crates/backend-wgpu/src/shaders/efb_pack.wgsl
index c150d21..62e9bb1 100644
--- a/crates/backend-wgpu/src/shaders/efb_pack.wgsl
+++ b/crates/backend-wgpu/src/shaders/efb_pack.wgsl
@@ -3,13 +3,14 @@ struct Uniforms {
dst_size: vec2<f32>,
gamma: f32,
filter_mode: u32,
+ force_opaque: u32,
};
@group(0) @binding(0) var<uniform> u: Uniforms;
@group(0) @binding(1) var efb_color: texture_2d<f32>;
@group(0) @binding(2) var efb_color_sampler: sampler;
-fn fetch(pos: vec2<f32>) -> vec4<f32> {
+fn fetch_raw(pos: vec2<f32>) -> vec4<f32> {
let dst_size = max(u.dst_size, vec2<f32>(1.0, 1.0));
if (u.filter_mode == 1u) {
@@ -28,3 +29,8 @@ fn fetch(pos: vec2<f32>) -> vec4<f32> {
let coord = vec2<i32>(src_pixel);
return textureLoad(efb_color, coord, 0);
}
+
+fn fetch(pos: vec2<f32>) -> vec4<f32> {
+ let color = fetch_raw(pos);
+ return vec4<f32>(color.rgb, select(color.a, 1.0, u.force_opaque != 0u));
+}