Browse Source

GL: unconditionally trim shader compilation/linking messages.

Until now it relied on the driver adding a \n after each message. Which
happened in 99% cases, but sometimes not, and it is really annoying in
that case. Right now I witnessed Mesa giving me a non-newlined message
if I call checkLink() and a shader compilation failed before, resulting
in nasty output like

    error: linking with uncompiled/unspecialized shaderAssertion checkLink() failed at /home/mosra/Code/magnum/src/Magnum/Shaders/FlatGL.cpp:248

And I bet I encountered other weird cases, like there being two
newlines, or the message being just a newline without any other content,
thus spamming the output on every compilation. It's not practical to try
to find driver-specific workarounds here, so I'm just trimming always
and then rely on Debug adding its own newline after.
pull/589/head
Vladimír Vondruš 4 years ago
parent
commit
70fc232dbc
  1. 22
      src/Magnum/GL/AbstractShaderProgram.cpp
  2. 23
      src/Magnum/GL/Shader.cpp

22
src/Magnum/GL/AbstractShaderProgram.cpp

@ -31,6 +31,7 @@
#ifndef MAGNUM_TARGET_WEBGL
#include <Corrade/Containers/String.h>
#endif
#include <Corrade/Containers/StringStl.h> /** @todo remove once <string>-free */
#include <Corrade/Containers/Reference.h>
#include <Corrade/Utility/DebugStl.h>
@ -606,17 +607,24 @@ bool AbstractShaderProgram::checkLink() {
be said, handle that as well. */
Context::current().state().shaderProgram.cleanLogImplementation(message);
/* Usually the driver messages contain a newline at the end. But sometimes
not, such as in case of a program link error due to shaders not being
compiled yet on Mesa; sometimes there's two newlines, sometimes just a
newline and nothing else etc. Because trying do this in driver-specific
workarounds would involve an impossible task of checking all possible
error messages on every possible driver, just trim all whitespace around
the message always and let Debug add its own newline. */
const Containers::StringView messageTrimmed = Containers::StringView{message}.trimmed();
/* Show error log */
if(!success) {
Error out{Debug::Flag::NoNewlineAtTheEnd};
out << "GL::AbstractShaderProgram::link(): linking failed with the following message:"
<< Debug::newline << message;
Error{} << "GL::AbstractShaderProgram::link(): linking failed with the following message:"
<< Debug::newline << messageTrimmed;
/* Or just warnings, if any */
} else if(!message.empty()) {
Warning out{Debug::Flag::NoNewlineAtTheEnd};
out << "GL::AbstractShaderProgram::link(): linking succeeded with the following message:"
<< Debug::newline << message;
} else if(messageTrimmed) {
Warning{} << "GL::AbstractShaderProgram::link(): linking succeeded with the following message:"
<< Debug::newline << messageTrimmed;
}
return success;

23
src/Magnum/GL/Shader.cpp

@ -783,17 +783,26 @@ bool Shader::checkCompile() {
be said, handle that as well. */
Context::current().state().shader.cleanLogImplementation(message);
/* Usually the driver messages contain a newline at the end. But sometimes
not, such as in case of a program link error due to shaders not being
compiled yet on Mesa; sometimes there's two newlines, sometimes just a
newline and nothing else etc. Because trying do this in driver-specific
workarounds would involve an impossible task of checking all possible
error messages on every possible driver, just trim all whitespace around
the message always and let Debug add its own newline. */
const Containers::StringView messageTrimmed = Containers::StringView{message}.trimmed();
/* Show error log */
if(!success) {
Error out{Debug::Flag::NoNewlineAtTheEnd};
out << "GL::Shader::compile(): compilation of" << shaderName(_type) << "shader"
<< "failed with the following message:" << Debug::newline << message;
Error{} << "GL::Shader::compile(): compilation of" << shaderName(_type)
<< "shader failed with the following message:" << Debug::newline
<< messageTrimmed;
/* Or just warnings, if any */
} else if(!message.empty()) {
Warning out{Debug::Flag::NoNewlineAtTheEnd};
out << "GL::Shader::compile(): compilation of" << shaderName(_type) << "shader"
<< "succeeded with the following message:" << Debug::newline << message;
} else if(messageTrimmed) {
Warning{} << "GL::Shader::compile(): compilation of" << shaderName(_type)
<< "shader succeeded with the following message:" << Debug::newline
<< messageTrimmed;
}
return success;

Loading…
Cancel
Save