skip to content
==> include/mesh/assemble.h <==
1/* @ajax/mesh-assemble: the assembler of a fleet-rendered pathtrace image (assemble.rs), sans IO:
2 * blobd feeds it the job's committed results (each item's blob reference and pass-sum digest) and the
3 * blobs' bytes, and asks it what to fetch next and for the image.
4 *
5 * An item w = pass x tiles + tile is one tile's pass sums, computed from +0 wherever it ran. The image
6 * is the reference's because each tile's pass sums are folded in pass order -- acc = ((0 + P0) + P1)
7 * + .., every add in the cluster float mode Z -- and exactly once per (tile, pass): a tile advances
8 * only by its next pass, so a blob that arrives early waits (the caller fetches at most WINDOW passes
9 * ahead) and a second copy of a folded pass is dropped. The 8-bit pixels are the tone map of the
10 * accumulators so far, recomputed when a tile changed or the tone map did. Every payload is checked
11 * against its item's pass-sum digest (the job record's J_PART) before it is folded. */
12#ifndef MESH_ASSEMBLE_H
13#define MESH_ASSEMBLE_H
14
15#include "mesh/jobs/id.h"
16#include "mesh/jobs/spec.h"
17#include "mesh/omap.h"
18
19#include <stdbool.h>
20#include <stddef.h>
21#include <stdint.h>
22
23/* Passes ahead of a tile's next one that are fetched and kept waiting. */
24#define MESH_ASSEMBLE_WINDOW 2u
25
26/* A committed item as the assembler needs it. */
27typedef struct {
28    mj_hash hash;
29    uint32_t len, holders;
30    uint32_t member; /* whose result was committed */
31    uint64_t part;   /* the item's pass-sum digest (its job record's J_PART) */
32} masm_item;
33
34/* The pass-sum digest in a pathtrace job record (job_out: J_PART, a u64 at word 2); false if short. */
35bool masm_part_of(const uint8_t *out, size_t n, uint64_t *part);
36/* The scene a job renders: the default scene with its setup applied in order (5:0, 7:<word << 24 |
37 * value>), valid for pass sums. Writes PT_DEFAULT_SCENE_WORDS words; false with *err. */
38bool masm_job_scene(const mj_setup *setup, size_t n, uint32_t *sc, char **err);
39/* Whether a job is a pathtrace image (its program renders one, its op leaves payloads). */
40bool masm_renders(const char *program, uint32_t op);
41
42typedef struct masm masm;
43
44masm *masm_new(mj_job_id job, const mj_setup *setup, size_t nsetup, uint32_t tone, char **err);
45void masm_free(masm *a);
46
47mj_job_id masm_job(const masm *a);
48const uint32_t *masm_scene(const masm *a);
49uint32_t masm_tiles(const masm *a);
50uint32_t masm_passes(const masm *a);
51uint32_t masm_tone(const masm *a);
52uint64_t masm_items(const masm *a);
53uint32_t masm_width(const masm *a);
54uint32_t masm_height(const masm *a);
55uint32_t masm_spp(const masm *a);
56bool masm_complete(const masm *a);
57uint32_t masm_tiles_done(const masm *a);
58uint64_t masm_folded(const masm *a);
59uint64_t masm_committed(const masm *a);
60/* Items folded per member (member -> uint64_t). */
61const momap *masm_by_member(const masm *a);
62/* Payloads refused (length or digest wrong): their count, and the i-th (item, why). */
63size_t masm_bad_count(const masm *a);
64const char *masm_bad_at(const masm *a, size_t i, uint64_t *item);
65/* Tile t: passes folded, and the member of the last one (UINT32_MAX: none). */
66void masm_tile(const masm *a, uint32_t t, uint32_t *passes, uint32_t *owner);
67
68/* A committed result (each at most once: a repeat, or an item folded already, is ignored). */
69void masm_commit(masm *a, uint64_t item, masm_item it);
70/* The committed items to fetch next, the lowest passes first: each tile's next WINDOW passes that are
71 * committed, not here yet and not asked for (asked(ctx, item)). At most budget; out[i] items. */
72size_t masm_wants(const masm *a, bool (*asked)(void *ctx, uint64_t item), void *ctx, size_t budget, uint64_t *items, masm_item *its);
73/* The committed item for item if it is still wanted, or NULL. */
74const masm_item *masm_wanted(const masm *a, uint64_t item);
75/* A blob's bytes for item (its sha256 checked by the caller): checked against the item's pass-sum
76 * digest, then folded with every pass of its tile that is ready, in order. Returns the passes folded
77 * now, or -1 when refused (kept as bad; *err says why: free it). */
78long masm_blob(masm *a, uint64_t item, const uint8_t *bytes, size_t n, char **err);
79/* The tone map the pixels are shown with; every tile is re-toned (no accumulator changes). */
80void masm_set_tone(masm *a, uint32_t tone);
81/* The 8-bit pixels (0xffBBGGRR), tile-major, re-toned where a tile changed. */
82const uint32_t *masm_rgb(masm *a);
83/* A tile's accumulators (3 x TILE_PIX f32 bits), or NULL before its first pass. */
84const uint32_t *masm_acc(const masm *a, uint32_t t);
85/* The image's digests as kcheck prints them: FNV over every tile's accumulator words in tile order
86 * (zeros for a tile with no pass) and over its pixels. */
87void masm_digests(masm *a, uint64_t *acc, uint64_t *pixels);
88/* The 8-bit RGB raster (row-major), PPM, BMP, and the PPM's sha256 in hex: new buffers. */
89uint8_t *masm_raster(masm *a, size_t *len);
90uint8_t *masm_ppm(masm *a, size_t *len);
91uint8_t *masm_bmp_of(masm *a, size_t *len);
92char *masm_sha256(masm *a);
93
94#endif