Cycles: Switch node address to absolute values in BVH tree
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 14 Jun 2016 12:29:09 +0000 (14:29 +0200)
committerSergey Sharybin <sergey.vfx@gmail.com>
Thu, 7 Jul 2016 15:25:48 +0000 (17:25 +0200)
This seems to be straightforward way to support heterogeneous nodes
in the same tree.

There is some penalty related on 4gig limit of the address space now,
but here's are the thing:

Traversal code was already using ints to store final offset, so
there can't be regressions really.

This is a required commit to make it possible to encode both aligned
and unaligned nodes in the same array. Also, in the future we can use
this to get rid of __leaf_nodes array (which is a bit tricky to do since
trickery in pack_instances().

13 files changed:
intern/cycles/bvh/bvh.cpp
intern/cycles/kernel/geom/geom.h
intern/cycles/kernel/geom/geom_bvh_shadow.h
intern/cycles/kernel/geom/geom_bvh_subsurface.h
intern/cycles/kernel/geom/geom_bvh_traversal.h
intern/cycles/kernel/geom/geom_bvh_volume.h
intern/cycles/kernel/geom/geom_bvh_volume_all.h
intern/cycles/kernel/geom/geom_qbvh.h
intern/cycles/kernel/geom/geom_qbvh_shadow.h
intern/cycles/kernel/geom/geom_qbvh_subsurface.h
intern/cycles/kernel/geom/geom_qbvh_traversal.h
intern/cycles/kernel/geom/geom_qbvh_volume.h
intern/cycles/kernel/geom/geom_qbvh_volume_all.h

index 5669bab857c17519f02dbfed311ac2262b804cb5..ab4dbe814ab64382c04237e12e5ddbaba97e1f5b 100644 (file)
@@ -288,8 +288,8 @@ void BVH::pack_instances(size_t nodes_size, size_t leaf_nodes_size)
 
                BVH *bvh = mesh->bvh;
 
-               int noffset = nodes_offset/nsize;
-               int noffset_leaf = nodes_leaf_offset/nsize_leaf;
+               int noffset = nodes_offset;
+               int noffset_leaf = nodes_leaf_offset;
                int mesh_tri_offset = mesh->tri_offset;
                int mesh_curve_offset = mesh->curve_offset;
 
@@ -421,7 +421,7 @@ void RegularBVH::pack_leaf(const BVHStackEntry& e, const LeafNode *leaf)
                data[0].w = __uint_as_float(pack.prim_type[leaf->m_lo]);
        }
 
-       memcpy(&pack.leaf_nodes[e.idx * BVH_NODE_LEAF_SIZE], data, sizeof(float4)*BVH_NODE_LEAF_SIZE);
+       memcpy(&pack.leaf_nodes[e.idx], data, sizeof(float4)*BVH_NODE_LEAF_SIZE);
 }
 
 void RegularBVH::pack_inner(const BVHStackEntry& e, const BVHStackEntry& e0, const BVHStackEntry& e1)
@@ -439,7 +439,7 @@ void RegularBVH::pack_node(int idx, const BoundBox& b0, const BoundBox& b1, int
                make_int4(c0, c1, visibility0, visibility1)
        };
 
-       memcpy(&pack.nodes[idx * BVH_NODE_SIZE], data, sizeof(int4)*BVH_NODE_SIZE);
+       memcpy(&pack.nodes[idx], data, sizeof(int4)*BVH_NODE_SIZE);
 }
 
 void RegularBVH::pack_nodes(const BVHNode *root)
@@ -465,10 +465,13 @@ void RegularBVH::pack_nodes(const BVHNode *root)
 
        vector<BVHStackEntry> stack;
        stack.reserve(BVHParams::MAX_DEPTH*2);
-       if(root->is_leaf())
+       if(root->is_leaf()) {
                stack.push_back(BVHStackEntry(root, nextLeafNodeIdx++));
-       else
-               stack.push_back(BVHStackEntry(root, nextNodeIdx++));
+       }
+       else {
+               stack.push_back(BVHStackEntry(root, nextNodeIdx));
+               nextNodeIdx += BVH_NODE_SIZE;
+       }
 
        while(stack.size()) {
                BVHStackEntry e = stack.back();
@@ -481,10 +484,19 @@ void RegularBVH::pack_nodes(const BVHNode *root)
                }
                else {
                        /* innner node */
-                       int idx0 = (e.node->get_child(0)->is_leaf())? (nextLeafNodeIdx++) : (nextNodeIdx++);
-                       int idx1 = (e.node->get_child(1)->is_leaf())? (nextLeafNodeIdx++) : (nextNodeIdx++);
-                       stack.push_back(BVHStackEntry(e.node->get_child(0), idx0));
-                       stack.push_back(BVHStackEntry(e.node->get_child(1), idx1));
+                       int idx[2];
+                       for (int i = 0; i < 2; ++i) {
+                               if (e.node->get_child(i)->is_leaf()) {
+                                       idx[i] = nextLeafNodeIdx++;
+                               }
+                               else {
+                                       idx[i] = nextNodeIdx;
+                                       nextNodeIdx += BVH_NODE_SIZE;
+                               }
+                       }
+
+                       stack.push_back(BVHStackEntry(e.node->get_child(0), idx[0]));
+                       stack.push_back(BVHStackEntry(e.node->get_child(1), idx[1]));
 
                        pack_inner(e, stack[stack.size()-2], stack[stack.size()-1]);
                }
@@ -506,7 +518,7 @@ void RegularBVH::refit_nodes()
 void RegularBVH::refit_node(int idx, bool leaf, BoundBox& bbox, uint& visibility)
 {
        if(leaf) {
-               int4 *data = &pack.leaf_nodes[idx*BVH_NODE_LEAF_SIZE];
+               int4 *data = &pack.leaf_nodes[idx];
                int c0 = data[0].x;
                int c1 = data[0].y;
                /* refit leaf node */
@@ -580,12 +592,12 @@ void RegularBVH::refit_node(int idx, bool leaf, BoundBox& bbox, uint& visibility
                leaf_data[0].y = __int_as_float(c1);
                leaf_data[0].z = __uint_as_float(visibility);
                leaf_data[0].w = __uint_as_float(data[0].w);
-               memcpy(&pack.leaf_nodes[idx * BVH_NODE_LEAF_SIZE],
+               memcpy(&pack.leaf_nodes[idx],
                       leaf_data,
                       sizeof(float4)*BVH_NODE_LEAF_SIZE);
        }
        else {
-               int4 *data = &pack.nodes[idx*BVH_NODE_SIZE];
+               int4 *data = &pack.nodes[idx];
                int c0 = data[3].x;
                int c1 = data[3].y;
                /* refit inner node, set bbox from children */
@@ -630,7 +642,7 @@ void QBVH::pack_leaf(const BVHStackEntry& e, const LeafNode *leaf)
                data[0].w = __uint_as_float(pack.prim_type[leaf->m_lo]);
        }
 
-       memcpy(&pack.leaf_nodes[e.idx * BVH_QNODE_LEAF_SIZE], data, sizeof(float4)*BVH_QNODE_LEAF_SIZE);
+       memcpy(&pack.leaf_nodes[e.idx], data, sizeof(float4)*BVH_QNODE_LEAF_SIZE);
 }
 
 void QBVH::pack_inner(const BVHStackEntry& e, const BVHStackEntry *en, int num)
@@ -668,7 +680,7 @@ void QBVH::pack_inner(const BVHStackEntry& e, const BVHStackEntry *en, int num)
                data[7][i] = __int_as_float(0);
        }
 
-       memcpy(&pack.nodes[e.idx * BVH_QNODE_SIZE], data, sizeof(float4)*BVH_QNODE_SIZE);
+       memcpy(&pack.nodes[e.idx], data, sizeof(float4)*BVH_QNODE_SIZE);
 }
 
 /* Quad SIMD Nodes */
@@ -701,7 +713,8 @@ void QBVH::pack_nodes(const BVHNode *root)
                stack.push_back(BVHStackEntry(root, nextLeafNodeIdx++));
        }
        else {
-               stack.push_back(BVHStackEntry(root, nextNodeIdx++));
+               stack.push_back(BVHStackEntry(root, nextNodeIdx));
+               nextNodeIdx += BVH_QNODE_SIZE;
        }
 
        while(stack.size()) {
@@ -746,7 +759,8 @@ void QBVH::pack_nodes(const BVHNode *root)
                                        idx = nextLeafNodeIdx++;
                                }
                                else {
-                                       idx = nextNodeIdx++;
+                                       idx = nextNodeIdx;
+                                       nextNodeIdx += BVH_QNODE_SIZE;
                                }
                                stack.push_back(BVHStackEntry(nodes[i], idx));
                        }
@@ -772,7 +786,7 @@ void QBVH::refit_nodes()
 void QBVH::refit_node(int idx, bool leaf, BoundBox& bbox, uint& visibility)
 {
        if(leaf) {
-               int4 *data = &pack.leaf_nodes[idx*BVH_QNODE_LEAF_SIZE];
+               int4 *data = &pack.leaf_nodes[idx];
                int4 c = data[0];
                /* Refit leaf node. */
                for(int prim = c.x; prim < c.y; prim++) {
@@ -854,12 +868,12 @@ void QBVH::refit_node(int idx, bool leaf, BoundBox& bbox, uint& visibility)
                leaf_data[0].y = __int_as_float(c.y);
                leaf_data[0].z = __uint_as_float(visibility);
                leaf_data[0].w = __uint_as_float(c.w);
-               memcpy(&pack.leaf_nodes[idx * BVH_QNODE_LEAF_SIZE],
+               memcpy(&pack.leaf_nodes[idx],
                       leaf_data,
                       sizeof(float4)*BVH_QNODE_LEAF_SIZE);
        }
        else {
-               int4 *data = &pack.nodes[idx*BVH_QNODE_SIZE];
+               int4 *data = &pack.nodes[idx];
                int4 c = data[7];
                /* Refit inner node, set bbox from children. */
                BoundBox child_bbox[4] = {BoundBox::empty,
@@ -895,7 +909,7 @@ void QBVH::refit_node(int idx, bool leaf, BoundBox& bbox, uint& visibility)
                        inner_data[6][i] = bb_max.z;
                        inner_data[7][i] = __int_as_float(c[i]);
                }
-               memcpy(&pack.nodes[idx * BVH_QNODE_SIZE],
+               memcpy(&pack.nodes[idx],
                       inner_data,
                       sizeof(float4)*BVH_QNODE_SIZE);
        }
index 26e0af99bbce3b800149df0f6595e0f9a99c847e..33e91d1ee44d787972fc207d3eb31b8a990ad6f4 100644 (file)
 /* 64 object BVH + 64 mesh BVH + 64 object node splitting */
 #define BVH_STACK_SIZE 192
 #define BVH_QSTACK_SIZE 384
-#define BVH_NODE_SIZE 4
-#define BVH_NODE_LEAF_SIZE 1
-#define BVH_QNODE_SIZE 8
-#define BVH_QNODE_LEAF_SIZE 1
 #define TRI_NODE_SIZE 3
 
 #include "geom_attribute.h"
index 4991eb5045af2946bfeb6dd7e896afa2681498e0..60cc50e8bfd8a2da97fca3dde8666957ed87d829 100644 (file)
@@ -102,10 +102,10 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
                                float t = isect_t;
 
                                /* fetch node data */
-                               float4 node0 = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_NODE_SIZE+0);
-                               float4 node1 = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_NODE_SIZE+1);
-                               float4 node2 = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_NODE_SIZE+2);
-                               float4 cnodes = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_NODE_SIZE+3);
+                               float4 node0 = kernel_tex_fetch(__bvh_nodes, nodeAddr+0);
+                               float4 node1 = kernel_tex_fetch(__bvh_nodes, nodeAddr+1);
+                               float4 node2 = kernel_tex_fetch(__bvh_nodes, nodeAddr+2);
+                               float4 cnodes = kernel_tex_fetch(__bvh_nodes, nodeAddr+3);
 
                                /* intersect ray against child nodes */
                                float c0lox = (node0.x - P.x) * idir.x;
@@ -140,7 +140,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
                                /* Intersect two child bounding boxes, SSE3 version adapted from Embree */
 
                                /* fetch node data */
-                               const ssef *bvh_nodes = (ssef*)kg->__bvh_nodes.data + nodeAddr*BVH_NODE_SIZE;
+                               const ssef *bvh_nodes = (ssef*)kg->__bvh_nodes.data + nodeAddr;
                                const float4 cnodes = ((float4*)bvh_nodes)[3];
 
                                /* intersect ray against child nodes */
@@ -200,7 +200,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
 
                        /* if node is leaf, fetch triangle list */
                        if(nodeAddr < 0) {
-                               float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-nodeAddr-1)*BVH_NODE_LEAF_SIZE);
+                               float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-nodeAddr-1));
                                int primAddr = __float_as_int(leaf.x);
 
 #if BVH_FEATURE(BVH_INSTANCING)
index a5243f079f2b57ea335439afbaa67d2eef52a937..e43eedad7bc22ee0cfaa4772d7b373167bf91531 100644 (file)
@@ -113,10 +113,10 @@ ccl_device void BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
                                float t = isect_t;
 
                                /* fetch node data */
-                               float4 node0 = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_NODE_SIZE+0);
-                               float4 node1 = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_NODE_SIZE+1);
-                               float4 node2 = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_NODE_SIZE+2);
-                               float4 cnodes = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_NODE_SIZE+3);
+                               float4 node0 = kernel_tex_fetch(__bvh_nodes, nodeAddr+0);
+                               float4 node1 = kernel_tex_fetch(__bvh_nodes, nodeAddr+1);
+                               float4 node2 = kernel_tex_fetch(__bvh_nodes, nodeAddr+2);
+                               float4 cnodes = kernel_tex_fetch(__bvh_nodes, nodeAddr+3);
 
                                /* intersect ray against child nodes */
                                float c0lox = (node0.x - P.x) * idir.x;
@@ -145,7 +145,7 @@ ccl_device void BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
                                /* Intersect two child bounding boxes, SSE3 version adapted from Embree */
 
                                /* fetch node data */
-                               const ssef *bvh_nodes = (ssef*)kg->__bvh_nodes.data + nodeAddr*BVH_NODE_SIZE;
+                               const ssef *bvh_nodes = (ssef*)kg->__bvh_nodes.data + nodeAddr;
                                const float4 cnodes = ((float4*)bvh_nodes)[3];
 
                                /* intersect ray against child nodes */
@@ -199,7 +199,7 @@ ccl_device void BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
 
                        /* if node is leaf, fetch triangle list */
                        if(nodeAddr < 0) {
-                               float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-nodeAddr-1)*BVH_NODE_LEAF_SIZE);
+                               float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-nodeAddr-1));
                                int primAddr = __float_as_int(leaf.x);
 
                                const int primAddr2 = __float_as_int(leaf.y);
index 89e6ba6162d406db02db1026f93ce782219c65a1..5b9c7b46f82ee204fb3b1225ed04db28e854979c 100644 (file)
@@ -109,10 +109,10 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
                                float t = isect->t;
 
                                /* fetch node data */
-                               float4 node0 = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_NODE_SIZE+0);
-                               float4 node1 = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_NODE_SIZE+1);
-                               float4 node2 = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_NODE_SIZE+2);
-                               float4 cnodes = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_NODE_SIZE+3);
+                               float4 node0 = kernel_tex_fetch(__bvh_nodes, nodeAddr+0);
+                               float4 node1 = kernel_tex_fetch(__bvh_nodes, nodeAddr+1);
+                               float4 node2 = kernel_tex_fetch(__bvh_nodes, nodeAddr+2);
+                               float4 cnodes = kernel_tex_fetch(__bvh_nodes, nodeAddr+3);
 
                                /* intersect ray against child nodes */
                                float c0lox = (node0.x - P.x) * idir.x;
@@ -162,7 +162,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
                                /* Intersect two child bounding boxes, SSE3 version adapted from Embree */
 
                                /* fetch node data */
-                               const ssef *bvh_nodes = (ssef*)kg->__bvh_nodes.data + nodeAddr*BVH_NODE_SIZE;
+                               const ssef *bvh_nodes = (ssef*)kg->__bvh_nodes.data + nodeAddr;
                                const float4 cnodes = ((float4*)bvh_nodes)[3];
 
                                /* intersect ray against child nodes */
@@ -243,7 +243,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
 
                        /* if node is leaf, fetch triangle list */
                        if(nodeAddr < 0) {
-                               float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-nodeAddr-1)*BVH_NODE_LEAF_SIZE);
+                               float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-nodeAddr-1));
                                int primAddr = __float_as_int(leaf.x);
 
 #if BVH_FEATURE(BVH_INSTANCING)
index 195c4043cd7124ce953ce87f283e2c80aeaaebad..36033ecf459a62fda3cccac419bb8a9b8adcdb7b 100644 (file)
@@ -99,10 +99,10 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
                                float t = isect->t;
 
                                /* fetch node data */
-                               float4 node0 = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_NODE_SIZE+0);
-                               float4 node1 = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_NODE_SIZE+1);
-                               float4 node2 = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_NODE_SIZE+2);
-                               float4 cnodes = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_NODE_SIZE+3);
+                               float4 node0 = kernel_tex_fetch(__bvh_nodes, nodeAddr+0);
+                               float4 node1 = kernel_tex_fetch(__bvh_nodes, nodeAddr+1);
+                               float4 node2 = kernel_tex_fetch(__bvh_nodes, nodeAddr+2);
+                               float4 cnodes = kernel_tex_fetch(__bvh_nodes, nodeAddr+3);
 
                                /* intersect ray against child nodes */
                                float c0lox = (node0.x - P.x) * idir.x;
@@ -131,7 +131,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
                                /* Intersect two child bounding boxes, SSE3 version adapted from Embree */
 
                                /* fetch node data */
-                               const ssef *bvh_nodes = (ssef*)kg->__bvh_nodes.data + nodeAddr*BVH_NODE_SIZE;
+                               const ssef *bvh_nodes = (ssef*)kg->__bvh_nodes.data + nodeAddr;
                                const float4 cnodes = ((float4*)bvh_nodes)[3];
 
                                /* intersect ray against child nodes */
@@ -186,7 +186,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
 
                        /* if node is leaf, fetch triangle list */
                        if(nodeAddr < 0) {
-                               float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-nodeAddr-1)*BVH_NODE_LEAF_SIZE);
+                               float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-nodeAddr-1));
                                int primAddr = __float_as_int(leaf.x);
 
 #if BVH_FEATURE(BVH_INSTANCING)
index c76d6155065fa123b49229ff9ba8c0339df5096a..f95361489331d5e4050a91d6c203ee1a2ffb8914 100644 (file)
@@ -103,10 +103,10 @@ ccl_device uint BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
                                float t = isect_array->t;
 
                                /* fetch node data */
-                               float4 node0 = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_NODE_SIZE+0);
-                               float4 node1 = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_NODE_SIZE+1);
-                               float4 node2 = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_NODE_SIZE+2);
-                               float4 cnodes = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_NODE_SIZE+3);
+                               float4 node0 = kernel_tex_fetch(__bvh_nodes, nodeAddr+0);
+                               float4 node1 = kernel_tex_fetch(__bvh_nodes, nodeAddr+1);
+                               float4 node2 = kernel_tex_fetch(__bvh_nodes, nodeAddr+2);
+                               float4 cnodes = kernel_tex_fetch(__bvh_nodes, nodeAddr+3);
 
                                /* intersect ray against child nodes */
                                float c0lox = (node0.x - P.x) * idir.x;
@@ -135,7 +135,7 @@ ccl_device uint BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
                                /* Intersect two child bounding boxes, SSE3 version adapted from Embree */
 
                                /* fetch node data */
-                               const ssef *bvh_nodes = (ssef*)kg->__bvh_nodes.data + nodeAddr*BVH_NODE_SIZE;
+                               const ssef *bvh_nodes = (ssef*)kg->__bvh_nodes.data + nodeAddr;
                                const float4 cnodes = ((float4*)bvh_nodes)[3];
 
                                /* intersect ray against child nodes */
@@ -190,7 +190,7 @@ ccl_device uint BVH_FUNCTION_FULL_NAME(BVH)(KernelGlobals *kg,
 
                        /* if node is leaf, fetch triangle list */
                        if(nodeAddr < 0) {
-                               float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-nodeAddr-1)*BVH_NODE_LEAF_SIZE);
+                               float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-nodeAddr-1));
                                int primAddr = __float_as_int(leaf.x);
 
 #if BVH_FEATURE(BVH_INSTANCING)
index 118bceb4bec4594a80c85527a145f096cd3f6cbb..30ed851d8619ec3317442aa6f8e1c195a97c2acb 100644 (file)
@@ -69,7 +69,7 @@ ccl_device_inline int qbvh_node_intersect(KernelGlobals *__restrict kg,
                                           const int nodeAddr,
                                           ssef *__restrict dist)
 {
-       const int offset = nodeAddr*BVH_QNODE_SIZE + 1;
+       const int offset = nodeAddr + 1;
 #ifdef __KERNEL_AVX2__
        const ssef tnear_x = msub(kernel_tex_fetch_ssef(__bvh_nodes, offset+near_x), idir.x, org_idir.x);
        const ssef tnear_y = msub(kernel_tex_fetch_ssef(__bvh_nodes, offset+near_y), idir.y, org_idir.y);
@@ -120,7 +120,7 @@ ccl_device_inline int qbvh_node_intersect_robust(KernelGlobals *__restrict kg,
                                                  const float difl,
                                                  ssef *__restrict dist)
 {
-       const int offset = nodeAddr*BVH_QNODE_SIZE + 1;
+       const int offset = nodeAddr + 1;
 #ifdef __KERNEL_AVX2__
        const ssef tnear_x = msub(kernel_tex_fetch_ssef(__bvh_nodes, offset+near_x), idir.x, P_idir.x);
        const ssef tnear_y = msub(kernel_tex_fetch_ssef(__bvh_nodes, offset+near_y), idir.y, P_idir.y);
index 01babba021507a9c6e3360662cc0bbc6877606fd..97a0ceb068721e98b55b20fadd08bb4e5bdbf3f1 100644 (file)
@@ -97,7 +97,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
                do {
                        /* Traverse internal nodes. */
                        while(nodeAddr >= 0 && nodeAddr != ENTRYPOINT_SENTINEL) {
-                               float4 inodes = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_QNODE_SIZE+0);
+                               float4 inodes = kernel_tex_fetch(__bvh_nodes, nodeAddr+0);
 
 #ifdef __VISIBILITY_FLAG__
                                if((__float_as_uint(inodes.x) & PATH_RAY_SHADOW) == 0) {
@@ -124,8 +124,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
                                                                        &dist);
 
                                if(traverseChild != 0) {
-                                       float4 cnodes = kernel_tex_fetch(__bvh_nodes,
-                                                                        nodeAddr*BVH_QNODE_SIZE+7);
+                                       float4 cnodes = kernel_tex_fetch(__bvh_nodes, nodeAddr+7);
 
                                        /* One child is hit, continue with that child. */
                                        int r = __bscf(traverseChild);
@@ -218,7 +217,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
 
                        /* If node is leaf, fetch triangle list. */
                        if(nodeAddr < 0) {
-                               float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-nodeAddr-1)*BVH_QNODE_LEAF_SIZE);
+                               float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-nodeAddr-1));
 #ifdef __VISIBILITY_FLAG__
                                if((__float_as_uint(leaf.z) & PATH_RAY_SHADOW) == 0) {
                                        /* Pop. */
index bc717a0747ed321e0e3435cf85aabcc7cd19ac5c..5d76ac4b1f13c55efa65a1494a03f9d6cf10bd51 100644 (file)
@@ -123,8 +123,7 @@ ccl_device void BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
                                                                        &dist);
 
                                if(traverseChild != 0) {
-                                       float4 cnodes = kernel_tex_fetch(__bvh_nodes,
-                                                                        nodeAddr*BVH_QNODE_SIZE+7);
+                                       float4 cnodes = kernel_tex_fetch(__bvh_nodes, nodeAddr+7);
 
                                        /* One child is hit, continue with that child. */
                                        int r = __bscf(traverseChild);
@@ -217,7 +216,7 @@ ccl_device void BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
 
                        /* If node is leaf, fetch triangle list. */
                        if(nodeAddr < 0) {
-                               float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-nodeAddr-1)*BVH_QNODE_LEAF_SIZE);
+                               float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-nodeAddr-1));
                                int primAddr = __float_as_int(leaf.x);
 
                                int primAddr2 = __float_as_int(leaf.y);
index 098881a6d7e436a63e61c68227c8a03a6bd93654..1588ae3605c4ca72c89c91a7d7e0f5f249898e37 100644 (file)
@@ -106,8 +106,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
                do {
                        /* Traverse internal nodes. */
                        while(nodeAddr >= 0 && nodeAddr != ENTRYPOINT_SENTINEL) {
-                               float4 inodes = kernel_tex_fetch(__bvh_nodes, 
-                                                                nodeAddr*BVH_QNODE_SIZE+0);
+                               float4 inodes = kernel_tex_fetch(__bvh_nodes, nodeAddr+0);
 
                                if(UNLIKELY(nodeDist > isect->t)
 #ifdef __VISIBILITY_FLAG__
@@ -167,8 +166,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
                                }
 
                                if(traverseChild != 0) {
-                                       float4 cnodes = kernel_tex_fetch(__bvh_nodes,
-                                                                        nodeAddr*BVH_QNODE_SIZE+7);
+                                       float4 cnodes = kernel_tex_fetch(__bvh_nodes, nodeAddr+7);
 
                                        /* One child is hit, continue with that child. */
                                        int r = __bscf(traverseChild);
@@ -266,7 +264,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
 
                        /* If node is leaf, fetch triangle list. */
                        if(nodeAddr < 0) {
-                               float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-nodeAddr-1)*BVH_QNODE_LEAF_SIZE);
+                               float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-nodeAddr-1));
 
 #ifdef __VISIBILITY_FLAG__
                                if(UNLIKELY((nodeDist > isect->t) ||
index 2aae90380c11341e83a9c0388a327147cf9681e0..d66c6e2b1e55725bc3eb3f7626260e8fdeaa3047 100644 (file)
@@ -94,7 +94,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
                        /* Traverse internal nodes. */
                        while(nodeAddr >= 0 && nodeAddr != ENTRYPOINT_SENTINEL) {
 #ifdef __VISIBILITY_FLAG__
-                               float4 inodes = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_QNODE_SIZE+0);
+                               float4 inodes = kernel_tex_fetch(__bvh_nodes, nodeAddr+0);
                                if((__float_as_uint(inodes.x) & visibility) == 0) {
                                        /* Pop. */
                                        nodeAddr = traversalStack[stackPtr].addr;
@@ -119,8 +119,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
                                                                        &dist);
 
                                if(traverseChild != 0) {
-                                       float4 cnodes = kernel_tex_fetch(__bvh_nodes,
-                                                                        nodeAddr*BVH_QNODE_SIZE+7);
+                                       float4 cnodes = kernel_tex_fetch(__bvh_nodes, nodeAddr+7);
 
                                        /* One child is hit, continue with that child. */
                                        int r = __bscf(traverseChild);
@@ -213,7 +212,7 @@ ccl_device bool BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
 
                        /* If node is leaf, fetch triangle list. */
                        if(nodeAddr < 0) {
-                               float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-nodeAddr-1)*BVH_QNODE_LEAF_SIZE);
+                               float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-nodeAddr-1));
                                int primAddr = __float_as_int(leaf.x);
 
 #if BVH_FEATURE(BVH_INSTANCING)
index e6b668eb75881e678abdcc33ffe79dc721984209..89950f17c64cefba2deafdbbb82decdd88062fed 100644 (file)
@@ -98,7 +98,7 @@ ccl_device uint BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
                        /* Traverse internal nodes. */
                        while(nodeAddr >= 0 && nodeAddr != ENTRYPOINT_SENTINEL) {
 #ifdef __VISIBILITY_FLAG__
-                               float4 inodes = kernel_tex_fetch(__bvh_nodes, nodeAddr*BVH_QNODE_SIZE+0);
+                               float4 inodes = kernel_tex_fetch(__bvh_nodes, nodeAddr+0);
                                if((__float_as_uint(inodes.x) & visibility) == 0) {
                                        /* Pop. */
                                        nodeAddr = traversalStack[stackPtr].addr;
@@ -123,8 +123,7 @@ ccl_device uint BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
                                                                        &dist);
 
                                if(traverseChild != 0) {
-                                       float4 cnodes = kernel_tex_fetch(__bvh_nodes,
-                                                                        nodeAddr*BVH_QNODE_SIZE+7);
+                                       float4 cnodes = kernel_tex_fetch(__bvh_nodes, nodeAddr+7);
 
                                        /* One child is hit, continue with that child. */
                                        int r = __bscf(traverseChild);
@@ -217,7 +216,7 @@ ccl_device uint BVH_FUNCTION_FULL_NAME(QBVH)(KernelGlobals *kg,
 
                        /* If node is leaf, fetch triangle list. */
                        if(nodeAddr < 0) {
-                               float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-nodeAddr-1)*BVH_QNODE_LEAF_SIZE);
+                               float4 leaf = kernel_tex_fetch(__bvh_leaf_nodes, (-nodeAddr-1));
                                int primAddr = __float_as_int(leaf.x);
 
 #if BVH_FEATURE(BVH_INSTANCING)