• 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_INSPECTOR_ENTRY_POINT_H_
16 #define SRC_INSPECTOR_ENTRY_POINT_H_
17 
18 #include <string>
19 #include <tuple>
20 #include <vector>
21 
22 #include "src/ast/interpolate_decoration.h"
23 #include "src/ast/pipeline_stage.h"
24 
25 namespace tint {
26 namespace inspector {
27 
28 /// Base component type of a stage variable.
29 enum class ComponentType {
30   kUnknown = -1,
31   kFloat,
32   kUInt,
33   kSInt,
34 };
35 
36 /// Composition of components of a stage variable.
37 enum class CompositionType {
38   kUnknown = -1,
39   kScalar,
40   kVec2,
41   kVec3,
42   kVec4,
43 };
44 
45 /// Type of interpolation of a stage variable.
46 enum class InterpolationType { kUnknown = -1, kPerspective, kLinear, kFlat };
47 
48 /// Type of interpolation sampling of a stage variable.
49 enum class InterpolationSampling {
50   kUnknown = -1,
51   kNone,
52   kCenter,
53   kCentroid,
54   kSample
55 };
56 
57 /// Reflection data about an entry point input or output.
58 struct StageVariable {
59   /// Name of the variable in the shader.
60   std::string name;
61   /// Is Location Decoration present
62   bool has_location_decoration = false;
63   /// Value of Location Decoration, only valid if |has_location_decoration| is
64   /// true.
65   uint32_t location_decoration;
66   /// Scalar type that the variable is composed of.
67   ComponentType component_type = ComponentType::kUnknown;
68   /// How the scalars are composed for the variable.
69   CompositionType composition_type = CompositionType::kUnknown;
70   /// Interpolation type of the variable.
71   InterpolationType interpolation_type = InterpolationType::kUnknown;
72   /// Interpolation sampling of the variable.
73   InterpolationSampling interpolation_sampling =
74       InterpolationSampling::kUnknown;
75 };
76 
77 /// Convert from internal ast::InterpolationType to public ::InterpolationType.
78 /// @param ast_type internal value to convert from
79 /// @returns the publicly visible equivalent
80 InterpolationType ASTToInspectorInterpolationType(
81     ast::InterpolationType ast_type);
82 
83 /// Convert from internal ast::InterpolationSampling to public
84 /// ::InterpolationSampling
85 /// @param sampling internal value to convert from
86 /// @returns the publicly visible equivalent
87 InterpolationSampling ASTToInspectorInterpolationSampling(
88     ast::InterpolationSampling sampling);
89 
90 /// Reflection data about a pipeline overridable constant referenced by an entry
91 /// point
92 struct OverridableConstant {
93   /// Name of the constant
94   std::string name;
95 
96   /// ID of the constant
97   uint16_t numeric_id;
98 
99   /// Type of the scalar
100   enum class Type {
101     kBool,
102     kFloat32,
103     kUint32,
104     kInt32,
105   };
106 
107   /// Type of the scalar
108   Type type;
109 
110   /// Does this pipeline overridable constant have an initializer?
111   bool is_initialized = false;
112 
113   /// Does this pipeline overridable constant have a numeric ID specified
114   /// explicitly?
115   bool is_numeric_id_specified = false;
116 };
117 
118 /// Reflection data for an entry point in the shader.
119 struct EntryPoint {
120   /// Constructors
121   EntryPoint();
122   /// Copy Constructor
123   EntryPoint(EntryPoint&);
124   /// Move Constructor
125   EntryPoint(EntryPoint&&);
126   ~EntryPoint();
127 
128   /// The entry point name
129   std::string name;
130   /// Remapped entry point name in the backend
131   std::string remapped_name;
132   /// The entry point stage
133   ast::PipelineStage stage = ast::PipelineStage::kNone;
134   /// The workgroup x size
135   uint32_t workgroup_size_x = 0;
136   /// The workgroup y size
137   uint32_t workgroup_size_y = 0;
138   /// The workgroup z size
139   uint32_t workgroup_size_z = 0;
140   /// List of the input variable accessed via this entry point.
141   std::vector<StageVariable> input_variables;
142   /// List of the output variable accessed via this entry point.
143   std::vector<StageVariable> output_variables;
144   /// List of the pipeline overridable constants accessed via this entry point.
145   std::vector<OverridableConstant> overridable_constants;
146   /// Does the entry point use the sample_mask builtin as an input builtin
147   /// variable.
148   bool input_sample_mask_used = false;
149   /// Does the entry point use the sample_mask builtin as an output builtin
150   /// variable.
151   bool output_sample_mask_used = false;
152   /// Does the entry point use the position builtin as an input builtin
153   /// variable.
154   bool input_position_used = false;
155   /// Does the entry point use the front_facing builtin
156   bool front_facing_used = false;
157   /// Does the entry point use the sample_index builtin
158   bool sample_index_used = false;
159   /// Does the entry point use the num_workgroups builtin
160   bool num_workgroups_used = false;
161 
162   /// @returns the size of the workgroup in {x,y,z} format
workgroup_sizeEntryPoint163   std::tuple<uint32_t, uint32_t, uint32_t> workgroup_size() {
164     return std::tuple<uint32_t, uint32_t, uint32_t>(
165         workgroup_size_x, workgroup_size_y, workgroup_size_z);
166   }
167 };
168 
169 }  // namespace inspector
170 }  // namespace tint
171 
172 #endif  // SRC_INSPECTOR_ENTRY_POINT_H_
173