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

Example hello fails on MS Windows #4109

Closed
tigerwings opened this issue Sep 1, 2023 · 16 comments
Closed

Example hello fails on MS Windows #4109

tigerwings opened this issue Sep 1, 2023 · 16 comments
Labels
backend: gles Issues with GLES or WebGL

Comments

@tigerwings
Copy link

tigerwings commented Sep 1, 2023

Description
Run hello on Microsoft Windows 10

$ set WGPU_BACKEND=dx12
$ cargo run --example hello
    Finished dev [unoptimized + debuginfo] target(s) in 0.27s
     Running `target\debug\examples\hello.exe`
Error loading EGL entry points.
error: process didn't exit successfully: `target\debug\examples\hello.exe` (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)

while cargo run --example cube works.

Repro steps
After tracing down the issue, it seems this line is the root cause. And the stack trace is the following:

<unknown> 0x0000000000000000
[Inlined] khronos_egl::impl$98::eglQueryString(*mut khronos_egl::Dynamic<libloading::safe::Library,khronos_egl::EGL1_4>,*mut core::ffi::c_void,i32) lib.rs:2032
khronos_egl::Instance<khronos_egl::Dynamic<libloading::safe::Library,khronos_egl::EGL1_4> >::query_string<khronos_egl::Dynamic<libloading::safe::Library,khronos_egl::EGL1_4> >(enum2$<core::option::Option<khronos_egl::egl1_0::Display> >,i32) lib.rs:987
wgpu_hal::gles::egl::impl$14::init(*mut wgpu_hal::InstanceDescriptor) egl.rs:756
wgpu_core::instance::impl$0::new::init<wgpu_hal::gles::Api>(wgpu_hal::gles::Api,*mut wgpu_types::InstanceDescriptor) instance.rs:87
wgpu_core::instance::Instance::new(str,wgpu_types::InstanceDescriptor) instance.rs:104
wgpu_core::global::Global<wgpu_core::identity::IdentityManagerFactory>::new<wgpu_core::identity::IdentityManagerFactory>(str,wgpu_core::identity::IdentityManagerFactory,wgpu_types::InstanceDescriptor) global.rs:36
wgpu::backend::direct::impl$7::init(wgpu_types::InstanceDescriptor) direct.rs:570
wgpu::Instance::new(wgpu_types::InstanceDescriptor) lib.rs:1733
wgpu::impl$21::default() lib.rs:1720
hello::run::async_fn$0(core::pin::Pin<ref_mut$<enum2$<hello::run::async_fn_env$0> > >,core::future::ResumeTy) main.rs:5
core::future::from_generator::impl$1::poll<enum2$<hello::run::async_fn_env$0> >(core::pin::Pin<ref_mut$<core::future::from_generator::GenFuture<enum2$<hello::run::async_fn_env$0> > > >,*mut core::task::wake::Context) 0x00007ff62af72724
pollster::block_on<core::future::from_generator::GenFuture<enum2$<hello::run::async_fn_env$0> > >(core::future::from_generator::GenFuture<enum2$<hello::run::async_fn_env$0> >) lib.rs:128
hello::main() main.rs:26
core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >(*mut ) 0x00007ff62af710cb
[Inlined] core::hint::black_box(tuple$<>) 0x00007ff62af72c3e
std::rt::lang_start::closure$0<tuple$<> >(*mut std::rt::lang_start::closure_env$0<tuple$<> >) 0x00007ff62af733d1
[Inlined] core::ops::function::impls::impl$2::call_once() 0x00007ff62bec86de
[Inlined] std::panicking::try::do_call() 0x00007ff62bec86d3
[Inlined] std::panicking::try() 0x00007ff62bec86d3
[Inlined] std::panic::catch_unwind() 0x00007ff62bec86d3
[Inlined] std::rt::lang_start_internal::closure$2() 0x00007ff62bec86d3
[Inlined] std::panicking::try::do_call() 0x00007ff62bec86d3
[Inlined] std::panicking::try() 0x00007ff62bec86d3
[Inlined] std::panic::catch_unwind() 0x00007ff62bec86d3
std::rt::lang_start_internal() 0x00007ff62bec86d3
std::rt::lang_start<tuple$<> >(*mut ,i64,*mut *mut u8,u8) 0x00007ff62af733aa
main 0x00007ff62af7260c
[Inlined] invoke_main() 0x00007ff62bef0eb8
__scrt_common_main_seh() 0x00007ff62bef0e96
<unknown> 0x00007ff8f8c87614
<unknown> 0x00007ff8fa8a26b1

Expected vs observed behavior
The example should run successfully on Windows.

Extra materials
Screenshots to help explain your problem.
Validation logs can be attached in case there are warnings and errors.
Zip-compressed API traces and GPU captures can also land here.

Platform
Information about your OS, version of wgpu, your tech stack, etc.
OS: Microsoft Windows 10
wgpu: trunk

@teoxoy teoxoy added the backend: gles Issues with GLES or WebGL label Sep 28, 2023
@teoxoy
Copy link
Member

teoxoy commented Sep 28, 2023

The error comes from here: https://chromium.googlesource.com/angle/angle/+/4b94d7bb4fbed9018d198dfdc50c3aa5f9be3ddf/src/libEGL/libEGL.cpp#47.

I'm not sure why though and it doesn't seem there is a way to catch and deal with this error.
@cwfitzgerald any ideas?

@cwfitzgerald
Copy link
Member

I think we've seen this before, if you get a weird version of angle in your path first you'll get this problem. I'm really not sure why it happens, but putting a normally built angle in path fixes it.

@teoxoy
Copy link
Member

teoxoy commented Sep 28, 2023

It's also odd that the cube example works but not the hello. @tigerwings do the other examples work?

I think we've seen this before, if you get a weird version of angle in your path first you'll get this problem. I'm really not sure why it happens, but putting a normally built angle in path fixes it.

It might have to do with the ANGLE_USE_EGL_LOADER define in angle. EnsureEGLLoaded is a noop if it's not defined. I feel like it should not be defined since as far as I understand we already load the dll ourselves?

@teoxoy
Copy link
Member

teoxoy commented Sep 28, 2023

Stepping a bit back:

The examples don't require any additional feature flags and the angle feature is not enabled by default.
Looking into this further, I see that we enable the gles feature on all platforms by default.

What we probably want to do is enable gles by default only on linux & android and map the angle feature to gles for windows & macOS.

@tigerwings
Copy link
Author

tigerwings commented Sep 28, 2023

@tigerwings do the other examples work?

under v0.16 and in those I tried:
cube, water, and halmark work only if the env var is set as WGPU_BACKEND=dx12 ; hello, hello-triangle and wgpu-info show the same error.

under v0.17: none of them work. the new error shows:

error: failed to run custom build command for `nv-flip-sys v0.1.1`

@cwfitzgerald
Copy link
Member

Could you show the whole issue - likely you're missing a C compiler?

@tasogare3710
Copy link

tasogare3710 commented Oct 12, 2023

I was able to reproduce it, this error occurs when libEGL is not found when using the GL backend.

The cause of this problem is that the environment variable WGPU_BACKEND is not respected, wgpu::Backends::all() is used in the following line, which initializes all backends.

https://github.com/gfx-rs/wgpu/blob/858d7d590ef9ebfe1b91f6f0925aacde15cce714/examples/hello/src/main.rs#L5C30-L5C30

@tasogare3710
Copy link

reproducible minimum source code.

set RUST_LOG=debug
async fn run() {
    let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
        backends: wgpu::Backends::GL,
        flags: wgpu::InstanceFlags::default(),
        dx12_shader_compiler: wgpu::Dx12Compiler::default(),
        gles_minor_version: wgpu::Gles3MinorVersion::default(),
    });
    instance
        .request_adapter(&wgpu::RequestAdapterOptions::default())
        .await
        .unwrap();
}

fn main() {
    env_logger::init();
    pollster::block_on(run());
}

important line is DEBUG wgpu_core::instance] Instance::new: failed to create Gl backend in the log, so do not forget to set RUST_LOG=debug.

@teoxoy
Copy link
Member

teoxoy commented Oct 12, 2023

@tigerwings do the other examples work?

under v0.16 and in those I tried: cube, water, and halmark work only if the env var is set as WGPU_BACKEND=dx12 ; hello, hello-triangle and wgpu-info show the same error.

The cause of this problem is that the environment variable WGPU_BACKEND is not respected, wgpu::Backends::all() is used in the following line, which initializes all backends.

https://github.com/gfx-rs/wgpu/blob/858d7d590ef9ebfe1b91f6f0925aacde15cce714/examples/hello/src/main.rs#L5C30-L5C30

This explains why some of the examples were working and some were not.

@teoxoy
Copy link
Member

teoxoy commented Oct 12, 2023

With #4185 merged, the GLES backend is now disabled by default on Windows.
So, the loader won't try to load some random libEGL on the system.

I think we can close this issue and open a new one to track moving the examples over to use the example framework (which takes into account env variables).

@cwfitzgerald thoughts on this?

@cwfitzgerald
Copy link
Member

The hello examples all don't use the framework intentionally to make them easier to grok.

@teoxoy
Copy link
Member

teoxoy commented Oct 16, 2023

We are done here then 🎉

@teoxoy teoxoy closed this as completed Oct 16, 2023
@TheYahton
Copy link

I have the same problem even after you merged #4185
As far as I understand, I don't have libegl and idk how to install it.

@cwfitzgerald
Copy link
Member

What is the exact error you're getting?

@TheYahton
Copy link

TheYahton commented Jan 29, 2024

What is the exact error you're getting?

error: process didn't exit successfully: `target\debug\wgpu-examples.exe hello` (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)

My gpu does not support DirectX 12 or Vulkan. To be sure that OpenGL was used instead of any other API, I tried replacing wgpu::Backends::all() with wgpu::Backends::GL in examples\src\hello\mod.rs and the error was the same.

@cwfitzgerald
Copy link
Member

Could you post a stack trace on a new issue, using latest trunk?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: gles Issues with GLES or WebGL
Projects
None yet
Development

No branches or pull requests

5 participants