Issue SetDrawColorBuffers before clearing buffers in GLES, use clear_buffer_f32_slice instead of clear #5666
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Currently, CommandEncoder issues
SetDrawColorBuffers
after issuingClearColorF
,ClearColorU
andClearColorI
. On AMD Renoir graphics on Linux, this results inglClearBuffer
calls sometimes being ignored. I can see theglClearBuffer
calls in RenderDoc, but the output texture is not cleared. I suspect that this may also be the cause of some of the crashes on other machines (e.g. Sandy Bridge on Windows).It seems that the correct way to use
glClearBuffer
is to callglDrawBuffers
before callingglClearBuffer
.Additionally, I've replaced the
glClear
call withglClearBufferF
(viaglow::clear_buffer_f32_slice
), becauseglDrawBuffers
does not like it when you passCOLOR_ATTACHMENTi
as thej
-th buffer unlessi==j
. When rendering using a WebGL backend, this results in warnings:On native OpenGL, this doesn't seem to be an issue, but the spec for OpenGL ES 3.2 also demands this:
(See page 398, OpenGL ES 3.2)
Testing
Theoretically, issuing
SetDrawColorBuffers(0)
before beginning a render pass (maybe with a non-default frame-buffer?) and attempting to clear the color buffers will result in the clear commands being ignored on some machines. Admittedly, I've only tested this in a larger application, so I don't have a self-contained test for this.The changes regarding clearing float buffers can be verified by attempting to clear buffers as part of a render pass involving multiple color attachments in WebGL (both Firefox and Chrome produce similar warnings).
It would be great if someone could verify that this fixes their issues on Sandy Bridge on Windows, because I've removed (a part of) the workaround in hopes that the crashes were caused by this bug(or quirk).
Checklist
cargo fmt
.cargo clippy
. If applicable, add:--target wasm32-unknown-unknown
--target wasm32-unknown-emscripten
cargo xtask test
to run tests.CHANGELOG.md
. See simple instructions inside file.