[Bf-blender-cvs] [930186d3df] master: Cycles: Optimize sorting of transparent intersections on CUDA

Sergey Sharybin noreply at git.blender.org
Mon Feb 13 18:27:55 CET 2017


Commit: 930186d3df9cb55832d625e96a9655491360ba1e
Author: Sergey Sharybin
Date:   Mon Feb 13 18:24:45 2017 +0100
Branches: master
https://developer.blender.org/rB930186d3df9cb55832d625e96a9655491360ba1e

Cycles: Optimize sorting of transparent intersections on CUDA

===================================================================

M	intern/cycles/kernel/bvh/bvh.h

===================================================================

diff --git a/intern/cycles/kernel/bvh/bvh.h b/intern/cycles/kernel/bvh/bvh.h
index dfd7010601..321983c1ab 100644
--- a/intern/cycles/kernel/bvh/bvh.h
+++ b/intern/cycles/kernel/bvh/bvh.h
@@ -378,16 +378,19 @@ 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) {
+	bool swapped;
+	do {
+		swapped = false;
+		for(int j = 0; j < num_hits - 1; ++j) {
 			if(hits[j].t > hits[j + 1].t) {
 				struct Intersection tmp = hits[j];
 				hits[j] = hits[j + 1];
 				hits[j + 1] = tmp;
+				swapped = true;
 			}
 		}
-	}
+		--num_hits;
+	} while(swapped);
 #else
 	qsort(hits, num_hits, sizeof(Intersection), intersections_compare);
 #endif




More information about the Bf-blender-cvs mailing list