diff --git a/src/tint/BUILD.gn b/src/tint/BUILD.gn index a9871da121..8d6a3b1dfa 100644 --- a/src/tint/BUILD.gn +++ b/src/tint/BUILD.gn @@ -659,6 +659,7 @@ libtint_source_set("libtint_sem_src") { "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 @@ libtint_source_set("libtint_writer_src") { "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 91f81786a8..db51dfbaa0 100644 --- a/src/tint/CMakeLists.txt +++ b/src/tint/CMakeLists.txt @@ -301,6 +301,7 @@ list(APPEND TINT_LIB_SRCS 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 @@ list(APPEND TINT_LIB_SRCS 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 0000000000..2ad5673069 --- /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 + +#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; + +} // 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 625c756861..656d0adae9 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 @@ class MultiplanarExternalTexture final : public Castable; + 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 7fd6e63b75..275867f54f 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 0000000000..e5ea26f360 --- /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 0000000000..926eabd1e2 --- /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 + +#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 2bb4b03979..5c2de66e68 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 @@ struct Options { /// 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 @@ struct Options { 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 74d79ba15b..1c072d8958 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 @@ struct Options { /// 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 @@ struct Options { 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 1add25957a..e58ef9e49f 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 @@ struct Options { /// 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 @@ struct Options { 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 8b34032a98..11660fe6e5 100644 --- a/src/tint/writer/spirv/generator.h +++ b/src/tint/writer/spirv/generator.h @@ -20,6 +20,7 @@ #include #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 @@ struct Options { /// 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 @@ struct Options { emit_vertex_point_size, disable_workgroup_init, generate_external_texture_bindings, + external_texture_options, use_zero_initialize_workgroup_memory_extension); };