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_AST_STRUCT_MEMBER_OFFSET_DECORATION_H_ 16 #define SRC_AST_STRUCT_MEMBER_OFFSET_DECORATION_H_ 17 18 #include <string> 19 20 #include "src/ast/decoration.h" 21 22 namespace tint { 23 namespace ast { 24 25 /// A struct member offset decoration 26 /// @note The WGSL spec removed the `[[offset(n)]]` decoration for `[[size(n)]]` 27 /// and `[[align(n)]]` in https://github.com/gpuweb/gpuweb/pull/1447. However 28 /// this decoration is kept because the SPIR-V reader has to deal with absolute 29 /// offsets, and transforming these to size / align is complex and can be done 30 /// in a number of ways. The Resolver is responsible for consuming the size and 31 /// align decorations and transforming these into absolute offsets. It is 32 /// trivial for the Resolver to handle `[[offset(n)]]` or `[[size(n)]]` / 33 /// `[[align(n)]]` decorations, so this is what we do, keeping all the layout 34 /// logic in one place. 35 class StructMemberOffsetDecoration 36 : public Castable<StructMemberOffsetDecoration, Decoration> { 37 public: 38 /// constructor 39 /// @param pid the identifier of the program that owns this node 40 /// @param src the source of this node 41 /// @param offset the offset value 42 StructMemberOffsetDecoration(ProgramID pid, 43 const Source& src, 44 uint32_t offset); 45 ~StructMemberOffsetDecoration() override; 46 47 /// @returns the WGSL name for the decoration 48 std::string Name() const override; 49 50 /// Clones this node and all transitive child nodes using the `CloneContext` 51 /// `ctx`. 52 /// @param ctx the clone context 53 /// @return the newly cloned node 54 const StructMemberOffsetDecoration* Clone(CloneContext* ctx) const override; 55 56 /// The offset value 57 const uint32_t offset; 58 }; 59 60 } // namespace ast 61 } // namespace tint 62 63 #endif // SRC_AST_STRUCT_MEMBER_OFFSET_DECORATION_H_ 64