Module dsl

Module dsl 

Source
Expand description

DSL marker functions for WGSL code generation.

These functions are compile-time markers that the transpiler recognizes and converts to WGSL intrinsics. They do nothing at Rust compile time.

§Thread/Workgroup Indices

FunctionWGSL Equivalent
thread_idx_x()local_invocation_id.x
thread_idx_y()local_invocation_id.y
thread_idx_z()local_invocation_id.z
block_idx_x()workgroup_id.x
block_idx_y()workgroup_id.y
block_idx_z()workgroup_id.z
block_dim_x()WORKGROUP_SIZE_X (constant)
global_thread_id()global_invocation_id.x

Functions§

abs
Absolute value. Maps to abs(x) in WGSL.
atomic_add
Atomic add. Maps to atomicAdd(&var, value) in WGSL.
atomic_cas
Atomic compare-and-swap. Maps to atomicCompareExchangeWeak(&var, compare, value) in WGSL. Returns the old value.
atomic_exchange
Atomic exchange. Maps to atomicExchange(&var, value) in WGSL.
atomic_load
Atomic load. Maps to atomicLoad(&var) in WGSL.
atomic_max
Atomic maximum. Maps to atomicMax(&var, value) in WGSL.
atomic_min
Atomic minimum. Maps to atomicMin(&var, value) in WGSL.
atomic_store
Atomic store. Maps to atomicStore(&var, value) in WGSL.
atomic_sub
Atomic subtract. Maps to atomicSub(&var, value) in WGSL.
block_dim_x
Get the x-dimension of the workgroup size. Maps to a compile-time constant WORKGROUP_SIZE_X in WGSL.
block_dim_y
Get the y-dimension of the workgroup size. Maps to a compile-time constant WORKGROUP_SIZE_Y in WGSL.
block_dim_z
Get the z-dimension of the workgroup size. Maps to a compile-time constant WORKGROUP_SIZE_Z in WGSL.
block_idx_x
Get the x-component of the workgroup index. Maps to workgroup_id.x in WGSL.
block_idx_y
Get the y-component of the workgroup index. Maps to workgroup_id.y in WGSL.
block_idx_z
Get the z-component of the workgroup index. Maps to workgroup_id.z in WGSL.
ceil
Ceiling. Maps to ceil(x) in WGSL.
clamp
Clamp. Maps to clamp(x, lo, hi) in WGSL.
cos
Cosine. Maps to cos(x) in WGSL.
exp
Exponential. Maps to exp(x) in WGSL.
floor
Floor. Maps to floor(x) in WGSL.
fma
Fused multiply-add. Maps to fma(a, b, c) in WGSL.
global_thread_id
Get the global thread ID (x-component). Maps to global_invocation_id.x in WGSL.
global_thread_id_y
Get the global thread ID in the y-dimension. Maps to global_invocation_id.y in WGSL.
global_thread_id_z
Get the global thread ID in the z-dimension. Maps to global_invocation_id.z in WGSL.
grid_dim_x
Get the x-component of the number of workgroups in the dispatch. Maps to num_workgroups.x in WGSL.
grid_dim_y
Get the y-component of the number of workgroups in the dispatch. Maps to num_workgroups.y in WGSL.
grid_dim_z
Get the z-component of the number of workgroups in the dispatch. Maps to num_workgroups.z in WGSL.
lane_id
Get the lane ID within the subgroup. Maps to subgroup_invocation_id builtin in WGSL.
log
Natural logarithm. Maps to log(x) in WGSL.
max
Maximum. Maps to max(a, b) in WGSL.
min
Minimum. Maps to min(a, b) in WGSL.
mix
Linear interpolation. Maps to mix(a, b, t) in WGSL.
powf
Power. Maps to pow(x, y) in WGSL.
round
Round to nearest. Maps to round(x) in WGSL.
rsqrt
Reciprocal square root. Maps to inverseSqrt(x) in WGSL.
sin
Sine. Maps to sin(x) in WGSL.
sqrt
Square root. Maps to sqrt(x) in WGSL.
sync_threads
Synchronize all threads in the workgroup. Maps to workgroupBarrier() in WGSL.
tan
Tangent. Maps to tan(x) in WGSL.
thread_fence
Memory fence for storage buffers. Maps to storageBarrier() in WGSL.
thread_fence_block
Memory fence within the workgroup. Maps to workgroupBarrier() in WGSL.
thread_idx_x
Get the x-component of the local thread index within the workgroup. Maps to local_invocation_id.x in WGSL.
thread_idx_y
Get the y-component of the local thread index within the workgroup. Maps to local_invocation_id.y in WGSL.
thread_idx_z
Get the z-component of the local thread index within the workgroup. Maps to local_invocation_id.z in WGSL.
warp_all
Check if all lanes in subgroup satisfy predicate. Maps to subgroupAll(predicate) in WGSL.
warp_any
Check if any lane in subgroup satisfies predicate. Maps to subgroupAny(predicate) in WGSL.
warp_ballot
Ballot within subgroup. Maps to subgroupBallot(predicate) in WGSL. Returns a vec4 where each bit represents a lane’s predicate.
warp_shuffle
Shuffle within subgroup. Maps to subgroupShuffle(value, lane) in WGSL. Requires: enable chromium_experimental_subgroups;
warp_shuffle_down
Shuffle down within subgroup. Maps to subgroupShuffleDown(value, delta) in WGSL.
warp_shuffle_up
Shuffle up within subgroup. Maps to subgroupShuffleUp(value, delta) in WGSL.
warp_shuffle_xor
Shuffle XOR within subgroup. Maps to subgroupShuffleXor(value, mask) in WGSL.
warp_size
Get the subgroup size. Maps to subgroup_size builtin in WGSL.