tint: spir-v reader: fix atomicCompareExchangeWeak with var comparator

Also fix HLSL generator to unwrap the ref type when emitting the
comparator value.

Bug: tint:1185
Change-Id: I01d04ca6357e72fd5ead0f25012ab39794e65da5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/94522
Reviewed-by: Ben Clayton <bclayton@chromium.org>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Antonio Maiorano 2022-06-23 13:14:54 +00:00 committed by Dawn LUCI CQ
parent 606abfbeae
commit f99671b830
8 changed files with 110 additions and 91 deletions

View File

@ -1779,8 +1779,8 @@ bool GeneratorImpl::EmitWorkgroupAtomicCall(std::ostream& out,
{ // T compare_value = <compare_value>; { // T compare_value = <compare_value>;
auto pre = line(); auto pre = line();
if (!EmitTypeAndName(pre, TypeOf(compare_value), ast::StorageClass::kNone, if (!EmitTypeAndName(pre, TypeOf(compare_value)->UnwrapRef(),
ast::Access::kUndefined, compare)) { ast::StorageClass::kNone, ast::Access::kUndefined, compare)) {
return false; return false;
} }
pre << " = "; pre << " = ";

View File

@ -3272,7 +3272,8 @@ bool Builder::GenerateAtomicBuiltin(const sem::Call* call,
value, value,
}); });
case sem::BuiltinType::kAtomicCompareExchangeWeak: { case sem::BuiltinType::kAtomicCompareExchangeWeak: {
auto comparator = GenerateExpression(call->Arguments()[1]->Declaration()); auto comparator =
GenerateExpressionWithLoadIfNeeded(call->Arguments()[1]->Declaration());
if (comparator == 0) { if (comparator == 0) {
return false; return false;
} }

View File

@ -1,9 +1,7 @@
SKIP: FAILED
; SPIR-V ; SPIR-V
; Version: 1.3 ; Version: 1.3
; Generator: Google Tint Compiler; 0 ; Generator: Google Tint Compiler; 0
; Bound: 35 ; Bound: 36
; Schema: 0 ; Schema: 0
OpCapability Shader OpCapability Shader
OpMemoryModel Logical GLSL450 OpMemoryModel Logical GLSL450
@ -45,32 +43,30 @@ SKIP: FAILED
%uint_0 = OpConstant %uint 0 %uint_0 = OpConstant %uint 0
%_ptr_StorageBuffer_int = OpTypePointer StorageBuffer %int %_ptr_StorageBuffer_int = OpTypePointer StorageBuffer %int
%_ptr_Function___atomic_compare_exchange_resulti32 = OpTypePointer Function %__atomic_compare_exchange_resulti32 %_ptr_Function___atomic_compare_exchange_resulti32 = OpTypePointer Function %__atomic_compare_exchange_resulti32
%28 = OpConstantNull %__atomic_compare_exchange_resulti32 %29 = OpConstantNull %__atomic_compare_exchange_resulti32
%atomicCompareExchangeWeak_1bd40a = OpFunction %void None %5 %atomicCompareExchangeWeak_1bd40a = OpFunction %void None %5
%8 = OpLabel %8 = OpLabel
%arg_1 = OpVariable %_ptr_Function_int Function %12 %arg_1 = OpVariable %_ptr_Function_int Function %12
%arg_2 = OpVariable %_ptr_Function_int Function %12 %arg_2 = OpVariable %_ptr_Function_int Function %12
%res = OpVariable %_ptr_Function___atomic_compare_exchange_resulti32 Function %28 %res = OpVariable %_ptr_Function___atomic_compare_exchange_resulti32 Function %29
OpStore %arg_1 %int_1 OpStore %arg_1 %int_1
OpStore %arg_2 %int_1 OpStore %arg_2 %int_1
%22 = OpAccessChain %_ptr_StorageBuffer_int %sb_rw %uint_0 %22 = OpAccessChain %_ptr_StorageBuffer_int %sb_rw %uint_0
%23 = OpLoad %int %arg_2 %23 = OpLoad %int %arg_2
%24 = OpAtomicCompareExchange %int %22 %uint_1 %uint_0 %uint_0 %23 %arg_1 %24 = OpLoad %int %arg_1
%25 = OpIEqual %bool %24 %23 %25 = OpAtomicCompareExchange %int %22 %uint_1 %uint_0 %uint_0 %23 %24
%14 = OpCompositeConstruct %__atomic_compare_exchange_resulti32 %24 %25 %26 = OpIEqual %bool %25 %23
%14 = OpCompositeConstruct %__atomic_compare_exchange_resulti32 %25 %26
OpStore %res %14 OpStore %res %14
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
%fragment_main = OpFunction %void None %5 %fragment_main = OpFunction %void None %5
%30 = OpLabel %31 = OpLabel
%31 = OpFunctionCall %void %atomicCompareExchangeWeak_1bd40a %32 = OpFunctionCall %void %atomicCompareExchangeWeak_1bd40a
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
%compute_main = OpFunction %void None %5 %compute_main = OpFunction %void None %5
%33 = OpLabel %34 = OpLabel
%34 = OpFunctionCall %void %atomicCompareExchangeWeak_1bd40a %35 = OpFunctionCall %void %atomicCompareExchangeWeak_1bd40a
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
1:1: AtomicCompareExchange: expected Comparator to be of type Result Type
%24 = OpAtomicCompareExchange %int %22 %uint_1 %uint_0 %uint_0 %23 %arg_1

View File

@ -1,9 +1,7 @@
SKIP: FAILED
; SPIR-V ; SPIR-V
; Version: 1.3 ; Version: 1.3
; Generator: Google Tint Compiler; 0 ; Generator: Google Tint Compiler; 0
; Bound: 33 ; Bound: 34
; Schema: 0 ; Schema: 0
OpCapability Shader OpCapability Shader
OpMemoryModel Logical GLSL450 OpMemoryModel Logical GLSL450
@ -43,32 +41,30 @@ SKIP: FAILED
%uint_0 = OpConstant %uint 0 %uint_0 = OpConstant %uint 0
%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint %_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
%_ptr_Function___atomic_compare_exchange_resultu32 = OpTypePointer Function %__atomic_compare_exchange_resultu32 %_ptr_Function___atomic_compare_exchange_resultu32 = OpTypePointer Function %__atomic_compare_exchange_resultu32
%26 = OpConstantNull %__atomic_compare_exchange_resultu32 %27 = OpConstantNull %__atomic_compare_exchange_resultu32
%atomicCompareExchangeWeak_63d8e6 = OpFunction %void None %5 %atomicCompareExchangeWeak_63d8e6 = OpFunction %void None %5
%8 = OpLabel %8 = OpLabel
%arg_1 = OpVariable %_ptr_Function_uint Function %12 %arg_1 = OpVariable %_ptr_Function_uint Function %12
%arg_2 = OpVariable %_ptr_Function_uint Function %12 %arg_2 = OpVariable %_ptr_Function_uint Function %12
%res = OpVariable %_ptr_Function___atomic_compare_exchange_resultu32 Function %26 %res = OpVariable %_ptr_Function___atomic_compare_exchange_resultu32 Function %27
OpStore %arg_1 %uint_1 OpStore %arg_1 %uint_1
OpStore %arg_2 %uint_1 OpStore %arg_2 %uint_1
%20 = OpAccessChain %_ptr_StorageBuffer_uint %sb_rw %uint_0 %20 = OpAccessChain %_ptr_StorageBuffer_uint %sb_rw %uint_0
%21 = OpLoad %uint %arg_2 %21 = OpLoad %uint %arg_2
%22 = OpAtomicCompareExchange %uint %20 %uint_1 %uint_0 %uint_0 %21 %arg_1 %22 = OpLoad %uint %arg_1
%23 = OpIEqual %bool %22 %21 %23 = OpAtomicCompareExchange %uint %20 %uint_1 %uint_0 %uint_0 %21 %22
%14 = OpCompositeConstruct %__atomic_compare_exchange_resultu32 %22 %23 %24 = OpIEqual %bool %23 %21
%14 = OpCompositeConstruct %__atomic_compare_exchange_resultu32 %23 %24
OpStore %res %14 OpStore %res %14
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
%fragment_main = OpFunction %void None %5 %fragment_main = OpFunction %void None %5
%28 = OpLabel %29 = OpLabel
%29 = OpFunctionCall %void %atomicCompareExchangeWeak_63d8e6 %30 = OpFunctionCall %void %atomicCompareExchangeWeak_63d8e6
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
%compute_main = OpFunction %void None %5 %compute_main = OpFunction %void None %5
%31 = OpLabel %32 = OpLabel
%32 = OpFunctionCall %void %atomicCompareExchangeWeak_63d8e6 %33 = OpFunctionCall %void %atomicCompareExchangeWeak_63d8e6
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
1:1: AtomicCompareExchange: expected Comparator to be of type Result Type
%22 = OpAtomicCompareExchange %uint %20 %uint_1 %uint_0 %uint_0 %21 %arg_1

View File

@ -1,17 +1,34 @@
SKIP: FAILED struct atomic_compare_exchange_resultu32 {
uint old_value;
bool exchanged;
};
groupshared uint arg_0;
void atomicCompareExchangeWeak_83580d() {
var<workgroup> arg_0 : atomic<u32>; uint arg_1 = 1u;
uint arg_2 = 1u;
fn atomicCompareExchangeWeak_83580d() { atomic_compare_exchange_resultu32 atomic_result = (atomic_compare_exchange_resultu32)0;
var arg_1 = 1u; uint atomic_compare_value = arg_1;
var arg_2 = 1u; InterlockedCompareExchange(arg_0, atomic_compare_value, arg_2, atomic_result.old_value);
var res = atomicCompareExchangeWeak(&(arg_0), arg_1, arg_2); atomic_result.exchanged = atomic_result.old_value == atomic_compare_value;
atomic_compare_exchange_resultu32 res = atomic_result;
} }
@compute @workgroup_size(1) struct tint_symbol_1 {
fn compute_main() { uint local_invocation_index : SV_GroupIndex;
};
void compute_main_inner(uint local_invocation_index) {
{
uint atomic_result_1 = 0u;
InterlockedExchange(arg_0, 0u, atomic_result_1);
}
GroupMemoryBarrierWithGroupSync();
atomicCompareExchangeWeak_83580d(); atomicCompareExchangeWeak_83580d();
} }
Failed to generate: error: unknown type in EmitType [numthreads(1, 1, 1)]
void compute_main(tint_symbol_1 tint_symbol) {
compute_main_inner(tint_symbol.local_invocation_index);
return;
}

View File

@ -1,9 +1,7 @@
SKIP: FAILED
; SPIR-V ; SPIR-V
; Version: 1.3 ; Version: 1.3
; Generator: Google Tint Compiler; 0 ; Generator: Google Tint Compiler; 0
; Bound: 40 ; Bound: 41
; Schema: 0 ; Schema: 0
OpCapability Shader OpCapability Shader
OpMemoryModel Logical GLSL450 OpMemoryModel Logical GLSL450
@ -39,37 +37,35 @@ SKIP: FAILED
%uint_2 = OpConstant %uint 2 %uint_2 = OpConstant %uint 2
%uint_0 = OpConstant %uint 0 %uint_0 = OpConstant %uint 0
%_ptr_Function___atomic_compare_exchange_resultu32 = OpTypePointer Function %__atomic_compare_exchange_resultu32 %_ptr_Function___atomic_compare_exchange_resultu32 = OpTypePointer Function %__atomic_compare_exchange_resultu32
%26 = OpConstantNull %__atomic_compare_exchange_resultu32 %27 = OpConstantNull %__atomic_compare_exchange_resultu32
%27 = OpTypeFunction %void %uint %28 = OpTypeFunction %void %uint
%uint_264 = OpConstant %uint 264 %uint_264 = OpConstant %uint 264
%atomicCompareExchangeWeak_83580d = OpFunction %void None %6 %atomicCompareExchangeWeak_83580d = OpFunction %void None %6
%9 = OpLabel %9 = OpLabel
%arg_1 = OpVariable %_ptr_Function_uint Function %13 %arg_1 = OpVariable %_ptr_Function_uint Function %13
%arg_2 = OpVariable %_ptr_Function_uint Function %13 %arg_2 = OpVariable %_ptr_Function_uint Function %13
%res = OpVariable %_ptr_Function___atomic_compare_exchange_resultu32 Function %26 %res = OpVariable %_ptr_Function___atomic_compare_exchange_resultu32 Function %27
OpStore %arg_1 %uint_1 OpStore %arg_1 %uint_1
OpStore %arg_2 %uint_1 OpStore %arg_2 %uint_1
%21 = OpLoad %uint %arg_2 %21 = OpLoad %uint %arg_2
%22 = OpAtomicCompareExchange %uint %arg_0 %uint_2 %uint_0 %uint_0 %21 %arg_1 %22 = OpLoad %uint %arg_1
%23 = OpIEqual %bool %22 %21 %23 = OpAtomicCompareExchange %uint %arg_0 %uint_2 %uint_0 %uint_0 %21 %22
%15 = OpCompositeConstruct %__atomic_compare_exchange_resultu32 %22 %23 %24 = OpIEqual %bool %23 %21
%15 = OpCompositeConstruct %__atomic_compare_exchange_resultu32 %23 %24
OpStore %res %15 OpStore %res %15
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
%compute_main_inner = OpFunction %void None %27 %compute_main_inner = OpFunction %void None %28
%local_invocation_index = OpFunctionParameter %uint %local_invocation_index = OpFunctionParameter %uint
%30 = OpLabel %31 = OpLabel
OpAtomicStore %arg_0 %uint_2 %uint_0 %13 OpAtomicStore %arg_0 %uint_2 %uint_0 %13
OpControlBarrier %uint_2 %uint_2 %uint_264 OpControlBarrier %uint_2 %uint_2 %uint_264
%35 = OpFunctionCall %void %atomicCompareExchangeWeak_83580d %36 = OpFunctionCall %void %atomicCompareExchangeWeak_83580d
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
%compute_main = OpFunction %void None %6 %compute_main = OpFunction %void None %6
%37 = OpLabel %38 = OpLabel
%39 = OpLoad %uint %local_invocation_index_1 %40 = OpLoad %uint %local_invocation_index_1
%38 = OpFunctionCall %void %compute_main_inner %39 %39 = OpFunctionCall %void %compute_main_inner %40
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
1:1: AtomicCompareExchange: expected Comparator to be of type Result Type
%22 = OpAtomicCompareExchange %uint %arg_0 %uint_2 %uint_0 %uint_0 %21 %arg_1

View File

@ -1,17 +1,34 @@
SKIP: FAILED struct atomic_compare_exchange_resulti32 {
int old_value;
bool exchanged;
};
groupshared int arg_0;
void atomicCompareExchangeWeak_e88938() {
var<workgroup> arg_0 : atomic<i32>; int arg_1 = 1;
int arg_2 = 1;
fn atomicCompareExchangeWeak_e88938() { atomic_compare_exchange_resulti32 atomic_result = (atomic_compare_exchange_resulti32)0;
var arg_1 = 1; int atomic_compare_value = arg_1;
var arg_2 = 1; InterlockedCompareExchange(arg_0, atomic_compare_value, arg_2, atomic_result.old_value);
var res = atomicCompareExchangeWeak(&(arg_0), arg_1, arg_2); atomic_result.exchanged = atomic_result.old_value == atomic_compare_value;
atomic_compare_exchange_resulti32 res = atomic_result;
} }
@compute @workgroup_size(1) struct tint_symbol_1 {
fn compute_main() { uint local_invocation_index : SV_GroupIndex;
};
void compute_main_inner(uint local_invocation_index) {
{
int atomic_result_1 = 0;
InterlockedExchange(arg_0, 0, atomic_result_1);
}
GroupMemoryBarrierWithGroupSync();
atomicCompareExchangeWeak_e88938(); atomicCompareExchangeWeak_e88938();
} }
Failed to generate: error: unknown type in EmitType [numthreads(1, 1, 1)]
void compute_main(tint_symbol_1 tint_symbol) {
compute_main_inner(tint_symbol.local_invocation_index);
return;
}

View File

@ -1,9 +1,7 @@
SKIP: FAILED
; SPIR-V ; SPIR-V
; Version: 1.3 ; Version: 1.3
; Generator: Google Tint Compiler; 0 ; Generator: Google Tint Compiler; 0
; Bound: 41 ; Bound: 42
; Schema: 0 ; Schema: 0
OpCapability Shader OpCapability Shader
OpMemoryModel Logical GLSL450 OpMemoryModel Logical GLSL450
@ -40,37 +38,35 @@ SKIP: FAILED
%uint_2 = OpConstant %uint 2 %uint_2 = OpConstant %uint 2
%uint_0 = OpConstant %uint 0 %uint_0 = OpConstant %uint 0
%_ptr_Function___atomic_compare_exchange_resulti32 = OpTypePointer Function %__atomic_compare_exchange_resulti32 %_ptr_Function___atomic_compare_exchange_resulti32 = OpTypePointer Function %__atomic_compare_exchange_resulti32
%27 = OpConstantNull %__atomic_compare_exchange_resulti32 %28 = OpConstantNull %__atomic_compare_exchange_resulti32
%28 = OpTypeFunction %void %uint %29 = OpTypeFunction %void %uint
%uint_264 = OpConstant %uint 264 %uint_264 = OpConstant %uint 264
%atomicCompareExchangeWeak_e88938 = OpFunction %void None %7 %atomicCompareExchangeWeak_e88938 = OpFunction %void None %7
%10 = OpLabel %10 = OpLabel
%arg_1 = OpVariable %_ptr_Function_int Function %14 %arg_1 = OpVariable %_ptr_Function_int Function %14
%arg_2 = OpVariable %_ptr_Function_int Function %14 %arg_2 = OpVariable %_ptr_Function_int Function %14
%res = OpVariable %_ptr_Function___atomic_compare_exchange_resulti32 Function %27 %res = OpVariable %_ptr_Function___atomic_compare_exchange_resulti32 Function %28
OpStore %arg_1 %int_1 OpStore %arg_1 %int_1
OpStore %arg_2 %int_1 OpStore %arg_2 %int_1
%22 = OpLoad %int %arg_2 %22 = OpLoad %int %arg_2
%23 = OpAtomicCompareExchange %int %arg_0 %uint_2 %uint_0 %uint_0 %22 %arg_1 %23 = OpLoad %int %arg_1
%24 = OpIEqual %bool %23 %22 %24 = OpAtomicCompareExchange %int %arg_0 %uint_2 %uint_0 %uint_0 %22 %23
%16 = OpCompositeConstruct %__atomic_compare_exchange_resulti32 %23 %24 %25 = OpIEqual %bool %24 %22
%16 = OpCompositeConstruct %__atomic_compare_exchange_resulti32 %24 %25
OpStore %res %16 OpStore %res %16
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
%compute_main_inner = OpFunction %void None %28 %compute_main_inner = OpFunction %void None %29
%local_invocation_index = OpFunctionParameter %uint %local_invocation_index = OpFunctionParameter %uint
%31 = OpLabel %32 = OpLabel
OpAtomicStore %arg_0 %uint_2 %uint_0 %14 OpAtomicStore %arg_0 %uint_2 %uint_0 %14
OpControlBarrier %uint_2 %uint_2 %uint_264 OpControlBarrier %uint_2 %uint_2 %uint_264
%36 = OpFunctionCall %void %atomicCompareExchangeWeak_e88938 %37 = OpFunctionCall %void %atomicCompareExchangeWeak_e88938
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
%compute_main = OpFunction %void None %7 %compute_main = OpFunction %void None %7
%38 = OpLabel %39 = OpLabel
%40 = OpLoad %uint %local_invocation_index_1 %41 = OpLoad %uint %local_invocation_index_1
%39 = OpFunctionCall %void %compute_main_inner %40 %40 = OpFunctionCall %void %compute_main_inner %41
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd
1:1: AtomicCompareExchange: expected Comparator to be of type Result Type
%23 = OpAtomicCompareExchange %int %arg_0 %uint_2 %uint_0 %uint_0 %22 %arg_1