ParallelCompile: Parallelize D3D linking
This adds a new linking state to Program. If a Program is in linking
state, on the one hand the foreground thread may continue issuing more
GL calls, and on the other hand the background linking threads may be
accessing Program internally too. Without a proper constraint there
must be conflicts between them. For this purpose, we block any further
GL calls to Program until it's actually linked. In addition, we
prohibit parallel linking an active program, so that ProgramD3D does
not have to worry about such similar conflicts.
Also changes the WorkerThread to support limiting the number of
concurrently running worker threads.
BUG=chromium:849576
Change-Id: I52618647539323f8bf27201320bdf7301c4982e6
Reviewed-on: https://chromium-review.googlesource.com/1127495
Commit-Queue: Jie A Chen <jie.a.chen@intel.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/util/shader_utils.cpp b/util/shader_utils.cpp
index d425077..e4cdaa5 100644
--- a/util/shader_utils.cpp
+++ b/util/shader_utils.cpp
@@ -126,12 +126,11 @@
transformFeedbackVaryings, bufferMode);
}
-GLuint CompileProgramWithGSAndTransformFeedback(
- const std::string &vsSource,
- const std::string &gsSource,
- const std::string &fsSource,
- const std::vector<std::string> &transformFeedbackVaryings,
- GLenum bufferMode)
+static GLuint CompileAndLinkProgram(const std::string &vsSource,
+ const std::string &gsSource,
+ const std::string &fsSource,
+ const std::vector<std::string> &transformFeedbackVaryings,
+ GLenum bufferMode)
{
GLuint program = glCreateProgram();
@@ -182,6 +181,22 @@
glLinkProgram(program);
+ return program;
+}
+
+GLuint CompileProgramWithGSAndTransformFeedback(
+ const std::string &vsSource,
+ const std::string &gsSource,
+ const std::string &fsSource,
+ const std::vector<std::string> &transformFeedbackVaryings,
+ GLenum bufferMode)
+{
+ GLuint program =
+ CompileAndLinkProgram(vsSource, gsSource, fsSource, transformFeedbackVaryings, bufferMode);
+ if (program == 0)
+ {
+ return 0;
+ }
return CheckLinkStatusAndReturnProgram(program, true);
}
@@ -190,6 +205,12 @@
return CompileProgramWithGS(vsSource, "", fsSource);
}
+GLuint CompileProgramParallel(const std::string &vsSource, const std::string &fsSource)
+{
+ std::vector<std::string> emptyVector;
+ return CompileAndLinkProgram(vsSource, "", fsSource, emptyVector, GL_NONE);
+}
+
GLuint CompileProgramWithGS(const std::string &vsSource,
const std::string &gsSource,
const std::string &fsSource)