From 4f3e0b7709bb64ffc24f2a003509d5f480848239 Mon Sep 17 00:00:00 2001 From: Anthony LaTorre Date: Tue, 9 Aug 2011 16:39:40 -0400 Subject: switch to indexing child nodes by start and stop indices instead of start and length; this reduces a bit of arithmetic when traversing the bounding volume hierarchy and makes the code in Geometry.build() more concise. add an untested cuda kernel to interleave the bits in three uint64 arrays. --- src/alpha.h | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'src/alpha.h') diff --git a/src/alpha.h b/src/alpha.h index 5e3e803..a9963eb 100644 --- a/src/alpha.h +++ b/src/alpha.h @@ -17,14 +17,14 @@ __device__ void swap(T &a, T &b) struct HitList { - int size; - int indices[ALPHA_DEPTH]; + unsigned int size; + unsigned int indices[ALPHA_DEPTH]; float distances[ALPHA_DEPTH]; }; __device__ void add_to_hit_list(const float &distance, const int &index, HitList &h) { - int i; + unsigned int i; if (h.size >= ALPHA_DEPTH) { if (distance > h.distances[ALPHA_DEPTH-1]) @@ -50,7 +50,7 @@ __device__ void add_to_hit_list(const float &distance, const int &index, HitList } } -__device__ __noinline__ int get_color_alpha(const float3 &origin, const float3& direction) +__device__ int get_color_alpha(const float3 &origin, const float3& direction) { HitList h; h.size = 0; @@ -60,34 +60,34 @@ __device__ __noinline__ int get_color_alpha(const float3 &origin, const float3& if (!intersect_node(origin, direction, g_start_node)) return 0; - int stack[STACK_SIZE]; + unsigned int stack[STACK_SIZE]; - int *head = &stack[0]; - int *node = &stack[1]; - int *tail = &stack[STACK_SIZE-1]; + unsigned int *head = &stack[0]; + unsigned int *node = &stack[1]; + unsigned int *tail = &stack[STACK_SIZE-1]; *node = g_start_node; - int i; + unsigned int i; do { - int first_child = tex1Dfetch(node_map, *node); - int child_count = tex1Dfetch(node_length, *node); + unsigned int first_child = tex1Dfetch(node_map, *node); + unsigned int stop = tex1Dfetch(node_map_end, *node); - while (*node >= g_first_node && child_count == 1) + while (*node >= g_first_node && stop == first_child+1) { *node = first_child; first_child = tex1Dfetch(node_map, *node); - child_count = tex1Dfetch(node_length, *node); + stop = tex1Dfetch(node_map_end, *node); } if (*node >= g_first_node) { - for (i=0; i < child_count; i++) + for (i=first_child; i < stop; i++) { - if (intersect_node(origin, direction, first_child+i)) + if (intersect_node(origin, direction, i)) { - *node = first_child+i; + *node = i; node++; } } @@ -96,9 +96,9 @@ __device__ __noinline__ int get_color_alpha(const float3 &origin, const float3& } else // node is a leaf { - for (i=0; i < child_count; i++) + for (i=first_child; i < stop; i++) { - uint4 triangle_data = g_triangles[first_child+i]; + uint4 triangle_data = g_triangles[i]; float3 v0 = g_vertices[triangle_data.x]; float3 v1 = g_vertices[triangle_data.y]; @@ -106,7 +106,7 @@ __device__ __noinline__ int get_color_alpha(const float3 &origin, const float3& if (intersect_triangle(origin, direction, v0, v1, v2, distance)) { - add_to_hit_list(distance, first_child+i, h); + add_to_hit_list(distance, i, h); } } // triangle loop -- cgit