skip to content
==> include/pathtrace/view.h <==
1/* @ajax/pathtrace-view: the view of programs/pathtrace (and its variant pathtrace-live): what the
2 * program, kcheck, mesh-top and the http program agree on (pathtrace-core lib.rs `view`). Byte
3 * offsets into the view. Tile-major: tile t's pixels are contiguous (row-major within it), so a
4 * tile's result is one block (a fleet job's payload). Freestanding. */
5#ifndef PATHTRACE_VIEW_H
6#define PATHTRACE_VIEW_H
7
8#include "pathtrace/scene.h"
9
10#include <stdint.h>
11
12#define PT_V_MAGIC 0x000u  /* u32 "PTVW" once OP_INIT ran */
13#define PT_V_NEXT 0x004u   /* pathtrace-live's next progressive work item: w = pass x tiles + tile */
14#define PT_V_TONEMAP 0x008u
15#define PT_V_GEN 0x00cu    /* scene generation: +1 on every scene load or restart */
16#define PT_V_TILES 0x010u
17#define PT_V_DONE 0x014u   /* tiles with every pass done */
18#define PT_V_WIDTH 0x018u
19#define PT_V_HEIGHT 0x01cu
20#define PT_V_SPP 0x020u
21#define PT_V_PASSES 0x024u
22#define PT_V_LAST_TILE 0x028u /* the last tile rendered, by whom (system; PEER_NONE single), where */
23#define PT_V_LAST_SYSTEM 0x02cu
24#define PT_V_LAST_EXEC 0x030u
25#define PT_V_SCENE_ERR 0x034u /* the last scene request's error code (0 ok) */
26#define PT_V_ITEMS 0x038u     /* work items (passes or job tiles) run */
27#define PT_VIEW_MAGIC 0x57565450u /* "PTVW" */
28#define PT_V_JOB_BASE 0x100u /* u64: the job item base meshd writes (manifest job_base) */
29#define PT_V_JOB_OUT 0x200u  /* job records: PT_JOB_REC bytes at V_JOB_OUT + JOB_REC (ticket % 64) */
30#define PT_JOB_REC 32u
31/* Words of a job record: the item's tile and pass, the digest of its pass sums (u64), the tile's
32 * accumulator digest after the fold (u64), its microseconds, its executor. */
33#define PT_J_TILE 0u
34#define PT_J_PASS 1u
35#define PT_J_PART 2u /* u64 lo, hi */
36#define PT_J_ACC 4u  /* u64 lo, hi */
37#define PT_J_US 6u
38#define PT_J_EXEC 7u
39/* The request window: a scene's words (raw, little-endian), or text ("restart", "status"). */
40#define PT_V_REQ 0x0a00u
41#define PT_REQ_MAX 0x1000u
42#define PT_V_RESP 0x1a00u
43#define PT_RESP_MAX 0x100u
44#define PT_V_SCENE 0x2000u
45/* Per tile, PT_META bytes: passes done (PT_FOLDING set while a pass is being added), system,
46 * exec | node << 8, last item's us, acc digest (u64), rgb digest (u64). */
47#define PT_V_META 0x3000u
48#define PT_META 32u
49#define PT_M_PASSES 0u
50#define PT_M_SYSTEM 4u
51#define PT_M_EXEC 8u
52#define PT_M_US 12u
53#define PT_M_ACC 16u
54#define PT_M_RGB 24u
55#define PT_FOLDING 0x80000000u /* M_PASSES while pass p is folded in: p | FOLDING */
56#define PT_VIEW_SNAP_BYTES 0x5600u /* the prefix the snapshot copies: header, scene, tiles' meta */
57/* The payload ring (manifest job_payload): an OP_JOB / OP_PASS item writes its pass sums (f32 r g b
58 * per pixel, row-major) at V_PAYLOAD + PAYLOAD (ticket % 64) before it returns. */
59#define PT_V_PAYLOAD 0x6000u
60#define PT_PAYLOAD (12u * PT_TILE_PIX)
61/* A view this long (and no longer) holds no tile: a fleet job's CPU variant (pathtrace-cpu). */
62#define PT_FLEET_VIEW_BYTES (PT_V_PAYLOAD + 64u * PT_PAYLOAD)
63#define PT_V_RGB PT_FLEET_VIEW_BYTES                          /* 0xffBBGGRR per pixel, tile-major */
64#define PT_V_ACC (PT_V_RGB + 4u * PT_TILE_PIX * PT_MAX_TILES) /* f32 r g b per pixel: the sums */
65#define PT_VIEW_BYTES (PT_V_ACC + 12u * PT_TILE_PIX * PT_MAX_TILES)
66/* Executors (M_EXEC's low byte). */
67#define PT_EXEC_CUDA 1u
68#define PT_EXEC_METAL 2u
69#define PT_EXEC_WASM 3u
70#define PT_EXEC_CPU 4u
71/* Ops (task pathtrace <op> <arg>). */
72#define PT_OP_RESTART 3u /* forget every tile (the scene stays) */
73#define PT_OP_TONEMAP 4u /* tone map arg (TONEMAP_*) and re-tone every tile, no render */
74#define PT_OP_DEFAULT 5u /* load the default scene (and restart) */
75#define PT_OP_PASS 6u    /* a job item as pass sums only: payload and record, no fold, no wait */
76#define PT_OP_SET 7u     /* a job's setup: scene word arg >> 24 := arg & 0xffffff, no restart */
77
78static inline uint32_t pt_view_rgb(uint32_t t) { return PT_V_RGB + 4u * PT_TILE_PIX * t; }
79static inline uint32_t pt_view_acc(uint32_t t) { return PT_V_ACC + 12u * PT_TILE_PIX * t; }
80static inline uint32_t pt_view_meta(uint32_t t) { return PT_V_META + PT_META * t; }
81static inline uint32_t pt_view_payload(uint32_t slot) { return PT_V_PAYLOAD + PT_PAYLOAD * slot; }
82
83_Static_assert(PT_V_SCENE + 4u * PT_SCENE_MAX_WORDS <= PT_V_META &&
84                   PT_V_META + PT_META * PT_MAX_TILES <= PT_VIEW_SNAP_BYTES && PT_VIEW_SNAP_BYTES <= PT_V_RGB,
85               "pathtrace view regions overlap");
86_Static_assert(PT_V_JOB_OUT + 64u * PT_JOB_REC <= PT_V_REQ && PT_V_REQ + PT_REQ_MAX <= PT_V_RESP &&
87                   PT_V_RESP + PT_RESP_MAX <= PT_V_SCENE,
88               "pathtrace view windows overlap");
89_Static_assert(PT_VIEW_BYTES <= 7u << 20, "pathtrace view exceeds 7 MiB");
90
91#endif