From e892d8f3ff63a34dbebf57b582b02dbe46f7f1a7 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 13 Oct 2022 12:01:47 +0200 Subject: [PATCH 1/6] Specify struct for vertex shader input --- crates/fj-viewer/src/graphics/shader.wgsl | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/crates/fj-viewer/src/graphics/shader.wgsl b/crates/fj-viewer/src/graphics/shader.wgsl index 304205923..0dc10d89e 100644 --- a/crates/fj-viewer/src/graphics/shader.wgsl +++ b/crates/fj-viewer/src/graphics/shader.wgsl @@ -1,3 +1,9 @@ +struct VertexInput { + @location(0) position: vec3, + @location(1) normal: vec3, + @location(2) color: vec4, +} + struct VertexOutput { @builtin(position) position: vec4, @location(0) normal: vec3, @@ -13,18 +19,12 @@ struct Uniforms { var uniforms: Uniforms; @vertex -fn vertex( - @location(0) position: vec3, - @location(1) normal: vec3, - @location(2) color: vec4, -) - -> VertexOutput -{ +fn vertex(in: VertexInput) -> VertexOutput { var out: VertexOutput; - out.normal = (uniforms.transform_normals * vec4(normal, 0.0)).xyz; - out.position = uniforms.transform * vec4(position, 1.0); + out.normal = (uniforms.transform_normals * vec4(in.normal, 0.0)).xyz; + out.position = uniforms.transform * vec4(in.position, 1.0); // We use premultiplied alpha blending. - out.color = vec4(color.rgb * color.a, color.a); + out.color = vec4(in.color.rgb * in.color.a, in.color.a); return out; } From ecb0301cc69d1d501e313041bce4dd82fbfb0439 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 13 Oct 2022 12:02:42 +0200 Subject: [PATCH 2/6] Update order of code --- crates/fj-viewer/src/graphics/shader.wgsl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/crates/fj-viewer/src/graphics/shader.wgsl b/crates/fj-viewer/src/graphics/shader.wgsl index 0dc10d89e..bb0011c5c 100644 --- a/crates/fj-viewer/src/graphics/shader.wgsl +++ b/crates/fj-viewer/src/graphics/shader.wgsl @@ -1,3 +1,11 @@ +struct Uniforms { + transform: mat4x4, + transform_normals: mat4x4, +}; + +@group(0) @binding(0) +var uniforms: Uniforms; + struct VertexInput { @location(0) position: vec3, @location(1) normal: vec3, @@ -10,14 +18,6 @@ struct VertexOutput { @location(1) color: vec4, }; -struct Uniforms { - transform: mat4x4, - transform_normals: mat4x4, -}; - -@group(0) @binding(0) -var uniforms: Uniforms; - @vertex fn vertex(in: VertexInput) -> VertexOutput { var out: VertexOutput; From 5fa849d883e6c6483db1183f047f0c8f2a84612f Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 13 Oct 2022 12:05:10 +0200 Subject: [PATCH 3/6] Consolidate duplicate return values --- crates/fj-viewer/src/graphics/shader.wgsl | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/crates/fj-viewer/src/graphics/shader.wgsl b/crates/fj-viewer/src/graphics/shader.wgsl index bb0011c5c..035900538 100644 --- a/crates/fj-viewer/src/graphics/shader.wgsl +++ b/crates/fj-viewer/src/graphics/shader.wgsl @@ -18,6 +18,10 @@ struct VertexOutput { @location(1) color: vec4, }; +struct FragmentOutput { + @location(0) color: vec4, +} + @vertex fn vertex(in: VertexInput) -> VertexOutput { var out: VertexOutput; @@ -32,7 +36,7 @@ fn vertex(in: VertexInput) -> VertexOutput { let pi: f32 = 3.14159265359; @fragment -fn frag_model(in: VertexOutput) -> @location(0) vec4 { +fn frag_model(in: VertexOutput) -> FragmentOutput { let light = vec3(0.0, 0.0, -1.0); let angle = acos(dot(light, -in.normal)); @@ -40,17 +44,22 @@ fn frag_model(in: VertexOutput) -> @location(0) vec4 { let f_normal = max(1.0 - f_angle, 0.0); - let color = vec4(in.color.rgb * f_normal, in.color.a); + var out: FragmentOutput; + out.color = vec4(in.color.rgb * f_normal, in.color.a); - return color; + return out; } @fragment -fn frag_mesh(in: VertexOutput) -> @location(0) vec4 { - return vec4(1.0 - in.color.rgb, in.color.a); +fn frag_mesh(in: VertexOutput) -> FragmentOutput { + var out: FragmentOutput; + out.color = vec4(1.0 - in.color.rgb, in.color.a); + return out; } @fragment -fn frag_lines(in: VertexOutput) -> @location(0) vec4 { - return vec4(in.color.rgb, in.color.a); +fn frag_lines(in: VertexOutput) -> FragmentOutput { + var out: FragmentOutput; + out.color = vec4(in.color.rgb, in.color.a); + return out; } From 4ad8c5a78182587db58fa1ec943962d4eb8fb386 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 13 Oct 2022 12:33:04 +0200 Subject: [PATCH 4/6] Disable default `egui-winit` features This takes care of this error: ``` 2022-10-13T10:23:44.527262Z ERROR egui_winit::clipboard: Cannot initialize smithay clipboard without a display handle! at /home/hanno/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/egui-winit-0.19.0/src/clipboard.rs:139 ``` See #807 for more context. --- Cargo.lock | 228 ++---------------------------------- crates/fj-window/Cargo.toml | 5 +- 2 files changed, 14 insertions(+), 219 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index ba5f04829..823d90e79 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -98,23 +98,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "arboard" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc120354d1b5ec6d7aaf4876b602def75595937b5e15d356eb554ab5177e08bb" -dependencies = [ - "clipboard-win", - "log", - "objc", - "objc-foundation", - "objc_id", - "parking_lot", - "thiserror", - "winapi", - "x11rb", -] - [[package]] name = "arc-swap" version = "1.5.1" @@ -317,7 +300,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a22a6a8f622f797120d452c630b0ab12e1331a1a753e2039ce7868d4ac77b4ee" dependencies = [ "log", - "nix 0.24.2", + "nix", "slotmap", "thiserror", "vec_map", @@ -360,12 +343,6 @@ version = "1.0.73" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2fff2a6927b3bb87f9595d67196a70493f627687a71d87a0d692242c33f58c11" -[[package]] -name = "cesu8" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" - [[package]] name = "cfg-if" version = "1.0.0" @@ -431,17 +408,6 @@ dependencies = [ "os_str_bytes", ] -[[package]] -name = "clipboard-win" -version = "4.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4ab1b92798304eedc095b53942963240037c0516452cb11aeba709d420b2219" -dependencies = [ - "error-code", - "str-buf", - "winapi", -] - [[package]] name = "cmake" version = "0.1.48" @@ -517,16 +483,6 @@ dependencies = [ "unicode-width", ] -[[package]] -name = "combine" -version = "4.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4" -dependencies = [ - "bytes", - "memchr", -] - [[package]] name = "copyless" version = "0.1.5" @@ -864,12 +820,9 @@ version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "07ddc525334c416e11580123e147b970f738507f427c9fb1cd09ea2dd7416a3a" dependencies = [ - "arboard", "egui", "instant", - "smithay-clipboard", "tracing", - "webbrowser", "winit", ] @@ -925,16 +878,6 @@ dependencies = [ "parking_lot", ] -[[package]] -name = "error-code" -version = "2.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64f18991e7bf11e7ffee451b5318b5c1a73c52d0d0ada6e5a3017c8c1ced6a21" -dependencies = [ - "libc", - "str-buf", -] - [[package]] name = "expat-sys" version = "2.1.6" @@ -1335,16 +1278,6 @@ dependencies = [ "byteorder 1.4.3", ] -[[package]] -name = "gethostname" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1ebd34e35c46e00bb73e81363248d627782724609fe1b6396f553f68fe3862e" -dependencies = [ - "libc", - "winapi", -] - [[package]] name = "getrandom" version = "0.2.7" @@ -1701,20 +1634,6 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" -[[package]] -name = "jni" -version = "0.19.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c6df18c2e3db7e453d3c6ac5b3e9d5182664d28788126d39b91f2d1e22b017ec" -dependencies = [ - "cesu8", - "combine", - "jni-sys", - "log", - "thiserror", - "walkdir", -] - [[package]] name = "jni-sys" version = "0.3.0" @@ -2018,19 +1937,6 @@ dependencies = [ "tempfile", ] -[[package]] -name = "ndk" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2032c77e030ddee34a6787a64166008da93f6a352b629261d0fee232b8742dd4" -dependencies = [ - "bitflags", - "jni-sys", - "ndk-sys 0.3.0", - "num_enum", - "thiserror", -] - [[package]] name = "ndk" version = "0.7.0" @@ -2039,7 +1945,7 @@ checksum = "451422b7e4718271c8b5b3aadf5adedba43dc76312454b387e98fae0fc951aa0" dependencies = [ "bitflags", "jni-sys", - "ndk-sys 0.4.0", + "ndk-sys", "num_enum", "raw-window-handle 0.5.0", "thiserror", @@ -2051,21 +1957,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b" -[[package]] -name = "ndk-glue" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d0c4a7b83860226e6b4183edac21851f05d5a51756e97a1144b7f5a6b63e65f" -dependencies = [ - "lazy_static", - "libc", - "log", - "ndk 0.6.0", - "ndk-context", - "ndk-macro", - "ndk-sys 0.3.0", -] - [[package]] name = "ndk-glue" version = "0.7.0" @@ -2074,10 +1965,10 @@ checksum = "0434fabdd2c15e0aab768ca31d5b7b333717f03cf02037d5a0a3ff3c278ed67f" dependencies = [ "libc", "log", - "ndk 0.7.0", + "ndk", "ndk-context", "ndk-macro", - "ndk-sys 0.4.0", + "ndk-sys", "once_cell", "parking_lot", ] @@ -2095,15 +1986,6 @@ dependencies = [ "syn", ] -[[package]] -name = "ndk-sys" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e5a6ae77c8ee183dcbbba6150e2e6b9f3f4196a7666c02a715a95692ec1fa97" -dependencies = [ - "jni-sys", -] - [[package]] name = "ndk-sys" version = "0.4.0" @@ -2113,19 +1995,6 @@ dependencies = [ "jni-sys", ] -[[package]] -name = "nix" -version = "0.22.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4916f159ed8e5de0082076562152a76b7a1f64a01fd9d1e0fea002c37624faf" -dependencies = [ - "bitflags", - "cc", - "cfg-if", - "libc", - "memoffset", -] - [[package]] name = "nix" version = "0.24.2" @@ -2294,17 +2163,6 @@ dependencies = [ "objc_exception", ] -[[package]] -name = "objc-foundation" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" -dependencies = [ - "block", - "objc", - "objc_id", -] - [[package]] name = "objc_exception" version = "0.1.2" @@ -2314,15 +2172,6 @@ dependencies = [ "cc", ] -[[package]] -name = "objc_id" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" -dependencies = [ - "objc", -] - [[package]] name = "object" version = "0.29.0" @@ -3198,23 +3047,13 @@ dependencies = [ "lazy_static", "log", "memmap2", - "nix 0.24.2", + "nix", "pkg-config", "wayland-client", "wayland-cursor", "wayland-protocols", ] -[[package]] -name = "smithay-clipboard" -version = "0.6.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a345c870a1fae0b1b779085e81b51e614767c239e93503588e54c5b17f4b0e8" -dependencies = [ - "smithay-client-toolkit", - "wayland-client", -] - [[package]] name = "snafu" version = "0.7.2" @@ -3305,12 +3144,6 @@ dependencies = [ "byteorder 0.4.2", ] -[[package]] -name = "str-buf" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9e08d8363704e6c71fc928674353e6b7c23dcea9d82d7012c8faf2a3a025f8d0" - [[package]] name = "strsim" version = "0.10.0" @@ -3837,7 +3670,7 @@ dependencies = [ "bitflags", "downcast-rs", "libc", - "nix 0.24.2", + "nix", "scoped-tls", "wayland-commons", "wayland-scanner", @@ -3850,7 +3683,7 @@ version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8691f134d584a33a6606d9d717b95c4fa20065605f798a3f350d78dced02a902" dependencies = [ - "nix 0.24.2", + "nix", "once_cell", "smallvec", "wayland-sys", @@ -3862,7 +3695,7 @@ version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6865c6b66f13d6257bef1cd40cbfe8ef2f150fb8ebbdb1e8e873455931377661" dependencies = [ - "nix 0.24.2", + "nix", "wayland-client", "xcursor", ] @@ -3911,20 +3744,6 @@ dependencies = [ "wasm-bindgen", ] -[[package]] -name = "webbrowser" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc6a3cffdb686fbb24d9fb8f03a213803277ed2300f11026a3afe1f108dc021b" -dependencies = [ - "jni", - "ndk-glue 0.6.2", - "url", - "web-sys", - "widestring", - "winapi", -] - [[package]] name = "wgpu" version = "0.13.1" @@ -4041,12 +3860,6 @@ dependencies = [ "safe_arch 0.6.0", ] -[[package]] -name = "widestring" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17882f045410753661207383517a6f62ec3dbeb6a4ed2acce01f0728238d1983" - [[package]] name = "winapi" version = "0.3.9" @@ -4072,15 +3885,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "winapi-wsapoll" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c17110f57155602a80dca10be03852116403c9ff3cd25b079d666f2aa3df6e" -dependencies = [ - "winapi", -] - [[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" @@ -4145,8 +3949,8 @@ dependencies = [ "libc", "log", "mio", - "ndk 0.7.0", - "ndk-glue 0.7.0", + "ndk", + "ndk-glue", "objc", "once_cell", "parking_lot", @@ -4192,18 +3996,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "x11rb" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e99be55648b3ae2a52342f9a870c0e138709a3493261ce9b469afe6e4df6d8a" -dependencies = [ - "gethostname", - "nix 0.22.3", - "winapi", - "winapi-wsapoll", -] - [[package]] name = "xcursor" version = "0.3.4" diff --git a/crates/fj-window/Cargo.toml b/crates/fj-window/Cargo.toml index ada8da742..5092bc562 100644 --- a/crates/fj-window/Cargo.toml +++ b/crates/fj-window/Cargo.toml @@ -15,8 +15,11 @@ fj-host.workspace = true fj-operations.workspace = true fj-viewer.workspace = true fj-interop.workspace = true -egui-winit = "0.19.0" futures = "0.3.24" thiserror = "1.0.35" tracing = "0.1.37" winit = "0.27.4" + +[dependencies.egui-winit] +version = "0.19.0" +default-features = false From 085c161ed30c2e0420d1dbda311868004f1d5f2d Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 13 Oct 2022 12:49:47 +0200 Subject: [PATCH 5/6] Remove empty comment --- crates/fj-window/src/run.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/fj-window/src/run.rs b/crates/fj-window/src/run.rs index 2988fedfd..401bebaae 100644 --- a/crates/fj-window/src/run.rs +++ b/crates/fj-window/src/run.rs @@ -90,8 +90,6 @@ pub fn run( } } - // - if let Event::WindowEvent { event: window_event, .. From 74887df61ee7a1f7bc04647fda29af34518a4ce6 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Thu, 13 Oct 2022 13:03:30 +0200 Subject: [PATCH 6/6] Handle window resize once per frame --- crates/fj-window/src/run.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/fj-window/src/run.rs b/crates/fj-window/src/run.rs index 401bebaae..a7815a8cb 100644 --- a/crates/fj-window/src/run.rs +++ b/crates/fj-window/src/run.rs @@ -51,6 +51,12 @@ pub fn run( let mut camera = Camera::new(&Default::default()); let mut camera_update_once = watcher.is_some(); + // Only handle resize events once every frame. This filters out spurious + // resize events that can lead to wgpu warnings. See this issue for some + // context: + // https://github.com/rust-windowing/winit/issues/2094 + let mut new_size = None; + event_loop.run(move |event, _, control_flow| { trace!("Handling event: {:?}", event); @@ -147,11 +153,10 @@ pub fn run( event: WindowEvent::Resized(size), .. } => { - let size = Size { + new_size = Some(Size { width: size.width, height: size.height, - }; - renderer.handle_resize(size); + }); } Event::WindowEvent { event: WindowEvent::MouseInput { state, button, .. }, @@ -169,6 +174,9 @@ pub fn run( if let Some(shape) = &shape { camera.update_planes(&shape.aabb); } + if let Some(size) = new_size.take() { + renderer.handle_resize(size); + } let egui_input = egui_winit_state.take_egui_input(window.window());