Skip to content

Commit 4f40934

Browse files
committed
Fix r_lazyShaders behaviors
1. Don't build everything on map load if mode 2 is used. GLSL_InitWorldShadersOrError is called before EndRegistration so it's not necessary to request building shaders therie. 2. Do rebuild everything on glsl_restart if mode 1 is used. This fixes the broken fallback-to-builtin-shaders behavior.
1 parent 9576cfe commit 4f40934

File tree

4 files changed

+27
-22
lines changed

4 files changed

+27
-22
lines changed

src/engine/renderer/tr_bsp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7034,5 +7034,5 @@ void RE_LoadWorldMap( const char *name )
70347034
}
70357035

70367036
tr.worldLoaded = true;
7037-
GLSL_InitWorldShadersOrError();
7037+
GLSL_InitWorldShaders();
70387038
}

src/engine/renderer/tr_init.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,18 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
9393
cvar_t *r_exportTextures;
9494
cvar_t *r_heatHaze;
9595
cvar_t *r_noMarksOnTrisurfs;
96-
cvar_t *r_lazyShaders;
96+
97+
/* Default value is 1: Delay GLSL shader build until first map load.
98+
99+
This makes possible for the user to quickly reach the game main menu
100+
without building all GLSL shaders and set a low graphics preset before
101+
joining a game and loading a map.
102+
103+
Doing so prevents building unwanted or unsupported GLSL shaders on slow
104+
and/or old hardware and drastically reduce first startup time. */
105+
Cvar::Range<Cvar::Cvar<int>> r_lazyShaders(
106+
"r_lazyShaders", "build GLSL shaders (0) on startup, (1) on map load or (2) when used",
107+
Cvar::NONE, 1, 0, 2);
97108

98109
cvar_t *r_checkGLErrors;
99110
cvar_t *r_logFile;
@@ -1122,16 +1133,6 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
11221133
r_heatHaze = Cvar_Get( "r_heatHaze", "1", CVAR_LATCH | CVAR_ARCHIVE );
11231134
r_noMarksOnTrisurfs = Cvar_Get( "r_noMarksOnTrisurfs", "1", CVAR_CHEAT );
11241135

1125-
/* 1: Delay GLSL shader build until first map load.
1126-
1127-
This makes possible for the user to quickly reach the game main menu
1128-
without building all GLSL shaders and set a low graphics preset before
1129-
joining a game and loading a map.
1130-
1131-
Doing so prevents building unwanted or unsupported GLSL shaders on slow
1132-
and/or old hardware and drastically reduce first startup time. */
1133-
r_lazyShaders = Cvar_Get( "r_lazyShaders", "1", 0 );
1134-
11351136
r_wolfFog = Cvar_Get( "r_wolfFog", "1", CVAR_CHEAT );
11361137
r_noFog = Cvar_Get( "r_noFog", "0", CVAR_CHEAT );
11371138

@@ -1556,7 +1557,7 @@ ScreenshotCmd screenshotPNGRegistration("screenshotPNG", ssFormat_t::SSF_PNG, "p
15561557
void RE_EndRegistration()
15571558
{
15581559
R_SyncRenderThread();
1559-
if ( r_lazyShaders->integer == 1 )
1560+
if ( r_lazyShaders.Get() == 1 )
15601561
{
15611562
GLSL_FinishGPUShaders();
15621563
}

src/engine/renderer/tr_local.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2837,7 +2837,7 @@ enum class realtimeLightingRenderer_t { LEGACY, TILED };
28372837
extern cvar_t *r_exportTextures;
28382838
extern cvar_t *r_heatHaze;
28392839
extern cvar_t *r_noMarksOnTrisurfs;
2840-
extern cvar_t *r_lazyShaders; // 0: build all shaders on program start 1: delay shader build until first map load 2: delay shader build until needed
2840+
extern Cvar::Range<Cvar::Cvar<int>> r_lazyShaders; // 0: build all shaders on program start 1: delay shader build until first map load 2: delay shader build until needed
28412841

28422842
extern cvar_t *r_norefresh; // bypasses the ref rendering
28432843
extern cvar_t *r_drawentities; // disable/enable entity rendering
@@ -3378,7 +3378,7 @@ inline bool checkGLErrors()
33783378
alignas(16) extern shaderCommands_t tess;
33793379

33803380
void GLSL_InitGPUShaders();
3381-
void GLSL_InitWorldShadersOrError();
3381+
void GLSL_InitWorldShaders();
33823382
void GLSL_ShutdownGPUShaders();
33833383
void GLSL_FinishGPUShaders();
33843384

src/engine/renderer/tr_shade.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ static void EnableAvailableFeatures()
143143
}
144144

145145
// For shaders that require map data for compile-time values
146-
void GLSL_InitWorldShadersOrError() {
146+
void GLSL_InitWorldShaders() {
147147
// make sure the render thread is stopped
148148
R_SyncRenderThread();
149149

@@ -155,8 +155,6 @@ void GLSL_InitWorldShadersOrError() {
155155
if ( glConfig2.materialSystemAvailable ) {
156156
gl_shaderManager.load( gl_cullShader );
157157
}
158-
159-
gl_shaderManager.buildAll();
160158
}
161159

162160
static void GLSL_InitGPUShadersOrError()
@@ -350,7 +348,7 @@ static void GLSL_InitGPUShadersOrError()
350348
gl_shaderManager.load( gl_fxaaShader );
351349
}
352350

353-
if ( !r_lazyShaders->integer )
351+
if ( r_lazyShaders.Get() == 0 )
354352
{
355353
gl_shaderManager.buildAll();
356354
}
@@ -369,9 +367,10 @@ void GLSL_InitGPUShaders()
369367
is set on the command line, the cycle is:
370368
1. Start the app.
371369
2. Change shader file(s)
372-
3. Do /glsl_restart at the app console to reload them. If there is a problem the app will
373-
revert to the last working changes in shaders.cpp, so no need to restart the app.
374-
FIXME: this doesn't work, actually it kills the app!
370+
3. Do /glsl_restart at the app console to reload them. If there is a problem and
371+
r_lazyShaders < 2, the app will revert to the last working changes in shaders.cpp, so no need
372+
to restart the app. OTOH if r_lazyShaders = 2 you can iterate really fast, but
373+
you die if you make a typo.
375374
4. If further changes are needed, repeat from step 3.
376375
377376
Note that Daemon will respond by listing the files it thinks are different.
@@ -391,6 +390,10 @@ void GLSL_InitGPUShaders()
391390
{
392391
Log::Warn("Loading external shaders.");
393392
GLSL_InitGPUShadersOrError();
393+
if ( r_lazyShaders.Get() == 1 && tr.world != nullptr )
394+
{
395+
gl_shaderManager.buildAll();
396+
}
394397
Log::Warn("External shaders in use.");
395398
}
396399
catch (const ShaderException& e)
@@ -426,6 +429,7 @@ void GLSL_ShutdownGPUShaders()
426429

427430
gl_shaderManager.freeAll();
428431

432+
gl_generic2DShader = nullptr;
429433
gl_genericShader = nullptr;
430434
gl_genericShaderMaterial = nullptr;
431435
gl_cullShader = nullptr;

0 commit comments

Comments
 (0)