Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 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_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 sinclair | aba5a21 | 2022-04-07 17:59:54 +0000 | [diff] [blame] | 25 | namespace tint::inspector { |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 26 | |
| 27 | /// Base component type of a stage variable. |
| 28 | enum class ComponentType { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 29 | kUnknown = -1, |
| 30 | kFloat, |
| 31 | kUInt, |
| 32 | kSInt, |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | /// Composition of components of a stage variable. |
| 36 | enum class CompositionType { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 37 | kUnknown = -1, |
| 38 | kScalar, |
| 39 | kVec2, |
| 40 | kVec3, |
| 41 | kVec4, |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | /// Type of interpolation of a stage variable. |
| 45 | enum class InterpolationType { kUnknown = -1, kPerspective, kLinear, kFlat }; |
| 46 | |
| 47 | /// Type of interpolation sampling of a stage variable. |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 48 | enum class InterpolationSampling { kUnknown = -1, kNone, kCenter, kCentroid, kSample }; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 49 | |
| 50 | /// Reflection data about an entry point input or output. |
| 51 | struct StageVariable { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 52 | /// Constructor |
| 53 | StageVariable(); |
| 54 | /// Copy constructor |
| 55 | /// @param other the StageVariable to copy |
| 56 | StageVariable(const StageVariable& other); |
| 57 | /// Destructor |
| 58 | ~StageVariable(); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 59 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 60 | /// 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 Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 82 | }; |
| 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 sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 87 | InterpolationType ASTToInspectorInterpolationType(ast::InterpolationType ast_type); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 88 | |
| 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 sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 93 | InterpolationSampling ASTToInspectorInterpolationSampling(ast::InterpolationSampling sampling); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 94 | |
| 95 | /// Reflection data about a pipeline overridable constant referenced by an entry |
| 96 | /// point |
| 97 | struct OverridableConstant { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 98 | /// Name of the constant |
| 99 | std::string name; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 100 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 101 | /// ID of the constant |
| 102 | uint16_t numeric_id; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 103 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 104 | /// Type of the scalar |
| 105 | enum class Type { |
| 106 | kBool, |
| 107 | kFloat32, |
| 108 | kUint32, |
| 109 | kInt32, |
| 110 | }; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 111 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 112 | /// Type of the scalar |
| 113 | Type type; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 114 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 115 | /// Does this pipeline overridable constant have an initializer? |
| 116 | bool is_initialized = false; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 117 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 118 | /// Does this pipeline overridable constant have a numeric ID specified |
| 119 | /// explicitly? |
| 120 | bool is_numeric_id_specified = false; |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | /// Reflection data for an entry point in the shader. |
| 124 | struct EntryPoint { |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 125 | /// Constructors |
| 126 | EntryPoint(); |
| 127 | /// Copy Constructor |
| 128 | EntryPoint(EntryPoint&); |
| 129 | /// Move Constructor |
| 130 | EntryPoint(EntryPoint&&); |
| 131 | ~EntryPoint(); |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 132 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 133 | /// 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 Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 166 | |
dan sinclair | 41e4d9a | 2022-05-01 14:40:55 +0000 | [diff] [blame] | 167 | /// @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 Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 172 | }; |
| 173 | |
dan sinclair | aba5a21 | 2022-04-07 17:59:54 +0000 | [diff] [blame] | 174 | } // namespace tint::inspector |
Ryan Harrison | dbc13af | 2022-02-21 15:19:07 +0000 | [diff] [blame] | 175 | |
| 176 | #endif // SRC_TINT_INSPECTOR_ENTRY_POINT_H_ |