From 9830eeb44b84cdb12e477cbb067f3b7e56634024 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 21 Sep 2016 17:34:15 +0200 Subject: Cycles: Implement record-all transparent shadow function for GPU The idea is to record all possible transparent intersections when shooting transparent ray on GPU (similar to what we were doing on CPU already). This avoids need of doing whole ray-to-scene intersections queries for each intersection and speeds up a lot cases like transparent hair in the cost of extra memory. This commit is a base ground for now and this feature is kept disabled for until some further tweaks. --- intern/cycles/kernel/bvh/bvh.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'intern/cycles/kernel/bvh') diff --git a/intern/cycles/kernel/bvh/bvh.h b/intern/cycles/kernel/bvh/bvh.h index 36798982653..2667f236064 100644 --- a/intern/cycles/kernel/bvh/bvh.h +++ b/intern/cycles/kernel/bvh/bvh.h @@ -357,7 +357,7 @@ ccl_device_inline float3 ray_offset(float3 P, float3 Ng) #endif } -#if defined(__SHADOW_RECORD_ALL__) || defined (__VOLUME_RECORD_ALL__) +#if defined(__SHADOW_RECORD_ALL__) || defined(__VOLUME_RECORD_ALL__) /* ToDo: Move to another file? */ ccl_device int intersections_compare(const void *a, const void *b) { @@ -371,7 +371,25 @@ ccl_device int intersections_compare(const void *a, const void *b) else return 0; } + +ccl_device_inline void sort_intersections(Intersection *hits, uint num_hits) +{ +#ifdef __KERNEL_GPU__ + /* Use bubble sort which has more friendly memory pattern on GPU. */ + int i, j; + for(i = 0; i < num_hits; ++i) { + for(j = 0; j < num_hits - 1; ++j) { + if(hits[j].t < hits[j + 1].t) { + Intersection tmp = hits[j]; + hits[j] = hits[j + 1]; + hits[j + 1] = tmp; + } + } + } +#else + qsort(hits, num_hits, sizeof(Intersection), intersections_compare); #endif +} +#endif /* __SHADOW_RECORD_ALL__ | __VOLUME_RECORD_ALL__ */ CCL_NAMESPACE_END - -- cgit v1.2.3