Issue SetDrawColorBuffers before clearing buffers in GLES, use clear_buffer_f32_slice instead of clear (#5666)

* Issue SetDrawColorBuffers commands before issuing ClearColor

This is necessary for glClearBuffer calls to work correctly on some machines (e.g. AMD Renoir graphics running on Linux). Without this, glClearBuffer calls are ignored.

* Use clear_buffer_f32_slice instead of gl.clear to suppress WebGL warnings

This fixes the following WebGL warning: "WebGL warning: drawBuffers: `buffers[i]` must be NONE or COLOR_ATTACHMENTi."

When using native OpenGL, it is acceptable to call glDrawBuffers with an array of buffers where i != COLOR_ATTACHMENTi. In WebGL, this is not allowed.

* Run cargo fmt

* Add changes for PR GH-5666 to the CHANGELOG
This commit is contained in:
Nick Guletskii 2024-05-14 12:57:18 +03:00 committed by GitHub
parent 9b70254437
commit 65d8c94afd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 14 deletions

View File

@ -81,6 +81,8 @@ By @stefnotch in [#5410](https://github.com/gfx-rs/wgpu/pull/5410)
#### GLES / OpenGL
- Fix regression on OpenGL (EGL) where non-sRGB still used sRGB [#5642](https://github.com/gfx-rs/wgpu/pull/5642)
- Fix `ClearColorF`, `ClearColorU` and `ClearColorI` commands being issued before `SetDrawColorBuffers` [#5666](https://github.com/gfx-rs/wgpu/pull/5666)
- Replace `glClear` with `glClearBufferF` because `glDrawBuffers` requires that the ith buffer must be `COLOR_ATTACHMENTi` or `NONE` [#5666](https://github.com/gfx-rs/wgpu/pull/5666)
## v0.20.0 (2024-04-28)

View File

@ -608,6 +608,13 @@ impl crate::CommandEncoder for super::CommandEncoder {
depth: 0.0..1.0,
});
if !rendering_to_external_framebuffer {
// set the draw buffers and states
self.cmd_buffer
.commands
.push(C::SetDrawColorBuffers(desc.color_attachments.len() as u8));
}
// issue the clears
for (i, cat) in desc
.color_attachments
@ -638,13 +645,6 @@ impl crate::CommandEncoder for super::CommandEncoder {
}
}
if !rendering_to_external_framebuffer {
// set the draw buffers and states
self.cmd_buffer
.commands
.push(C::SetDrawColorBuffers(desc.color_attachments.len() as u8));
}
if let Some(ref dsat) = desc.depth_stencil_attachment {
let clear_depth = !dsat.depth_ops.contains(crate::AttachmentOps::LOAD);
let clear_stencil = !dsat.stencil_ops.contains(crate::AttachmentOps::LOAD);

View File

@ -1075,13 +1075,7 @@ impl super::Queue {
{
unsafe { self.perform_shader_clear(gl, draw_buffer, *color) };
} else {
// Prefer `clear` as `clear_buffer` functions have issues on Sandy Bridge
// on Windows.
unsafe {
gl.draw_buffers(&[glow::COLOR_ATTACHMENT0 + draw_buffer]);
gl.clear_color(color[0], color[1], color[2], color[3]);
gl.clear(glow::COLOR_BUFFER_BIT);
}
unsafe { gl.clear_buffer_f32_slice(glow::COLOR, draw_buffer, color) };
}
}
C::ClearColorU(draw_buffer, ref color) => {