hlsl-writer: support subgroupBroadcast
Bug: tint:2041
Change-Id: If411acf82baa2645dd384be82a0091d2695904e1
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/152600
Commit-Queue: David Neto <dneto@google.com>
Auto-Submit: David Neto <dneto@google.com>
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc b/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc
index 352c4d8..20b7775 100644
--- a/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc
+++ b/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc
@@ -1213,7 +1213,11 @@
return EmitDP4aCall(out, expr, builtin);
}
if (builtin->IsSubgroup()) {
- return EmitSubgroupCall(out, expr, builtin);
+ if (builtin->Type() == core::Function::kSubgroupBroadcast) {
+ // Fall through the regular path.
+ } else {
+ return EmitSubgroupCall(out, expr, builtin);
+ }
}
auto name = generate_builtin_name(builtin);
@@ -2507,6 +2511,7 @@
if (builtin->Type() == core::Function::kSubgroupBallot) {
out << "WaveActiveBallot(true)";
} else {
+ // subgroupBroadcast is already handled in the regular builtin flow.
TINT_UNREACHABLE() << "unexpected subgroup builtin type " << core::str(builtin->Type());
return false;
}
@@ -2992,6 +2997,8 @@
return "reversebits";
case core::Function::kSmoothstep:
return "smoothstep";
+ case core::Function::kSubgroupBroadcast:
+ return "WaveReadLaneAt";
default:
diagnostics_.add_error(diag::System::Writer,
"Unknown builtin method: " + std::string(builtin->str()));
diff --git a/test/tint/builtins/gen/literal/subgroupBroadcast/08beca.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/subgroupBroadcast/08beca.wgsl.expected.dxc.hlsl
index 9f667dd..9eb3961 100644
--- a/test/tint/builtins/gen/literal/subgroupBroadcast/08beca.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/literal/subgroupBroadcast/08beca.wgsl.expected.dxc.hlsl
@@ -1,9 +1,12 @@
-SKIP: FAILED
+RWByteAddressBuffer prevent_dce : register(u0, space2);
-/build/dawn/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc:2510 internal compiler error: TINT_UNREACHABLE unexpected subgroup builtin type subgroupBroadcast
-********************************************************************
-* The tint shader compiler has encountered an unexpected error. *
-* *
-* Please help us fix this issue by submitting a bug report at *
-* crbug.com/tint with the source program that triggered the bug. *
-********************************************************************
+void subgroupBroadcast_08beca() {
+ float res = WaveReadLaneAt(1.0f, 1u);
+ prevent_dce.Store(0u, asuint(res));
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+ subgroupBroadcast_08beca();
+ return;
+}
diff --git a/test/tint/builtins/gen/literal/subgroupBroadcast/1d79c7.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/subgroupBroadcast/1d79c7.wgsl.expected.dxc.hlsl
index 9f667dd..c7e668c 100644
--- a/test/tint/builtins/gen/literal/subgroupBroadcast/1d79c7.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/literal/subgroupBroadcast/1d79c7.wgsl.expected.dxc.hlsl
@@ -1,9 +1,12 @@
-SKIP: FAILED
+RWByteAddressBuffer prevent_dce : register(u0, space2);
-/build/dawn/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc:2510 internal compiler error: TINT_UNREACHABLE unexpected subgroup builtin type subgroupBroadcast
-********************************************************************
-* The tint shader compiler has encountered an unexpected error. *
-* *
-* Please help us fix this issue by submitting a bug report at *
-* crbug.com/tint with the source program that triggered the bug. *
-********************************************************************
+void subgroupBroadcast_1d79c7() {
+ int res = WaveReadLaneAt(1, 1u);
+ prevent_dce.Store(0u, asuint(res));
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+ subgroupBroadcast_1d79c7();
+ return;
+}
diff --git a/test/tint/builtins/gen/literal/subgroupBroadcast/c36fe1.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/literal/subgroupBroadcast/c36fe1.wgsl.expected.dxc.hlsl
index 9f667dd..a0062de 100644
--- a/test/tint/builtins/gen/literal/subgroupBroadcast/c36fe1.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/literal/subgroupBroadcast/c36fe1.wgsl.expected.dxc.hlsl
@@ -1,9 +1,12 @@
-SKIP: FAILED
+RWByteAddressBuffer prevent_dce : register(u0, space2);
-/build/dawn/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc:2510 internal compiler error: TINT_UNREACHABLE unexpected subgroup builtin type subgroupBroadcast
-********************************************************************
-* The tint shader compiler has encountered an unexpected error. *
-* *
-* Please help us fix this issue by submitting a bug report at *
-* crbug.com/tint with the source program that triggered the bug. *
-********************************************************************
+void subgroupBroadcast_c36fe1() {
+ uint res = WaveReadLaneAt(1u, 1u);
+ prevent_dce.Store(0u, asuint(res));
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+ subgroupBroadcast_c36fe1();
+ return;
+}
diff --git a/test/tint/builtins/gen/var/subgroupBroadcast/08beca.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/var/subgroupBroadcast/08beca.wgsl.expected.dxc.hlsl
index 9f667dd..d77f88e 100644
--- a/test/tint/builtins/gen/var/subgroupBroadcast/08beca.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/var/subgroupBroadcast/08beca.wgsl.expected.dxc.hlsl
@@ -1,9 +1,13 @@
-SKIP: FAILED
+RWByteAddressBuffer prevent_dce : register(u0, space2);
-/build/dawn/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc:2510 internal compiler error: TINT_UNREACHABLE unexpected subgroup builtin type subgroupBroadcast
-********************************************************************
-* The tint shader compiler has encountered an unexpected error. *
-* *
-* Please help us fix this issue by submitting a bug report at *
-* crbug.com/tint with the source program that triggered the bug. *
-********************************************************************
+void subgroupBroadcast_08beca() {
+ float arg_0 = 1.0f;
+ float res = WaveReadLaneAt(arg_0, 1u);
+ prevent_dce.Store(0u, asuint(res));
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+ subgroupBroadcast_08beca();
+ return;
+}
diff --git a/test/tint/builtins/gen/var/subgroupBroadcast/1d79c7.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/var/subgroupBroadcast/1d79c7.wgsl.expected.dxc.hlsl
index 9f667dd..66284a8 100644
--- a/test/tint/builtins/gen/var/subgroupBroadcast/1d79c7.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/var/subgroupBroadcast/1d79c7.wgsl.expected.dxc.hlsl
@@ -1,9 +1,13 @@
-SKIP: FAILED
+RWByteAddressBuffer prevent_dce : register(u0, space2);
-/build/dawn/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc:2510 internal compiler error: TINT_UNREACHABLE unexpected subgroup builtin type subgroupBroadcast
-********************************************************************
-* The tint shader compiler has encountered an unexpected error. *
-* *
-* Please help us fix this issue by submitting a bug report at *
-* crbug.com/tint with the source program that triggered the bug. *
-********************************************************************
+void subgroupBroadcast_1d79c7() {
+ int arg_0 = 1;
+ int res = WaveReadLaneAt(arg_0, 1u);
+ prevent_dce.Store(0u, asuint(res));
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+ subgroupBroadcast_1d79c7();
+ return;
+}
diff --git a/test/tint/builtins/gen/var/subgroupBroadcast/c36fe1.wgsl.expected.dxc.hlsl b/test/tint/builtins/gen/var/subgroupBroadcast/c36fe1.wgsl.expected.dxc.hlsl
index 9f667dd..31de11c 100644
--- a/test/tint/builtins/gen/var/subgroupBroadcast/c36fe1.wgsl.expected.dxc.hlsl
+++ b/test/tint/builtins/gen/var/subgroupBroadcast/c36fe1.wgsl.expected.dxc.hlsl
@@ -1,9 +1,13 @@
-SKIP: FAILED
+RWByteAddressBuffer prevent_dce : register(u0, space2);
-/build/dawn/src/tint/lang/hlsl/writer/ast_printer/ast_printer.cc:2510 internal compiler error: TINT_UNREACHABLE unexpected subgroup builtin type subgroupBroadcast
-********************************************************************
-* The tint shader compiler has encountered an unexpected error. *
-* *
-* Please help us fix this issue by submitting a bug report at *
-* crbug.com/tint with the source program that triggered the bug. *
-********************************************************************
+void subgroupBroadcast_c36fe1() {
+ uint arg_0 = 1u;
+ uint res = WaveReadLaneAt(arg_0, 1u);
+ prevent_dce.Store(0u, asuint(res));
+}
+
+[numthreads(1, 1, 1)]
+void compute_main() {
+ subgroupBroadcast_c36fe1();
+ return;
+}