tools: Multi-thread remote-compile
Considerably speeds up compilation
Change-Id: Ic7e04938f79989a15da36999fab1b192aca9619c
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/60214
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
diff --git a/tools/src/cmd/remote-compile/main.cc b/tools/src/cmd/remote-compile/main.cc
index 74ed6cb..df541c6 100644
--- a/tools/src/cmd/remote-compile/main.cc
+++ b/tools/src/cmd/remote-compile/main.cc
@@ -20,6 +20,8 @@
#include <type_traits>
#include <vector>
+#include <thread> // NOLINT
+
#include "tools/src/cmd/remote-compile/compile.h"
#include "tools/src/cmd/remote-compile/socket.h"
@@ -350,48 +352,50 @@
}
printf("Listening on port %s...\n", port.c_str());
while (auto conn = server_socket->Accept()) {
- DEBUG("Client connected...");
- Stream stream{conn.get()};
+ std::thread([=] {
+ DEBUG("Client connected...");
+ Stream stream{conn.get()};
- {
- ConnectionRequest req;
- stream >> req;
- if (!stream.error.empty()) {
- printf("%s\n", stream.error.c_str());
- continue;
- }
- ConnectionResponse resp;
- if (req.protocol_version != kProtocolVersion) {
- DEBUG("Protocol version mismatch");
- resp.error = "Protocol version mismatch";
- stream << resp;
- continue;
- }
- stream << resp;
- }
- DEBUG("Connection established");
- {
- CompileRequest req;
- stream >> req;
- if (!stream.error.empty()) {
- printf("%s\n", stream.error.c_str());
- continue;
- }
-#ifdef TINT_ENABLE_MSL_COMPILATION_USING_METAL_API
- if (req.language == SourceLanguage::MSL) {
- auto result = CompileMslUsingMetalAPI(req.source);
- CompileResponse resp;
- if (!result.success) {
- resp.error = result.output;
+ {
+ ConnectionRequest req;
+ stream >> req;
+ if (!stream.error.empty()) {
+ printf("%s\n", stream.error.c_str());
+ return;
+ }
+ ConnectionResponse resp;
+ if (req.protocol_version != kProtocolVersion) {
+ DEBUG("Protocol version mismatch");
+ resp.error = "Protocol version mismatch";
+ stream << resp;
+ return;
}
stream << resp;
- continue;
}
+ DEBUG("Connection established");
+ {
+ CompileRequest req;
+ stream >> req;
+ if (!stream.error.empty()) {
+ printf("%s\n", stream.error.c_str());
+ return;
+ }
+#ifdef TINT_ENABLE_MSL_COMPILATION_USING_METAL_API
+ if (req.language == SourceLanguage::MSL) {
+ auto result = CompileMslUsingMetalAPI(req.source);
+ CompileResponse resp;
+ if (!result.success) {
+ resp.error = result.output;
+ }
+ stream << resp;
+ return;
+ }
#endif
- CompileResponse resp;
- resp.error = "server cannot compile this type of shader";
- stream << resp;
- }
+ CompileResponse resp;
+ resp.error = "server cannot compile this type of shader";
+ stream << resp;
+ }
+ }).detach();
}
return true;
}