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

[Gles] Fix clearing depth and stencil at the same time #2675

Merged
merged 2 commits into from
May 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions wgpu-hal/src/gles/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,12 +520,19 @@ impl crate::CommandEncoder<super::Api> for super::CommandEncoder {
}
}
if let Some(ref dsat) = desc.depth_stencil_attachment {
if !dsat.depth_ops.contains(crate::AttachmentOps::LOAD) {
let clear_depth = !dsat.depth_ops.contains(crate::AttachmentOps::LOAD);
let clear_stencil = !dsat.stencil_ops.contains(crate::AttachmentOps::LOAD);

if clear_depth && clear_stencil {
self.cmd_buffer.commands.push(C::ClearDepthAndStencil(
dsat.clear_value.0,
dsat.clear_value.1,
));
} else if clear_depth {
self.cmd_buffer
.commands
.push(C::ClearDepth(dsat.clear_value.0));
}
if !dsat.stencil_ops.contains(crate::AttachmentOps::LOAD) {
} else if clear_stencil {
self.cmd_buffer
.commands
.push(C::ClearStencil(dsat.clear_value.1));
Expand Down
5 changes: 5 additions & 0 deletions wgpu-hal/src/gles/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,11 @@ enum Command {
ClearColorI(u32, [i32; 4]),
ClearDepth(f32),
ClearStencil(u32),
// Clearing both the depth and stencil buffer individually appears to
// result in the stencil buffer failing to clear, atleast in WebGL.
// It is also more efficient to emit a single command instead of two for
// this.
ClearDepthAndStencil(f32, u32),
cwfitzgerald marked this conversation as resolved.
Show resolved Hide resolved
BufferBarrier(glow::Buffer, crate::BufferUses),
TextureBarrier(crate::TextureUses),
SetViewport {
Expand Down
3 changes: 3 additions & 0 deletions wgpu-hal/src/gles/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -758,6 +758,9 @@ impl super::Queue {
C::ClearStencil(value) => {
gl.clear_buffer_i32_slice(glow::STENCIL, 0, &[value as i32]);
}
C::ClearDepthAndStencil(depth, stencil_value) => {
gl.clear_buffer_depth_stencil(glow::DEPTH_STENCIL, 0, depth, stencil_value as i32);
}
C::BufferBarrier(raw, usage) => {
let mut flags = 0;
if usage.contains(crate::BufferUses::VERTEX) {
Expand Down