Fermat
pathtracer_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 <pathtracer.h>
32 #include <ray.h>
34 
35 
38 
41 
42 // A class encapsulating the path tracing queues
43 //
44 struct PTRayQueue
45 {
46  MaskedRay* rays; // rays
47  Hit* hits; // ray hits
48  float4* weights; // path weight
49  float4* weights_d; // diffuse path weight
50  float4* weights_g; // glossy path weight
51  uint4* pixels; // path pixel info
52  float2* cones; // ray cones
53  uint32* size; // queue size
54 
55  FERMAT_HOST
56  PTRayQueue() :
57  rays(NULL),
58  hits(NULL),
59  weights(NULL),
60  weights_d(NULL),
61  weights_g(NULL),
62  pixels(NULL),
63  cones(NULL),
64  size(NULL) {}
65 
66  FERMAT_DEVICE
67  void warp_append(const uint32 pixel_info, const MaskedRay& ray, const float4 weight, const cugar::Vector2f cone = cugar::Vector2f(0), const uint32 vertex_info = uint32(-1), const uint32 nee_slot = uint32(-1))
68  {
69  const uint32 slot = cugar::cuda::warp_increment(size);
70 
71  rays[slot] = ray;
72  weights[slot] = weight;
73  pixels[slot] = make_uint4( pixel_info, vertex_info, nee_slot, uint32(-1) );
74  if (cones)
75  cones[slot] = cone;
76  }
77 
78  FERMAT_DEVICE
79  void warp_append(const uint32 pixel_info, const MaskedRay& ray, const float4 weight, const float4 weight_d, const float4 weight_g, const uint32 vertex_info = uint32(-1), const uint32 nee_slot = uint32(-1), const uint32 nee_cluster = uint32(-1))
80  {
81  const uint32 slot = cugar::cuda::warp_increment(size);
82 
83  rays[slot] = ray;
84  weights[slot] = weight;
85 
86  if (weights_d)
87  weights_d[slot] = weight_d;
88  if (weights_g)
89  weights_g[slot] = weight_g;
90 
91  pixels[slot] = make_uint4( pixel_info, vertex_info, nee_slot, nee_cluster );
92  }
93 };
94 
__device__ __forceinline__ unsigned int warp_increment(unsigned int *ptr)
Definition: warp_atomics.h:56
Definition: ray.h:68
Definition: ray.h:55
Definition: pathtracer_queues.h:44
Define CUDA based warp adders.