-
Notifications
You must be signed in to change notification settings - Fork 935
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
Initialize texture sub-resources to zero #1102
Comments
Here's a diff of what I changed: diff --git a/examples/hello-triangle/main.rs b/examples/hello-triangle/main.rs
index ceacf4e..71daf82 100644
--- a/examples/hello-triangle/main.rs
+++ b/examples/hello-triangle/main.rs
@@ -113,6 +108,7 @@ fn main() {
},
);
let mut running = true;
+ let mut once = true;
while running {
events_loop.poll_events(|event| match event {
Event::WindowEvent { event, .. } => match event {
@@ -142,15 +138,18 @@ fn main() {
color_attachments: &[wgpu::RenderPassColorAttachmentDescriptor {
attachment: &frame.view,
resolve_target: None,
- load_op: wgpu::LoadOp::Clear,
+ load_op: wgpu::LoadOp::Load,
store_op: wgpu::StoreOp::Store,
clear_color: wgpu::Color::GREEN,
}],
depth_stencil_attachment: None,
});
rpass.set_pipeline(&render_pipeline);
- rpass.set_bind_group(0, &bind_group, &[]);
- rpass.draw(0 .. 3, 0 .. 1);
+ if once {
+ rpass.set_bind_group(0, &bind_group, &[]);
+ rpass.draw(0..3, 0..1);
+ once = false;
+ }
}
device.get_queue().submit(&[encoder.finish()]); |
Thank you for filing the issue! By design WebGPU is required to zero-clear all resources. It doesn't allow uninitialized data to be used for anything. Newly acquired frames are also considered "new" resources and should be cleared unless the user does a Currently, this zero-initialization semantics isn't implemented here (in wgpu-native), but it should be. |
Hmm, are you sure that is the issue? If the zero-initialization semantics were implemented it would mean that my frames would be zero-initialized (since I don't use I did another experiment which is to draw the triangle twice, on two consecutive frames, and then never again. This yields the correct result, of showing the triangle on every frame thereafter. This leads me to believe that it could have to do with double-buffering. The explanation in this case would be that in my first experiment, the triangle is only drawn on frame |
With zero-initialization you'd only be able to see the triangle in a single frame (i.e. once) – all later frames would be empty (because they would be cleared by default). If you want the triangle to continue being displayed, you'd continue rendering it each frame or store the result of rendering somewhere and restore it each frame. |
Yes, this much is clear, and is how I was however under the assumption that |
Having the |
Yeah, I mean I guess it can't work due to double-buffering, but actually works fine when writing to an off-screen texture, which I guess is the intended use-case. |
This still causes vulkan validation errors on master. Transferring to |
|
This would be in "we need to initialize all resources to zero" bin. |
LoadOp::Load
If the
hello_triangle
example is changed slightly to only draw the triangle once, and we change the color attachment'sload_op
towgpu::LoadOp::Load
instead ofClear
, my expectation is that the result is the same, except that the green clear color is gone. However the result is that the red triangle only shows up every other frame, with blank frames in between.Is this expected behavior?
The text was updated successfully, but these errors were encountered: