Skip to content

Commit

Permalink
[Gles] Fix clearing depth and stencil at the same time (#2675)
Browse files Browse the repository at this point in the history
  • Loading branch information
expenses authored May 19, 2022
1 parent b53a8bc commit 1ec2678
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
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),
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

0 comments on commit 1ec2678

Please sign in to comment.