Generate C header#10
Conversation
wgpu-bindings/bindings.h
Outdated
| T *_0; | ||
| }; | ||
|
|
||
| using DeviceHandle = Handle<Device<B>>; |
There was a problem hiding this comment.
Generics either aren't working here, or they're expected to be resolved manually by us.
wgpu-bindings/bindings.h
Outdated
|
|
||
| struct BufferDescriptor { | ||
| uint32_t size; | ||
| BufferUsageFlags usage; |
There was a problem hiding this comment.
bitflags aren't supported yet, see mozilla/cbindgen#100
We could just expose uint32_t everywhere for flags, and map back on the Rust side...
wgpu-bindings/bindings.h
Outdated
| T *_0; | ||
| }; | ||
|
|
||
| using DeviceHandle = Handle<Device<B>>; |
There was a problem hiding this comment.
Do we expect to receive pointers or handle structs for these? For example, if we want this to exactly match the API used for IPC, pointers might be better
There was a problem hiding this comment.
not sure I understand the question, please clarify
There was a problem hiding this comment.
Just wondering if the intent would be to reuse this header as the interface for IPC too (not sure how it's planned), or whether this header would only used directly (within the graphics process) with a separate interface for IPC.
There was a problem hiding this comment.
It's a great question! Here is the thing: we need wgpu-native C header so that native apps (written in C or anything) can target both native and WASM. And we need wgpu-remote C header so that Gecko can call into us. Technically, these are two completely different things, but I believe we'd have a much easier time if these were exactly the same. So I think we should use the header generated here for both.
kvark
left a comment
There was a problem hiding this comment.
I do wonder though if we should generate the header as a build step for wgpu-native instead of a separate project.
|
Yeah that would work well too, although it will add extra time to regular builds even if the signatures haven't changed. |
wgpu-native/src/registry.rs
Outdated
|
|
||
| #[cfg(not(feature = "remote"))] | ||
| lazy_static! { | ||
| pub(crate) static ref ADAPTER_REGISTRY: Mutex<LocalRegistry<AdapterHandle>> = |
There was a problem hiding this comment.
It would be great to drop this Mutex too but it's not obvious how to support both paths without it. We need a no-op mutex or some helper functions to wrap usage of the mutex for the remote case.
There was a problem hiding this comment.
I think we should just move the mutability (i.e. Mutex) into the internals of the registry implementation, so that registry itself is Send+Sync and most methods are &self
| pub(crate) type Id = u32; | ||
|
|
||
| pub(crate) struct Registry<T> { | ||
| pub(crate) trait Registry<T> { |
There was a problem hiding this comment.
I just used a trait here to ensure we keep both registry implementations in sync, but it's not really necessary.
There was a problem hiding this comment.
makes sense. We might even go for Registry: IndexMut<Id>
|
@kvark see my latest commit, we now avoid the map for "local" usage, and "local" vs. "remote" are distinguished by a Cargo feature and |
wgpu-bindings/src/main.rs
Outdated
| crate_dir.push("../wgpu-native"); | ||
|
|
||
| let config = cbindgen::Config { | ||
| header: Some(String::from("#ifdef WGPU_REMOTE\n typedef uint32_t WGPUId;\n#else\n typedef void *WGPUId;\n#endif")), |
There was a problem hiding this comment.
looks to be a good case for raw strings:
const HEADER: &str = #"
#ifdef ...
...
#endif
";There was a problem hiding this comment.
Regular strings will work fine too, unfortunately doesn't avoid the leading newline though. I'll probably move it to a constant and simply use trim when it's used.
| pub(crate) type Id = u32; | ||
|
|
||
| pub(crate) struct Registry<T> { | ||
| pub(crate) trait Registry<T> { |
There was a problem hiding this comment.
makes sense. We might even go for Registry: IndexMut<Id>
wgpu-native/src/registry.rs
Outdated
|
|
||
| #[cfg(not(feature = "remote"))] | ||
| lazy_static! { | ||
| pub(crate) static ref ADAPTER_REGISTRY: Mutex<LocalRegistry<AdapterHandle>> = |
There was a problem hiding this comment.
I think we should just move the mutability (i.e. Mutex) into the internals of the registry implementation, so that registry itself is Send+Sync and most methods are &self
kvark
left a comment
There was a problem hiding this comment.
One nit about parking_lot, otherwise good to go!
wgpu-native/Cargo.toml
Outdated
|
|
||
| [features] | ||
| default = [] | ||
| remote = [] |
There was a problem hiding this comment.
this should bring parking_lot dependency
|
bors r=kvark |
Build succeeded |
10: Update API for new wgpu gl backend support r=kvark a=kyren This won't work until [this pr](gfx-rs#183) is merged in wgpu, but at least this way we can discuss it. Co-authored-by: kyren <kerriganw@gmail.com>
10: Update API for new wgpu gl backend support r=kvark a=kyren This won't work until [this pr](gfx-rs#183) is merged in wgpu, but at least this way we can discuss it. Co-authored-by: kyren <kerriganw@gmail.com>
Integrating latest trunk
Fixes #6
WIP: there are a few issues I've encountered already for the few functions we expose.