Skip to content

Conversation

@oguzeroglu
Copy link
Contributor

@oguzeroglu oguzeroglu commented May 13, 2018

In this PR a cache mechanism is implemented for Blend equations inside the WebGLState. I found this to be necessary since three.js was making redundant WebGL calls for such functions:
ekran resmi 2018-05-13 15 26 43

After the implementation I observed that such WebGL calls are eliminated thus performance increase is expected for scenes with many materials.

@Mugen87
Copy link
Collaborator

Mugen87 commented May 13, 2018

Can you please setup your PR on the latest dev branch? Besides, please use hard tabs instead of soft tabs.

@Mugen87 Mugen87 changed the title Blend equation caching mechanism to prevent redundant WebGL calls WebGLState: Added caching for blend equation May 13, 2018

if ( blending !== CustomBlending ) {

if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
Copy link
Collaborator

@Mugen87 Mugen87 May 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused. This line should already ensure no unnecessary updates, right?

Copy link
Contributor Author

@oguzeroglu oguzeroglu May 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was confused as well but it turns out that the currentBlending variable is shared between different materials so it did not ensure the blending equation caching (that's why I use the currentMaterial variable actually). Maybe it was supposed to serve another purpose that I'm not aware of, so I kept it just in case.

Copy link
Collaborator

@Mugen87 Mugen87 May 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think the change is correct. Caching WebGL State information is something different than caching uniforms. The WebGL state is always related to a draw call, it can't retain information that is related to a material (or shader program). In other words: You always have to set the blending equation or function if the current ones do not match.

Copy link
Contributor Author

@oguzeroglu oguzeroglu May 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I believe you are right about that. I believe that the reason of the redundant calls was that the blending equation function is acually the same (gl.FUNC_ADD) for different blending modes and that probably was the reason why this PR seemed to work. Maybe there should be different caches for blending equations and functions to prevent the redundant calls. Any thoughts?

For example:

if (NOT the last blending equation was gl.FUNC_ADD){
gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
}

The line if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) is not preventing gl.BlendEquation calls. I believe it was designed for gl.blendFuncSeparate calls.

I'm closing this PR as this adresses the problem in a wrong way :) I'll try non material based caching for blend equations as I mentionned above.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for investigating this! 👍

@oguzeroglu oguzeroglu closed this May 13, 2018
@oguzeroglu oguzeroglu deleted the blend_equation_cache branch May 14, 2018 07:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants