diff --git a/DEPS b/DEPS index 0d9f6fe750..15f9725e8c 100644 --- a/DEPS +++ b/DEPS @@ -68,7 +68,7 @@ deps = { 'condition': 'dawn_standalone', }, 'third_party/shaderc': { - 'url': '{chromium_git}/external/github.com/google/shaderc@ce7d92182b8cc9c72e99efb5fab1eae3c2084887', + 'url': '{chromium_git}/external/github.com/google/shaderc@634dd3545cbccb9362f16f41b3b75703f290a9fd', 'condition': 'dawn_standalone', }, diff --git a/src/fuzzers/BUILD.gn b/src/fuzzers/BUILD.gn index 9df69ebcc4..0c48266c84 100644 --- a/src/fuzzers/BUILD.gn +++ b/src/fuzzers/BUILD.gn @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. +import("../../scripts/dawn_overrides_with_defaults.gni") import("//build_overrides/build.gni") dawn_top_level = "../.." @@ -76,7 +77,7 @@ static_library("dawn_spirv_cross_fuzzer_common") { "DawnSPIRVCrossFuzzer.h", ] public_deps = [ - "${dawn_top_level}/third_party:spirv_cross_full_for_fuzzers", + "${dawn_shaderc_dir}:libshaderc_spvc", ] } @@ -111,7 +112,7 @@ dawn_fuzzer_test("dawn_spirv_cross_glsl_full_fuzzer") { # Uses Dawn specific options and varies input data dawn_fuzzer_test("dawn_spirv_cross_hlsl_fast_fuzzer") { sources = [ - "DawnSPIRVCrossGLSLFastFuzzer.cpp", + "DawnSPIRVCrossHLSLFastFuzzer.cpp", ] deps = [ ":dawn_spirv_cross_fuzzer_common", @@ -124,7 +125,7 @@ dawn_fuzzer_test("dawn_spirv_cross_hlsl_fast_fuzzer") { # Varies both the options and input data dawn_fuzzer_test("dawn_spirv_cross_hlsl_full_fuzzer") { sources = [ - "DawnSPIRVCrossGLSLFullFuzzer.cpp", + "DawnSPIRVCrossHLSLFullFuzzer.cpp", ] deps = [ ":dawn_spirv_cross_fuzzer_common", @@ -137,7 +138,7 @@ dawn_fuzzer_test("dawn_spirv_cross_hlsl_full_fuzzer") { # Uses Dawn specific options and varies input data dawn_fuzzer_test("dawn_spirv_cross_msl_fast_fuzzer") { sources = [ - "DawnSPIRVCrossGLSLFastFuzzer.cpp", + "DawnSPIRVCrossMSLFastFuzzer.cpp", ] deps = [ ":dawn_spirv_cross_fuzzer_common", @@ -150,7 +151,7 @@ dawn_fuzzer_test("dawn_spirv_cross_msl_fast_fuzzer") { # Varies both the options and input data dawn_fuzzer_test("dawn_spirv_cross_msl_full_fuzzer") { sources = [ - "DawnSPIRVCrossGLSLFullFuzzer.cpp", + "DawnSPIRVCrossMSLFullFuzzer.cpp", ] deps = [ ":dawn_spirv_cross_fuzzer_common", @@ -165,12 +166,10 @@ dawn_fuzzer_test("dawn_wire_server_and_frontend_fuzzer") { deps = [ "${dawn_top_level}:dawn_common", - "${dawn_top_level}:libdawn_static", "${dawn_top_level}:libdawn_native_static", + "${dawn_top_level}:libdawn_static", "${dawn_top_level}:libdawn_wire_static", ] - additional_configs = [ - "${dawn_top_level}:dawn_internal", - ] + additional_configs = [ "${dawn_top_level}:dawn_internal" ] } diff --git a/src/fuzzers/DawnSPIRVCrossFuzzer.cpp b/src/fuzzers/DawnSPIRVCrossFuzzer.cpp index c37b2156ad..f080adbc6f 100644 --- a/src/fuzzers/DawnSPIRVCrossFuzzer.cpp +++ b/src/fuzzers/DawnSPIRVCrossFuzzer.cpp @@ -65,43 +65,26 @@ namespace DawnSPIRVCrossFuzzer { } int Run(const uint8_t* data, size_t size, Task task) { - if (!data || size < 1) - return 0; - size_t sizeInU32 = size / sizeof(uint32_t); const uint32_t* u32Data = reinterpret_cast(data); std::vector input(u32Data, u32Data + sizeInU32); - task(input); + if (input.size() != 0) { + task(input); + } + return 0; } - template - int RunWithOptions(const uint8_t* data, size_t size, TaskWithOptions task) { - if (!data || size < sizeof(Options) + 1) + int RunWithOptions(const uint8_t* data, size_t size, TaskWithOptions task) { + shaderc_spvc::CompileOptions options; + size_t used = options.SetForFuzzing(data, size); + if (used == 0) { + // not enough data to set options return 0; + } - Options options = *reinterpret_cast(data); - data += sizeof(options); - size -= sizeof(options); - - std::vector input(data, data + (4 * (size / 4))); - - task(input, options); - - return 0; + return Run(data + used, size - used, std::bind(task, std::placeholders::_1, options)); } - template int RunWithOptions( - const uint8_t*, - size_t, - TaskWithOptions); - template int RunWithOptions( - const uint8_t*, - size_t, - TaskWithOptions); - template int RunWithOptions(const uint8_t*, - size_t, - TaskWithOptions); - } // namespace DawnSPIRVCrossFuzzer diff --git a/src/fuzzers/DawnSPIRVCrossFuzzer.h b/src/fuzzers/DawnSPIRVCrossFuzzer.h index 47e30400ac..2f017e3b7b 100644 --- a/src/fuzzers/DawnSPIRVCrossFuzzer.h +++ b/src/fuzzers/DawnSPIRVCrossFuzzer.h @@ -16,19 +16,13 @@ #include #include -#include "spirv-cross/spirv_glsl.hpp" -#include "spirv-cross/spirv_hlsl.hpp" +#include "shaderc/spvc.hpp" namespace DawnSPIRVCrossFuzzer { - struct CombinedOptions { - spirv_cross::CompilerGLSL::Options glsl; - spirv_cross::CompilerHLSL::Options hlsl; - }; - using Task = std::function&)>; - template - using TaskWithOptions = std::function&, Options)>; + using TaskWithOptions = + std::function&, shaderc_spvc::CompileOptions)>; // Used to wrap code that may fire a SIGABRT. Do not allocate anything local within |exec|, as // it is not guaranteed to return. @@ -38,7 +32,6 @@ namespace DawnSPIRVCrossFuzzer { int Run(const uint8_t* data, size_t size, Task task); // Used to fuzz by mutating both the input data and options to the compiler - template - int RunWithOptions(const uint8_t* data, size_t size, TaskWithOptions task); + int RunWithOptions(const uint8_t* data, size_t size, TaskWithOptions task); } // namespace DawnSPIRVCrossFuzzer diff --git a/src/fuzzers/DawnSPIRVCrossGLSLFastFuzzer.cpp b/src/fuzzers/DawnSPIRVCrossGLSLFastFuzzer.cpp index 53b06cf393..2a36cf1d41 100644 --- a/src/fuzzers/DawnSPIRVCrossGLSLFastFuzzer.cpp +++ b/src/fuzzers/DawnSPIRVCrossGLSLFastFuzzer.cpp @@ -19,22 +19,18 @@ #include "DawnSPIRVCrossFuzzer.h" namespace { - int GLSLFastFuzzTask(const std::vector& input) { - std::unique_ptr compiler; - DawnSPIRVCrossFuzzer::ExecuteWithSignalTrap([&compiler, input]() { - compiler = std::make_unique(input); - }); - if (compiler == nullptr) { + shaderc_spvc::Compiler compiler; + if (!compiler.IsValid()) { return 0; } - // Using the options that are used by Dawn, they appear in ShaderModuleGL.cpp - spirv_cross::CompilerGLSL::Options options; - options.version = 440; - compiler->set_common_options(options); - - DawnSPIRVCrossFuzzer::ExecuteWithSignalTrap([&compiler]() { compiler->compile(); }); + DawnSPIRVCrossFuzzer::ExecuteWithSignalTrap([&compiler, &input]() { + // Using the options that are used by Dawn, they appear in ShaderModuleGL.cpp + shaderc_spvc::CompileOptions options; + options.SetOutputLanguageVersion(440); + compiler.CompileSpvToGlsl(input.data(), input.size(), options); + }); return 0; } diff --git a/src/fuzzers/DawnSPIRVCrossGLSLFullFuzzer.cpp b/src/fuzzers/DawnSPIRVCrossGLSLFullFuzzer.cpp index 2ff9fefb7d..b592517b95 100644 --- a/src/fuzzers/DawnSPIRVCrossGLSLFullFuzzer.cpp +++ b/src/fuzzers/DawnSPIRVCrossGLSLFullFuzzer.cpp @@ -20,19 +20,15 @@ namespace { - int GLSLFullFuzzTask(const std::vector& input, - spirv_cross::CompilerGLSL::Options options) { - std::unique_ptr compiler; - DawnSPIRVCrossFuzzer::ExecuteWithSignalTrap([&compiler, input]() { - compiler = std::make_unique(input); - }); - if (compiler == nullptr) { + int GLSLFullFuzzTask(const std::vector& input, shaderc_spvc::CompileOptions options) { + shaderc_spvc::Compiler compiler; + if (!compiler.IsValid()) { return 0; } - compiler->set_common_options(options); - - DawnSPIRVCrossFuzzer::ExecuteWithSignalTrap([&compiler]() { compiler->compile(); }); + DawnSPIRVCrossFuzzer::ExecuteWithSignalTrap([&compiler, &input, &options]() { + compiler.CompileSpvToGlsl(input.data(), input.size(), options); + }); return 0; } @@ -40,6 +36,5 @@ namespace { } // namespace extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - return DawnSPIRVCrossFuzzer::RunWithOptions( - data, size, GLSLFullFuzzTask); + return DawnSPIRVCrossFuzzer::RunWithOptions(data, size, GLSLFullFuzzTask); } diff --git a/src/fuzzers/DawnSPIRVCrossHLSLFastFuzzer.cpp b/src/fuzzers/DawnSPIRVCrossHLSLFastFuzzer.cpp index 9d9cd9d24e..6c75b39608 100644 --- a/src/fuzzers/DawnSPIRVCrossHLSLFastFuzzer.cpp +++ b/src/fuzzers/DawnSPIRVCrossHLSLFastFuzzer.cpp @@ -18,30 +18,23 @@ #include "DawnSPIRVCrossFuzzer.h" -#include "spirv-cross/spirv_hlsl.hpp" - namespace { int FuzzTask(const std::vector& input) { - std::unique_ptr compiler; - DawnSPIRVCrossFuzzer::ExecuteWithSignalTrap([&compiler, input]() { - compiler = std::make_unique(input); - }); - if (compiler == nullptr) { + shaderc_spvc::Compiler compiler; + if (!compiler.IsValid()) { return 0; } - // Using the options that are used by Dawn, they appear in ShaderModuleD3D12.cpp - spirv_cross::CompilerGLSL::Options options_glsl; - options_glsl.vertex.fixup_clipspace = true; - options_glsl.vertex.flip_vert_y = true; - compiler->set_common_options(options_glsl); + DawnSPIRVCrossFuzzer::ExecuteWithSignalTrap([&compiler, &input]() { + shaderc_spvc::CompileOptions options; - spirv_cross::CompilerHLSL::Options options_hlsl; - options_hlsl.shader_model = 51; - compiler->set_hlsl_options(options_hlsl); - - DawnSPIRVCrossFuzzer::ExecuteWithSignalTrap([&compiler]() { compiler->compile(); }); + // Using the options that are used by Dawn, they appear in ShaderModuleD3D12.cpp + options.SetFixupClipspace(true); + options.SetFlipVertY(true); + options.SetShaderModel(51); + compiler.CompileSpvToHlsl(input.data(), input.size(), options); + }); return 0; } diff --git a/src/fuzzers/DawnSPIRVCrossHLSLFullFuzzer.cpp b/src/fuzzers/DawnSPIRVCrossHLSLFullFuzzer.cpp index 2433752ca4..c0601730a1 100644 --- a/src/fuzzers/DawnSPIRVCrossHLSLFullFuzzer.cpp +++ b/src/fuzzers/DawnSPIRVCrossHLSLFullFuzzer.cpp @@ -18,29 +18,22 @@ #include "DawnSPIRVCrossFuzzer.h" -#include "spirv-cross/spirv_hlsl.hpp" - namespace { - int FuzzTask(const std::vector& input, - DawnSPIRVCrossFuzzer::CombinedOptions options) { - std::unique_ptr compiler; - DawnSPIRVCrossFuzzer::ExecuteWithSignalTrap([&compiler, input]() { - compiler = std::make_unique(input); - }); - if (compiler == nullptr) { + int FuzzTask(const std::vector& input, shaderc_spvc::CompileOptions options) { + shaderc_spvc::Compiler compiler; + if (!compiler.IsValid()) { return 0; } - compiler->set_common_options(options.glsl); - compiler->set_hlsl_options(options.hlsl); + DawnSPIRVCrossFuzzer::ExecuteWithSignalTrap([&compiler, &input, &options]() { + compiler.CompileSpvToHlsl(input.data(), input.size(), options); + }); - DawnSPIRVCrossFuzzer::ExecuteWithSignalTrap([&compiler]() { compiler->compile(); }); return 0; } } // namespace extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - return DawnSPIRVCrossFuzzer::RunWithOptions(data, size, - FuzzTask); + return DawnSPIRVCrossFuzzer::RunWithOptions(data, size, FuzzTask); } diff --git a/src/fuzzers/DawnSPIRVCrossMSLFastFuzzer.cpp b/src/fuzzers/DawnSPIRVCrossMSLFastFuzzer.cpp index 4b0da62e27..fc30193475 100644 --- a/src/fuzzers/DawnSPIRVCrossMSLFastFuzzer.cpp +++ b/src/fuzzers/DawnSPIRVCrossMSLFastFuzzer.cpp @@ -18,24 +18,21 @@ #include "DawnSPIRVCrossFuzzer.h" -#include "spirv-cross/spirv_msl.hpp" - namespace { int FuzzTask(const std::vector& input) { - std::unique_ptr compiler; - DawnSPIRVCrossFuzzer::ExecuteWithSignalTrap( - [&compiler, input]() { compiler = std::make_unique(input); }); - if (compiler == nullptr) { + shaderc_spvc::Compiler compiler; + if (!compiler.IsValid()) { return 0; } - // Using the options that are used by Dawn, they appear in ShaderModuleMTL.mm - spirv_cross::CompilerGLSL::Options options; - options.vertex.flip_vert_y = true; - compiler->spirv_cross::CompilerGLSL::set_common_options(options); + DawnSPIRVCrossFuzzer::ExecuteWithSignalTrap([&compiler, &input]() { + shaderc_spvc::CompileOptions options; - DawnSPIRVCrossFuzzer::ExecuteWithSignalTrap([&compiler]() { compiler->compile(); }); + // Using the options that are used by Dawn, they appear in ShaderModuleMTL.mm + options.SetFlipVertY(true); + compiler.CompileSpvToMsl(input.data(), input.size(), options); + }); return 0; } diff --git a/src/fuzzers/DawnSPIRVCrossMSLFullFuzzer.cpp b/src/fuzzers/DawnSPIRVCrossMSLFullFuzzer.cpp index 7b66edd93c..0549f25523 100644 --- a/src/fuzzers/DawnSPIRVCrossMSLFullFuzzer.cpp +++ b/src/fuzzers/DawnSPIRVCrossMSLFullFuzzer.cpp @@ -18,21 +18,17 @@ #include "DawnSPIRVCrossFuzzer.h" -#include "spirv-cross/spirv_msl.hpp" - namespace { - int FuzzTask(const std::vector& input, spirv_cross::CompilerGLSL::Options options) { - std::unique_ptr compiler; - DawnSPIRVCrossFuzzer::ExecuteWithSignalTrap( - [&compiler, input]() { compiler = std::make_unique(input); }); - if (compiler == nullptr) { + int FuzzTask(const std::vector& input, shaderc_spvc::CompileOptions options) { + shaderc_spvc::Compiler compiler; + if (!compiler.IsValid()) { return 0; } - compiler->spirv_cross::CompilerGLSL::set_common_options(options); - - DawnSPIRVCrossFuzzer::ExecuteWithSignalTrap([&compiler]() { compiler->compile(); }); + DawnSPIRVCrossFuzzer::ExecuteWithSignalTrap([&compiler, &input, &options]() { + compiler.CompileSpvToMsl(input.data(), input.size(), options); + }); return 0; } @@ -40,6 +36,5 @@ namespace { } // namespace extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { - return DawnSPIRVCrossFuzzer::RunWithOptions(data, size, - FuzzTask); + return DawnSPIRVCrossFuzzer::RunWithOptions(data, size, FuzzTask); }