blob: fc460c6292292fbf9d051f8e64f083ad5afd1e9a [file] [log] [blame]
James Price87537962022-12-06 18:32:19 +00001// 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 Price7d2e2042023-05-11 13:10:59 +000015#ifndef SRC_TINT_AST_TRANSFORM_PRESERVE_PADDING_H_
16#define SRC_TINT_AST_TRANSFORM_PRESERVE_PADDING_H_
James Price87537962022-12-06 18:32:19 +000017
James Price7d2e2042023-05-11 13:10:59 +000018#include "src/tint/ast/transform/transform.h"
James Price87537962022-12-06 18:32:19 +000019
James Priceb4acbb82023-05-11 21:27:16 +000020namespace tint::ast::transform {
James Price87537962022-12-06 18:32:19 +000021
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 sinclair12fa3032023-04-19 23:52:33 +000029class PreservePadding final : public utils::Castable<PreservePadding, Transform> {
James Price87537962022-12-06 18:32:19 +000030 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 Priceb4acbb82023-05-11 21:27:16 +000045} // namespace tint::ast::transform
James Price87537962022-12-06 18:32:19 +000046
James Price7d2e2042023-05-11 13:10:59 +000047#endif // SRC_TINT_AST_TRANSFORM_PRESERVE_PADDING_H_