From 65b589f765784f0e6517ead82104c1e32c891460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Vondru=C5=A1?= Date: Tue, 15 Oct 2019 14:18:19 +0200 Subject: [PATCH] New explicit-uniform-location-is-less-explicit-than-you-hoped workaround. Intel drivers on Windows. Surprisingly unsurprising. --- doc/changelog.dox | 4 +++ .../GL/Implementation/driverSpecific.cpp | 28 +++++++++++++++---- src/Magnum/Shaders/MeshVisualizer.frag | 8 +++--- src/Magnum/Shaders/MeshVisualizer.geom | 2 +- src/Magnum/Shaders/MeshVisualizer.h | 10 +++---- 5 files changed, 37 insertions(+), 15 deletions(-) diff --git a/doc/changelog.dox b/doc/changelog.dox index 9cae87d4f..71515ccc8 100644 --- a/doc/changelog.dox +++ b/doc/changelog.dox @@ -449,6 +449,10 @@ See also: - @ref Shaders::Phong can now handle zero lights, in which case its output is equivalent to @ref Shaders::Flat3D. See @ref Shaders-Phong-zero-lights for more information. +- @ref Shaders::MeshVisualizer is fixed to work properly on Intel Windows + drivers, adding a new + @cpp "intel-windows-explicit-uniform-location-is-less-explicit-than-you-hoped" @ce + workaround @subsubsection changelog-latest-changes-texturetools TextureTools library diff --git a/src/Magnum/GL/Implementation/driverSpecific.cpp b/src/Magnum/GL/Implementation/driverSpecific.cpp index ee036c895..29c5f7043 100644 --- a/src/Magnum/GL/Implementation/driverSpecific.cpp +++ b/src/Magnum/GL/Implementation/driverSpecific.cpp @@ -253,6 +253,18 @@ namespace { glVertexAttribIFormat() works or not. A test that triggers this issue is in MeshGLTest::addVertexBufferIntWithShort(). */ "intel-windows-broken-dsa-integer-vertex-attributes", + +/* When using more than just a vertex and fragment shader (geometry shader, + e.g.), ARB_explicit_uniform_location on Intel silently uses wrong + locations, blowing up with either a non-descript + Error has been generated. GL error GL_INVALID_OPERATION in ProgramUniformMatrix4fv: (ID: 2052228270) Generic error + or, if you are lucky, a highly-cryptic-but-still-better-than-nothing + Error has been generated. GL error GL_INVALID_OPERATION in ProgramUniform4fv: (ID: 1725519030) GL error GL_INVALID_OPERATION: mismatched type setting uniform of location "3" in program 1, "" using shaders, 2, "", 3, "", 8, "" + *unless* you have vertex uniform locations first, fragment locations second + and geometry locations last. Not sure about the other stages. Note that this + workaround doesn't actually do anything, it's just printed as a heads-up + for the sleepless nights debugging issues that happen only on Intel. */ +"intel-windows-explicit-uniform-location-is-less-explicit-than-you-hoped", #endif #ifndef MAGNUM_TARGET_GLES @@ -396,16 +408,22 @@ void Context::setupDriverWorkarounds() { _extensionRequiredVersion[Extensions::extension::Index] = Version::version #ifndef MAGNUM_TARGET_GLES - #ifdef CORRADE_TARGET_WINDOWS - if((detectedDriver() & DetectedDriver::IntelWindows) && !isExtensionSupported() && !isDriverWorkaroundDisabled("intel-windows-glsl-exposes-unsupported-shading-language-420pack")) - _setRequiredVersion(ARB::shading_language_420pack, None); - #endif - if(!isDriverWorkaroundDisabled("no-layout-qualifiers-on-old-glsl")) { _setRequiredVersion(ARB::explicit_attrib_location, GL320); _setRequiredVersion(ARB::explicit_uniform_location, GL320); _setRequiredVersion(ARB::shading_language_420pack, GL320); } + + #ifdef CORRADE_TARGET_WINDOWS + if((detectedDriver() & DetectedDriver::IntelWindows) && !isExtensionSupported() && !isDriverWorkaroundDisabled("intel-windows-glsl-exposes-unsupported-shading-language-420pack")) + _setRequiredVersion(ARB::shading_language_420pack, None); + + if((detectedDriver() & DetectedDriver::IntelWindows) && isExtensionSupported() && !isDriverWorkaroundDisabled("intel-windows-explicit-uniform-location-is-less-explicit-than-you-hoped")) { + /* Just to have it printed in the log. Ideal would be to have this + covered with a minimal repro case but I have better things to do + in my life. */ + } + #endif #endif #ifndef MAGNUM_TARGET_GLES diff --git a/src/Magnum/Shaders/MeshVisualizer.frag b/src/Magnum/Shaders/MeshVisualizer.frag index 19ff354a3..12d792737 100644 --- a/src/Magnum/Shaders/MeshVisualizer.frag +++ b/src/Magnum/Shaders/MeshVisualizer.frag @@ -45,7 +45,7 @@ #endif #ifdef EXPLICIT_UNIFORM_LOCATION -layout(location = 2) +layout(location = 1) #endif uniform lowp vec4 color #ifndef GL_ES @@ -55,7 +55,7 @@ uniform lowp vec4 color #ifdef WIREFRAME_RENDERING #ifdef EXPLICIT_UNIFORM_LOCATION -layout(location = 3) +layout(location = 2) #endif uniform lowp vec4 wireframeColor #ifndef GL_ES @@ -64,7 +64,7 @@ uniform lowp vec4 wireframeColor ; #ifdef EXPLICIT_UNIFORM_LOCATION -layout(location = 4) +layout(location = 3) #endif uniform lowp float wireframeWidth #ifndef GL_ES @@ -73,7 +73,7 @@ uniform lowp float wireframeWidth ; #ifdef EXPLICIT_UNIFORM_LOCATION -layout(location = 5) +layout(location = 4) #endif uniform lowp float smoothness #ifndef GL_ES diff --git a/src/Magnum/Shaders/MeshVisualizer.geom b/src/Magnum/Shaders/MeshVisualizer.geom index 8a88ff7c0..4ca350882 100644 --- a/src/Magnum/Shaders/MeshVisualizer.geom +++ b/src/Magnum/Shaders/MeshVisualizer.geom @@ -35,7 +35,7 @@ #endif #ifdef EXPLICIT_UNIFORM_LOCATION -layout(location = 1) +layout(location = 5) #endif uniform lowp vec2 viewportSize; /* defaults to zero */ diff --git a/src/Magnum/Shaders/MeshVisualizer.h b/src/Magnum/Shaders/MeshVisualizer.h index 18a92a4b7..42d96f842 100644 --- a/src/Magnum/Shaders/MeshVisualizer.h +++ b/src/Magnum/Shaders/MeshVisualizer.h @@ -252,11 +252,11 @@ class MAGNUM_SHADERS_EXPORT MeshVisualizer: public GL::AbstractShaderProgram { private: Flags _flags; Int _transformationProjectionMatrixUniform{0}, - _viewportSizeUniform{1}, - _colorUniform{2}, - _wireframeColorUniform{3}, - _wireframeWidthUniform{4}, - _smoothnessUniform{5}; + _colorUniform{1}, + _wireframeColorUniform{2}, + _wireframeWidthUniform{3}, + _smoothnessUniform{4}, + _viewportSizeUniform{5}; }; /** @debugoperatorclassenum{MeshVisualizer,MeshVisualizer::Flag} */