-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Avoid redundant uniform uploads #2090
Avoid redundant uniform uploads #2090
Conversation
9682795
to
d85b969
Compare
If using If using I could go with |
d85b969
to
7f9ebc5
Compare
You should use |
Unfortunately it is not possible to optimize But dropped |
src/renderer_gl.cpp
Outdated
delete[] table; | ||
} | ||
// Uniform state cache for various types. | ||
static tinystl::unordered_map<uint64_t, T> uniformCacheMap; |
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.
static tinystl::unordered_map<uint64_t, T> uniformCacheMap;
Do not make it static, make it part of GL renderer context so that it can be deallocated properly.
Also use stl::unordered_map
(it's just name toggle between std/tinystl).
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.
Also make some #if BGFX_GL_CONFIG_UNIFORM_CACHE
so that this code path can be enabled/disabled.
src/renderer_gl.cpp
Outdated
delete[] table; | ||
} | ||
// Uniform state cache for various types. | ||
static tinystl::unordered_map<uint64_t, T> uniformCacheMap; |
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.
Also make some #if BGFX_GL_CONFIG_UNIFORM_CACHE
so that this code path can be enabled/disabled.
src/renderer_gl.cpp
Outdated
static GLuint currentProgram = 0; | ||
// Keep a global access to the currently active uniform state cache so that | ||
// individual GL functions can stay at global scope. | ||
static UniformStateCache *s_currentUniformStateCache = 0; |
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.
See: s_renderGL
at line 4313. You can make these functions part of RendererContextGL
or you can forward declare them at this point, and implement them below RendererContextGL
.
I'm getting compiler error because those templated functions are templated on return value. |
Would have been great to wait for the CI to go through to see that it works. What are the errors? Which compiler? With LLVM 6.0 and LLVM 10.0 it does build ok. Templating on return value by itself is not a problem, that will just require one to explicitly type specify the |
|
I assumed you compiled it... :)
|
Reverted it c023ac4... Just revert it back, fix template issue, and resubmit PR, the rest looks good. |
Ok the issue is that GCC does not treat the template specializations |
Actually wait. I can add inline. |
All good. |
Perfect, thanks! |
* Avoid redundant uniform uploads * Fix placement of GL_CHECK()s and import of glUniform4f. * Fix typo * Migrate GL uniform cache to use tinystl to conform to BGFX data structures * Address review * Address review
This reverts commit d9d9865.
This reverts commit c023ac4.
Manage a cache of current uniform state to avoid reuploading state that is already on the GPU side.
In a WebGL build, this was observed to reduce the number of GL calls from ~21k/frame to about ~7.5k/frame.