diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-01-19 12:59:58 +0300 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2018-01-22 19:19:20 +0300 |
commit | 2f79d1c0584f4d72984e56db1f5878be3360e044 (patch) | |
tree | f2385b9834d7a9e0c15be92ca5356f4bc91aa247 /intern/cycles/bvh | |
parent | 0f69026b1c3c07b203aeba658048f1129e41b116 (diff) |
Cycles: Replace use_qbvh boolean flag with an enum-based property
This was we can introduce other types of BVH, for example, wider ones, without
causing too much mess around boolean flags.
Thoughs:
- Ideally device info should probably return bitflag of what BVH types it
supports.
It is possible to implement based on simple logic in device/ and mesh.cpp,
rest of the changes will stay the same.
- Not happy with workarounds in util_debug and duplicated enum in kernel.
Maybe enbum should be stores in kernel, but then it's kind of weird to include
kernel types from utils. Soudns some cyclkic dependency.
Reviewers: brecht, maxim_d33
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D3011
Diffstat (limited to 'intern/cycles/bvh')
-rw-r--r-- | intern/cycles/bvh/bvh.cpp | 54 | ||||
-rw-r--r-- | intern/cycles/bvh/bvh4.cpp | 2 | ||||
-rw-r--r-- | intern/cycles/bvh/bvh_params.h | 32 |
3 files changed, 79 insertions, 9 deletions
diff --git a/intern/cycles/bvh/bvh.cpp b/intern/cycles/bvh/bvh.cpp index 6531ca50d9a..5bfe9d4ed1a 100644 --- a/intern/cycles/bvh/bvh.cpp +++ b/intern/cycles/bvh/bvh.cpp @@ -26,10 +26,46 @@ #include "bvh/bvh_node.h" #include "util/util_foreach.h" +#include "util/util_logging.h" #include "util/util_progress.h" CCL_NAMESPACE_BEGIN +/* BVH Parameters. */ + +const char *bvh_layout_name(BVHLayout layout) +{ + switch(layout) { + case BVH_LAYOUT_BVH2: return "BVH2"; + case BVH_LAYOUT_BVH4: return "BVH4"; + case BVH_LAYOUT_NONE: return "NONE"; + case BVH_LAYOUT_ALL: return "ALL"; + } + LOG(DFATAL) << "Unsupported BVH layout was passed."; + return ""; +} + +BVHLayout BVHParams::best_bvh_layout(BVHLayout requested_layout, + BVHLayoutMask supported_layouts) +{ + const BVHLayoutMask requested_layout_mask = (BVHLayoutMask)requested_layout; + /* Check whether requested layout is supported, if so -- no need to do + * any extra computation. + */ + if(supported_layouts & requested_layout_mask) { + return requested_layout; + } + /* Some bit magic to get widest supported BVH layout. */ + /* This is a mask of supported BVH layouts which are narrower than the + * requested one. + */ + const BVHLayoutMask allowed_layouts_mask = + (supported_layouts & (requested_layout_mask - 1)); + /* We get widest from allowed ones and convert mask to actual layout. */ + const BVHLayoutMask widest_allowed_layout_mask = __bsr(allowed_layouts_mask); + return (BVHLayout)widest_allowed_layout_mask; +} + /* Pack Utility */ BVHStackEntry::BVHStackEntry(const BVHNode *n, int i) @@ -51,10 +87,17 @@ BVH::BVH(const BVHParams& params_, const vector<Object*>& objects_) BVH *BVH::create(const BVHParams& params, const vector<Object*>& objects) { - if(params.use_qbvh) - return new BVH4(params, objects); - else - return new BVH2(params, objects); + switch(params.bvh_layout) { + case BVH_LAYOUT_BVH2: + return new BVH2(params, objects); + case BVH_LAYOUT_BVH4: + return new BVH4(params, objects); + case BVH_LAYOUT_NONE: + case BVH_LAYOUT_ALL: + break; + } + LOG(DFATAL) << "Requested unsupported BVH layout."; + return NULL; } /* Building */ @@ -248,7 +291,8 @@ void BVH::pack_instances(size_t nodes_size, size_t leaf_nodes_size) * BVH's are stored in global arrays. This function merges them into the * top level BVH, adjusting indexes and offsets where appropriate. */ - const bool use_qbvh = params.use_qbvh; + /* TODO(sergey): This code needs adjustment for wider BVH than 4. */ + const bool use_qbvh = (params.bvh_layout == BVH_LAYOUT_BVH4); /* Adjust primitive index to point to the triangle in the global array, for * meshes with transform applied and already in the top level BVH. diff --git a/intern/cycles/bvh/bvh4.cpp b/intern/cycles/bvh/bvh4.cpp index b910feccec8..4faf47af7bb 100644 --- a/intern/cycles/bvh/bvh4.cpp +++ b/intern/cycles/bvh/bvh4.cpp @@ -55,7 +55,7 @@ static bool node_qbvh_is_unaligned(const BVHNode *node) BVH4::BVH4(const BVHParams& params_, const vector<Object*>& objects_) : BVH(params_, objects_) { - params.use_qbvh = true; + params.bvh_layout = BVH_LAYOUT_BVH4; } void BVH4::pack_leaf(const BVHStackEntry& e, const LeafNode *leaf) diff --git a/intern/cycles/bvh/bvh_params.h b/intern/cycles/bvh/bvh_params.h index 7dd699b33a4..89a379cf356 100644 --- a/intern/cycles/bvh/bvh_params.h +++ b/intern/cycles/bvh/bvh_params.h @@ -24,11 +24,29 @@ CCL_NAMESPACE_BEGIN +/* Layout of BVH tree. + * + * For example, how wide BVH tree is, in terms of number of children + * per node. + */ +typedef KernelBVHLayout BVHLayout; + +/* Names bitflag type to denote which BVH layouts are supported by + * particular area. + * + * Bitflags are the BVH_LAYOUT_* values. + */ +typedef int BVHLayoutMask; + +/* Get human readable name of BVH layout. */ +const char *bvh_layout_name(BVHLayout layout); + /* BVH Parameters */ class BVHParams { public: + /* spatial split area threshold */ bool use_spatial_split; float spatial_split_alpha; @@ -50,8 +68,8 @@ public: /* object or mesh level bvh */ bool top_level; - /* QBVH */ - bool use_qbvh; + /* BVH layout to be built. */ + BVHLayout bvh_layout; /* Mask of primitives to be included into the BVH. */ int primitive_mask; @@ -98,7 +116,7 @@ public: max_motion_curve_leaf_size = 4; top_level = false; - use_qbvh = false; + bvh_layout = BVH_LAYOUT_BVH2; use_unaligned_nodes = false; primitive_mask = PRIMITIVE_ALL; @@ -119,6 +137,14 @@ public: __forceinline bool small_enough_for_leaf(int size, int level) { return (size <= min_leaf_size || level >= MAX_DEPTH); } + + /* Gets best matching BVH. + * + * If the requested layout is supported by the device, it will be used. + * Otherwise, widest supported layout below that will be used. + */ + static BVHLayout best_bvh_layout(BVHLayout requested_layout, + BVHLayoutMask supported_layouts); }; /* BVH Reference |