Is it necessary to align vertex data in VAR memory to 32 byte boundaries? I ask because I have encountered a very strange behavior in VAR, which I cannot trace to any bug in my code, so I assume there might be a bug in the VAR implementation. I use VAR in the following way:
allocate large chunk of VAR (16MB)
for every frame:
for all objects (all static):
copy vertex data to VAR memory (memcpy)
draw object
swapbuffer
The objects are simply copied consecutively, i.e., if object 1 goes to address a1 in VAR and has s1 bytes, then object 2 will go to address a2=a1+s1, until there is a wraparound.
Now here ist the problem:
If I don’t align vertex data on a 32 byte address, some triangles in the scene will just go wild. I can reproduce that with a very simple case, just drawing a rectangle in one triangle strip with 4 vertices, no colors/normals/texcoords, and 3 floats for each vertex (which gives 48 bytes for the object). I have made screenshots of the problem ( here is the intended image, this is what it looks like every second frame). Padding the object to 64 bytes fixes the problem. If I don’t use VAR, or if I step through the program with the debugger, or do something else between copying and drawing (like writing some debug output to the console), the problem goes away.
This is strange because the VAR-spec says that there are no alignment requirements on the NV20 (where the problem appears), only “<pointer>” needs to be 32 byte aligned, and <pointer> I assume to be the pointer to the whole VAR-memory allocated with wglAllocateMemoryNV.
I have no problem with aligning my data to 32 bytes, but this has cost me quite some time debugging, and (assuming it’s not a bug in my code) such a behavior should be documented.
I have one suspicion:
Could the problem lie with some caching issue? If the last chunk of vertex data does not fill a 32 byte cache line, it is maybe not yet written to memory when the GPU already tries to access it (because I immediately draw the object after copying). This would still be quite a strange, non-sequential effect, but it would at least explain this strange behavior…
Any suggestions are welcome,
thanks,
Michael
[This message has been edited by wimmer (edited 03-09-2002).]
[This message has been edited by wimmer (edited 03-09-2002).]