Skip to content
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

[GPU] Pipeline caches #11629

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Conversation

DeltaW0x
Copy link
Contributor

@DeltaW0x DeltaW0x commented Dec 10, 2024

I've implemented a draft for a possible pipeline caching system.
The user can call SDL_CreateGPUPipelineCache to create a SDL_GPUPipelineCache object, which can then be used to accelerate pipeline compilations by passing it as a SDL_PropertiesID to SDL_CreateGPUGraphicsPipeline and SDL_CreateGPUGraphicsPipeline.

SDL_CreateGPUPipelineCache takes a SDL_GPUPipelineCacheCreateInfo struct, which supplies both a checksum binary blob (opaque to the user), a normal pipeline cache blob, and their respective sizes, or NULL/zero if no data is yet present.
On application exit, the user can call SDL_FetchGPUPipelineCacheData to fill a new SDL_GPUPipelineCacheCreateInfo with new/update pipeline data, which can then be written to disk and loaded on the next run.

Currently the Vulkan implementation is functional except the checksum control part, as I don't know which hash algorithm would be more suitable or preferred for SDL, the DirectX 12 implementation is in the process of being written.

Regarding Metal, I've left a commented implementation for all the necessary function, problem being that Apple wants me to write the entire MTLBinaryArchiveobject to disk, and doesn't provide neither a binary blob which I can use, nor a definition for what MTLBinaryArchive actually is internally

@thatcosmonaut
Copy link
Collaborator

thatcosmonaut commented Dec 10, 2024

This is on the right track. We'll definitely want a D3D12 implementation before merging this. We might just have to leave this as a no-op on Metal until Apple gets their act together and lets us grab the cache data in memory.

One thing that's slightly concerning is that it seems like the application will have to be aware of the backend and provide the correct cache file manually, which might be irritating. I'm not really sure of how to make that future-proof though.

@thatcosmonaut thatcosmonaut added this to the 3.x milestone Dec 10, 2024
@EtienneParmentier
Copy link

EtienneParmentier commented Feb 24, 2025

One thing that's slightly concerning is that it seems like the application will have to be aware of the backend and provide the correct cache file manually, which might be irritating. I'm not really sure of how to make that future-proof though.

I thought the principle of pipeline caching is to compile at first startup of the app, and only then reuse the cache once it was created ? Shipping a pipeline cache for each combination of drivers/device/ is not possible in general (some platforms like steam-deck can do that but only because the hardware is always the same).
In the case of multiple API availlable for the GPU API, mainly directX or vulkan on windows, would it be possible to assign each implementation of the GPU API an identifier ? This identifier can then be placed in the header of the file SDL saves to disk.

Here is an article from a roblox engineer that goes in depth about how pipeline caching works in the wild maybe some of the concepts can be applied to our needs ? Reading the article, it looks like mobile drivers aren't always compliant even though the functionality is implemented.

SDL provides hashing algorithm inside it's stdlib: crc32 and crc16 could be used to ensure the file has not be corrupted ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants