-
Notifications
You must be signed in to change notification settings - Fork 1k
Custom Backend: No api to get custom buffer during create_bind_group. #7533
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
Comments
First of all, thank you for trying custom backend. I mainly wrote for servo/vello, so we can use internal WebGPU objects of servo for vello, but it's great to see other uses.
That was exactly the point of supporting custom backend ❤. I am not sure I understand your issue correctly, but you can implement your own custom buffer as: #[derive(Debug)]
struct CustomBuffer(Counter);
impl wgpu::custom::BufferInterface for CustomBuffer {
// ...
} then to create it you must simply implement something like this on device: fn create_buffer(&self, _desc: &wgpu::BufferDescriptor<'_>) -> wgpu::custom::DispatchBuffer {
DispatchBuffer::custom(CustomBuffer(self.0.clone()))
} Then when your consumer will call I am not sure how exactly are you generating/storing ids, but instead of storing internal buffer (in hashmap of ids or whatever you have) you should be able to store just normal |
Or are you trying to access In that case I think we actually a have problem, and we would need something akin to |
Thanks for the replies and the Custom API. I guess your second comment describes my problem pretty well. The creation of a buffer is clear.
where that id is then used for referencing the buffer living on the host:
The problem arrives once I try to use the BindGroupDescriptor to create a bind group on the host (and thereby needing to pass a list of buffers to the host). I guess code is easier here, this are the changes that I required to do what I want to do: I am not sure if I am just using this wrong or whether a public API for this just does not exist yet (I guess your servo integration is able to just pass and maintain Rust structures, while I need to have u64 as resource identifiers (similar to what I assumed the wasm implementation does.)) |
This integration is yet to be done. I only have smaller prototype of vello using custom backend, but that was written on different revision of custom backend.
This is definitely missing API. I will fix this. |
Thanks, let me know if you need any help. |
Your workarounds were very educational, at least to know what is needed. I managed to get safer downcasting and hopefully nicer API. It still need some more polish, but I think it's generally ready: #7541 |
Thanks for your changes, I now switched to your changes while debugging an early drop. Your changes don't cover all situations yet. I guess they can be summarizes as "getting a dispatch entity instead of an api entity".
My code for reference (the edgeless_function_gpu crate/folder is the wasm-guest using the custom backend): |
Indeed, thanks for great description. I think this should do it: 3e758ee |
Yes that does indeed work, thanks. One thing I forgot to mention / have currently just not used: The SubmissionIndex used in poll is currently not useable in a custom backend as the inner part is private. I am not sure if you want a custom submission index for that or whether that should just be made public for the sake of custom backends. Other than that, I still need to properly disable all web-dependencies for wasm but not using the webgpu backend (currently just commented that out), but I guess that is only partially related to the custom backend and not really related to the api changes. But with your changes and commenting out the web-dependencies (and some wasm specific methods), I can now use a implementation of the custom backend to run the compute hello world example inside wasmtime. |
Indeed, I will open new issue about this.
This might be related to #7407, but it was ultimately scraped due to complexity (we want too keep same experience for existing wgpu users). Here WGPU custom backend users will continue to depend on core (at least on native). Do you have any commits I could look at to see what is needed? |
I think this is simpler than the native case. Here is my attempt to fix this: #7565 |
Hi, I'm trying to build a custom WGPU backend based on the example: https://github.com/gfx-rs/wgpu/blob/trunk/examples/standalone/custom_backend/src/custom.rs. The backend aims to support WASM outside a browser and is backed by a instance of wgpu running on the host.
What I'm essentially doing is mapping all things to objects held externally and just storing an unique id inside WASM, e.g., a buffer is represented as a u64 inside WASM, which maps to a core buffer outside of the VM.
That custom Implementation lives in my own crate (no fork of wgpu, just depending on wgpu).
However, there apears to be no way to get to my custom buffer (and therefore the id needed for serialization) during
create_bind_group(&self, desc: &wgpu::BindGroupDescriptor<'_>) -> wgpu::custom::DispatchBindGroup
in theDeviceInterface
. The crate-internal implementations rely on https://github.com/gfx-rs/wgpu/blob/trunk/wgpu/src/api/buffer.rs#L178, followed by e.g. https://github.com/gfx-rs/wgpu/blob/trunk/wgpu/src/dispatch.rs#L581, but that is crate-only public. There appears to be https://github.com/gfx-rs/wgpu/blob/trunk/wgpu/src/dispatch.rs#L600, but I can't get to that as the inner buffer is crate-public.Is there any way to do this using the existing public API or should the inner buffer be fully public to support this?
The text was updated successfully, but these errors were encountered: