[hlsl] Emit barriers in HLSL IR Writer.

This Cl adds barrier emission to the HLSL IR Writer.

Bug: 42251045
Change-Id: I064542a58fe73dd4fd215bcfe9922a91ecbfa19a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/197480
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: dan sinclair <dsinclair@chromium.org>
diff --git a/src/tint/lang/hlsl/writer/builtin_test.cc b/src/tint/lang/hlsl/writer/builtin_test.cc
index c7a2ac3..0b0df56 100644
--- a/src/tint/lang/hlsl/writer/builtin_test.cc
+++ b/src/tint/lang/hlsl/writer/builtin_test.cc
@@ -671,5 +671,59 @@
 )");
 }
 
+TEST_F(HlslWriterTest, BuiltinStorageBarrier) {
+    auto* func = b.Function("foo", ty.void_(), core::ir::Function::PipelineStage::kCompute);
+    func->SetWorkgroupSize(1, 1, 1);
+    b.Append(func->Block(), [&] {
+        b.Call(ty.void_(), core::BuiltinFn::kStorageBarrier);
+        b.Return(func);
+    });
+
+    ASSERT_TRUE(Generate()) << err_ << output_.hlsl;
+    EXPECT_EQ(output_.hlsl, R"(
+[numthreads(1, 1, 1)]
+void foo() {
+  DeviceMemoryBarrierWithGroupSync();
+}
+
+)");
+}
+
+TEST_F(HlslWriterTest, BuiltinTextureBarrier) {
+    auto* func = b.Function("foo", ty.void_(), core::ir::Function::PipelineStage::kCompute);
+    func->SetWorkgroupSize(1, 1, 1);
+    b.Append(func->Block(), [&] {
+        b.Call(ty.void_(), core::BuiltinFn::kTextureBarrier);
+        b.Return(func);
+    });
+
+    ASSERT_TRUE(Generate()) << err_ << output_.hlsl;
+    EXPECT_EQ(output_.hlsl, R"(
+[numthreads(1, 1, 1)]
+void foo() {
+  DeviceMemoryBarrierWithGroupSync();
+}
+
+)");
+}
+
+TEST_F(HlslWriterTest, BuiltinWorkgroupBarrier) {
+    auto* func = b.Function("foo", ty.void_(), core::ir::Function::PipelineStage::kCompute);
+    func->SetWorkgroupSize(1, 1, 1);
+    b.Append(func->Block(), [&] {
+        b.Call(ty.void_(), core::BuiltinFn::kWorkgroupBarrier);
+        b.Return(func);
+    });
+
+    ASSERT_TRUE(Generate()) << err_ << output_.hlsl;
+    EXPECT_EQ(output_.hlsl, R"(
+[numthreads(1, 1, 1)]
+void foo() {
+  GroupMemoryBarrierWithGroupSync();
+}
+
+)");
+}
+
 }  // namespace
 }  // namespace tint::hlsl::writer
diff --git a/src/tint/lang/hlsl/writer/printer/printer.cc b/src/tint/lang/hlsl/writer/printer/printer.cc
index 29abf40..485986a 100644
--- a/src/tint/lang/hlsl/writer/printer/printer.cc
+++ b/src/tint/lang/hlsl/writer/printer/printer.cc
@@ -968,6 +968,15 @@
             case core::BuiltinFn::kSubgroupBroadcast:
                 out << "WaveReadLaneAt";
                 break;
+            case core::BuiltinFn::kWorkgroupBarrier:
+                out << "GroupMemoryBarrierWithGroupSync";
+                break;
+            case core::BuiltinFn::kStorageBarrier:
+                out << "DeviceMemoryBarrierWithGroupSync";
+                break;
+            case core::BuiltinFn::kTextureBarrier:
+                out << "DeviceMemoryBarrierWithGroupSync";
+                break;
 
             default:
                 TINT_UNREACHABLE() << "unhandled: " << func;