Skip to content

Commit e6ef9ef

Browse files
dj2Dawn LUCI CQ
authored andcommitted
[spirv-reader][ir] Convert OpAtomicExchange
Convert the `OpAtomicExchange` to an `atomicExchange` instruction in WGSL. Bug: 391486936 Change-Id: Ie0e08cff353e6e4308d3c765341a7fd3314a8dc5 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/236895 Commit-Queue: dan sinclair <[email protected]> Reviewed-by: James Price <[email protected]>
1 parent d2e3404 commit e6ef9ef

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

src/tint/lang/spirv/reader/lower/atomics.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ struct State {
8888
AtomicOp(builtin, core::BuiltinFn::kAtomicStore);
8989
break;
9090
case spirv::BuiltinFn::kAtomicExchange:
91+
AtomicOp(builtin, core::BuiltinFn::kAtomicExchange);
92+
break;
9193
case spirv::BuiltinFn::kAtomicCompareExchange:
9294
break;
9395
case spirv::BuiltinFn::kAtomicIAdd:

src/tint/lang/spirv/reader/lower/atomics_test.cc

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1403,7 +1403,7 @@ S_atomic = struct @align(4) {
14031403
ASSERT_EQ(expect, str());
14041404
}
14051405

1406-
TEST_F(SpirvReader_AtomicsTest, DISABLED_AtomicExchange) {
1406+
TEST_F(SpirvReader_AtomicsTest, AtomicExchange) {
14071407
auto* f = b.ComputeFunction("main");
14081408

14091409
auto* sb = ty.Struct(mod.symbols.New("S"), {
@@ -1429,11 +1429,11 @@ TEST_F(SpirvReader_AtomicsTest, DISABLED_AtomicExchange) {
14291429

14301430
auto* a1 = b.Access(ty.ptr<storage, u32, read_write>(), sg, 1_u);
14311431
b.Call<spirv::ir::BuiltinCall>(ty.u32(), spirv::BuiltinFn::kAtomicExchange, a1, 1_u, 0_u,
1432-
1_u);
1432+
2_u);
14331433
b.Call<spirv::ir::BuiltinCall>(ty.i32(), spirv::BuiltinFn::kAtomicExchange, wg_i32, 1_u,
1434-
0_u, 1_i);
1434+
0_u, 3_i);
14351435
b.Call<spirv::ir::BuiltinCall>(ty.u32(), spirv::BuiltinFn::kAtomicExchange, wg_u32, 1_u,
1436-
0_u, 1_u);
1436+
0_u, 4_u);
14371437
b.Return(f);
14381438
});
14391439

@@ -1454,9 +1454,9 @@ S = struct @align(4) {
14541454
%5:ptr<storage, i32, read_write> = access %sb, 0u
14551455
%6:i32 = spirv.atomic_exchange %5, 1u, 0u, 1i
14561456
%7:ptr<storage, u32, read_write> = access %sb, 1u
1457-
%8:u32 = spirv.atomic_exchange %7, 1u, 0u, 1u
1458-
%9:i32 = spirv.atomic_exchange %wg_i32, 1u, 0u, 1i
1459-
%10:u32 = spirv.atomic_exchange %wg_u32, 1u, 0u, 1u
1457+
%8:u32 = spirv.atomic_exchange %7, 1u, 0u, 2u
1458+
%9:i32 = spirv.atomic_exchange %wg_i32, 1u, 0u, 3i
1459+
%10:u32 = spirv.atomic_exchange %wg_u32, 1u, 0u, 4u
14601460
ret
14611461
}
14621462
}
@@ -1466,7 +1466,33 @@ S = struct @align(4) {
14661466
Run(Atomics);
14671467

14681468
auto* expect = R"(
1469-
UNIMPLEMENTED
1469+
S = struct @align(4) {
1470+
a:i32 @offset(0)
1471+
b:u32 @offset(4)
1472+
}
1473+
1474+
S_atomic = struct @align(4) {
1475+
a:atomic<i32> @offset(0)
1476+
b:atomic<u32> @offset(4)
1477+
}
1478+
1479+
$B1: { # root
1480+
%sb:ptr<storage, S_atomic, read_write> = var undef @binding_point(0, 0)
1481+
%wg_i32:ptr<workgroup, atomic<i32>, read_write> = var undef
1482+
%wg_u32:ptr<workgroup, atomic<u32>, read_write> = var undef
1483+
}
1484+
1485+
%main = @compute @workgroup_size(1u, 1u, 1u) func():void {
1486+
$B2: {
1487+
%5:ptr<storage, atomic<i32>, read_write> = access %sb, 0u
1488+
%6:i32 = atomicExchange %5, 1i
1489+
%7:ptr<storage, atomic<u32>, read_write> = access %sb, 1u
1490+
%8:u32 = atomicExchange %7, 2u
1491+
%9:i32 = atomicExchange %wg_i32, 3i
1492+
%10:u32 = atomicExchange %wg_u32, 4u
1493+
ret
1494+
}
1495+
}
14701496
)";
14711497
ASSERT_EQ(expect, str());
14721498
}

0 commit comments

Comments
 (0)