Browse Source

GL: new "adreno-glsl-version-stuck-at-300" workaround.

pull/168/head
Vladimír Vondruš 3 years ago
parent
commit
9b160e95c3
  1. 6
      doc/changelog.dox
  2. 8
      src/Magnum/GL/Implementation/ShaderState.cpp
  3. 3
      src/Magnum/GL/Implementation/ShaderState.h
  4. 7
      src/Magnum/GL/Implementation/driverSpecific.cpp
  5. 24
      src/Magnum/GL/Shader.cpp
  6. 9
      src/Magnum/GL/Shader.h
  7. 2
      src/Magnum/Shaders/compatibility.glsl

6
doc/changelog.dox

@ -189,6 +189,12 @@ See also:
instanced buffers being too small when drawing such mesh as non-instanced.
See @ref opengl-workarounds for more information, see also
[mosra/magnum#539](https://github.com/mosra/magnum/pull/539).
- A new @cpp "adreno-glsl-version-stuck-at-300" @ce workaround for an
incorrect @glsl __VERSION__ @ce reported for GLSL ES 3.10 and 3.20 shaders
on Qualcomm Adreno drivers that caused builtin shaders to have broken
rendering or even crash. See @ref opengl-workarounds and
[mosra/magnum#618](https://github.com/mosra/magnum/issues/618) for more
information.
@subsubsection changelog-latest-new-math Math library

8
src/Magnum/GL/Implementation/ShaderState.cpp

@ -77,6 +77,14 @@ ShaderState::ShaderState(Context& context, Containers::StaticArrayView<Implement
} else {
completionStatusImplementation = &Shader::completionStatusImplementationFallback;
}
#if defined(MAGNUM_TARGET_GLES) && !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) && !defined(CORRADE_TARGET_APPLE)
if((context.detectedDriver() & Context::DetectedDriver::QualcommAdreno) && !context.isDriverWorkaroundDisabled("adreno-glsl-version-stuck-at-300"_s)) {
workaroundDefinesImplementation = &Shader::workaroundDefinesImplementationAdrenoVersion;
} else {
workaroundDefinesImplementation = &Shader::workaroundDefinesImplementationNoOp;
}
#endif
}
}}}

3
src/Magnum/GL/Implementation/ShaderState.h

@ -43,6 +43,9 @@ struct ShaderState {
#endif
};
#if defined(MAGNUM_TARGET_GLES) && !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) && !defined(CORRADE_TARGET_APPLE)
Containers::StringView(*workaroundDefinesImplementation)(Version);
#endif
void(*addSourceImplementation)(Shader&, Containers::String&&);
void(*cleanLogImplementation)(Containers::String&);
/* This is a direct pointer to a GL function, so needs a __stdcall on

7
src/Magnum/GL/Implementation/driverSpecific.cpp

@ -108,6 +108,13 @@ constexpr Containers::StringView KnownWorkarounds[]{
"apple-buffer-texture-unbind-on-buffer-modify"_s,
#endif
#if defined(MAGNUM_TARGET_GLES) && !defined(MAGNUM_TARGET_GLES2)
/* Qualcomm Adreno drivers V@0615.65 (and possibly others) report __VERSION__
as 300 even for GLSL ES 3.10 and 3.20, breaking version-dependent shader
code. */
"adreno-glsl-version-stuck-at-300"_s,
#endif
#if defined(CORRADE_TARGET_ANDROID) && defined(MAGNUM_TARGET_GLES)
/* glBeginQuery() with GL_TIME_ELAPSED causes a GL_OUT_OF_MEMORY error when
running from the Android shell (through ADB). No such error happens in an

24
src/Magnum/GL/Shader.cpp

@ -646,6 +646,24 @@ Int Shader::maxCombinedUniformComponents(const Type type) {
}
#endif
#if defined(MAGNUM_TARGET_GLES) && !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) && !defined(CORRADE_TARGET_APPLE)
Containers::StringView Shader::workaroundDefinesImplementationNoOp(Version) {
return {};
}
Containers::StringView Shader::workaroundDefinesImplementationAdrenoVersion(const Version version) {
if(version == Version::GLES310)
return "#if __VERSION__ < 310\n"
"#define MAGNUM_GLSL_VERSION 310\n"
"#endif\n";
if(version == Version::GLES320)
return "#if __VERSION__ < 320\n"
"#define MAGNUM_GLSL_VERSION 320\n"
"#endif\n";
return {};
}
#endif
Shader::Shader(const Version version, const Type type): _type{type}, _flags{ObjectFlag::DeleteOnDestruction|ObjectFlag::Created} {
_id = glCreateShader(GLenum(_type));
@ -715,6 +733,12 @@ Shader::Shader(const Version version, const Type type): _type{type}, _flags{Obje
arrayAppend(_sources, Containers::String::nullTerminatedGlobalView("#define MAGNUM_DISABLE_GL_MAGNUM_shader_vertex_id\n"_s));
#endif
#if defined(MAGNUM_TARGET_GLES) && !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) && !defined(CORRADE_TARGET_APPLE)
if(const Containers::StringView defines = context.state().shader.workaroundDefinesImplementation(version)) {
arrayAppend(_sources, Containers::String::nullTerminatedGlobalView(defines));
}
#endif
/* Remember how many initial sources were added to have consistent
#line numbering later */
_fileIndexOffset = _sources.size() - 1;

9
src/Magnum/GL/Shader.h

@ -81,6 +81,10 @@ passed to the constructor:
isn't working correctly. You can use the artificial
`GL_MAGNUM_shader_vertex_id` desktop, ES and WebGL extension to check for
this case in @ref GL::Context::isExtensionSupported(Version) const.
- @cpp #define MAGNUM_GLSL_VERSION 310 @ce or
@cpp #define MAGNUM_GLSL_VERSION 320 @ce if the builtin
@glsl __VERSION__ @ce macro doesn't have correct value for GLSL ES 3.10 or
3.20
See @ref opengl-workarounds for concrete information about driver workarounds
used. If @ref Version::None is passed to the constructor, none of the above
@ -805,6 +809,11 @@ class MAGNUM_GL_EXPORT Shader: public AbstractObject {
/* Used by addSource(Containers::String&&) */
Shader& addSourceInternal(Containers::String&& source);
#if defined(MAGNUM_TARGET_GLES) && !defined(MAGNUM_TARGET_GLES2) && !defined(MAGNUM_TARGET_WEBGL) && !defined(CORRADE_TARGET_APPLE)
static MAGNUM_GL_LOCAL Containers::StringView workaroundDefinesImplementationNoOp(Version version);
static MAGNUM_GL_LOCAL Containers::StringView workaroundDefinesImplementationAdrenoVersion(Version version);
#endif
static void MAGNUM_GL_LOCAL addSourceImplementationDefault(Shader& self, Containers::String&& source);
#if defined(CORRADE_TARGET_EMSCRIPTEN) && defined(__EMSCRIPTEN_PTHREADS__)
static void MAGNUM_GL_LOCAL addSourceImplementationEmscriptenPthread(Shader& self, Containers::String&& source);

2
src/Magnum/Shaders/compatibility.glsl

@ -47,7 +47,7 @@
#if __VERSION__ >= 300
#define EXPLICIT_ATTRIB_LOCATION
#endif
#if __VERSION__ >= 310
#if __VERSION__ >= 310 || (defined(MAGNUM_GLSL_VERSION) && MAGNUM_GLSL_VERSION >= 310)
#define EXPLICIT_BINDING
#define EXPLICIT_UNIFORM_LOCATION
#endif

Loading…
Cancel
Save