Skip to main content
gamedev.net
🔒 Locked

SetStreamSource Usage

Started by littlekid Jan 11, 2007 at 6:29 AM 2 replies 2.5k views
Original Post
littlekid
littlekid
I have multiple streams in my program. Is it better to store all the vertices in to one single VertexBuffer and then set the streams according base on the offset? Eg. pVertices ---> Buffer that contain all the vertices Stream0 - vertex0 to vertex 39; Stream1 - vertex40 to vertex 79; SetStreamSource(0, pVertices , 0); SetStreamSource(1, pVertices , 40); Or store them in separate buffer and do the following: SetStreamSource(0, pVertex1 , 0); //No Offset SetStreamSource(1, pVertex2 , 0); //No Offset Which will be faster? Will D3D prevent repeated setting of the buffer for example: SetStreamSource(0, pVertex, 0); SetStreamSource(0, pVertex, 0); SetStreamSource(0, pVertex, 0); SetStreamSource(0, pVertex, 0); Will this cause D3D to copy the buffer 4 times, or will just do it once? Thanks alot
remigius
remigius
I'm not entirely sure what you're trying to do with the 1st two samples, but setting up sources on different stream indices won't have the same effect as the last snippet you posted. By setting up streams at multiple indices, those streams will be read by the vertex shader simultaneously. You could construct two vertex declarations so the shader only uses a single stream, but then you'd be sending redundant data to the shader and the declaration switch also is an expensive operation. AFAIK, you should only use multiple streams if your shader needs to combine data from 2 sources, like with instancing or morphing.

If two streams is what you need however, I'd *guess* the 2nd snippet is marginally more efficient as the stream data is interleaved before it reaches the shader, which would be easier to do sequentially than by seeking within the same buffer (if that's even possible).

The final sample shouldn't be too expensive, since D3D is smart enough to ignore the redundant vertex source changes. The source change is only remembered -not executed- and D3D will only apply the last change when you actually make a Draw call. You can find more info on that over at this excellent DX faq.
Namethatnobodyelsetook
Namethatnobodyelsetook
SetStreamSource offset is bytes, not vertices, so an offset of 40 isn't going to point to vertex 40.

Some older cards don't support the offset in SetStreamSource (it's fairly new). Using a single stream you can use BaseVertexIndex to offset into the VB. For multiple streams you're probably best off using multiple buffers. If you require shader 2 you can probably safely expect the card to support stream offset, but I don't think it's really going to gain you anything.
ET3D
ET3D
Quote:
Some older cards don't support the offset in SetStreamSource

None of significance, though. All GeForce and Radeon cards support it. Only the likes of the TNT etc. will not support it.

Topic Locked

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

Sign in to reply to this topic.