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/bvh.cpp | |
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/bvh.cpp')
-rw-r--r-- | intern/cycles/bvh/bvh.cpp | 54 |
1 files changed, 49 insertions, 5 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. |