[glsl] Use GenerateBindings() for texture-builtins-from-uniform
This avoids duplicating the code for generating this across the main
Tint exe, the benchmark, and the fuzzer.
Since GenerateBindings operates on an IR module, we do not have an
Inspector to get the texture queries. Instead, just adding entries for
every texture in the module.
The benchmark can now just generate one set of options for all entry
points, so simplify that logic a bit too.
Bug: 375388105
Change-Id: I9e5685d0bf9ac20c99a08a54faa6cc5cbce92221
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/213377
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
diff --git a/src/tint/cmd/tint/main.cc b/src/tint/cmd/tint/main.cc
index 5eaa55c..f9403bd 100644
--- a/src/tint/cmd/tint/main.cc
+++ b/src/tint/cmd/tint/main.cc
@@ -1095,21 +1095,6 @@
// Generate binding options.
gen_options.bindings = tint::glsl::writer::GenerateBindings(ir.Get());
- constexpr uint32_t kMaxBindGroups = 4u;
- gen_options.bindings.texture_builtins_from_uniform.ubo_binding = {kMaxBindGroups, 0u};
-
- auto textureBuiltinsFromUniformData = inspector.GetTextureQueries(entry_point_name);
- if (!textureBuiltinsFromUniformData.empty()) {
- for (size_t i = 0; i < textureBuiltinsFromUniformData.size(); ++i) {
- const auto& info = textureBuiltinsFromUniformData[i];
-
- // This is the unmodified binding point from the WGSL shader.
- tint::BindingPoint srcBindingPoint{info.group, info.binding};
- gen_options.bindings.texture_builtins_from_uniform.ubo_bindingpoint_ordering
- .emplace_back(srcBindingPoint);
- }
- }
-
// Generate GLSL.
auto result = tint::glsl::writer::Generate(ir.Get(), gen_options, "");
if (result != tint::Success) {
diff --git a/src/tint/lang/glsl/writer/helpers/generate_bindings.cc b/src/tint/lang/glsl/writer/helpers/generate_bindings.cc
index 0c6645b..c159695 100644
--- a/src/tint/lang/glsl/writer/helpers/generate_bindings.cc
+++ b/src/tint/lang/glsl/writer/helpers/generate_bindings.cc
@@ -46,6 +46,10 @@
std::unordered_set<tint::BindingPoint> seen_binding_points;
+ // Set a binding point for the texture-builtins-from-uniform buffer.
+ constexpr uint32_t kMaxBindGroups = 4u;
+ bindings.texture_builtins_from_uniform.ubo_binding = {kMaxBindGroups, 0u};
+
// Collect next valid binding number per group
Hashmap<uint32_t, uint32_t, 4> group_to_next_binding_number;
Vector<tint::BindingPoint, 4> ext_tex_bps;
@@ -60,6 +64,11 @@
auto* ptr_type = var->Result(0)->Type()->As<core::type::Pointer>();
+ // Add all texture variables to the texture-builtin-from-uniform map.
+ if (ptr_type->StoreType()->Is<core::type::Texture>()) {
+ bindings.texture_builtins_from_uniform.ubo_bindingpoint_ordering.emplace_back(*bp);
+ }
+
// Store up the external textures, we'll add them in the next step
if (ptr_type->StoreType()->Is<core::type::ExternalTexture>()) {
ext_tex_bps.Push(*bp);
diff --git a/src/tint/lang/glsl/writer/writer_bench.cc b/src/tint/lang/glsl/writer/writer_bench.cc
index aeea055..73a584e 100644
--- a/src/tint/lang/glsl/writer/writer_bench.cc
+++ b/src/tint/lang/glsl/writer/writer_bench.cc
@@ -47,37 +47,23 @@
return;
}
- // Populate the generator options for each entry point.
- std::vector<Options> options;
std::vector<std::string> names;
- tint::inspector::Inspector inspector(res->program);
-
- for (auto ep : inspector.GetEntryPoints()) {
+ tint::glsl::writer::Options gen_options = {};
+ {
// Convert the AST program to an IR module, so that we can generating bindings data.
auto ir = tint::wgsl::reader::ProgramToLoweredIR(res->program);
if (ir != Success) {
state.SkipWithError(ir.Failure().reason.Str());
return;
}
-
- tint::glsl::writer::Options gen_options = {};
gen_options.bindings = tint::glsl::writer::GenerateBindings(ir.Get());
- gen_options.bindings.texture_builtins_from_uniform.ubo_binding = {4u, 0u};
- auto textureBuiltinsFromUniformData = inspector.GetTextureQueries(ep.name);
- if (!textureBuiltinsFromUniformData.empty()) {
- for (size_t i = 0; i < textureBuiltinsFromUniformData.size(); ++i) {
- const auto& info = textureBuiltinsFromUniformData[i];
-
- // This is the unmodified binding point from the WGSL shader.
- tint::BindingPoint srcBindingPoint{info.group, info.binding};
- gen_options.bindings.texture_builtins_from_uniform.ubo_bindingpoint_ordering
- .emplace_back(srcBindingPoint);
+ // Get the list of entry point names.
+ for (auto func : ir->functions) {
+ if (func->Stage() != core::ir::Function::PipelineStage::kUndefined) {
+ names.push_back(ir->NameOf(func).Name());
}
}
-
- options.push_back(gen_options);
- names.push_back(ep.name);
}
for (auto _ : state) {
@@ -97,7 +83,7 @@
}
// Generate GLSL.
- auto gen_res = Generate(ir.Get(), options[i], names[i]);
+ auto gen_res = Generate(ir.Get(), gen_options, names[i]);
if (gen_res != Success) {
state.SkipWithError(gen_res.Failure().reason.Str());
}