blob: 8fdba2a208f3e0eccd657eae46bb66784cca3b5a [file] [log] [blame]
Ryan Harrisondbc13af2022-02-21 15:19:07 +00001// 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 sinclairb6cc4cb2023-02-19 04:01:29 +000020#include "src/tint/builtin/access.h"
Ryan Harrisondbc13af2022-02-21 15:19:07 +000021#include "src/tint/sem/binding_point.h"
22#include "src/tint/transform/transform.h"
23
dan sinclairb5599d32022-04-07 16:55:14 +000024namespace tint::transform {
Ryan Harrisondbc13af2022-02-21 15:19:07 +000025
26/// BindingPoint is an alias to sem::BindingPoint
27using BindingPoint = sem::BindingPoint;
28
29/// BindingRemapper is a transform used to remap resource binding points and
30/// access controls.
Ben Clayton41f8d2a2022-03-07 18:37:46 +000031class BindingRemapper final : public Castable<BindingRemapper, Transform> {
dan sinclair41e4d9a2022-05-01 14:40:55 +000032 public:
33 /// BindingPoints is a map of old binding point to new binding point
34 using BindingPoints = std::unordered_map<BindingPoint, BindingPoint>;
Ryan Harrisondbc13af2022-02-21 15:19:07 +000035
dan sinclair41e4d9a2022-05-01 14:40:55 +000036 /// AccessControls is a map of old binding point to new access control
dan sinclairb6cc4cb2023-02-19 04:01:29 +000037 using AccessControls = std::unordered_map<BindingPoint, builtin::Access>;
Ryan Harrisondbc13af2022-02-21 15:19:07 +000038
dan sinclair41e4d9a2022-05-01 14:40:55 +000039 /// 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 Harrisondbc13af2022-02-21 15:19:07 +000066 /// Constructor
dan sinclair41e4d9a2022-05-01 14:40:55 +000067 BindingRemapper();
68 ~BindingRemapper() override;
Ryan Harrisondbc13af2022-02-21 15:19:07 +000069
Ben Claytonc6b38142022-11-03 08:41:19 +000070 /// @copydoc Transform::Apply
71 ApplyResult Apply(const Program* program,
72 const DataMap& inputs,
73 DataMap& outputs) const override;
Ryan Harrisondbc13af2022-02-21 15:19:07 +000074};
75
dan sinclairb5599d32022-04-07 16:55:14 +000076} // namespace tint::transform
Ryan Harrisondbc13af2022-02-21 15:19:07 +000077
78#endif // SRC_TINT_TRANSFORM_BINDING_REMAPPER_H_