blob: b9ac4e429e02031dee00cb678c7dde6b25387f21 [file] [log] [blame]
Ryan Harrisondbc13af2022-02-21 15:19:07 +00001// 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_TINT_INSPECTOR_ENTRY_POINT_H_
16#define SRC_TINT_INSPECTOR_ENTRY_POINT_H_
17
18#include <string>
19#include <tuple>
20#include <vector>
21
22#include "src/tint/ast/interpolate_attribute.h"
23#include "src/tint/ast/pipeline_stage.h"
24
dan sinclairaba5a212022-04-07 17:59:54 +000025namespace tint::inspector {
Ryan Harrisondbc13af2022-02-21 15:19:07 +000026
27/// Base component type of a stage variable.
28enum class ComponentType {
dan sinclair41e4d9a2022-05-01 14:40:55 +000029 kUnknown = -1,
30 kFloat,
31 kUInt,
32 kSInt,
Ryan Harrisondbc13af2022-02-21 15:19:07 +000033};
34
35/// Composition of components of a stage variable.
36enum class CompositionType {
dan sinclair41e4d9a2022-05-01 14:40:55 +000037 kUnknown = -1,
38 kScalar,
39 kVec2,
40 kVec3,
41 kVec4,
Ryan Harrisondbc13af2022-02-21 15:19:07 +000042};
43
44/// Type of interpolation of a stage variable.
45enum class InterpolationType { kUnknown = -1, kPerspective, kLinear, kFlat };
46
47/// Type of interpolation sampling of a stage variable.
dan sinclair41e4d9a2022-05-01 14:40:55 +000048enum class InterpolationSampling { kUnknown = -1, kNone, kCenter, kCentroid, kSample };
Ryan Harrisondbc13af2022-02-21 15:19:07 +000049
50/// Reflection data about an entry point input or output.
51struct StageVariable {
dan sinclair41e4d9a2022-05-01 14:40:55 +000052 /// Constructor
53 StageVariable();
54 /// Copy constructor
55 /// @param other the StageVariable to copy
56 StageVariable(const StageVariable& other);
57 /// Destructor
58 ~StageVariable();
Ryan Harrisondbc13af2022-02-21 15:19:07 +000059
dan sinclair41e4d9a2022-05-01 14:40:55 +000060 /// Name of the variable in the shader.
61 std::string name;
62 /// Is location attribute present
63 bool has_location_attribute = false;
64 /// Value of the location attribute, only valid if #has_location_attribute is
65 /// true.
66 uint32_t location_attribute;
67 /// Is Location attribute present
68 /// [DEPRECATED]: Use #has_location_attribute
69 bool& has_location_decoration = has_location_attribute;
70 /// Value of Location Decoration, only valid if #has_location_decoration is
71 /// true.
72 /// [DEPRECATED]: Use #location_attribute
73 uint32_t& location_decoration = location_attribute;
74 /// Scalar type that the variable is composed of.
75 ComponentType component_type = ComponentType::kUnknown;
76 /// How the scalars are composed for the variable.
77 CompositionType composition_type = CompositionType::kUnknown;
78 /// Interpolation type of the variable.
79 InterpolationType interpolation_type = InterpolationType::kUnknown;
80 /// Interpolation sampling of the variable.
81 InterpolationSampling interpolation_sampling = InterpolationSampling::kUnknown;
Ryan Harrisondbc13af2022-02-21 15:19:07 +000082};
83
84/// Convert from internal ast::InterpolationType to public ::InterpolationType.
85/// @param ast_type internal value to convert from
86/// @returns the publicly visible equivalent
dan sinclair41e4d9a2022-05-01 14:40:55 +000087InterpolationType ASTToInspectorInterpolationType(ast::InterpolationType ast_type);
Ryan Harrisondbc13af2022-02-21 15:19:07 +000088
89/// Convert from internal ast::InterpolationSampling to public
90/// ::InterpolationSampling
91/// @param sampling internal value to convert from
92/// @returns the publicly visible equivalent
dan sinclair41e4d9a2022-05-01 14:40:55 +000093InterpolationSampling ASTToInspectorInterpolationSampling(ast::InterpolationSampling sampling);
Ryan Harrisondbc13af2022-02-21 15:19:07 +000094
95/// Reflection data about a pipeline overridable constant referenced by an entry
96/// point
97struct OverridableConstant {
dan sinclair41e4d9a2022-05-01 14:40:55 +000098 /// Name of the constant
99 std::string name;
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000100
dan sinclair41e4d9a2022-05-01 14:40:55 +0000101 /// ID of the constant
102 uint16_t numeric_id;
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000103
dan sinclair41e4d9a2022-05-01 14:40:55 +0000104 /// Type of the scalar
105 enum class Type {
106 kBool,
107 kFloat32,
108 kUint32,
109 kInt32,
110 };
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000111
dan sinclair41e4d9a2022-05-01 14:40:55 +0000112 /// Type of the scalar
113 Type type;
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000114
dan sinclair41e4d9a2022-05-01 14:40:55 +0000115 /// Does this pipeline overridable constant have an initializer?
116 bool is_initialized = false;
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000117
dan sinclair41e4d9a2022-05-01 14:40:55 +0000118 /// Does this pipeline overridable constant have a numeric ID specified
119 /// explicitly?
120 bool is_numeric_id_specified = false;
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000121};
122
123/// Reflection data for an entry point in the shader.
124struct EntryPoint {
dan sinclair41e4d9a2022-05-01 14:40:55 +0000125 /// Constructors
126 EntryPoint();
127 /// Copy Constructor
128 EntryPoint(EntryPoint&);
129 /// Move Constructor
130 EntryPoint(EntryPoint&&);
131 ~EntryPoint();
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000132
dan sinclair41e4d9a2022-05-01 14:40:55 +0000133 /// The entry point name
134 std::string name;
135 /// Remapped entry point name in the backend
136 std::string remapped_name;
137 /// The entry point stage
138 ast::PipelineStage stage = ast::PipelineStage::kNone;
139 /// The workgroup x size
140 uint32_t workgroup_size_x = 0;
141 /// The workgroup y size
142 uint32_t workgroup_size_y = 0;
143 /// The workgroup z size
144 uint32_t workgroup_size_z = 0;
145 /// List of the input variable accessed via this entry point.
146 std::vector<StageVariable> input_variables;
147 /// List of the output variable accessed via this entry point.
148 std::vector<StageVariable> output_variables;
149 /// List of the pipeline overridable constants accessed via this entry point.
150 std::vector<OverridableConstant> overridable_constants;
151 /// Does the entry point use the sample_mask builtin as an input builtin
152 /// variable.
153 bool input_sample_mask_used = false;
154 /// Does the entry point use the sample_mask builtin as an output builtin
155 /// variable.
156 bool output_sample_mask_used = false;
157 /// Does the entry point use the position builtin as an input builtin
158 /// variable.
159 bool input_position_used = false;
160 /// Does the entry point use the front_facing builtin
161 bool front_facing_used = false;
162 /// Does the entry point use the sample_index builtin
163 bool sample_index_used = false;
164 /// Does the entry point use the num_workgroups builtin
165 bool num_workgroups_used = false;
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000166
dan sinclair41e4d9a2022-05-01 14:40:55 +0000167 /// @returns the size of the workgroup in {x,y,z} format
168 std::tuple<uint32_t, uint32_t, uint32_t> workgroup_size() {
169 return std::tuple<uint32_t, uint32_t, uint32_t>(workgroup_size_x, workgroup_size_y,
170 workgroup_size_z);
171 }
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000172};
173
dan sinclairaba5a212022-04-07 17:59:54 +0000174} // namespace tint::inspector
Ryan Harrisondbc13af2022-02-21 15:19:07 +0000175
176#endif // SRC_TINT_INSPECTOR_ENTRY_POINT_H_