From 548fe573e518c8dffd9006e4fb87819cdfe5caa8 Mon Sep 17 00:00:00 2001 From: Nick Guletskii Date: Sun, 5 May 2024 14:54:38 +0300 Subject: [PATCH 1/4] 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. --- wgpu-hal/src/gles/command.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/wgpu-hal/src/gles/command.rs b/wgpu-hal/src/gles/command.rs index 258dee76e5..e5f15e7f71 100644 --- a/wgpu-hal/src/gles/command.rs +++ b/wgpu-hal/src/gles/command.rs @@ -604,6 +604,14 @@ 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 @@ -634,13 +642,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); From 2b7b6d67bb9d04d1d4244f8c553dddf4c70c4175 Mon Sep 17 00:00:00 2001 From: Nick Guletskii Date: Sun, 5 May 2024 15:35:48 +0300 Subject: [PATCH 2/4] 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. --- wgpu-hal/src/gles/queue.rs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/wgpu-hal/src/gles/queue.rs b/wgpu-hal/src/gles/queue.rs index 7c728d3978..9a9e4bef99 100644 --- a/wgpu-hal/src/gles/queue.rs +++ b/wgpu-hal/src/gles/queue.rs @@ -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) => { From 75e3656d277ad9f8bb94d68e24594c2a47b408f8 Mon Sep 17 00:00:00 2001 From: Nick Guletskii Date: Sun, 5 May 2024 15:43:40 +0300 Subject: [PATCH 3/4] Run cargo fmt --- wgpu-hal/src/gles/command.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/wgpu-hal/src/gles/command.rs b/wgpu-hal/src/gles/command.rs index e5f15e7f71..6414ee5213 100644 --- a/wgpu-hal/src/gles/command.rs +++ b/wgpu-hal/src/gles/command.rs @@ -604,7 +604,6 @@ 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 From 0dc4232315cf0f826e7f25919ca6437a29c99b3c Mon Sep 17 00:00:00 2001 From: Nick Guletskii Date: Sun, 5 May 2024 16:33:08 +0300 Subject: [PATCH 4/4] Add changes for PR GH-5666 to the CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e753cb8f2f..6d47f9966f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -75,6 +75,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)