calebwin / emu

The write-once-run-anywhere GPGPU library for Rust
https://calebwin.github.io/emu
MIT License
1.6k stars 53 forks source link

Example code given in readme doesn't seem to work #45

Open JonathanWoollett-Light opened 4 years ago

JonathanWoollett-Light commented 4 years ago

Test project: emu_test.zip

Errors (and warning) produced:

error[E0433]: failed to resolve: use of undeclared type or module `futures`
  --> src\main.rs:15:5
   |
15 |     futures::executor::block_on(assert_device_pool_initialized());
   |     ^^^^^^^ use of undeclared type or module `futures`

error[E0433]: failed to resolve: use of undeclared type or module `GlslBuilder`
  --> src\main.rs:23:9
   |
23 |         GlslBuilder::new()
   |         ^^^^^^^^^^^ use of undeclared type or module `GlslBuilder`

error[E0433]: failed to resolve: use of undeclared type or module `futures`
  --> src\main.rs:70:22
   |
70 |     println!("{:?}", futures::executor::block_on(x.get())?);
   |                      ^^^^^^^ use of undeclared type or module `futures`

error[E0412]: cannot find type `GlslCompile` in this scope
  --> src\main.rs:22:31
   |
22 |     let c = compile::<String, GlslCompile, _, GlobalCache>(
   |                               ^^^^^^^^^^^ not found in this scope

warning: unused import: `emu_glsl::*`
 --> src\main.rs:1:5
  |
1 | use emu_glsl::*;
  |     ^^^^^^^^^^^
  |
  = note: `#[warn(unused_imports)]` on by default

error[E0277]: the trait bound `Rectangle: zerocopy::AsBytes` is not satisfied
  --> src\main.rs:18:71
   |
18 |     let mut x: DeviceBox<[Rectangle]> = vec![Default::default(); 128].as_device_boxed()?;
   |                                                                       ^^^^^^^^^^^^^^^ the trait `zerocopy::AsBytes` is not implemented for `Rectangle`
   |
help: trait impl with same name found
  --> src\main.rs:6:10
   |
6  | #[derive(AsBytes, FromBytes, Copy, Clone, Default, Debug)]
   |          ^^^^^^^
   = note: Perhaps two different versions of crate `zerocopy` are being used?
   = note: required because of the requirements on the impl of `zerocopy::AsBytes` for `[Rectangle]`
   = note: required because of the requirements on the impl of `emu_core::boxed::AsDeviceBoxed<[Rectangle]>` for `std::vec::Vec<Rectangle>`

error[E0599]: no method named `get` found for type `emu_core::device::DeviceBox<[Rectangle]>` in the current scope
  --> src\main.rs:70:52
   |
70 |     println!("{:?}", futures::executor::block_on(x.get())?);
   |                                                  --^^^
   |                                                  | |
   |                                                  | this is an associated function, not a method
   |                                                  help: use associated function syntax instead: `emu_core::device::DeviceBox::<[Rectangle]>::get`
   |
   = note: found the following associated functions; to be used as methods, functions must have a `self` parameter
note: the candidate is defined in the trait `emu_core::cache::Cache`
  --> C:\Users\jonat\.cargo\registry\src\github.com-1ecc6299db9ec823\emu_core-0.1.1\src\cache.rs:20:5
   |
20 |     fn get(key: u64) -> Arc<DeviceFnMut>;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = help: to disambiguate the method call, write `emu_core::cache::Cache::get(x)` instead
   = note: the method `get` exists but the following trait bounds were not satisfied:
           `Rectangle : zerocopy::FromBytes`

error: aborting due to 6 previous errors

Some errors have detailed explanations: E0277, E0412, E0433, E0599.
For more information about an error, try `rustc --explain E0277`.
error: could not compile `emu_test`.

To learn more, run the command again with --verbose.
calebwin commented 4 years ago

Does code from the examples directory work though? I always seem to be messing up the import stuff. It looks like I once again have multiple copies of a crate or something.

I'll try to take a look at what might be wrong soon.

demmel commented 4 years ago

I think it's because the readme example assumes that the futures is included as a dependency but doesn't state that. If you add futures = "0.3.5" to your Cargo.toml, that should fix the errors about futures

demmel commented 4 years ago

However, after fixing the dependency in Cargo.toml, I ran in to the following error with the example in the readme

error[E0277]: the trait bound `emu_core::compile_impls::GlslCompile: emu_core::compile::CompileToSpirv<std::string::String, _>` is not satisfied
   --> src\bin\main.rs:23:11
    |
23  |   let c = compile::<String, GlslCompile, _, GlobalCache>(
    |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `emu_core::compile::CompileToSpirv<std::string::String, _>` is not implemented for `emu_core::compile_impls::GlslCompile`
    |
   ::: C:\Users\demmel\.cargo\registry\src\github.com-1ecc6299db9ec823\emu_core-0.1.1\src\compile.rs:191:28
    |
191 | pub fn compile<I: Hash, U: CompileToSpirv<I, P>, P, C: Cache>(
    |                            -------------------- required by this bound in `emu_core::compile::compile`
    |
    = help: the following implementations were found:
              <emu_core::compile_impls::GlslCompile as emu_core::compile::CompileToSpirv<emu_core::compile_impls::Glsl, std::vec::Vec<u32>>>
calebwin commented 4 years ago

Are you using emu_core with the glsl-compile feature enabled?

[dependencies.emu_core]
version = "0.1.1"
features = ["glsl-compile"]
demmel commented 4 years ago

Yeah, that was part of my issue at first. Turns out the error above was that I needed to replace String with Glsl. Everything is working well now.

peter-lyons-kehl commented 4 years ago

Also, the example in README.md has fn main defined twice. You want to rename the first occurrence to fn do_some_stuff.