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