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>
This commit is contained in:
Ben Clayton 2021-07-30 16:02:26 +00:00 committed by Tint LUCI CQ
parent 38c5a28efd
commit 33c997b829
1 changed files with 41 additions and 37 deletions

View File

@ -20,6 +20,8 @@
#include <type_traits> #include <type_traits>
#include <vector> #include <vector>
#include <thread> // NOLINT
#include "tools/src/cmd/remote-compile/compile.h" #include "tools/src/cmd/remote-compile/compile.h"
#include "tools/src/cmd/remote-compile/socket.h" #include "tools/src/cmd/remote-compile/socket.h"
@ -350,6 +352,7 @@ bool RunServer(std::string port) {
} }
printf("Listening on port %s...\n", port.c_str()); printf("Listening on port %s...\n", port.c_str());
while (auto conn = server_socket->Accept()) { while (auto conn = server_socket->Accept()) {
std::thread([=] {
DEBUG("Client connected..."); DEBUG("Client connected...");
Stream stream{conn.get()}; Stream stream{conn.get()};
@ -358,14 +361,14 @@ bool RunServer(std::string port) {
stream >> req; stream >> req;
if (!stream.error.empty()) { if (!stream.error.empty()) {
printf("%s\n", stream.error.c_str()); printf("%s\n", stream.error.c_str());
continue; return;
} }
ConnectionResponse resp; ConnectionResponse resp;
if (req.protocol_version != kProtocolVersion) { if (req.protocol_version != kProtocolVersion) {
DEBUG("Protocol version mismatch"); DEBUG("Protocol version mismatch");
resp.error = "Protocol version mismatch"; resp.error = "Protocol version mismatch";
stream << resp; stream << resp;
continue; return;
} }
stream << resp; stream << resp;
} }
@ -375,7 +378,7 @@ bool RunServer(std::string port) {
stream >> req; stream >> req;
if (!stream.error.empty()) { if (!stream.error.empty()) {
printf("%s\n", stream.error.c_str()); printf("%s\n", stream.error.c_str());
continue; return;
} }
#ifdef TINT_ENABLE_MSL_COMPILATION_USING_METAL_API #ifdef TINT_ENABLE_MSL_COMPILATION_USING_METAL_API
if (req.language == SourceLanguage::MSL) { if (req.language == SourceLanguage::MSL) {
@ -385,13 +388,14 @@ bool RunServer(std::string port) {
resp.error = result.output; resp.error = result.output;
} }
stream << resp; stream << resp;
continue; return;
} }
#endif #endif
CompileResponse resp; CompileResponse resp;
resp.error = "server cannot compile this type of shader"; resp.error = "server cannot compile this type of shader";
stream << resp; stream << resp;
} }
}).detach();
} }
return true; return true;
} }