Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradient implementation does not work in Wasm #1523

Closed
2 tasks done
sergiyprotsiv opened this issue Nov 10, 2022 · 11 comments
Closed
2 tasks done

Gradient implementation does not work in Wasm #1523

sergiyprotsiv opened this issue Nov 10, 2022 · 11 comments
Labels
bug Something isn't working rendering
Milestone

Comments

@sergiyprotsiv
Copy link

Is there an existing issue for this?

  • I have searched the existing issues.

Is this issue related to iced?

  • My hardware is compatible and my graphics drivers are up-to-date.

What happened?

Trying to run Iced with wgpu compiled in webgl mode (e.g. in wasm or in the integration_wgpu example) results in an error

`thread 'main' panicked at 'wgpu error: Validation Error

Caused by:
In Device::create_render_pipeline
note: label = iced_wgpu::triangle::gradient pipeline
Internal error in VERTEX | FRAGMENT | VERTEX_FRAGMENT shader: new_render_pipeline_state: "Compiler encountered an internal error"`

This is related to the new gradient pipeline employing Storage Buffers in a fragment shader (which webgl does not support).

What is the expected behavior?

I expected the app to compile and run, and either take a performance hit (due to "faking" storage buffers using uniforms or textures) or at least only break when the gradients are actually used. As is, Iced does not compile the counter example nor the integration_wgpu. It could be that the gradients are now used in some default widgets that causes this.

Version

master

Operative System

macOS

Do you have any log output?

No response

@sergiyprotsiv sergiyprotsiv added the bug Something isn't working label Nov 10, 2022
@bungoboingo
Copy link
Contributor

bungoboingo commented Nov 10, 2022

As you've surmised, this is due to WASM target for wgpu not supporting storage buffers. The idea was to not support gradients for WASM right now, but I agree the app should still compile especially if you are not using gradients. I'll open a PR for a temporary fix for this until a real implementation can be written (or the ability to use storage buffers for WASM target is added to wgpu) where I will just check for a WASM target and not use the gradient pipeline.

@bungoboingo
Copy link
Contributor

Have a temp fix for this in #1524. Ran integration_wgpu and everything seems to be in order.

In the long term I think we can add a statically sized uniform array variant like we do for the OpenGL side for gradients for a WASM target.

@sergiyprotsiv
Copy link
Author

Thanks @bungoboingo, can confirm that the Wasm version of integration_wgpu works in your branch. I still cannot compile it for native using cargo run since this example itself imports wgpu with webgl flag (without the target being Wasm). So perhaps a medium-term solution would choose to include gradients based on the wgpu feature set, if that is possible.

@bungoboingo
Copy link
Contributor

bungoboingo commented Nov 11, 2022

Sorry, just to clarify: you cannot run the integration_wgpu example natively using just plain old cargo run? Or you cannot run the integration_wgpu example when executing the wasm binary natively without wasm-bindgen?

@sergiyprotsiv
Copy link
Author

Can't run it natively using plain old cargo run. I thought it was due to iced_wgpu = { path = "../../wgpu", features = ["webgl"] } in Cargo.toml, but removing the explicit webgl does not help. The example used to work in 0.4.

@bungoboingo
Copy link
Contributor

Hmm, I can run the integration_wgpu example natively on my pc on my PR branch & master and it runs fine. Are you getting any errors?

@sergiyprotsiv
Copy link
Author

I checked on a Linux machine and it runs there, so the issue is likely with my Mac's graphics configuration. In any case, Wasm works on both platforms, so I am closing the issue. Would be great for your fix to be integrated back into the master!

@hecrj hecrj added this to the 0.6.0 milestone Nov 15, 2022
@YI--
Copy link

YI-- commented Nov 22, 2022

Hi , I had a similar problem on mac

`thread 'main' panicked at 'wgpu error: Validation Error

Caused by:
In Device::create_render_pipeline
note: label = iced_wgpu::triangle::gradient pipeline
Internal error in VERTEX | FRAGMENT | VERTEX_FRAGMENT shader: new_render_pipeline_state: "Compiler encountered an internal error"

', /xxx/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/wgpu-0.14.0/src/backend/direct.rs:2403:5
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace`

@bungoboingo
Copy link
Contributor

On macos? Is it a m1 or an intel chip?

@YI--
Copy link

YI-- commented Nov 23, 2022

On macos? Is it a m1 or an intel chip?

Hi

Sorry 😅, I provided too little information;

OS:
macOS: 12.6 (21G115)
CPU/GPU: Intel

Rust:
cargo 1.65.0 (4bc8f24d3 2022-10-20)
rustc 1.65.0 (897e37553 2022-11-02)
rustup 1.25.1 (bb60b1e89 2022-07-12)

eg:
I used the program from the example directly and had the same problem;
https://github.com/iced-rs/iced/tree/master/examples/tour

log:

em_er@em-erdeMacBook-Pro iced-master % RUST_BACKTRACE=1 cargo run --package tour 

    Finished dev [unoptimized + debuginfo] target(s) in 0.33s
     Running `target/debug/tour`
[2022-11-23T01:48:35Z ERROR wgpu::backend::direct] Shader translation error for stage VERTEX | FRAGMENT | VERTEX_FRAGMENT: new_render_pipeline_state: "Compiler encountered an internal error"
[2022-11-23T01:48:35Z ERROR wgpu::backend::direct] Please report it to https://github.com/gfx-rs/naga
[2022-11-23T01:48:35Z ERROR wgpu::backend::direct] Handling wgpu errors as fatal by default
thread 'main' panicked at 'wgpu error: Validation Error

Caused by:
    In Device::create_render_pipeline
      note: label = `iced_wgpu::triangle::gradient pipeline`
    Internal error in VERTEX | FRAGMENT | VERTEX_FRAGMENT shader: new_render_pipeline_state: "Compiler encountered an internal error"

', /Users/em_er/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/wgpu-0.14.0/src/backend/direct.rs:2403:5
stack backtrace:
   0: rust_begin_unwind
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/panicking.rs:142:14
   2: wgpu::backend::direct::default_error_handler
             at /Users/em_er/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/wgpu-0.14.0/src/backend/direct.rs:2403:5
   3: core::ops::function::Fn::call
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/ops/function.rs:77:5
   4: <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/alloc/src/boxed.rs:1954:9
   5: wgpu::backend::direct::ErrorSinkRaw::handle_error
             at /Users/em_er/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/wgpu-0.14.0/src/backend/direct.rs:2389:17
   6: wgpu::backend::direct::Context::handle_error
             at /Users/em_er/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/wgpu-0.14.0/src/backend/direct.rs:254:9
   7: <wgpu::backend::direct::Context as wgpu::Context>::device_create_render_pipeline
             at /Users/em_er/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/wgpu-0.14.0/src/backend/direct.rs:1412:13
   8: wgpu::Device::create_render_pipeline
             at /Users/em_er/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/wgpu-0.14.0/src/lib.rs:2194:17
   9: iced_wgpu::triangle::gradient::Pipeline::new
             at ./wgpu/src/triangle/gradient.rs:115:13
  10: iced_wgpu::triangle::Pipeline::new
             at ./wgpu/src/triangle.rs:90:27
  11: iced_wgpu::backend::Backend::new
             at ./wgpu/src/backend.rs:48:13
  12: iced_wgpu::window::compositor::Compositor<Theme>::create_backend
             at ./wgpu/src/window/compositor.rs:117:9
  13: <iced_wgpu::window::compositor::Compositor<Theme> as iced_graphics::window::compositor::Compositor>::new
             at ./wgpu/src/window/compositor.rs:136:23
  14: iced_winit::application::run
             at ./winit/src/application.rs:181:34
  15: iced::application::Application::run
             at ./src/application.rs:216:12
  16: iced::sandbox::Sandbox::run
             at ./src/sandbox.rs:160:9
  17: tour::main
             at ./examples/tour/src/main.rs:13:5
  18: core::ops::function::FnOnce::call_once
             at /rustc/897e37553bba8b42751c67658967889d11ecd120/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

For reference only:
I also searched the issues of wgpu and found a related issue;
gfx-rs/wgpu#3136

I haven't verified it works in Linux or Windows

@bungoboingo
Copy link
Contributor

Hmm, I'm able to run the example on my Intel mac without problems, very confusing. I'll poke around and see what I can find!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working rendering
Projects
None yet
Development

No branches or pull requests

4 participants