PDA

View Full Version : AMD and non-multiple of 4 vertex



tonyo_au
02-20-2014, 12:24 AM
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


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



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

Dark Photon
02-20-2014, 06:04 AM
The following is working on nVidia but not on AMD Radeon R9 290


class C3D_VertexN
{
float x,y,z,w,nx,ny,nz;
...

sizeof(C3D_VertexN)


but



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.

tonyo_au
02-20-2014, 04:08 PM
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

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

Dark Photon
02-20-2014, 06:12 PM
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.

tonyo_au
02-20-2014, 06:33 PM
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.