Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/134.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 排序算法是什么(以及它在GPU上运行的效果如何)_C++_Qt_Sorting_Opengl_Glsl - Fatal编程技术网

C++ 排序算法是什么(以及它在GPU上运行的效果如何)

C++ 排序算法是什么(以及它在GPU上运行的效果如何),c++,qt,sorting,opengl,glsl,C++,Qt,Sorting,Opengl,Glsl,我已经实现了一个用于排序像素的着色器: void main() { vec4 renderedImagePixel = texture2D(CalculatedImage,v_texcoord); if(int(numRenderPass) == int(v_texcoord.y*float(height)) && fbo ){ vec2 coordTHIS = vec2(v_texcoord.x,v_texcoord.y-1.0/float(

我已经实现了一个用于排序像素的着色器:

void main()
{
    vec4 renderedImagePixel = texture2D(CalculatedImage,v_texcoord);

    if(int(numRenderPass) == int(v_texcoord.y*float(height)) && fbo ){

        vec2 coordTHIS = vec2(v_texcoord.x,v_texcoord.y-1.0/float(height));
        float THIS = unpack(texture2D(CalculatedImage,coordTHIS));
        renderedImagePixel = texture2D(CalculatedImage,coordTHIS);

        if(sieveCycle == true){ //even Cycle

            //Even cell
            if(mod(int(v_texcoord.x*float(width)),2) == 1){
                //CHANGES IN CODE HERE
                vec2 coordTHAT = vec2(v_texcoord.x+1.0/float(width),v_texcoord.y-1.0/float(height));
                float THAT = unpack(texture2D(CalculatedImage,coordTHAT));

                //CHANGES IN CODE HERE
                if( THIS > THAT ){
                    renderedImagePixel = texture2D(CalculatedImage,coordTHAT);
                }
            }else{
            //Odd cell
                //CHANGES IN CODE HERE
                vec2 coordTHAT = vec2(v_texcoord.x-1.0/float(width),v_texcoord.y-1.0/float(height));
                float THAT = unpack(texture2D(CalculatedImage,coordTHAT));

                //CHANGES IN CODE HERE
                if( THAT > THIS ){
                    renderedImagePixel = texture2D(CalculatedImage,coordTHAT);
                }
            }

        }else{ //odd cycle

            //Even cell
            if(mod(int(v_texcoord.x*float(width)),2) == 0){
                //CHANGES IN CODE HERE
                vec2 coordTHAT = vec2(v_texcoord.x+1.0/float(width),v_texcoord.y-1.0/float(height));
                float THAT = unpack(texture2D(CalculatedImage,coordTHAT));

                //CHANGES IN CODE HERE
                if( THIS > THAT ){
                    renderedImagePixel = texture2D(CalculatedImage,coordTHAT);
                }
            }else{
            //Odd cell
                //CHANGES IN CODE HERE
                vec2 coordTHAT = vec2(v_texcoord.x-1.0/float(width),v_texcoord.y-1.0/float(height));
                float THAT = unpack(texture2D(CalculatedImage,coordTHAT));

                //CHANGES IN CODE HERE
                if( THAT > THIS ){
                    renderedImagePixel = texture2D(CalculatedImage,coordTHAT);
                }
            }

        }
    }

    gl_FragColor = renderedImagePixel;

}
现在我想知道它有多有效

我的想法是,如果在一个周期内计算每个像素,那么在最坏的情况下,算法应该是开启的。是这样吗。以防它只是一个泡沫排序的衍生物

下面是一个排序示例的图像:

您正在实现一个,并且使用了奇偶排序算法

这需要在输出完全排序之前进行迭代

然而,更有效的算法存在,如。这只需要Olog²n迭代。着色器将变得更加复杂,因为其他值将根据迭代次数而变化


您可以通过使用另一个纹理来简化它,在该纹理中,其他索引将被编码,以及是取最小值还是最大值。

您可能希望看看排序网络,这是您试图实现的,Dude,它很漂亮。我在哪里可以找到生成相对索引掩码的实现?