-
-
Notifications
You must be signed in to change notification settings - Fork 162
gl_engine/shader: Introduced binary shader caching #3897
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
base: main
Are you sure you want to change the base?
Conversation
a821049 to
2dcd2cf
Compare
2dcd2cf to
9941559
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.
Pull Request Overview
This PR implements a binary shader caching system for the OpenGL renderer to improve performance by eliminating redundant shader compilation on subsequent application runs. The system automatically stores compiled OpenGL shader binaries to disk and attempts to load them before falling back to source compilation.
- Introduces
GlShaderCacheclass with persistent binary shader storage and retrieval functionality - Integrates caching into existing
GlProgramcompilation pipeline with transparent fallback behavior - Adds OpenGL 4.1+ binary shader API support via
glGetProgramBinary/glProgramBinaryextensions
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tvgGlShaderCache.h | Defines GlShaderCache class interface for binary shader caching operations |
| tvgGlShaderCache.cpp | Implements shader cache functionality with file I/O and hash-based naming |
| tvgGlProgram.cpp | Integrates shader caching into program compilation with cache-first loading |
| tvgGl.h | Adds OpenGL 4.1 binary shader API constants and function pointer declarations |
| tvgGl.cpp | Implements dynamic loading of binary shader API functions with version checking |
| meson.build | Adds new shader cache source files to build configuration |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
94fa894 to
95cb9bd
Compare
|
@hermet @SergeyLebedkin Binary shader support is an OpenGL 4.1+ feature, while our requirement is OpenGL 3. I added a helper function glIsProgramBinarySupportAvailable() in tvgGl.h to check runtime availability. This is the first runtime capability check in the project, so I’m not sure if this approach aligns with our design principles. Although my MacBook Air supports OpenGL 4.1, it still returns GL_NUM_PROGRAM_BINARY_FORMATS = 0, meaning binary shader support isn’t available. I’m waiting for GPU access on a cloud platform to test the performance improvement in another environment. While waiting, I’ll continue investigating the stroke rendering issue on the GL engine. |
@wenjieshen Looks good, if the binary shaders doesn't working, we can fallback to a normal scenario. |
|
@wenjieshen Could you please double-check this as well? a few systems might use this |
@hermet Understood, I’ll pause the PR. |
@wenjieshen I mean we can hold support v3 for binary shaders. I didn't mean hold this PR. Please go proceed. :) Thanks. |
hermet
left a comment
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.
@wenjieshen Please check comments and please respect thorvg coding convention.
Thanks.
ec10334 to
7dc6139
Compare
|
Thank you for the suggestion. I’ve added a validation header to the binary file. However, identifying and removing redundant files is still challenging. At the moment, I don’t have a good way to determine which files are no longer needed. I’d prefer to address this together with the version that stores the mono cache file, so both features can be handled cleanly in the same update.
|
7dc6139 to
cd6c12d
Compare
SergeyLebedkin
left a comment
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.
✅windows 11: OK
✅ubuntu (wsl2): OK
✅ubuntu (h/w): OK
✅macos (intel): OK (there are no supported binary formats)
1971b85 to
db355dd
Compare
cd6c12d to
a5acce0
Compare
|
The file IO is expensive relatively. Current shaders are more than 10, it needs a consideration before pushing this. That would be the best if we can introduce the one single binary form.... |
|
1. Verifying Shaders
2. Lazy Loading or Immediate Loading
|
1b33069 to
9ebd273
Compare
Implement binary shader caching system to improve OpenGL performance by: - Add GlShaderCache class with read/write functionality for compiled shaders - Support OpenGL binary shader format - Add proper OpenGL ARB extension loading for glGetProgramBinary/glProgramBinary - Integrate caching into GlProgram compilation pipeline This reduces shader compilation overhead on subsequent application runs, significantly improving startup performance for OpenGL-based rendering. Related issue: thorvg#2884
5066488 to
99e7369
Compare
@hermet Memory UsageAfter combining the binary shader files, the maximum additional memory usage observed across all examples is 857.21 KB. Shader Loading Time (per example)
Accumulated Write Time(per example)
Shader Writing Time (per shader)
|
We've implemented a comprehensive binary shader caching system to significantly improve OpenGL rendering performance on macOS by eliminating redundant shader compilation overhead on subsequent application runs.
This feature introduces the
GlShaderCacheclass that provides persistent storage and retrieval of compiled OpenGL shader binaries. The system automatically caches compiled shader programs to the user's cache directory using a hash-based naming scheme and attempts to load cached binaries before falling back to source compilation.Key implementation details:
glGetProgramBinary/glProgramBinaryextensionsGlProgramcompilation pipelineThe caching mechanism works transparently:
Performance benefits:
issue: #2884