Instancing with three vertex buffers / streams

Started by
3 comments, last by skytiger 14 years, 4 months ago
Is there any way to achieve this with instancing + more than 2 streams:
---------------	---------------	---------------	---------------
		3 verts		3 verts		4 verts
		triangle	particles	instances
---------------	---------------	---------------	---------------
counter		stream0		stream1		stream2
---------------	---------------	---------------	---------------
0		0		0		0
1		1		0		0
2		2		0		0
3		0		1		0
4		1		1		0
5		2		1		0
6		0		2		0
7		1		2		0
8		2		2		0
9		0		0		1
10		1		0		1
11		2		0		1
12		0		1		1
13		1		1		1
14		2		1		1
15		0		2		1
16		1		2		1
17		2		2		1
18		0		0		2
19		1		0		2
20		2		0		2
21		0		1		2
22		1		1		2
23		2		1		2
24		0		2		2
25		1		2		2
26		2		2		2
27		0		0		3
28		1		0		3
29		2		0		3
30		0		1		3
31		1		1		3
32		2		1		3
33		0		2		3
34		1		2		3
35		2		2		3
---------------	---------------	---------------	---------------


by default instancing only expands the instance streams - it doesn't repeat them this is what I get:
---------------	---------------	---------------	---------------
		3 verts		3 verts		4 verts        
		triangle	particles	instances      
---------------	---------------	---------------	---------------
counter		stream0		stream1		stream2        
---------------	---------------	---------------	---------------
0		0		0		0              
1		1		0		0              
2		2		0		0              
3		0		0		0              
4		1		0		0              
5		2		0		0              
6		0		0		0              
7		1		0		0              
8		2		0		0              
9		0		0		1              
10		1		0		1              
11		2		0		1              
12		0		1		1              
13		1		1		1              
14		2		1		1              
15		0		1		1              
16		1		1		1              
17		2		1		1              
18		0		1		2              
19		1		1		2              
20		2		1		2              
21		0		1		2              
22		1		1		2              
23		2		1		2              
24		0		2		2              
25		1		2		2              
26		2		2		2              
27		0		2		3              
28		1		2		3              
29		2		2		3              
30		0		2		3              
31		1		2		3              
32		2		2		3              
33		0		2		3              
34		1		2		3              
35		2		2		3              
---------------	---------------	---------------	---------------
[Edited by - skytiger on December 6, 2009 4:37:33 AM]
Advertisement
Instancing only has two frequencies, one for instanced streams and one for regular streams.

If you're using DX10 (you haven't mentioned what you're using), you can attach the data as tbuffers and sample them yourself.
There is definitely a frequency per stream
that is clear from the function signature:

HRESULT SetStreamSourceFreq(  UINT StreamNumber,  UINT FrequencyParameter);

and the fact that it selects the vertex from each stream using:

stream.vertex = index.loop / stream.freq

its just that the Index Frequency can only be used with Stream 0

DXDOCS "Note that D3DSTREAMSOURCE_INDEXEDDATA and the number of instances to draw must always be set in stream zero."

what DX9 seems to be missing is the ability to repeat the vertex buffer of
an instanced stream when it reaches the end

if it could do that multiple instancing would be a snap

eg. triangle * particles * explosions
or billboard * puffs * clouds

and I could render my whole game in 10 draw calls!
I think that the SetStreamSourceFreq function is misleading. I think it's just meant to set which streams are the per instance vertices and which are the instance data. Though the parameters suggest a lot more possible complexity, I don't think that's meant to work in practice, which is why D3D10 simplified the interface. The results you get are interesting, though, and suggest that things might work beyond the simple case. Are these results with the reference device? And what parameters did you use for the calls?
Index(0, particles * instances)
Instance(1, particles)
Instance(2, 1)

gives [2080] Direct3D9: (ERROR) :Stream 2 size is too small

because it refuses! to loop the vertices in Stream 2

in release mode it reads from memory outside of the vertex buffer

to use multiple streams without error you can do this:

Index(0, particles * instances)
Instance(1, particles)
Instance(2, instances)

which will give something like this:

0 0 0
1 0 0
2 0 0
0 0 0
1 0 1
2 0 1
0 1 1
1 1 1
2 1 2
0 1 2
1 1 2
2 1 2

which must be useful to somebody

instead I am creating my own multiple instancing system
using a single monotonic vertex buffer
and vertex texture fetch in combination with some modulo
arithmetic

this has the advantage of working for PointLists and on XBOX also
plus the same vertex buffer can be re-used across many models
and particle systems so the memory expense is mitigated

This topic is closed to new replies.

Advertisement