Skip to content

Commit

Permalink
workaround for nvidia shader compiler bug on very old windows drivers.
Browse files Browse the repository at this point in the history
  • Loading branch information
slime73 committed Aug 10, 2024
1 parent 1b8a501 commit 36fa78f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/modules/graphics/Graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,9 @@ class Graphics : public Module
return (T *) scratchBuffer.data();
}

// Workaround for some very old nvidia drivers that aren't compliant with the GLSL 3.30 spec.
bool isUsingNoTextureCubeShadowBiasHack() const { return usingNoTextureCubeShadowBiasHack; }

static Graphics *createInstance();

STRINGMAP_CLASS_DECLARE(DrawMode);
Expand Down Expand Up @@ -1086,6 +1089,8 @@ class Graphics : public Module

Deprecations deprecations;

bool usingNoTextureCubeShadowBiasHack = false;

static const size_t MAX_USER_STACK_DEPTH = 128;
static const int MAX_TEMPORARY_RESOURCE_UNUSED_FRAMES = 16;

Expand Down
5 changes: 5 additions & 0 deletions src/modules/graphics/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,10 @@ float Texel(sampler2DArrayShadow s, highp vec4 c) { return texture(s, c); }
uvec4 Texel(usampler2DArray s, highp vec3 c, float b) { return texture(s, c, b); }
float Texel(sampler2DShadow s, highp vec3 c, float b) { return texture(s, c, b); }
#ifndef LOVE_NO_TEXTURECUBESHADOWBIAS_HACK
float Texel(samplerCubeShadow s, highp vec4 c, float b) { return texture(s, c, b); }
#endif
#endif
uniform mediump float deprecatedTextureCall;
Expand Down Expand Up @@ -613,6 +615,9 @@ std::string Shader::createShaderStageCode(Graphics *gfx, ShaderStageType stage,
if (info.usesMRT)
ss << "#define LOVE_MULTI_RENDER_TARGETS 1\n";

if (gfx->isUsingNoTextureCubeShadowBiasHack())
ss << "#define LOVE_NO_TEXTURECUBESHADOWBIAS_HACK 1\n";

for (const auto &def : options.defines)
ss << "#define " + def.first + " " + def.second + "\n";

Expand Down
20 changes: 19 additions & 1 deletion src/modules/graphics/opengl/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,25 @@ bool Graphics::setMode(void */*context*/, int width, int height, int pixelwidth,
Shader::CompileOptions opts;
stages.push_back(Shader::getDefaultCode(stype, SHADERSTAGE_VERTEX));
stages.push_back(Shader::getDefaultCode(stype, SHADERSTAGE_PIXEL));
Shader::standardShaders[i] = newShader(stages, opts);

try
{
Shader::standardShaders[i] = newShader(stages, opts);
}
catch (love::Exception &)
{
// Attempted workaround for nvidia driver bug affecting old GPUs
// on Windows (e.g. the 300 series).
if (!isUsingNoTextureCubeShadowBiasHack())
{
usingNoTextureCubeShadowBiasHack = true;
Shader::standardShaders[i] = newShader(stages, opts);
}
else
{
throw;
}
}
}
}

Expand Down

0 comments on commit 36fa78f

Please sign in to comment.