Commit 6d51f262 by Austin Kinross Committed by Jamie Madill

Compile the D3D11 VS and PS on separate threads at GL link time

BUG=angle:900 Change-Id: Iad5dbbcc676e2a2b6dfc3d7bc6ab5957154de33e Reviewed-on: https://chromium-review.googlesource.com/240490Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarAustin Kinross <aukinros@microsoft.com>
parent c3b9b26a
...@@ -43,3 +43,22 @@ std::string FormatString(const char *fmt, ...) ...@@ -43,3 +43,22 @@ std::string FormatString(const char *fmt, ...)
va_end(vararg); va_end(vararg);
return result; return result;
} }
// The D3D11 renderer compiles the pixel and vertex shaders on different threads.
// That code needs to format strings, so we need thread-safe helpers.
std::string FormatStringThreadSafe(const char *fmt, va_list vararg)
{
std::vector<char> buffer(512);
size_t len = FormatStringIntoVector(fmt, vararg, buffer);
return std::string(&buffer[0], len);
}
std::string FormatStringThreadSafe(const char *fmt, ...)
{
va_list vararg;
va_start(vararg, fmt);
std::string result = FormatStringThreadSafe(fmt, vararg);
va_end(vararg);
return result;
}
\ No newline at end of file
...@@ -146,6 +146,8 @@ size_t FormatStringIntoVector(const char *fmt, va_list vararg, std::vector<char> ...@@ -146,6 +146,8 @@ size_t FormatStringIntoVector(const char *fmt, va_list vararg, std::vector<char>
std::string FormatString(const char *fmt, va_list vararg); std::string FormatString(const char *fmt, va_list vararg);
std::string FormatString(const char *fmt, ...); std::string FormatString(const char *fmt, ...);
std::string FormatStringThreadSafe(const char *fmt, va_list vararg);
std::string FormatStringThreadSafe(const char *fmt, ...);
// snprintf is not defined with MSVC prior to to msvc14 // snprintf is not defined with MSVC prior to to msvc14
#if defined(_MSC_VER) && _MSC_VER < 1900 #if defined(_MSC_VER) && _MSC_VER < 1900
......
...@@ -29,7 +29,9 @@ Error::Error(GLenum errorCode, const char *msg, ...) ...@@ -29,7 +29,9 @@ Error::Error(GLenum errorCode, const char *msg, ...)
va_list vararg; va_list vararg;
va_start(vararg, msg); va_start(vararg, msg);
createMessageString(); createMessageString();
*mMessage = FormatString(msg, vararg);
// gl::Errors can be created across multiple threads, so we must make sure they're thread safe.
*mMessage = FormatStringThreadSafe(msg, vararg);
va_end(vararg); va_end(vararg);
} }
...@@ -98,7 +100,7 @@ Error::Error(EGLint errorCode, const char *msg, ...) ...@@ -98,7 +100,7 @@ Error::Error(EGLint errorCode, const char *msg, ...)
va_list vararg; va_list vararg;
va_start(vararg, msg); va_start(vararg, msg);
createMessageString(); createMessageString();
*mMessage = FormatString(msg, vararg); *mMessage = FormatStringThreadSafe(msg, vararg);
va_end(vararg); va_end(vararg);
} }
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include "libANGLE/renderer/d3d/ShaderExecutableD3D.h" #include "libANGLE/renderer/d3d/ShaderExecutableD3D.h"
#include "libANGLE/renderer/d3d/VertexDataManager.h" #include "libANGLE/renderer/d3d/VertexDataManager.h"
#include <future> // For std::async
namespace rx namespace rx
{ {
...@@ -955,6 +957,7 @@ gl::Error ProgramD3D::getVertexExecutableForInputLayout(const gl::VertexFormat i ...@@ -955,6 +957,7 @@ gl::Error ProgramD3D::getVertexExecutableForInputLayout(const gl::VertexFormat i
} }
else if (!infoLog) else if (!infoLog)
{ {
// This isn't thread-safe, so we should ensure that we always pass in an infoLog if using multiple threads.
std::vector<char> tempCharBuffer(tempInfoLog.getLength() + 3); std::vector<char> tempCharBuffer(tempInfoLog.getLength() + 3);
tempInfoLog.getLog(tempInfoLog.getLength(), NULL, &tempCharBuffer[0]); tempInfoLog.getLog(tempInfoLog.getLength(), NULL, &tempCharBuffer[0]);
ERR("Error compiling dynamic vertex executable:\n%s\n", &tempCharBuffer[0]); ERR("Error compiling dynamic vertex executable:\n%s\n", &tempCharBuffer[0]);
...@@ -970,18 +973,38 @@ LinkResult ProgramD3D::compileProgramExecutables(gl::InfoLog &infoLog, gl::Shade ...@@ -970,18 +973,38 @@ LinkResult ProgramD3D::compileProgramExecutables(gl::InfoLog &infoLog, gl::Shade
ShaderD3D *vertexShaderD3D = ShaderD3D::makeShaderD3D(vertexShader->getImplementation()); ShaderD3D *vertexShaderD3D = ShaderD3D::makeShaderD3D(vertexShader->getImplementation());
ShaderD3D *fragmentShaderD3D = ShaderD3D::makeShaderD3D(fragmentShader->getImplementation()); ShaderD3D *fragmentShaderD3D = ShaderD3D::makeShaderD3D(fragmentShader->getImplementation());
gl::VertexFormat defaultInputLayout[gl::MAX_VERTEX_ATTRIBS]; gl::Error vertexShaderTaskResult(GL_NO_ERROR);
GetDefaultInputLayoutFromShader(vertexShader->getActiveAttributes(), defaultInputLayout); gl::InfoLog tempVertexShaderInfoLog;
ShaderExecutableD3D *defaultVertexExecutable = NULL;
gl::Error error = getVertexExecutableForInputLayout(defaultInputLayout, &defaultVertexExecutable, &infoLog); std::future<ShaderExecutableD3D*> vertexShaderTask = std::async([this, vertexShader, &tempVertexShaderInfoLog, &vertexShaderTaskResult]()
if (error.isError())
{ {
return LinkResult(false, error); gl::VertexFormat defaultInputLayout[gl::MAX_VERTEX_ATTRIBS];
} GetDefaultInputLayoutFromShader(vertexShader->getActiveAttributes(), defaultInputLayout);
ShaderExecutableD3D *defaultVertexExecutable = NULL;
vertexShaderTaskResult = getVertexExecutableForInputLayout(defaultInputLayout, &defaultVertexExecutable, &tempVertexShaderInfoLog);
return defaultVertexExecutable;
});
std::vector<GLenum> defaultPixelOutput = GetDefaultOutputLayoutFromShader(getPixelShaderKey()); std::vector<GLenum> defaultPixelOutput = GetDefaultOutputLayoutFromShader(getPixelShaderKey());
ShaderExecutableD3D *defaultPixelExecutable = NULL; ShaderExecutableD3D *defaultPixelExecutable = NULL;
error = getPixelExecutableForOutputLayout(defaultPixelOutput, &defaultPixelExecutable, &infoLog); gl::Error error = getPixelExecutableForOutputLayout(defaultPixelOutput, &defaultPixelExecutable, &infoLog);
ShaderExecutableD3D *defaultVertexExecutable = vertexShaderTask.get();
// Combine the temporary infoLog with the real one
if (tempVertexShaderInfoLog.getLength() > 0)
{
std::vector<char> tempCharBuffer(tempVertexShaderInfoLog.getLength() + 3);
tempVertexShaderInfoLog.getLog(tempVertexShaderInfoLog.getLength(), NULL, &tempCharBuffer[0]);
infoLog.append(&tempCharBuffer[0]);
}
if (vertexShaderTaskResult.isError())
{
return LinkResult(false, vertexShaderTaskResult);
}
// If the pixel shader compilation failed, then return error
if (error.isError()) if (error.isError())
{ {
return LinkResult(false, error); return LinkResult(false, error);
......
...@@ -2659,7 +2659,7 @@ gl::Error Renderer11::compileToExecutable(gl::InfoLog &infoLog, const std::strin ...@@ -2659,7 +2659,7 @@ gl::Error Renderer11::compileToExecutable(gl::InfoLog &infoLog, const std::strin
return gl::Error(GL_INVALID_OPERATION); return gl::Error(GL_INVALID_OPERATION);
} }
std::string profile = FormatString("%s_%d_%d%s", profileType, getMajorShaderModel(), getMinorShaderModel(), getShaderModelSuffix().c_str()); std::string profile = FormatStringThreadSafe("%s_%d_%d%s", profileType, getMajorShaderModel(), getMinorShaderModel(), getShaderModelSuffix().c_str());
UINT flags = D3DCOMPILE_OPTIMIZATION_LEVEL2; UINT flags = D3DCOMPILE_OPTIMIZATION_LEVEL2;
......
...@@ -2678,7 +2678,7 @@ gl::Error Renderer9::compileToExecutable(gl::InfoLog &infoLog, const std::string ...@@ -2678,7 +2678,7 @@ gl::Error Renderer9::compileToExecutable(gl::InfoLog &infoLog, const std::string
} }
unsigned int profileMajorVersion = (getMajorShaderModel() >= 3) ? 3 : 2; unsigned int profileMajorVersion = (getMajorShaderModel() >= 3) ? 3 : 2;
unsigned int profileMinorVersion = 0; unsigned int profileMinorVersion = 0;
std::string profile = FormatString("%s_%u_%u", profileType, profileMajorVersion, profileMinorVersion); std::string profile = FormatStringThreadSafe("%s_%u_%u", profileType, profileMajorVersion, profileMinorVersion);
UINT flags = ANGLE_COMPILE_OPTIMIZATION_LEVEL; UINT flags = ANGLE_COMPILE_OPTIMIZATION_LEVEL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment