Fix DebugDraw shaders compilation (#2362)

* Fix DebugDraw shaders compilation

Pull request #2317 broke compilation of the DebugDraw shaders (vs_debugdraw_fill.sc, etc)
on the Intel mesa driver. Shaders with a version lower than 130 have no
support for uvec or ivec by default on OpenGL.

This patch detects when these shaders are present and bumps the version when appropriate.

* Removed the ivecs from the patch
It seems the ivecs are infact supported on versions lower than 130 on
OpenGL.
This commit is contained in:
kingscallop 2021-06-06 22:05:14 +01:00 committed by GitHub
parent 73784ac9eb
commit e65d185ed6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -254,6 +254,23 @@ namespace bgfx
NULL NULL
}; };
static const char* s_bitsToEncoders[] =
{
"floatBitsToUint",
"floatBitsToInt",
"intBitsToFloat",
"uintBitsToFloat",
NULL
};
static const char* s_unsignedVecs[] =
{
"uvec2",
"uvec3",
"uvec4",
NULL
};
const char* s_uniformTypeName[] = const char* s_uniformTypeName[] =
{ {
"int", "int", "int", "int",
@ -2129,15 +2146,14 @@ namespace bgfx
const bx::StringView preprocessedInput(preprocessor.m_preprocessed.c_str() ); const bx::StringView preprocessedInput(preprocessor.m_preprocessed.c_str() );
uint32_t glsl_profile = profile->id; uint32_t glsl_profile = profile->id;
const bool usesBitsToEncoders = true
&& _options.shaderType == 'f'
&& !bx::findIdentifierMatch(preprocessedInput, s_bitsToEncoders).isEmpty()
;
if (!bx::strFind(preprocessedInput, "layout(std430").isEmpty() if (!bx::strFind(preprocessedInput, "layout(std430").isEmpty()
|| !bx::strFind(preprocessedInput, "image2D").isEmpty() || !bx::strFind(preprocessedInput, "image2D").isEmpty()
|| (_options.shaderType == 'f' || usesBitsToEncoders)
&& (!bx::strFind(preprocessedInput, "floatBitsToUint").isEmpty() ||
!bx::strFind(preprocessedInput, "floatBitsToInt").isEmpty() ||
!bx::strFind(preprocessedInput, "intBitsToFloat").isEmpty() ||
!bx::strFind(preprocessedInput, "uintBitsToFloat").isEmpty()
) )
)
{ {
if (profile->lang == ShadingLang::GLSL if (profile->lang == ShadingLang::GLSL
&& glsl_profile < 430) && glsl_profile < 430)
@ -2169,6 +2185,7 @@ namespace bgfx
const bool usesTextureArray = !bx::findIdentifierMatch(input, s_textureArray).isEmpty(); const bool usesTextureArray = !bx::findIdentifierMatch(input, s_textureArray).isEmpty();
const bool usesPacking = !bx::findIdentifierMatch(input, s_ARB_shading_language_packing).isEmpty(); const bool usesPacking = !bx::findIdentifierMatch(input, s_ARB_shading_language_packing).isEmpty();
const bool usesViewportLayerArray = !bx::findIdentifierMatch(input, s_ARB_shader_viewport_layer_array).isEmpty(); const bool usesViewportLayerArray = !bx::findIdentifierMatch(input, s_ARB_shader_viewport_layer_array).isEmpty();
const bool usesUnsignedVecs = !bx::findIdentifierMatch(preprocessedInput, s_unsignedVecs).isEmpty();
if (profile->lang != ShadingLang::ESSL) if (profile->lang != ShadingLang::ESSL)
{ {
@ -2176,6 +2193,7 @@ namespace bgfx
|| !bx::findIdentifierMatch(input, s_130).isEmpty() || !bx::findIdentifierMatch(input, s_130).isEmpty()
|| usesInterpolationQualifiers || usesInterpolationQualifiers
|| usesTexelFetch || usesTexelFetch
|| usesUnsignedVecs
) ); ) );
bx::stringPrintf(code, "#version %d\n", need130 ? 130 : glsl_profile); bx::stringPrintf(code, "#version %d\n", need130 ? 130 : glsl_profile);
@ -2303,6 +2321,11 @@ namespace bgfx
} }
else else
{ {
if ((glsl_profile < 300) && usesUnsignedVecs)
{
glsl_profile = 300;
}
if (glsl_profile > 100) if (glsl_profile > 100)
{ {
bx::stringPrintf(code, "#version %d es\n", glsl_profile); bx::stringPrintf(code, "#version %d es\n", glsl_profile);