[hlsl] Stub out the DecomposeMemoryAccess IR transform.
This CL creates the basic structure for the DMA transform.
Bug: 349867642
Change-Id: I713556a37bd2b2539c476623c29f99b2f99aa36a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/196215
Auto-Submit: dan sinclair <dsinclair@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: James Price <jrprice@google.com>
diff --git a/src/tint/lang/hlsl/writer/raise/BUILD.bazel b/src/tint/lang/hlsl/writer/raise/BUILD.bazel
index 87e903f..a152b37 100644
--- a/src/tint/lang/hlsl/writer/raise/BUILD.bazel
+++ b/src/tint/lang/hlsl/writer/raise/BUILD.bazel
@@ -40,6 +40,7 @@
name = "raise",
srcs = [
"builtin_polyfill.cc",
+ "decompose_memory_access.cc",
"fxc_polyfill.cc",
"promote_initializers.cc",
"raise.cc",
@@ -47,6 +48,7 @@
],
hdrs = [
"builtin_polyfill.h",
+ "decompose_memory_access.h",
"fxc_polyfill.h",
"promote_initializers.h",
"raise.h",
@@ -86,6 +88,7 @@
alwayslink = True,
srcs = [
"builtin_polyfill_test.cc",
+ "decompose_memory_access_test.cc",
"fxc_polyfill_test.cc",
"promote_initializers_test.cc",
"shader_io_test.cc",
diff --git a/src/tint/lang/hlsl/writer/raise/BUILD.cmake b/src/tint/lang/hlsl/writer/raise/BUILD.cmake
index c24bca7..7e21ab8 100644
--- a/src/tint/lang/hlsl/writer/raise/BUILD.cmake
+++ b/src/tint/lang/hlsl/writer/raise/BUILD.cmake
@@ -41,6 +41,8 @@
tint_add_target(tint_lang_hlsl_writer_raise lib
lang/hlsl/writer/raise/builtin_polyfill.cc
lang/hlsl/writer/raise/builtin_polyfill.h
+ lang/hlsl/writer/raise/decompose_memory_access.cc
+ lang/hlsl/writer/raise/decompose_memory_access.h
lang/hlsl/writer/raise/fxc_polyfill.cc
lang/hlsl/writer/raise/fxc_polyfill.h
lang/hlsl/writer/raise/promote_initializers.cc
@@ -84,6 +86,7 @@
################################################################################
tint_add_target(tint_lang_hlsl_writer_raise_test test
lang/hlsl/writer/raise/builtin_polyfill_test.cc
+ lang/hlsl/writer/raise/decompose_memory_access_test.cc
lang/hlsl/writer/raise/fxc_polyfill_test.cc
lang/hlsl/writer/raise/promote_initializers_test.cc
lang/hlsl/writer/raise/shader_io_test.cc
diff --git a/src/tint/lang/hlsl/writer/raise/BUILD.gn b/src/tint/lang/hlsl/writer/raise/BUILD.gn
index 35236a5..8fdf1be 100644
--- a/src/tint/lang/hlsl/writer/raise/BUILD.gn
+++ b/src/tint/lang/hlsl/writer/raise/BUILD.gn
@@ -46,6 +46,8 @@
sources = [
"builtin_polyfill.cc",
"builtin_polyfill.h",
+ "decompose_memory_access.cc",
+ "decompose_memory_access.h",
"fxc_polyfill.cc",
"fxc_polyfill.h",
"promote_initializers.cc",
@@ -86,6 +88,7 @@
tint_unittests_source_set("unittests") {
sources = [
"builtin_polyfill_test.cc",
+ "decompose_memory_access_test.cc",
"fxc_polyfill_test.cc",
"promote_initializers_test.cc",
"shader_io_test.cc",
diff --git a/src/tint/lang/hlsl/writer/raise/decompose_memory_access.cc b/src/tint/lang/hlsl/writer/raise/decompose_memory_access.cc
new file mode 100644
index 0000000..883c4ed
--- /dev/null
+++ b/src/tint/lang/hlsl/writer/raise/decompose_memory_access.cc
@@ -0,0 +1,68 @@
+// 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/hlsl/writer/raise/decompose_memory_access.h"
+
+#include "src/tint/lang/core/ir/block.h"
+#include "src/tint/lang/core/ir/builder.h"
+#include "src/tint/lang/core/ir/validator.h"
+#include "src/tint/utils/result/result.h"
+
+namespace tint::hlsl::writer::raise {
+namespace {
+
+using namespace tint::core::fluent_types; // NOLINT
+
+/// PIMPL state for the transform.
+struct State {
+ /// The IR module.
+ core::ir::Module& ir;
+
+ /// The IR builder.
+ core::ir::Builder b{ir};
+
+ /// The type manager.
+ core::type::Manager& ty{ir.Types()};
+
+ /// Process the module.
+ void Process() {}
+};
+
+} // namespace
+
+Result<SuccessType> DecomposeMemoryAccess(core::ir::Module& ir) {
+ auto result = ValidateAndDumpIfNeeded(ir, "DecomposeMemoryAccess transform");
+ if (result != Success) {
+ return result.Failure();
+ }
+
+ State{ir}.Process();
+
+ return Success;
+}
+
+} // namespace tint::hlsl::writer::raise
diff --git a/src/tint/lang/hlsl/writer/raise/decompose_memory_access.h b/src/tint/lang/hlsl/writer/raise/decompose_memory_access.h
new file mode 100644
index 0000000..2a7b36d
--- /dev/null
+++ b/src/tint/lang/hlsl/writer/raise/decompose_memory_access.h
@@ -0,0 +1,51 @@
+// 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_HLSL_WRITER_RAISE_DECOMPOSE_MEMORY_ACCESS_H_
+#define SRC_TINT_LANG_HLSL_WRITER_RAISE_DECOMPOSE_MEMORY_ACCESS_H_
+
+#include <string>
+
+#include "src/tint/utils/result/result.h"
+
+// Forward declarations.
+namespace tint::core::ir {
+class Module;
+} // namespace tint::core::ir
+
+namespace tint::hlsl::writer::raise {
+
+/// DecomposeMemoryAccess is a transform used to replace storage and uniform buffer accesses with a
+/// combination of load, store or atomic functions on primitive types.
+///
+/// @param module the module to transform
+/// @returns success or failure
+Result<SuccessType> DecomposeMemoryAccess(core::ir::Module& module);
+
+} // namespace tint::hlsl::writer::raise
+
+#endif // SRC_TINT_LANG_HLSL_WRITER_RAISE_DECOMPOSE_MEMORY_ACCESS_H_
diff --git a/src/tint/lang/hlsl/writer/raise/decompose_memory_access_test.cc b/src/tint/lang/hlsl/writer/raise/decompose_memory_access_test.cc
new file mode 100644
index 0000000..08df8a2
--- /dev/null
+++ b/src/tint/lang/hlsl/writer/raise/decompose_memory_access_test.cc
@@ -0,0 +1,65 @@
+// 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/hlsl/writer/raise/decompose_memory_access.h"
+
+#include <gtest/gtest.h>
+
+#include "src/tint/lang/core/fluent_types.h"
+#include "src/tint/lang/core/ir/function.h"
+#include "src/tint/lang/core/ir/transform/helper_test.h"
+#include "src/tint/lang/core/number.h"
+
+using namespace tint::core::fluent_types; // NOLINT
+using namespace tint::core::number_suffixes; // NOLINT
+
+namespace tint::hlsl::writer::raise {
+namespace {
+
+using HlslWriterDecomposeMemoryAccessTest = core::ir::transform::TransformTest;
+
+TEST_F(HlslWriterDecomposeMemoryAccessTest, NoBufferAccess) {
+ auto* func = b.Function("foo", ty.void_(), core::ir::Function::PipelineStage::kFragment);
+ b.Append(func->Block(), [&] { b.Return(func); });
+
+ auto* src = R"(
+%foo = @fragment func():void {
+ $B1: {
+ ret
+ }
+}
+)";
+ EXPECT_EQ(src, str());
+
+ auto* expect = src;
+ Run(DecomposeMemoryAccess);
+
+ EXPECT_EQ(expect, str());
+}
+
+} // namespace
+} // namespace tint::hlsl::writer::raise
diff --git a/src/tint/lang/hlsl/writer/raise/raise.cc b/src/tint/lang/hlsl/writer/raise/raise.cc
index 63f4eda8..8a50940 100644
--- a/src/tint/lang/hlsl/writer/raise/raise.cc
+++ b/src/tint/lang/hlsl/writer/raise/raise.cc
@@ -33,6 +33,7 @@
#include "src/tint/lang/core/ir/transform/value_to_let.h"
#include "src/tint/lang/hlsl/writer/common/options.h"
#include "src/tint/lang/hlsl/writer/raise/builtin_polyfill.h"
+#include "src/tint/lang/hlsl/writer/raise/decompose_memory_access.h"
#include "src/tint/lang/hlsl/writer/raise/fxc_polyfill.h"
#include "src/tint/lang/hlsl/writer/raise/promote_initializers.h"
#include "src/tint/lang/hlsl/writer/raise/shader_io.h"
@@ -58,6 +59,8 @@
RUN_TRANSFORM(core::ir::transform::AddEmptyEntryPoint);
+ RUN_TRANSFORM(raise::DecomposeMemoryAccess);
+
if (options.compiler == Options::Compiler::kFXC) {
RUN_TRANSFORM(raise::FxcPolyfill);
}