Skip to content

Commit 1103fcc

Browse files
authored
Subgroup intrinsics (#14)
* subgroup: add trait VectorOrScalar, representing either a vector or a scalar type * subgroup: added all non-uniform subgroup operations * subgroup: remove all target_feature cfgs, replaced with docs * subgroup: added all subgroupBarrier*() functions from glsl * subgroup: added non group-op tests * subgroup: fixed asm for instructions taking GROUP_OP generic * subgroup: added tests for group-op instructions * gitignore: added rustc-ice* error reports * subgroup: added test for subgroup buildins * subgroup: make SubgroupMask a struct to prevent implicit casts to and from UVec4 * subgroup: fixed clippy lints * subgroup: drop the `non_uniform` from all subgroup functions, matching glsl * changelog: add subgroup intrinsics PR * subgroup: make VectorOrScalar trait match discussions in EmbarkStudios/rust-gpu#1030 * cleanup: remove internal type F32x2 for glam::Vec2 --------- Co-authored-by: Firestar99 <[email protected]>
1 parent 4c9718f commit 1103fcc

27 files changed

+2437
-51
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ target/
33
.vim/
44
tests/Cargo.lock
55
.github/install-spirv-tools/Cargo.lock
6+
rustc-ice-*.txt

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3333
- Signed for loops like `for _ in 0..4i32 {}` no longer compile. We recommend switching to unsigned for loops and casting back to signed integers in the meanwhile.
3434

3535
### Changed 🛠
36+
- [PR#14](https://github.com/Rust-GPU/rust-gpu/pull/14) add subgroup intrinsics matching glsl's [`GL_KHR_shader_subgroup`](https://github.com/KhronosGroup/GLSL/blob/main/extensions/khr/GL_KHR_shader_subgroup.txt)
3637
- [PR#13](https://github.com/Rust-GPU/rust-gpu/pull/13) allow cargo features to be passed to the shader crate
3738
- [PR#12](https://github.com/rust-gpu/rust-gpu/pull/12) updated toolchain to `nightly-2024-04-24`
3839
- [PR#9](https://github.com/Rust-GPU/rust-gpu/pull/9) relaxed `glam` version requirements (`>=0.22, <=0.29`)

crates/rustc_codegen_spirv/src/builder/spirv_asm.rs

+13-6
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ use super::Builder;
22
use crate::builder_spirv::{BuilderCursor, SpirvValue};
33
use crate::codegen_cx::CodegenCx;
44
use crate::spirv_type::SpirvType;
5+
use num_traits::FromPrimitive;
56
use rspirv::dr;
67
use rspirv::grammar::{reflect, LogicalOperand, OperandKind, OperandQuantifier};
78
use rspirv::spirv::{
8-
FPFastMathMode, FragmentShadingRate, FunctionControl, ImageOperands, KernelProfilingInfo,
9-
LoopControl, MemoryAccess, MemorySemantics, Op, RayFlags, SelectionControl, StorageClass, Word,
9+
FPFastMathMode, FragmentShadingRate, FunctionControl, GroupOperation, ImageOperands,
10+
KernelProfilingInfo, LoopControl, MemoryAccess, MemorySemantics, Op, RayFlags,
11+
SelectionControl, StorageClass, Word,
1012
};
1113
use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
1214
use rustc_codegen_ssa::mir::place::PlaceRef;
@@ -1347,10 +1349,15 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
13471349
Ok(x) => inst.operands.push(dr::Operand::Scope(x)),
13481350
Err(()) => self.err(format!("unknown Scope {word}")),
13491351
},
1350-
(OperandKind::GroupOperation, Some(word)) => match word.parse() {
1351-
Ok(x) => inst.operands.push(dr::Operand::GroupOperation(x)),
1352-
Err(()) => self.err(format!("unknown GroupOperation {word}")),
1353-
},
1352+
(OperandKind::GroupOperation, Some(word)) => {
1353+
match word.parse::<u32>().ok().and_then(GroupOperation::from_u32) {
1354+
Some(id) => inst.operands.push(dr::Operand::GroupOperation(id)),
1355+
None => match word.parse() {
1356+
Ok(x) => inst.operands.push(dr::Operand::GroupOperation(x)),
1357+
Err(()) => self.err(format!("unknown GroupOperation {word}")),
1358+
},
1359+
}
1360+
}
13541361
(OperandKind::KernelEnqueueFlags, Some(word)) => match word.parse() {
13551362
Ok(x) => inst.operands.push(dr::Operand::KernelEnqueueFlags(x)),
13561363
Err(()) => self.err(format!("unknown KernelEnqueueFlags {word}")),

crates/spirv-std/src/arch.rs

+2
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ mod demote_to_helper_invocation_ext;
1919
mod derivative;
2020
mod primitive;
2121
mod ray_tracing;
22+
mod subgroup;
2223

2324
pub use atomics::*;
2425
pub use barrier::*;
2526
pub use demote_to_helper_invocation_ext::*;
2627
pub use derivative::*;
2728
pub use primitive::*;
2829
pub use ray_tracing::*;
30+
pub use subgroup::*;
2931

3032
/// Result is true if any component of `vector` is true, otherwise result is
3133
/// false.

0 commit comments

Comments
 (0)