• 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_GLSL_H_
16 #define SRC_TRANSFORM_GLSL_H_
17 
18 #include <string>
19 
20 #include "src/transform/transform.h"
21 
22 namespace tint {
23 
24 // Forward declarations
25 class CloneContext;
26 
27 namespace transform {
28 
29 /// Glsl is a transform used to sanitize a Program for use with the Glsl writer.
30 /// Passing a non-sanitized Program to the Glsl writer will result in undefined
31 /// behavior.
32 class Glsl : public Castable<Glsl, Transform> {
33  public:
34   /// Configuration options for the Glsl sanitizer transform.
35   struct Config : public Castable<Data, transform::Data> {
36     /// Constructor
37     /// @param entry_point the root entry point function to generate
38     /// @param disable_workgroup_init `true` to disable workgroup memory zero
39     ///        initialization
40     explicit Config(const std::string& entry_point,
41                     bool disable_workgroup_init = false);
42 
43     /// Copy constructor
44     Config(const Config&);
45 
46     /// Destructor
47     ~Config() override;
48 
49     /// GLSL generator wraps a single entry point in a main() function.
50     std::string entry_point;
51 
52     /// Set to `true` to disable workgroup memory zero initialization
53     bool disable_workgroup_init = false;
54   };
55 
56   /// Constructor
57   Glsl();
58   ~Glsl() override;
59 
60   /// Runs the transform on `program`, returning the transformation result.
61   /// @param program the source program to transform
62   /// @param data optional extra transform-specific data
63   /// @returns the transformation result
64   Output Run(const Program* program, const DataMap& data = {}) override;
65 
66  private:
67   /// Add an empty shader entry point if none exist in the module.
68   void AddEmptyEntryPoint(CloneContext& ctx) const;
69 };
70 
71 }  // namespace transform
72 }  // namespace tint
73 
74 #endif  // SRC_TRANSFORM_GLSL_H_
75