|
| 1 | +//! compute shader built-ins |
| 2 | +
|
| 3 | +use glam::UVec3; |
| 4 | + |
| 5 | +/// The index of work item currently being operated on by a compute shader. |
| 6 | +/// |
| 7 | +/// In the compute language, [`local_invocation_id`] is an input variable containing the n-dimensional index of the |
| 8 | +/// local work invocation within the work group that the current shader is executing in. The possible values for this |
| 9 | +/// variable range across the local work group size, i.e., `(0,0,0)` to |
| 10 | +/// `(`[`workgroup_size`]`.x - 1, `[`workgroup_size`]`.y - 1, `[`workgroup_size`]`.z - 1)`. |
| 11 | +/// |
| 12 | +/// * GLSL: [`gl_LocalInvocationID`](https://registry.khronos.org/OpenGL-Refpages/gl4/html/gl_LocalInvocationID.xhtml) |
| 13 | +/// * WGSL: [`local_invocation_id`](https://www.w3.org/TR/WGSL/#local-invocation-id-builtin-value) |
| 14 | +/// * SPIR-V: [`LocalInvocationId`](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_builtin) |
| 15 | +#[doc(alias = "gl_LocalInvocationID")] |
| 16 | +#[doc(alias = "LocalInvocationId")] |
| 17 | +#[inline] |
| 18 | +#[gpu_only] |
| 19 | +pub fn local_invocation_id() -> UVec3 { |
| 20 | + crate::load_builtin!(LocalInvocationId) |
| 21 | +} |
| 22 | + |
| 23 | +/// The local linear index of work item currently being operated on by a compute shader. |
| 24 | +/// |
| 25 | +/// In the compute language, [`local_invocation_index`] is a derived input variable containing the 1-dimensional |
| 26 | +/// linearized index of the work invocation within the work group that the current shader is executing on. The value of |
| 27 | +/// [`local_invocation_index`] is equal to [`local_invocation_id`]`.z * `[`workgroup_size`]`.x * `[`workgroup_size`]`.y` |
| 28 | +/// `+ `[`local_invocation_id`]`.y * `[`workgroup_size`]`.x + `[`local_invocation_id`]`.x`. |
| 29 | +/// |
| 30 | +/// * GLSL: [`gl_LocalInvocationIndex`](https://registry.khronos.org/OpenGL-Refpages/gl4/html/gl_LocalInvocationIndex.xhtml) |
| 31 | +/// * WGSL: [`local_invocation_index`](https://www.w3.org/TR/WGSL/#local-invocation-index-builtin-value) |
| 32 | +/// * SPIR-V: [`LocalInvocationIndex`](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_builtin) |
| 33 | +#[doc(alias = "gl_LocalInvocationIndex")] |
| 34 | +#[doc(alias = "LocalInvocationIndex")] |
| 35 | +#[inline] |
| 36 | +#[gpu_only] |
| 37 | +pub fn local_invocation_index() -> u32 { |
| 38 | + crate::load_builtin!(LocalInvocationIndex) |
| 39 | +} |
| 40 | + |
| 41 | +/// The global index of work item currently being operated on by a compute shader. |
| 42 | +/// |
| 43 | +/// In the compute language, [`global_invocation_id`] is a derived input variable containing the n-dimensional index of |
| 44 | +/// the work invocation within the global work group that the current shader is executing on. The value of |
| 45 | +/// [`global_invocation_id`] is equal to [`workgroup_id`] * [`workgroup_size`] + [`local_invocation_id`]. |
| 46 | +/// |
| 47 | +/// * GLSL: [`gl_GlobalInvocationID`](https://registry.khronos.org/OpenGL-Refpages/gl4/html/gl_GlobalInvocationID.xhtml) |
| 48 | +/// * WGSL: [`global_invocation_id`](https://www.w3.org/TR/WGSL/#global-invocation-index-builtin-value) |
| 49 | +/// * SPIR-V: [`GlobalInvocationId`](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_builtin) |
| 50 | +#[doc(alias = "gl_GlobalInvocationID")] |
| 51 | +#[doc(alias = "GlobalInvocationId")] |
| 52 | +#[inline] |
| 53 | +#[gpu_only] |
| 54 | +pub fn global_invocation_id() -> UVec3 { |
| 55 | + crate::load_builtin!(GlobalInvocationId) |
| 56 | +} |
| 57 | + |
| 58 | +// custom: do not mention `glDispatchCompute` directly, be more general across APIs |
| 59 | +/// The number of workgroups that have been dispatched to a compute shader. |
| 60 | +/// |
| 61 | +/// In the compute language, [`num_workgroups`] contains the total number of work groups that will execute the compute |
| 62 | +/// shader. The components of [`num_workgroups`] are equal to the `x`, `y`, and `z` parameters passed to the dispatch |
| 63 | +/// command. |
| 64 | +/// |
| 65 | +/// * GLSL: [`gl_NumWorkGroups`](https://registry.khronos.org/OpenGL-Refpages/gl4/html/gl_NumWorkGroups.xhtml) |
| 66 | +/// * WGSL: [`num_workgroups`](https://www.w3.org/TR/WGSL/#num-workgroups-builtin-value) |
| 67 | +/// * SPIR-V: [`NumWorkgroups`](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_builtin) |
| 68 | +#[doc(alias = "gl_NumWorkGroups")] |
| 69 | +#[doc(alias = "NumWorkgroups")] |
| 70 | +#[inline] |
| 71 | +#[gpu_only] |
| 72 | +pub fn num_workgroups() -> UVec3 { |
| 73 | + crate::load_builtin!(NumWorkgroups) |
| 74 | +} |
| 75 | + |
| 76 | +// custom: do not mention `glDispatchCompute` directly, be more general across APIs |
| 77 | +/// The index of the workgroup currently being operated on by a compute shader. |
| 78 | +/// |
| 79 | +/// In the compute language, [`workgroup_id`] contains the 3-dimensional index of the global work group that the current |
| 80 | +/// compute shader invocation is executing within. The possible values range across the parameters passed into the |
| 81 | +/// dispatch command, i.e., from `(0, 0, 0)` to |
| 82 | +/// `(`[`num_workgroups`]`.x - 1, `[`num_workgroups`]`.y - 1, `[`num_workgroups`]`.z - 1)`. |
| 83 | +/// |
| 84 | +/// * GLSL: [`gl_WorkGroupID`](https://registry.khronos.org/OpenGL-Refpages/gl4/html/gl_WorkGroupID.xhtml) |
| 85 | +/// * WGSL: [`workgroup_id`](https://www.w3.org/TR/WGSL/#workgroup-id-builtin-value) |
| 86 | +/// * SPIR-V: [`WorkgroupId`](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html#_builtin) |
| 87 | +#[doc(alias = "gl_WorkGroupID")] |
| 88 | +#[doc(alias = "WorkgroupId")] |
| 89 | +#[inline] |
| 90 | +#[gpu_only] |
| 91 | +pub fn workgroup_id() -> UVec3 { |
| 92 | + crate::load_builtin!(WorkgroupId) |
| 93 | +} |
0 commit comments