wgpu icon indicating copy to clipboard operation
wgpu copied to clipboard

Implement texture clear on store = false

Open kvark opened this issue 3 years ago • 3 comments

This code should be portable (from #2254)



let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
    label: Some("Render Pass"),
    color_attachments: &[
        wgpu::RenderPassColorAttachment {
            view: &view,
            resolve_target: None,
            ops: wgpu::Operations {
                load: wgpu::LoadOp::Clear(
                    if self.config.wgpu.transparent {    
                        wgpu::Color::TRANSPARENT
                    } else {
                        wgpu::Color::BLACK
                    }
                ),
                store: false, /* issue */
            }
        }
    ],
    depth_stencil_attachment: None,
});

kvark avatar Dec 06 '21 17:12 kvark

There is an upstream spec. issue for clarifying that we need to be zeroing when store is false (viz., is "discard" in JS): https://github.com/gpuweb/gpuweb/issues/4398

ErichDonGubler avatar Jan 18 '24 15:01 ErichDonGubler

We should have implemented this a while ago - the zero init code should handle this.

cwfitzgerald avatar Jan 18 '24 17:01 cwfitzgerald

I think I'm running into this "issue" on my project. I have one render pass that writes to a depth buffer (store: true), and then the several following passes with store: false. I need that depth buffer to /not/ be zeroed after these passes. How can I disable?

Cheers

EDIT:

Well, immediately after posting this I had an idea to try out a different approach. I use "store: true" on all my render passes but change the pipeline state instead. By using a pipeline descriptor with the DepthStencilState::depth_write_enable set to false, the depth texture is no longer cleared.

I'm new to this but "store" is confusing for a beginner. The store always happens, as it seems, but the value is either discarded or kept.

sarchar avatar Feb 03 '24 07:02 sarchar