1/* @ajax/mesh-ref-pathtrace: programs/pathtrace's CPU reference (mesh-ref pathtrace.rs): the renderer
2 * in Z (@ajax/pathtrace-z), the same code the wasm image runs, so a tile rendered here is bit for bit
3 * the tile every backend must render. Also the image's assembly from tiles (tile-major -> raster), its
4 * PPM, and the digests kcheck and the demo compare. Host (threads, malloc). */
5#ifndef MESH_REF_PATHTRACE_H
6#define MESH_REF_PATHTRACE_H
78#include "pathtrace/default_scene.h" /* DEFAULT_SCENE, as mesh-ref re-exports it */
9#include "pathtrace/scene.h"
1011#include <stdbool.h>
12#include <stddef.h>
13#include <stdint.h>
1415/* One tile as the view holds it: the accumulated sums (f32 bits, r g b a pixel, row-major), the 8-bit
16 * pixels (0xffBBGGRR), their digests, and the digest of each pass's sums. */
17typedef struct {
18 uint32_t t, passes;
19 uint32_t acc[3 * PT_TILE_PIX];
20 uint32_t rgb[PT_TILE_PIX];
21 uint64_t acc_digest, rgb_digest;
22 uint64_t *part_digests; /* passes of them; free with mesh_pt_tile_free */
23} mesh_pt_tile;
2425/* Tile t after passes 0..passes (each pass's sums from +0, folded in pass order), tone mapped with op.
26 * False only when memory runs out. */
27bool mesh_pt_tile_render(const uint32_t *sc, uint32_t t, uint32_t passes, uint32_t op, mesh_pt_tile *out);
28void mesh_pt_tile_free(mesh_pt_tile *tile);
29/* Tiles ts[0..n) on every core into out[0..n) (each tile independent: order and threads change
30 * nothing). False when memory runs out (out is then freed). */
31bool mesh_pt_tiles(const uint32_t *sc, const uint32_t *ts, size_t n, uint32_t passes, uint32_t op, mesh_pt_tile *out);
3233/* The image's 8-bit RGB raster (row-major, 3 bytes a pixel, width x height x 3 bytes into out) from
34 * tile-major 0xffBBGGRR words (tiles x PT_TILE_PIX). */
35void mesh_pt_raster(const uint32_t *sc, const uint32_t *rgb, uint8_t *out);
36/* A binary PPM (P6) of a raster, malloc'd; its length in *len. NULL when memory runs out. */
37uint8_t *mesh_pt_ppm(uint32_t w, uint32_t h, const uint8_t *raster, size_t *len);
3839#endif