Consistent formatting for Dawn/Tint.

This CL updates the clang format files to have a single shared format
between Dawn and Tint. The major changes are tabs are 4 spaces, lines
are 100 columns and namespaces are not indented.

Bug: dawn:1339
Change-Id: I4208742c95643998d9fd14e77a9cc558071ded39
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/87603
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
dan sinclair
2022-05-01 14:40:55 +00:00
committed by Dawn LUCI CQ
parent 73b1d1dafa
commit 41e4d9a34c
1827 changed files with 218382 additions and 227741 deletions

View File

@@ -31,93 +31,93 @@ std::filesystem::path kInputFileDir;
/// @returns true if we successfully read the file.
template <typename T>
std::variant<std::vector<T>, Error> ReadFile(const std::string& input_file) {
FILE* file = nullptr;
FILE* file = nullptr;
#if defined(_MSC_VER)
fopen_s(&file, input_file.c_str(), "rb");
fopen_s(&file, input_file.c_str(), "rb");
#else
file = fopen(input_file.c_str(), "rb");
file = fopen(input_file.c_str(), "rb");
#endif
if (!file) {
return Error{"Failed to open " + input_file};
}
if (!file) {
return Error{"Failed to open " + input_file};
}
fseek(file, 0, SEEK_END);
const auto file_size = static_cast<size_t>(ftell(file));
if (0 != (file_size % sizeof(T))) {
std::stringstream err;
err << "File " << input_file
<< " does not contain an integral number of objects: " << file_size
<< " bytes in the file, require " << sizeof(T) << " bytes per object";
fseek(file, 0, SEEK_END);
const auto file_size = static_cast<size_t>(ftell(file));
if (0 != (file_size % sizeof(T))) {
std::stringstream err;
err << "File " << input_file
<< " does not contain an integral number of objects: " << file_size
<< " bytes in the file, require " << sizeof(T) << " bytes per object";
fclose(file);
return Error{err.str()};
}
fseek(file, 0, SEEK_SET);
std::vector<T> buffer;
buffer.resize(file_size / sizeof(T));
size_t bytes_read = fread(buffer.data(), 1, file_size, file);
fclose(file);
return Error{err.str()};
}
fseek(file, 0, SEEK_SET);
if (bytes_read != file_size) {
return Error{"Failed to read " + input_file};
}
std::vector<T> buffer;
buffer.resize(file_size / sizeof(T));
size_t bytes_read = fread(buffer.data(), 1, file_size, file);
fclose(file);
if (bytes_read != file_size) {
return Error{"Failed to read " + input_file};
}
return buffer;
return buffer;
}
bool FindBenchmarkInputDir() {
// Attempt to find the benchmark input files by searching up from the current
// working directory.
auto path = std::filesystem::current_path();
while (std::filesystem::is_directory(path)) {
auto test = path / "test" / "tint" / "benchmark";
if (std::filesystem::is_directory(test)) {
kInputFileDir = test;
return true;
// Attempt to find the benchmark input files by searching up from the current
// working directory.
auto path = std::filesystem::current_path();
while (std::filesystem::is_directory(path)) {
auto test = path / "test" / "tint" / "benchmark";
if (std::filesystem::is_directory(test)) {
kInputFileDir = test;
return true;
}
auto parent = path.parent_path();
if (path == parent) {
break;
}
path = parent;
}
auto parent = path.parent_path();
if (path == parent) {
break;
}
path = parent;
}
return false;
return false;
}
} // namespace
std::variant<tint::Source::File, Error> LoadInputFile(std::string name) {
auto path = (kInputFileDir / name).string();
auto data = ReadFile<uint8_t>(path);
if (auto* buf = std::get_if<std::vector<uint8_t>>(&data)) {
return tint::Source::File(path, std::string(buf->begin(), buf->end()));
}
return std::get<Error>(data);
auto path = (kInputFileDir / name).string();
auto data = ReadFile<uint8_t>(path);
if (auto* buf = std::get_if<std::vector<uint8_t>>(&data)) {
return tint::Source::File(path, std::string(buf->begin(), buf->end()));
}
return std::get<Error>(data);
}
std::variant<ProgramAndFile, Error> LoadProgram(std::string name) {
auto res = bench::LoadInputFile(name);
if (auto err = std::get_if<bench::Error>(&res)) {
return *err;
}
auto& file = std::get<Source::File>(res);
auto program = reader::wgsl::Parse(&file);
if (program.Diagnostics().contains_errors()) {
return Error{program.Diagnostics().str()};
}
return ProgramAndFile{std::move(program), std::move(file)};
auto res = bench::LoadInputFile(name);
if (auto err = std::get_if<bench::Error>(&res)) {
return *err;
}
auto& file = std::get<Source::File>(res);
auto program = reader::wgsl::Parse(&file);
if (program.Diagnostics().contains_errors()) {
return Error{program.Diagnostics().str()};
}
return ProgramAndFile{std::move(program), std::move(file)};
}
} // namespace tint::bench
int main(int argc, char** argv) {
benchmark::Initialize(&argc, argv);
if (benchmark::ReportUnrecognizedArguments(argc, argv)) {
return 1;
}
if (!tint::bench::FindBenchmarkInputDir()) {
std::cerr << "failed to locate benchmark input files" << std::endl;
return 1;
}
benchmark::RunSpecifiedBenchmarks();
benchmark::Initialize(&argc, argv);
if (benchmark::ReportUnrecognizedArguments(argc, argv)) {
return 1;
}
if (!tint::bench::FindBenchmarkInputDir()) {
std::cerr << "failed to locate benchmark input files" << std::endl;
return 1;
}
benchmark::RunSpecifiedBenchmarks();
}

View File

@@ -28,16 +28,16 @@ namespace tint::bench {
/// Error indicates an operation did not complete successfully.
struct Error {
/// The error message.
std::string msg;
/// The error message.
std::string msg;
};
/// ProgramAndFile holds a Program and a Source::File.
struct ProgramAndFile {
/// The tint program parsed from file.
Program program;
/// The source file
Source::File file;
/// The tint program parsed from file.
Program program;
/// The source file
Source::File file;
};
/// LoadInputFile attempts to load a benchmark input file with the given file
@@ -53,24 +53,23 @@ std::variant<Source::File, Error> LoadInputFile(std::string name);
std::variant<ProgramAndFile, Error> LoadProgram(std::string name);
/// Declares a benchmark with the given function and WGSL file name
#define TINT_BENCHMARK_WGSL_PROGRAM(FUNC, WGSL_NAME) \
BENCHMARK_CAPTURE(FUNC, WGSL_NAME, WGSL_NAME);
#define TINT_BENCHMARK_WGSL_PROGRAM(FUNC, WGSL_NAME) BENCHMARK_CAPTURE(FUNC, WGSL_NAME, WGSL_NAME);
/// Declares a set of benchmarks for the given function using a list of WGSL
/// files in `<tint>/test/benchmark`.
#define TINT_BENCHMARK_WGSL_PROGRAMS(FUNC) \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "animometer.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "bloom-vertical-blur.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "cluster-lights.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "empty.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "metaball-isosurface.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "particles.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "shadow-fragment.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "simple-compute.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "simple-fragment.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "simple-vertex.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "skinned-shadowed-pbr-fragment.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "skinned-shadowed-pbr-vertex.wgsl");
#define TINT_BENCHMARK_WGSL_PROGRAMS(FUNC) \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "animometer.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "bloom-vertical-blur.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "cluster-lights.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "empty.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "metaball-isosurface.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "particles.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "shadow-fragment.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "simple-compute.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "simple-fragment.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "simple-vertex.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "skinned-shadowed-pbr-fragment.wgsl"); \
TINT_BENCHMARK_WGSL_PROGRAM(FUNC, "skinned-shadowed-pbr-vertex.wgsl");
} // namespace tint::bench