AMD card strange behavior

Hi,

While testing my application on a AMD graphics card (Radeon Pro W5500) I noticed a strange behavior: drawing multiple display lists and setting gl_color before each one of them the second entity had the color of the first, but only during the first frame.

The problem doesn’t occur with NVidia cards.

I’m still trying to reproduce the issue consistently in a minimal application (generating and drawing as described before outside my application logic works fine, so maybe there’s something wrong with it and amd drivers are fine ).

What I find really interesting is that the same application isn’t affected by this problem when I launch it via NVidia Nsight Graphics.

How does nsight influence the behavior of the application? Could it be somehow a hint of the cause of the problem?

gl_color tends to suggest gl_Color, which means some old-style GLSL v1.1 built-in vertex attribute built-ins for vertex shaders.

Post what you’re doing. Both the referencing GLSL shader code, and the C++ code you’re using to populate all vertex attributes (and bind and enable them, if applicable) for the draw call you’re seeing the problem with.

I’m missing something. You said the problem doesn’t occur on NVIDIA cards. And the app doesn’t exhibit the problem in NVIDIA NSight Graphics. Nsight Graphics (AFAIK) only runs on NVIDIA cards. So… it’s unclear why you mentioned the latter.

Also, re the old built-in vertex attributes from legacy GL days, note that NVIDIA’s implementation supports vertex attribute aliasing between the old built-in attributes and generic attributes whereas AMD does not. See the example below for details, but basically, don’t bind to generic vertex attribute location 3 on the C++ side and expect this to materialize as gl_Color in the GLSL vertex shader on the AMD GPU.

Since it seems like this old link has rotted, I’ll just repost the relevant portion of the content here:

Clockworkcoders Tutorials : Vertex Attributes (subset)

Clockworkcoders Tutorials : Vertex Attributes (subset)
(formerly https://www.opengl.org//sdk/docs/tutorials/ClockworkCoders/attributes.php)

I managed to reproduce the issue (or at least an issue) systematically with the following:

public void TestAMD(ref uint line1List, ref uint line2List, ref uint line3List, bool gen)
{
    if (gen)
    {
        //---------------------- LINE 1 COMPILE ---------------------- //
        gl.DeleteLists(line1List, 1);
        line1List = gl.GenLists(1);

        gl.NewList(line1List, gl.COMPILE);
        gl.Begin(gl.LINES);
        {
            gl.Vertex3f(0, 0, 0);
            gl.Vertex3f(1, 1, 0);
        }
        gl.End();
        gl.EndList();

        //---------------------- LINE 2 COMPILE ---------------------- //
        gl.DeleteLists(line2List, 1);
        line2List = gl.GenLists(1);

        gl.NewList(line2List, gl.COMPILE);
        gl.Begin(gl.LINES);
        {
            gl.Vertex3f(0, 0, 0);
            gl.Vertex3f(-1, -1, 0);
        }
        gl.End();
        gl.EndList();

        //---------------------- LINE 3 COMPILE ---------------------- //
        gl.DeleteLists(line3List, 1);
        line3List = gl.GenLists(1);

        gl.NewList(line3List, gl.COMPILE);
        gl.Begin(gl.LINES);
        {
            gl.Vertex3f(0.5f, 0.5f, 0);
            gl.Vertex3f(0.5f, -0.5f, 0);
        }
        gl.End();
        gl.EndList();
    }
    

    gl.UseProgram(...);

    gl.ClearColor(0.25f, 0.25f, 0.25f, 1.0f);
    gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

    gl.Color4ub(255, 0, 0, 255);

    gl.CallList(line1List);

    gl.Color4ub(0, 255, 0, 255);

    gl.CallList(line2List);

    gl.Color4ub(0, 0, 255, 255);

    gl.CallList(line3List);


    SwapBuffers();
}

This is the shader I’m using:

// VERTEX
void main(void)
{
   vec4 ecPosition = gl_ModelViewMatrix * gl_Vertex;

   gl_ClipVertex = ecPosition; // userclipping

   gl_FrontColor = gl_Color;

   gl_Position = ftransform();
}

// FRAGMENT
void main(void)
{
   vec4 finalColor;    

   finalColor = gl_Color;

   finalColor = clamp (finalColor, 0.0, 1.0);

   gl_FragColor = finalColor;        
}

If I use the TestAMD method as follows:

uint line1, line2, line3;

line1 = line2 = line3 = 0;

TestAMD(ref line1, ref line2, ref line3, true);

TestAMD(ref line1, ref line2, ref line3, false);

the first invocation results in an incorrect drawing where line3List is green, while the second invocation gets the line drawn right (blue).

I’m missing something. You said the problem doesn’t occur on NVIDIA cards. And the app doesn’t exhibit the problem in NVIDIA NSight Graphics. Nsight Graphics (AFAIK) only runs on NVIDIA cards. So… it’s unclear why you mentioned the latter.

You are right, NSight Graphics only runs on NVidia Cards but I didn’t know with certainty so I tried to launch the application from NSight and it actually allowed me to run the program (without the possibility to capture and analyze a frame however) and the issue is not there when doing so, so I was wondering about the effect that NSight Graphics may have on an application.

You’re poking through old, dusty corners of ancient OpenGL with immediate mode drawing wrapped in display lists and fixed-function built-in attributes in GLSL, with some attribs provided per vertex and others not. And as I recall, only NVIDIA supported this old stuff reliably.

If you want cross-GPU vendor compatibility, I’d suggest dropping your use of old immediate mode, display lists, vertex attribute values not provided per vertex, and instead use simple, straightforward vertex arrays where all vertex attribute values are provided by the arrays.

Using vertex attributes where some attr values are not provided by arrays has some ugly performance consequences (as far as triggering draw-time shader recompiles). So if you care about performance, you avoid using those like the plague. You use GLSL uniforms instead.

1 Like

It’s already in my TODO list, however, since I’m not going to rebuild the entire drawing logic overnight, is there a subset of those old features supported by every implementation?

As an example, I repeated the same TestAMD I posted above, this time using VBOs and vertex arrays for positions. Again, with color not provided by arrays. This time no color issue. Could it be a coincidence?

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.