Fix debug annotations and shaders.
The Program refactor inadvertantly broken Debug annotations. Fix this
by correctly passing the path to the temporary shader source in the
first "C" string argument to ShCompile, instead of as the first part
of the source string.
BUG=angleproject:1177
TEST=manual testing with MSVS
Change-Id: Ie77bb11b51645a474b542ddd2ae0f391e019e341
Reviewed-on: https://chromium-review.googlesource.com/306210
Tryjob-Request: Jamie Madill <jmadill@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
diff --git a/src/libANGLE/Shader.cpp b/src/libANGLE/Shader.cpp
index 98fcdca..0b9b4f0 100644
--- a/src/libANGLE/Shader.cpp
+++ b/src/libANGLE/Shader.cpp
@@ -219,7 +219,9 @@
std::stringstream sourceStream;
- int additionalOptions = mImplementation->prepareSourceAndReturnOptions(&sourceStream);
+ std::string sourcePath;
+ int additionalOptions =
+ mImplementation->prepareSourceAndReturnOptions(&sourceStream, &sourcePath);
int compileOptions = (SH_OBJECT_CODE | SH_VARIABLES | additionalOptions);
// Some targets (eg D3D11 Feature Level 9_3 and below) do not support non-constant loop indexes
@@ -231,8 +233,17 @@
}
std::string sourceString = sourceStream.str();
- const char *sourceCString = sourceString.c_str();
- bool result = ShCompile(compilerHandle, &sourceCString, 1, compileOptions);
+ std::vector<const char *> sourceCStrings;
+
+ if (!sourcePath.empty())
+ {
+ sourceCStrings.push_back(sourcePath.c_str());
+ }
+
+ sourceCStrings.push_back(sourceString.c_str());
+
+ bool result =
+ ShCompile(compilerHandle, &sourceCStrings[0], sourceCStrings.size(), compileOptions);
if (!result)
{
diff --git a/src/libANGLE/renderer/ShaderImpl.h b/src/libANGLE/renderer/ShaderImpl.h
index ec164f3..3f2921e 100644
--- a/src/libANGLE/renderer/ShaderImpl.h
+++ b/src/libANGLE/renderer/ShaderImpl.h
@@ -22,7 +22,8 @@
virtual ~ShaderImpl() { }
// Returns additional ShCompile options.
- virtual int prepareSourceAndReturnOptions(std::stringstream *sourceStream) = 0;
+ virtual int prepareSourceAndReturnOptions(std::stringstream *sourceStream,
+ std::string *sourcePath) = 0;
// Returns success for compiling on the driver. Returns success.
virtual bool postTranslateCompile(gl::Compiler *compiler, std::string *infoLog) = 0;
diff --git a/src/libANGLE/renderer/d3d/ShaderD3D.cpp b/src/libANGLE/renderer/d3d/ShaderD3D.cpp
index ade6f9e..c6507aa 100644
--- a/src/libANGLE/renderer/d3d/ShaderD3D.cpp
+++ b/src/libANGLE/renderer/d3d/ShaderD3D.cpp
@@ -117,7 +117,8 @@
return mCompilerOutputType;
}
-int ShaderD3D::prepareSourceAndReturnOptions(std::stringstream *shaderSourceStream)
+int ShaderD3D::prepareSourceAndReturnOptions(std::stringstream *shaderSourceStream,
+ std::string *sourcePath)
{
uncompile();
@@ -128,10 +129,9 @@
#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
if (gl::DebugAnnotationsActive())
{
- std::string sourcePath = getTempPath();
- writeFile(sourcePath.c_str(), source.c_str(), source.length());
+ *sourcePath = getTempPath();
+ writeFile(sourcePath->c_str(), source.c_str(), source.length());
additionalOptions |= SH_LINE_DIRECTIVES | SH_SOURCE_PATH;
- *shaderSourceStream << sourcePath;
}
#endif
diff --git a/src/libANGLE/renderer/d3d/ShaderD3D.h b/src/libANGLE/renderer/d3d/ShaderD3D.h
index f61917a..5a54f24 100644
--- a/src/libANGLE/renderer/d3d/ShaderD3D.h
+++ b/src/libANGLE/renderer/d3d/ShaderD3D.h
@@ -28,7 +28,8 @@
virtual ~ShaderD3D();
// ShaderImpl implementation
- int prepareSourceAndReturnOptions(std::stringstream *sourceStream) override;
+ int prepareSourceAndReturnOptions(std::stringstream *sourceStream,
+ std::string *sourcePath) override;
bool postTranslateCompile(gl::Compiler *compiler, std::string *infoLog) override;
std::string getDebugInfo() const override;
diff --git a/src/libANGLE/renderer/gl/ShaderGL.cpp b/src/libANGLE/renderer/gl/ShaderGL.cpp
index 52efd44..0ab4a44 100644
--- a/src/libANGLE/renderer/gl/ShaderGL.cpp
+++ b/src/libANGLE/renderer/gl/ShaderGL.cpp
@@ -36,7 +36,8 @@
}
}
-int ShaderGL::prepareSourceAndReturnOptions(std::stringstream *sourceStream)
+int ShaderGL::prepareSourceAndReturnOptions(std::stringstream *sourceStream,
+ std::string * /*sourcePath*/)
{
// Reset the previous state
if (mShaderID != 0)
diff --git a/src/libANGLE/renderer/gl/ShaderGL.h b/src/libANGLE/renderer/gl/ShaderGL.h
index c3e0982..76139ac 100644
--- a/src/libANGLE/renderer/gl/ShaderGL.h
+++ b/src/libANGLE/renderer/gl/ShaderGL.h
@@ -25,7 +25,8 @@
~ShaderGL() override;
// ShaderImpl implementation
- int prepareSourceAndReturnOptions(std::stringstream *sourceStream) override;
+ int prepareSourceAndReturnOptions(std::stringstream *sourceStream,
+ std::string *sourcePath) override;
bool postTranslateCompile(gl::Compiler *compiler, std::string *infoLog) override;
std::string getDebugInfo() const override;
diff --git a/src/tests/test_utils/ANGLETest.cpp b/src/tests/test_utils/ANGLETest.cpp
index 4df5349..af124eb 100644
--- a/src/tests/test_utils/ANGLETest.cpp
+++ b/src/tests/test_utils/ANGLETest.cpp
@@ -122,10 +122,17 @@
GLint infoLogLength;
glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &infoLogLength);
- std::vector<GLchar> infoLog(infoLogLength);
- glGetShaderInfoLog(shader, static_cast<GLsizei>(infoLog.size()), NULL, &infoLog[0]);
+ if (infoLogLength == 0)
+ {
+ std::cerr << "shader compilation failed with empty log." << std::endl;
+ }
+ else
+ {
+ std::vector<GLchar> infoLog(infoLogLength);
+ glGetShaderInfoLog(shader, static_cast<GLsizei>(infoLog.size()), NULL, &infoLog[0]);
- std::cerr << "shader compilation failed: " << &infoLog[0];
+ std::cerr << "shader compilation failed: " << &infoLog[0];
+ }
glDeleteShader(shader);
shader = 0;