Daemon icon indicating copy to clipboard operation
Daemon copied to clipboard

Rebuilding GLSL shaders that don't need a `vid_restart`

Open illwieckz opened this issue 1 year ago • 5 comments

I would like to see a mechanism that can rebuild a GLSL shader without needing a vid_restart.

I assume this would be doable for GLSL shaders not requiring to load any new data.

Not candidates:

  • r_normalMapping (requires shader parsing and image loading)
  • r_drawSky (requires shader parsing and image loading)
  • r_lightMode (requires bsp loading and image loading)

Candidates:

  • r_toneMapping
  • r_colorGrading (as far as I know the way colorGrade images are loaded may make it possible)

illwieckz avatar Mar 04 '25 18:03 illwieckz

We already have some lazy shader compilation mechanism, so maybe we can just invalidate a shader to get it rebuilt.

illwieckz avatar Mar 04 '25 18:03 illwieckz

We may implement a mechanism similar to Cvar::Latch(), to register shader cvars with their related GLSL shader, like that:

Cvar::Shader( r_toneMapping, gl_cameraEffectsShader );

When r_toneMapping would be modified, some code would invalidate gl_cameraEffectsShader to trigger a rebuild.

illwieckz avatar Mar 04 '25 18:03 illwieckz

Do note that I'm in the process of reworking shader loading/building to a substantial degree to make it faster and fix a few issues, so any actual changes here shoud be done after that.

VReaperV avatar Mar 04 '25 18:03 VReaperV

Yes, don't worry I have this in the back of my mind since years, but I thought it would be the right time to share the thought.

illwieckz avatar Mar 04 '25 18:03 illwieckz

We already have some lazy shader compilation mechanism, so maybe we can just invalidate a shader to get it rebuilt.

That's a nice idea. Maybe a simple Cvar::Callback to unload the affected shaders could really work. (Can we NUKE r_smp? It would be awfully annoying to have to sync the thread in the callback.)

slipher avatar Mar 06 '25 00:03 slipher