Wgpu-rs: How to enable serde feature on wgpu-types through wgpu-rs ?

Created on 27 Apr 2020  路  8Comments  路  Source: gfx-rs/wgpu-rs

wgpu-types has a feature to allow (de)serialization for types, descriptors and enums.
How can I enable it through wgpu-rs ?

question

All 8 comments

@gzp-crey can't you add a dependency to wgpu-types to your project and enable the serde feature this way?

I'm using the git version right now (to play with the latest wasm support ):
wgpu = {git = "https://github.com/gfx-rs/wgpu-rs.git", branch = "master"}

I'm not sure how to add the wgpu-types without some extra check during updates as type is using git revision and I have no idea what to provide for package version in this case. I'd use wgpu-types directly if someone shows and example how to do so :)

Also according to https://doc.rust-lang.org/cargo/reference/features.html#usage-in-packages I think it'd make sense to add the feature but I'm far for being an expert on the topic :).

I hear you. So if you have this in your Cargo.toml

wgpu-types = {git = "https://github.com/gfx-rs/wgpu", rev = "5c172dd4756aa152b4f3350e624d7b1b5d24ddda", features = "serde"}

This should get you the same result. It may be slightly annoying (I agree!) that whenever you do cargo update -p wgpu, you'll need to check what revision of wgpu-types is being used by wgpu and adjust your Cargo.toml accordingly.

I wonder if it would work to just leave the git path without a revision here, such that Cargo picks the revision it already has for wgpu crate... If that works, it would be magically wonderful!

I've tried it, but no magic happened :(

in Cargo.toml

wgpu-types = {git = "https://github.com/gfx-rs/wgpu", features = ["serde"]}
wgpu = {git = "https://github.com/gfx-rs/wgpu-rs.git", branch = "master"}

compile result:

 Compiling gfx-backend-vulkan v0.5.6
   Compiling wgpu-types v0.5.0 (https://github.com/gfx-rs/wgpu#d4532350)
   Compiling wgpu-types v0.5.0 (https://github.com/gfx-rs/wgpu?rev=5c172dd4756aa152b4f3350e624d7b1b5d24ddda#5c172dd4)
   Compiling wgpu-core v0.5.0 (https://github.com/gfx-rs/wgpu?rev=5c172dd4756aa152b4f3350e624d7b1b5d24ddda#5c172dd4)
   Compiling wgpu v0.5.0 (https://github.com/gfx-rs/wgpu-rs.git#49640d24)
   Compiling shine-game v0.1.0 (D:\work\shine-backend\game\game)
error[E0277]: the trait bound `wgpu_types::VertexFormat: config::_IMPL_DESERIALIZE_FOR_Config::_serde::Serialize` is not satisfied             
 --> game\src\render\pipeline_descriptor.rs:8:14
  |
8 |     Position(wgpu::VertexFormat),
  |              ^^^^^^^^^^^^^^^^^^ the trait `config::_IMPL_DESERIALIZE_FOR_Config::_serde::Serialize` is not implemented for `wgpu_types::VertexFormat`

It seems as it tries to compile two instance with different version of the package.
One for my use: d4532350 is the current master head for wgpu
Another used by the wgpu-rs

If I add the rev = "5c172dd4756aa152b4f3350e624d7b1b5d24ddda" the feature is picked up cargo correctly but it is not too ergonomic. So It could be a workaround if the new feature for wgpu-rs is rejected.

Any update on this issue ?
I see "trace", "replay" feature were added to the wgpu-type but it still cannot be enabled through the wgpu crate.

"trace" is a feature on wgpu-rs and can be enabled directly now.
Also, you were able to enable the feature previously by specifying the exact revision.
So is there anything else you are missing?

wgpu-rs enables only trace in core
but it enables only Serialize but not Deserialize in wgpu-types

Enabling it through revision is a real pain as after each update I have to open the git repo, find the exact revison...

So I'm still missing the Deserialize feature from wgpu-rs.

Ok, that's fair. Let's propagate the replay feature from wgpu-rs to the dependencies, just like with trace.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gzp-crey picture gzp-crey  路  3Comments

donpdonp picture donpdonp  路  3Comments

OptimisticPeach picture OptimisticPeach  路  3Comments

sagacity picture sagacity  路  3Comments

kvark picture kvark  路  3Comments