Update AST Fuzzers to initialize MultiPlanar transform.

When the fuzzers execute they need to make sure that, if there is data
effecting the MultiPlanar transform that the configuration is provided.
This used to be done by the generator, but is now the requirement of the
caller to initialize.

ThiS CL updates the AST Fuzzer common code to initialize the
`ExternalTextureOptions` with the same logic that is done by the tint
command.

Bug: chromium:1421379
Change-Id: Id957d73fe1317558edfdfcec3c0e2eaee48625bd
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/125280
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair 2023-03-23 19:35:02 +00:00 committed by Dawn LUCI CQ
parent b7179aa89d
commit 5ab6dcb59b
1 changed files with 48 additions and 0 deletions

View File

@ -14,6 +14,7 @@
#include "src/tint/fuzzers/tint_common_fuzzer.h"
#include <algorithm>
#include <cassert>
#include <cstring>
#include <fstream>
@ -21,6 +22,7 @@
#include <memory>
#include <sstream>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
@ -31,6 +33,9 @@
#include "src/tint/ast/module.h"
#include "src/tint/diagnostic/formatter.h"
#include "src/tint/program.h"
#include "src/tint/sem/binding_point.h"
#include "src/tint/sem/variable.h"
#include "src/tint/type/external_texture.h"
#include "src/tint/utils/hash.h"
#include "src/tint/writer/flatten_bindings.h"
@ -256,6 +261,49 @@ int CommonFuzzer::Run(const uint8_t* data, size_t size) {
}
}
// For the generates which use MultiPlanar, make sure the configuration options are provided so
// that the transformer will execute.
if (output_ == OutputFormat::kMSL || output_ == OutputFormat::kHLSL) {
// Gather external texture binding information
// Collect next valid binding number per group
std::unordered_map<uint32_t, uint32_t> group_to_next_binding_number;
std::vector<sem::BindingPoint> ext_tex_bps;
for (auto* var : program.AST().GlobalVariables()) {
if (auto* sem_var = program.Sem().Get(var)->As<sem::GlobalVariable>()) {
auto bp = sem_var->BindingPoint();
auto& n = group_to_next_binding_number[bp.group];
n = std::max(n, bp.binding + 1);
if (sem_var->Type()->UnwrapRef()->Is<type::ExternalTexture>()) {
ext_tex_bps.emplace_back(bp);
}
}
}
writer::ExternalTextureOptions::BindingsMap new_bindings_map;
for (auto bp : ext_tex_bps) {
uint32_t g = bp.group;
uint32_t& next_num = group_to_next_binding_number[g];
auto new_bps =
writer::ExternalTextureOptions::BindingPoints{{g, next_num++}, {g, next_num++}};
new_bindings_map[bp] = new_bps;
}
switch (output_) {
case OutputFormat::kMSL: {
options_msl_.external_texture_options.bindings_map = new_bindings_map;
break;
}
case OutputFormat::kHLSL: {
options_hlsl_.external_texture_options.bindings_map = new_bindings_map;
break;
}
default:
break;
}
}
switch (output_) {
case OutputFormat::kWGSL: {
#if TINT_BUILD_WGSL_WRITER