我们已经编写了GLSL着色器代码来做射线跟踪可视化使用GPU。在光线行进环中放置一个早期的出口中断似乎是相当标准的,所以如果灯被熄灭,环就会断裂。
但是根据我对GPU代码的了解,每次呈现将花费最长的循环运行时间。所以我的问题是:提前退出值得吗?
例如:
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;
}
}发布于 2015-05-15 10:04:00
GPU的调度单元是经纱/波前。通常是由32个或64个线程组成的连续组。翘曲的执行时间是该翘曲内所有线程执行时间的最大值。
因此,如果您的早期退出可以使整个翘曲更快地终止(例如,如果线程0到31都采用早期退出),那么是的,这是值得的,因为硬件可以安排另一个翘曲来执行,从而减少了整个内核运行时间。否则,它可能不是,因为即使线程1到31采取早期退出,翘曲仍然占用硬件,直到线程0完成。
https://stackoverflow.com/questions/30256579
复制相似问题