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_PAD_ARRAY_ELEMENTS_H_ 16 #define SRC_TRANSFORM_PAD_ARRAY_ELEMENTS_H_ 17 18 #include "src/transform/transform.h" 19 20 namespace tint { 21 namespace transform { 22 23 /// PadArrayElements is a transform that replaces array types with an explicit 24 /// stride that is larger than the implicit stride, with an array of a new 25 /// structure type. This structure holds with a single field of the element 26 /// type, decorated with a [[size]] decoration to pad the structure to the 27 /// required array stride. The new array types have no explicit stride, 28 /// structure size is equal to the desired stride. 29 /// Array index expressions and constructors are also adjusted to deal with this 30 /// structure element type. 31 /// This transform helps with backends that cannot directly return arrays or use 32 /// them as parameters. 33 class PadArrayElements : public Castable<PadArrayElements, Transform> { 34 public: 35 /// Constructor 36 PadArrayElements(); 37 38 /// Destructor 39 ~PadArrayElements() override; 40 41 protected: 42 /// Runs the transform using the CloneContext built for transforming a 43 /// program. Run() is responsible for calling Clone() on the CloneContext. 44 /// @param ctx the CloneContext primed with the input program and 45 /// ProgramBuilder 46 /// @param inputs optional extra transform-specific input data 47 /// @param outputs optional extra transform-specific output data 48 void Run(CloneContext& ctx, const DataMap& inputs, DataMap& outputs) override; 49 }; 50 51 } // namespace transform 52 } // namespace tint 53 54 #endif // SRC_TRANSFORM_PAD_ARRAY_ELEMENTS_H_ 55