Skip to content

armgit / gecko

Public Imported from GitHub
0

A GameCube/Wii emulator and debugger written in Rust.

use wgpu fork with system memory upload staging, fix reclaim_batch dropping recycled buffers and map locked cached through fastmem. summa summarium, sam & max season 1 finally performs well, was some vertices upload bs issue in a wgpu 28 regression

Layle4bb6cc87e0b5
diff --git a/Cargo.lock b/Cargo.lock
index 8caaf97..18ed106 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4129,8 +4129,7 @@ checksum = "13d2233c9842d08cfe13f9eac96e207ca6a2ea10b80259ebe8ad0268be27d2af"
[[package]]
name = "naga"
version = "29.0.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0dd91265cc2454558f659b3b4b9640f0ddb8cc6521277f166b8a8c181c898079"
+source = "git+https://github.com/ioncodes/wgpu?branch=gecko#e995382966810ef0e62b96631e28aed38076a245"
dependencies = [
"arrayvec",
"bit-set 0.9.1",
@@ -7702,8 +7701,7 @@ dependencies = [
[[package]]
name = "wgpu"
version = "29.0.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bb3feacc458f7bee8bc1737149b42b6c731aa461039a4264a67bb6681646b250"
+source = "git+https://github.com/ioncodes/wgpu?branch=gecko#e995382966810ef0e62b96631e28aed38076a245"
dependencies = [
"arrayvec",
"bitflags 2.11.1",
@@ -7732,8 +7730,7 @@ dependencies = [
[[package]]
name = "wgpu-core"
version = "29.0.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "02da3ad1b568337f25513b317870960ef87073ea0945502e44b864b67a8c77b7"
+source = "git+https://github.com/ioncodes/wgpu?branch=gecko#e995382966810ef0e62b96631e28aed38076a245"
dependencies = [
"arrayvec",
"bit-set 0.9.1",
@@ -7766,8 +7763,7 @@ dependencies = [
[[package]]
name = "wgpu-core-deps-apple"
version = "29.0.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "62e51b5447e144b3dbba4feb01f80f4fa21696fa0cd99afb2c3df1affd6fdb28"
+source = "git+https://github.com/ioncodes/wgpu?branch=gecko#e995382966810ef0e62b96631e28aed38076a245"
dependencies = [
"wgpu-hal",
]
@@ -7775,8 +7771,7 @@ dependencies = [
[[package]]
name = "wgpu-core-deps-emscripten"
version = "29.0.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "3487cd6293a963bc5c0c0396f6a2192043c50003c07f4efdccbad3d90ec9d819"
+source = "git+https://github.com/ioncodes/wgpu?branch=gecko#e995382966810ef0e62b96631e28aed38076a245"
dependencies = [
"wgpu-hal",
]
@@ -7784,8 +7779,7 @@ dependencies = [
[[package]]
name = "wgpu-core-deps-wasm"
version = "29.0.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0c2f2fb042f36920771deb0b966543c5751b18f3d327760ffc90f74e20b2dcd4"
+source = "git+https://github.com/ioncodes/wgpu?branch=gecko#e995382966810ef0e62b96631e28aed38076a245"
dependencies = [
"wgpu-hal",
]
@@ -7793,8 +7787,7 @@ dependencies = [
[[package]]
name = "wgpu-core-deps-windows-linux-android"
version = "29.0.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1bfb01076d0aa08b0ba9bd741e178b5cc440f5abe99d9581323a4c8b5d1a1916"
+source = "git+https://github.com/ioncodes/wgpu?branch=gecko#e995382966810ef0e62b96631e28aed38076a245"
dependencies = [
"wgpu-hal",
]
@@ -7802,8 +7795,7 @@ dependencies = [
[[package]]
name = "wgpu-hal"
version = "29.0.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "31f8e1a9e7a8512f276f7c62e018c7fa8d60954303fed2e5750114332049193f"
+source = "git+https://github.com/ioncodes/wgpu?branch=gecko#e995382966810ef0e62b96631e28aed38076a245"
dependencies = [
"android_system_properties",
"arrayvec",
@@ -7856,8 +7848,7 @@ dependencies = [
[[package]]
name = "wgpu-naga-bridge"
version = "29.0.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "59c654c483f058800972c3645e95388a7eca31bf9fe1933bc20e036588a0be02"
+source = "git+https://github.com/ioncodes/wgpu?branch=gecko#e995382966810ef0e62b96631e28aed38076a245"
dependencies = [
"naga",
"wgpu-types",
@@ -7866,8 +7857,7 @@ dependencies = [
[[package]]
name = "wgpu-types"
version = "29.0.3"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "a9bcc31518a0e9735aefebedb5f7a9ef3ed1c42549c9f4c882fa9060ceaac639"
+source = "git+https://github.com/ioncodes/wgpu?branch=gecko#e995382966810ef0e62b96631e28aed38076a245"
dependencies = [
"bitflags 2.11.1",
"bytemuck",
diff --git a/Cargo.toml b/Cargo.toml
index 3d202f8..4b33c5b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -61,6 +61,19 @@ iced_futures = { git = "https://github.com/iced-rs/iced.git", rev = "0d12e964da8
iced_program = { git = "https://github.com/iced-rs/iced.git", rev = "0d12e964da8c3f0f7a02d3d731e3187eecfe5779" }
iced_debug = { git = "https://github.com/iced-rs/iced.git", rev = "0d12e964da8c3f0f7a02d3d731e3187eecfe5779" }
+# wgpu fork (v29.0.3 + system-memory upload staging on Vulkan)
+# fixes performance issues on Vulkan backend for games like Sam & Max Season 1
+wgpu = { git = "https://github.com/ioncodes/wgpu", branch = "gecko" }
+wgpu-core = { git = "https://github.com/ioncodes/wgpu", branch = "gecko" }
+wgpu-hal = { git = "https://github.com/ioncodes/wgpu", branch = "gecko" }
+wgpu-types = { git = "https://github.com/ioncodes/wgpu", branch = "gecko" }
+wgpu-naga-bridge = { git = "https://github.com/ioncodes/wgpu", branch = "gecko" }
+naga = { git = "https://github.com/ioncodes/wgpu", branch = "gecko" }
+wgpu-core-deps-apple = { git = "https://github.com/ioncodes/wgpu", branch = "gecko" }
+wgpu-core-deps-emscripten = { git = "https://github.com/ioncodes/wgpu", branch = "gecko" }
+wgpu-core-deps-wasm = { git = "https://github.com/ioncodes/wgpu", branch = "gecko" }
+wgpu-core-deps-windows-linux-android = { git = "https://github.com/ioncodes/wgpu", branch = "gecko" }
+
[profile.release]
codegen-units = 1
lto = "fat"
diff --git a/crates/backend-wgpu/src/sink.rs b/crates/backend-wgpu/src/sink.rs
index 82c703d..1e61140 100644
--- a/crates/backend-wgpu/src/sink.rs
+++ b/crates/backend-wgpu/src/sink.rs
@@ -297,7 +297,7 @@ impl ThreadedSink {
}
fn reclaim_batch(&mut self) {
- if !self.pending_actions.is_empty() || !self.scratch.is_empty() {
+ if self.pending_actions.capacity() != 0 || self.scratch.capacity() != 0 {
return;
}
diff --git a/crates/gecko/src/gekko/jit/translator.rs b/crates/gecko/src/gekko/jit/translator.rs
index 84d0c8d..8024173 100644
--- a/crates/gecko/src/gekko/jit/translator.rs
+++ b/crates/gecko/src/gekko/jit/translator.rs
@@ -2505,6 +2505,13 @@ pub(crate) fn emit_fastmem_lookup<const SYSTEM: SystemId>(
let page_off_u32 = builder.ins().band_imm(ea, crate::mmio::FASTMEM_PAGE_MASK as i64);
let page_off = builder.ins().uextend(types::I64, page_off_u32);
+ let in_page = builder.ins().icmp_imm(
+ IntCC::UnsignedLessThanOrEqual,
+ page_off_u32,
+ (crate::mmio::FASTMEM_PAGE_BYTES - 8) as i64,
+ );
+ let zero = builder.ins().iconst(types::I64, 0);
+ let host_ptr = builder.ins().select(in_page, host_ptr, zero);
(host_ptr, page_off)
}
diff --git a/crates/gecko/src/gekko/jit/translator/quantized.rs b/crates/gecko/src/gekko/jit/translator/quantized.rs
index 6d93543..a7a6035 100644
--- a/crates/gecko/src/gekko/jit/translator/quantized.rs
+++ b/crates/gecko/src/gekko/jit/translator/quantized.rs
@@ -2,12 +2,10 @@ use cranelift_codegen::ir::condcodes::IntCC;
use cranelift_codegen::ir::{InstBuilder, Value, types};
use cranelift_frontend::FunctionBuilder;
-use crate::gekko::jit::abi;
use crate::mmio::FASTMEM_PAGE_BYTES;
-use crate::mmio::constants::{LCACHE_BASE, LCACHE_SIZE};
use crate::system::SystemId;
-use super::{BlockEmitContext, MemSize, emit_fastmem_load, emit_fastmem_lookup, emit_fastmem_store, vmctx_flags};
+use super::{BlockEmitContext, MemSize, emit_fastmem_load, emit_fastmem_lookup, emit_fastmem_store};
fn pointer<const SYSTEM: SystemId>(builder: &mut FunctionBuilder, ctx_ptr: Value, ea: Value, size: MemSize) -> Value {
let bytes = size.bytes() as usize;
@@ -17,6 +15,8 @@ fn pointer<const SYSTEM: SystemId>(builder: &mut FunctionBuilder, ctx_ptr: Value
let cached = builder.ins().icmp_imm(IntCC::Equal, top, 8);
let uncached = builder.ins().icmp_imm(IntCC::Equal, top, 12);
let alias = builder.ins().bor(cached, uncached);
+ let locked = builder.ins().icmp_imm(IntCC::Equal, top, 14);
+ let alias = builder.ins().bor(alias, locked);
let mapped = builder.ins().icmp_imm(IntCC::NotEqual, base, 0);
let in_page = builder.ins().icmp_imm(
IntCC::UnsignedLessThanOrEqual,
@@ -27,23 +27,7 @@ fn pointer<const SYSTEM: SystemId>(builder: &mut FunctionBuilder, ctx_ptr: Value
let valid = builder.ins().band(valid, in_page);
let addr = builder.ins().iadd(base, offset);
let zero = builder.ins().iconst(types::I64, 0);
- let ram = builder.ins().select(valid, addr, zero);
-
- let lc_offset = builder.ins().iadd_imm(ea, -(LCACHE_BASE as i64));
- let in_cache = builder
- .ins()
- .icmp_imm(IntCC::UnsignedLessThanOrEqual, lc_offset, (LCACHE_SIZE - bytes) as i64);
- let lc_base = builder.ins().load(
- types::I64,
- vmctx_flags(),
- ctx_ptr,
- abi::lcache_fastmem_ptr_offset::<SYSTEM>() as i32,
- );
- let lc_mapped = builder.ins().icmp_imm(IntCC::NotEqual, lc_base, 0);
- let lc_valid = builder.ins().band(in_cache, lc_mapped);
- let lc_offset = builder.ins().uextend(types::I64, lc_offset);
- let lc_addr = builder.ins().iadd(lc_base, lc_offset);
- builder.ins().select(lc_valid, lc_addr, ram)
+ builder.ins().select(valid, addr, zero)
}
pub(super) fn load<const SYSTEM: SystemId>(
diff --git a/crates/gecko/src/mmio.rs b/crates/gecko/src/mmio.rs
index 6a2d94f..3b9f75c 100644
--- a/crates/gecko/src/mmio.rs
+++ b/crates/gecko/src/mmio.rs
@@ -8,10 +8,11 @@ use crate::system::{SystemId, WII};
use constants::*;
use rustc_hash::FxHashSet;
-pub const FASTMEM_LUT_PAGES: usize = 1 << 15;
-pub const FASTMEM_PAGE_BYTES: usize = 1 << 17;
+// A page must fit the entire locked cache without mapping bytes beyond it.
+pub const FASTMEM_LUT_PAGES: usize = 1 << 18;
+pub const FASTMEM_PAGE_BYTES: usize = 1 << 14;
pub const FASTMEM_PAGE_MASK: u32 = (FASTMEM_PAGE_BYTES as u32) - 1;
-pub const FASTMEM_PAGE_SHIFT: u32 = 17;
+pub const FASTMEM_PAGE_SHIFT: u32 = 14;
pub const CODE_LINE_BYTES: u32 = 32;
pub const CODE_LINE_SHIFT: u32 = 5;
diff --git a/crates/gecko/src/mmio/bus.rs b/crates/gecko/src/mmio/bus.rs
index adf67be..b123731 100644
--- a/crates/gecko/src/mmio/bus.rs
+++ b/crates/gecko/src/mmio/bus.rs
@@ -87,6 +87,7 @@ impl<const SYSTEM: SystemId> System<SYSTEM> {
} else {
0
};
+ self.mmio.fastmem_lut[(base >> crate::mmio::FASTMEM_PAGE_SHIFT) as usize] = self.mmio.lcache_fastmem_ptr;
}
#[cold]