[tint][bench]: Fix MSL benchmarks
These required binding point remapping so that the @group is always zero. Also: Use a unique_ptr for the file in ProgramAndFile. Previously the diagnostics were referring to the std::moved file, causing segfaults if the benchmark program errors and printed diagnostics. Change-Id: Id0e41665b97b3fc73a6cdd5848c5f505cd77e805 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/134280 Kokoro: Ben Clayton <bclayton@google.com> Reviewed-by: Dan Sinclair <dsinclair@chromium.org> Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
parent
4b35f52f9b
commit
ad22d567e5
|
@ -120,8 +120,8 @@ std::variant<ProgramAndFile, Error> LoadProgram(std::string name) {
|
||||||
if (auto err = std::get_if<bench::Error>(&res)) {
|
if (auto err = std::get_if<bench::Error>(&res)) {
|
||||||
return *err;
|
return *err;
|
||||||
}
|
}
|
||||||
auto& file = std::get<Source::File>(res);
|
auto file = std::make_unique<Source::File>(std::move(std::get<Source::File>(res)));
|
||||||
auto program = reader::wgsl::Parse(&file);
|
auto program = reader::wgsl::Parse(file.get());
|
||||||
if (program.Diagnostics().contains_errors()) {
|
if (program.Diagnostics().contains_errors()) {
|
||||||
return Error{program.Diagnostics().str()};
|
return Error{program.Diagnostics().str()};
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ struct ProgramAndFile {
|
||||||
/// The tint program parsed from file.
|
/// The tint program parsed from file.
|
||||||
Program program;
|
Program program;
|
||||||
/// The source file
|
/// The source file
|
||||||
Source::File file;
|
std::unique_ptr<Source::File> file;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// LoadInputFile attempts to load a benchmark input file with the given file
|
/// LoadInputFile attempts to load a benchmark input file with the given file
|
||||||
|
|
|
@ -14,7 +14,9 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
#include "src/tint/ast/module.h"
|
||||||
#include "src/tint/bench/benchmark.h"
|
#include "src/tint/bench/benchmark.h"
|
||||||
|
#include "src/tint/sem/variable.h"
|
||||||
|
|
||||||
namespace tint::writer::msl {
|
namespace tint::writer::msl {
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -26,26 +28,38 @@ void GenerateMSL(benchmark::State& state, std::string input_name) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto& program = std::get<bench::ProgramAndFile>(res).program;
|
auto& program = std::get<bench::ProgramAndFile>(res).program;
|
||||||
for (auto _ : state) {
|
|
||||||
tint::writer::msl::Options gen_options = {};
|
|
||||||
gen_options.array_length_from_uniform.ubo_binding = tint::writer::BindingPoint{0, 30};
|
|
||||||
gen_options.array_length_from_uniform.bindpoint_to_size_index.emplace(
|
|
||||||
tint::writer::BindingPoint{0, 0}, 0);
|
|
||||||
gen_options.array_length_from_uniform.bindpoint_to_size_index.emplace(
|
|
||||||
tint::writer::BindingPoint{0, 1}, 1);
|
|
||||||
gen_options.array_length_from_uniform.bindpoint_to_size_index.emplace(
|
|
||||||
tint::writer::BindingPoint{0, 2}, 2);
|
|
||||||
gen_options.array_length_from_uniform.bindpoint_to_size_index.emplace(
|
|
||||||
tint::writer::BindingPoint{0, 3}, 3);
|
|
||||||
gen_options.array_length_from_uniform.bindpoint_to_size_index.emplace(
|
|
||||||
tint::writer::BindingPoint{0, 4}, 4);
|
|
||||||
gen_options.array_length_from_uniform.bindpoint_to_size_index.emplace(
|
|
||||||
tint::writer::BindingPoint{0, 5}, 5);
|
|
||||||
gen_options.array_length_from_uniform.bindpoint_to_size_index.emplace(
|
|
||||||
tint::writer::BindingPoint{0, 6}, 6);
|
|
||||||
gen_options.array_length_from_uniform.bindpoint_to_size_index.emplace(
|
|
||||||
tint::writer::BindingPoint{0, 7}, 7);
|
|
||||||
|
|
||||||
|
tint::writer::msl::Options gen_options = {};
|
||||||
|
gen_options.array_length_from_uniform.ubo_binding = tint::writer::BindingPoint{0, 30};
|
||||||
|
gen_options.array_length_from_uniform.bindpoint_to_size_index.emplace(
|
||||||
|
tint::writer::BindingPoint{0, 0}, 0);
|
||||||
|
gen_options.array_length_from_uniform.bindpoint_to_size_index.emplace(
|
||||||
|
tint::writer::BindingPoint{0, 1}, 1);
|
||||||
|
gen_options.array_length_from_uniform.bindpoint_to_size_index.emplace(
|
||||||
|
tint::writer::BindingPoint{0, 2}, 2);
|
||||||
|
gen_options.array_length_from_uniform.bindpoint_to_size_index.emplace(
|
||||||
|
tint::writer::BindingPoint{0, 3}, 3);
|
||||||
|
gen_options.array_length_from_uniform.bindpoint_to_size_index.emplace(
|
||||||
|
tint::writer::BindingPoint{0, 4}, 4);
|
||||||
|
gen_options.array_length_from_uniform.bindpoint_to_size_index.emplace(
|
||||||
|
tint::writer::BindingPoint{0, 5}, 5);
|
||||||
|
gen_options.array_length_from_uniform.bindpoint_to_size_index.emplace(
|
||||||
|
tint::writer::BindingPoint{0, 6}, 6);
|
||||||
|
gen_options.array_length_from_uniform.bindpoint_to_size_index.emplace(
|
||||||
|
tint::writer::BindingPoint{0, 7}, 7);
|
||||||
|
|
||||||
|
uint32_t next_binding_point = 0;
|
||||||
|
for (auto* var : program.AST().GlobalVariables()) {
|
||||||
|
if (auto* var_sem = program.Sem().Get(var)->As<sem::GlobalVariable>()) {
|
||||||
|
if (auto bp = var_sem->BindingPoint()) {
|
||||||
|
gen_options.binding_remapper_options.binding_points[*bp] = sem::BindingPoint{
|
||||||
|
0, // group
|
||||||
|
next_binding_point++, // binding
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (auto _ : state) {
|
||||||
auto res = Generate(&program, gen_options);
|
auto res = Generate(&program, gen_options);
|
||||||
if (!res.error.empty()) {
|
if (!res.error.empty()) {
|
||||||
state.SkipWithError(res.error.c_str());
|
state.SkipWithError(res.error.c_str());
|
||||||
|
|
Loading…
Reference in New Issue