[tint][fuzz][ast] Add CanonicalizeEntryPointIO fuzzer
Bug: tint:2223
Change-Id: Ie727d9b5eb2d8859c77e1ddc646100e13c88a2bb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/185626
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
diff --git a/src/tint/lang/wgsl/ast/transform/BUILD.cmake b/src/tint/lang/wgsl/ast/transform/BUILD.cmake
index 06f5358..ac08f17 100644
--- a/src/tint/lang/wgsl/ast/transform/BUILD.cmake
+++ b/src/tint/lang/wgsl/ast/transform/BUILD.cmake
@@ -253,6 +253,7 @@
lang/wgsl/ast/transform/array_length_from_uniform_fuzz.cc
lang/wgsl/ast/transform/binding_remapper_fuzz.cc
lang/wgsl/ast/transform/builtin_polyfill_fuzz.cc
+ lang/wgsl/ast/transform/canonicalize_entry_point_io_fuzz.cc
lang/wgsl/ast/transform/zero_init_workgroup_memory_fuzz.cc
)
diff --git a/src/tint/lang/wgsl/ast/transform/BUILD.gn b/src/tint/lang/wgsl/ast/transform/BUILD.gn
index b5eb4a9..0535e2a 100644
--- a/src/tint/lang/wgsl/ast/transform/BUILD.gn
+++ b/src/tint/lang/wgsl/ast/transform/BUILD.gn
@@ -243,6 +243,7 @@
"array_length_from_uniform_fuzz.cc",
"binding_remapper_fuzz.cc",
"builtin_polyfill_fuzz.cc",
+ "canonicalize_entry_point_io_fuzz.cc",
"zero_init_workgroup_memory_fuzz.cc",
]
deps = [
diff --git a/src/tint/lang/wgsl/ast/transform/canonicalize_entry_point_io.cc b/src/tint/lang/wgsl/ast/transform/canonicalize_entry_point_io.cc
index 3e2029b..e61f615 100644
--- a/src/tint/lang/wgsl/ast/transform/canonicalize_entry_point_io.cc
+++ b/src/tint/lang/wgsl/ast/transform/canonicalize_entry_point_io.cc
@@ -1011,6 +1011,8 @@
return resolver::Resolve(b);
}
+CanonicalizeEntryPointIO::Config::Config() = default;
+
CanonicalizeEntryPointIO::Config::Config(ShaderStyle style,
uint32_t sample_mask,
bool emit_point_size,
diff --git a/src/tint/lang/wgsl/ast/transform/canonicalize_entry_point_io.h b/src/tint/lang/wgsl/ast/transform/canonicalize_entry_point_io.h
index ddf761d..9899e3d5 100644
--- a/src/tint/lang/wgsl/ast/transform/canonicalize_entry_point_io.h
+++ b/src/tint/lang/wgsl/ast/transform/canonicalize_entry_point_io.h
@@ -32,6 +32,7 @@
#include "src/tint/lang/wgsl/ast/internal_attribute.h"
#include "src/tint/lang/wgsl/ast/transform/transform.h"
+#include "src/tint/utils/reflection/reflection.h"
namespace tint::ast::transform {
@@ -115,6 +116,9 @@
/// Configuration options for the transform.
struct Config final : public Castable<Config, Data> {
/// Constructor
+ Config();
+
+ /// Constructor
/// @param style the approach to use for emitting shader IO.
/// @param sample_mask an optional sample mask to combine with shader masks
/// @param emit_vertex_point_size `true` to generate a pointsize builtin
@@ -131,17 +135,24 @@
~Config() override;
/// The approach to use for emitting shader IO.
- const ShaderStyle shader_style;
+ ShaderStyle shader_style = ShaderStyle::kSpirv;
/// A fixed sample mask to combine into masks produced by fragment shaders.
- const uint32_t fixed_sample_mask;
+ uint32_t fixed_sample_mask = 0xffffffff;
/// Set to `true` to generate a pointsize builtin and have it set to 1.0
/// from all vertex shaders in the module.
- const bool emit_vertex_point_size;
+ bool emit_vertex_point_size = false;
/// Set to `true` to replace f16 IO types with f32 types and convert them.
- const bool polyfill_f16_io = false;
+ bool polyfill_f16_io = false;
+
+ /// Reflection for this struct
+ TINT_REFLECT(Config,
+ shader_style,
+ fixed_sample_mask,
+ emit_vertex_point_size,
+ polyfill_f16_io);
};
/// HLSLWaveIntrinsic is an InternalAttribute that is used to decorate a stub function so that
@@ -189,4 +200,11 @@
} // namespace tint::ast::transform
+namespace tint {
+
+/// Reflection for ShaderStyle
+TINT_REFLECT_ENUM_RANGE(ast::transform::CanonicalizeEntryPointIO::ShaderStyle, kSpirv, kHlsl);
+
+} // namespace tint
+
#endif // SRC_TINT_LANG_WGSL_AST_TRANSFORM_CANONICALIZE_ENTRY_POINT_IO_H_
diff --git a/src/tint/lang/wgsl/ast/transform/canonicalize_entry_point_io_fuzz.cc b/src/tint/lang/wgsl/ast/transform/canonicalize_entry_point_io_fuzz.cc
new file mode 100644
index 0000000..136291a
--- /dev/null
+++ b/src/tint/lang/wgsl/ast/transform/canonicalize_entry_point_io_fuzz.cc
@@ -0,0 +1,51 @@
+// Copyright 2024 The Dawn & Tint Authors
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this
+// list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "src/tint/cmd/fuzz/wgsl/fuzz.h"
+#include "src/tint/lang/wgsl/ast/transform/canonicalize_entry_point_io.h"
+
+namespace tint::ast::transform {
+namespace {
+
+void CanonicalizeEntryPointIOFuzzer(const Program& program,
+ const CanonicalizeEntryPointIO::Config& config) {
+ DataMap inputs;
+ inputs.Add<CanonicalizeEntryPointIO::Config>(std::move(config));
+
+ DataMap outputs;
+ if (auto result = CanonicalizeEntryPointIO{}.Apply(program, inputs, outputs)) {
+ if (!result->IsValid()) {
+ TINT_ICE() << "CanonicalizeEntryPointIO returned invalid program:\n"
+ << result->Diagnostics();
+ }
+ }
+}
+
+} // namespace
+} // namespace tint::ast::transform
+
+TINT_WGSL_PROGRAM_FUZZER(tint::ast::transform::CanonicalizeEntryPointIOFuzzer);