Fermat
bpt_queues.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 <ray_queues.h>
32 #include <buffers.h>
33 
36 
39 
43 {
44  RayQueue in_queue;
45  RayQueue scatter_queue;
46  RayQueue shadow_queue;
47 };
48 
52 {
53  void alloc(const uint32 n_entries)
54  {
55  m_rays.alloc(n_entries);
56  m_hits.alloc(n_entries);
57  m_weights.alloc(n_entries);
58  m_probs.alloc(n_entries);
59  m_path_weights.alloc(n_entries);
60  m_pixels.alloc(n_entries);
61  m_counters.alloc(4);
62  }
63 
64  void alloc(const uint32 n_eye_paths, const uint32 n_light_paths, const uint32 max_path_length)
65  {
66  const uint32 queue_size = cugar::max(n_eye_paths, n_light_paths) * 2 + n_eye_paths * (max_path_length + 1);
67 
68  alloc(queue_size);
69  }
70 
71  BPTQueuesView view(const uint32 n_eye_paths, const uint32 n_light_paths)
72  {
73  const uint32 n_rays = cugar::max(n_eye_paths, n_light_paths);
74 
75  BPTQueuesView r;
76 
77  r.in_queue.rays = m_rays.ptr();
78  r.in_queue.hits = m_hits.ptr();
79  r.in_queue.weights = m_weights.ptr();
80  r.in_queue.probs = m_probs.ptr();
81  r.in_queue.pixels = m_pixels.ptr();
82  r.in_queue.path_weights = m_path_weights.ptr();
83  r.in_queue.size = m_counters.ptr();
84 
85  r.scatter_queue.rays = r.in_queue.rays + n_rays;
86  r.scatter_queue.hits = r.in_queue.hits + n_rays;
87  r.scatter_queue.weights = r.in_queue.weights + n_rays;
88  r.scatter_queue.probs = r.in_queue.probs + n_rays;
89  r.scatter_queue.pixels = r.in_queue.pixels + n_rays;
90  r.scatter_queue.path_weights = r.in_queue.path_weights + n_rays;
91  r.scatter_queue.size = r.in_queue.size + 1;
92 
93  r.shadow_queue.rays = r.scatter_queue.rays + n_rays;
94  r.shadow_queue.hits = r.scatter_queue.hits + n_rays;
95  r.shadow_queue.weights = r.scatter_queue.weights + n_rays;
96  r.shadow_queue.probs = r.scatter_queue.probs + n_rays;
97  r.shadow_queue.pixels = r.scatter_queue.pixels + n_rays;
98  r.shadow_queue.path_weights = r.scatter_queue.path_weights + n_rays;
99  r.shadow_queue.size = r.scatter_queue.size + 1;
100 
101  return r;
102  }
103 
108  DomainBuffer<CUDA_BUFFER, float4> m_path_weights; // see 'TempPathWeights' struct
111 };
112 
Definition: bpt_queues.h:42
Definition: ray_queues.h:57
Definition: bpt_queues.h:51