Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

merge in and fix the old per texcoord su texture coordinate scaling. fixes the glyphs in mario superstar baseball

Layle4598de1ca07c
diff --git a/crates/backend-wgpu/src/action.rs b/crates/backend-wgpu/src/action.rs
index 7222d27..df4b5fd 100644
--- a/crates/backend-wgpu/src/action.rs
+++ b/crates/backend-wgpu/src/action.rs
@@ -106,6 +106,7 @@ fn build_frame_uniform(
zfreeze_plane: draw.zfreeze.map_or(Vec4::ZERO, |p| {
Vec4::new(p.dx / efb_scale as f32, p.dy / efb_scale as f32, p.c, 1.0)
}),
+ texcoord_scales: pack_u32_slice_to_uvec4x4(&draw.texcoord_scales),
}
}
@@ -455,7 +456,6 @@ impl GxRenderer {
} else {
draw_active_slot_mask(state)
};
- let num_indirect_stages = state.num_indirect_stages;
let next_frame_uniform = (state_changed || self.last_frame_uniform_index.is_none())
.then(|| build_frame_uniform(state, self.current_alpha_compare, self.efb_scale));
if !self.shader_cache.contains_key(&shader_key) {
@@ -499,25 +499,23 @@ impl GxRenderer {
let mut tex_dims = [UVec4::splat(1); 4];
- if num_indirect_stages > 0 {
- for slot in 0..8 {
- if (active >> slot) & 1 == 0 {
- continue;
- }
+ for slot in 0..8 {
+ if (active >> slot) & 1 == 0 {
+ continue;
+ }
- let Some(tid) = &self.current_texture_ids[slot] else {
- continue;
- };
+ let Some(tid) = &self.current_texture_ids[slot] else {
+ continue;
+ };
- let Some((_, tex, _)) = self.texture_cache.get(tid) else {
- continue;
- };
+ let Some((_, tex, _)) = self.texture_cache.get(tid) else {
+ continue;
+ };
- let size = tex.size();
- let c = (slot % 2) * 2;
- tex_dims[slot / 2][c] = size.width;
- tex_dims[slot / 2][c + 1] = size.height;
- }
+ let size = tex.size();
+ let c = (slot % 2) * 2;
+ tex_dims[slot / 2][c] = size.width;
+ tex_dims[slot / 2][c + 1] = size.height;
}
let draw_uniform = DrawUniforms {
diff --git a/crates/backend-wgpu/src/lib.rs b/crates/backend-wgpu/src/lib.rs
index d2a203a..2bc2760 100644
--- a/crates/backend-wgpu/src/lib.rs
+++ b/crates/backend-wgpu/src/lib.rs
@@ -205,13 +205,14 @@ pub(crate) struct FrameUniforms {
pub ztex_op: u32,
pub dst_alpha: u32,
pub zfreeze_plane: glam::Vec4,
+ pub texcoord_scales: [glam::UVec4; 4],
}
pub(crate) const FRAME_UNIFORMS_SIZE: NonZeroU64 = match NonZeroU64::new(std::mem::size_of::<FrameUniforms>() as u64) {
Some(v) => v,
None => panic!("FrameUniforms must be non-zero sized"),
};
-const _: () = assert!(std::mem::size_of::<FrameUniforms>() == 1568);
+const _: () = assert!(std::mem::size_of::<FrameUniforms>() == 1632);
#[repr(C)]
#[derive(Copy, Clone, bytemuck::Pod, bytemuck::Zeroable)]
@@ -219,7 +220,7 @@ pub(crate) struct DrawUniforms {
pub mvp: glam::Mat4,
/// Guest texture dimensions for texmaps 0-7, two slots per
/// vector (slot i at `tex_dims[i / 2]`, xy for even i, zw for odd).
- /// Indirect texturing needs these instead of `textureDimensions`
+ /// Texture-coordinate scaling needs these instead of `textureDimensions`
/// because scaled EFB copies bind a larger GPU texture.
pub tex_dims: [glam::UVec4; 4],
pub tex_lod_bias: [f32; 8],
diff --git a/crates/backend-wgpu/src/shaders/common.wesl b/crates/backend-wgpu/src/shaders/common.wesl
index 4789aeb..b49bd2c 100644
--- a/crates/backend-wgpu/src/shaders/common.wesl
+++ b/crates/backend-wgpu/src/shaders/common.wesl
@@ -42,6 +42,7 @@ struct FrameUniforms {
ztex_op: u32,
dst_alpha: u32,
zfreeze_plane: vec4<f32>,
+ texcoord_scales: array<vec4<u32>, 4>,
};
struct DrawUniforms {
diff --git a/crates/backend-wgpu/src/shaders/main.wesl b/crates/backend-wgpu/src/shaders/main.wesl
index ffcd83d..2e86345 100644
--- a/crates/backend-wgpu/src/shaders/main.wesl
+++ b/crates/backend-wgpu/src/shaders/main.wesl
@@ -1,6 +1,6 @@
import super::common::{FrameUniforms, DrawUniforms, VsIn, VsOut, frame, draw, tex0, tex1, tex2, tex3, tex4, tex5, tex6, tex7, samp0, samp1, samp2, samp3, samp4, samp5, samp6, samp7};
-import super::tev_helpers::{extract_bits, select_texcoord, stq_to_uv, sample_texmap, swizzle_tev_color, tev_color_in, tev_alpha_in};
-import super::tev_indirect::{IndirectSamples, IndirectResult, sample_indirect_textures, apply_indirect, texmap_size};
+import super::tev_helpers::{extract_bits, select_texcoord, texmap_size, texmap_uv, sample_texmap, swizzle_tev_color, tev_color_in, tev_alpha_in};
+import super::tev_indirect::{IndirectSamples, IndirectResult, sample_indirect_textures, apply_indirect};
import super::tev_combiners::{tev_combine_color, tev_combine_alpha};
import super::alpha_test::{alpha_compare, alpha_combine};
import super::lighting::{compute_lighting_c0, compute_lighting_c1};
@@ -187,8 +187,8 @@ fn run_stage(
let ras_channel = (order >> 7u) & 7u;
let stq = select_texcoord(in, texcoord_idx);
- let direct_uv = stq_to_uv(stq);
let direct_size = texmap_size(texmap_idx);
+ let direct_uv = texmap_uv(stq, texcoord_idx, direct_size);
let indirect = apply_indirect(ind_cmd, direct_uv, direct_size, presampled, (*state).running_uv);
(*state).running_uv = indirect.uv;
diff --git a/crates/backend-wgpu/src/shaders/tev_helpers.wesl b/crates/backend-wgpu/src/shaders/tev_helpers.wesl
index f837b31..aa17b07 100644
--- a/crates/backend-wgpu/src/shaders/tev_helpers.wesl
+++ b/crates/backend-wgpu/src/shaders/tev_helpers.wesl
@@ -1,4 +1,4 @@
-import super::common::{VsOut, draw, tex0, tex1, tex2, tex3, tex4, tex5, tex6, tex7, samp0, samp1, samp2, samp3, samp4, samp5, samp6, samp7};
+import super::common::{VsOut, frame, draw, tex0, tex1, tex2, tex3, tex4, tex5, tex6, tex7, samp0, samp1, samp2, samp3, samp4, samp5, samp6, samp7};
fn extract_bits(val: u32, lo: u32, width: u32) -> u32 {
return (val >> lo) & ((1u << width) - 1u);
@@ -52,6 +52,20 @@ fn stq_to_uv(stq: vec3<f32>) -> vec2<f32> {
return stq.xy / stq.z;
}
+fn select_pair(pair: vec4<u32>, i: u32) -> vec2<u32> {
+ return select(pair.xy, pair.zw, (i & 1u) == 1u);
+}
+
+fn texmap_size(texmap: u32) -> vec2<f32> {
+ let dims = select_pair(draw.tex_dims[texmap / 2u], texmap);
+ return vec2<f32>(max(dims, vec2<u32>(1u, 1u)));
+}
+
+fn texmap_uv(stq: vec3<f32>, texcoord: u32, size: vec2<f32>) -> vec2<f32> {
+ let scale = vec2<f32>(select_pair(frame.texcoord_scales[texcoord / 2u], texcoord));
+ return stq_to_uv(stq) * scale / size;
+}
+
fn sample_texmap(texmap: u32, uv: vec2<f32>) -> vec4<f32> {
switch texmap {
case 0u: { return textureSampleBias(tex0, samp0, uv, draw.tex_lod_bias[0u][0u]); }
diff --git a/crates/backend-wgpu/src/shaders/tev_indirect.wesl b/crates/backend-wgpu/src/shaders/tev_indirect.wesl
index 2836b4a..385cdd7 100644
--- a/crates/backend-wgpu/src/shaders/tev_indirect.wesl
+++ b/crates/backend-wgpu/src/shaders/tev_indirect.wesl
@@ -1,11 +1,5 @@
-import super::common::{VsOut, frame, draw};
-import super::tev_helpers::{select_texcoord, stq_to_uv, sample_texmap};
-
-fn texmap_size(texmap: u32) -> vec2<f32> {
- let pair = draw.tex_dims[texmap / 2u];
- let dims = select(pair.xy, pair.zw, (texmap & 1u) == 1u);
- return vec2<f32>(max(dims, vec2<u32>(1u, 1u)));
-}
+import super::common::{VsOut, frame};
+import super::tev_helpers::{select_texcoord, select_pair, texmap_size, texmap_uv, sample_texmap};
fn ind_quantize_and_bias(
sample: vec3<f32>,
@@ -69,16 +63,11 @@ fn sample_indirect_one(i: u32, in: VsOut, indirect_refs: u32, result: ptr<functi
let shift = i * 6u;
let texmap = (indirect_refs >> shift) & 7u;
let texcoord = (indirect_refs >> (shift + 3u)) & 7u;
- let scale_pair = frame.indirect_scales[i / 2u];
- let scale_s: u32 = select(scale_pair.x, scale_pair.z, (i & 1u) == 1u);
- let scale_t: u32 = select(scale_pair.y, scale_pair.w, (i & 1u) == 1u);
+ let scale = select_pair(frame.indirect_scales[i / 2u], i);
let stq = select_texcoord(in, texcoord);
- let direct_uv = stq_to_uv(stq);
- let sample_uv = vec2<f32>(
- direct_uv.x * exp2(-f32(scale_s)),
- direct_uv.y * exp2(-f32(scale_t)),
- );
+ let direct_uv = texmap_uv(stq, texcoord, texmap_size(texmap));
+ let sample_uv = direct_uv * exp2(-vec2<f32>(scale));
let sample = sample_texmap(texmap, sample_uv);
(*result).samples[i] = sample.abg;
}
diff --git a/crates/gecko/src/flipper/gx/bp.rs b/crates/gecko/src/flipper/gx/bp.rs
index a5880de..4d284b4 100644
--- a/crates/gecko/src/flipper/gx/bp.rs
+++ b/crates/gecko/src/flipper/gx/bp.rs
@@ -98,6 +98,10 @@ impl GraphicsProcessor {
}
}
+ if (BP_SU_SSIZE0..BP_SU_SIZE_END).contains(&idx) {
+ self.frame_state_dirty = true;
+ }
+
// Forward PE render state
match idx {
BP_PE_ZMODE => {
@@ -924,3 +928,4 @@ impl GraphicsProcessor {
tracing::debug!(ram_base = format!("{ram_base:#010X}"), tmem_offset, entries, "LOADTLUT");
}
}
+
diff --git a/crates/gecko/src/flipper/gx/constants.rs b/crates/gecko/src/flipper/gx/constants.rs
index 07eacef..5a18ae3 100644
--- a/crates/gecko/src/flipper/gx/constants.rs
+++ b/crates/gecko/src/flipper/gx/constants.rs
@@ -178,6 +178,8 @@ pub const XF_VIEWPORT_END: usize = 0x101F;
// BP scissor registers
pub const BP_SU_SCIS_TL: usize = 0x20;
pub const BP_SU_SCIS_BR: usize = 0x21;
+pub const BP_SU_SSIZE0: usize = 0x30;
+pub const BP_SU_SIZE_END: usize = 0x40;
pub const BP_SU_SCIS_OFFSET: usize = 0x59;
// BP EFB copy registers
diff --git a/crates/gecko/src/flipper/gx/vertex.rs b/crates/gecko/src/flipper/gx/vertex.rs
index 7888f37..c2a21e4 100644
--- a/crates/gecko/src/flipper/gx/vertex.rs
+++ b/crates/gecko/src/flipper/gx/vertex.rs
@@ -278,6 +278,7 @@ impl GraphicsProcessor {
material_color: self.cached_material_color,
lights: self.cached_lights,
active_texcoords: (self.xf_mem[crate::flipper::gx::constants::XF_NUM_TEXGENS] as u8).min(8),
+ texcoord_scales: std::array::from_fn(|i| (self.bp_regs[BP_SU_SSIZE0 + i] & 0xffff) + 1),
ztex_bias: TevZtex1::from_raw(self.bp_regs[BP_TEV_ZTEX1]).bias(),
ztex_type: ztex2.tex_type(),
ztex_op: self.effective_ztex_op(),
diff --git a/crates/gecko/src/host.rs b/crates/gecko/src/host.rs
index 95d96de..25c4bef 100644
--- a/crates/gecko/src/host.rs
+++ b/crates/gecko/src/host.rs
@@ -193,6 +193,7 @@ pub struct DrawData {
pub struct DrawState {
pub dst_alpha: Option<u8>,
pub active_texcoords: u8,
+ pub texcoord_scales: [u32; 16],
pub zfreeze: Option<crate::flipper::gx::depth::DepthPlane>,
// TEV combiner state
pub tev_color_env: [u32; 16],