Blender V5.0
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#pragma once
9
10#include "bvh/params.h"
11#include "bvh/unaligned.h"
12
13#include "util/types.h"
14
16
17class BVHBuild;
18
19/* Single threaded object binner. Finds the split with the best SAH heuristic
20 * by testing for each dimension multiple partitionings for regular spaced
21 * partition locations. A partitioning for a partition location is computed,
22 * by putting primitives whose centroid is on the left and right of the split
23 * location to different sets. The SAH is evaluated by computing the number of
24 * blocks occupied by the primitives in the partitions. */
25
26class BVHObjectBinning : public BVHRange {
27 public:
29
30 BVHObjectBinning(const BVHRange &job,
31 BVHReference *prims,
32 const BVHUnaligned *unaligned_heuristic = nullptr,
33 const Transform *aligned_space = nullptr);
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. */
63 {
64 const int4 a = make_int4((box.center2() - cent_bounds_.min) * scale - make_float3(0.5f));
65 const int4 mn = make_int4(0);
66 const 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(const size_t a) const
85 {
86 return (int)((a + ((1LL << LOG_BLOCK_SIZE) - 1)) >> LOG_BLOCK_SIZE);
87 }
88
90 {
91 if (aligned_space_ == nullptr) {
92 return prim.bounds();
93 }
94 return unaligned_heuristic_->compute_aligned_prim_boundbox(prim, *aligned_space_);
95 }
96};
97
void split(BVHReference *prims, BVHObjectBinning &left_o, BVHObjectBinning &right_o) const
Definition binning.cpp:212
__forceinline int4 get_bin(const float3 &c) const
Definition binning.h:72
const BVHUnaligned * unaligned_heuristic_
Definition binning.h:55
__forceinline int4 get_bin(const BoundBox &box) const
Definition binning.h:62
__forceinline BVHObjectBinning()
Definition binning.h:28
__forceinline int blocks(const size_t a) const
Definition binning.h:84
BoundBox bounds_
Definition binning.h:52
__forceinline BoundBox get_prim_bounds(const BVHReference &prim) const
Definition binning.h:89
__forceinline const BoundBox & unaligned_bounds()
Definition binning.h:37
__forceinline float4 blocks(const int4 &a) const
Definition binning.h:78
const Transform * aligned_space_
Definition binning.h:56
size_t num_bins
Definition binning.h:48
BoundBox cent_bounds_
Definition binning.h:53
__forceinline BVHRange()
Definition params.h:245
__forceinline const BoundBox & bounds() const
Definition params.h:204
#define __forceinline
#define CCL_NAMESPACE_END
ccl_device_forceinline float3 make_float3(const float x, const float y, const float z)
ccl_device_forceinline int4 make_int4(const int x, const int y, const int z, const int w)
constexpr T clamp(T, U, U) RET
#define make_float4
#define FLT_MAX
Definition stdcycles.h:14
__forceinline float3 center2() const
Definition boundbox.h:117