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_NUM_WORKGROUPS_FROM_UNIFORM_H_ 16 #define SRC_TRANSFORM_NUM_WORKGROUPS_FROM_UNIFORM_H_ 17 18 #include "src/sem/binding_point.h" 19 #include "src/transform/transform.h" 20 21 namespace tint { 22 23 // Forward declarations 24 class CloneContext; 25 26 namespace transform { 27 28 /// NumWorkgroupsFromUniform is a transform that implements the `num_workgroups` 29 /// builtin by loading it from a uniform buffer. 30 /// 31 /// The generated uniform buffer will have the form: 32 /// ``` 33 /// [[block]] 34 /// struct num_workgroups_struct { 35 /// num_workgroups : vec3<u32>; 36 /// }; 37 /// 38 /// [[group(0), binding(0)]] 39 /// var<uniform> num_workgroups_ubo : num_workgroups_struct; 40 /// ``` 41 /// The binding group and number used for this uniform buffer is provided via 42 /// the `Config` transform input. 43 class NumWorkgroupsFromUniform 44 : public Castable<NumWorkgroupsFromUniform, Transform> { 45 public: 46 /// Constructor 47 NumWorkgroupsFromUniform(); 48 /// Destructor 49 ~NumWorkgroupsFromUniform() override; 50 51 /// Configuration options for the NumWorkgroupsFromUniform transform. 52 struct Config : public Castable<Data, transform::Data> { 53 /// Constructor 54 /// @param ubo_bp the binding point to use for the generated uniform buffer. 55 explicit Config(sem::BindingPoint ubo_bp); 56 57 /// Copy constructor 58 Config(const Config&); 59 60 /// Destructor 61 ~Config() override; 62 63 /// The binding point to use for the generated uniform buffer. 64 sem::BindingPoint ubo_binding; 65 }; 66 67 protected: 68 /// Runs the transform using the CloneContext built for transforming a 69 /// program. Run() is responsible for calling Clone() on the CloneContext. 70 /// @param ctx the CloneContext primed with the input program and 71 /// ProgramBuilder 72 /// @param inputs optional extra transform-specific input data 73 /// @param outputs optional extra transform-specific output data 74 void Run(CloneContext& ctx, const DataMap& inputs, DataMap& outputs) override; 75 }; 76 77 } // namespace transform 78 } // namespace tint 79 80 #endif // SRC_TRANSFORM_NUM_WORKGROUPS_FROM_UNIFORM_H_ 81