Skip to content

Commit 2a9576c

Browse files
committed
builtin: glsl equivalents
1 parent 2dfc1eb commit 2a9576c

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

crates/spirv-std/src/builtin.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
//! Query SPIR-V read-only global built-in values
22
//!
33
//! Reference links:
4-
//! * [WGSL specification describing these builtins](https://www.w3.org/TR/WGSL/#builtin-inputs-outputs)
4+
//! * [WGSL specification describing builtins](https://www.w3.org/TR/WGSL/#builtin-inputs-outputs)
55
//! * [SPIR-V specification for builtins](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_builtin)
6-
//! * [GLSL 4.x reference](https://registry.khronos.org/OpenGL-Refpages/gl4/)
6+
//! * [GLSL reference](https://registry.khronos.org/OpenGL-Refpages/gl4/)
7+
//! * [GLSL reference source code](https://github.com/KhronosGroup/OpenGL-Refpages/tree/main/gl4)
8+
//! * [GLSL extensions](https://github.com/KhronosGroup/GLSL/tree/main/extensions)
79
810
#[cfg(target_arch = "spirv")]
911
macro_rules! load_builtin {
1012
($ty:ty, $name:ident) => {
1113
unsafe {
1214
let mut result = <$ty>::default();
13-
asm! {
15+
core::arch::asm! {
1416
"%builtin = OpVariable typeof{result_ref} Input",
1517
concat!("OpDecorate %builtin BuiltIn ", stringify!($name)),
1618
"%result = OpLoad typeof*{result_ref} %builtin",
@@ -24,8 +26,6 @@ macro_rules! load_builtin {
2426

2527
/// Compute shader built-ins
2628
pub mod compute {
27-
#[cfg(target_arch = "spirv")]
28-
use core::arch::asm;
2929
use glam::UVec3;
3030

3131
// Local builtins (for this invocation's position in the workgroup).
@@ -70,10 +70,11 @@ pub mod compute {
7070

7171
// Subgroup builtins
7272

73-
/// The number of subgroups in the current invocation’s workgroup.
73+
/// The number of subgroups in the current invocation’s workgroup.
7474
///
75+
/// GLSL: [`gl_NumSubgroups`](https://github.com/KhronosGroup/GLSL/blob/main/extensions/khr/GL_KHR_shader_subgroup.txt)
7576
/// WGSL: `num_subgroups`
76-
/// No equivalent in GLSL.
77+
#[doc(alias = "gl_NumSubgroups")]
7778
#[inline]
7879
#[gpu_only]
7980
pub fn num_subgroups() -> u32 {
@@ -82,8 +83,9 @@ pub mod compute {
8283

8384
/// The subgroup ID of current invocation’s subgroup within the workgroup.
8485
///
86+
/// GLSL: [`gl_SubgroupID`](https://github.com/KhronosGroup/GLSL/blob/main/extensions/khr/GL_KHR_shader_subgroup.txt)
8587
/// WGSL: `subgroup_id`
86-
/// No equivalent in GLSL.
88+
#[doc(alias = "gl_SubgroupID")]
8789
#[inline]
8890
#[gpu_only]
8991
pub fn subgroup_id() -> u32 {
@@ -92,19 +94,20 @@ pub mod compute {
9294

9395
/// This invocation's ID within its subgroup.
9496
///
97+
/// GLSL: [`gl_SubgroupInvocationID`](https://github.com/KhronosGroup/GLSL/blob/main/extensions/khr/GL_KHR_shader_subgroup.txt)
9598
/// WGSL: `subgroup_invocation_id`
96-
/// No equivalent in GLSL.
97-
#[doc(alias = "subgroup_invocation_id")]
99+
#[doc(alias = "gl_SubgroupInvocationID")]
98100
#[inline]
99101
#[gpu_only]
100-
pub fn subgroup_local_invocation_id() -> u32 {
102+
pub fn subgroup_invocation_id() -> u32 {
101103
load_builtin!(u32, SubgroupLocalInvocationId)
102104
}
103105

104106
/// The subgroup size of current invocation’s subgroup.
105107
///
108+
/// GLSL: [`gl_SubgroupSize`](https://github.com/KhronosGroup/GLSL/blob/main/extensions/khr/GL_KHR_shader_subgroup.txt)
106109
/// WGSL: `subgroup_size`
107-
/// No equivalent in GLSL.
110+
#[doc(alias = "gl_SubgroupInvocationID")]
108111
#[inline]
109112
#[gpu_only]
110113
pub fn subgroup_size() -> u32 {

0 commit comments

Comments
 (0)