From a01bc8ab6fdbafc7ec19a4d272bf96fe9174810b Mon Sep 17 00:00:00 2001 From: Wayne Van Son <=> Date: Fri, 6 Sep 2024 16:04:28 +1000 Subject: [PATCH 1/3] chore: nix --- .vscode/settings.json | 4 ++ flake.lock | 114 ++++++++++++++++++++++++++++++++++++++++++ flake.nix | 65 ++++++++++++++++++++++++ rust-toolchain.toml | 3 ++ shell.nix | 10 ++++ 5 files changed, 196 insertions(+) create mode 100644 .vscode/settings.json create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 rust-toolchain.toml create mode 100644 shell.nix diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..28040d0 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,4 @@ +{ + "nixEnvSelector.nixFile": "${workspaceRoot}/shell.nix", + "rust-analyzer.server.path": "/nix/store/ij5rn845i4qzmzznh4ryqm89bqhg7kiq-rust-nightly/bin/rust-analyzer" +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..351a6d7 --- /dev/null +++ b/flake.lock @@ -0,0 +1,114 @@ +{ + "nodes": { + "fenix": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ], + "rust-analyzer-src": "rust-analyzer-src" + }, + "locked": { + "lastModified": 1725517947, + "narHash": "sha256-sB8B3M6CS0Y0rnncsCPz0htg6LoC1RbI2Mq9K88tSOk=", + "owner": "nix-community", + "repo": "fenix", + "rev": "96072c2af73da16c7db013dbb8c8869000157235", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "fenix", + "type": "github" + } + }, + "flake-compat": { + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "revCount": 57, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.0.1/018afb31-abd1-7bff-a5e4-cff7e18efb7a/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1725432240, + "narHash": "sha256-+yj+xgsfZaErbfYM3T+QvEE2hU7UuE+Jf0fJCJ8uPS0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ad416d066ca1222956472ab7d0555a6946746a80", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "fenix": "fenix", + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "rust-analyzer-src": { + "flake": false, + "locked": { + "lastModified": 1725444219, + "narHash": "sha256-VjItfg2kZJ2to3bnNlkWAClKQLssIi86QcE1/vcRvv0=", + "owner": "rust-lang", + "repo": "rust-analyzer", + "rev": "50882fbfa204027c84753e6d51a1a12884dc1b19", + "type": "github" + }, + "original": { + "owner": "rust-lang", + "ref": "nightly", + "repo": "rust-analyzer", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..fd68025 --- /dev/null +++ b/flake.nix @@ -0,0 +1,65 @@ +{ + inputs = { + flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"; + flake-utils.url = "github:numtide/flake-utils"; + fenix = { + url = "github:nix-community/fenix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + nixpkgs.url = "nixpkgs/nixos-unstable"; + }; + + outputs = { self, nixpkgs, flake-utils, fenix, ...}: + flake-utils.lib.eachDefaultSystem (system: + let + overlays = [fenix.overlays.default]; + pkgs = import nixpkgs { + inherit system overlays; + }; + rust' = fenix.packages.${system}.fromToolchainFile { + file = ./rust-toolchain.toml; + sha256 = "sha256-sZ4gSN88DqNWcUSUloG3tX8hZulnsvmtkRIpWMPPzBg="; + }; + nativeBuildInputs = with pkgs; [ + clang + llvmPackages.bintools + pkg-config + rust' + ]; + buildInputs = with pkgs; [ + rust-analyzer-nightly + cargo-watch + + udev alsa-lib vulkan-loader + xorg.libX11 xorg.libXcursor xorg.libXi xorg.libXrandr # To use the x11 feature + libxkbcommon wayland # To use the wayland feature + ]; + allInputs = nativeBuildInputs ++ buildInputs; + env = with pkgs; { + LIBCLANG_PATH = lib.makeLibraryPath [ + llvmPackages_latest.libclang.lib + ]; + RUSTFLAGS = (builtins.map(a: ''-L ${a}/lib'') []); + LD_LIBRARY_PATH = lib.makeLibraryPath allInputs; + BINGEN_EXTRA_CLANG_ARGS = (builtins.map(a: ''-I"${a}/include"'') [ + pkgs.glibc.dev + ]) ++ [ + ''-I"${pkgs.llvmPackages_latest.libclang.lib}/lib/clang/${pkgs.llvmPackages_latest.libclang.version}/include"'' + ''-I"${pkgs.glib.dev}/include/glib-2.0"'' + ''-I${pkgs.glib.out}/lib/glib-2.0/include/'' + ]; + }; + shell = rec { + inherit nativeBuildInputs buildInputs; + + shellHook = '' + export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin + export PATH=$PATH:''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/ + ''; + } // env; + in + { + devShells.default = pkgs.mkShell shell; + } + ); +} \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..99d2ae9 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "nightly" +profile = "complete" diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..64fbdb4 --- /dev/null +++ b/shell.nix @@ -0,0 +1,10 @@ +(import + ( + let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in + fetchTarball { + url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; + } + ) + { src = ./.; } +).shellNix \ No newline at end of file From 4e545f10990338163e792e33ad151468bb936c53 Mon Sep 17 00:00:00 2001 From: Wayne Van Son <=> Date: Fri, 6 Sep 2024 17:29:21 +1000 Subject: [PATCH 2/3] chore: get most of the way there --- Cargo.toml | 9 ++++++--- src/plugin.rs | 8 ++++---- src/system.rs | 20 ++++++++++---------- src/wrapper.rs | 4 ++-- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2987adf..fd0c3c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "bevy_pixels" description = "Bevy plugin that uses Pixels (a tiny pixel buffer) for rendering" -version = "0.13.0" +version = "0.14.0" authors = ["David Cristofaro "] edition = "2021" license = "MIT OR Apache-2.0" @@ -22,10 +22,13 @@ wayland = ["bevy/wayland"] x11 = ["bevy/x11"] [dependencies] -bevy = { version = "0.13", default_features = false, features = ["bevy_winit"] } -winit = { version = "0.29", features = ["rwh_05"] } +bevy = { version = "0.14", default_features = false, features = ["bevy_winit"] } +winit = { version = "0.30", features = ["rwh_06"] } pixels = "0.13" +[patch.crates-io] +pixels = { git = "https://github.com/mkrasnitski/pixels.git", branch = "bump-wgpu-winit" } + [target.'cfg(target_arch = "wasm32")'.dependencies] pollster = "0.3" diff --git a/src/plugin.rs b/src/plugin.rs index 0435ddf..32521e9 100644 --- a/src/plugin.rs +++ b/src/plugin.rs @@ -48,7 +48,7 @@ impl Plugin for PixelsPlugin { ); // Ensure `Draw` and `Render` schedules execute at the correct moment. - let mut order = app.world.resource_mut::(); + let mut order = app.world_mut().resource_mut::(); order.insert_after(PostUpdate, Draw); order.insert_after(Draw, Render); @@ -57,11 +57,11 @@ impl Plugin for PixelsPlugin { // [`create_pixels`] system for this entity which will initialize the [`Pixels`] buffer. if let Some(options) = &self.primary_window { let mut system_state: SystemState>> = - SystemState::new(&mut app.world); - let query = system_state.get(&app.world); + SystemState::new(&mut app.world_mut()); + let query = system_state.get(&app.world()); if let Ok(entity) = query.get_single() { - app.world.entity_mut(entity).insert(*options); + app.world_mut().entity_mut(entity).insert(*options); }; } } diff --git a/src/system.rs b/src/system.rs index 39c2ef3..43acc46 100644 --- a/src/system.rs +++ b/src/system.rs @@ -21,11 +21,11 @@ use std::time::Instant; /// Create [`PixelsWrapper`] (and underlying [`Pixels`] buffer) for all suitable [`Window`] with /// a [`PixelsOptions`] component. #[allow(clippy::type_complexity)] -pub fn create_pixels( +pub fn create_pixels<'win: 'static>( mut commands: Commands, query: Query< (Entity, &PixelsOptions, &Window), - (With, Without), + (With, Without>), >, winit_windows: NonSend, ) { @@ -66,9 +66,9 @@ pub fn create_pixels( } /// Resize buffer and surface to window when it is resized. -pub fn window_resize( +pub fn window_resize<'win: 'static>( mut window_resized_events: EventReader, - mut query: Query<(&mut PixelsWrapper, &mut PixelsOptions, &Window)>, + mut query: Query<(&mut PixelsWrapper<'win>, &mut PixelsOptions, &Window)>, ) { for event in window_resized_events.read() { if let Ok((mut wrapper, mut options, window)) = query.get_mut(event.window) { @@ -85,9 +85,9 @@ pub fn window_resize( } /// Resize surface to window when scale factor changes. -pub fn window_change( +pub fn window_change<'win: 'static>( mut window_backend_scale_factor_changed_events: EventReader, - mut query: Query<(&mut PixelsWrapper, &PixelsOptions, &Window)>, + mut query: Query<(&mut PixelsWrapper<'win>, &PixelsOptions, &Window)>, ) { for event in window_backend_scale_factor_changed_events.read() { if let Ok((mut wrapper, options, window)) = query.get_mut(event.window) { @@ -105,8 +105,8 @@ fn resize_surface_to_window(wrapper: &mut PixelsWrapper, window: &Window) { } /// Resize buffer when width and height change. -pub fn resize_buffer( - mut query: Query<(&mut PixelsWrapper, &PixelsOptions), Changed>, +pub fn resize_buffer<'win: 'static>( + mut query: Query<(&mut PixelsWrapper<'win>, &PixelsOptions), Changed>, ) { for (mut wrapper, options) in &mut query { if options.auto_resize_buffer { @@ -117,10 +117,10 @@ pub fn resize_buffer( /// Render buffer to surface. #[cfg(feature = "render")] -pub fn render( +pub fn render<'win: 'static>( // TODO: Support `RENDER_TIME` diagnostics on web. #[cfg(not(target_arch = "wasm32"))] mut diagnostics: Diagnostics, - query: Query<&PixelsWrapper>, + query: Query<&PixelsWrapper<'win>>, ) { #[cfg(not(target_arch = "wasm32"))] let start = Instant::now(); diff --git a/src/wrapper.rs b/src/wrapper.rs index 58a5374..3cf0a10 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -3,6 +3,6 @@ use pixels::Pixels; /// Wrapper component for underlying [`Pixels`] struct. #[derive(Component, Debug)] -pub struct PixelsWrapper { - pub pixels: Pixels, +pub struct PixelsWrapper<'win> { + pub pixels: Pixels<'win>, } From 6c07d70d99cf5f8d0e0c6de575ff28de6df8d323 Mon Sep 17 00:00:00 2001 From: Wayne Van Son <=> Date: Fri, 6 Sep 2024 17:31:07 +1000 Subject: [PATCH 3/3] chore: remove nix parts --- .vscode/settings.json | 4 -- flake.lock | 114 ------------------------------------------ flake.nix | 65 ------------------------ rust-toolchain.toml | 3 -- shell.nix | 10 ---- 5 files changed, 196 deletions(-) delete mode 100644 .vscode/settings.json delete mode 100644 flake.lock delete mode 100644 flake.nix delete mode 100644 rust-toolchain.toml delete mode 100644 shell.nix diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index 28040d0..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "nixEnvSelector.nixFile": "${workspaceRoot}/shell.nix", - "rust-analyzer.server.path": "/nix/store/ij5rn845i4qzmzznh4ryqm89bqhg7kiq-rust-nightly/bin/rust-analyzer" -} diff --git a/flake.lock b/flake.lock deleted file mode 100644 index 351a6d7..0000000 --- a/flake.lock +++ /dev/null @@ -1,114 +0,0 @@ -{ - "nodes": { - "fenix": { - "inputs": { - "nixpkgs": [ - "nixpkgs" - ], - "rust-analyzer-src": "rust-analyzer-src" - }, - "locked": { - "lastModified": 1725517947, - "narHash": "sha256-sB8B3M6CS0Y0rnncsCPz0htg6LoC1RbI2Mq9K88tSOk=", - "owner": "nix-community", - "repo": "fenix", - "rev": "96072c2af73da16c7db013dbb8c8869000157235", - "type": "github" - }, - "original": { - "owner": "nix-community", - "repo": "fenix", - "type": "github" - } - }, - "flake-compat": { - "locked": { - "lastModified": 1696426674, - "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", - "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", - "revCount": 57, - "type": "tarball", - "url": "https://api.flakehub.com/f/pinned/edolstra/flake-compat/1.0.1/018afb31-abd1-7bff-a5e4-cff7e18efb7a/source.tar.gz" - }, - "original": { - "type": "tarball", - "url": "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz" - } - }, - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1710146030, - "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, - "nixpkgs": { - "locked": { - "lastModified": 1725432240, - "narHash": "sha256-+yj+xgsfZaErbfYM3T+QvEE2hU7UuE+Jf0fJCJ8uPS0=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "ad416d066ca1222956472ab7d0555a6946746a80", - "type": "github" - }, - "original": { - "id": "nixpkgs", - "ref": "nixos-unstable", - "type": "indirect" - } - }, - "root": { - "inputs": { - "fenix": "fenix", - "flake-compat": "flake-compat", - "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" - } - }, - "rust-analyzer-src": { - "flake": false, - "locked": { - "lastModified": 1725444219, - "narHash": "sha256-VjItfg2kZJ2to3bnNlkWAClKQLssIi86QcE1/vcRvv0=", - "owner": "rust-lang", - "repo": "rust-analyzer", - "rev": "50882fbfa204027c84753e6d51a1a12884dc1b19", - "type": "github" - }, - "original": { - "owner": "rust-lang", - "ref": "nightly", - "repo": "rust-analyzer", - "type": "github" - } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/flake.nix b/flake.nix deleted file mode 100644 index fd68025..0000000 --- a/flake.nix +++ /dev/null @@ -1,65 +0,0 @@ -{ - inputs = { - flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz"; - flake-utils.url = "github:numtide/flake-utils"; - fenix = { - url = "github:nix-community/fenix"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - nixpkgs.url = "nixpkgs/nixos-unstable"; - }; - - outputs = { self, nixpkgs, flake-utils, fenix, ...}: - flake-utils.lib.eachDefaultSystem (system: - let - overlays = [fenix.overlays.default]; - pkgs = import nixpkgs { - inherit system overlays; - }; - rust' = fenix.packages.${system}.fromToolchainFile { - file = ./rust-toolchain.toml; - sha256 = "sha256-sZ4gSN88DqNWcUSUloG3tX8hZulnsvmtkRIpWMPPzBg="; - }; - nativeBuildInputs = with pkgs; [ - clang - llvmPackages.bintools - pkg-config - rust' - ]; - buildInputs = with pkgs; [ - rust-analyzer-nightly - cargo-watch - - udev alsa-lib vulkan-loader - xorg.libX11 xorg.libXcursor xorg.libXi xorg.libXrandr # To use the x11 feature - libxkbcommon wayland # To use the wayland feature - ]; - allInputs = nativeBuildInputs ++ buildInputs; - env = with pkgs; { - LIBCLANG_PATH = lib.makeLibraryPath [ - llvmPackages_latest.libclang.lib - ]; - RUSTFLAGS = (builtins.map(a: ''-L ${a}/lib'') []); - LD_LIBRARY_PATH = lib.makeLibraryPath allInputs; - BINGEN_EXTRA_CLANG_ARGS = (builtins.map(a: ''-I"${a}/include"'') [ - pkgs.glibc.dev - ]) ++ [ - ''-I"${pkgs.llvmPackages_latest.libclang.lib}/lib/clang/${pkgs.llvmPackages_latest.libclang.version}/include"'' - ''-I"${pkgs.glib.dev}/include/glib-2.0"'' - ''-I${pkgs.glib.out}/lib/glib-2.0/include/'' - ]; - }; - shell = rec { - inherit nativeBuildInputs buildInputs; - - shellHook = '' - export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin - export PATH=$PATH:''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/ - ''; - } // env; - in - { - devShells.default = pkgs.mkShell shell; - } - ); -} \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml deleted file mode 100644 index 99d2ae9..0000000 --- a/rust-toolchain.toml +++ /dev/null @@ -1,3 +0,0 @@ -[toolchain] -channel = "nightly" -profile = "complete" diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 64fbdb4..0000000 --- a/shell.nix +++ /dev/null @@ -1,10 +0,0 @@ -(import - ( - let lock = builtins.fromJSON (builtins.readFile ./flake.lock); in - fetchTarball { - url = lock.nodes.flake-compat.locked.url or "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; - sha256 = lock.nodes.flake-compat.locked.narHash; - } - ) - { src = ./.; } -).shellNix \ No newline at end of file