Skip to content

Commit

Permalink
Subgroup intrinsics (#14)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
Firestar99 and Firestar99 authored Sep 23, 2024
1 parent 4c9718f commit 1103fcc
Show file tree
Hide file tree
Showing 27 changed files with 2,437 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ target/
.vim/
tests/Cargo.lock
.github/install-spirv-tools/Cargo.lock
rustc-ice-*.txt
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- 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.

### Changed 🛠
- [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)
- [PR#13](https://github.com/Rust-GPU/rust-gpu/pull/13) allow cargo features to be passed to the shader crate
- [PR#12](https://github.com/rust-gpu/rust-gpu/pull/12) updated toolchain to `nightly-2024-04-24`
- [PR#9](https://github.com/Rust-GPU/rust-gpu/pull/9) relaxed `glam` version requirements (`>=0.22, <=0.29`)
Expand Down
19 changes: 13 additions & 6 deletions crates/rustc_codegen_spirv/src/builder/spirv_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ use super::Builder;
use crate::builder_spirv::{BuilderCursor, SpirvValue};
use crate::codegen_cx::CodegenCx;
use crate::spirv_type::SpirvType;
use num_traits::FromPrimitive;
use rspirv::dr;
use rspirv::grammar::{reflect, LogicalOperand, OperandKind, OperandQuantifier};
use rspirv::spirv::{
FPFastMathMode, FragmentShadingRate, FunctionControl, ImageOperands, KernelProfilingInfo,
LoopControl, MemoryAccess, MemorySemantics, Op, RayFlags, SelectionControl, StorageClass, Word,
FPFastMathMode, FragmentShadingRate, FunctionControl, GroupOperation, ImageOperands,
KernelProfilingInfo, LoopControl, MemoryAccess, MemorySemantics, Op, RayFlags,
SelectionControl, StorageClass, Word,
};
use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_codegen_ssa::mir::place::PlaceRef;
Expand Down Expand Up @@ -1347,10 +1349,15 @@ impl<'cx, 'tcx> Builder<'cx, 'tcx> {
Ok(x) => inst.operands.push(dr::Operand::Scope(x)),
Err(()) => self.err(format!("unknown Scope {word}")),
},
(OperandKind::GroupOperation, Some(word)) => match word.parse() {
Ok(x) => inst.operands.push(dr::Operand::GroupOperation(x)),
Err(()) => self.err(format!("unknown GroupOperation {word}")),
},
(OperandKind::GroupOperation, Some(word)) => {
match word.parse::<u32>().ok().and_then(GroupOperation::from_u32) {
Some(id) => inst.operands.push(dr::Operand::GroupOperation(id)),
None => match word.parse() {
Ok(x) => inst.operands.push(dr::Operand::GroupOperation(x)),
Err(()) => self.err(format!("unknown GroupOperation {word}")),
},
}
}
(OperandKind::KernelEnqueueFlags, Some(word)) => match word.parse() {
Ok(x) => inst.operands.push(dr::Operand::KernelEnqueueFlags(x)),
Err(()) => self.err(format!("unknown KernelEnqueueFlags {word}")),
Expand Down
2 changes: 2 additions & 0 deletions crates/spirv-std/src/arch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ mod demote_to_helper_invocation_ext;
mod derivative;
mod primitive;
mod ray_tracing;
mod subgroup;

pub use atomics::*;
pub use barrier::*;
pub use demote_to_helper_invocation_ext::*;
pub use derivative::*;
pub use primitive::*;
pub use ray_tracing::*;
pub use subgroup::*;

/// Result is true if any component of `vector` is true, otherwise result is
/// false.
Expand Down
Loading

0 comments on commit 1103fcc

Please sign in to comment.