2011-04-27 11:58:34 +00:00
|
|
|
/*
|
|
|
|
* Adapted from code copyright 2009-2010 NVIDIA Corporation
|
|
|
|
* Modifications Copyright 2011, Blender Foundation.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2017-04-13 08:55:46 +00:00
|
|
|
#include "bvh/bvh.h"
|
|
|
|
|
|
|
|
#include "bvh/bvh2.h"
|
2020-06-05 09:39:11 +00:00
|
|
|
#include "bvh/bvh_embree.h"
|
2020-12-10 13:18:25 +00:00
|
|
|
#include "bvh/bvh_multi.h"
|
2020-06-05 09:39:11 +00:00
|
|
|
#include "bvh/bvh_optix.h"
|
2018-11-07 11:58:12 +00:00
|
|
|
|
2018-01-19 09:59:58 +00:00
|
|
|
#include "util/util_logging.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 18:39:14 +00:00
|
|
|
#include "util/util_progress.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2018-01-19 09:59:58 +00:00
|
|
|
/* BVH Parameters. */
|
|
|
|
|
|
|
|
const char *bvh_layout_name(BVHLayout layout)
|
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
switch (layout) {
|
|
|
|
case BVH_LAYOUT_NONE:
|
|
|
|
return "NONE";
|
2020-12-10 13:18:25 +00:00
|
|
|
case BVH_LAYOUT_BVH2:
|
|
|
|
return "BVH2";
|
2019-04-17 04:17:24 +00:00
|
|
|
case BVH_LAYOUT_EMBREE:
|
|
|
|
return "EMBREE";
|
2019-09-12 12:50:06 +00:00
|
|
|
case BVH_LAYOUT_OPTIX:
|
|
|
|
return "OPTIX";
|
2020-12-10 13:18:25 +00:00
|
|
|
case BVH_LAYOUT_MULTI_OPTIX:
|
|
|
|
case BVH_LAYOUT_MULTI_OPTIX_EMBREE:
|
|
|
|
return "MULTI";
|
2019-04-17 04:17:24 +00:00
|
|
|
case BVH_LAYOUT_ALL:
|
|
|
|
return "ALL";
|
|
|
|
}
|
|
|
|
LOG(DFATAL) << "Unsupported BVH layout was passed.";
|
|
|
|
return "";
|
2018-01-19 09:59:58 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 04:17:24 +00:00
|
|
|
BVHLayout BVHParams::best_bvh_layout(BVHLayout requested_layout, BVHLayoutMask supported_layouts)
|
2018-01-19 09:59:58 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
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.
|
|
|
|
*/
|
2019-08-26 15:29:06 +00:00
|
|
|
BVHLayoutMask allowed_layouts_mask = (supported_layouts & (requested_layout_mask - 1));
|
|
|
|
/* If the requested layout is not supported, choose from the supported layouts instead. */
|
|
|
|
if (allowed_layouts_mask == 0) {
|
|
|
|
allowed_layouts_mask = supported_layouts;
|
|
|
|
}
|
2019-04-17 04:17:24 +00:00
|
|
|
/* We get widest from allowed ones and convert mask to actual layout. */
|
2021-02-14 14:34:23 +00:00
|
|
|
const BVHLayoutMask widest_allowed_layout_mask = __bsr((uint32_t)allowed_layouts_mask);
|
2019-04-17 04:17:24 +00:00
|
|
|
return (BVHLayout)(1 << widest_allowed_layout_mask);
|
2018-01-19 09:59:58 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* BVH */
|
|
|
|
|
2020-02-02 11:04:19 +00:00
|
|
|
BVH::BVH(const BVHParams ¶ms_,
|
|
|
|
const vector<Geometry *> &geometry_,
|
|
|
|
const vector<Object *> &objects_)
|
|
|
|
: params(params_), geometry(geometry_), objects(objects_)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-08-26 15:29:06 +00:00
|
|
|
BVH *BVH::create(const BVHParams ¶ms,
|
2020-02-02 11:04:19 +00:00
|
|
|
const vector<Geometry *> &geometry,
|
2020-09-01 12:47:34 +00:00
|
|
|
const vector<Object *> &objects,
|
2020-12-10 13:18:25 +00:00
|
|
|
Device *device)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-04-17 04:17:24 +00:00
|
|
|
switch (params.bvh_layout) {
|
|
|
|
case BVH_LAYOUT_BVH2:
|
2020-02-02 11:04:19 +00:00
|
|
|
return new BVH2(params, geometry, objects);
|
2019-04-17 04:17:24 +00:00
|
|
|
case BVH_LAYOUT_EMBREE:
|
2018-11-07 11:58:12 +00:00
|
|
|
#ifdef WITH_EMBREE
|
2020-12-10 13:18:25 +00:00
|
|
|
return new BVHEmbree(params, geometry, objects);
|
2019-08-26 15:29:06 +00:00
|
|
|
#else
|
|
|
|
break;
|
2019-09-12 12:50:06 +00:00
|
|
|
#endif
|
|
|
|
case BVH_LAYOUT_OPTIX:
|
|
|
|
#ifdef WITH_OPTIX
|
2020-12-10 13:18:25 +00:00
|
|
|
return new BVHOptiX(params, geometry, objects, device);
|
2019-09-12 12:50:06 +00:00
|
|
|
#else
|
2020-12-10 13:18:25 +00:00
|
|
|
(void)device;
|
2019-09-12 12:50:06 +00:00
|
|
|
break;
|
2018-11-07 11:58:12 +00:00
|
|
|
#endif
|
2020-12-10 13:18:25 +00:00
|
|
|
case BVH_LAYOUT_MULTI_OPTIX:
|
|
|
|
case BVH_LAYOUT_MULTI_OPTIX_EMBREE:
|
|
|
|
return new BVHMulti(params, geometry, objects);
|
2019-04-17 04:17:24 +00:00
|
|
|
case BVH_LAYOUT_NONE:
|
|
|
|
case BVH_LAYOUT_ALL:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
LOG(DFATAL) << "Requested unsupported BVH layout.";
|
|
|
|
return NULL;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2014-12-17 17:46:02 +00:00
|
|
|
CCL_NAMESPACE_END
|