Blender  V3.3
binning.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: Apache-2.0
2  * Adapted from code copyright 2009-2011 Intel Corporation
3  * Modifications Copyright 2012-2022 Blender Foundation. */
4 
5 #ifndef __BVH_BINNING_H__
6 #define __BVH_BINNING_H__
7 
8 #include "bvh/params.h"
9 #include "bvh/unaligned.h"
10 
11 #include "util/types.h"
12 
14 
15 class BVHBuild;
16 
17 /* Single threaded object binner. Finds the split with the best SAH heuristic
18  * by testing for each dimension multiple partitionings for regular spaced
19  * partition locations. A partitioning for a partition location is computed,
20  * by putting primitives whose centroid is on the left and right of the split
21  * location to different sets. The SAH is evaluated by computing the number of
22  * blocks occupied by the primitives in the partitions. */
23 
24 class BVHObjectBinning : public BVHRange {
25  public:
27  {
28  }
29 
30  BVHObjectBinning(const BVHRange &job,
31  BVHReference *prims,
32  const BVHUnaligned *unaligned_heuristic = NULL,
33  const Transform *aligned_space = NULL);
34 
35  void split(BVHReference *prims, BVHObjectBinning &left_o, BVHObjectBinning &right_o) const;
36 
38  {
39  return bounds_;
40  }
41 
42  float splitSAH; /* SAH cost of the best split */
43  float leafSAH; /* SAH cost of creating a leaf */
44 
45  protected:
46  int dim; /* best split dimension */
47  int pos; /* best split position */
48  size_t num_bins; /* actual number of bins to use */
49  float3 scale; /* scaling factor to compute bin */
50 
51  /* Effective bounds and centroid bounds. */
54 
57 
58  enum { MAX_BINS = 32 };
59  enum { LOG_BLOCK_SIZE = 2 };
60 
61  /* computes the bin numbers for each dimension for a box. */
62  __forceinline int4 get_bin(const BoundBox &box) const
63  {
64  int4 a = make_int4((box.center2() - cent_bounds_.min) * scale - make_float3(0.5f));
65  int4 mn = make_int4(0);
66  int4 mx = make_int4((int)num_bins - 1);
67 
68  return clamp(a, mn, mx);
69  }
70 
71  /* computes the bin numbers for each dimension for a point. */
73  {
74  return make_int4((c - cent_bounds_.min) * scale - make_float3(0.5f));
75  }
76 
77  /* compute the number of blocks occupied for each dimension. */
79  {
80  return make_float4((a + make_int4((1 << LOG_BLOCK_SIZE) - 1)) >> LOG_BLOCK_SIZE);
81  }
82 
83  /* compute the number of blocks occupied in one dimension. */
84  __forceinline int blocks(size_t a) const
85  {
86  return (int)((a + ((1LL << LOG_BLOCK_SIZE) - 1)) >> LOG_BLOCK_SIZE);
87  }
88 
90  {
91  if (aligned_space_ == NULL) {
92  return prim.bounds();
93  }
94  else {
96  }
97  }
98 };
99 
101 
102 #endif /* __BVH_BINNING_H__ */
float float4[4]
Definition: build.h:34
float3 scale
Definition: binning.h:49
void split(BVHReference *prims, BVHObjectBinning &left_o, BVHObjectBinning &right_o) const
Definition: binning.cpp:216
__forceinline int4 get_bin(const float3 &c) const
Definition: binning.h:72
const BVHUnaligned * unaligned_heuristic_
Definition: binning.h:55
__forceinline const BoundBox & unaligned_bounds()
Definition: binning.h:37
__forceinline int4 get_bin(const BoundBox &box) const
Definition: binning.h:62
__forceinline BVHObjectBinning()
Definition: binning.h:26
float leafSAH
Definition: binning.h:43
float splitSAH
Definition: binning.h:42
BoundBox bounds_
Definition: binning.h:52
__forceinline BoundBox get_prim_bounds(const BVHReference &prim) const
Definition: binning.h:89
__forceinline float4 blocks(const int4 &a) const
Definition: binning.h:78
__forceinline int blocks(size_t a) const
Definition: binning.h:84
const Transform * aligned_space_
Definition: binning.h:56
size_t num_bins
Definition: binning.h:48
BoundBox cent_bounds_
Definition: binning.h:53
__forceinline const BoundBox & bounds() const
Definition: params.h:203
BoundBox compute_aligned_prim_boundbox(const BVHReference &prim, const Transform &aligned_space) const
Definition: unaligned.cpp:77
#define CCL_NAMESPACE_END
Definition: cuda/compat.h:9
#define make_int4(x, y, z, w)
Definition: metal/compat.h:208
#define make_float4(x, y, z, w)
Definition: metal/compat.h:205
#define make_float3(x, y, z)
Definition: metal/compat.h:204
static unsigned c
Definition: RandGen.cpp:83
static unsigned a[3]
Definition: RandGen.cpp:78
T clamp(const T &a, const T &min, const T &max)
#define __forceinline
float3 min
Definition: boundbox.h:21
__forceinline float3 center2() const
Definition: boundbox.h:119