Algorithm 用GPU优化BVH遍历

Algorithm 用GPU优化BVH遍历,algorithm,optimization,parallel-processing,gpu,bounding-volume,Algorithm,Optimization,Parallel Processing,Gpu,Bounding Volume,我创建了一个每帧生成的边界体积层次。由于它的使用,每个节点必须有两个子节点,不能多,也不能少 遍历是目前我的程序中最昂贵的计算,它可以防止大型场景(>2k三角形)以可接受的帧速率运行。我不知道如何才能更快地完成。有16个三角形的简单正方形在多条光线同时通过时会引入明显的帧下降 为了遍历它,我使用了本文提供的概念,其中每个线程遍历以下代码 怎样才能提高它的速度 目前,这个函数在一个更大的内核中使用。以使用更多内存存储其输出为代价,将其隔离在自己的分派调用中是否会有所帮助 //o= origin ,

我创建了一个每帧生成的边界体积层次。由于它的使用,每个节点必须有两个子节点,不能多,也不能少

遍历是目前我的程序中最昂贵的计算,它可以防止大型场景(>2k三角形)以可接受的帧速率运行。我不知道如何才能更快地完成。有16个三角形的简单正方形在多条光线同时通过时会引入明显的帧下降

为了遍历它,我使用了本文提供的概念,其中每个线程遍历以下代码

怎样才能提高它的速度

目前,这个函数在一个更大的内核中使用。以使用更多内存存储其输出为代价,将其隔离在自己的分派调用中是否会有所帮助

//o= origin , d =direction, bestT = the intersection distance

bool FindBVHIntersect(vec3 o, vec3 d,inout float bestT){ 

//starting at the root of the bvh(0) the locations of the two children are found (near , far)

uint current=0;
uint last=0;
uint near=uint(bvh[current].w);
uint far=uint(bvh[current+1].w);

//max distance to test intersection
float distance=4294967295.0f;
bool success=false;
bool run= true;

while(run){

//update the children's location
near=uint(bvh[current].w);
far=uint(bvh[current+1].w);

//traversing up from the last child

//ending
if(last==far&&current==0){
run=false;
continue;
}
//go to the parent of the node
else if(last==far){
last=current;
current=bvhAtomics[current/2].y;
continue;
}

//depending on the last position, pick a child
uint tryChild= (last==bvhAtomics[current/2].y)?near:far;

bool delve;
//test the AABB
if(tryChild==near){
delve=FindAABBIntersect(bvh[current].xyz,bvh[current+1].xyz,o,d,0.0f,distance);
}
else{
delve=true;
}

//if the child is a node and needs to be delved.  A triangle intersection test.
if(delve&&tryChild>=(nodeSize-1)*2){

    float pt;
    float ob1;
    float ob2; 

    uint bvhPos=uint(bvh[tryChild+2].x);
    uvec3 indPos=indices[bvhPos].xyz;

    bool tr = FindTriangleIntersect(vertices[indPos.x].xyz, vertices[indPos.y].xyz,     vertices[indPos.z].xyz, o, d, pt, ob1, ob2 );
        if(tr){ 
            distance=pt;
            float t = pt;

            if (t > 0 && t < bestT) {
                bestT = t;
                success=true;
            }

        }

last=tryChild;
}

//switching children or setting up for climbing up the tree
else if(delve){

last =current;
current=tryChild;

}
else{       

last=far;
}


}

return success;
}
//o=原点,d=方向,bestT=交点距离
bool findbvhdintersect(vec3o,vec3d,inout float best){
//从bvh(0)的根开始,可以找到两个子对象的位置(近、远)
uint电流=0;
uint last=0;
uint near=uint(bvh[current].w);
uint far=uint(bvh[电流+1].w);
//到测试交叉口的最大距离
浮动距离=4294967295.0f;
布尔成功=假;
bool run=true;
while(运行){
//更新孩子们的位置
近=uint(bvh[当前].w);
far=uint(bvh[current+1].w);
//从最后一个孩子开始向上移动
//结束
如果(最后一个==far&¤t==0){
运行=错误;
持续
}
//转到节点的父级
else if(last==far){
last=当前值;
current=bHatOMICS[current/2].y;
持续
}
//根据最后一个位置,选择一个子对象
uint tryChild=(last==bvhAtomics[current/2].y)?近:远;
布尔德尔夫;
//测试AABB
如果(tryChild==near){
delve=FindAABBIntersect(bvh[current].xyz,bvh[current+1].xyz,o,d,0.0f,距离);
}
否则{
delve=真;
}
//如果子节点是一个节点,需要深入研究。三角形相交测试。
if(delve&&tryChild>=(节点大小-1)*2){
浮动pt;
浮动ob1;
浮动ob2;
uint bvhPos=uint(bvh[tryChild+2].x);
uvec3 indPos=指数[bvhPos].xyz;
bool tr=FindTriangleIntersect(顶点[indPos.x].xyz,顶点[indPos.y].xyz,顶点[indPos.z].xyz,o,d,pt,ob1,ob2);
如果(tr){
距离=pt;
浮点数t=pt;
如果(t>0&&t
我试图在算法的上下文中最小化内存访问,然而,我认为是问题所在的分歧似乎是一个不可能克服的障碍