From ff102f01ed25b80abb770c6c6ef82d877dd508a3 Mon Sep 17 00:00:00 2001 From: Laszlo Agocs Date: Wed, 11 Dec 2019 11:01:06 +0100 Subject: Drop binding qualifiers from samplers in GLSL Enabling GL_ARB_shading_language_420pack (for core-compatible shaders) is not quite ok when the OpenGL implementation (e.g. the one on macOS) does not support this extension. The QRhi OpenGL backend does not rely on bindings for samplers in the first place (and uniform blocks are converted to plain uniforms). So there is no purpose for the binding points in the GLSL code. This fixes operating on macOS with the 4.1 core profile context. (2.1 worked in any case, as this flag and the concept of layout qualifiers are not relevant for <= 120 shaders) Change-Id: Iaec2130aac5fef7c3d8656718bd9ccf418299580 Fixes: QTBUG-80690 Reviewed-by: Johan Helsing --- src/shadertools/qspirvshader.cpp | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/src/shadertools/qspirvshader.cpp b/src/shadertools/qspirvshader.cpp index a8ae0bf..0110bad 100644 --- a/src/shadertools/qspirvshader.cpp +++ b/src/shadertools/qspirvshader.cpp @@ -546,6 +546,10 @@ QByteArray QSpirvShader::translateToGLSL(int version, GlslFlags flags) const // behavior regardless of the GLSL version. spvc_compiler_options_set_bool(options, SPVC_COMPILER_OPTION_GLSL_EMIT_UNIFORM_BUFFER_AS_PLAIN_UNIFORMS, true); + // Do not emit binding qualifiers for samplers (and for uniform blocks, but + // those we just disabled above). + spvc_compiler_options_set_bool(options, SPVC_COMPILER_OPTION_GLSL_ENABLE_420PACK_EXTENSION, + false); spvc_compiler_install_compiler_options(d->glslGen, options); const char *result = nullptr; @@ -554,19 +558,10 @@ QByteArray QSpirvShader::translateToGLSL(int version, GlslFlags flags) const return QByteArray(); } - QByteArray src(result); - - // Fix it up by adding #extension GL_ARB_separate_shader_objects : require - // as well in order to make Mesa and perhaps others happy. - const QByteArray searchStr = QByteArrayLiteral("#extension GL_ARB_shading_language_420pack : require\n#endif\n"); - int pos = src.indexOf(searchStr); - if (pos >= 0) { - src.insert(pos + searchStr.count(), QByteArrayLiteral("#ifdef GL_ARB_separate_shader_objects\n" - "#extension GL_ARB_separate_shader_objects : require\n" - "#endif\n")); - } - - return src; + // We used to fix up the result to complement GL_ARB_shading_language_420pack + // with GL_ARB_separate_shader_objects to make Mesa happy, but the 420pack + // is never relied on now so no need to do anything here. + return result; } QByteArray QSpirvShader::translateToHLSL(int version) const -- cgit v1.2.3