Add ExternalTextureOptions
This CL adds a `writer/ExternalTextureOptions` to allow providing
external texture information to the generators. The generators are
updated to have the option in their config, but do not use it yet.
Bug: tint:1855 chromium:1421379
Change-Id: I99b122c5cae145e8527158f300da81743f89775a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/123160
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
diff --git a/src/tint/BUILD.gn b/src/tint/BUILD.gn
index a9871da..8d6a3b1 100644
--- a/src/tint/BUILD.gn
+++ b/src/tint/BUILD.gn
@@ -659,6 +659,7 @@
"sem/evaluation_stage.h",
"sem/expression.cc",
"sem/expression.h",
+ "sem/external_texture.h",
"sem/for_loop_statement.cc",
"sem/for_loop_statement.h",
"sem/function.cc",
@@ -899,6 +900,8 @@
"writer/binding_point.h",
"writer/check_supported_extensions.cc",
"writer/check_supported_extensions.h",
+ "writer/external_texture_options.cc",
+ "writer/external_texture_options.h",
"writer/flatten_bindings.cc",
"writer/flatten_bindings.h",
"writer/float_to_string.cc",
diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt
index 91f8178..db51dfb 100644
--- a/src/tint/CMakeLists.txt
+++ b/src/tint/CMakeLists.txt
@@ -301,6 +301,7 @@
sem/evaluation_stage.h
sem/expression.cc
sem/expression.h
+ sem/external_texture.h
sem/for_loop_statement.cc
sem/for_loop_statement.h
sem/function_expression.cc
@@ -543,6 +544,8 @@
writer/binding_point.h
writer/check_supported_extensions.cc
writer/check_supported_extensions.h
+ writer/external_texture_options.cc
+ writer/external_texture_options.h
writer/flatten_bindings.cc
writer/flatten_bindings.h
writer/float_to_string.cc
diff --git a/src/tint/sem/external_texture.h b/src/tint/sem/external_texture.h
new file mode 100644
index 0000000..2ad5673
--- /dev/null
+++ b/src/tint/sem/external_texture.h
@@ -0,0 +1,45 @@
+// Copyright 2023 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef SRC_TINT_SEM_EXTERNAL_TEXTURE_H_
+#define SRC_TINT_SEM_EXTERNAL_TEXTURE_H_
+
+#include <unordered_map>
+
+#include "src/tint/sem/binding_point.h"
+
+namespace tint::sem::external_texture {
+
+/// This struct identifies the binding groups and locations for new bindings to
+/// use when transforming a texture_external instance.
+struct BindingPoints {
+ /// The desired binding location of the texture_2d representing plane #1 when
+ /// a texture_external binding is expanded.
+ BindingPoint plane_1;
+ /// The desired binding location of the ExternalTextureParams uniform when a
+ /// texture_external binding is expanded.
+ BindingPoint params;
+
+ /// Reflect the fields of this class so that it can be used by tint::ForeachField()
+ TINT_REFLECT(plane_1, params);
+};
+
+/// BindingsMap is a map where the key is the binding location of a
+/// texture_external and the value is a struct containing the desired
+/// locations for new bindings expanded from the texture_external instance.
+using BindingsMap = std::unordered_map<BindingPoint, BindingPoints>;
+
+} // namespace tint::sem::external_texture
+
+#endif // SRC_TINT_SEM_EXTERNAL_TEXTURE_H_
diff --git a/src/tint/transform/multiplanar_external_texture.h b/src/tint/transform/multiplanar_external_texture.h
index 625c756..656d0ad 100644
--- a/src/tint/transform/multiplanar_external_texture.h
+++ b/src/tint/transform/multiplanar_external_texture.h
@@ -21,6 +21,7 @@
#include "src/tint/ast/struct_member.h"
#include "src/tint/builtin/function.h"
#include "src/tint/sem/binding_point.h"
+#include "src/tint/sem/external_texture.h"
#include "src/tint/transform/transform.h"
namespace tint::transform {
@@ -40,22 +41,12 @@
public:
/// This struct identifies the binding groups and locations for new bindings to
/// use when transforming a texture_external instance.
- struct BindingPoints {
- /// The desired binding location of the texture_2d representing plane #1 when
- /// a texture_external binding is expanded.
- sem::BindingPoint plane_1;
- /// The desired binding location of the ExternalTextureParams uniform when a
- /// texture_external binding is expanded.
- sem::BindingPoint params;
-
- /// Reflect the fields of this class so that it can be used by tint::ForeachField()
- TINT_REFLECT(plane_1, params);
- };
+ using BindingPoints = sem::external_texture::BindingPoints;
/// BindingsMap is a map where the key is the binding location of a
/// texture_external and the value is a struct containing the desired
/// locations for new bindings expanded from the texture_external instance.
- using BindingsMap = std::unordered_map<sem::BindingPoint, BindingPoints>;
+ using BindingsMap = sem::external_texture::BindingsMap;
/// NewBindingPoints is consumed by the MultiplanarExternalTexture transform.
/// Data holds information about location of each texture_external binding and
diff --git a/src/tint/writer/array_length_from_uniform_options.cc b/src/tint/writer/array_length_from_uniform_options.cc
index 7fd6e63..275867f 100644
--- a/src/tint/writer/array_length_from_uniform_options.cc
+++ b/src/tint/writer/array_length_from_uniform_options.cc
@@ -17,11 +17,15 @@
namespace tint::writer {
ArrayLengthFromUniformOptions::ArrayLengthFromUniformOptions() = default;
+
ArrayLengthFromUniformOptions::~ArrayLengthFromUniformOptions() = default;
+
ArrayLengthFromUniformOptions::ArrayLengthFromUniformOptions(const ArrayLengthFromUniformOptions&) =
default;
+
ArrayLengthFromUniformOptions& ArrayLengthFromUniformOptions::operator=(
const ArrayLengthFromUniformOptions&) = default;
+
ArrayLengthFromUniformOptions::ArrayLengthFromUniformOptions(ArrayLengthFromUniformOptions&&) =
default;
diff --git a/src/tint/writer/external_texture_options.cc b/src/tint/writer/external_texture_options.cc
new file mode 100644
index 0000000..e5ea26f
--- /dev/null
+++ b/src/tint/writer/external_texture_options.cc
@@ -0,0 +1,29 @@
+// Copyright 2023 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "src/tint/writer/external_texture_options.h"
+
+namespace tint::writer {
+
+ExternalTextureOptions::ExternalTextureOptions() = default;
+
+ExternalTextureOptions::~ExternalTextureOptions() = default;
+
+ExternalTextureOptions::ExternalTextureOptions(const ExternalTextureOptions&) = default;
+
+ExternalTextureOptions& ExternalTextureOptions::operator=(const ExternalTextureOptions&) = default;
+
+ExternalTextureOptions::ExternalTextureOptions(ExternalTextureOptions&&) = default;
+
+} // namespace tint::writer
diff --git a/src/tint/writer/external_texture_options.h b/src/tint/writer/external_texture_options.h
new file mode 100644
index 0000000..926eabd
--- /dev/null
+++ b/src/tint/writer/external_texture_options.h
@@ -0,0 +1,57 @@
+// Copyright 2023 The Tint Authors.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef SRC_TINT_WRITER_EXTERNAL_TEXTURE_OPTIONS_H_
+#define SRC_TINT_WRITER_EXTERNAL_TEXTURE_OPTIONS_H_
+
+#include <unordered_map>
+
+#include "src/tint/sem/external_texture.h"
+
+namespace tint::writer {
+
+/// Options used to specify mappings of binding points for external textures.
+class ExternalTextureOptions {
+ public:
+ /// This struct identifies the binding groups and locations for new bindings to
+ /// use when transforming a texture_external instance.
+ using BindingPoints = sem::external_texture::BindingPoints;
+
+ /// BindingsMap is a map where the key is the binding location of a
+ /// texture_external and the value is a struct containing the desired
+ /// locations for new bindings expanded from the texture_external instance.
+ using BindingsMap = sem::external_texture::BindingsMap;
+
+ /// Constructor
+ ExternalTextureOptions();
+ /// Destructor
+ ~ExternalTextureOptions();
+ /// Copy constructor
+ ExternalTextureOptions(const ExternalTextureOptions&);
+ /// Copy assignment
+ /// @returns this ExternalTextureOptions
+ ExternalTextureOptions& operator=(const ExternalTextureOptions&);
+ /// Move constructor
+ ExternalTextureOptions(ExternalTextureOptions&&);
+
+ /// A map of new binding points to use.
+ BindingsMap bindings_map;
+
+ /// Reflect the fields of this class so that it can be used by tint::ForeachField()
+ TINT_REFLECT(bindings_map);
+};
+
+} // namespace tint::writer
+
+#endif // SRC_TINT_WRITER_EXTERNAL_TEXTURE_OPTIONS_H_
diff --git a/src/tint/writer/glsl/generator.h b/src/tint/writer/glsl/generator.h
index 2bb4b03..5c2de66 100644
--- a/src/tint/writer/glsl/generator.h
+++ b/src/tint/writer/glsl/generator.h
@@ -25,6 +25,7 @@
#include "src/tint/builtin/access.h"
#include "src/tint/sem/binding_point.h"
#include "src/tint/sem/sampler_texture_pair.h"
+#include "src/tint/writer/external_texture_options.h"
#include "src/tint/writer/glsl/version.h"
#include "src/tint/writer/text.h"
@@ -76,6 +77,9 @@
/// Set to 'true' to generates binding mappings for external textures
bool generate_external_texture_bindings = false;
+ /// Options used in the binding mappings for external textures
+ ExternalTextureOptions external_texture_options = {};
+
/// The GLSL version to emit
Version version;
@@ -84,6 +88,7 @@
allow_collisions,
disable_workgroup_init,
generate_external_texture_bindings,
+ external_texture_options,
version);
};
diff --git a/src/tint/writer/hlsl/generator.h b/src/tint/writer/hlsl/generator.h
index 74d79ba..1c072d8 100644
--- a/src/tint/writer/hlsl/generator.h
+++ b/src/tint/writer/hlsl/generator.h
@@ -28,6 +28,7 @@
#include "src/tint/sem/binding_point.h"
#include "src/tint/utils/bitset.h"
#include "src/tint/writer/array_length_from_uniform_options.h"
+#include "src/tint/writer/external_texture_options.h"
#include "src/tint/writer/text.h"
// Forward declarations
@@ -61,6 +62,9 @@
/// Set to 'true' to generates binding mappings for external textures
bool generate_external_texture_bindings = false;
+ /// Options used in the binding mappings for external textures
+ ExternalTextureOptions external_texture_options = {};
+
/// Options used to specify a mapping of binding points to indices into a UBO
/// from which to load buffer sizes.
ArrayLengthFromUniformOptions array_length_from_uniform = {};
@@ -77,6 +81,7 @@
root_constant_binding_point,
disable_workgroup_init,
generate_external_texture_bindings,
+ external_texture_options,
array_length_from_uniform);
};
diff --git a/src/tint/writer/msl/generator.h b/src/tint/writer/msl/generator.h
index 1add259..e58ef9e 100644
--- a/src/tint/writer/msl/generator.h
+++ b/src/tint/writer/msl/generator.h
@@ -23,6 +23,7 @@
#include "src/tint/reflection.h"
#include "src/tint/writer/array_length_from_uniform_options.h"
+#include "src/tint/writer/external_texture_options.h"
#include "src/tint/writer/text.h"
// Forward declarations
@@ -65,6 +66,9 @@
/// Set to 'true' to generates binding mappings for external textures
bool generate_external_texture_bindings = false;
+ /// Options used in the binding mappings for external textures
+ ExternalTextureOptions external_texture_options = {};
+
/// Options used to specify a mapping of binding points to indices into a UBO
/// from which to load buffer sizes.
ArrayLengthFromUniformOptions array_length_from_uniform = {};
@@ -76,6 +80,7 @@
emit_vertex_point_size,
disable_workgroup_init,
generate_external_texture_bindings,
+ external_texture_options,
array_length_from_uniform);
};
diff --git a/src/tint/writer/spirv/generator.h b/src/tint/writer/spirv/generator.h
index 8b34032..11660fe 100644
--- a/src/tint/writer/spirv/generator.h
+++ b/src/tint/writer/spirv/generator.h
@@ -20,6 +20,7 @@
#include <vector>
#include "src/tint/reflection.h"
+#include "src/tint/writer/external_texture_options.h"
#include "src/tint/writer/writer.h"
// Forward declarations
@@ -48,6 +49,9 @@
/// Set to 'true' to generates binding mappings for external textures
bool generate_external_texture_bindings = false;
+ /// Options used in the binding mappings for external textures
+ ExternalTextureOptions external_texture_options = {};
+
/// Set to `true` to initialize workgroup memory with OpConstantNull when
/// VK_KHR_zero_initialize_workgroup_memory is enabled.
bool use_zero_initialize_workgroup_memory_extension = false;
@@ -57,6 +61,7 @@
emit_vertex_point_size,
disable_workgroup_init,
generate_external_texture_bindings,
+ external_texture_options,
use_zero_initialize_workgroup_memory_extension);
};