[ast] Add @row_major attribute
This will only be used internally by the SPIR-V reader to support
row-major matrices.
Bug: 364267168
Change-Id: I7283d16a3048d3b76ac27d50c9c9c40e4529a3f9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/207414
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: James Price <jrprice@google.com>
diff --git a/src/tint/lang/wgsl/ast/BUILD.bazel b/src/tint/lang/wgsl/ast/BUILD.bazel
index 0614182..e3dbfb8 100644
--- a/src/tint/lang/wgsl/ast/BUILD.bazel
+++ b/src/tint/lang/wgsl/ast/BUILD.bazel
@@ -100,6 +100,7 @@
"pipeline_stage.cc",
"requires.cc",
"return_statement.cc",
+ "row_major_attribute.cc",
"stage_attribute.cc",
"statement.cc",
"stride_attribute.cc",
@@ -182,6 +183,7 @@
"pipeline_stage.h",
"requires.h",
"return_statement.h",
+ "row_major_attribute.h",
"stage_attribute.h",
"statement.h",
"stride_attribute.h",
diff --git a/src/tint/lang/wgsl/ast/BUILD.cmake b/src/tint/lang/wgsl/ast/BUILD.cmake
index 4399bb0..dc49054 100644
--- a/src/tint/lang/wgsl/ast/BUILD.cmake
+++ b/src/tint/lang/wgsl/ast/BUILD.cmake
@@ -164,6 +164,8 @@
lang/wgsl/ast/requires.h
lang/wgsl/ast/return_statement.cc
lang/wgsl/ast/return_statement.h
+ lang/wgsl/ast/row_major_attribute.cc
+ lang/wgsl/ast/row_major_attribute.h
lang/wgsl/ast/stage_attribute.cc
lang/wgsl/ast/stage_attribute.h
lang/wgsl/ast/statement.cc
diff --git a/src/tint/lang/wgsl/ast/BUILD.gn b/src/tint/lang/wgsl/ast/BUILD.gn
index c163961..e86e55c 100644
--- a/src/tint/lang/wgsl/ast/BUILD.gn
+++ b/src/tint/lang/wgsl/ast/BUILD.gn
@@ -168,6 +168,8 @@
"requires.h",
"return_statement.cc",
"return_statement.h",
+ "row_major_attribute.cc",
+ "row_major_attribute.h",
"stage_attribute.cc",
"stage_attribute.h",
"statement.cc",
diff --git a/src/tint/lang/wgsl/ast/row_major_attribute.cc b/src/tint/lang/wgsl/ast/row_major_attribute.cc
new file mode 100644
index 0000000..2b8b95d
--- /dev/null
+++ b/src/tint/lang/wgsl/ast/row_major_attribute.cc
@@ -0,0 +1,52 @@
+// Copyright 2024 The Dawn & Tint Authors
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this
+// list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "src/tint/lang/wgsl/ast/row_major_attribute.h"
+
+#include "src/tint/lang/wgsl/ast/builder.h"
+#include "src/tint/lang/wgsl/ast/clone_context.h"
+
+TINT_INSTANTIATE_TYPEINFO(tint::ast::RowMajorAttribute);
+
+namespace tint::ast {
+
+RowMajorAttribute::RowMajorAttribute(GenerationID pid, NodeID nid, const Source& src)
+ : Base(pid, nid, src) {}
+
+RowMajorAttribute::~RowMajorAttribute() = default;
+
+std::string RowMajorAttribute::Name() const {
+ return "row_major";
+}
+
+const RowMajorAttribute* RowMajorAttribute::Clone(CloneContext& ctx) const {
+ // Clone arguments outside of create() call to have deterministic ordering
+ auto src = ctx.Clone(source);
+ return ctx.dst->create<RowMajorAttribute>(src);
+}
+
+} // namespace tint::ast
diff --git a/src/tint/lang/wgsl/ast/row_major_attribute.h b/src/tint/lang/wgsl/ast/row_major_attribute.h
new file mode 100644
index 0000000..0d94122
--- /dev/null
+++ b/src/tint/lang/wgsl/ast/row_major_attribute.h
@@ -0,0 +1,58 @@
+// Copyright 2024 The Dawn & Tint Authors
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice, this
+// list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its
+// contributors may be used to endorse or promote products derived from
+// this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef SRC_TINT_LANG_WGSL_AST_ROW_MAJOR_ATTRIBUTE_H_
+#define SRC_TINT_LANG_WGSL_AST_ROW_MAJOR_ATTRIBUTE_H_
+
+#include <string>
+
+#include "src/tint/lang/wgsl/ast/attribute.h"
+
+namespace tint::ast {
+
+/// The row_major attribute
+class RowMajorAttribute final : public Castable<RowMajorAttribute, Attribute> {
+ public:
+ /// constructor
+ /// @param pid the identifier of the program that owns this node
+ /// @param nid the unique node identifier
+ /// @param src the source of this node
+ RowMajorAttribute(GenerationID pid, NodeID nid, const Source& src);
+ ~RowMajorAttribute() override;
+
+ /// @returns the WGSL name for the attribute
+ std::string Name() const override;
+
+ /// Clones this node and all transitive child nodes using the `CloneContext` `ctx`.
+ /// @param ctx the clone context
+ /// @return the newly cloned node
+ const RowMajorAttribute* Clone(CloneContext& ctx) const override;
+};
+
+} // namespace tint::ast
+
+#endif // SRC_TINT_LANG_WGSL_AST_ROW_MAJOR_ATTRIBUTE_H_