skip to content
==> include/pathtrace/real.h <==
1/* @ajax/pathtrace-math: the float contract of programs/pathtrace's renderer. pathtrace-core in Rust is
2 * written once over `R: Real` and instantiated twice: f32 on the GPU (every op .rn.ftz by the build)
3 * and mesh-ref's Z on CPUs (every op flushed). Here the same code is written once in template headers
4 * (pathtrace/t_*.h) over these macros, and a translation unit instantiates it by defining them and
5 * including pathtrace/instantiate.h (@ajax/pathtrace-tile). Values are always `float`; only the
6 * operations differ.
7 *
8 * An instantiation defines:
9 *   PT_SUFFIX            the name suffix of every function, e.g. _f32 (pt_sample_f32)
10 *   PT_ADD(a, b) PT_SUB(a, b) PT_MUL(a, b) PT_DIV(a, b) PT_NEG(a)     each correctly rounded, unfused
11 *   PT_LT(a, b) PT_GT(a, b) PT_LE(a, b) PT_GE(a, b)                   false when a NaN is involved
12 * and may define PT_API (the linkage of the public functions; default static inline).
13 *
14 * Determinism rules (README "Cluster float mode: FTZ" of the Rust repo): only + - * / and compares on
15 * floats; integer -> float converts of values < 2^24; sqrt is a Newton iteration, cis a polynomial;
16 * the random numbers are a counter-based hash; accumulation orders are fixed. Compile with
17 * -ffp-contract=off. */
18#ifndef PATHTRACE_REAL_H
19#define PATHTRACE_REAL_H
20
21#include "pathtrace/consts.h"
22
23#include <stddef.h>
24
25#define PT_CAT_(a, b) a##b
26#define PT_CAT(a, b) PT_CAT_(a, b)
27/* pt_<name><PT_SUFFIX>. */
28#define PT_FN(name) PT_CAT(PT_CAT(pt_, name), PT_SUFFIX)
29/* A float from its bits, and an exact integer convert (callers pass values < 2^24). */
30#define PT_K(bits) pt_from_bits(bits)
31#define PT_FROM_U32(u) ((float)(uint32_t)(u))
32
33#endif