Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: AMD and non-multiple of 4 vertex

  1. #1
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117

    AMD and non-multiple of 4 vertex

    Anybody had problems with AMD driver 12.13 with non-mutliple of 4 vertices?

    The following is working on nVidia but not on AMD Radeon R9 290
    Code :
    class C3D_VertexN
    {
    public:
        float        x;
        float        y;
        float        z;
        float        w;
        float        nx;
        float        ny;
        float        nz;
     
     
      static int VertexType()
      {
        return VERTEXN;
      }
     
     
      static void SetBindings()
      {
        glVertexAttribPointer(VERTEX_BINDINGS_POSITION, 4, GL_FLOAT, GL_FALSE, sizeof(C3D_VertexN), 0);
          glEnableVertexAttribArray(VERTEX_BINDINGS_POSITION);
          glVertexAttribPointer(VERTEX_BINDINGS_NORMAL, 3, GL_FLOAT, GL_FALSE,sizeof(C3D_VertexN),(const void*)(offsetof (C3D_VertexN,nx)));
          glEnableVertexAttribArray(VERTEX_BINDINGS_NORMAL);
      }
    };

    but

    Code :
    class C3D_VertexN
    {
    public:
        float        x;
        float        y;
        float        z;
        float        w;
        float        nx;
        float        ny;
        float        nz;
        float          FILLER;
     
     
      static int VertexType()
      {
        return VERTEXN;
      }
     
     
      static void SetBindings()
      {
        glVertexAttribPointer(VERTEX_BINDINGS_POSITION, 4, GL_FLOAT, GL_FALSE, sizeof(C3D_VertexN), 0);
          glEnableVertexAttribArray(VERTEX_BINDINGS_POSITION);
          glVertexAttribPointer(VERTEX_BINDINGS_NORMAL, 4, GL_FLOAT, GL_FALSE,sizeof(C3D_VertexN),(const void*)(offsetof (C3D_VertexN,nx)));
          glEnableVertexAttribArray(VERTEX_BINDINGS_NORMAL);
      }
    };

    works fine

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,209
    Quote Originally Posted by tonyo_au View Post
    The following is working on nVidia but not on AMD Radeon R9 290
    Code :
    class C3D_VertexN
    {
        float        x,y,z,w,nx,ny,nz;
    ...
     
    sizeof(C3D_VertexN)

    but

    Code :
    class C3D_VertexN
    {
        float        x,y,z,w,nx,ny,nz,FILLER;
    ...
     
    sizeof(C3D_VertexN)

    works fine

    I suspect this is not an NVidia vs. AMD issue. But a structure size/alignment issue between your systems.

    Print sizeof(C3D_VertexN) and verify that it is 28 for the first definition. I suspect you'll find that it is 32 on the AMD system.

    Try adding #pragma pack(push[,n]) / #pragma pack(pop) around your struct, or adding __attribute__((packed)) to it, or whatever your compiler supports to eliminate the implicit padding that is probably being added. I think that'll fix your problem.

    That said, it is generally recommended to keep your vertex sizes a multiple of 16 bytes. So I'd benchmark against the struct with FILLER in-place.

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    verify that it is 28


    I verified it is 28 bytes (I am not surprised since I use the same compiler on both).

    It also effects compute shaders. This
    Code :
    struct vertex_in_struct
    {
      float x;
      float y;
      float z;
      float w;
      float nx;
      float ny;
      float nz;
    };
     
     
    layout( std430, binding=4 ) buffer Vertices
    {
      vertex_in_struct Vertex[ ];
    };

    works on nVidia but not AMD.

    I think I will take your advice and pad to 16 bytes although it does cost my a bit of space on large DTM's

  4. #4
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    3,209
    Wow. If true, that's ugly. I would have thought I'd have seen some mention of that before if that was the case.

    Are you sure you're not doing something else wrong like overrunning your vertex buffer(s)? I would run a memory checker like valgrind, purify, or similar to double check that.

  5. #5
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    I am less sure on what is happening in the compute shader (it is my first attempt to use one). But the change for the vertex structure for rendering the DTM fixed my problem. Everything renders correctly including textures where I generate uv's procedurally.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •