OpenQMC API
Loading...
Searching...
No Matches
pmjbn.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright Contributors to the OpenQMC Project.
3
6
7#pragma once
8
9#include "bntables.h"
10#include "gpu.h"
11#include "lookup.h"
12#include "pcg.h"
13#include "sampler.h"
14#include "state.h"
15#include "stochastic.h"
16
17#include <cassert>
18#include <cstddef>
19#include <cstdint>
20#include <cstring>
21
22namespace oqmc
23{
24
26class PmjBnImpl
27{
28 // See SamplerInterface for public API documentation.
30
31 struct CacheType
32 {
33 std::uint32_t samples[State64Bit::maxIndexSize][4];
34 std::uint32_t keyTable[bntables::size];
35 std::uint32_t rankTable[bntables::size];
36 };
37
38 static constexpr std::size_t cacheSize = sizeof(CacheType);
39 static void initialiseCache(void* cache);
40
41 /*AUTO_DEFINED*/ PmjBnImpl() = default;
43 OQMC_HOST_DEVICE PmjBnImpl(int x, int y, int frame, int index,
44 const void* cache);
45
46 OQMC_HOST_DEVICE PmjBnImpl newDomain(int key) const;
47 OQMC_HOST_DEVICE PmjBnImpl newDomainSplit(int key, int size,
48 int index) const;
49 OQMC_HOST_DEVICE PmjBnImpl newDomainDistrib(int key, int index) const;
50
51 template <int Size>
52 OQMC_HOST_DEVICE void drawSample(std::uint32_t sample[Size]) const;
53
54 template <int Size>
55 OQMC_HOST_DEVICE void drawRnd(std::uint32_t rnd[Size]) const;
56
57 State64Bit state;
58 const CacheType* cache;
59};
60
61inline void PmjBnImpl::initialiseCache(void* cache)
62{
64
65 auto typedCache = static_cast<CacheType*>(cache);
66
68
69 std::memcpy(typedCache->keyTable, bntables::pmj::keyTable,
71 std::memcpy(typedCache->rankTable, bntables::pmj::rankTable,
73}
74
75inline PmjBnImpl::PmjBnImpl(State64Bit state, const CacheType* cache)
77{
78 assert(cache);
79}
80
81inline PmjBnImpl::PmjBnImpl(int x, int y, int frame, int index,
82 const void* cache)
83 : state(x, y, frame, index), cache(static_cast<const CacheType*>(cache))
84{
85 assert(cache);
86}
87
88inline PmjBnImpl PmjBnImpl::newDomain(int key) const
89{
90 return {state.newDomain(key), cache};
91}
92
93inline PmjBnImpl PmjBnImpl::newDomainSplit(int key, int size, int index) const
94{
95 return {state.newDomainSplit(key, size, index), cache};
96}
97
98inline PmjBnImpl PmjBnImpl::newDomainDistrib(int key, int index) const
99{
100 return {state.newDomainDistrib(key, index), cache};
101}
102
103template <int Size>
104void PmjBnImpl::drawSample(std::uint32_t sample[Size]) const
105{
106 constexpr auto xBits = State64Bit::spatialEncodeBitSizeX;
107 constexpr auto yBits = State64Bit::spatialEncodeBitSizeY;
108
109 static_assert(xBits == bntables::xBits,
110 "Pixel x encoding must match table.");
111 static_assert(yBits == bntables::yBits,
112 "Pixel y encoding must match table.");
113
114 const auto table = bntables::tableValue<xBits, yBits, 0>(
115 state.pixelId, pcg::output(state.patternId), cache->keyTable,
116 cache->rankTable);
117
118 shuffledScrambledLookup<4, Size>(state.sampleId ^ table.rank, table.key,
119 cache->samples, sample);
120}
121
122template <int Size>
123void PmjBnImpl::drawRnd(std::uint32_t rnd[Size]) const
124{
125 state.newDomain(state.pixelId).drawRnd<Size>(rnd);
126}
128
136
137} // namespace oqmc
#define OQMC_HOST_DEVICE
Definition gpu.h:13
Public sampler API.
Definition sampler.h:111
EncodeKey decodeBits16(std::uint16_t value)
Decode a value back into a key.
Definition encode.h:81
constexpr std::uint32_t keyTable[]
Optimised blue noise key table for pmj.
Definition bntables.h:93
constexpr std::uint32_t rankTable[]
Optimised blue noise rank table for pmj.
Definition bntables.h:98
constexpr auto yBits
256 pixels in y.
Definition bntables.h:70
constexpr auto xBits
256 pixels in x.
Definition bntables.h:69
Definition bntables.h:21
void stochasticPmjInit(int nsamples, std::uint32_t table[][4])
Initialise a table with a progressive mult-jittered (0,2) sequence.
Definition stochastic.h:33
static constexpr auto maxIndexSize
2^16 index upper limit.
Definition state.h:30