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

Improve Context Traits #6324

Open
cwfitzgerald opened this issue Sep 25, 2024 · 0 comments
Open

Improve Context Traits #6324

cwfitzgerald opened this issue Sep 25, 2024 · 0 comments
Assignees
Labels
type: enhancement New feature or request

Comments

@cwfitzgerald
Copy link
Member

cwfitzgerald commented Sep 25, 2024

Full dump of the various proposals for improving the context api cwfitzgerald@f508bbd

Notable points is that there will be a trait for every type with any inherent methods. It will be stored in a thing like this:

enum InterfaceType<Core, WebGPU> {
    Core(Core),
    WebGPU(WebGPU),
}

impl<Core, WebGPU> InterfaceType {
    fn as_core(&self) -> &Core {
        match self {
            InterfaceType::Core(value) => value,
            _ => panic!("AdapterInterfaceType is not core"),
        }
    }

    fn as_webgpu(&self) -> &WebGPU {
        match self {
            InterfaceType::WebGPU(value) => value,
            _ => panic!("AdapterInterfaceType is not webgpu"),
        }
    };
}

// For each type with a trait:
impl Deref for InterfaceType<crate::wgpu_core::Adapter, crate::webgpu::Adapter> {
    type Target = dyn AdapterInterface;

    fn deref(&self) -> &Self::Target {
        match self {
            InterfaceType::Core(value) => value,
            InterfaceType::WebGPU(value) => value,
        }
    }
}

Then do the same trick for the Context

enum HoldMeAContext {
    Core(crate::wgpu_core::CoreContext),
    WebGPU(crate::webgpu::WebGPUContext),
}

impl Deref for HoldMeAContext {
    type Target = dyn Context;

    fn deref(&self) -> &Self::Target {
        match self {
            InterfaceType::Core(value) => value,
            InterfaceType::WebGPU(value) => value,
        }
    }
}

The context trait will do all the as_core/as_webgpu calls inline right at the beginning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants