-
Notifications
You must be signed in to change notification settings - Fork 963
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
Pipeline cache API and implementation for Vulkan #5319
Pipeline cache API and implementation for Vulkan #5319
Conversation
6350e86
to
b657c91
Compare
cc @expenses, as you had a previous investigation in gfx-rs/gfx#3716 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! The code itself is fine, keep it up like this, and the documentation is dreamy.
The api has a few issues at multiple layers. At points wgpu-hal is expected to do validation, at other points the end user is just expected to know how to pass the correct thing. I think we should unify the api as follows.
wgpu-hal
The wgpu-hal layer should just expect that the blob passed to it is correct for that platform and driver combination. It shouldn't do any additional validation. All of its internal code can expect that the cache key is honored.
It may append additional data structures to the blob which contain shader intermediate states (such as HLSL generated or DXBC/DXIL).
There is a method on the Adapter which returns a backend-specific string of bytes to serve as a "cache key". This includes the wgpu-hal version.
wgpu-core
Core does all of the validation that the key is honored and the file was not corrupted.
It adds metadata to the top of the blob that stores the magic number, file size, file hash, and pipeline key.
If this errors, it will create a new empty cache.
wgpu
Passes through the core apis.
User
The user will pull the pipeline key from the adapter, hash it, and use it as a filename to store the data.
Does this all make sense?
Thanks for the review @cwfitzgerald In terms of validation, my intent was to follow up with that, because I wasn't sure I was doing the right thing. So I can definitely add that in here. I just want some clarification about what you mean by:
In my prototype integration, I wasn't hashing the filename. I find it unlikely that users would do so, either. |
This is also slightly troubling, as different APIs have different validation needs. For example, Vulkan probably needs to validate the driver version is the same, whereas the concept of a driver version isn't exposed at the higher levels |
397326f
to
d256e9c
Compare
That's interesting... are there Vk drivers in the wild that accept incompatible pipeline caches from applications, or is this more preemptive (due to the quality issues with some drivers)? |
According to the linked article, there have been cases in the past where a driver either:
|
The idea is that the wgpu-hal decides on its pipeline key based on its validation needs, and wgpu-core is the one who does the comparison and rejection of the pipeline key. This way the driver version will be part of the wgpu-hal pipeline key.
If we make cache key an opaque type we can put a |
The key factor which needs to be accounted for is:
I'm planning on implementing that with effectively two keys, a "device" key (which identifies the device/backend combination) and a further validation key. The device key should related to the "file name" being used, whereas the validation key is just used to bail from using the cache. That is potentially what you are describing, but I think it's good to clarify that |
e973ce8
to
7626051
Compare
This is now ready for follow-up review. I am going to now test this updated version in Vello, and also need some guidance on computing the I'm unlikely to make further functional changes before another review |
Having done some more thinking on this, I have decided to exclude the hashing of the cache data from this PR. The main reasons for this are:
I also don't see the necessity in making the pipeline cache key an opaque set of bytes, rather than a readable string. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is absolutely fabulous work!
I think the setup for caching is perfectly reasonable, and the core/hal relationship is exactly what i wanted to see!
Have some comments. I also would like to see an execution test that actually uses the pipeline cache. Maybe make a cache, make a pipeline, serialize the cache, re-parse it to a new cache, and make an identical pipeline. Just to make sure everything actually works and there aren't any api level issues.
53f7f1e
to
84e1616
Compare
Re-requesting review pending CI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for taking so long to get back to you on this - we're basically there, just some small nits at this point.
Fix some CI issues
Temp: Start wiring up data access
We don't have any current dependencies which would compute this, and it is probably superfluous
d3d4fb9
to
20906e9
Compare
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just need your throughs on where the pipeline cache should go, then we're good to land.
This really makes the diff so much more unwieldy
Looks to be an issue with the ash update |
I'll fix this up and get it in |
Co-authored-by: Connor Fitzgerald <connorwadefitzgerald@gmail.com>
Connections
Description
Adds a
PipelineCache
resource towgpu
's API, and wires it down to VulkanvkCreatePipelineCache
.This cache is added as a parameter to
ComputePipelineDescriptor
andRenderPipelineDescriptor
.This parameter is used as expected on Vulkan, and ignored on DirectX/Metal/WebGPU/gles.
Testing
Testing has been performed on a Pixel 6, which has validated that this works as expected between runs.
This is in the branch in my fork of Vello.
This does only test the cache for Vulkan pipelining.
Checklist
cargo fmt
.cargo clippy
. If applicable, add:--target wasm32-unknown-unknown
--target wasm32-unknown-emscripten
- gets the same errors onmain
, so I assume it's finecargo xtask test
to run tests - I get the same failures onmain
, so I assume it's fineCHANGELOG.md
. See simple instructions inside file.Status
This PR is now fully ready for review
Future Work
I am planning on implementing additional validation inside wgpu that the cache is suitable, as discussed in https://medium.com/@zeuxcg/creating-a-robust-pipeline-cache-with-vulkan-961d09416cda. That is mainly about storing the driver version and file size inline in the file. This should be done before this feature is released, but could be in a different pull request. Please advise if you have any preference here.
This could also be extended to different platforms/APIs - see e.g. gfx-rs/gfx#2877
I am not intending to do this work myself