From 681edb035550a0611e79cb3e6543c607b2767fca Mon Sep 17 00:00:00 2001 From: Alex Janka Date: Thu, 27 Apr 2023 09:55:25 +1000 Subject: [PATCH] move to winit --- .gitmodules | 4 - Cargo.lock | 665 ++++++++++++++---- gb-emu/Cargo.toml | 6 +- gb-emu/src/debug.rs | 4 +- gb-emu/src/window.rs | 158 +++-- lib/src/processor/memory/mmio/cgb/vram_dma.rs | 6 +- vendored/rust_minifb | 1 - 7 files changed, 657 insertions(+), 187 deletions(-) delete mode 160000 vendored/rust_minifb diff --git a/.gitmodules b/.gitmodules index d37fb71..64ffe99 100644 --- a/.gitmodules +++ b/.gitmodules @@ -6,10 +6,6 @@ path = vendored/baseview url = https://github.com/italicsjenga/baseview branch = raw-window-handle-0.5.0 -[submodule "vendored/rust_minifb"] - path = vendored/rust_minifb - url = https://github.com/italicsjenga/rust_minifb - branch = raw-window-handle-0.5.0 [submodule "vendored/librashader"] path = vendored/librashader url = https://github.com/italicsjenga/librashader diff --git a/Cargo.lock b/Cargo.lock index 7037c97..5e1236f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,22 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ab_glyph" +version = "0.2.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5110f1c78cf582855d895ecd0746b653db010cec6d9f5575293f27934d980a39" +dependencies = [ + "ab_glyph_rasterizer", + "owned_ttf_parser", +] + +[[package]] +name = "ab_glyph_rasterizer" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c71b1793ee61086797f5c80b6efa2b8ffa6d5dd703f118545808a7f2e27f7046" + [[package]] name = "addr2line" version = "0.19.0" @@ -59,6 +75,30 @@ dependencies = [ "pkg-config", ] +[[package]] +name = "android-activity" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c77a0045eda8b888c76ea473c2b0515ba6f471d318f8927c5c72240937035a6" +dependencies = [ + "android-properties", + "bitflags", + "cc", + "jni-sys", + "libc", + "log", + "ndk", + "ndk-context", + "ndk-sys", + "num_enum", +] + +[[package]] +name = "android-properties" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc7eb209b1518d6bb87b283c20095f5228ecda460da70b44f0802523dea6da04" + [[package]] name = "android_system_properties" version = "0.1.5" @@ -129,6 +169,12 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33954243bd79057c2de7338850b85983a44588021f8a5fee574a8888c6de4344" +[[package]] +name = "arrayref" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" + [[package]] name = "arrayvec" version = "0.7.2" @@ -193,7 +239,7 @@ dependencies = [ "cc", "cfg-if", "libc", - "miniz_oxide", + "miniz_oxide 0.6.2", "object", "rustc-demangle", ] @@ -213,7 +259,7 @@ dependencies = [ "keyboard-types", "nix 0.22.3", "objc", - "raw-window-handle 0.5.2", + "raw-window-handle", "uuid 0.8.2", "winapi", "x11", @@ -268,6 +314,25 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" +[[package]] +name = "block-sys" +version = "0.1.0-beta.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fa55741ee90902547802152aaf3f8e5248aab7e21468089560d4c8840561146" +dependencies = [ + "objc-sys", +] + +[[package]] +name = "block2" +version = "0.2.0-alpha.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dd9e63c1744f755c2f60332b88de39d341e5e86239014ad839bd71c106dec42" +dependencies = [ + "block-sys", + "objc2-encode", +] + [[package]] name = "bumpalo" version = "3.12.1" @@ -298,6 +363,19 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1db59621ec70f09c5e9b597b220c7a2b43611f4710dc03ceb8748637775692c" +[[package]] +name = "calloop" +version = "0.10.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a59225be45a478d772ce015d9743e49e92798ece9e34eda9a6aa2a6a7f40192" +dependencies = [ + "log", + "nix 0.25.1", + "slotmap", + "thiserror", + "vec_map", +] + [[package]] name = "cc" version = "1.0.79" @@ -416,15 +494,6 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8a2dd5a6fe8c6e3502f568a6353e5273bbb15193ad9a89e457b9970798efbea1" -[[package]] -name = "cmake" -version = "0.1.50" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31c789563b815f77f4250caee12365734369f942439b7defd71e18a48197130" -dependencies = [ - "cc", -] - [[package]] name = "cocoa" version = "0.24.1" @@ -478,6 +547,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +[[package]] +name = "com-rs" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf43edc576402991846b093a7ca18a3477e0ef9c588cde84964b5d3e43016642" + [[package]] name = "combine" version = "4.6.6" @@ -600,6 +675,15 @@ dependencies = [ "windows 0.46.0", ] +[[package]] +name = "crc32fast" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" +dependencies = [ + "cfg-if", +] + [[package]] name = "crossbeam" version = "0.8.2" @@ -677,12 +761,6 @@ dependencies = [ "windows-sys 0.45.0", ] -[[package]] -name = "cty" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" - [[package]] name = "cxx" version = "1.0.94" @@ -738,6 +816,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "d3d12" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8f0de2f5a8e7bd4a9eec0e3c781992a4ce1724f68aec7d7a3715344de8b39da" +dependencies = [ + "bitflags", + "libloading", + "winapi", +] + [[package]] name = "darling" version = "0.14.4" @@ -779,6 +868,12 @@ version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c87e182de0887fd5361989c677c4e8f5000cd9491d6d563161a8f3a5519fc7f" +[[package]] +name = "dispatch" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" + [[package]] name = "dlib" version = "0.5.0" @@ -828,12 +923,22 @@ dependencies = [ ] [[package]] -name = "fastrand" -version = "1.9.0" +name = "fdeflate" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +checksum = "d329bdeac514ee06249dabc27877490f17f5d371ec693360768b838e19f3ae10" dependencies = [ - "instant", + "simd-adler32", +] + +[[package]] +name = "flate2" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841" +dependencies = [ + "crc32fast", + "miniz_oxide 0.6.2", ] [[package]] @@ -970,7 +1075,7 @@ dependencies = [ [[package]] name = "gb-emu" -version = "0.3.0" +version = "0.3.1" dependencies = [ "clap", "cpal", @@ -978,9 +1083,11 @@ dependencies = [ "futures", "gb-emu-lib", "gilrs", - "minifb", "nokhwa", + "pixels 0.12.1", "send_wrapper", + "winit", + "winit_input_helper", ] [[package]] @@ -1068,6 +1175,18 @@ dependencies = [ "web-sys", ] +[[package]] +name = "glow" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e007a07a24de5ecae94160f141029e9a347282cfe25d1d58d85d845cf3130f1" +dependencies = [ + "js-sys", + "slotmap", + "wasm-bindgen", + "web-sys", +] + [[package]] name = "goblin" version = "0.6.1" @@ -1098,6 +1217,19 @@ dependencies = [ "bitflags", ] +[[package]] +name = "gpu-allocator" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce95f9e2e11c2c6fadfce42b5af60005db06576f231f5c92550fdded43c423e8" +dependencies = [ + "backtrace", + "log", + "thiserror", + "winapi", + "windows 0.44.0", +] + [[package]] name = "gpu-descriptor" version = "0.2.3" @@ -1127,6 +1259,21 @@ dependencies = [ "ahash", ] +[[package]] +name = "hassle-rs" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90601c6189668c7345fc53842cb3f3a3d872203d523be1b3cb44a36a3e62fb85" +dependencies = [ + "bitflags", + "com-rs", + "libc", + "libloading", + "thiserror", + "widestring 0.5.1", + "winapi", +] + [[package]] name = "heck" version = "0.4.1" @@ -1477,6 +1624,15 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" +[[package]] +name = "memmap2" +version = "0.5.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83faa42c0a078c393f6b29d5db232d8be22776a891f8f56e5284faee4a20b327" +dependencies = [ + "libc", +] + [[package]] name = "memoffset" version = "0.6.5" @@ -1531,30 +1687,6 @@ dependencies = [ "windows 0.43.0", ] -[[package]] -name = "minifb" -version = "0.24.0" -dependencies = [ - "cc", - "dlib", - "futures", - "instant", - "js-sys", - "lazy_static", - "libc", - "orbclient", - "raw-window-handle 0.5.2", - "serde", - "serde_derive", - "tempfile", - "wasm-bindgen-futures", - "wayland-client", - "wayland-cursor", - "wayland-protocols", - "winapi", - "x11-dl", -] - [[package]] name = "minimal-lexical" version = "0.2.1" @@ -1570,6 +1702,28 @@ dependencies = [ "adler", ] +[[package]] +name = "miniz_oxide" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", + "simd-adler32", +] + +[[package]] +name = "mio" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" +dependencies = [ + "libc", + "log", + "wasi", + "windows-sys 0.45.0", +] + [[package]] name = "mozjpeg" version = "0.9.4" @@ -1614,6 +1768,26 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "naga" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eafe22a23b797c9bc227c6c896419b26b5bb88fa903417a3adaed08778850d5" +dependencies = [ + "bit-set", + "bitflags", + "codespan-reporting", + "hexf-parse", + "indexmap", + "log", + "num-traits", + "rustc-hash", + "spirv", + "termcolor", + "thiserror", + "unicode-xid", +] + [[package]] name = "nanorand" version = "0.7.0" @@ -1639,7 +1813,7 @@ dependencies = [ "jni-sys", "ndk-sys", "num_enum", - "raw-window-handle 0.5.2", + "raw-window-handle", "thiserror", ] @@ -1699,12 +1873,12 @@ dependencies = [ "nih_plug_derive", "objc", "parking_lot", - "raw-window-handle 0.5.2", + "raw-window-handle", "rtrb", "serde", "serde_json", "vst3-sys", - "widestring", + "widestring 1.0.2", "windows 0.44.0", ] @@ -1753,6 +1927,19 @@ dependencies = [ "memoffset 0.6.5", ] +[[package]] +name = "nix" +version = "0.25.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f346ff70e7dbfd675fe90590b92d59ef2de15a8779ae305ebcbfd3f0caf59be4" +dependencies = [ + "autocfg", + "bitflags", + "cfg-if", + "libc", + "memoffset 0.6.5", +] + [[package]] name = "nix" version = "0.26.2" @@ -1884,6 +2071,32 @@ dependencies = [ "objc_exception", ] +[[package]] +name = "objc-sys" +version = "0.2.0-beta.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df3b9834c1e95694a05a828b59f55fa2afec6288359cda67146126b3f90a55d7" + +[[package]] +name = "objc2" +version = "0.3.0-beta.3.patch-leaks.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e01640f9f2cb1220bbe80325e179e532cb3379ebcd1bf2279d703c19fe3a468" +dependencies = [ + "block2", + "objc-sys", + "objc2-encode", +] + +[[package]] +name = "objc2-encode" +version = "2.0.0-pre.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abfcac41015b00a120608fdaa6938c44cb983fee294351cc4bac7638b4e50512" +dependencies = [ + "objc-sys", +] + [[package]] name = "objc_exception" version = "0.1.2" @@ -1974,15 +2187,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0e9829e16c5e112e94efb5e2ad1fe17f8c1c99bb0fcdc8c65c44e935d904767d" dependencies = [ "cfg-if", - "libc", - "raw-window-handle 0.3.4", "redox_syscall 0.2.16", - "sdl2", - "sdl2-sys", "wasm-bindgen", "web-sys", ] +[[package]] +name = "owned_ttf_parser" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "706de7e2214113d63a8238d1910463cfce781129a6f263d13fdb09ff64355ba4" +dependencies = [ + "ttf-parser", +] + [[package]] name = "parking_lot" version = "0.12.1" @@ -2064,10 +2282,24 @@ checksum = "d5169d2d398c75596005313afae6b4b26cb14a22210f148a0183de95b45795a5" dependencies = [ "bytemuck", "pollster", - "raw-window-handle 0.5.2", + "raw-window-handle", "thiserror", "ultraviolet", - "wgpu", + "wgpu 0.14.2", +] + +[[package]] +name = "pixels" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8a87d67cc8f4592a5313b37ce395e8965dd8284492a85f19478af941a4df257" +dependencies = [ + "bytemuck", + "pollster", + "raw-window-handle", + "thiserror", + "ultraviolet", + "wgpu 0.15.1", ] [[package]] @@ -2082,6 +2314,19 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4596b6d070b27117e987119b4dac604f3c58cfb0b191112e24771b2faeac1a6" +[[package]] +name = "png" +version = "0.17.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aaeebc51f9e7d2c150d3f3bfeb667f2aa985db5ef1e3d212847bdedb488beeaa" +dependencies = [ + "bitflags", + "crc32fast", + "fdeflate", + "flate2", + "miniz_oxide 0.7.1", +] + [[package]] name = "pollster" version = "0.2.5" @@ -2164,25 +2409,6 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8a99fddc9f0ba0a85884b8d14e3592853e787d581ca1816c91349b10e4eeab" -[[package]] -name = "raw-window-handle" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e28f55143d0548dad60bb4fbdc835a3d7ac6acc3324506450c5fdd6e42903a76" -dependencies = [ - "libc", - "raw-window-handle 0.4.3", -] - -[[package]] -name = "raw-window-handle" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b800beb9b6e7d2df1fe337c9e3d04e3af22a124460fb4c30fcc22c9117cefb41" -dependencies = [ - "cty", -] - [[package]] name = "raw-window-handle" version = "0.5.2" @@ -2355,28 +2581,16 @@ dependencies = [ ] [[package]] -name = "sdl2" -version = "0.35.2" +name = "sctk-adwaita" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7959277b623f1fb9e04aea73686c3ca52f01b2145f8ea16f4ff30d8b7623b1a" +checksum = "cda4e97be1fd174ccc2aae81c8b694e803fa99b34e8fd0f057a9d70698e3ed09" dependencies = [ - "bitflags", - "lazy_static", - "libc", - "raw-window-handle 0.4.3", - "sdl2-sys", -] - -[[package]] -name = "sdl2-sys" -version = "0.35.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3586be2cf6c0a8099a79a12b4084357aa9b3e0b0d7980e3b67aaf7a9d55f9f0" -dependencies = [ - "cfg-if", - "cmake", - "libc", - "version-compare", + "ab_glyph", + "log", + "memmap2", + "smithay-client-toolkit", + "tiny-skia", ] [[package]] @@ -2465,6 +2679,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "43b2853a4d09f215c24cc5489c992ce46052d359b5109343cbafbf26bc62f8a3" +[[package]] +name = "simd-adler32" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "238abfbb77c1915110ad968465608b68e869e0772622c9656714e73e5a1a522f" + [[package]] name = "slab" version = "0.4.8" @@ -2489,6 +2709,25 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +[[package]] +name = "smithay-client-toolkit" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f307c47d32d2715eb2e0ece5589057820e0e5e70d07c247d1063e844e107f454" +dependencies = [ + "bitflags", + "calloop", + "dlib", + "lazy_static", + "log", + "memmap2", + "nix 0.24.3", + "pkg-config", + "wayland-client", + "wayland-cursor", + "wayland-protocols", +] + [[package]] name = "spin" version = "0.9.8" @@ -2514,6 +2753,12 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "strict-num" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9df65f20698aeed245efdde3628a6b559ea1239bbb871af1b6e3b58c413b2bd1" + [[package]] name = "strsim" version = "0.10.0" @@ -2542,19 +2787,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "tempfile" -version = "3.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" -dependencies = [ - "cfg-if", - "fastrand", - "redox_syscall 0.3.5", - "rustix", - "windows-sys 0.45.0", -] - [[package]] name = "termcolor" version = "1.2.0" @@ -2623,6 +2855,31 @@ dependencies = [ "time-core", ] +[[package]] +name = "tiny-skia" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df8493a203431061e901613751931f047d1971337153f96d0e5e363d6dbf6a67" +dependencies = [ + "arrayref", + "arrayvec", + "bytemuck", + "cfg-if", + "png", + "tiny-skia-path", +] + +[[package]] +name = "tiny-skia-path" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "adbfb5d3f3dd57a0e11d12f4f13d4ebbbc1b5c15b7ab0a156d030b21da5f677c" +dependencies = [ + "arrayref", + "bytemuck", + "strict-num", +] + [[package]] name = "toml" version = "0.7.3" @@ -2657,6 +2914,12 @@ dependencies = [ "winnow", ] +[[package]] +name = "ttf-parser" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44dcf002ae3b32cd25400d6df128c5babec3927cd1eb7ce813cfff20eb6c3746" + [[package]] name = "ultraviolet" version = "0.9.1" @@ -2723,12 +2986,6 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" -[[package]] -name = "version-compare" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "579a42fc0b8e0c63b76519a339be31bed574929511fa53c1a3acae26eb258f29" - [[package]] name = "version_check" version = "0.9.4" @@ -2745,7 +3002,7 @@ dependencies = [ "gb-emu-lib", "keyboard-types", "nih_plug", - "pixels", + "pixels 0.11.0", ] [[package]] @@ -2959,17 +3216,41 @@ dependencies = [ "arrayvec", "js-sys", "log", - "naga", + "naga 0.10.0", "parking_lot", - "raw-window-handle 0.5.2", + "raw-window-handle", "smallvec", "static_assertions", "wasm-bindgen", "wasm-bindgen-futures", "web-sys", - "wgpu-core", - "wgpu-hal", - "wgpu-types", + "wgpu-core 0.14.2", + "wgpu-hal 0.14.1", + "wgpu-types 0.14.1", +] + +[[package]] +name = "wgpu" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d745a1b6d91d85c33defbb29f0eee0450e1d2614d987e14bf6baf26009d132d7" +dependencies = [ + "arrayvec", + "cfg-if", + "js-sys", + "log", + "naga 0.11.0", + "parking_lot", + "profiling", + "raw-window-handle", + "smallvec", + "static_assertions", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "wgpu-core 0.15.1", + "wgpu-hal 0.15.4", + "wgpu-types 0.15.2", ] [[package]] @@ -2985,15 +3266,38 @@ dependencies = [ "codespan-reporting", "fxhash", "log", - "naga", + "naga 0.10.0", "parking_lot", "profiling", - "raw-window-handle 0.5.2", + "raw-window-handle", "smallvec", "thiserror", "web-sys", - "wgpu-hal", - "wgpu-types", + "wgpu-hal 0.14.1", + "wgpu-types 0.14.1", +] + +[[package]] +name = "wgpu-core" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7131408d940e335792645a98f03639573b0480e9e2e7cddbbab74f7c6d9f3fff" +dependencies = [ + "arrayvec", + "bit-vec", + "bitflags", + "codespan-reporting", + "fxhash", + "log", + "naga 0.11.0", + "parking_lot", + "profiling", + "raw-window-handle", + "smallvec", + "thiserror", + "web-sys", + "wgpu-hal 0.15.4", + "wgpu-types 0.15.2", ] [[package]] @@ -3009,10 +3313,10 @@ dependencies = [ "bitflags", "block", "core-graphics-types", - "d3d12", + "d3d12 0.5.0", "foreign-types", "fxhash", - "glow", + "glow 0.11.2", "gpu-alloc", "gpu-descriptor", "js-sys", @@ -3020,18 +3324,60 @@ dependencies = [ "libloading", "log", "metal", - "naga", + "naga 0.10.0", "objc", "parking_lot", "profiling", "range-alloc", - "raw-window-handle 0.5.2", + "raw-window-handle", "renderdoc-sys", "smallvec", "thiserror", "wasm-bindgen", "web-sys", - "wgpu-types", + "wgpu-types 0.14.1", + "winapi", +] + +[[package]] +name = "wgpu-hal" +version = "0.15.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bdcf61a283adc744bb5453dd88ea91f3f86d5ca6b027661c6c73c7734ae0288b" +dependencies = [ + "android_system_properties", + "arrayvec", + "ash", + "bit-set", + "bitflags", + "block", + "core-graphics-types", + "d3d12 0.6.0", + "foreign-types", + "fxhash", + "glow 0.12.1", + "gpu-alloc", + "gpu-allocator", + "gpu-descriptor", + "hassle-rs", + "js-sys", + "khronos-egl", + "libc", + "libloading", + "log", + "metal", + "naga 0.11.0", + "objc", + "parking_lot", + "profiling", + "range-alloc", + "raw-window-handle", + "renderdoc-sys", + "smallvec", + "thiserror", + "wasm-bindgen", + "web-sys", + "wgpu-types 0.15.2", "winapi", ] @@ -3044,6 +3390,17 @@ dependencies = [ "bitflags", ] +[[package]] +name = "wgpu-types" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32444e121b0bd00cb02c0de32fde457a9491bd44e03e7a5db6df9b1da2f6f110" +dependencies = [ + "bitflags", + "js-sys", + "web-sys", +] + [[package]] name = "wide" version = "0.7.8" @@ -3054,6 +3411,12 @@ dependencies = [ "safe_arch", ] +[[package]] +name = "widestring" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17882f045410753661207383517a6f62ec3dbeb6a4ed2acce01f0728238d1983" + [[package]] name = "widestring" version = "1.0.2" @@ -3265,6 +3628,50 @@ version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +[[package]] +name = "winit" +version = "0.28.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f504e8c117b9015f618774f8d58cd4781f5a479bc41079c064f974cbb253874" +dependencies = [ + "android-activity", + "bitflags", + "cfg_aliases", + "core-foundation", + "core-graphics", + "dispatch", + "instant", + "libc", + "log", + "mio", + "ndk", + "objc2", + "once_cell", + "orbclient", + "percent-encoding", + "raw-window-handle", + "redox_syscall 0.3.5", + "sctk-adwaita", + "smithay-client-toolkit", + "wasm-bindgen", + "wayland-client", + "wayland-commons", + "wayland-protocols", + "wayland-scanner", + "web-sys", + "windows-sys 0.45.0", + "x11-dl", +] + +[[package]] +name = "winit_input_helper" +version = "0.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5de0485e86aa2ee87d2d4c373a908c9548357bc65c5bce19fd884c8ea9eac4d7" +dependencies = [ + "winit", +] + [[package]] name = "winnow" version = "0.4.1" diff --git a/gb-emu/Cargo.toml b/gb-emu/Cargo.toml index 0b52bce..8e381eb 100644 --- a/gb-emu/Cargo.toml +++ b/gb-emu/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "gb-emu" -version = "0.3.0" +version = "0.3.1" edition = "2021" [features] @@ -10,10 +10,12 @@ camera = ["dep:nokhwa", "dep:send_wrapper"] [dependencies] gb-emu-lib = { path = "../lib" } clap = { version = "4.1.8", features = ["derive"] } -minifb = { path = "../vendored/rust_minifb" } gilrs = "0.10" cpal = "0.15" futures = "0.3" ctrlc = "3.2.5" nokhwa = { version = "0.10.3", features = ["input-opencv"], optional = true } send_wrapper = { version = "0.6.0", optional = true } +winit = "0.28" +winit_input_helper = "0.14" +pixels = "0.12" \ No newline at end of file diff --git a/gb-emu/src/debug.rs b/gb-emu/src/debug.rs index e931298..ada6c62 100644 --- a/gb-emu/src/debug.rs +++ b/gb-emu/src/debug.rs @@ -52,7 +52,7 @@ impl FromStr for Commands { } pub struct Debugger { - core: EmulatorCore, + core: EmulatorCore<[u8; 4], WindowRenderer, NoCamera>, debug_receiver: Receiver, stepping: bool, last_command: String, @@ -62,7 +62,7 @@ pub struct Debugger { impl Debugger { pub fn new( - core: EmulatorCore, + core: EmulatorCore<[u8; 4], WindowRenderer, NoCamera>, debug_receiver: Receiver, ) -> Self { Self { diff --git a/gb-emu/src/window.rs b/gb-emu/src/window.rs index cbda981..923396e 100644 --- a/gb-emu/src/window.rs +++ b/gb-emu/src/window.rs @@ -1,82 +1,148 @@ use gb_emu_lib::{ connect::{JoypadState, Renderer}, - util::scale_buffer, + util::scale_buffer_in_place, }; use gilrs::{ ff::{BaseEffect, BaseEffectType, EffectBuilder, Replay, Ticks}, Button, Gilrs, }; -use minifb::{Key, Window, WindowOptions}; +use pixels::{Pixels, SurfaceTexture}; +use winit::{ + dpi::PhysicalSize, + event::{Event, VirtualKeyCode, WindowEvent}, + event_loop::EventLoop, + platform::run_return::EventLoopExtRunReturn, + window::{Window, WindowBuilder}, +}; +use winit_input_helper::WinitInputHelper; pub struct WindowRenderer { - window: Option, - scaled_buf: Vec, + event_loop: EventLoop<()>, + window: Window, + input: WinitInputHelper, + pixels: Pixels, + scaled_buf: Vec<[u8; 4]>, width: usize, height: usize, factor: usize, + real_factor: usize, gamepad_handler: Option, joypad_state: JoypadState, current_rumble: bool, - position: Option<(isize, isize)>, } impl WindowRenderer { pub fn new(factor: usize, gamepad_handler: Option) -> Self { + let event_loop = EventLoop::new(); + let window = WindowBuilder::new() + .with_title("A fantastic window!") + .build(&event_loop) + .unwrap(); + + let real_factor = (window.scale_factor() * factor as f64) as usize; + + let pixels = { + let window_size = window.inner_size(); + let surface_texture = + SurfaceTexture::new(window_size.width, window_size.height, &window); + pixels::PixelsBuilder::new(window_size.width, window_size.height, surface_texture) + .request_adapter_options(pixels::wgpu::RequestAdapterOptionsBase { + power_preference: pixels::wgpu::PowerPreference::HighPerformance, + ..pixels::wgpu::RequestAdapterOptionsBase::default() + }) + .build() + .unwrap() + }; + + let input = WinitInputHelper::new(); Self { - window: None, + event_loop, + window, + input, + pixels, scaled_buf: vec![], width: 0, height: 0, factor, + real_factor, gamepad_handler, joypad_state: JoypadState::default(), current_rumble: false, - position: None, } } + + fn update_events(&mut self) { + self.event_loop.run_return(|event, _, control_flow| { + control_flow.set_wait(); + self.input.update(&event); + + match event { + Event::WindowEvent { + event: WindowEvent::CloseRequested, + .. + } => { + // quit = true; + } + Event::MainEventsCleared => { + control_flow.set_exit(); + } + Event::RedrawRequested(_) => { + for (pixel, source) in self + .pixels + .frame_mut() + .chunks_exact_mut(4) + .zip(&self.scaled_buf) + { + pixel.copy_from_slice(source); + } + self.pixels.render().unwrap(); + } + _ => {} + } + }); + } } -impl Renderer for WindowRenderer { +impl Renderer<[u8; 4]> for WindowRenderer { fn prepare(&mut self, width: usize, height: usize) { self.width = width; self.height = height; + self.real_factor = (self.window.scale_factor() * self.factor as f64) as usize; - let mut w = Window::new( - "Gameboy", - width * self.factor, - height * self.factor, - WindowOptions::default(), - ) - .unwrap(); + let w = (width * self.real_factor) as u32; + let h = (height * self.real_factor) as u32; - if let Some((x, y)) = self.position { - w.set_position(x, y); - } + self.window.set_inner_size(PhysicalSize::new(w, h)); + self.pixels = { + let window_size = self.window.inner_size(); + let surface_texture = + SurfaceTexture::new(window_size.width, window_size.height, &self.window); + Pixels::new(window_size.width, window_size.height, surface_texture).unwrap() + }; - self.window = Some(w); + self.scaled_buf.resize((w * h) as usize, [0; 4]); + + self.window.request_redraw(); } - fn display(&mut self, buffer: &[u32]) { - if let Some(ref mut window) = self.window { - self.scaled_buf = scale_buffer(buffer, self.width, self.height, self.factor); - self.position = Some(window.get_position()); - window - .update_with_buffer( - &self.scaled_buf, - self.width * self.factor, - self.height * self.factor, - ) - .unwrap(); - } + fn display(&mut self, buffer: &[[u8; 4]]) { + scale_buffer_in_place( + buffer, + &mut self.scaled_buf, + self.width, + self.height, + self.real_factor, + ); + self.window.request_redraw(); + self.update_events(); } fn set_title(&mut self, title: String) { - if let Some(ref mut window) = self.window { - window.set_title(&title); - } + self.window.set_title(&title); } fn latest_joypad_state(&mut self) -> JoypadState { + self.update_events(); self.joypad_state.reset(); if let Some(ref mut gamepad_handler) = self.gamepad_handler { @@ -108,18 +174,18 @@ impl Renderer for WindowRenderer { } } - if let Some(window) = &self.window { - let keys = window.get_keys(); - - self.joypad_state.down |= keys.contains(&Key::Down) || keys.contains(&Key::S); - self.joypad_state.up |= keys.contains(&Key::Up) || keys.contains(&Key::W); - self.joypad_state.left |= keys.contains(&Key::Left) || keys.contains(&Key::A); - self.joypad_state.right |= keys.contains(&Key::Right) || keys.contains(&Key::D); - self.joypad_state.start |= keys.contains(&Key::Equal); - self.joypad_state.select |= keys.contains(&Key::Minus); - self.joypad_state.a |= keys.contains(&Key::Apostrophe); - self.joypad_state.b |= keys.contains(&Key::Semicolon); - } + self.joypad_state.down |= + self.input.key_held(VirtualKeyCode::Down) || self.input.key_held(VirtualKeyCode::S); + self.joypad_state.up |= + self.input.key_held(VirtualKeyCode::Up) || self.input.key_held(VirtualKeyCode::W); + self.joypad_state.left |= + self.input.key_held(VirtualKeyCode::Left) || self.input.key_held(VirtualKeyCode::A); + self.joypad_state.right |= + self.input.key_held(VirtualKeyCode::Right) || self.input.key_held(VirtualKeyCode::D); + self.joypad_state.start |= self.input.key_held(VirtualKeyCode::Equals); + self.joypad_state.select |= self.input.key_held(VirtualKeyCode::Minus); + self.joypad_state.a |= self.input.key_held(VirtualKeyCode::Apostrophe); + self.joypad_state.b |= self.input.key_held(VirtualKeyCode::Semicolon); self.joypad_state } diff --git a/lib/src/processor/memory/mmio/cgb/vram_dma.rs b/lib/src/processor/memory/mmio/cgb/vram_dma.rs index 6fcda03..4af2ad2 100644 --- a/lib/src/processor/memory/mmio/cgb/vram_dma.rs +++ b/lib/src/processor/memory/mmio/cgb/vram_dma.rs @@ -97,8 +97,6 @@ where cgb_peripherals.vram_dma.destination, length, )); - cgb_peripherals.vram_dma.source += length; - cgb_peripherals.vram_dma.destination += length; cgb_peripherals.vram_dma.mode = DmaMode::Waiting; cgb_peripherals.vram_dma.reset_registers(); ((l as usize) + 1) * 8 @@ -130,7 +128,9 @@ where }; if let Some((source, dest, length)) = copy { for i in 0..length { - self.set(dest + i, self.get(source + i)); + if let Some(s) = source.checked_add(i) { + self.set(dest + i, self.get(s)); + } } } if self.is_double_speed() { diff --git a/vendored/rust_minifb b/vendored/rust_minifb deleted file mode 160000 index 1f10d26..0000000 --- a/vendored/rust_minifb +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1f10d269987e1973a6f70b951c4e8688d30f5d6d