Skip to content

Async shader loading and caching - #178

Merged
marchc1 merged 17 commits into
SourceDotNET:mainfrom
ZehMatt:async-shaders
Oct 13, 2026
Merged

marchc1 merged 17 commits into
SourceDotNET:mainfrom
ZehMatt:async-shaders

Conversation

@ZehMatt

@ZehMatt ZehMatt commented Oct 13, 2026

Copy link
Copy Markdown
Contributor

Because the stutters annoyed me I decided to refactor this, the changes in a nutshell:

  • Shaders are now loaded in a dedicated worker thread with a shared context.
  • After successful compilation they are now stored on disk keyed by driver and hash of the source.
  • When loading a map it now builds every combination, so most if not all shaders are immediately available from cache.
  • Lazy shader loading remains in case something comes later like with addons.
  • I enabled the loading panel now unconditionally just like GMod does it and also display a progress of shader compilation, I've reused the text given the localization is a bit broken currently.
  • Optimized how it builds the shader source with includes, each include is now loaded only once saving roughly 300~ MB memory.

I also did a little bit of cleaning up the code and added some enums for the flags. So overall the stutters are now gone, the downside is that it now holds very shader combination in memory which is about 10 MB so its not really much and compared to Unity this is nothing. Another thing to note, I've set the parallel worker threads for shader compilation to only 2, it does seem to allocate quite a bit of memory per worker and its done in like 4 seconds on my machine and only when the cache has not been yet built so I think this is reasonable.

@marchc1

marchc1 commented Oct 13, 2026

Copy link
Copy Markdown
Member

Check proposed changes, otherwise good

@marchc1

marchc1 commented Oct 13, 2026

Copy link
Copy Markdown
Member

Confirmed the Wayland-specific (well, Linux at least, but I don't have X11 on this system) paranoia was correct, undoing that commit results in a blank screen.

@marchc1
marchc1 merged commit e4f8bf7 into SourceDotNET:main Oct 13, 2026
4 checks passed
@ZehMatt
ZehMatt deleted the async-shaders branch October 14, 2026 00:06
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.

2 participants