-
Notifications
You must be signed in to change notification settings - Fork 931
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
Support configuring Surface
s with Device
s that don't share the same underlying WebGL2 context
#2343
Comments
I think I have it tracked down to this: Lines 27 to 29 in f8a63c4
The WebGL Backend Instance has only one canvas, but shouldn't it have a vector of canvases? |
Ok, yeah, I don't know atm how we'd support multiple canvases on WebGL. Some investigation is needed. Maybe the Instance should be some kind of an offscreen canvas, and then presenting to other canvases would do some image copies on GPU.... Not sure. |
@kvark Each Line 82 in f8a63c4
const ctx0 = canvas0.getContext("webgl");
const ctx1 = canvas1.getContext("webgl"); |
My use case would need shared resources between canvases |
What we could do is store an array of canvases and present a device for each canvas we have. The user would need to make sure they pick the correct device, but that's what surface compatibility is for anyway. |
I ran into this problem too when I was testing basic wgpu example (v0.18). For instance, wgpu will draw onto the let surface_a = instance.create_surface(canvas_a);
let surface_b = instance.create_surface(canvas_b);
let adapter = instance.request_adapter();
drop(surface_a);
drop(surface_b);
let surface_c = instance.create_surface(canvas_c);
...
// Intended to render onto surface_c
let texture = surface_c.get_current_texture();
let view = texture.create_view();
// But, actually wgpu renders onto surface_b
render to view Full source is here example So, I guess wgpu can solve this confusing operation by bloking configuration of surface like so, wgpu/wgpu-hal/src/gles/web.rs : 298 impl crate::Surface<super::Api> for Surface {
unsafe fn configure(
&mut self,
device: &super::Device,
config: &crate::SurfaceConfiguration,
) -> Result<(), crate::SurfaceError> {
// Blocks configuration if users attempt to configure different surface.
// But, device.shared.context should have raw webgl context for this operation.
let adapter_webgl2_context = &device.shared.context.webgl2_context;
if &self.webgl2_context != adapter_webgl2_context {
return Err(crate::SurfaceError::Other("Some error msg"));
}
...
} |
#5901 adds validation to prevent this from silently happening. |
Surface
s with Device
s that don't share the same underlying WebGL2 context
Description
When creating multiple canvases on web and multiple corresponding surfaces, all rendering is done in the last canvas associated to the last surface created.
Repro steps
Here is a modified hello-triangle main.rs file, run it with cargo run-wasm --example hello-triangle --features webgl
Expected vs observed behavior
I only see the triangle in the second canvas, but was expecting a triangle in both. This produces two windows with correct renderings on native.
I confirmed that both canvases are on the page with data-raw-handle attributes correspondig to the raw-window-handle produced by winit. There is also no error when creating the surfaces, indicating that the canvases were both found. Only the canvas associated to the last surface created is rendered to. The other surfaces render to the canvas of the last surface.
Platform
current master version of wgpu, WSL Ubuntu Linux
The text was updated successfully, but these errors were encountered: