Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

fix vertex alpha, now xenoblade chronicles seems to be perfect

Laylec5b80d344766
diff --git a/crates/gecko/src/flipper/gx/jit/attr.rs b/crates/gecko/src/flipper/gx/jit/attr.rs
index 9a20cd0..e2456b5 100644
--- a/crates/gecko/src/flipper/gx/jit/attr.rs
+++ b/crates/gecko/src/flipper/gx/jit/attr.rs
@@ -4,7 +4,7 @@ use cranelift_frontend::FunctionBuilder;
use super::VtxKey;
use super::builder::{MEMFLAGS, MEMFLAGS_RO, MEMFLAGS_RO_MOVABLE, array_offset, offset, xf_byte_off};
use crate::flipper::gx::constants::*;
-use crate::flipper::gx::regs::{AttributeType, ColorCount, ColorFormat, ComponentFormat, NrmCount, PosCount, TexCount};
+use crate::flipper::gx::regs::{AttributeType, ColorFormat, ComponentFormat, NrmCount, PosCount, TexCount};
pub struct AttrCtx<'a, 'f> {
pub bd: &'a mut FunctionBuilder<'f>,
@@ -32,10 +32,10 @@ pub fn emit_vertex(ctx: &mut AttrCtx) {
let nrm_xyz = decode_normal(ctx, vcd_lo.normal(), vat_a);
- let color0 = decode_color(ctx, vcd_lo.color0(), vat_a.clr0_fmt(), vat_a.clr0_cnt(), 2);
+ let color0 = decode_color(ctx, vcd_lo.color0(), vat_a.clr0_fmt(), 2);
ctx.bd.ins().store(MEMFLAGS, color0, ctx.out_ptr, offset::COLOR0);
- let color1 = decode_color(ctx, vcd_lo.color1(), vat_a.clr1_fmt(), vat_a.clr1_cnt(), 3);
+ let color1 = decode_color(ctx, vcd_lo.color1(), vat_a.clr1_fmt(), 3);
ctx.bd.ins().store(MEMFLAGS, color1, ctx.out_ptr, offset::COLOR1);
let tex_attrs = [
@@ -463,26 +463,18 @@ fn unpack_fields(ctx: &mut AttrCtx, lanes: ir::Value, mul: [u32; 4], shift: i64,
ctx.bd.ins().band(v, and)
}
-fn decode_color(
- ctx: &mut AttrCtx,
- attr: AttributeType,
- fmt: ColorFormat,
- cnt: ColorCount,
- array_idx: usize,
-) -> ir::Value {
+fn decode_color(ctx: &mut AttrCtx, attr: AttributeType, fmt: ColorFormat, array_idx: usize) -> ir::Value {
if matches!(attr, AttributeType::None) {
return self::splat_f32x4(ctx, 1.0);
}
- let direct = fmt.data_size(cnt);
+ let direct = fmt.data_size();
let ptr = attr_ptr_and_advance(ctx, attr, array_idx, direct, 0);
- self::decode_color_bytes(ctx, ptr, fmt, cnt)
+ self::decode_color_bytes(ctx, ptr, fmt)
}
-fn decode_color_bytes(ctx: &mut AttrCtx, ptr: ir::Value, fmt: ColorFormat, cnt: ColorCount) -> ir::Value {
- let has_alpha = matches!(cnt, ColorCount::Rgba);
-
+fn decode_color_bytes(ctx: &mut AttrCtx, ptr: ir::Value, fmt: ColorFormat) -> ir::Value {
let (lanes, div, force_alpha_one) = match fmt {
ColorFormat::Rgb565 => {
let l = self::shuffle_to_i32x4(ctx, ptr, &SWZ_COLOR_U16);
@@ -493,12 +485,12 @@ fn decode_color_bytes(ctx: &mut AttrCtx, ptr: ir::Value, fmt: ColorFormat, cnt:
ColorFormat::Rgba4 => {
let l = self::shuffle_to_i32x4(ctx, ptr, &SWZ_COLOR_U16);
let l = self::unpack_fields(ctx, l, [1, 16, 256, 4096], 12, [0xF, 0xF, 0xF, 0xF]);
- (l, self::splat_f32x4(ctx, 15.0), !has_alpha)
+ (l, self::splat_f32x4(ctx, 15.0), false)
}
ColorFormat::Rgba6 => {
let l = self::shuffle_to_i32x4(ctx, ptr, &SWZ_COLOR_U24);
let l = self::unpack_fields(ctx, l, [1, 64, 4096, 262144], 18, [0x3F, 0x3F, 0x3F, 0x3F]);
- (l, self::splat_f32x4(ctx, 63.0), !has_alpha)
+ (l, self::splat_f32x4(ctx, 63.0), false)
}
ColorFormat::Rgb8 | ColorFormat::Rgbx8 => {
let l = self::shuffle_to_i32x4(ctx, ptr, &SWZ_COLOR_BYTES);
@@ -506,7 +498,7 @@ fn decode_color_bytes(ctx: &mut AttrCtx, ptr: ir::Value, fmt: ColorFormat, cnt:
}
ColorFormat::Rgba8 => {
let l = self::shuffle_to_i32x4(ctx, ptr, &SWZ_COLOR_BYTES);
- (l, self::splat_f32x4(ctx, 255.0), !has_alpha)
+ (l, self::splat_f32x4(ctx, 255.0), false)
}
};
diff --git a/crates/gecko/src/flipper/gx/regs.rs b/crates/gecko/src/flipper/gx/regs.rs
index e094881..33d48ba 100644
--- a/crates/gecko/src/flipper/gx/regs.rs
+++ b/crates/gecko/src/flipper/gx/regs.rs
@@ -256,15 +256,11 @@ pub enum ColorFormat {
}
impl ColorFormat {
- pub fn data_size(&self, count: ColorCount) -> usize {
- match (self, count) {
- (ColorFormat::Rgb565, _) => 2,
- (ColorFormat::Rgb8, _) => 3,
- (ColorFormat::Rgbx8, _) => 4,
- (ColorFormat::Rgba4, _) => 2,
- (ColorFormat::Rgba6, _) => 3,
- (ColorFormat::Rgba8, ColorCount::Rgb) => 3,
- (ColorFormat::Rgba8, ColorCount::Rgba) => 4,
+ pub fn data_size(&self) -> usize {
+ match self {
+ ColorFormat::Rgb565 | ColorFormat::Rgba4 => 2,
+ ColorFormat::Rgb8 | ColorFormat::Rgba6 => 3,
+ ColorFormat::Rgbx8 | ColorFormat::Rgba8 => 4,
}
}
}
@@ -367,11 +363,11 @@ impl VatA {
}
pub fn clr0_data_size(&self) -> usize {
- self.clr0_fmt().data_size(self.clr0_cnt())
+ self.clr0_fmt().data_size()
}
pub fn clr1_data_size(&self) -> usize {
- self.clr1_fmt().data_size(self.clr1_cnt())
+ self.clr1_fmt().data_size()
}
pub fn tex0_data_size(&self) -> usize {
diff --git a/crates/gecko/src/flipper/gx/vertex.rs b/crates/gecko/src/flipper/gx/vertex.rs
index d950a5f..87945ac 100644
--- a/crates/gecko/src/flipper/gx/vertex.rs
+++ b/crates/gecko/src/flipper/gx/vertex.rs
@@ -464,18 +464,13 @@ impl GraphicsProcessor {
} else if vf.clr0_attr == AttributeType::Direct {
let start = cur.position() as usize;
cur.set_position(cur.position() + vf.clr0_data_size as u64);
- decode_color(
- &data[start..start + vf.clr0_data_size],
- vf.vat_a.clr0_fmt(),
- vf.vat_a.clr0_cnt(),
- )
+ decode_color(&data[start..start + vf.clr0_data_size], vf.vat_a.clr0_fmt())
} else {
let clr0_index = read_index(cur, vf.clr0_attr);
let clr0_addr = vf.clr0_base + clr0_index * vf.clr0_stride;
decode_color(
fetch(ram, clr0_addr, vf.clr0_data_size, &mut scratch),
vf.vat_a.clr0_fmt(),
- vf.vat_a.clr0_cnt(),
)
};
@@ -485,18 +480,13 @@ impl GraphicsProcessor {
} else if vf.clr1_attr == AttributeType::Direct {
let start = cur.position() as usize;
cur.set_position(cur.position() + vf.clr1_data_size as u64);
- decode_color(
- &data[start..start + vf.clr1_data_size],
- vf.vat_a.clr1_fmt(),
- vf.vat_a.clr1_cnt(),
- )
+ decode_color(&data[start..start + vf.clr1_data_size], vf.vat_a.clr1_fmt())
} else {
let clr1_index = read_index(cur, vf.clr1_attr);
let clr1_addr = vf.clr1_base + clr1_index * vf.clr1_stride;
decode_color(
fetch(ram, clr1_addr, vf.clr1_data_size, &mut scratch),
vf.vat_a.clr1_fmt(),
- vf.vat_a.clr1_cnt(),
)
};
@@ -804,8 +794,7 @@ fn decode_components<const N: usize>(data: &[u8], num: usize, fmt: ComponentForm
result
}
-fn decode_color(data: &[u8], fmt: regs::ColorFormat, cnt: regs::ColorCount) -> [f32; 4] {
- let has_alpha = cnt == regs::ColorCount::Rgba;
+fn decode_color(data: &[u8], fmt: regs::ColorFormat) -> [f32; 4] {
match fmt {
regs::ColorFormat::Rgb565 => {
let raw = u16::from_be_bytes([data[0], data[1]]);
@@ -831,7 +820,7 @@ fn decode_color(data: &[u8], fmt: regs::ColorFormat, cnt: regs::ColorCount) -> [
let r = ((raw >> 12) & 0xF) as f32 / 15.0;
let g = ((raw >> 8) & 0xF) as f32 / 15.0;
let b = ((raw >> 4) & 0xF) as f32 / 15.0;
- let a = if has_alpha { (raw & 0xF) as f32 / 15.0 } else { 1.0 };
+ let a = (raw & 0xF) as f32 / 15.0;
[r, g, b, a]
}
regs::ColorFormat::Rgba6 => {
@@ -839,14 +828,14 @@ fn decode_color(data: &[u8], fmt: regs::ColorFormat, cnt: regs::ColorCount) -> [
let r = ((raw >> 18) & 0x3F) as f32 / 63.0;
let g = ((raw >> 12) & 0x3F) as f32 / 63.0;
let b = ((raw >> 6) & 0x3F) as f32 / 63.0;
- let a = if has_alpha { (raw & 0x3F) as f32 / 63.0 } else { 1.0 };
+ let a = (raw & 0x3F) as f32 / 63.0;
[r, g, b, a]
}
regs::ColorFormat::Rgba8 => {
let r = data[0] as f32 / 255.0;
let g = data[1] as f32 / 255.0;
let b = data[2] as f32 / 255.0;
- let a = if has_alpha { data[3] as f32 / 255.0 } else { 1.0 };
+ let a = data[3] as f32 / 255.0;
[r, g, b, a]
}
}