After packaging an Unreal Engine project into PAK archives with the packaging setting Share Material Shader Code enabled, the ShaderLibrarySource
folder within each PAK contains compiled .ushaderbytecode shader binaries.
My goal is to implement shader hot patching.I also spotted the packaging toggle Deterministic Shader Code Order, which seems critical for shader patch generation.
While digging through UE source code, I located two APIs that look related to this workflow and want to confirm they are designed for shader bytecode hot patches:
- FShaderLibraryCooker::CreatePatchLibrary
- UShaderCodeLibraryToolsCommandlet
Could you outline the full end-to-end workflow for generating and deploying hot patches of compiled shader bytecode?
[Attachment Removed]
Hello,
I need to preface the following instructions by noting that we do have the features to hot-fix shader bytecode, but since we have not tested or used this setup ourselves, there are many unknowns you will need to sort out yourself. Of course, we can help you with any problems you encounter, though. Assuming you are using the pre-iostore functionality, the rough plan is as follows:
- You mention Deterministic Shader Code Order (bDeterministicShaderCodeOrder), but note that FShaderLibraryCooker::CreatePatchLibrary ignores this parameter.
- You need to keep the cook metadata for the base build cook <Project>/Saved/Cooked/<Platform>/<Project>/Metadata/ShaderLibrarySource/
- Update your content and recook
- Use ShaderCodeLibraryTools and point it at the old and new metadata. That will output a patched .ushaderbytecode with only new shadermaps in it
- Package the new .ushaderbytecode into a patch package with other content, using a new chunk ID that must be incremented with each patch.
- Deliver the patched package somehow or ship it with a game update
- Mount the patch package, and its shaders will load and be available for use.
There are lots of questions here that would need to be explored/updated. For example, the ShaderCodeLibraryTools commandlet only takes one old and one new directory, so it cannot perform a second patch on the first. The underlying engine function can, but the commandlet doesn’t expose it. This will work for new content, but it’s less clear on how it would work to modify existing shaders. If the mount order is correct, the new shaders will be found before the old ones, but the original shaderlibs will still be there. I think you should definitely test this before shipping.
I am sure what I just wrote will raise further questions, so please reach out in case you need more clarification.
Best,
Tim
[Attachment Removed]