Skip to main content
GameDev.net gamedev.net
🔒 Locked

Getting a warning whenever I pad my vertex structure.

Started by ph33r Oct 7, 2004 at 11:53 AM 11 replies 2.6k views
Original Post
ph33r
ph33r
I try to keep my vertex structure padded to a multiple of 32 bytes but whenever I do that I get this warning, spammed in my output window 100's of times a second. "D3D(WARN): Stream 0 stride and vertex size, computed from the current vertex declaration or FVF, are different, which might not work with pre-DX8 drivers" If I take out the padding it wont give me that warning. Here is the code I use for creating a vb and setting the stream

#define D3DFVF_CUSTOM   ( D3DFVF_XYZ | D3DFVF_DIFFUSE )
struct CUSTOM_FVF
{
	D3DXVECTOR3		m_position;
	D3DCOLOR		m_color;
	char			pad[16];
};


g_pDevice->CreateVertexBuffer(
		8 * sizeof( CUSTOM_FVF ),    // byte size of buffer
		0,                           // flags
		D3DFVF_CUSTOM,                  // FVF format
		D3DPOOL_DEFAULT,             // memory pool
		&g_pVertexBuffer,            // stored buffer
		NULL );   

g_pDevice->SetStreamSource( 0, g_pVertexBuffer, 0, sizeof( CUSTOM_FVF ) );

So how do I pad my structure to a multiple of 32 bytes without getting that annoying warning?
Evil Steve
Evil Steve
Take your D3D debug output level down a notch [wink]

EDIT: I just tried that (adding padding) and you need to take the warning level down to the lowest but one to get rid of it. So maybe its not such a good idea...
Domini
Domini
If you're using the pre-DX9 FVF and the fixed function pipeline instead of Vertex Declarations and shaders, he warning makes sense. DX uses the flags to determine the size of the vertex and the location of the data. It's giving the warning because the sizes are different from expected.

Why do you pad the vertex size? Are you planning on adding more data later? Just curious.

Dominque Douglas
www.miraclemanstudios.com

---

you know i'm getting frustrated when i start naming my variables "please_work" and "for_the_love_of_god"
:-(
ph33r
ph33r
I use padding because the docs say it's more effecient to pad thte structure to an interval of 32 bytes
hplus0603
hplus0603
You could add un-used COLOR elements to pad it out; that will silence the warning :-)
enum Bool { True, False, FileNotFound };
circlesoft
circlesoft
Quote:
Original post by ph33r
I use padding because the docs say it's more effecient to pad thte structure to an interval of 32 bytes

You have to take this advice in stride. Your current vertex structure is laid out like this:

D3DXVECTOR3  // 12 bytesD3DCOLOR     // 4 byteschar[16]     // 16 bytes


You are *doubling* the vertex size here, just to make it 32-byte aligned. This means that you are doubling the memory usage of each vertex buffer, and doubling the amount of data that you are sending to the card every frame.

However, let's say your vertex structure was laid out like this:
D3DXVECTOR3 position  // 12 bytesD3DXVECTOR3 normal    // 12 bytesD3DCOLOR    color     // 4 bytesfloat       emptyData // 4 bytes


In this scenario, padding the vertices would be more benificial, since you are only adding 4 bytes to each vertex (only 12.5% more data, insead of 50%).

I usually never pad my vertices, just to save the most amount of memory as possible (especially when doing keyframe animation). Have you benchmarked padded/aligned performance against unaligned performance?
ph33r
ph33r
No I havn't benchmarked it, I don't know any profilers that work on the gpu.
DBX
DBX
I don't see why you feel the need to pad it. Take the padding out. If, when you have a working app, you find that padding your vertices gives an increase in framerate then you can pad them. But don't bother until then.
Optmisations like this are tips, not rules. You never perform an optimisation unless you can measure the difference it makes to your [working] application.
nohbdy
nohbdy
Quote:
Original post by circlesoft
In this scenario, padding the vertices would be more benificial, since you are only adding 4 bytes to each vertex (only 12.5% more data, insead of 50%).


Actually, it'd be ~16% and 100%(ew!) increase in size from the padding. Adding a whole 16 bytes per vertex probably isn't a good idea... and while I'm not entirely sure about this, I think the fact that your vertices are power-of-two size almost nullifies the fact that they aren't the magic size of 32 bytes (2 of your vertices fit perfectly in the space of 32 bytes, there shouldn't be any problems that arise due to memory alignment that might be an issue if your verts were, say, 24 or 28 bytes)

As for profilers... DirectX 9.0c SDK comes with a version of PIX (which is a graphics profiler). Never used it though, so I can't say how much information it would give you about something like this... it's probably more helpful for finding your bottlenecks, which is what you should be focusing on before worrying about padding your vertices for optimality :)

-nohbdy
S1CA
S1CA
Quote:
Original post by Anonymous Poster
The D3DFVFCAPS_DONOTSTRIPELEMENTS device cap in D3DCAPS9.FVFCaps relates to this.

Whether padding/stripping elements improves performance is increadibly hardware and even driver revision specific.

ISTR someone at nVidia did a presentation comparing the peformance of different vertex sizes on their hardware - you should be able to find it on their developer website (search for FVF).


oops - pesky auto logout.
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
circlesoft
circlesoft
Quote:
Original post by nohbdy
Quote:
Original post by circlesoft
In this scenario, padding the vertices would be more benificial, since you are only adding 4 bytes to each vertex (only 12.5% more data, insead of 50%).


Actually, it'd be ~16% and 100%(ew!)
Bah, I knew I was going to get that wrong! [smile]

Anyways, PIX is a pretty useful tool, as long as you take the time to learn it. Although there isn't that much functionality there right now, MS is still working on it.
Codemonger
Codemonger
Quote:
Original post by Anonymous Poster
The D3DFVFCAPS_DONOTSTRIPELEMENTS device cap in D3DCAPS9.FVFCaps relates to this.

Whether padding/stripping elements improves performance is increadibly hardware and even driver revision specific.

ISTR someone at nVidia did a presentation comparing the peformance of different vertex sizes on their hardware - you should be able to find it on their developer website (search for FVF).


I remember reading that presentation and I believe it went something like this:

24 bytes optimal
32 or 64 bytes ran around the same speed
-------------Become part of developing the specifications of a new language. Visit CodeBASIC.org

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.