-
Notifications
You must be signed in to change notification settings - Fork 1.1k
wgpu should cache pipelines #7716
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
Comments
It seems like using
The |
There is ID3D12PipelineLibrary but what I heard this was focusing on serializing between runs not deduplicating within a run. D3D12 does have implicit pipeline caches, though our biggest cost on d3d12 is compiling HLSL -> DXIL/DXBC which is a user space operation, so we'd need to cache those. |
I thought you did HLSL -> DXIL at createRenderPipelines time and not
createShaderModule time?
I think some cache keyed off the shader module (and codegen-relevant state)
would prevent a lot of duplicate work here.
I had some early prototype experiments for this in Vulkan using dynamic
state but I need to get back to it…
Jasper
…On Fri, May 23, 2025 at 8:54 AM Connor Fitzgerald ***@***.***> wrote:
*cwfitzgerald* left a comment (gfx-rs/wgpu#7716)
<#7716 (comment)>
There is ID3D12PipelineLibrary
<https://learn.microsoft.com/en-us/windows/win32/api/d3d12/nn-d3d12-id3d12pipelinelibrary>
but what I heard this was focusing on serializing between runs not
deduplicating within a run. D3D12 does have implicit pipeline caches,
though our biggest cost on d3d12 is compiling HLSL -> DXIL/DXBC which is a
user space operation, so we'd need to cache those.
—
Reply to this email directly, view it on GitHub
<#7716 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAJ7OSMRCZD5RWWDOU3VV327ZPRTAVCNFSM6AAAAAB5XGLHNSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSMBSHA3TONRRGQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
I gotta ask, what is the use case for pipeline caching? I create mine once (or recreate on shader reload). Meaning, what is this caching used for if one shouldn't keep recreating pipelines each frame anyway? Is this something different? (Please explainer assume I know nothing) |
It sounds like the metaballs application is somewhat poorly written in that
it creates the same pipeline every frame, which causes us to do a lot more
work than would be necessary if we had a cache.
But there are some valid cases even well-written applications where a
pipeline or shader cache would be beneficial.
A shader cache would help cases where the shader is the same, but the
fixed-function state is different, such as using the same shader with
depth-write on/off states. In this case, we shouldn’t need to recompile the
shader from source, and can reuse the same bytecode.
A pipeline cache would help in cases where certain kinds of state are not
in the native PSO. e.g. Metal, depth write is dynamic on the command buffer
and isn’t part of the PSO; in this case, we should have a cache for only
the compiled parts of the Metal PSO and reuse it, and store the Metal PSO
and depth state in a separate structure, applying both at setRenderPipeline
time. And the same is also true for Vulkan dynamic state.
Jasper
…On Fri, May 23, 2025 at 5:24 PM Okko Hakola ***@***.***> wrote:
*hakolao* left a comment (gfx-rs/wgpu#7716)
<#7716 (comment)>
I gotta ask, what is the use case for pipeline caching? I create mine once
(or recreate on shader reload). Meaning, what is this caching used for if
one shouldn't keep recreating pipelines each frame anyway?
Vulkan says: *The big advantage of a pipeline cache is that the pipeline
state can be saved to a file to be used between runs of an application
<https://docs.vulkan.org/guide/latest/pipeline_cache.html>*
Is this something different?
—
Reply to this email directly, view it on GitHub
<#7716 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAJ7OWXS6Q5J22S42NFY43273LMRAVCNFSM6AAAAAB5XGLHNSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDSMBTGY3TKOJXG4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
One of the unity demos (https://vfx-demo.cds.unity3d.com) also stutters occasionally due to
I also think we can try caching just the bytecode (to avoid calling into FXC/DXC), that will probably get us far enough. Caching pipelines is more involved since we'd also need to cache everything else that makes up a pipeline. |
Regarding the Marching Cubes demo, this is what it's calling every frame: https://github.com/tcoppex/webgpu-marchingcubes/blob/e464ccf192dcd9ded794dae5593a0e4cbedf487a/js/utils.js#L296 |
P1 for Firefox because it blocks Marching Cubes. |
wgpu is too slow when render or compute pipelines are created repeatedly.
At present, each call to
wgpu_core::global::Global::device_create_compute_pipeline
results in a separate call towgpu_hal::Device::create_compute_pipeline
. Render pipelines are similar. However, the WebGPU specification says (§2.2.4 User Agent State):This means that applications are within their rights to assume that calling
createRenderPipeline
in every animation frame, with the same parameters, should be cheap.This Firefox profile shows that the Marching Cubes demo ends up pegging the Canvas Renderer thread running DXC. The profile has other problems, like taking 270ms for every
requestAnimationFrame
call, but the time in DXC is responsible for the pace of calls torequestAnimationFrame
being only around 1fps.The text was updated successfully, but these errors were encountered: