Shader built-ins¶
Import: import system.gpu;
This reference lists the public declarations for this part of the library. See Reading API signatures for parameter and result notation. Shader-only declarations can be used only inside @compute, @vertex, @fragment, inferred helpers and ray tracing shader functions; using them elsewhere is a compile error.
global_id¶
This thread's position in the whole compute dispatch: workgroup_id() * workgroup size + local_id(). With GpuDispatch.threads_1d(n), global_id().x runs from 0 to at least n - 1.
local_id¶
This thread's position within its workgroup, from 0 to the @compute size minus one.
local_index¶
local_id() flattened to one number: x + y * size.x + z * size.x * size.y.
workgroup_id¶
This thread's workgroup's position in the dispatch.
workgroup_count¶
The number of workgroups in the dispatch.
workgroup_barrier¶
Waits until every thread of the workgroup reaches this call, and makes their earlier writes to workgroup memory visible. Every thread must reach the same call.
storage_barrier¶
Like workgroup_barrier, and also makes the workgroup's earlier buffer writes visible to each other.
workgroup_array¶
Declares length elements of workgroup memory, shared by every thread of the workgroup and uninitialized at the start. length must be a constant. Call it once per array at the top of the shader.
vertex_id¶
The index of the vertex being processed: 0 to the draw's vertex count minus one, or the index buffer's value for indexed draws.
instance_id¶
The index of the instance being drawn, from 0.
discard_fragment¶
Discards the current pixel: nothing is written for it. The shader stops at this call.