Skip to content

Use callback for request_adapter #375

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

Merged
merged 2 commits into from
Nov 8, 2019
Merged

Use callback for request_adapter #375

merged 2 commits into from
Nov 8, 2019

Conversation

grovesNL
Copy link
Collaborator

@grovesNL grovesNL commented Nov 7, 2019

For now this is mostly a signature change which allows us to start using a callback for request_adapter. Once we have an event loop, the callback could be scheduled to make this asynchronous. At that point the examples and server would have to be updated, because they currently rely on the callback running immediately (inline).

The reason for this change is that request_adapter is supposed to return a Promise in JS, so we can represent it with callbacks at the C API, and Future in Rust (though we'll probably keep using callbacks initially).

I also changed request_adapter to provide an adapter with AdapterId::ERROR when no adapters are available, so we can add basic error handling to wgpu-rs (gfx-rs/wgpu-rs#117).

@grovesNL grovesNL requested a review from kvark November 7, 2019 16:05
@@ -301,11 +302,16 @@ pub extern "C" fn wgpu_create_surface_from_windows_hwnd(
))
}

pub fn request_adapter(
pub type RequestAdapterCallback =
extern "C" fn(adapter: *const AdapterId, userdata: *mut c_void);
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I noticed we use *mut u8 for userdata in buffer mapping, but maybe we should consider using *mut c_void like we do here. For example, we expect userdata to generally be a user-provided type anyway (not necessarily a byte array), so is there any benefit from requiring *mut u8?

Copy link
Member

Choose a reason for hiding this comment

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

yes, I agree, *mut void seems more appropriate. We might need to file a PR to upstream webgpu header

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

Thank you for the PR!
So how do you see us proceeding here? If we merge, all the examples are going to be broken.

@kvark
Copy link
Member

kvark commented Nov 8, 2019

Thank you for addressing my concerns!
bors r+

bors bot added a commit that referenced this pull request Nov 8, 2019
375: Use callback for `request_adapter` r=kvark a=grovesNL

For now this is mostly a signature change which allows us to start using a callback for `request_adapter`. Once we have an event loop, the callback could be scheduled to make this asynchronous. At that point the examples and server would have to be updated, because they currently rely on the callback running immediately (inline).

The reason for this change is that `request_adapter` is supposed to return a `Promise` in JS, so we can represent it with callbacks at the C API, and `Future` in Rust (though we'll probably keep using callbacks initially).

I also changed `request_adapter` to provide an adapter with `AdapterId::ERROR` when no adapters are available, so we can add basic error handling to wgpu-rs (gfx-rs/wgpu-rs#117).

Co-authored-by: Joshua Groves <[email protected]>
@bors
Copy link
Contributor

bors bot commented Nov 8, 2019

Build succeeded

@bors bors bot merged commit 7f25b8c into gfx-rs:master Nov 8, 2019
@grovesNL grovesNL deleted the async_request_adapter branch November 21, 2019 02:19
kvark pushed a commit to kvark/wgpu that referenced this pull request Jun 3, 2021
375: Add water example.  r=kvark,cwfitzgerald a=OptimisticPeach

Solves gfx-rs#329, water example requested by @kvark.

I tuned it to my personal preference of visuals, however it might be different for you. 

Note: I used https://github.com/ashima/webgl-noise for 3D open simplex noise.

I've commented to explain what most of the things in the rust side of the example mean. However, I'm not 100% sure I did the best job at giving a brief overview, and wouldn't mind someone making sure my terminology/definitions are correct. 

Thanks!
Patrik

Co-authored-by: OptimisticPeach <[email protected]>
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