Devsh-Graphics-Programming / Nabla

Vulkan, OptiX and CUDA Interoperation Modular Rendering Library and Framework for PC/Linux/Android
http://devsh.eu
Apache License 2.0
487 stars 58 forks source link

Streaming shader preprocessor cache #688

Open Fletterio opened 6 months ago

Fletterio commented 6 months ago

Description

The current cache holds all resources on memory at all times. This could be problematic if, for example, the cache is required to hold many shaders

A streaming shader preprocessor cache is proposed: stored as an LZMA CArchive that would hold:

And then load shaders on-demand when compilation is requested

Solution proposal

I think the best would be to load the whole JSON at cache creation time, and then load each shader's byte code onto memory on-demand (so only when compilation for that shader is requested and not earlier)

Additional context

Since each entry contains ALL of the plaintext for ALL its dependencies, that could also start to pile up, so an option is to also have each entry's dependencies stored in an LZMA-compressed file. We would then only load an entry's dependencies onto memory when those need to be compared when compilation is requested. This could additionally come with a Cache method to drop all loaded dependencies from memory if the cache starts taking up too much space in memory (not counting shader code). Or if it's fast enough we could simply make it more "pure-streaming": load dependencies, compare, immediately drop

As it stands right now, shared dependencies are repeated once for each shader. That could also be problematic, so an optimization would be to handle dependencies in another manner so they're unique and shared by entries. This also holds for the current Cache implementation

devshgraphicsprogramming commented 6 months ago

We need to dedup the contents of files, and keep the dependencies LZMA compressed before we approach on-demand streaming from a file