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_TRANSFORM_ROBUSTNESS_H_ 16 #define SRC_TRANSFORM_ROBUSTNESS_H_ 17 18 #include <unordered_set> 19 20 #include "src/transform/transform.h" 21 22 // Forward declarations 23 namespace tint { 24 namespace ast { 25 class IndexAccessorExpression; 26 class CallExpression; 27 } // namespace ast 28 } // namespace tint 29 30 namespace tint { 31 namespace transform { 32 33 /// This transform is responsible for clamping all array accesses to be within 34 /// the bounds of the array. Any access before the start of the array will clamp 35 /// to zero and any access past the end of the array will clamp to 36 /// (array length - 1). 37 class Robustness : public Castable<Robustness, Transform> { 38 public: 39 /// Storage class to be skipped in the transform 40 enum class StorageClass { 41 kUniform, 42 kStorage, 43 }; 44 45 /// Configuration options for the transform 46 struct Config : public Castable<Config, Data> { 47 /// Constructor 48 Config(); 49 50 /// Copy constructor 51 Config(const Config&); 52 53 /// Destructor 54 ~Config() override; 55 56 /// Assignment operator 57 /// @returns this Config 58 Config& operator=(const Config&); 59 60 /// Storage classes to omit from apply the transform to. 61 /// This allows for optimizing on hardware that provide safe accesses. 62 std::unordered_set<StorageClass> omitted_classes; 63 }; 64 65 /// Constructor 66 Robustness(); 67 /// Destructor 68 ~Robustness() override; 69 70 protected: 71 /// Runs the transform using the CloneContext built for transforming a 72 /// program. Run() is responsible for calling Clone() on the CloneContext. 73 /// @param ctx the CloneContext primed with the input program and 74 /// ProgramBuilder 75 /// @param inputs optional extra transform-specific input data 76 /// @param outputs optional extra transform-specific output data 77 void Run(CloneContext& ctx, const DataMap& inputs, DataMap& outputs) override; 78 79 private: 80 struct State; 81 }; 82 83 } // namespace transform 84 } // namespace tint 85 86 #endif // SRC_TRANSFORM_ROBUSTNESS_H_ 87