Skip to content

Commit b62cd33

Browse files
committed
builtin: make load_builtin macro $ty optional
1 parent 37f2a5b commit b62cd33

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

crates/spirv-std/src/builtin.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
//! * [GLSL reference source code](https://github.com/KhronosGroup/OpenGL-Refpages/tree/main/gl4)
88
//! * [GLSL extensions](https://github.com/KhronosGroup/GLSL/tree/main/extensions)
99
10+
/// Load a BuiltIn by name with optional type
1011
#[cfg(target_arch = "spirv")]
12+
#[macro_export]
1113
macro_rules! load_builtin {
12-
($ty:ty, $name:ident) => {
14+
($name:ident $(: $ty:ty)?) => {
1315
unsafe {
14-
let mut result = <$ty>::default();
16+
let mut result $(: $ty)? = Default::default();
1517
core::arch::asm! {
1618
"%builtin = OpVariable typeof{result_ref} Input",
1719
concat!("OpDecorate %builtin BuiltIn ", stringify!($name)),
@@ -39,7 +41,7 @@ pub mod compute {
3941
#[inline]
4042
#[gpu_only]
4143
pub fn local_invocation_id() -> UVec3 {
42-
load_builtin!(UVec3, LocalInvocationId)
44+
load_builtin!(LocalInvocationId)
4345
}
4446

4547
/// The current invocation’s local invocation index,
@@ -51,7 +53,7 @@ pub mod compute {
5153
#[inline]
5254
#[gpu_only]
5355
pub fn local_invocation_index() -> u32 {
54-
load_builtin!(u32, LocalInvocationIndex)
56+
load_builtin!(LocalInvocationIndex)
5557
}
5658

5759
// Global builtins, for this invocation's position in the compute grid.
@@ -65,7 +67,7 @@ pub mod compute {
6567
#[inline]
6668
#[gpu_only]
6769
pub fn global_invocation_id() -> UVec3 {
68-
load_builtin!(UVec3, GlobalInvocationId)
70+
load_builtin!(GlobalInvocationId)
6971
}
7072

7173
// Subgroup builtins
@@ -78,7 +80,7 @@ pub mod compute {
7880
#[inline]
7981
#[gpu_only]
8082
pub fn num_subgroups() -> u32 {
81-
load_builtin!(u32, NumSubgroups)
83+
load_builtin!(NumSubgroups)
8284
}
8385

8486
/// The subgroup ID of current invocation’s subgroup within the workgroup.
@@ -89,7 +91,7 @@ pub mod compute {
8991
#[inline]
9092
#[gpu_only]
9193
pub fn subgroup_id() -> u32 {
92-
load_builtin!(u32, SubgroupId)
94+
load_builtin!(SubgroupId)
9395
}
9496

9597
/// This invocation's ID within its subgroup.
@@ -100,7 +102,7 @@ pub mod compute {
100102
#[inline]
101103
#[gpu_only]
102104
pub fn subgroup_invocation_id() -> u32 {
103-
load_builtin!(u32, SubgroupLocalInvocationId)
105+
load_builtin!(SubgroupLocalInvocationId)
104106
}
105107

106108
/// The subgroup size of current invocation’s subgroup.
@@ -111,7 +113,7 @@ pub mod compute {
111113
#[inline]
112114
#[gpu_only]
113115
pub fn subgroup_size() -> u32 {
114-
load_builtin!(u32, SubgroupSize)
116+
load_builtin!(SubgroupSize)
115117
}
116118

117119
// Workgroup builtins
@@ -124,7 +126,7 @@ pub mod compute {
124126
#[inline]
125127
#[gpu_only]
126128
pub fn num_workgroups() -> UVec3 {
127-
load_builtin!(UVec3, NumWorkgroups)
129+
load_builtin!(NumWorkgroups)
128130
}
129131

130132
/// The current invocation’s workgroup ID,
@@ -136,6 +138,6 @@ pub mod compute {
136138
#[inline]
137139
#[gpu_only]
138140
pub fn workgroup_id() -> UVec3 {
139-
load_builtin!(UVec3, WorkgroupId)
141+
load_builtin!(WorkgroupId)
140142
}
141143
}

0 commit comments

Comments
 (0)