• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 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_WRITER_HLSL_GENERATOR_H_
16 #define SRC_WRITER_HLSL_GENERATOR_H_
17 
18 #include <memory>
19 #include <string>
20 #include <unordered_set>
21 #include <utility>
22 #include <vector>
23 
24 #include "src/ast/pipeline_stage.h"
25 #include "src/sem/binding_point.h"
26 #include "src/writer/array_length_from_uniform_options.h"
27 #include "src/writer/text.h"
28 
29 namespace tint {
30 
31 // Forward declarations
32 class Program;
33 
34 namespace writer {
35 namespace hlsl {
36 
37 // Forward declarations
38 class GeneratorImpl;
39 
40 /// Configuration options used for generating HLSL.
41 struct Options {
42   /// Constructor
43   Options();
44   /// Destructor
45   ~Options();
46   /// Copy constructor
47   Options(const Options&);
48   /// Copy assignment
49   /// @returns this Options
50   Options& operator=(const Options&);
51 
52   /// The binding point to use for information passed via root constants.
53   sem::BindingPoint root_constant_binding_point;
54   /// Set to `true` to disable workgroup memory zero initialization
55   bool disable_workgroup_init = false;
56   /// Options used to specify a mapping of binding points to indices into a UBO
57   /// from which to load buffer sizes.
58   ArrayLengthFromUniformOptions array_length_from_uniform = {};
59 
60   // NOTE: Update fuzzers/data_builder.h when adding or changing any struct
61   // members.
62 };
63 
64 /// The result produced when generating HLSL.
65 struct Result {
66   /// Constructor
67   Result();
68 
69   /// Destructor
70   ~Result();
71 
72   /// Copy constructor
73   Result(const Result&);
74 
75   /// True if generation was successful.
76   bool success = false;
77 
78   /// The errors generated during code generation, if any.
79   std::string error;
80 
81   /// The generated HLSL.
82   std::string hlsl = "";
83 
84   /// The list of entry points in the generated HLSL.
85   std::vector<std::pair<std::string, ast::PipelineStage>> entry_points;
86 
87   /// Indices into the array_length_from_uniform binding that are statically
88   /// used.
89   std::unordered_set<uint32_t> used_array_length_from_uniform_indices;
90 };
91 
92 /// Generate HLSL for a program, according to a set of configuration options.
93 /// The result will contain the HLSL, as well as success status and diagnostic
94 /// information.
95 /// @param program the program to translate to HLSL
96 /// @param options the configuration options to use when generating HLSL
97 /// @returns the resulting HLSL and supplementary information
98 Result Generate(const Program* program, const Options& options);
99 
100 }  // namespace hlsl
101 }  // namespace writer
102 }  // namespace tint
103 
104 #endif  // SRC_WRITER_HLSL_GENERATOR_H_
105