Fuzz WGSL and MSL generator options
BUG=tint:973 Change-Id: I94dc136444e9650dcf3d1c81a52e6d4491b21a16 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/59221 Auto-Submit: Ryan Harrison <rharrison@chromium.org> Commit-Queue: Ben Clayton <bclayton@google.com> Reviewed-by: James Price <jrprice@google.com> Reviewed-by: Ben Clayton <bclayton@google.com> Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
parent
4ffcf067a3
commit
18d7e785d3
|
@ -168,6 +168,22 @@ void ExtractVertexPullingInputs(Reader* r, tint::transform::DataMap* inputs) {
|
|||
inputs->Add<transform::VertexPulling::Config>(cfg);
|
||||
}
|
||||
|
||||
void ExtractSpirvOptions(Reader* r, writer::spirv::Options* options) {
|
||||
*options = r->read<writer::spirv::Options>();
|
||||
}
|
||||
|
||||
void ExtractWgslOptions(Reader* r, writer::wgsl::Options* options) {
|
||||
*options = r->read<writer::wgsl::Options>();
|
||||
}
|
||||
|
||||
void ExtractHlslOptions(Reader* r, writer::hlsl::Options* options) {
|
||||
*options = r->read<writer::hlsl::Options>();
|
||||
}
|
||||
|
||||
void ExtractMslOptions(Reader* r, writer::msl::Options* options) {
|
||||
*options = r->read<writer::msl::Options>();
|
||||
}
|
||||
|
||||
CommonFuzzer::CommonFuzzer(InputFormat input, OutputFormat output)
|
||||
: input_(input),
|
||||
output_(output),
|
||||
|
@ -337,8 +353,7 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) {
|
|||
switch (output_) {
|
||||
case OutputFormat::kWGSL: {
|
||||
#if TINT_BUILD_WGSL_WRITER
|
||||
writer::wgsl::Options options;
|
||||
auto result = writer::wgsl::Generate(&program, options);
|
||||
auto result = writer::wgsl::Generate(&program, options_wgsl_);
|
||||
generated_wgsl_ = std::move(result.wgsl);
|
||||
if (!result.success) {
|
||||
FatalError(program.Diagnostics(),
|
||||
|
@ -349,8 +364,7 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) {
|
|||
}
|
||||
case OutputFormat::kSpv: {
|
||||
#if TINT_BUILD_SPV_WRITER
|
||||
writer::spirv::Options options;
|
||||
auto result = writer::spirv::Generate(&program, options);
|
||||
auto result = writer::spirv::Generate(&program, options_spirv_);
|
||||
generated_spirv_ = std::move(result.spirv);
|
||||
if (!result.success) {
|
||||
FatalError(program.Diagnostics(),
|
||||
|
@ -366,8 +380,7 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) {
|
|||
}
|
||||
case OutputFormat::kHLSL: {
|
||||
#if TINT_BUILD_HLSL_WRITER
|
||||
writer::hlsl::Options options;
|
||||
auto result = writer::hlsl::Generate(&program, options);
|
||||
auto result = writer::hlsl::Generate(&program, options_hlsl_);
|
||||
generated_hlsl_ = std::move(result.hlsl);
|
||||
if (!result.success) {
|
||||
FatalError(program.Diagnostics(),
|
||||
|
@ -378,8 +391,7 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) {
|
|||
}
|
||||
case OutputFormat::kMSL: {
|
||||
#if TINT_BUILD_MSL_WRITER
|
||||
writer::msl::Options options;
|
||||
auto result = writer::msl::Generate(&program, options);
|
||||
auto result = writer::msl::Generate(&program, options_msl_);
|
||||
generated_msl_ = std::move(result.msl);
|
||||
if (!result.success) {
|
||||
FatalError(program.Diagnostics(), "MSL writer failed: " + result.error);
|
||||
|
|
|
@ -90,12 +90,21 @@ class Reader {
|
|||
};
|
||||
|
||||
void ExtractBindingRemapperInputs(Reader* r, tint::transform::DataMap* inputs);
|
||||
|
||||
void ExtractFirstIndexOffsetInputs(Reader* r, tint::transform::DataMap* inputs);
|
||||
|
||||
void ExtractSingleEntryPointInputs(Reader* r, tint::transform::DataMap* inputs);
|
||||
|
||||
void ExtractVertexPullingInputs(Reader* r, tint::transform::DataMap* inputs);
|
||||
|
||||
void ExtractSpirvOptions(Reader* r, writer::spirv::Options* options);
|
||||
|
||||
void ExtractWgslOptions(Reader* r, writer::wgsl::Options* options);
|
||||
|
||||
void ExtractHlslOptions(Reader* r, writer::hlsl::Options* options);
|
||||
|
||||
void ExtractMslOptions(Reader* r, writer::msl::Options* options);
|
||||
|
||||
enum class InputFormat { kWGSL, kSpv, kNone };
|
||||
|
||||
enum class OutputFormat { kWGSL, kSpv, kHLSL, kMSL, kNone };
|
||||
|
@ -113,6 +122,10 @@ class CommonFuzzer {
|
|||
|
||||
int Run(const uint8_t* data, size_t size);
|
||||
|
||||
const tint::diag::List& Diagnostics() const { return diagnostics_; }
|
||||
|
||||
bool HasErrors() const { return diagnostics_.contains_errors(); }
|
||||
|
||||
const std::vector<uint32_t>& GetGeneratedSpirv() const {
|
||||
return generated_spirv_;
|
||||
}
|
||||
|
@ -123,9 +136,21 @@ class CommonFuzzer {
|
|||
|
||||
const std::string& GetGeneratedMsl() const { return generated_msl_; }
|
||||
|
||||
const tint::diag::List& Diagnostics() const { return diagnostics_; }
|
||||
void SetOptionsSpirv(const writer::spirv::Options& options) {
|
||||
options_spirv_ = options;
|
||||
}
|
||||
|
||||
bool HasErrors() const { return diagnostics_.contains_errors(); }
|
||||
void SetOptionsWgsl(const writer::wgsl::Options& options) {
|
||||
options_wgsl_ = options;
|
||||
}
|
||||
|
||||
void SetOptionsHlsl(const writer::hlsl::Options& options) {
|
||||
options_hlsl_ = options;
|
||||
}
|
||||
|
||||
void SetOptionsMsl(const writer::msl::Options& options) {
|
||||
options_msl_ = options;
|
||||
}
|
||||
|
||||
private:
|
||||
InputFormat input_;
|
||||
|
@ -139,6 +164,11 @@ class CommonFuzzer {
|
|||
std::string generated_wgsl_;
|
||||
std::string generated_hlsl_;
|
||||
std::string generated_msl_;
|
||||
|
||||
writer::spirv::Options options_spirv_;
|
||||
writer::wgsl::Options options_wgsl_;
|
||||
writer::hlsl::Options options_hlsl_;
|
||||
writer::msl::Options options_msl_;
|
||||
};
|
||||
|
||||
} // namespace fuzzers
|
||||
|
|
|
@ -20,8 +20,12 @@ namespace tint {
|
|||
namespace fuzzers {
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
Reader reader(data, size);
|
||||
writer::msl::Options options;
|
||||
ExtractMslOptions(&reader, &options);
|
||||
tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kSpv, OutputFormat::kMSL);
|
||||
return fuzzer.Run(data, size);
|
||||
fuzzer.SetOptionsMsl(options);
|
||||
return fuzzer.Run(reader.data(), reader.size());
|
||||
}
|
||||
|
||||
} // namespace fuzzers
|
||||
|
|
|
@ -20,8 +20,12 @@ namespace tint {
|
|||
namespace fuzzers {
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
Reader reader(data, size);
|
||||
writer::spirv::Options options;
|
||||
ExtractSpirvOptions(&reader, &options);
|
||||
tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kSpv, OutputFormat::kSpv);
|
||||
return fuzzer.Run(data, size);
|
||||
fuzzer.SetOptionsSpirv(options);
|
||||
return fuzzer.Run(reader.data(), reader.size());
|
||||
}
|
||||
|
||||
} // namespace fuzzers
|
||||
|
|
|
@ -20,8 +20,12 @@ namespace tint {
|
|||
namespace fuzzers {
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
Reader reader(data, size);
|
||||
writer::msl::Options options;
|
||||
ExtractMslOptions(&reader, &options);
|
||||
tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kMSL);
|
||||
return fuzzer.Run(data, size);
|
||||
fuzzer.SetOptionsMsl(options);
|
||||
return fuzzer.Run(reader.data(), reader.size());
|
||||
}
|
||||
|
||||
} // namespace fuzzers
|
||||
|
|
|
@ -20,8 +20,12 @@ namespace tint {
|
|||
namespace fuzzers {
|
||||
|
||||
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
|
||||
Reader reader(data, size);
|
||||
writer::spirv::Options options;
|
||||
ExtractSpirvOptions(&reader, &options);
|
||||
tint::fuzzers::CommonFuzzer fuzzer(InputFormat::kWGSL, OutputFormat::kSpv);
|
||||
return fuzzer.Run(data, size);
|
||||
fuzzer.SetOptionsSpirv(options);
|
||||
return fuzzer.Run(reader.data(), reader.size());
|
||||
}
|
||||
|
||||
} // namespace fuzzers
|
||||
|
|
Loading…
Reference in New Issue