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

This commit is contained in:
Ashley 2022-05-19 23:10:27 +02:00 committed by GitHub
parent b53a8bcb17
commit 1ec26784c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 18 additions and 3 deletions

View File

@ -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));

View File

@ -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 {

View File

@ -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) {