Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spv-in parse more atomic ops #5824

Merged
merged 17 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ By @bradwerth [#6216](https://github.com/gfx-rs/wgpu/pull/6216).

- Support constant evaluation for `firstLeadingBit` and `firstTrailingBit` numeric built-ins in WGSL. Front-ends that translate to these built-ins also benefit from constant evaluation. By @ErichDonGubler in [#5101](https://github.com/gfx-rs/wgpu/pull/5101).
- Add `first` and `either` sampling types for `@interpolate(flat, …)` in WGSL. By @ErichDonGubler in [#6181](https://github.com/gfx-rs/wgpu/pull/6181).
- Support for more atomic ops in the SPIR-V frontend. By @schell in [#5824](https://github.com/gfx-rs/wgpu/pull/5824).

#### Vulkan

Expand Down
8 changes: 2 additions & 6 deletions naga/src/front/atomic_upgrade.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ pub enum Error {
MultiMemberStruct,
#[error("encountered unsupported global initializer in an atomic variable")]
GlobalInitUnsupported,
}

impl From<Error> for crate::front::spv::Error {
fn from(source: Error) -> Self {
crate::front::spv::Error::AtomicUpgradeError(source)
}
#[error("expected to find a global variable")]
GlobalVariableMissing,
}

#[derive(Clone, Default)]
Expand Down
6 changes: 6 additions & 0 deletions naga/src/front/spv/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,9 @@ impl Error {
String::from_utf8(writer.into_inner()).unwrap()
}
}

impl From<atomic_upgrade::Error> for Error {
fn from(source: atomic_upgrade::Error) -> Self {
crate::front::spv::Error::AtomicUpgradeError(source)
}
}
405 changes: 363 additions & 42 deletions naga/src/front/spv/mod.rs

Large diffs are not rendered by default.

Binary file added naga/tests/in/spv/atomic_exchange.spv
Binary file not shown.
Empty file.
Binary file added naga/tests/in/spv/atomic_i_add_sub.spv
Binary file not shown.
51 changes: 51 additions & 0 deletions naga/tests/in/spv/atomic_i_add_sub.spvasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
; SPIR-V
; Version: 1.5
; Generator: Google rspirv; 0
; Bound: 30
; Schema: 0
OpCapability Shader
OpCapability VulkanMemoryModel
OpMemoryModel Logical Vulkan
OpEntryPoint GLCompute %1 "stage::test_atomic_i_add_sub" %2 %3
OpExecutionMode %1 LocalSize 32 1 1
OpDecorate %_runtimearr_uint ArrayStride 4
OpDecorate %_struct_7 Block
OpMemberDecorate %_struct_7 0 Offset 0
OpDecorate %_struct_8 Block
OpMemberDecorate %_struct_8 0 Offset 0
OpDecorate %2 Binding 0
OpDecorate %2 DescriptorSet 0
OpDecorate %3 Binding 1
OpDecorate %3 DescriptorSet 0
%uint = OpTypeInt 32 0
%void = OpTypeVoid
%11 = OpTypeFunction %void
%bool = OpTypeBool
%_runtimearr_uint = OpTypeRuntimeArray %uint
%_struct_7 = OpTypeStruct %_runtimearr_uint
%_ptr_StorageBuffer__struct_7 = OpTypePointer StorageBuffer %_struct_7
%uint_0 = OpConstant %uint 0
%uint_2 = OpConstant %uint 2
%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
%_struct_8 = OpTypeStruct %uint
%_ptr_StorageBuffer__struct_8 = OpTypePointer StorageBuffer %_struct_8
%2 = OpVariable %_ptr_StorageBuffer__struct_8 StorageBuffer
%3 = OpVariable %_ptr_StorageBuffer__struct_7 StorageBuffer
%1 = OpFunction %void None %11
%19 = OpLabel
%20 = OpAccessChain %_ptr_StorageBuffer_uint %2 %uint_0
%22 = OpArrayLength %uint %3 0
%23 = OpAtomicIAdd %uint %20 %uint_2 %uint_0 %uint_2
%24 = OpAtomicISub %uint %20 %uint_2 %uint_0 %23
%25 = OpULessThan %bool %23 %22
OpSelectionMerge %26 None
OpBranchConditional %25 %27 %28
%27 = OpLabel
%29 = OpAccessChain %_ptr_StorageBuffer_uint %3 %uint_0 %23
OpStore %29 %24
OpBranch %26
%28 = OpLabel
OpBranch %26
%26 = OpLabel
OpReturn
OpFunctionEnd
Binary file added naga/tests/in/spv/atomic_i_decrement.spv
Binary file not shown.
64 changes: 64 additions & 0 deletions naga/tests/in/spv/atomic_i_decrement.spvasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
; SPIR-V
; Version: 1.5
; Generator: Google rspirv; 0
; Bound: 42
; Schema: 0
OpCapability Shader
OpCapability VulkanMemoryModel
OpMemoryModel Logical Vulkan
OpEntryPoint GLCompute %1 "stage::test_atomic_i_decrement" %2 %3
OpExecutionMode %1 LocalSize 32 1 1
OpDecorate %_runtimearr_uint ArrayStride 4
OpDecorate %_struct_7 Block
OpMemberDecorate %_struct_7 0 Offset 0
OpDecorate %_struct_8 Block
OpMemberDecorate %_struct_8 0 Offset 0
OpDecorate %2 Binding 0
OpDecorate %2 DescriptorSet 0
OpDecorate %3 Binding 1
OpDecorate %3 DescriptorSet 0
%uint = OpTypeInt 32 0
%void = OpTypeVoid
%11 = OpTypeFunction %void
%bool = OpTypeBool
%_runtimearr_uint = OpTypeRuntimeArray %uint
%_struct_7 = OpTypeStruct %_runtimearr_uint
%_ptr_StorageBuffer__struct_7 = OpTypePointer StorageBuffer %_struct_7
%uint_0 = OpConstant %uint 0
%uint_2 = OpConstant %uint 2
%false = OpConstantFalse %bool
%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
%true = OpConstantTrue %bool
%_struct_8 = OpTypeStruct %uint
%_ptr_StorageBuffer__struct_8 = OpTypePointer StorageBuffer %_struct_8
%2 = OpVariable %_ptr_StorageBuffer__struct_8 StorageBuffer
%3 = OpVariable %_ptr_StorageBuffer__struct_7 StorageBuffer
%1 = OpFunction %void None %11
%21 = OpLabel
%22 = OpAccessChain %_ptr_StorageBuffer_uint %2 %uint_0
%24 = OpArrayLength %uint %3 0
OpBranch %25
%25 = OpLabel
OpLoopMerge %26 %27 None
OpBranch %28
%28 = OpLabel
%29 = OpAtomicIDecrement %uint %22 %uint_2 %uint_0
%30 = OpULessThan %bool %29 %24
OpSelectionMerge %31 None
OpBranchConditional %30 %32 %33
%32 = OpLabel
%34 = OpAccessChain %_ptr_StorageBuffer_uint %3 %uint_0 %29
OpStore %34 %29
%35 = OpIEqual %bool %29 %uint_0
%41 = OpSelect %bool %35 %false %true
OpBranch %31
%33 = OpLabel
OpBranch %31
%31 = OpLabel
%40 = OpPhi %bool %41 %32 %false %33
OpBranch %27
%27 = OpLabel
OpBranchConditional %40 %25 %26
%26 = OpLabel
OpReturn
OpFunctionEnd
Binary file added naga/tests/in/spv/atomic_load_and_store.spv
Binary file not shown.
86 changes: 86 additions & 0 deletions naga/tests/in/spv/atomic_load_and_store.spvasm
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
; SPIR-V
; Version: 1.5
; Generator: Google rspirv; 0
; Bound: 60
; Schema: 0
OpCapability Shader
OpCapability VulkanMemoryModel
OpMemoryModel Logical Vulkan
OpEntryPoint GLCompute %1 "stage::test_atomic_load_and_store" %2 %3
OpExecutionMode %1 LocalSize 32 1 1
OpMemberDecorate %_struct_11 0 Offset 0
OpMemberDecorate %_struct_11 1 Offset 4
OpDecorate %_struct_12 Block
OpMemberDecorate %_struct_12 0 Offset 0
OpDecorate %2 Binding 0
OpDecorate %2 DescriptorSet 0
OpDecorate %3 NonWritable
OpDecorate %3 Binding 1
OpDecorate %3 DescriptorSet 0
%uint = OpTypeInt 32 0
%void = OpTypeVoid
%15 = OpTypeFunction %void
%bool = OpTypeBool
%uint_0 = OpConstant %uint 0
%uint_2 = OpConstant %uint 2
%false = OpConstantFalse %bool
%_ptr_StorageBuffer_uint = OpTypePointer StorageBuffer %uint
%uint_1 = OpConstant %uint 1
%_struct_11 = OpTypeStruct %uint %uint
%22 = OpUndef %_struct_11
%int = OpTypeInt 32 1
%true = OpConstantTrue %bool
%_struct_12 = OpTypeStruct %uint
%_ptr_StorageBuffer__struct_12 = OpTypePointer StorageBuffer %_struct_12
%2 = OpVariable %_ptr_StorageBuffer__struct_12 StorageBuffer
%3 = OpVariable %_ptr_StorageBuffer__struct_12 StorageBuffer
%1 = OpFunction %void None %15
%26 = OpLabel
%27 = OpAccessChain %_ptr_StorageBuffer_uint %2 %uint_0
%28 = OpAccessChain %_ptr_StorageBuffer_uint %3 %uint_0
%29 = OpLoad %uint %28
%30 = OpCompositeConstruct %_struct_11 %uint_0 %29
OpBranch %31
%31 = OpLabel
%32 = OpPhi %_struct_11 %30 %26 %33 %34
OpLoopMerge %35 %34 None
OpBranch %36
%36 = OpLabel
%37 = OpCompositeExtract %uint %32 0
%38 = OpCompositeExtract %uint %32 1
%39 = OpULessThan %bool %37 %38
OpSelectionMerge %40 None
OpBranchConditional %39 %41 %42
%41 = OpLabel
%44 = OpIAdd %uint %37 %uint_1
%46 = OpCompositeInsert %_struct_11 %44 %32 0
%47 = OpCompositeConstruct %_struct_11 %uint_1 %37
OpBranch %40
%42 = OpLabel
%48 = OpCompositeInsert %_struct_11 %uint_0 %22 0
OpBranch %40
%40 = OpLabel
%49 = OpPhi %_struct_11 %46 %41 %32 %42
%50 = OpPhi %_struct_11 %47 %41 %48 %42
%51 = OpCompositeExtract %uint %50 0
%52 = OpBitcast %int %51
OpSelectionMerge %53 None
OpSwitch %52 %54 0 %55 1 %56
%54 = OpLabel
OpBranch %53
%55 = OpLabel
OpBranch %53
%56 = OpLabel
%57 = OpAtomicLoad %uint %27 %uint_2 %uint_0
%58 = OpIAdd %uint %57 %uint_2
OpAtomicStore %27 %uint_2 %uint_0 %58
OpBranch %53
%53 = OpLabel
%59 = OpPhi %bool %false %54 %false %55 %true %56
%33 = OpPhi %_struct_11 %22 %54 %22 %55 %49 %56
OpBranch %34
%34 = OpLabel
OpBranchConditional %59 %31 %35
%35 = OpLabel
OpReturn
OpFunctionEnd
4 changes: 0 additions & 4 deletions naga/tests/out/ir/atomic_i_increment.compact.ron
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,6 @@
),
],
reject: [
Emit((
start: 13,
end: 14,
)),
Atomic(
pointer: 7,
fun: Add,
Expand Down
4 changes: 0 additions & 4 deletions naga/tests/out/ir/atomic_i_increment.ron
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,6 @@
),
],
reject: [
Emit((
start: 14,
end: 15,
)),
Atomic(
pointer: 8,
fun: Add,
Expand Down
Loading