• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_TRANSFORM_BINDING_REMAPPER_H_
16 #define SRC_TRANSFORM_BINDING_REMAPPER_H_
17 
18 #include <unordered_map>
19 
20 #include "src/ast/access.h"
21 #include "src/sem/binding_point.h"
22 #include "src/transform/transform.h"
23 
24 namespace tint {
25 namespace transform {
26 
27 /// BindingPoint is an alias to sem::BindingPoint
28 using BindingPoint = sem::BindingPoint;
29 
30 /// BindingRemapper is a transform used to remap resource binding points and
31 /// access controls.
32 class BindingRemapper : public Castable<BindingRemapper, Transform> {
33  public:
34   /// BindingPoints is a map of old binding point to new binding point
35   using BindingPoints = std::unordered_map<BindingPoint, BindingPoint>;
36 
37   /// AccessControls is a map of old binding point to new access control
38   using AccessControls = std::unordered_map<BindingPoint, ast::Access>;
39 
40   /// Remappings is consumed by the BindingRemapper transform.
41   /// Data holds information about shader usage and constant buffer offsets.
42   struct Remappings : public Castable<Data, transform::Data> {
43     /// Constructor
44     /// @param bp a map of new binding points
45     /// @param ac a map of new access controls
46     /// @param may_collide If true, then validation will be disabled for
47     /// binding point collisions generated by this transform
48     Remappings(BindingPoints bp, AccessControls ac, bool may_collide = true);
49 
50     /// Copy constructor
51     Remappings(const Remappings&);
52 
53     /// Destructor
54     ~Remappings() override;
55 
56     /// A map of old binding point to new binding point
57     const BindingPoints binding_points;
58 
59     /// A map of old binding point to new access controls
60     const AccessControls access_controls;
61 
62     /// If true, then validation will be disabled for binding point collisions
63     /// generated by this transform
64     const bool allow_collisions;
65   };
66 
67   /// Constructor
68   BindingRemapper();
69   ~BindingRemapper() override;
70 
71  protected:
72   /// Runs the transform using the CloneContext built for transforming a
73   /// program. Run() is responsible for calling Clone() on the CloneContext.
74   /// @param ctx the CloneContext primed with the input program and
75   /// ProgramBuilder
76   /// @param inputs optional extra transform-specific input data
77   /// @param outputs optional extra transform-specific output data
78   void Run(CloneContext& ctx, const DataMap& inputs, DataMap& outputs) override;
79 };
80 
81 }  // namespace transform
82 }  // namespace tint
83 
84 #endif  // SRC_TRANSFORM_BINDING_REMAPPER_H_
85