WIP: GPU: Add batch shader compilation API and per backend ShaderCompiler #121471
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
No due date set.
Blocks
#121542 WIP: EEVEE-Next: Parallel static shader compilation
blender/blender
Reference: blender/blender#121471
Loading…
Reference in New Issue
No description provided.
Delete Branch "pragma37/blender:pull-parallel-shader-compilation"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Allow GPU backends to support multithreaded async shader compilation by providing their own
gpu::ShaderCompiler
implementation.Add new functions to the GPU_shader API to allow async shader compilation:
And their equivalent to GPU_material:
Implement a
GLShaderCompiler
that usesGL_KHR/ARB_parallel_shader_compile
.To avoid shader compilation blocking Blender, there's only one global
GLShaderCompiler
that always runs from the main context atbegin_frame
, and yields when too much time has passed.Current issues:
begin_frame
, the user code must request redraws until the compilation has finished.Material compile times
The time improvements seem to be very case-dependent, and for the Mr Elephant scene in EEVEE Next it ends up being slightly slower.
But it brings a ~2x improvement in most of the tested cases.
(WIP) GPU: Add batch shader compilation API and per backend ShaderCompilerto WIP: GPU: Add batch shader compilation API and per backend ShaderCompiler@blender-bot build +gpu
Looking at the API, it would be useful for OpenGL. Metal and Vulkan have separated the frontend and backend compilation stages which will only perform the frontend stage when batching. The frontend stage is fairly light. I think that the backend stage (pipelines) should be implemented in each backend differently and outside the responsibility of the proposed API (as it now is).
For the material batch compilation it might be useful due to their special usecases. How would this API handle the 'optimized' version of a material. Would that be the same batch, or become a different batch.
@ -1545,0 +1645,4 @@
bool GLShaderCompiler::batch_is_ready(BatchHandle handle)
{
mutex.lock();
can use
std::scoped_lock
@ -1235,0 +1247,4 @@
if (GLContext::khr_parallel_shader_compile_support) {
glGetProgramiv(program_id, GL_COMPLETION_STATUS_KHR, &is_ready);
}
else if (GLContext::arb_parallel_shader_compile_support) {
Both share the same status code (0x91B1) so might be moved into a single 'parallel_shader_compile_support` flag in context.
So in "modern" GAPI backends, there's not any upfront pipeline compilation at all?
Won't compile times become an even worse problem with Vulkan+Nvidia then?
I've made a test for using unoptimized variants and I've implemented the optimization step as a separate batch. I think it makes more sense with the current API, since optimized materials use a separate Shader and not all materials do the optimization step.
a148563ac6
I didn't include it in this PR since I thought it was large enough already, and wouldn't make any practical change since the optimization step is never used on OpenGL.
We have to find out. But on the other side we have more parameters to balance between performance and compilation times. LTO can be disabled, pipeline stages can be controlled individually (and reused between shaders). Caches can be stored to disk. Dynamic rendering reduces the amount of recompilations.
But yeah frontend compilation might become a file load operation in the end for the static shaders.
I’m not experienced with vulkan +Nvidia. So there is uncertainty in my answers
I get a lot of leaked memory blocks. I removed the duplicated ones for clarity. Just opening an EEVEE demo file and closing it is enough to reproduce.
Regarding backend compilation (PSO precaching), Michael had the idea of specifying the pipeline option in the create infos to prewarm the PSO cache with the most likely used variant(s). They are likely to be the same for each pipeline so it should be easy. But I wouldn't worry about this right now.
Performance
I gave it a spin but it doesn't look good on AMD + Mesa.
I only counted the materials compilation (time from first shaded frame). So static / pipeline shaders are not part of these timings.
EEVEE
Note that with the patch applied, I had to refresh the viewport for it to finish otherwise it could take more than 1min before the viewport refreshes.
EEVEE Next
*: broken, not sure if representative, could be worse in practice.
Not sure why EEVEE Next is not impacted by the same slowdown.
Maybe some batches are not being requested.
😣
Could you check different values for
glMaxShaderCompilerThreads
to see if that helps?Also, could you try to disable the extensions to see if it also affects compile times negatively?
Ie. just remove this:
That's weird, EEVEE should be requesting refreshes.
Edit: Well, EEVEE-Next requests updates, for EEVEE Legacy that's expected, yes.
I fixed the leaks and the refresh issue with EEVEE Legacy.
For reference, these are my compile times on EEVEE Next in other files:
BTW, I've also made another PR to parallelize the engine static shaders compilation (#121542).
I have not marked it for review yet since it depends on this one, but I'm linking it here so you're aware of it.
Even without the extension, I get the same slowdown. So I believe the extension is not correctly used on Mesa's OpengGL implementation (it is reported to support both
GL_ARB_parallel_shader_compile
andGL_KHR_parallel_shader_compile
).@blender-bot package
Package build started. Download here when ready.
Windows10 / RTX2060M / Studio Driver 552.22 (Apr 16 2024)
Checkout
From your project repository, check out a new branch and test the changes.