ftz shaders 0.0.1
HLSL 2021 interface
Loading...
Searching...
No Matches
HLSL values

Classes

struct  ftz::ftz32
 Canonical binary32 word wrapper with named HLSL imports and exports. Ordinary aggregate casts/default storage do not normalize or initialize a value; use from_bits(), from_float() or zero(). Treat bits_ as implementation storage. More...

Functions

static ftz32 ftz::ftz32::from_bits (unsigned int bits)
 Imports a binary32 word and replaces a subnormal magnitude with signed zero.
static ftz32 ftz::ftz32::from_float (float value)
 Imports a float through its bits and normalizes subnormals.
static ftz32 ftz::ftz32::unsafe_from_float32 (float value)
 Wraps bits unchanged; the caller must supply normal, signed zero, infinity or NaN.
static ftz32 ftz::ftz32::zero ()
 Returns positive zero.
unsigned int ftz::ftz32::to_bits ()
 Exports the exact stored word without arithmetic.
float ftz::ftz32::to_float ()
 Exports stored bits as an ordinary HLSL float, leaving this value contract.
ftz32 ftz::neg (ftz32 value)
 Flips the sign bit without floating-point arithmetic.
ftz32 ftz::abs (ftz32 value)
 Clears the sign bit without floating-point arithmetic.
ftz32 ftz::sqrt (ftz32 value)
 Returns the reciprocal-refined square-root approximation; signed zero and positive infinity are preserved, negative nonzero values give NaN.
ftz32 ftz::floor (ftz32 value)
 Rounds toward negative infinity, independently of the ambient rounding direction; retains signed zero and infinities.
ftz32 ftz::ceil (ftz32 value)
 Rounds toward positive infinity, independently of the ambient rounding direction; retains signed zero and infinities.
ftz32 ftz::trunc (ftz32 value)
 Rounds toward zero, independently of the ambient rounding direction; retains signed zero and infinities.
ftz32 ftz::sin (ftz32 value)
 Returns the reproducible sine approximation in radians; signed zero is preserved and infinity gives NaN.
ftz32 ftz::cos (ftz32 value)
 Returns the reproducible cosine approximation in radians; either zero gives one and infinity gives NaN.
template<unsigned int Degree = 6>
ftz32 ftz::exp (ftz32 value)
 Returns the reproducible exponential; negative infinity gives positive zero and positive infinity is preserved.
ftz32 ftz::expm1 (ftz32 value)
 Approximates exp(x)-1 without subtracting one for tiny x; signed zero is preserved.
ftz32 ftz::tanh (ftz32 value)
 Returns the reproducible hyperbolic tangent; signed zero is preserved and infinities give signed one.
ftz32 ftz::log (ftz32 value)
 Returns the natural-log approximation; either zero gives negative infinity, negative nonzero values give NaN.
ftz32 ftz::log1p (ftz32 value)
 Approximates log(1+x); -1 gives negative infinity, x below -1 gives NaN, and signed zero is preserved.
ftz32 ftz::atan2 (ftz32 y, ftz32 x)
 Returns the angle in radians for (y,x), retaining signed-axis and infinity quadrants; NaN inputs give NaN.
ftz32_sincos_result ftz::sincos (ftz32 value)
 Returns sine followed by cosine, sharing reduction; C++ uses a pair and HLSL uses named fields.
bool ftz::isnan (ftz32 value)
 Tests the encoded NaN class without floating-point arithmetic or quieting a signaling NaN.
bool ftz::isinf (ftz32 value)
 Tests for either signed infinity by its encoded bits.
bool ftz::isfinite (ftz32 value)
 Tests for zero or finite magnitude by its encoded bits.
bool ftz::signbit (ftz32 value)
 Tests the sign bit, including negative zero and signed NaNs.
ftz32 ftz::copysign (ftz32 value, ftz32 sign)
 Copies the second operand's sign to the first operand's magnitude, preserving the magnitude's NaN payload.
ftz32 ftz::fma (ftz32 a, ftz32 b, ftz32 c)
 Computes a*b+c with one fused rounding and the FTZ boundary repair.

Detailed Description

Include <ftz/ftz32.h> in HLSL 2021. FTZ_FP32_HARDWARE_FTZ selects one shader policy at compilation; it does not choose CPU m32/h32 or configure the device. Hardware mode requires device-specific admission, including signed add/sub flushing. CPU admission never establishes that shader contract.

[numthreads(64,1,1)] void shader(uint3 id : SV_DispatchThreadID) {
// Shader policy is chosen at compile time with FTZ_FP32_HARDWARE_FTZ.
ftz::ftz32 value = ftz::ftz32::from_bits(inputs[id.x].x);
ftz::ftz32_sincos_result pair = ftz::sincos(value); // Named sine/cosine fields in HLSL.
ftz::ftz32 fused = ftz::fma(value, ftz::ftz32::from_float(2.f),
ftz::ftz32::from_float(1.f));
outputs[id.x] = uint4(pair.sine.to_bits(), pair.cosine.to_bits(),
fused.to_bits(), ftz::floor(value).to_bits());
}

Function Documentation

◆ exp()

template<unsigned int Degree = 6>
ftz32 ftz::exp ( ftz32 value)

Returns the reproducible exponential; negative infinity gives positive zero and positive infinity is preserved.

Template Parameters
DegreePolynomial degree in [1,7]; the default is 6.

Definition at line 214 of file ftz32.h.

◆ sincos()

ftz32_sincos_result ftz::sincos ( ftz32 value)

Returns sine followed by cosine, sharing reduction; C++ uses a pair and HLSL uses named fields.

Returns
ftz32_sincos_result with sine and cosine fields.

Definition at line 264 of file ftz32.h.