首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >GPU上循环的早期退出值得吗?

GPU上循环的早期退出值得吗?
EN

Stack Overflow用户
提问于 2015-05-15 09:59:10
回答 1查看 1.9K关注 0票数 4

我们已经编写了GLSL着色器代码来做射线跟踪可视化使用GPU。在光线行进环中放置一个早期的出口中断似乎是相当标准的,所以如果灯被熄灭,环就会断裂。

但是根据我对GPU代码的了解,每次呈现将花费最长的循环运行时间。所以我的问题是:提前退出值得吗?

例如:

代码语言:javascript
复制
for(int i = 0; i < MAX_STEPS; i++){
        //Get the voxel intensity value from the 3D texture.    
        dataRGBA = getRGBAfromDataTex(dataTexture, currentPosition, dataShape, textureShape);

        // get contribution from the light
        lightRayPathRGBA = getPathRGBA(currentPosition, light.position, steps, tex); // this is the light absorbed so we need to take 1.0- to get the light transmitted
        lightRayRGBA = (vec4(1.0) - lightRayPathRGBA) * vec4(light.color, light.intensity);

        apparentRGB = (1.0 - accumulatedAlpha) * dataRGBA.rgb * lightRayRGBA.rgb * dataRGBA.a * lightRayRGBA.a;
        //apparentRGB = (1.0 - accumulatedAlpha) * dataRGBA.rgb * dataRGBA.a * lightRayRGBA.a;

        //Perform the composition.
        accumulatedColor += apparentRGB;
        //Store the alpha accumulated so far.
        accumulatedAlpha += dataRGBA.a;

        //Adva      nce the ray.
        currentPosition += deltaDirection;
        accumulatedLength += deltaDirectionLength;

        //If the length traversed is more than the ray length, or if the alpha accumulated reaches 1.0 then exit.
        if(accumulatedLength >= rayLength || accumulatedAlpha >= 1.0 ){
            break;
        }
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-05-15 10:04:00

GPU的调度单元是经纱/波前。通常是由32个或64个线程组成的连续组。翘曲的执行时间是该翘曲内所有线程执行时间的最大值。

因此,如果您的早期退出可以使整个翘曲更快地终止(例如,如果线程0到31都采用早期退出),那么是的,这是值得的,因为硬件可以安排另一个翘曲来执行,从而减少了整个内核运行时间。否则,它可能不是,因为即使线程1到31采取早期退出,翘曲仍然占用硬件,直到线程0完成。

票数 11
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30256579

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档