-
Notifications
You must be signed in to change notification settings - Fork 163
win32 tool to generate shadercache #1785
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
Draft
CedricGuillemet
wants to merge
2
commits into
BabylonJS:master
Choose a base branch
from
CedricGuillemet:shaderCompilerGL
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # ShaderCacheGenerator | ||
| # | ||
| # A headless Win32 + OpenGL tool that builds a GPU shader cache for a Babylon.js | ||
| # scene. It hosts the scene script through the Babylon::Embedding Runtime/View | ||
| # API (backed by an offscreen window + the ANGLE OpenGL backend), renders frames | ||
| # until the scene has finished compiling its shaders, and writes the resulting | ||
| # ShaderCache to a file. | ||
| # | ||
| # Usage: | ||
| # ShaderCacheGenerator <scene.js> <output.bin> [--width N] [--height N] | ||
| # [--max-frames N] [--stable-checks N] [--check-interval N] | ||
| # | ||
| # The produced cache is GRAPHICS_API-specific: configuring with | ||
| # -DGRAPHICS_API=OpenGLWindowsDevOnly (which maps to the OpenGL/ANGLE backend) | ||
| # yields GLES shaders compatible with the Android OpenGL backend. | ||
|
|
||
| set(PLAYGROUND_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../Playground") | ||
|
|
||
| set(SOURCES | ||
| "Source/Main.cpp") | ||
|
|
||
| # Reused from Apps/Playground/Shared: command-line parsing, process diagnostics | ||
| # (console/crash/exit handling) and the log callback. | ||
| set(SHARED_SOURCES | ||
| "${PLAYGROUND_DIR}/Shared/CommandLine.cpp" | ||
| "${PLAYGROUND_DIR}/Shared/CommandLine.h" | ||
| "${PLAYGROUND_DIR}/Shared/Diagnostics.cpp" | ||
| "${PLAYGROUND_DIR}/Shared/Diagnostics.h" | ||
| "${PLAYGROUND_DIR}/Shared/PlaygroundScripts.cpp" | ||
| "${PLAYGROUND_DIR}/Shared/PlaygroundScripts.h") | ||
|
|
||
| add_executable(ShaderCacheGenerator ${SOURCES} ${SHARED_SOURCES}) | ||
|
|
||
| warnings_as_errors(ShaderCacheGenerator) | ||
|
|
||
| target_compile_definitions(ShaderCacheGenerator | ||
| PRIVATE UNICODE | ||
| PRIVATE _UNICODE) | ||
|
|
||
| # So Main.cpp can include the reused headers as <Shared/CommandLine.h> etc. | ||
| target_include_directories(ShaderCacheGenerator PRIVATE "${PLAYGROUND_DIR}") | ||
|
|
||
| # SUBSYSTEM:CONSOLE so stdout/stderr behave like a normal console app; the tool | ||
| # still creates a hidden Win32 window for the GL swapchain. | ||
| set_target_properties(ShaderCacheGenerator PROPERTIES | ||
| LINK_FLAGS "/SUBSYSTEM:CONSOLE") | ||
|
|
||
| # Embedding transitively provides the polyfills/plugins (NativeEngine, | ||
| # ShaderCache, ...) and their include paths. ShaderCache is listed explicitly | ||
| # because Main.cpp includes <Babylon/Plugins/ShaderCache.h> and calls Save(). | ||
| # bx / Foundation are required by the reused Shared sources (Diagnostics.cpp, | ||
| # PlaygroundScripts.cpp). Shlwapi provides UrlCreateFromPathA for the file:// | ||
| # script URL. | ||
| target_link_libraries(ShaderCacheGenerator | ||
| PRIVATE Embedding | ||
| PRIVATE ShaderCache | ||
| PRIVATE bx | ||
| PRIVATE Foundation | ||
| PRIVATE Shlwapi) | ||
|
|
||
| # Copy transitive runtime DLLs next to the executable. | ||
| add_custom_command(TARGET ShaderCacheGenerator POST_BUILD | ||
| COMMAND ${CMAKE_COMMAND} -E $<IF:$<BOOL:$<TARGET_RUNTIME_DLLS:ShaderCacheGenerator>>,copy,true> $<TARGET_RUNTIME_DLLS:ShaderCacheGenerator> $<TARGET_FILE_DIR:ShaderCacheGenerator> COMMAND_EXPAND_LISTS) | ||
|
|
||
| # Copy the ANGLE GL DLLs so the OpenGL backend can load at runtime. | ||
| if(ANGLE_LIBEGL) | ||
| add_custom_command(TARGET ShaderCacheGenerator POST_BUILD | ||
| COMMAND ${CMAKE_COMMAND} -E copy_if_different "${ANGLE_LIBEGL}" "$<TARGET_FILE_DIR:ShaderCacheGenerator>" | ||
| COMMAND ${CMAKE_COMMAND} -E copy_if_different "${ANGLE_LIBGLESV2}" "$<TARGET_FILE_DIR:ShaderCacheGenerator>" | ||
| COMMENT "Copying ANGLE libraries to ShaderCacheGenerator output directory") | ||
| endif() | ||
|
|
||
| set_property(TARGET ShaderCacheGenerator PROPERTY FOLDER Apps) | ||
| source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${SOURCES}) | ||
| source_group("Shared" FILES ${SHARED_SOURCES}) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| # ShaderCacheGenerator | ||
|
|
||
| Headless Win32 + OpenGL tool that builds a GPU shader cache for a Babylon.js | ||
| scene. It hosts the scene through the `Babylon::Embedding` Runtime/View API on a | ||
| hidden window (ANGLE OpenGL backend), renders frames until the scene's shaders | ||
| are compiled, then writes the `ShaderCache` to a file. | ||
|
|
||
| Command-line parsing, process diagnostics (console/crash/exit handling) and the | ||
| log callback are reused from `Apps/Playground/Shared`. | ||
|
|
||
| ## Usage | ||
|
|
||
| ``` | ||
| ShaderCacheGenerator <scene.js> <output.bin> [shared options] | ||
| ``` | ||
|
|
||
| | Argument | Description | | ||
| | -------------- | -------------------------------------- | | ||
| | `<scene.js>` | Scene script to load (required). | | ||
| | `<output.bin>` | Shader cache file to write (required). | | ||
|
|
||
| `[shared options]` are the Playground command-line flags (run with `--help` to | ||
| list them); e.g. `--debug-trace=true`. | ||
|
|
||
| Exit codes: `0` success (>=1 shader written), `2` command-line / input error, | ||
| `1` runtime failure, `3` hard crash. | ||
|
|
||
| ## Build | ||
|
|
||
| Configure BabylonNative for Win32 with the ANGLE OpenGL backend, then build the | ||
| target: | ||
|
|
||
| ``` | ||
| cmake -B build -G "Visual Studio 18 2026" -A x64 -D GRAPHICS_API=OpenGLWindowsDevOnly -D BABYLON_NATIVE_BUILD_APPS=ON | ||
| cmake --build build --target ShaderCacheGenerator --config Release | ||
| ``` | ||
|
|
||
| Requires an installed Edge/Chrome (for `libEGL.dll` / `libGLESv2.dll`). The | ||
| cache is GL-specific, so it is compatible with the Android OpenGL backend. | ||
|
|
||
| ## "Scene ready" detection | ||
|
|
||
| There is no fixed frame count. The tool renders until the shader-cache entry | ||
| count stops growing for a number of consecutive checks -- i.e. the scene has | ||
| finished compiling every effect it uses. This is the meaningful signal for a | ||
| cache generator and works for any scene without it exposing globals. A frame cap | ||
| is applied only as a safety net. |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.