Intrinsics8 min read
Intrinsics
Built-in functions available in BWSL for common shader operations.
Reading Time
8 min
Word Count
1,354
Sections
15
Try It Live
Turn the guide into code
Take the key idea from this page into the playground and validate it in a real shader instead of leaving it as theory.
Open PlaygroundBWSL provides a broad intrinsic surface for math, texturing, derivatives, compute synchronization, atomics, and wave operations.
Math Functions
| Function | Signature | Description |
|---|---|---|
| abs | abs :: (T x) -> T | Absolute value |
| ceil | ceil :: (T x) -> T | Round up to nearest integer |
| clamp | clamp :: (T x, T min, T max) -> T | Clamp value between min and max |
| floor | floor :: (T x) -> T | Round down to nearest integer |
| fma | fma :: (T a, T b, T c) -> T | Fused multiply-add |
| fract | fract :: (T x) -> T | Fractional part of value |
| lerp | lerp :: (T a, T b, S t) -> T | Linear interpolation |
| max | max :: (T a, T b, ...) -> T | Maximum of values |
| min | min :: (T a, T b, ...) -> T | Minimum of values |
| mod | mod :: (T x, T y) -> T | Floating-point modulo |
| modf | modf :: (float x) -> BwslModfResult | Split fraction and whole parts |
| round | round :: (T x) -> T | Round to nearest integer |
| saturate | saturate :: (T x) -> T | Clamp to [0, 1] |
| sign | sign :: (T x) -> T | Sign of value (-1, 0, or 1) |
| smoothstep | smoothstep :: (S edge0, S edge1, T x) -> T | Hermite interpolation |
| step | step :: (T edge, T x) -> T | Step function |
| trunc | trunc :: (T x) -> T | Round toward zero |
Exponential & Power Functions
| Function | Signature | Description |
|---|---|---|
| exp | exp :: (T x) -> T | Natural exponential |
| exp2 | exp2 :: (T x) -> T | Base-2 exponential |
| frexp | frexp :: (float x) -> BwslFrexpResult | Split mantissa and exponent |
| ldexp | ldexp :: (float x, int e) -> float | Scale by a power of two |
| log | log :: (T x) -> T | Natural logarithm |
| log10 | log10 :: (T x) -> T | Base-10 logarithm |
| log2 | log2 :: (T x) -> T | Base-2 logarithm |
| pow | pow :: (T x, T y) -> T | Power function |
| rcp | rcp :: (T x) -> T | Reciprocal |
| rsqrt | rsqrt :: (T x) -> T | Inverse square root |
| sqrt | sqrt :: (T x) -> T | Square root |
Trigonometric Functions
| Function | Signature | Description |
|---|---|---|
| acos | acos :: (T x) -> T | Arc cosine |
| asin | asin :: (T x) -> T | Arc sine |
| atan | atan :: (T x) -> T | Arc tangent |
| atan2 | atan2 :: (T y, T x) -> T | Two-argument arc tangent |
| cos | cos :: (T x) -> T | Cosine |
| cosh | cosh :: (T x) -> T | Hyperbolic cosine |
| degrees | degrees :: (T x) -> T | Radians to degrees |
| radians | radians :: (T x) -> T | Degrees to radians |
| sin | sin :: (T x) -> T | Sine |
| sincos | sincos :: (...) -> void | Combined sine/cosine intrinsic; prefer sin and cos in user code for now |
| sinh | sinh :: (T x) -> T | Hyperbolic sine |
| tan | tan :: (T x) -> T | Tangent |
| tanh | tanh :: (T x) -> T | Hyperbolic tangent |
Vector Functions
| Function | Signature | Description |
|---|---|---|
| cross | cross :: (float3 a, float3 b) -> float3 | Cross product |
| distance | distance :: (vecN a, vecN b) -> float | Distance between points |
| dot | dot :: (vecN a, vecN b) -> float | Dot product |
| faceforward | faceforward :: (vecN n, vecN i, vecN nref) -> vecN | Flip normal to face viewer |
| length | length :: (vecN v) -> float | Vector magnitude |
| normalize | normalize :: (vecN v) -> vecN | Unit vector |
| reflect | reflect :: (vecN i, vecN n) -> vecN | Reflection vector |
| refract | refract :: (vecN i, vecN n, float eta) -> vecN | Refraction vector |
Matrix Functions
| Function | Signature | Description |
|---|---|---|
| determinant | determinant :: (matNxN m) -> float | Matrix determinant |
| inverse | inverse :: (matNxN m) -> matNxN | Matrix inverse |
| transpose | transpose :: (matNxM m) -> matMxN | Matrix transpose |
Derivative Functions
| Function | Signature | Description |
|---|---|---|
| ddx | ddx :: (T x) -> T | Partial derivative in x |
| ddx_coarse | ddx_coarse :: (T x) -> T | Coarse partial derivative in x |
| ddx_fine | ddx_fine :: (T x) -> T | Fine partial derivative in x |
| ddy | ddy :: (T x) -> T | Partial derivative in y |
| ddy_coarse | ddy_coarse :: (T x) -> T | Coarse partial derivative in y |
| ddy_fine | ddy_fine :: (T x) -> T | Fine partial derivative in y |
| fwidth | fwidth :: (T x) -> T | Sum of absolute derivatives |
| fwidth_coarse | fwidth_coarse :: (T x) -> T | Coarse filter width |
| fwidth_fine | fwidth_fine :: (T x) -> T | Fine filter width |
Texture Functions
| Function | Signature | Description |
|---|---|---|
| gather | gather :: (texture2D tex, sampler samp, float2 uv, int component) -> float4 | Gather 4 texels |
| gather_offset | gather_offset :: (texture2D tex, sampler samp, float2 uv, int component, int2 offset) -> float4 | Gather 4 texels with offset |
| load | load :: (texture2D tex, int2 coord, int mip) -> float4 | Load texel without filtering |
| load_offset | load_offset :: (texture2D tex, int2 coord, int mip, int2 offset) -> float4 | Load texel with offset |
| sample | sample :: (texture2D tex, sampler samp, float2 uv) -> float4 | Sample texture |
| sample_offset | sample_offset :: (texture2D tex, sampler samp, float2 uv, int2 offset) -> float4 | Sample texture with offset |
| sample_bias | sample_bias :: (texture2D tex, sampler samp, float2 uv, float bias) -> float4 | Sample with LOD bias |
| sample_bias_offset | sample_bias_offset :: (texture2D tex, sampler samp, float2 uv, float bias, int2 offset) -> float4 | Sample with bias and offset |
| sample_cmp | sample_cmp :: (texture2D tex, sampler samp, float2 uv, float cmp) -> float | Sample with comparison |
| sample_grad | sample_grad :: (texture2D tex, sampler samp, float2 uv, float2 ddx, float2 ddy) -> float4 | Sample with explicit gradients |
| sample_lod | sample_lod :: (texture2D tex, sampler samp, float2 uv, float lod) -> float4 | Sample at explicit LOD |
| sample_lod_offset | sample_lod_offset :: (texture2D tex, sampler samp, float2 uv, float lod, int2 offset) -> float4 | Sample explicit LOD with offset |
| store | store :: (RWTexture2D tex, int2 coord, float4 value) | Write to storage texture |
| texture_levels | texture_levels :: (texture tex) -> int | Query texture mip count |
| texture_size | texture_size :: (texture tex, int mip) -> intN | Query texture dimensions |
Synchronization Functions
| Function | Signature | Description |
|---|---|---|
barrier | barrier :: () -> void | Workgroup barrier |
memoryBarrier | memoryBarrier :: () -> void | Make memory writes visible |
storageBarrier | storageBarrier :: () -> void | Make storage writes visible |
Wave/SIMD Functions
| Function | Signature | Description |
|---|---|---|
| wave_all | wave_all :: (bool x) -> bool | True if all lanes are true |
| wave_any | wave_any :: (bool x) -> bool | True if any lane is true |
| wave_broadcast | wave_broadcast :: (T x, int lane) -> T | Broadcast from lane |
| wave_max | wave_max :: (T x) -> T | Maximum across wave |
| wave_min | wave_min :: (T x) -> T | Minimum across wave |
| wave_product | wave_product :: (T x) -> T | Product across wave |
| wave_read_first | wave_read_first :: (T x) -> T | Read from first active lane |
| wave_sum | wave_sum :: (T x) -> T | Sum across wave |
Atomic Functions
| Function | Signature | Description |
|---|---|---|
| atomic_add | atomic_add :: (integer lvalue dest, integer value) -> integer | Atomic addition |
| atomic_and | atomic_and :: (integer lvalue dest, integer value) -> integer | Atomic bitwise AND |
| atomic_cmp_exchange | atomic_cmp_exchange :: (integer lvalue dest, integer compare, integer value) -> integer | Atomic compare-exchange |
| atomic_exchange | atomic_exchange :: (integer lvalue dest, integer value) -> integer | Atomic exchange |
| atomic_max | atomic_max :: (integer lvalue dest, integer value) -> integer | Atomic maximum |
| atomic_min | atomic_min :: (integer lvalue dest, integer value) -> integer | Atomic minimum |
| atomic_or | atomic_or :: (integer lvalue dest, integer value) -> integer | Atomic bitwise OR |
| atomic_xor | atomic_xor :: (integer lvalue dest, integer value) -> integer | Atomic bitwise XOR |
Bit Manipulation Functions
| Function | Signature | Description |
|---|---|---|
| bitfield_extract | bitfield_extract :: (T value, int offset, int bits) -> T | Extract a bit field |
| bitfield_insert | bitfield_insert :: (T base, T insert, int offset, int bits) -> T | Insert a bit field |
| count_bits | count_bits :: (int x) -> int | Count set bits |
| first_bit_high | first_bit_high :: (int x) -> int | Find highest set bit |
| first_bit_low | first_bit_low :: (int x) -> int | Find lowest set bit |
| reverse_bits | reverse_bits :: (int x) -> int | Reverse bit order |
Data Conversion & Packing
| Function | Signature | Description |
|---|---|---|
| asfloat | asfloat :: (intNuintN x) -> floatN | Reinterpret bits as floats |
| asint | asint :: (floatNuintN x) -> intN | Reinterpret bits as signed integers |
| asuint | asuint :: (floatNintN x) -> uintN | Reinterpret bits as unsigned integers |
| f16tof32 | f16tof32 :: (uint x) -> float | Decode half-float bits |
| f32tof16 | f32tof16 :: (float x) -> uint | Encode half-float bits |
| pack_half2x16 | pack_half2x16 :: (float2 value) -> uint | Pack two half floats |
| unpack_half2x16 | unpack_half2x16 :: (uint packed) -> float2 | Unpack two half floats |
| pack_snorm2x16 | pack_snorm2x16 :: (float2 value) -> uint | Pack two signed normalized channels |
| unpack_snorm2x16 | unpack_snorm2x16 :: (uint packed) -> float2 | Unpack two signed normalized channels |
| pack_snorm4x8 | pack_snorm4x8 :: (float4 value) -> uint | Pack signed normalized channels |
| unpack_snorm4x8 | unpack_snorm4x8 :: (uint packed) -> float4 | Unpack signed normalized channels |
| pack_unorm2x16 | pack_unorm2x16 :: (float2 value) -> uint | Pack two unsigned normalized channels |
| unpack_unorm2x16 | unpack_unorm2x16 :: (uint packed) -> float2 | Unpack two unsigned normalized channels |
| pack_unorm4x8 | pack_unorm4x8 :: (float4 value) -> uint | Pack unsigned normalized channels |
| unpack_unorm4x8 | unpack_unorm4x8 :: (uint packed) -> float4 | Unpack unsigned normalized channels |
Control Flow Functions
| Function | Signature | Description |
|---|---|---|
| discard | discard :: () | Discard current fragment |
| select | select :: (T a, T b, bool cond) -> T | Conditional select |
Boolean Reductions
| Function | Signature | Description |
|---|---|---|
| all | all :: (bvecN x) -> bool | True if every component is true |
| any | any :: (bvecN x) -> bool | True if at least one component is true |
Float Classification
| Function | Signature | Description |
|---|---|---|
| isfinite | isfinite :: (floatN x) -> boolN | Componentwise finite-value test |
| isinf | isinf :: (floatN x) -> boolN | Componentwise +/-infinity test |
| isnan | isnan :: (floatN x) -> boolN | Componentwise NaN test |
| isnormal | isnormal :: (floatN x) -> boolN | Componentwise normal-value test |
T indicates the function works with scalar and vector types. S indicates a scalar type. The atomic rows above describe the current call shape rather than a formal type-system syntax.