-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[3.x] GLES2 & GLES3 - Use gl_FragColor
temporary
#84529
Conversation
Tested locally, it works as expected (no rendering issues). I can't notice any performance difference on a RTX 4090 (even at 8K) but it's not exactly the kind of GPU targeted by this optimization 🙂 |
It may not be a bottleneck on your super GPU, especially with such a simple test project (or not have the vulnerability). I bumped up the MSAA to make the difference show up more in the test project. It may appear more when the GPU is stressed by fill rate. |
f0c9849
to
4a82140
Compare
gl_FragColor
temporarygl_FragColor
temporary
4a82140
to
a6c6279
Compare
On some hardware, modifying gl_FragColor multiple times can cause large performance drops. This PR writes to a standard temporary variable instead, and copies across to gl_FragColor once only at the end of the fragment shader. This could potentially lead to large gains in performance on affected hardware.
a6c6279
to
ed3d029
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't tested locally, but I trust your testing on this. Issues would be immediately apparent if they appear.
Thanks! |
On some hardware, modifying
gl_FragColor
multiple times (or more likely reading fromgl_FragColor
) can cause large performance drops. This PR writes to a standard temporary variable instead, and copies across togl_FragColor
once only at the end of the fragment shader.This could potentially lead to large gains in performance on affected hardware (so far I've measured from 2x increase in fps (GLES2) to 4x (GLES3)).
Temporary variable is called
frag_color
in GLES2, andfrag_color
in GLES3 (In GLES3 the final output is renamed tofrag_color_final
).Partially addresses #84526.
Notes
frag_color
is read / modified more than once.ALBEDO
rather thanfrag_color
directly.frag_color
multiple times in shader seems to cause performance problem #84526 (comment) for tests on different hardware.scene.glsl
, I've included the fix for other potentially affected shaders, as there is no evidence of a drop in performance and potential for gain, especially if these shaders are later modified.Example Project
(Simple box with fog and emission)
Before 51 fps
After 104 fps
glFragColor.zip