PDA

View Full Version : Sorting



mradwan
05-28-2017, 04:41 AM
I am trying to write a fragment shader that sorts a part of a texture. Each thread is responsible for sorting a part. Perhaps this is not the most efficient way, but this is how I need to do it now. I wrote the following code, which works with a data set and fails with another (I think the shader halts with no output).


minDepth=100000.0;
minEpoint=float(count)+10.0;

for(int j=0;j<2*count;j++) //to find min
{

EpointIndexGlobal = 2*offset+j;

EpointIndexGlobalX=EpointIndexGlobal%EpointsNumSqr t;
EpointIndexGlobalY=EpointIndexGlobal/EpointsNumSqrt;


info = texelFetch(TmpEpointsImage, ivec2(int(EpointIndexGlobalX),int(EpointIndexGloba lY)),0);

Depth=info.x;
Epoint=info.z;

if(lessThan(Depth,Epoint,minDepth,minEpoint) && greaterThan(Depth,Epoint,lastDepth,lastEpoint))
{
minDepth=Depth;
minEpoint=Epoint;
minInfo=info;
}

}

EpointIndexGlobal = 2*offset+i;
EpointIndexGlobalX=EpointIndexGlobal%EpointsNumSqr t;
EpointIndexGlobalY=EpointIndexGlobal/EpointsNumSqrt;

imageStore(EpointsImage, ivec2(EpointIndexGlobalX,EpointIndexGlobalY), minInfo);

lastDepth=minDepth;
lastEpoint=minEpoint;

}


I read vec4 values from tmpEpointsImage and sort in EpointsImage. Sorting is performed according to two values. Does anyone know what is the problem?