I am working to an OpenGL graphic engine which can render transparent meshes with accuracy. The full project is available here; it is a Visual Studio 2017 solution (you may need to install the Windows 10 SDK) but also includes a makefile to build under Linux. It uses linked lists of fragments on the GPU which are then sorted and blended back-to-front.
The problem is that everything works fine on my notebook with discrete AMD graphics, but crashes on my other nVidia PC (GT 740, very cheap). It crashes both on Windows and Linux and both with the official driver and the open source stack. The code that cause this is inside the sorting shader (please see the TODO comment):
int listBegin = listsHeads[getPixelBufferIndex()];
if(listBegin != -1)
{
// Sort linked list using bubble sort
bool swapped;
do
{
// Start at list head
swapped = false;
int previousNode = listBegin;
int currentNode = listsNodes[listBegin].nextNode;
// Loop until list end
while(currentNode != -1)
{
// Furthest first
float previousDepth = listsNodes[previousNode].depth;
float currentDepth = listsNodes[currentNode].depth;
// TODO fix crash on nVidia
if(previousDepth < currentDepth)
{
swapped = true;
FragmentNode temp;
temp.color = listsNodes[currentNode].color;
temp.meshId = listsNodes[currentNode].meshId;
listsNodes[currentNode].color = listsNodes[previousNode].color;
listsNodes[currentNode].depth = previousDepth;
listsNodes[currentNode].meshId = listsNodes[previousNode].meshId;
listsNodes[previousNode].color = temp.color;
listsNodes[previousNode].depth = currentDepth;
listsNodes[previousNode].meshId = temp.meshId;
}
previousNode = currentNode;
currentNode = listsNodes[currentNode].nextNode;
}
}
while(swapped);
}
If I remove the inner if the program no longer crashes, but of course the result is incorrect since the lists are not sorted. I am starting to think that there is a problem with my particular graphic card model, because crashing both with the binary driver and the open source stack on the same card seems to suggests that. But maybe there is actually a bug in the shader that I couldn’t find.
Any idea?