Skip to content

Generate C header#10

Merged
bors[bot] merged 8 commits intogfx-rs:masterfrom
grovesNL:bindings
Sep 25, 2018
Merged

Generate C header#10
bors[bot] merged 8 commits intogfx-rs:masterfrom
grovesNL:bindings

Conversation

@grovesNL
Copy link
Copy Markdown
Collaborator

@grovesNL grovesNL commented Sep 20, 2018

Fixes #6

WIP: there are a few issues I've encountered already for the few functions we expose.

@grovesNL grovesNL requested a review from kvark September 20, 2018 18:46
T *_0;
};

using DeviceHandle = Handle<Device<B>>;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generics either aren't working here, or they're expected to be resolved manually by us.


struct BufferDescriptor {
uint32_t size;
BufferUsageFlags usage;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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...

T *_0;
};

using DeviceHandle = Handle<Device<B>>;
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I understand the question, please clarify

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do wonder though if we should generate the header as a build step for wgpu-native instead of a separate project.

@grovesNL
Copy link
Copy Markdown
Collaborator Author

Yeah that would work well too, although it will add extra time to regular builds even if the signatures haven't changed.


#[cfg(not(feature = "remote"))]
lazy_static! {
pub(crate) static ref ADAPTER_REGISTRY: Mutex<LocalRegistry<AdapterHandle>> =
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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> {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just used a trait here to ensure we keep both registry implementations in sync, but it's not really necessary.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense. We might even go for Registry: IndexMut<Id>

@grovesNL
Copy link
Copy Markdown
Collaborator Author

@kvark see my latest commit, we now avoid the map for "local" usage, and "local" vs. "remote" are distinguished by a Cargo feature and #ifdef in the header

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")),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks to be a good case for raw strings:

const HEADER: &str = #"
#ifdef ...
   ...
#endif
";

Copy link
Copy Markdown
Collaborator Author

@grovesNL grovesNL Sep 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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> {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense. We might even go for Registry: IndexMut<Id>


#[cfg(not(feature = "remote"))]
lazy_static! {
pub(crate) static ref ADAPTER_REGISTRY: Mutex<LocalRegistry<AdapterHandle>> =
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One nit about parking_lot, otherwise good to go!


[features]
default = []
remote = []
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should bring parking_lot dependency

@grovesNL grovesNL changed the title WIP: Generate C header Generate C header Sep 25, 2018
@grovesNL
Copy link
Copy Markdown
Collaborator Author

bors r=kvark

bors bot added a commit that referenced this pull request Sep 25, 2018
10: Generate C header r=kvark a=grovesNL

Fixes #6

~~WIP: there are a few issues I've encountered already for the few functions we expose.~~

Co-authored-by: grovesNL <josh@joshgroves.com>
Co-authored-by: Joshua Groves <josh@joshgroves.com>
@bors
Copy link
Copy Markdown
Contributor

bors bot commented Sep 25, 2018

Build succeeded

@bors bors bot merged commit 19ddb63 into gfx-rs:master Sep 25, 2018
@grovesNL grovesNL deleted the bindings branch September 25, 2018 03:26
mitchmindtree pushed a commit to mitchmindtree/wgpu that referenced this pull request Feb 23, 2020
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>
kvark pushed a commit to kvark/wgpu that referenced this pull request Jun 3, 2021
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>
victorvde pushed a commit to victorvde/wgpu that referenced this pull request Apr 23, 2023
cwfitzgerald pushed a commit that referenced this pull request Oct 26, 2023
24: One big cleanup for the 0.3.1 release r=kvark a=kvark

Closes #10 

Co-authored-by: Dzmitry Malyshau <dmalyshau@mozilla.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants