Skip to content
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

WIP: Support extern context impl #6658

Draft
wants to merge 10 commits into
base: trunk
Choose a base branch
from
Draft

Conversation

sagudev
Copy link
Contributor

@sagudev sagudev commented Dec 4, 2024

Connections
Based on #6619, fixes #6330

Description
This PR enables users of wgpu to provide custom Instance impl (and other wgpu types as all other types are derived from Instance->Adapter->Device), by adding Custom variant and custom backend that has dyn wrapper for all types: struct DynDevice(Arc<dyn DeviceInterface>). I'm intermixing Custom with Dyn because I cannot really decide on name (CustomDevice is weird, but we already have Dyn* in wgpu-hal).
There are few rough sports:

  • RenderBundleEncoderInterface::finish (other backends hacks around by not using dyn dispatch, but we can't:
    pub fn finish(self, desc: &RenderBundleDescriptor<'_>) -> RenderBundle {
    let bundle = match self.inner {
    #[cfg(wgpu_core)]
    dispatch::DispatchRenderBundleEncoder::Core(b) => b.finish(desc),
    #[cfg(webgpu)]
    dispatch::DispatchRenderBundleEncoder::WebGPU(b) => b.finish(desc),
    };
  • InstanceInterface::new cannot work because we cannot use dyn dispatch to create new instance (instance must be created by consumer)
  • webgpu only methods are unimplemented!

future work:

  • allow wgpu on native to be without core (libraries using wgpu (ex: vello) usually get instance/device from their users, so they would want to disable core if user is providing instance anyway), although this make wgpu to play 2 roles: abstraction provider and impl provider (of core and webgpu backend). Should we somehow split this into two creates? (so libraries would only depend on wgpu-abstract while consumers of those libraries would use wgpu-provider that would also depend on wgpu-abstract and toggle appropriate features for enums: core,webgpu,custom)

Testing
For testing we simply pass wgpu-core/webgpu as dyn Instance (be5acfa), so this works, but I plan to do example of creating dummy interface (for testing purposes).

Checklist

  • Run cargo fmt.
  • Run taplo format.
  • Run cargo clippy. If applicable, add:
    • --target wasm32-unknown-unknown
    • --target wasm32-unknown-emscripten
  • Run cargo xtask test to run tests.
  • Add change to CHANGELOG.md. See simple instructions inside file.

@sagudev sagudev requested a review from a team as a code owner December 4, 2024 19:50
@sagudev sagudev marked this pull request as draft December 4, 2024 19:50
@sagudev sagudev changed the title Init CustomContext and Dyn_ WIP: SUpport extern context impl Dec 4, 2024
@sagudev sagudev changed the title WIP: SUpport extern context impl WIP: Support extern context impl Dec 4, 2024
@cwfitzgerald cwfitzgerald self-assigned this Dec 5, 2024
@sagudev
Copy link
Contributor Author

sagudev commented Dec 5, 2024

TBH, I have no idea what's wrong with WASM.

Comment on lines 207 to 212
#[doc(hidden)]
/// Creates Instance from custom context implementation
pub fn from_custom_instance(instance: std::sync::Arc<dyn InstanceInterface>) -> Self {
Self {
inner: dispatch::DispatchInstance::Custom(backend::custom::DynContext::new(instance)),
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is triggering visibility problems for WASM, but I do not know why.

@cwfitzgerald
Copy link
Member

Ping me if this needs looking at or you need help before it is out of draft, going to un-assign myself for bookeeeping

@cwfitzgerald cwfitzgerald removed their assignment Dec 11, 2024
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.

Support extern Context implementations
2 participants