Skip to content

Remove unsafe from unconditionally safe subgroup ops #306

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

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
500 changes: 293 additions & 207 deletions crates/spirv-std/src/arch/subgroup.rs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions tests/compiletests/ui/arch/subgroup/subgroup_ballot.stderr
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
%1 = OpFunction %2 None %3
%4 = OpFunctionParameter %2
%5 = OpLabel
OpLine %6 380 8
OpLine %6 373 8
%7 = OpGroupNonUniformBallot %8 %9 %4
OpLine %6 416 8
OpLine %6 412 8
%10 = OpGroupNonUniformInverseBallot %2 %9 %7
OpNoLine
OpReturnValue %10
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%1 = OpFunction %2 None %3
%4 = OpFunctionParameter %2
%5 = OpLabel
OpLine %6 347 8
OpLine %6 340 8
%7 = OpGroupNonUniformBroadcastFirst %2 %8 %4
OpNoLine
OpReturnValue %7
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// build-pass
// compile-flags: -C target-feature=+GroupNonUniform,+GroupNonUniformArithmetic,+GroupNonUniformClustered,+ext:SPV_KHR_vulkan_memory_model
// normalize-stderr-test "\S*/crates/spirv-std/src/" -> "$$SPIRV_STD_SRC/"

use glam::UVec3;
use spirv_std::arch::{GroupOperation, SubgroupMask};
use spirv_std::spirv;

unsafe fn subgroup_test_fail(value: u32) -> u32 {
spirv_std::arch::subgroup_clustered_i_add::<0, _>(value)
}

#[spirv(compute(threads(32, 1, 1)))]
pub fn main(#[spirv(local_invocation_id)] local_invocation_id: UVec3) {
unsafe {
subgroup_test_fail(local_invocation_id.x);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
error[E0080]: evaluation of `spirv_std::arch::subgroup_clustered_i_add::<0, u32, u32>::{constant#0}` failed
--> $SPIRV_STD_SRC/arch/subgroup.rs:840:1
|
840 | / macro_subgroup_op_clustered!(impl Integer, "OpGroupNonUniformIAdd", subgroup_clustered_i_add; r"
841 | | An integer add group operation of all `value` operands contributed by active invocations in the group.
842 | |
843 | | Result Type must be a scalar or vector of integer type.
... |
856 | | * `ClusterSize` must not be greater than the size of the group
857 | | ");
| |__^ the evaluated program panicked at '`ClusterSize` must be at least 1', $SPIRV_STD_SRC/arch/subgroup.rs:840:1
|
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `macro_subgroup_op_clustered` (in Nightly builds, run with -Z macro-backtrace for more info)

note: erroneous constant encountered
--> $SPIRV_STD_SRC/arch/subgroup.rs:840:1
|
840 | / macro_subgroup_op_clustered!(impl Integer, "OpGroupNonUniformIAdd", subgroup_clustered_i_add; r"
841 | | An integer add group operation of all `value` operands contributed by active invocations in the group.
842 | |
843 | | Result Type must be a scalar or vector of integer type.
... |
856 | | * `ClusterSize` must not be greater than the size of the group
857 | | ");
| |__^
|
= note: this note originates in the macro `macro_subgroup_op_clustered` (in Nightly builds, run with -Z macro-backtrace for more info)

note: the above error was encountered while instantiating `fn spirv_std::arch::subgroup_clustered_i_add::<0, u32, u32>`
--> $DIR/subgroup_cluster_size_0_fail.rs:10:5
|
10 | spirv_std::arch::subgroup_clustered_i_add::<0, _>(value)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0080`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// build-pass
// compile-flags: -C target-feature=+GroupNonUniform,+GroupNonUniformArithmetic,+GroupNonUniformClustered,+ext:SPV_KHR_vulkan_memory_model
// normalize-stderr-test "\S*/crates/spirv-std/src/" -> "$$SPIRV_STD_SRC/"

use glam::UVec3;
use spirv_std::arch::{GroupOperation, SubgroupMask};
use spirv_std::spirv;

unsafe fn subgroup_test_fail(value: u32) -> u32 {
spirv_std::arch::subgroup_clustered_i_add::<5, _>(value)
}

#[spirv(compute(threads(32, 1, 1)))]
pub fn main(#[spirv(local_invocation_id)] local_invocation_id: UVec3) {
unsafe {
subgroup_test_fail(local_invocation_id.x);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
error[E0080]: evaluation of `spirv_std::arch::subgroup_clustered_i_add::<5, u32, u32>::{constant#0}` failed
--> $SPIRV_STD_SRC/arch/subgroup.rs:840:1
|
840 | / macro_subgroup_op_clustered!(impl Integer, "OpGroupNonUniformIAdd", subgroup_clustered_i_add; r"
841 | | An integer add group operation of all `value` operands contributed by active invocations in the group.
842 | |
843 | | Result Type must be a scalar or vector of integer type.
... |
856 | | * `ClusterSize` must not be greater than the size of the group
857 | | ");
| |__^ the evaluated program panicked at '`ClusterSize` must be a power of 2', $SPIRV_STD_SRC/arch/subgroup.rs:840:1
|
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `macro_subgroup_op_clustered` (in Nightly builds, run with -Z macro-backtrace for more info)

note: erroneous constant encountered
--> $SPIRV_STD_SRC/arch/subgroup.rs:840:1
|
840 | / macro_subgroup_op_clustered!(impl Integer, "OpGroupNonUniformIAdd", subgroup_clustered_i_add; r"
841 | | An integer add group operation of all `value` operands contributed by active invocations in the group.
842 | |
843 | | Result Type must be a scalar or vector of integer type.
... |
856 | | * `ClusterSize` must not be greater than the size of the group
857 | | ");
| |__^
|
= note: this note originates in the macro `macro_subgroup_op_clustered` (in Nightly builds, run with -Z macro-backtrace for more info)

note: the above error was encountered while instantiating `fn spirv_std::arch::subgroup_clustered_i_add::<5, u32, u32>`
--> $DIR/subgroup_cluster_size_non_power_of_two_fail.rs:10:5
|
10 | spirv_std::arch::subgroup_clustered_i_add::<5, _>(value)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0080`.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
%1 = OpFunction %2 None %3
%4 = OpLabel
OpLine %5 182 8
OpLine %5 170 8
%6 = OpGroupNonUniformElect %2 %7
OpNoLine
OpReturnValue %6
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%1 = OpFunction %2 None %3
%4 = OpFunctionParameter %2
%5 = OpLabel
OpLine %6 810 0
OpLine %6 840 0
%7 = OpGroupNonUniformIAdd %2 %8 ClusteredReduce %4 %9
OpNoLine
OpReturnValue %7
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%1 = OpFunction %2 None %3
%4 = OpFunctionParameter %2
%5 = OpLabel
OpLine %6 797 0
OpLine %6 827 0
%7 = OpGroupNonUniformIAdd %2 %8 ExclusiveScan %4
OpNoLine
OpReturnValue %7
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%1 = OpFunction %2 None %3
%4 = OpFunctionParameter %2
%5 = OpLabel
OpLine %6 797 0
OpLine %6 827 0
%7 = OpGroupNonUniformIAdd %2 %8 InclusiveScan %4
OpNoLine
OpReturnValue %7
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%1 = OpFunction %2 None %3
%4 = OpFunctionParameter %2
%5 = OpLabel
OpLine %6 797 0
OpLine %6 827 0
%7 = OpGroupNonUniformIAdd %2 %8 Reduce %4
OpNoLine
OpReturnValue %7
Expand Down