Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 1 | // Copyright 2021 The Tint Authors. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #ifndef SRC_TINT_TRANSFORM_BINDING_REMAPPER_H_ |
| 16 | #define SRC_TINT_TRANSFORM_BINDING_REMAPPER_H_ |
| 17 | |
| 18 | #include <unordered_map> |
| 19 | |
dan sinclair | b6cc4cb | 2023-02-19 04:01:29 +0000 | [diff] [blame] | 20 | #include "src/tint/builtin/access.h" |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 21 | #include "src/tint/sem/binding_point.h" |
| 22 | #include "src/tint/transform/transform.h" |
| 23 | |
dan sinclair | b5599d3 | 2022-04-07 16:55:14 +0000 | [diff] [blame] | 24 | namespace tint::transform { |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 25 | |
| 26 | /// BindingPoint is an alias to sem::BindingPoint |
| 27 | using BindingPoint = sem::BindingPoint; |
| 28 | |
| 29 | /// BindingRemapper is a transform used to remap resource binding points and |
| 30 | /// access controls. |
Ben Clayton | 41f8d2a | 2022-03-07 18:37:46 +0000 | [diff] [blame] | 31 | class BindingRemapper final : public Castable<BindingRemapper, Transform> { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 32 | public: |
| 33 | /// BindingPoints is a map of old binding point to new binding point |
| 34 | using BindingPoints = std::unordered_map<BindingPoint, BindingPoint>; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 35 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 36 | /// AccessControls is a map of old binding point to new access control |
dan sinclair | b6cc4cb | 2023-02-19 04:01:29 +0000 | [diff] [blame] | 37 | using AccessControls = std::unordered_map<BindingPoint, builtin::Access>; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 38 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 39 | /// Remappings is consumed by the BindingRemapper transform. |
| 40 | /// Data holds information about shader usage and constant buffer offsets. |
| 41 | struct Remappings final : public Castable<Data, transform::Data> { |
| 42 | /// Constructor |
| 43 | /// @param bp a map of new binding points |
| 44 | /// @param ac a map of new access controls |
| 45 | /// @param may_collide If true, then validation will be disabled for |
| 46 | /// binding point collisions generated by this transform |
| 47 | Remappings(BindingPoints bp, AccessControls ac, bool may_collide = true); |
| 48 | |
| 49 | /// Copy constructor |
| 50 | Remappings(const Remappings&); |
| 51 | |
| 52 | /// Destructor |
| 53 | ~Remappings() override; |
| 54 | |
| 55 | /// A map of old binding point to new binding point |
| 56 | const BindingPoints binding_points; |
| 57 | |
| 58 | /// A map of old binding point to new access controls |
| 59 | const AccessControls access_controls; |
| 60 | |
| 61 | /// If true, then validation will be disabled for binding point collisions |
| 62 | /// generated by this transform |
| 63 | const bool allow_collisions; |
| 64 | }; |
| 65 | |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 66 | /// Constructor |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 67 | BindingRemapper(); |
| 68 | ~BindingRemapper() override; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 69 | |
Ben Clayton | c6b3814 | 2022-11-03 08:41:19 +0000 | [diff] [blame] | 70 | /// @copydoc Transform::Apply |
| 71 | ApplyResult Apply(const Program* program, |
| 72 | const DataMap& inputs, |
| 73 | DataMap& outputs) const override; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 74 | }; |
| 75 | |
dan sinclair | b5599d3 | 2022-04-07 16:55:14 +0000 | [diff] [blame] | 76 | } // namespace tint::transform |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 77 | |
| 78 | #endif // SRC_TINT_TRANSFORM_BINDING_REMAPPER_H_ |