James Price | 8753796 | 2022-12-06 18:32:19 +0000 | [diff] [blame] | 1 | // Copyright 2022 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 | |
James Price | 7d2e204 | 2023-05-11 13:10:59 +0000 | [diff] [blame] | 15 | #ifndef SRC_TINT_AST_TRANSFORM_PRESERVE_PADDING_H_ |
| 16 | #define SRC_TINT_AST_TRANSFORM_PRESERVE_PADDING_H_ |
James Price | 8753796 | 2022-12-06 18:32:19 +0000 | [diff] [blame] | 17 | |
James Price | 7d2e204 | 2023-05-11 13:10:59 +0000 | [diff] [blame] | 18 | #include "src/tint/ast/transform/transform.h" |
James Price | 8753796 | 2022-12-06 18:32:19 +0000 | [diff] [blame] | 19 | |
James Price | b4acbb8 | 2023-05-11 21:27:16 +0000 | [diff] [blame] | 20 | namespace tint::ast::transform { |
James Price | 8753796 | 2022-12-06 18:32:19 +0000 | [diff] [blame] | 21 | |
| 22 | /// Decompose assignments of whole structure and array types to preserve padding bytes. |
| 23 | /// |
| 24 | /// WGSL states that memory operations on structures and arrays will not access padding bytes. To |
| 25 | /// avoid overwriting padding bytes when writing to buffers, this transform decomposes those |
| 26 | /// assignments into element-wise assignments via helper functions. |
| 27 | /// |
| 28 | /// @note Assumes that the DirectVariableTransform will be run afterwards for backends that need it. |
dan sinclair | 12fa303 | 2023-04-19 23:52:33 +0000 | [diff] [blame] | 29 | class PreservePadding final : public utils::Castable<PreservePadding, Transform> { |
James Price | 8753796 | 2022-12-06 18:32:19 +0000 | [diff] [blame] | 30 | public: |
| 31 | /// Constructor |
| 32 | PreservePadding(); |
| 33 | /// Destructor |
| 34 | ~PreservePadding() override; |
| 35 | |
| 36 | /// @copydoc Transform::Apply |
| 37 | ApplyResult Apply(const Program* program, |
| 38 | const DataMap& inputs, |
| 39 | DataMap& outputs) const override; |
| 40 | |
| 41 | private: |
| 42 | struct State; |
| 43 | }; |
| 44 | |
James Price | b4acbb8 | 2023-05-11 21:27:16 +0000 | [diff] [blame] | 45 | } // namespace tint::ast::transform |
James Price | 8753796 | 2022-12-06 18:32:19 +0000 | [diff] [blame] | 46 | |
James Price | 7d2e204 | 2023-05-11 13:10:59 +0000 | [diff] [blame] | 47 | #endif // SRC_TINT_AST_TRANSFORM_PRESERVE_PADDING_H_ |