Skip to content

Commit

Permalink
Move remote-compile to src/tint/cmd
Browse files Browse the repository at this point in the history
The remote-compile command is moved out of tools and into tint/cmd. The
socket code is moved into tint/utils.

Change-Id: I62502db2cf82ca17b16f05d51c477be4a4b6bdb2
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/147244
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
  • Loading branch information
dj2 authored and Dawn LUCI CQ committed Aug 21, 2023
1 parent d8c693a commit 46bd2e1
Show file tree
Hide file tree
Showing 23 changed files with 248 additions and 187 deletions.
1 change: 1 addition & 0 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ group("all") {
if (dawn_standalone) {
deps += [
"src/dawn/samples",
"src/tint/cmd/remote_compile",
"src/tint/cmd/tint",
]
}
Expand Down
5 changes: 0 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ option_if_not_defined(TINT_BUILD_REGEX_FUZZER "Build regex fuzzer" OFF)
option_if_not_defined(TINT_BUILD_BENCHMARKS "Build Tint benchmarks" OFF)
option_if_not_defined(TINT_BUILD_TESTS "Build tests" ON)
option_if_not_defined(TINT_BUILD_AS_OTHER_OS "Override OS detection to force building of *_other.cc files" OFF)
option_if_not_defined(TINT_BUILD_REMOTE_COMPILE "Build the remote-compile tool for validating shaders on a remote machine" OFF)

set_if_not_defined(TINT_EXTERNAL_BENCHMARK_CORPUS_DIR "" "Directory that holds a corpus of external shaders to benchmark.")

Expand Down Expand Up @@ -323,7 +322,6 @@ message(STATUS "Tint build regex fuzzer: ${TINT_BUILD_REGEX_FUZZER}")
message(STATUS "Tint build benchmarks: ${TINT_BUILD_BENCHMARKS}")
message(STATUS "Tint build tests: ${TINT_BUILD_TESTS}")
message(STATUS "Tint build checking [chromium-style]: ${TINT_CHECK_CHROMIUM_STYLE}")
message(STATUS "Tint build remote-compile tool: ${TINT_BUILD_REMOTE_COMPILE}")
message(STATUS "Tint external benchmark corpus dir: ${TINT_EXTERNAL_BENCHMARK_CORPUS_DIR}")


Expand Down Expand Up @@ -571,6 +569,3 @@ if (DAWN_EMIT_COVERAGE)
VERBATIM)
endif()

if (TINT_BUILD_REMOTE_COMPILE)
add_subdirectory(tools/src/cmd/remote-compile)
endif()
4 changes: 4 additions & 0 deletions src/tint/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ group("abseil") {
}
}

source_set("winsock") {
libs = [ "ws2_32.lib" ]
}

###############################################################################
# Aliases.
###############################################################################
Expand Down
6 changes: 6 additions & 0 deletions src/tint/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,8 @@ function(tint_target_add_external_dependencies UNSUFFIXED_TARGET KIND)
target_link_libraries(${TARGET} PRIVATE
glslang-default-resource-limits
)
elseif(${DEPENDENCY} STREQUAL "winsock")
target_link_libraries(${TARGET} PRIVATE ws2_32)
else()
message(FATAL_ERROR "unhandled external dependency ${DEPENDENCY}")
endif()
Expand Down Expand Up @@ -492,6 +494,9 @@ endfunction()
################################################################################
include("BUILD.cmake")

find_package(Threads REQUIRED)
target_link_libraries(tint_cmd_remote_compile_cmd PRIVATE Threads::Threads)

# If we're building on mac / ios and we have CoreGraphics, then we can use the
# metal API to validate our shaders. This is roughly 4x faster than invoking
# the metal shader compiler executable.
Expand All @@ -500,6 +505,7 @@ if(APPLE AND TINT_BUILD_MSL_WRITER)

if(LIB_CORE_GRAPHICS)
target_sources("tint_lang_msl_validate" PRIVATE "lang/msl/validate/msl_metal.mm")
target_compile_definitions("tint_cmd_remote_compile_cmd" PRIVATE "-DTINT_ENABLE_MSL_VALIDATION_USING_METAL_API=1")
target_compile_definitions("tint_lang_msl_validate" PUBLIC "-DTINT_ENABLE_MSL_VALIDATION_USING_METAL_API=1")
target_compile_options("tint_lang_msl_validate" PRIVATE "-fmodules" "-fcxx-modules")
target_link_options("tint_lang_msl_validate" PUBLIC "-framework" "CoreGraphics")
Expand Down
1 change: 1 addition & 0 deletions src/tint/cmd/BUILD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ include(cmd/bench/BUILD.cmake)
include(cmd/common/BUILD.cmake)
include(cmd/info/BUILD.cmake)
include(cmd/loopy/BUILD.cmake)
include(cmd/remote_compile/BUILD.cmake)
include(cmd/test/BUILD.cmake)
include(cmd/tint/BUILD.cmake)
3 changes: 3 additions & 0 deletions src/tint/cmd/remote_compile/BUILD.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"cmd": { "OutputName": "tint_remote_compile" }
}
45 changes: 45 additions & 0 deletions src/tint/cmd/remote_compile/BUILD.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2023 The Tint Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

################################################################################
# File generated by tools/src/cmd/gen
# using the template:
# tools/src/cmd/gen/build/BUILD.cmake.tmpl
#
# Do not modify this file directly
################################################################################

################################################################################
# Target: tint_cmd_remote_compile_cmd
# Kind: cmd
################################################################################
tint_add_target(tint_cmd_remote_compile_cmd cmd
cmd/remote_compile/main.cc
)

tint_target_add_dependencies(tint_cmd_remote_compile_cmd cmd
tint_lang_wgsl_ast
tint_utils_macros
tint_utils_socket
tint_utils_text
tint_utils_traits
)

if(TINT_BUILD_MSL_WRITER)
tint_target_add_dependencies(tint_cmd_remote_compile_cmd cmd
tint_lang_msl_validate
)
endif(TINT_BUILD_MSL_WRITER)

tint_target_set_output_name(tint_cmd_remote_compile_cmd cmd "tint_remote_compile")
41 changes: 41 additions & 0 deletions src/tint/cmd/remote_compile/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2023 The Tint Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

################################################################################
# File generated by tools/src/cmd/gen
# using the template:
# tools/src/cmd/gen/build/BUILD.gn.tmpl
#
# Do not modify this file directly
################################################################################

import("../../../../scripts/tint_overrides_with_defaults.gni")

import("${tint_src_dir}/tint.gni")

executable("remote_compile") {
output_name = "tint_remote_compile"
sources = [ "main.cc" ]
deps = [
"${tint_src_dir}/lang/wgsl/ast",
"${tint_src_dir}/utils/macros",
"${tint_src_dir}/utils/socket",
"${tint_src_dir}/utils/text",
"${tint_src_dir}/utils/traits",
]

if (tint_build_msl_writer) {
deps += [ "${tint_src_dir}/lang/msl/validate" ]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
#include <type_traits>
#include <vector>

#include "tools/src/cmd/remote-compile/compile.h"
#include "tools/src/cmd/remote-compile/socket.h"
#include "src/tint/lang/msl/validate/val.h"
#include "src/tint/utils/macros/compiler.h"
#include "src/tint/utils/socket/socket.h"

namespace {

Expand All @@ -34,6 +35,14 @@ namespace {
#define DEBUG(...)
#endif

/// The return structure of a compile function
struct CompileResult {
/// True if shader compiled
bool success = false;
/// Output of the compiler
std::string output;
};

/// Print the tool usage, and exit with 1.
[[noreturn]] void ShowUsage() {
const char* name = "tint-remote-compile";
Expand Down Expand Up @@ -214,11 +223,11 @@ struct CompileRequest : Message { // Client -> Server
using Response = CompileResponse;

CompileRequest() : Message(Type::CompileRequest) {}
CompileRequest(SourceLanguage lang, uint32_t ver_major, uint32_t ver_minor, std::string src)
CompileRequest(SourceLanguage lang, int ver_major, int ver_minor, std::string src)
: Message(Type::CompileRequest),
language(lang),
version_major(ver_major),
version_minor(ver_minor),
version_major(uint32_t(ver_major)),
version_minor(uint32_t(ver_minor)),
source(src) {}

template <typename T>
Expand Down Expand Up @@ -284,13 +293,13 @@ bool RunServer(std::string port);
bool RunClient(std::string address,
std::string port,
std::string file,
uint32_t version_major,
uint32_t version_minor);
int version_major,
int version_minor);

int main(int argc, char* argv[]) {
bool run_server = false;
uint32_t version_major = 0;
uint32_t version_minor = 0;
int version_major = 0;
int version_minor = 0;
std::string port = "19000";

std::regex metal_version_re{"^-?-std=macos-metal([0-9]+)\\.([0-9]+)"};
Expand Down Expand Up @@ -347,9 +356,11 @@ int main(int argc, char* argv[]) {
std::string file;
switch (args.size()) {
case 1:
TINT_BEGIN_DISABLE_WARNING(DEPRECATED);
if (auto* addr = getenv("TINT_REMOTE_COMPILE_ADDRESS")) {
address = addr;
}
TINT_END_DISABLE_WARNING(DEPRECATED);
file = args[0];
break;
case 2:
Expand All @@ -360,7 +371,6 @@ int main(int argc, char* argv[]) {
std::cerr << "expected 1 or 2 arguments, got " << args.size() << std::endl
<< std::endl;
ShowUsage();
break;
}
if (address.empty() || file.empty()) {
ShowUsage();
Expand All @@ -385,7 +395,7 @@ bool RunServer(std::string port) {
while (auto conn = server_socket->Accept()) {
std::thread([=] {
DEBUG("Client connected...");
Stream stream{conn.get()};
Stream stream{conn.get(), ""};

{
ConnectionRequest req;
Expand All @@ -411,12 +421,15 @@ bool RunServer(std::string port) {
DEBUG("%s\n", stream.error.c_str());
return;
}
#ifdef TINT_ENABLE_MSL_COMPILATION_USING_METAL_API
#ifdef TINT_ENABLE_MSL_VALIDATION_USING_METAL_API
if (req.language == SourceLanguage::MSL) {
auto result =
CompileMslUsingMetalAPI(req.source, req.version_major, req.version_minor);
auto version = tint::msl::validate::MslVersion::kMsl_1_2;
if (req.version_major == 2 && req.version_minor == 1) {
version = tint::msl::validate::MslVersion::kMsl_2_1;
}
auto result = tint::msl::validate::UsingMetalAPI(req.source, version);
CompileResponse resp;
if (!result.success) {
if (result.failed) {
resp.error = result.output;
}
stream << resp;
Expand All @@ -435,8 +448,8 @@ bool RunServer(std::string port) {
bool RunClient(std::string address,
std::string port,
std::string file,
uint32_t version_major,
uint32_t version_minor) {
int version_major,
int version_minor) {
// Read the file
std::ifstream input(file, std::ios::binary);
if (!input) {
Expand All @@ -453,7 +466,7 @@ bool RunClient(std::string address,
return false;
}

Stream stream{conn.get()};
Stream stream{conn.get(), ""};

DEBUG("Sending connection request...");
auto conn_resp = Send(stream, ConnectionRequest{kProtocolVersion});
Expand Down
2 changes: 1 addition & 1 deletion src/tint/lang/msl/validate/val.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ enum class MslVersion {
struct Result {
/// True if validation passed
bool failed = false;
/// Output of DXC.
/// Output of Metal compiler.
std::string output;
};

Expand Down
1 change: 1 addition & 0 deletions src/tint/utils/BUILD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ include(utils/memory/BUILD.cmake)
include(utils/reflection/BUILD.cmake)
include(utils/result/BUILD.cmake)
include(utils/rtti/BUILD.cmake)
include(utils/socket/BUILD.cmake)
include(utils/strconv/BUILD.cmake)
include(utils/symbol/BUILD.cmake)
include(utils/text/BUILD.cmake)
Expand Down
3 changes: 3 additions & 0 deletions src/tint/utils/macros/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#define TINT_DISABLE_WARNING_UNREACHABLE_CODE __pragma(warning(disable : 4702))
#define TINT_DISABLE_WARNING_WEAK_VTABLES /* currently no-op */
#define TINT_DISABLE_WARNING_FLOAT_EQUAL /* currently no-op */
#define TINT_DISABLE_WARNING_DEPRECATED __pragma(warning(disable : 4996))

// clang-format off
#define TINT_BEGIN_DISABLE_WARNING(name) \
Expand All @@ -57,6 +58,7 @@
#define TINT_DISABLE_WARNING_UNREACHABLE_CODE /* currently no-op */
#define TINT_DISABLE_WARNING_WEAK_VTABLES _Pragma("clang diagnostic ignored \"-Wweak-vtables\"")
#define TINT_DISABLE_WARNING_FLOAT_EQUAL _Pragma("clang diagnostic ignored \"-Wfloat-equal\"")
#define TINT_DISABLE_WARNING_DEPRECATED /* currently no-op */

// clang-format off
#define TINT_BEGIN_DISABLE_WARNING(name) \
Expand All @@ -83,6 +85,7 @@
#define TINT_DISABLE_WARNING_UNREACHABLE_CODE /* currently no-op */
#define TINT_DISABLE_WARNING_WEAK_VTABLES /* currently no-op */
#define TINT_DISABLE_WARNING_FLOAT_EQUAL /* currently no-op */
#define TINT_DISABLE_WARNING_DEPRECATED /* currently no-op */

// clang-format off
#define TINT_BEGIN_DISABLE_WARNING(name) \
Expand Down
37 changes: 37 additions & 0 deletions src/tint/utils/socket/BUILD.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright 2023 The Tint Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

################################################################################
# File generated by tools/src/cmd/gen
# using the template:
# tools/src/cmd/gen/build/BUILD.cmake.tmpl
#
# Do not modify this file directly
################################################################################

################################################################################
# Target: tint_utils_socket
# Kind: lib
################################################################################
tint_add_target(tint_utils_socket lib
utils/socket/rwmutex.h
utils/socket/socket.cc
utils/socket/socket.h
)

if(IS_WIN)
tint_target_add_external_dependencies(tint_utils_socket lib
"winsock"
)
endif(IS_WIN)
Loading

0 comments on commit 46bd2e1

Please sign in to comment.