[Bf-blender-cvs] [d710953c227] cycles_embree: Cycles: Some cleanup for Embree integration.
Stefan Werner
noreply at git.blender.org
Wed Nov 7 10:53:25 CET 2018
Commit: d710953c22785f73a322e3fc9e6aba7e098c75b9
Author: Stefan Werner
Date: Wed Nov 7 10:52:50 2018 +0100
Branches: cycles_embree
https://developer.blender.org/rBd710953c22785f73a322e3fc9e6aba7e098c75b9
Cycles: Some cleanup for Embree integration.
===================================================================
M intern/cycles/bvh/bvh_embree.cpp
M intern/cycles/bvh/bvh_embree.h
===================================================================
diff --git a/intern/cycles/bvh/bvh_embree.cpp b/intern/cycles/bvh/bvh_embree.cpp
index 82859f3c881..84b8ee08dba 100644
--- a/intern/cycles/bvh/bvh_embree.cpp
+++ b/intern/cycles/bvh/bvh_embree.cpp
@@ -55,14 +55,14 @@
CCL_NAMESPACE_BEGIN
+#define IS_HAIR(x) (x & 1)
+
/* This gets called by Embree at every valid ray/object intersection.
* Things like recording subsurface or shadow hits for later evaluation
* as well as filtering for volume objects happen here.
* Cycles' own BVH does that directly inside the traversal calls.
*/
-
-void rtc_filter_func(const RTCFilterFunctionNArguments *args);
-void rtc_filter_func(const RTCFilterFunctionNArguments *args)
+static void rtc_filter_func(const RTCFilterFunctionNArguments *args)
{
/* Current implementation in Cycles assumes only single-ray intersection queries. */
assert(args->N == 1);
@@ -72,9 +72,10 @@ void rtc_filter_func(const RTCFilterFunctionNArguments *args)
CCLIntersectContext *ctx = ((IntersectContext*)args->context)->userRayExt;
KernelGlobals *kg = ctx->kg;
- if((kernel_data.curve.curveflags & CURVE_KN_INTERPOLATE)
+ /* Check if there is backfacing hair to ignore. */
+ if(IS_HAIR(hit->geomID) && (kernel_data.curve.curveflags & CURVE_KN_INTERPOLATE)
&& !(kernel_data.curve.curveflags & CURVE_KN_BACKFACING)
- && !(kernel_data.curve.curveflags & CURVE_KN_RIBBONS) && hit->geomID & 1) {
+ && !(kernel_data.curve.curveflags & CURVE_KN_RIBBONS)) {
if(dot(make_float3(ray->dir_x, ray->dir_y, ray->dir_z), make_float3(hit->Ng_x, hit->Ng_y, hit->Ng_z)) > 0.0f) {
*args->valid = 0;
return;
@@ -82,8 +83,7 @@ void rtc_filter_func(const RTCFilterFunctionNArguments *args)
}
}
-void rtc_filter_occluded_func(const RTCFilterFunctionNArguments* args);
-void rtc_filter_occluded_func(const RTCFilterFunctionNArguments* args)
+static void rtc_filter_occluded_func(const RTCFilterFunctionNArguments* args)
{
assert(args->N == 1);
@@ -92,10 +92,10 @@ void rtc_filter_occluded_func(const RTCFilterFunctionNArguments* args)
CCLIntersectContext *ctx = ((IntersectContext*)args->context)->userRayExt;
KernelGlobals *kg = ctx->kg;
- /* For all ray types: check if there is backfacing hair to ignore */
- if((kernel_data.curve.curveflags & CURVE_KN_INTERPOLATE)
+ /* For all ray types: Check if there is backfacing hair to ignore */
+ if(IS_HAIR(hit->geomID) && (kernel_data.curve.curveflags & CURVE_KN_INTERPOLATE)
&& !(kernel_data.curve.curveflags & CURVE_KN_BACKFACING)
- && !(kernel_data.curve.curveflags & CURVE_KN_RIBBONS) && hit->geomID & 1) {
+ && !(kernel_data.curve.curveflags & CURVE_KN_RIBBONS)) {
if(dot(make_float3(ray->dir_x, ray->dir_y, ray->dir_z), make_float3(hit->Ng_x, hit->Ng_y, hit->Ng_z)) > 0.0f) {
*args->valid = 0;
return;
@@ -118,7 +118,7 @@ void rtc_filter_occluded_func(const RTCFilterFunctionNArguments* args)
}
}
Intersection *isect = &ctx->isect_s[ctx->num_hits];
- ctx->num_hits++;
+ ++ctx->num_hits;
*isect = current_isect;
int prim = kernel_tex_fetch(__prim_index, isect->prim);
int shader = 0;
@@ -139,7 +139,7 @@ void rtc_filter_occluded_func(const RTCFilterFunctionNArguments* args)
else {
/* Increase the number of hits beyond ray.max_hits
* so that the caller can detect this as opaque. */
- ctx->num_hits++;
+ ++ctx->num_hits;
}
break;
}
@@ -158,7 +158,7 @@ void rtc_filter_occluded_func(const RTCFilterFunctionNArguments* args)
}
}
- ctx->ss_isect->num_hits++;
+ ++ctx->ss_isect->num_hits;
int hit_idx;
if(ctx->ss_isect->num_hits <= ctx->max_hits) {
@@ -181,7 +181,7 @@ void rtc_filter_occluded_func(const RTCFilterFunctionNArguments* args)
ctx->ss_isect->Ng[hit_idx].y = hit->Ng_y;
ctx->ss_isect->Ng[hit_idx].z = hit->Ng_z;
ctx->ss_isect->Ng[hit_idx] = normalize(ctx->ss_isect->Ng[hit_idx]);
- /* this tells Embree to continue tracing */
+ /* This tells Embree to continue tracing .*/
*args->valid = 0;
break;
}
@@ -200,14 +200,14 @@ void rtc_filter_occluded_func(const RTCFilterFunctionNArguments* args)
}
}
Intersection *isect = &ctx->isect_s[ctx->num_hits];
- ctx->num_hits++;
+ ++ctx->num_hits;
*isect = current_isect;
/* Only primitives from volume object. */
uint tri_object = (isect->object == OBJECT_NONE) ?
kernel_tex_fetch(__prim_object, isect->prim) : isect->object;
int object_flag = kernel_tex_fetch(__object_flag, tri_object);
if((object_flag & SD_OBJECT_HAS_VOLUME) == 0) {
- ctx->num_hits--;
+ --ctx->num_hits;
}
/* This tells Embree to continue tracing. */
*args->valid = 0;
@@ -215,15 +215,15 @@ void rtc_filter_occluded_func(const RTCFilterFunctionNArguments* args)
}
}
case CCLIntersectContext::RAY_REGULAR:
- /* nothing to do here. */
+ default:
+ /* Nothing to do here. */
break;
}
}
static size_t unaccounted_mem = 0;
-bool rtc_memory_monitor_func(void* userPtr, const ssize_t bytes, const bool post);
-bool rtc_memory_monitor_func(void* userPtr, const ssize_t bytes, const bool)
+static bool rtc_memory_monitor_func(void* userPtr, const ssize_t bytes, const bool)
{
Stats *stats = (Stats*)userPtr;
if(stats) {
@@ -246,24 +246,22 @@ bool rtc_memory_monitor_func(void* userPtr, const ssize_t bytes, const bool)
return true;
}
-void rtc_error_func(void*, enum RTCError code, const char* str);
-void rtc_error_func(void*, enum RTCError, const char* str)
+static void rtc_error_func(void*, enum RTCError, const char* str)
{
VLOG(0) << str;
}
static double progress_start_time = 0.0f;
-bool rtc_progress_func(void* user_ptr, const double n);
-bool rtc_progress_func(void* user_ptr, const double n)
+static bool rtc_progress_func(void* user_ptr, const double n)
{
Progress *progress = (Progress*)user_ptr;
- if(time_dt() - progress_start_time < 0.25)
+ if(time_dt() - progress_start_time < 0.25) {
return true;
+ }
string msg = string_printf("Building BVH %.0f%%", n * 100.0);
-
progress->set_substatus(msg);
progress_start_time = time_dt();
@@ -278,7 +276,7 @@ thread_mutex BVHEmbree::rtc_shared_mutex;
BVHEmbree::BVHEmbree(const BVHParams& params_, const vector<Object*>& objects_)
: BVH(params_, objects_), scene(NULL), mem_used(0), top_level(NULL), stats(NULL),
- curve_subdivisions(params.curve_subdivisions), build_quality(RTC_BUILD_QUALITY_LOW),
+ curve_subdivisions(params.curve_subdivisions), build_quality(RTC_BUILD_QUALITY_REFIT),
use_curves(params_.curve_flags & CURVE_KN_INTERPOLATE),
use_ribbons(params.curve_flags & CURVE_KN_RIBBONS), dynamic_scene(true)
{
@@ -286,41 +284,9 @@ BVHEmbree::BVHEmbree(const BVHParams& params_, const vector<Object*>& objects_)
_MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON);
thread_scoped_lock lock(rtc_shared_mutex);
if(rtc_shared_users == 0) {
- rtc_shared_device = rtcNewDevice(NULL);
-
- /* Check here if Embree was built with the correct flags. */
- ssize_t ret = rtcGetDeviceProperty (rtc_shared_device,RTC_DEVICE_PROPERTY_RAY_MASK_SUPPORTED);
- if(ret != 1) {
- assert(0);
- VLOG(1) << "Embree is compiled without the RTC_DEVICE_PROPERTY_RAY_MASK_SUPPORTED flag."\
- "Ray visiblity will not work.";
- }
- ret = rtcGetDeviceProperty (rtc_shared_device,RTC_DEVICE_PROPERTY_FILTER_FUNCTION_SUPPORTED);
- if(ret != 1) {
- assert(0);
- VLOG(1) << "Embree is compiled without the RTC_DEVICE_PROPERTY_FILTER_FUNCTION_SUPPORTED flag."\
- "Renders may not look as expected.";
- }
- ret = rtcGetDeviceProperty (rtc_shared_device,RTC_DEVICE_PROPERTY_CURVE_GEOMETRY_SUPPORTED);
- if(ret != 1) {
- assert(0);
- VLOG(1) << "Embree is compiled without the RTC_DEVICE_PROPERTY_CURVE_GEOMETRY_SUPPORTED flag. "\
- "Line primitives will not be rendered.";
- }
- ret = rtcGetDeviceProperty (rtc_shared_device,RTC_DEVICE_PROPERTY_TRIANGLE_GEOMETRY_SUPPORTED);
- if(ret != 1) {
- assert(0);
- VLOG(1) << "Embree is compiled without the RTC_DEVICE_PROPERTY_TRIANGLE_GEOMETRY_SUPPORTED flag. "\
- "Triangle primitives will not be rendered.";
- }
- ret = rtcGetDeviceProperty (rtc_shared_device,RTC_DEVICE_PROPERTY_BACKFACE_CULLING_ENABLED);
- if(ret != 0) {
- assert(0);
- VLOG(1) << "Embree is compiled with the RTC_DEVICE_PROPERTY_BACKFACE_CULLING_ENABLED flag. "\
- "Renders may not look as expected.";
- }
- }
- rtc_shared_users++;
+ rtc_shared_device = rtcNewDevice("verbose=0");
+ }
+ ++rtc_shared_users;
rtcSetDeviceErrorFunction(rtc_shared_device, rtc_error_func, NULL);
@@ -341,7 +307,7 @@ void BVHEmbree::destroy(RTCScene scene)
scene = NULL;
}
thread_scoped_lock lock(rtc_shared_mutex);
- rtc_shared_users--;
+ --rtc_shared_users;
if(rtc_shared_users == 0) {
rtcReleaseDevice (rtc_shared_device);
rtc_shared_device = NULL;
@@ -371,12 +337,13 @@ void BVHEmbree::delete_rtcScene()
void BVHEmbree::build(Progress& progress, Stats *stats_)
{
+ assert(rtc_shared_device);
stats = stats_;
rtcSetDeviceMemoryMonitorFunction(rtc_shared_device, rtc_memory_monitor_func, stats);
progress.set_substatus("Building BVH");
- if (scene) {
+ if(scene) {
rtcReleaseScene(scene);
scene = NULL;
}
@@ -517,7 +484,7 @@ void BVHEmbree::add_triangles(Object *ob, int i)
VLOG(0) << "Embree could not create new geometry buffer for mesh " << mesh->name.c_str() << ".\n";
return;
}
- for(size_t j = 0; j < num_triangles; j++) {
+ for(size_t j = 0; j < num_triangles; ++j) {
Mesh::Triangle t = mesh->get_triangle(j);
rtc_indices[j*3] = t.v[0];
rtc_indices[j*3+1] = t.v[1];
@@ -530,7 +497,7 @@ void BVHEmbree::add_triangles(Object *ob, int i)
pack.prim_type.reserve(pack.prim_type.size() + num_triangles);
pack.prim_index.reserve(pack.prim_index.size() + num_triangles);
pack.prim_tri_index.reserve(pack.prim_index.size() + num_triangles);
- for(size_t j = 0; j < num_triangles; j++) {
+ for(size_t j = 0; j < num_triangles; ++j) {
pack.prim_object.push_back_reserved(i);
pack.prim_type.push_back_reserved(num_motion_steps > 1 ? PRIMITIVE_MOTION_TRIANGLE : PRIMITIVE_TRIANGLE);
pack.prim_index.push_back_reserved(j);
@@ -565,7 +532,7 @@ void BVHEmbree::update_tri_verte
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list