skip to content
==> src/digest.c <==
1/* programs/pathtrace's digests (pathtrace-core lib.rs `fold`, `payload_digest`; mesh-ref `fnv_words`). */
2#include "pathtrace/digest.h"
3
4#include "pathtrace/scene.h"
5
6uint64_t pt_fold(const uint64_t cols[32]) {
7    uint64_t h = PT_FNV_OFFSET;
8    for (int c = 0; c < 32; c++) h = pt_fnv(pt_fnv(h, (uint32_t)cols[c]), (uint32_t)(cols[c] >> 32));
9    return h;
10}
11
12uint64_t pt_fnv_words(const uint32_t *w, size_t n) {
13    uint64_t h = PT_FNV_OFFSET;
14    for (size_t i = 0; i < n; i++) h = pt_fnv(h, w[i]);
15    return h;
16}
17
18uint64_t pt_payload_digest(const uint32_t *words) {
19    uint64_t cols[32];
20    for (uint32_t cx = 0; cx < 32; cx++) {
21        uint64_t h = PT_FNV_OFFSET;
22        for (uint32_t row = 0; row < PT_TILE_H; row++) {
23            size_t o = 3 * (size_t)(row * PT_TILE_W + cx);
24            h = pt_fnv(pt_fnv(pt_fnv(h, words[o]), words[o + 1]), words[o + 2]);
25        }
26        cols[cx] = h;
27    }
28    return pt_fold(cols);
29}