Vulkan: Parallelize GLSL compilation #15589
Merged
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.
Instead of simply directly compiling GLSL to SPIR-V on the main thread using glslang (which, it turns out, is just as expensive as pipeline creation, at least on my machine), we spawn tasks as the needed shaders are discovered, and then the actual pipeline creation blocks on those tasks to finish. This, almost surprisingly, often manages to spread the work out over 10+ threads in heavy scenarios, reducing the length of shader compilation stutters.
There seems to be some minor serialization over memory allocation from within glslang, but still a win.
Should reduce shader compilation stutters a bit. There's of course lots more to do in this area.
Still a draft as there seems to be a leak of shader modules (according to the validation layers) that I can't quite figure out right now.Never mind, fixed, still leaving as draft due to need for more testing.A next step might be to run multiple CreateGraphicsPipeline in parallel on the pool too instead of having a single "ShaderCompileThread", but there are recommendations to run compiles that use the same shaders on the same thread so some additional logic would be needed (the ShaderCompileThread should probably remain and try to group the pipeline creation requests to the best of its ability as they come in).
The actual win on Android seems pretty small on older devices with 4 cores unfortunately. Probably need to also look into pipeline creation parallelization.