Fermat
tiled_sequence.h
1 /*
2  * Fermat
3  *
4  * Copyright (c) 2016-2019, NVIDIA CORPORATION. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the NVIDIA CORPORATION nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #pragma once
30 
31 #include <tiled_sampling.h>
32 #include <buffers.h>
33 
36 
39 
53 struct FERMAT_API TiledSequenceView
54 {
55  FERMAT_HOST_DEVICE
56  uint32 shift_index(const uint32 idx, const uint32 dim) const
57  {
58  return dim*tile_size*tile_size + (idx & (tile_size*tile_size - 1u));
59  }
60 
61  FERMAT_HOST_DEVICE
62  float sample(const uint32 idx, const uint32 dim) const
63  {
64  FERMAT_ASSERT(dim < n_dimensions);
65  return samples[shift_index(idx, dim)];
66  }
67 
68  FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
69  float shift(const uint32 idx, const uint32 dim) const
70  {
71  FERMAT_ASSERT(dim < n_dimensions);
72  return shifts[shift_index(idx, dim)];
73  }
74 
75  FERMAT_HOST_DEVICE FERMAT_FORCEINLINE
76  float shift(const uint32 pixel_x, const uint32 pixel_y, const uint32 dim) const
77  {
78  FERMAT_ASSERT(dim < n_dimensions);
79  const uint32 shift_x = pixel_x & (tile_size - 1);
80  const uint32 shift_y = pixel_y & (tile_size - 1);
81  const uint32 shift_i = shift_x + shift_y*tile_size;
82  return shift(shift_i,dim);
83  }
84 
85  FERMAT_HOST_DEVICE
86  float sample_1d(const uint32 tile_idx, const uint32 idx, const uint32 dim) const
87  {
88  FERMAT_ASSERT(dim < n_dimensions);
89  return fmodf(sample(idx, dim) + shift(tile_idx, dim), 1.0f);
90  }
91 
92  FERMAT_HOST_DEVICE
93  float sample_2d(const uint32 pixel_x, const uint32 pixel_y, const uint32 dim) const
94  {
95  FERMAT_ASSERT(dim < n_dimensions);
96  const uint32 shift_x = pixel_x & (tile_size - 1);
97  const uint32 shift_y = pixel_y & (tile_size - 1);
98  const uint32 shift = shift_x + shift_y*tile_size;
99 
100  const uint32 tile_x = (pixel_x / tile_size) & (tile_size - 1);
101  const uint32 tile_y = (pixel_y / tile_size) & (tile_size - 1);
102  const uint32 tile = tile_x + tile_y*tile_size;
103 
104  return sample_1d(tile, shift, dim);
105  }
106 
107  uint32 n_dimensions;
108  uint32 tile_size;
109  const float* samples;
110  const float* shifts;
111 };
112 
131 struct FERMAT_API TiledSequence
132 {
133  TiledSequence() {}
134 
135  void setup(const uint32 _n_dimensions, const uint32 _tile_size, const bool _random = false);
136 
137  void set_instance(const uint32 instance);
138 
139  TiledSequenceView view()
140  {
142  r.n_dimensions = n_dimensions;
143  r.tile_size = tile_size;
144  r.samples = m_samples.ptr();
145  //r.shifts = m_shifts.ptr();
146  r.shifts = m_tile_shifts.ptr();
147  return r;
148  }
149 
150  uint32 n_dimensions;
151  uint32 tile_size;
152 
154  DomainBuffer<CUDA_BUFFER, float> m_tile_shifts;
157 };
158 
Definition: tiled_sequence.h:53
Definition: tiled_sequence.h:131