OpenQMC API
Loading...
Searching...
No Matches
sobolbn.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 "owen.h"
12#include "pcg.h"
13#include "sampler.h"
14#include "state.h"
15
16#include <cassert>
17#include <cstddef>
18#include <cstdint>
19#include <cstring>
20
21namespace oqmc
22{
23
25class SobolBnImpl
26{
27 // See SamplerInterface for public API documentation.
29
30 struct CacheType
31 {
32 std::uint32_t keyTable[bntables::size];
33 std::uint32_t rankTable[bntables::size];
34 };
35
36 static constexpr std::size_t cacheSize = sizeof(CacheType);
37 static void initialiseCache(void* cache);
38
39 /*AUTO_DEFINED*/ SobolBnImpl() = default;
41 OQMC_HOST_DEVICE SobolBnImpl(int x, int y, int frame, int index,
42 const void* cache);
43
44 OQMC_HOST_DEVICE SobolBnImpl newDomain(int key) const;
45 OQMC_HOST_DEVICE SobolBnImpl newDomainSplit(int key, int size,
46 int index) const;
47 OQMC_HOST_DEVICE SobolBnImpl newDomainDistrib(int key, int index) const;
48
49 template <int Size>
50 OQMC_HOST_DEVICE void drawSample(std::uint32_t sample[Size]) const;
51
52 template <int Size>
53 OQMC_HOST_DEVICE void drawRnd(std::uint32_t rnd[Size]) const;
54
55 State64Bit state;
56 const CacheType* cache;
57};
58
59inline void SobolBnImpl::initialiseCache(void* cache)
60{
62
63 auto typedCache = static_cast<CacheType*>(cache);
64
65 std::memcpy(typedCache->keyTable, bntables::sobol::keyTable,
67 std::memcpy(typedCache->rankTable, bntables::sobol::rankTable,
69}
70
71inline SobolBnImpl::SobolBnImpl(State64Bit state, const CacheType* cache)
73{
74 assert(cache);
75}
76
77inline SobolBnImpl::SobolBnImpl(int x, int y, int frame, int index,
78 const void* cache)
79 : state(x, y, frame, index), cache(static_cast<const CacheType*>(cache))
80{
81 assert(cache);
82}
83
84inline SobolBnImpl SobolBnImpl::newDomain(int key) const
85{
86 return {state.newDomain(key), cache};
87}
88
89inline SobolBnImpl SobolBnImpl::newDomainSplit(int key, int size,
90 int index) const
91{
92 return {state.newDomainSplit(key, size, index), cache};
93}
94
95inline SobolBnImpl SobolBnImpl::newDomainDistrib(int key, int index) const
96{
97 return {state.newDomainDistrib(key, index), cache};
98}
99
100template <int Size>
101void SobolBnImpl::drawSample(std::uint32_t sample[Size]) const
102{
103 constexpr auto xBits = State64Bit::spatialEncodeBitSizeX;
104 constexpr auto yBits = State64Bit::spatialEncodeBitSizeY;
105
106 static_assert(xBits == bntables::xBits,
107 "Pixel x encoding must match table.");
108 static_assert(yBits == bntables::yBits,
109 "Pixel y encoding must match table.");
110
111 const auto table = bntables::tableValue<xBits, yBits, 0>(
112 state.pixelId, pcg::output(state.patternId), cache->keyTable,
113 cache->rankTable);
114
115 shuffledScrambledSobol<Size>(state.sampleId ^ table.rank, table.key,
116 sample);
117}
118
119template <int Size>
120void SobolBnImpl::drawRnd(std::uint32_t rnd[Size]) const
121{
122 state.newDomain(state.pixelId).drawRnd<Size>(rnd);
123}
125
133
134} // 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 std::uint32_t rankTable[]
Optimised blue noise rank table for sobol.
Definition bntables.h:125
constexpr std::uint32_t keyTable[]
Optimised blue noise key table for sobol.
Definition bntables.h:120
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