2021-01-12 16:23:48 +00:00
|
|
|
// Copyright 2021 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.
|
|
|
|
|
|
|
|
#include "fuzzers/tint_common_fuzzer.h"
|
|
|
|
|
2021-09-22 14:37:46 +00:00
|
|
|
#include <cassert>
|
2021-06-07 08:07:11 +00:00
|
|
|
#include <cstring>
|
2021-08-05 15:52:58 +00:00
|
|
|
#include <fstream>
|
2021-01-12 16:23:48 +00:00
|
|
|
#include <memory>
|
2021-07-08 22:11:09 +00:00
|
|
|
#include <sstream>
|
2021-01-12 16:23:48 +00:00
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
|
2021-07-08 22:11:09 +00:00
|
|
|
#if TINT_BUILD_SPV_READER
|
|
|
|
#include "spirv-tools/libspirv.hpp"
|
|
|
|
#endif // TINT_BUILD_SPV_READER
|
|
|
|
|
2021-01-26 16:57:10 +00:00
|
|
|
#include "src/ast/module.h"
|
2021-06-24 18:10:46 +00:00
|
|
|
#include "src/diagnostic/formatter.h"
|
2021-01-26 16:57:10 +00:00
|
|
|
#include "src/program.h"
|
2021-08-05 15:52:58 +00:00
|
|
|
#include "src/utils/hash.h"
|
2021-01-26 16:57:10 +00:00
|
|
|
|
2021-01-12 16:23:48 +00:00
|
|
|
namespace tint {
|
|
|
|
namespace fuzzers {
|
|
|
|
|
2021-05-06 15:43:33 +00:00
|
|
|
namespace {
|
|
|
|
|
2021-07-08 22:11:09 +00:00
|
|
|
[[noreturn]] void FatalError(const tint::diag::List& diags,
|
2021-07-16 09:25:14 +00:00
|
|
|
const std::string& msg = "") {
|
2021-03-25 11:40:07 +00:00
|
|
|
auto printer = tint::diag::Printer::create(stderr, true);
|
2021-07-16 09:25:14 +00:00
|
|
|
if (!msg.empty()) {
|
|
|
|
printer->write(msg + "\n", {diag::Color::kRed, true});
|
2021-07-08 22:11:09 +00:00
|
|
|
}
|
|
|
|
tint::diag::Formatter().format(diags, printer.get());
|
2021-03-25 11:40:07 +00:00
|
|
|
__builtin_trap();
|
|
|
|
}
|
|
|
|
|
2021-07-08 22:11:09 +00:00
|
|
|
[[noreturn]] void TintInternalCompilerErrorReporter(
|
|
|
|
const tint::diag::List& diagnostics) {
|
|
|
|
FatalError(diagnostics);
|
2021-05-05 21:12:22 +00:00
|
|
|
}
|
|
|
|
|
2021-09-22 14:37:46 +00:00
|
|
|
transform::VertexAttributeDescriptor GenerateVertexAttributeDescriptor(
|
|
|
|
DataBuilder* b) {
|
2021-07-16 09:25:14 +00:00
|
|
|
transform::VertexAttributeDescriptor desc{};
|
2021-09-22 14:37:46 +00:00
|
|
|
desc.format = b->enum_class<transform::VertexFormat>(
|
2021-05-06 15:43:33 +00:00
|
|
|
static_cast<uint8_t>(transform::VertexFormat::kLastEntry) + 1);
|
2021-09-22 14:37:46 +00:00
|
|
|
desc.offset = b->build<uint32_t>();
|
|
|
|
desc.shader_location = b->build<uint32_t>();
|
2021-05-06 15:43:33 +00:00
|
|
|
return desc;
|
|
|
|
}
|
|
|
|
|
2021-09-22 14:37:46 +00:00
|
|
|
transform::VertexBufferLayoutDescriptor GenerateVertexBufferLayoutDescriptor(
|
|
|
|
DataBuilder* b) {
|
2021-05-06 15:43:33 +00:00
|
|
|
transform::VertexBufferLayoutDescriptor desc;
|
2021-09-22 14:37:46 +00:00
|
|
|
desc.array_stride = b->build<uint32_t>();
|
|
|
|
desc.step_mode = b->enum_class<transform::VertexStepMode>(
|
2021-07-27 07:33:19 +00:00
|
|
|
static_cast<uint8_t>(transform::VertexStepMode::kLastEntry) + 1);
|
2021-09-22 14:37:46 +00:00
|
|
|
desc.attributes = b->vector(GenerateVertexAttributeDescriptor);
|
2021-05-06 15:43:33 +00:00
|
|
|
return desc;
|
|
|
|
}
|
2021-04-28 15:35:43 +00:00
|
|
|
|
2021-07-08 22:11:09 +00:00
|
|
|
bool SPIRVToolsValidationCheck(const tint::Program& program,
|
2021-07-16 09:25:14 +00:00
|
|
|
const std::vector<uint32_t>& spirv) {
|
2021-07-08 22:11:09 +00:00
|
|
|
spvtools::SpirvTools tools(SPV_ENV_VULKAN_1_1);
|
|
|
|
const tint::diag::List& diags = program.Diagnostics();
|
|
|
|
tools.SetMessageConsumer([diags](spv_message_level_t, const char*,
|
|
|
|
const spv_position_t& pos, const char* msg) {
|
|
|
|
std::stringstream out;
|
|
|
|
out << "Unexpected spirv-val error:\n"
|
|
|
|
<< (pos.line + 1) << ":" << (pos.column + 1) << ": " << msg
|
|
|
|
<< std::endl;
|
|
|
|
|
|
|
|
auto printer = tint::diag::Printer::create(stderr, true);
|
|
|
|
printer->write(out.str(), {diag::Color::kYellow, false});
|
|
|
|
tint::diag::Formatter().format(diags, printer.get());
|
|
|
|
});
|
|
|
|
|
|
|
|
return tools.Validate(spirv.data(), spirv.size(),
|
|
|
|
spvtools::ValidatorOptions());
|
|
|
|
}
|
|
|
|
|
2021-05-06 15:43:33 +00:00
|
|
|
} // namespace
|
2021-04-28 15:35:43 +00:00
|
|
|
|
2021-09-22 14:37:46 +00:00
|
|
|
DataBuilder::DataBuilder(const uint8_t* data, size_t size)
|
|
|
|
: generator_(RandomGenerator::CalculateSeed(data, size)) {}
|
2021-04-28 15:35:43 +00:00
|
|
|
|
2021-09-22 14:37:46 +00:00
|
|
|
std::string DataBuilder::string() {
|
|
|
|
auto count = build<uint8_t>();
|
|
|
|
if (count == 0) {
|
2021-05-06 15:43:33 +00:00
|
|
|
return "";
|
2021-04-28 15:35:43 +00:00
|
|
|
}
|
2021-09-22 14:37:46 +00:00
|
|
|
std::vector<uint8_t> source(count);
|
|
|
|
build(source.data(), count);
|
|
|
|
return std::string(source.begin(), source.end());
|
2021-05-06 15:43:33 +00:00
|
|
|
}
|
2021-04-28 15:35:43 +00:00
|
|
|
|
2021-09-22 14:37:46 +00:00
|
|
|
void DataBuilder::build(void* out, size_t n) {
|
|
|
|
assert(out != nullptr && "|out| cannot be nullptr");
|
|
|
|
assert(n > 0 && "|n| must be > 0");
|
2021-04-28 15:35:43 +00:00
|
|
|
|
2021-09-22 14:37:46 +00:00
|
|
|
generator_.GetNBytes(reinterpret_cast<uint8_t*>(out), n);
|
2021-05-06 15:43:33 +00:00
|
|
|
}
|
2021-04-28 15:35:43 +00:00
|
|
|
|
2021-09-22 14:37:46 +00:00
|
|
|
void GenerateBindingRemapperInputs(DataBuilder* b,
|
|
|
|
tint::transform::DataMap* inputs) {
|
2021-05-06 15:43:33 +00:00
|
|
|
struct Config {
|
|
|
|
uint8_t old_group;
|
|
|
|
uint8_t old_binding;
|
|
|
|
uint8_t new_group;
|
|
|
|
uint8_t new_binding;
|
2021-06-04 20:41:47 +00:00
|
|
|
ast::Access new_access;
|
2021-05-06 15:43:33 +00:00
|
|
|
};
|
2021-04-28 15:35:43 +00:00
|
|
|
|
2021-09-22 14:37:46 +00:00
|
|
|
std::vector<Config> configs = b->vector<Config>();
|
2021-04-28 15:35:43 +00:00
|
|
|
transform::BindingRemapper::BindingPoints binding_points;
|
2021-06-07 08:07:11 +00:00
|
|
|
transform::BindingRemapper::AccessControls accesses;
|
2021-04-28 15:35:43 +00:00
|
|
|
for (const auto& config : configs) {
|
|
|
|
binding_points[{config.old_binding, config.old_group}] = {
|
|
|
|
config.new_binding, config.new_group};
|
2021-06-07 08:07:11 +00:00
|
|
|
accesses[{config.old_binding, config.old_group}] = config.new_access;
|
2021-04-28 15:35:43 +00:00
|
|
|
}
|
|
|
|
|
2021-06-07 08:07:11 +00:00
|
|
|
inputs->Add<transform::BindingRemapper::Remappings>(binding_points, accesses);
|
2021-04-28 15:35:43 +00:00
|
|
|
}
|
|
|
|
|
2021-09-22 14:37:46 +00:00
|
|
|
void GenerateFirstIndexOffsetInputs(DataBuilder* b,
|
|
|
|
tint::transform::DataMap* inputs) {
|
2021-04-28 15:35:43 +00:00
|
|
|
struct Config {
|
|
|
|
uint32_t group;
|
|
|
|
uint32_t binding;
|
|
|
|
};
|
|
|
|
|
2021-09-22 14:37:46 +00:00
|
|
|
Config config = b->build<Config>();
|
2021-04-28 15:35:43 +00:00
|
|
|
inputs->Add<tint::transform::FirstIndexOffset::BindingPoint>(config.binding,
|
|
|
|
config.group);
|
|
|
|
}
|
|
|
|
|
2021-09-22 14:37:46 +00:00
|
|
|
void GenerateSingleEntryPointInputs(DataBuilder* b,
|
|
|
|
tint::transform::DataMap* inputs) {
|
|
|
|
std::string input = b->string();
|
2021-04-29 20:49:25 +00:00
|
|
|
transform::SingleEntryPoint::Config cfg(input);
|
|
|
|
inputs->Add<transform::SingleEntryPoint::Config>(cfg);
|
2021-05-06 15:43:33 +00:00
|
|
|
}
|
2021-04-29 20:49:25 +00:00
|
|
|
|
2021-09-22 14:37:46 +00:00
|
|
|
void GenerateVertexPullingInputs(DataBuilder* b,
|
|
|
|
tint::transform::DataMap* inputs) {
|
2021-05-06 15:43:33 +00:00
|
|
|
transform::VertexPulling::Config cfg;
|
2021-09-22 14:37:46 +00:00
|
|
|
cfg.entry_point_name = b->string();
|
|
|
|
cfg.vertex_state = b->vector(GenerateVertexBufferLayoutDescriptor);
|
|
|
|
cfg.pulling_group = b->build<uint32_t>();
|
2021-05-06 15:43:33 +00:00
|
|
|
inputs->Add<transform::VertexPulling::Config>(cfg);
|
2021-04-29 20:49:25 +00:00
|
|
|
}
|
|
|
|
|
2021-09-22 14:37:46 +00:00
|
|
|
void GenerateSpirvOptions(DataBuilder* b, writer::spirv::Options* options) {
|
|
|
|
*options = b->build<writer::spirv::Options>();
|
2021-07-22 13:25:54 +00:00
|
|
|
}
|
|
|
|
|
2021-09-22 14:37:46 +00:00
|
|
|
void GenerateWgslOptions(DataBuilder* b, writer::wgsl::Options* options) {
|
|
|
|
*options = b->build<writer::wgsl::Options>();
|
2021-07-22 13:25:54 +00:00
|
|
|
}
|
|
|
|
|
2021-09-22 14:37:46 +00:00
|
|
|
void GenerateHlslOptions(DataBuilder* b, writer::hlsl::Options* options) {
|
|
|
|
*options = b->build<writer::hlsl::Options>();
|
2021-07-22 13:25:54 +00:00
|
|
|
}
|
|
|
|
|
2021-09-22 14:37:46 +00:00
|
|
|
void GenerateMslOptions(DataBuilder* b, writer::msl::Options* options) {
|
|
|
|
*options = b->build<writer::msl::Options>();
|
2021-07-22 13:25:54 +00:00
|
|
|
}
|
|
|
|
|
2021-01-12 16:23:48 +00:00
|
|
|
CommonFuzzer::CommonFuzzer(InputFormat input, OutputFormat output)
|
2021-01-18 19:48:54 +00:00
|
|
|
: input_(input),
|
|
|
|
output_(output),
|
|
|
|
transform_manager_(nullptr),
|
|
|
|
inspector_enabled_(false) {}
|
|
|
|
|
2021-01-12 16:23:48 +00:00
|
|
|
CommonFuzzer::~CommonFuzzer() = default;
|
|
|
|
|
|
|
|
int CommonFuzzer::Run(const uint8_t* data, size_t size) {
|
2021-03-25 11:40:07 +00:00
|
|
|
tint::SetInternalCompilerErrorReporter(&TintInternalCompilerErrorReporter);
|
|
|
|
|
2021-02-17 20:15:25 +00:00
|
|
|
Program program;
|
|
|
|
|
2021-07-08 22:11:09 +00:00
|
|
|
#if TINT_BUILD_SPV_READER
|
2021-07-16 09:25:14 +00:00
|
|
|
std::vector<uint32_t> spirv_input(size / sizeof(uint32_t));
|
2021-07-08 22:11:09 +00:00
|
|
|
|
|
|
|
#endif // TINT_BUILD_SPV_READER
|
|
|
|
|
2021-08-05 15:52:58 +00:00
|
|
|
#if TINT_BUILD_WGSL_READER || TINT_BUILD_SPV_READER
|
|
|
|
auto dump_input_data = [&](auto& content, const char* extension) {
|
|
|
|
size_t hash = utils::Hash(content);
|
|
|
|
auto filename = "fuzzer_input_" + std::to_string(hash) + extension; //
|
|
|
|
std::ofstream fout(filename, std::ios::binary);
|
|
|
|
fout.write(reinterpret_cast<const char*>(data),
|
|
|
|
static_cast<std::streamsize>(size));
|
|
|
|
std::cout << "Dumped input data to " << filename << std::endl;
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2021-01-12 16:23:48 +00:00
|
|
|
switch (input_) {
|
|
|
|
#if TINT_BUILD_WGSL_READER
|
2021-02-19 19:04:18 +00:00
|
|
|
case InputFormat::kWGSL: {
|
2021-07-22 22:53:24 +00:00
|
|
|
// Clear any existing diagnostics, as these will hold pointers to file_,
|
|
|
|
// which we are about to release.
|
|
|
|
diagnostics_ = {};
|
2021-01-12 16:23:48 +00:00
|
|
|
std::string str(reinterpret_cast<const char*>(data), size);
|
2021-07-22 22:53:24 +00:00
|
|
|
file_ = std::make_unique<Source::File>("test.wgsl", str);
|
2021-08-05 15:52:58 +00:00
|
|
|
if (dump_input_) {
|
|
|
|
dump_input_data(str, ".wgsl");
|
|
|
|
}
|
2021-07-22 22:53:24 +00:00
|
|
|
program = reader::wgsl::Parse(file_.get());
|
2021-02-19 19:04:18 +00:00
|
|
|
break;
|
2021-01-12 16:23:48 +00:00
|
|
|
}
|
|
|
|
#endif // TINT_BUILD_WGSL_READER
|
|
|
|
#if TINT_BUILD_SPV_READER
|
2021-02-19 19:04:18 +00:00
|
|
|
case InputFormat::kSpv: {
|
2021-07-20 20:56:30 +00:00
|
|
|
// `spirv_input` has been initialized with the capacity to store `size /
|
|
|
|
// sizeof(uint32_t)` uint32_t values. If `size` is not a multiple of
|
|
|
|
// sizeof(uint32_t) then not all of `data` can be copied into
|
|
|
|
// `spirv_input`, and any trailing bytes are discarded.
|
2021-07-21 13:23:51 +00:00
|
|
|
std::memcpy(spirv_input.data(), data,
|
|
|
|
spirv_input.size() * sizeof(uint32_t));
|
2021-07-20 20:56:30 +00:00
|
|
|
if (spirv_input.empty()) {
|
|
|
|
return 0;
|
2021-01-12 16:23:48 +00:00
|
|
|
}
|
2021-08-05 15:52:58 +00:00
|
|
|
if (dump_input_) {
|
|
|
|
dump_input_data(spirv_input, ".spv");
|
|
|
|
}
|
2021-07-20 20:56:30 +00:00
|
|
|
program = reader::spirv::Parse(spirv_input);
|
2021-02-19 19:04:18 +00:00
|
|
|
break;
|
2021-01-12 16:23:48 +00:00
|
|
|
}
|
2021-07-08 22:11:09 +00:00
|
|
|
#endif // TINT_BUILD_SPV_READER
|
2021-01-12 16:23:48 +00:00
|
|
|
default:
|
2021-02-19 19:04:18 +00:00
|
|
|
return 0;
|
2021-01-12 16:23:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (output_ == OutputFormat::kNone) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-26 16:57:10 +00:00
|
|
|
if (!program.IsValid()) {
|
2021-07-20 14:39:50 +00:00
|
|
|
diagnostics_ = program.Diagnostics();
|
2021-01-12 16:23:48 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-07-08 22:11:09 +00:00
|
|
|
#if TINT_BUILD_SPV_READER
|
|
|
|
if (input_ == InputFormat::kSpv &&
|
|
|
|
!SPIRVToolsValidationCheck(program, spirv_input)) {
|
|
|
|
FatalError(program.Diagnostics(),
|
|
|
|
"Fuzzing detected invalid input spirv not being caught by Tint");
|
|
|
|
}
|
|
|
|
#endif // TINT_BUILD_SPV_READER
|
|
|
|
|
2021-01-13 15:50:11 +00:00
|
|
|
if (inspector_enabled_) {
|
2021-01-26 16:57:10 +00:00
|
|
|
inspector::Inspector inspector(&program);
|
2021-01-13 15:50:11 +00:00
|
|
|
|
|
|
|
auto entry_points = inspector.GetEntryPoints();
|
|
|
|
if (inspector.has_error()) {
|
2021-07-20 14:39:50 +00:00
|
|
|
diagnostics_.add_error(tint::diag::System::Inspector, inspector.error());
|
2021-01-13 15:50:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& ep : entry_points) {
|
|
|
|
auto remapped_name = inspector.GetRemappedNameForEntryPoint(ep.name);
|
|
|
|
if (inspector.has_error()) {
|
2021-07-20 14:39:50 +00:00
|
|
|
diagnostics_.add_error(tint::diag::System::Inspector,
|
|
|
|
inspector.error());
|
2021-01-13 15:50:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto constant_ids = inspector.GetConstantIDs();
|
|
|
|
if (inspector.has_error()) {
|
2021-07-20 14:39:50 +00:00
|
|
|
diagnostics_.add_error(tint::diag::System::Inspector,
|
|
|
|
inspector.error());
|
2021-01-13 15:50:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto uniform_bindings =
|
|
|
|
inspector.GetUniformBufferResourceBindings(ep.name);
|
|
|
|
if (inspector.has_error()) {
|
2021-07-20 14:39:50 +00:00
|
|
|
diagnostics_.add_error(tint::diag::System::Inspector,
|
|
|
|
inspector.error());
|
2021-01-13 15:50:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto storage_bindings =
|
|
|
|
inspector.GetStorageBufferResourceBindings(ep.name);
|
|
|
|
if (inspector.has_error()) {
|
2021-07-20 14:39:50 +00:00
|
|
|
diagnostics_.add_error(tint::diag::System::Inspector,
|
|
|
|
inspector.error());
|
2021-01-13 15:50:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto readonly_bindings =
|
|
|
|
inspector.GetReadOnlyStorageBufferResourceBindings(ep.name);
|
|
|
|
if (inspector.has_error()) {
|
2021-07-20 14:39:50 +00:00
|
|
|
diagnostics_.add_error(tint::diag::System::Inspector,
|
|
|
|
inspector.error());
|
2021-01-13 15:50:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto sampler_bindings = inspector.GetSamplerResourceBindings(ep.name);
|
|
|
|
if (inspector.has_error()) {
|
2021-07-20 14:39:50 +00:00
|
|
|
diagnostics_.add_error(tint::diag::System::Inspector,
|
|
|
|
inspector.error());
|
2021-01-13 15:50:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto comparison_sampler_bindings =
|
|
|
|
inspector.GetComparisonSamplerResourceBindings(ep.name);
|
|
|
|
if (inspector.has_error()) {
|
2021-07-20 14:39:50 +00:00
|
|
|
diagnostics_.add_error(tint::diag::System::Inspector,
|
|
|
|
inspector.error());
|
2021-01-13 15:50:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto sampled_texture_bindings =
|
|
|
|
inspector.GetSampledTextureResourceBindings(ep.name);
|
|
|
|
if (inspector.has_error()) {
|
2021-07-20 14:39:50 +00:00
|
|
|
diagnostics_.add_error(tint::diag::System::Inspector,
|
|
|
|
inspector.error());
|
2021-01-13 15:50:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto multisampled_texture_bindings =
|
|
|
|
inspector.GetMultisampledTextureResourceBindings(ep.name);
|
|
|
|
if (inspector.has_error()) {
|
2021-07-20 14:39:50 +00:00
|
|
|
diagnostics_.add_error(tint::diag::System::Inspector,
|
|
|
|
inspector.error());
|
2021-01-13 15:50:11 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-12 16:23:48 +00:00
|
|
|
if (transform_manager_) {
|
2021-04-26 20:38:36 +00:00
|
|
|
auto out = transform_manager_->Run(&program, transform_inputs_);
|
2021-02-24 15:55:24 +00:00
|
|
|
if (!out.program.IsValid()) {
|
2021-06-24 11:27:36 +00:00
|
|
|
// Transforms can produce error messages for bad input.
|
|
|
|
// Catch ICEs and errors from non transform systems.
|
2021-07-16 09:25:14 +00:00
|
|
|
for (const auto& diag : out.program.Diagnostics()) {
|
2021-06-24 11:27:36 +00:00
|
|
|
if (diag.severity > diag::Severity::Error ||
|
|
|
|
diag.system != diag::System::Transform) {
|
2021-07-08 22:11:09 +00:00
|
|
|
FatalError(out.program.Diagnostics(),
|
|
|
|
"Fuzzing detected valid input program being transformed "
|
|
|
|
"into an invalid output program");
|
2021-06-24 11:27:36 +00:00
|
|
|
}
|
|
|
|
}
|
2021-01-12 16:23:48 +00:00
|
|
|
}
|
|
|
|
|
2021-01-26 16:57:10 +00:00
|
|
|
program = std::move(out.program);
|
2021-01-12 16:23:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (output_) {
|
2021-07-12 21:07:41 +00:00
|
|
|
case OutputFormat::kWGSL: {
|
2021-01-12 16:23:48 +00:00
|
|
|
#if TINT_BUILD_WGSL_WRITER
|
2021-07-22 13:25:54 +00:00
|
|
|
auto result = writer::wgsl::Generate(&program, options_wgsl_);
|
2021-07-16 09:25:14 +00:00
|
|
|
generated_wgsl_ = std::move(result.wgsl);
|
2021-07-12 21:07:41 +00:00
|
|
|
if (!result.success) {
|
2021-07-16 21:07:25 +00:00
|
|
|
FatalError(program.Diagnostics(),
|
|
|
|
"WGSL writer failed: " + result.error);
|
2021-07-12 21:07:41 +00:00
|
|
|
}
|
2021-01-12 16:23:48 +00:00
|
|
|
#endif // TINT_BUILD_WGSL_WRITER
|
|
|
|
break;
|
2021-07-12 21:07:41 +00:00
|
|
|
}
|
|
|
|
case OutputFormat::kSpv: {
|
2021-01-12 16:23:48 +00:00
|
|
|
#if TINT_BUILD_SPV_WRITER
|
2021-07-22 13:25:54 +00:00
|
|
|
auto result = writer::spirv::Generate(&program, options_spirv_);
|
2021-07-16 09:25:14 +00:00
|
|
|
generated_spirv_ = std::move(result.spirv);
|
2021-07-12 21:07:41 +00:00
|
|
|
if (!result.success) {
|
2021-07-16 21:07:25 +00:00
|
|
|
FatalError(program.Diagnostics(),
|
|
|
|
"SPIR-V writer failed: " + result.error);
|
2021-07-12 21:07:41 +00:00
|
|
|
}
|
2021-07-16 09:25:14 +00:00
|
|
|
if (!SPIRVToolsValidationCheck(program, generated_spirv_)) {
|
2021-07-12 21:07:41 +00:00
|
|
|
FatalError(program.Diagnostics(),
|
|
|
|
"Fuzzing detected invalid spirv being emitted by Tint");
|
|
|
|
}
|
|
|
|
|
2021-01-12 16:23:48 +00:00
|
|
|
#endif // TINT_BUILD_SPV_WRITER
|
|
|
|
break;
|
2021-07-12 21:07:41 +00:00
|
|
|
}
|
|
|
|
case OutputFormat::kHLSL: {
|
2021-01-12 16:23:48 +00:00
|
|
|
#if TINT_BUILD_HLSL_WRITER
|
2021-07-22 13:25:54 +00:00
|
|
|
auto result = writer::hlsl::Generate(&program, options_hlsl_);
|
2021-07-16 09:25:14 +00:00
|
|
|
generated_hlsl_ = std::move(result.hlsl);
|
2021-07-12 21:07:41 +00:00
|
|
|
if (!result.success) {
|
2021-07-16 21:07:25 +00:00
|
|
|
FatalError(program.Diagnostics(),
|
|
|
|
"HLSL writer failed: " + result.error);
|
2021-07-12 21:07:41 +00:00
|
|
|
}
|
2021-01-12 16:23:48 +00:00
|
|
|
#endif // TINT_BUILD_HLSL_WRITER
|
|
|
|
break;
|
2021-07-12 21:07:41 +00:00
|
|
|
}
|
|
|
|
case OutputFormat::kMSL: {
|
2021-01-12 16:23:48 +00:00
|
|
|
#if TINT_BUILD_MSL_WRITER
|
2021-07-22 13:25:54 +00:00
|
|
|
auto result = writer::msl::Generate(&program, options_msl_);
|
2021-07-16 09:25:14 +00:00
|
|
|
generated_msl_ = std::move(result.msl);
|
2021-07-12 21:07:41 +00:00
|
|
|
if (!result.success) {
|
2021-07-16 21:07:25 +00:00
|
|
|
FatalError(program.Diagnostics(), "MSL writer failed: " + result.error);
|
2021-07-12 21:07:41 +00:00
|
|
|
}
|
2021-01-12 16:23:48 +00:00
|
|
|
#endif // TINT_BUILD_MSL_WRITER
|
|
|
|
break;
|
2021-07-12 21:07:41 +00:00
|
|
|
}
|
2021-01-12 16:23:48 +00:00
|
|
|
case OutputFormat::kNone:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace fuzzers
|
|
|
|
} // namespace tint
|