Blender  V2.93
bvh_binning.h
Go to the documentation of this file.
1 /*
2  * Adapted from code copyright 2009-2011 Intel Corporation
3  * Modifications Copyright 2012, Blender Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef __BVH_BINNING_H__
19 #define __BVH_BINNING_H__
20 
21 #include "bvh/bvh_params.h"
22 #include "bvh/bvh_unaligned.h"
23 
24 #include "util/util_types.h"
25 
27 
28 class BVHBuild;
29 
30 /* Single threaded object binner. Finds the split with the best SAH heuristic
31  * by testing for each dimension multiple partitionings for regular spaced
32  * partition locations. A partitioning for a partition location is computed,
33  * by putting primitives whose centroid is on the left and right of the split
34  * location to different sets. The SAH is evaluated by computing the number of
35  * blocks occupied by the primitives in the partitions. */
36 
37 class BVHObjectBinning : public BVHRange {
38  public:
40  {
41  }
42 
43  BVHObjectBinning(const BVHRange &job,
44  BVHReference *prims,
45  const BVHUnaligned *unaligned_heuristic = NULL,
46  const Transform *aligned_space = NULL);
47 
48  void split(BVHReference *prims, BVHObjectBinning &left_o, BVHObjectBinning &right_o) const;
49 
51  {
52  return bounds_;
53  }
54 
55  float splitSAH; /* SAH cost of the best split */
56  float leafSAH; /* SAH cost of creating a leaf */
57 
58  protected:
59  int dim; /* best split dimension */
60  int pos; /* best split position */
61  size_t num_bins; /* actual number of bins to use */
62  float3 scale; /* scaling factor to compute bin */
63 
64  /* Effective bounds and centroid bounds. */
67 
70 
71  enum { MAX_BINS = 32 };
72  enum { LOG_BLOCK_SIZE = 2 };
73 
74  /* computes the bin numbers for each dimension for a box. */
75  __forceinline int4 get_bin(const BoundBox &box) const
76  {
77  int4 a = make_int4((box.center2() - cent_bounds_.min) * scale - make_float3(0.5f));
78  int4 mn = make_int4(0);
79  int4 mx = make_int4((int)num_bins - 1);
80 
81  return clamp(a, mn, mx);
82  }
83 
84  /* computes the bin numbers for each dimension for a point. */
86  {
87  return make_int4((c - cent_bounds_.min) * scale - make_float3(0.5f));
88  }
89 
90  /* compute the number of blocks occupied for each dimension. */
91  __forceinline float4 blocks(const int4 &a) const
92  {
93  return make_float4((a + make_int4((1 << LOG_BLOCK_SIZE) - 1)) >> LOG_BLOCK_SIZE);
94  }
95 
96  /* compute the number of blocks occupied in one dimension. */
97  __forceinline int blocks(size_t a) const
98  {
99  return (int)((a + ((1LL << LOG_BLOCK_SIZE) - 1)) >> LOG_BLOCK_SIZE);
100  }
101 
103  {
104  if (aligned_space_ == NULL) {
105  return prim.bounds();
106  }
107  else {
109  }
110  }
111 };
112 
114 
115 #endif /* __BVH_BINNING_H__ */
void split(BVHReference *prims, BVHObjectBinning &left_o, BVHObjectBinning &right_o) const
__forceinline int4 get_bin(const float3 &c) const
Definition: bvh_binning.h:85
const BVHUnaligned * unaligned_heuristic_
Definition: bvh_binning.h:68
__forceinline const BoundBox & unaligned_bounds()
Definition: bvh_binning.h:50
__forceinline int4 get_bin(const BoundBox &box) const
Definition: bvh_binning.h:75
__forceinline BVHObjectBinning()
Definition: bvh_binning.h:39
BoundBox bounds_
Definition: bvh_binning.h:65
__forceinline BoundBox get_prim_bounds(const BVHReference &prim) const
Definition: bvh_binning.h:102
__forceinline float4 blocks(const int4 &a) const
Definition: bvh_binning.h:91
__forceinline int blocks(size_t a) const
Definition: bvh_binning.h:97
const Transform * aligned_space_
Definition: bvh_binning.h:69
BoundBox cent_bounds_
Definition: bvh_binning.h:66
__forceinline const BoundBox & bounds() const
Definition: bvh_params.h:180
BoundBox compute_aligned_prim_boundbox(const BVHReference &prim, const Transform &aligned_space) const
#define CCL_NAMESPACE_END
#define make_int4(x, y, z, w)
#define make_float4(x, y, z, w)
#define make_float3(x, y, z)
static unsigned c
Definition: RandGen.cpp:97
static unsigned a[3]
Definition: RandGen.cpp:92
float3 min
Definition: util_boundbox.h:34
__forceinline float3 center2() const
#define __forceinline
Definition: util_defines.h:71
ccl_device_inline int clamp(int a, int mn, int mx)
Definition: util_math.h:283