Sign in to follow this  
Endemoniada

Instancing Multiple Objects

Recommended Posts

Hi guys, I followed this [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb173349%28v=vs.85%29.aspx"]Efficiently Drawing Multiple Instances of Geometry[/url] article and got eveything working smoothly. I'm hoping my geometry buffer can contain multiple objects but I can't figure out how to do that.

I put two objects in my geometry buffer and can render either one but not both:

[code]
...
d3dDevice->SetStreamSourceFreq(0,(D3DSTREAMSOURCE_INDEXEDDATA|instanceCount));
...

// this draws the squares
d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,6,0,2);

// this draws the triangles
d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,6,6,3,0,1);
[/code]

It renders instanceCount squares but not the triangles, if I comment out the draw squares line it will render instanceCount triangles. I can't get it to render both the squares and the triangles, I'll also want to render a different count of each object.

I'm trying to avoid making a vertex buffer for each and every object.

Thanks for helping.

Share this post


Link to post
Share on other sites
Try setting the second argument in the second draw call to 0. That specific parameter is used if your index list and vertex list are not aligned how you need them to be when making the draw call if that makes sense.

Otherwise, I'm not sure exactly if this is the way it is or not, but it looks like its possible that your not resetting the data input stream before you call the second draw function. So what i mean is that as it is now, i think its the second draw call is starting where the first call left off. You could try to set the second and third arguments in the second call to 0, or you could just try to re-set the data input stream

Share this post


Link to post
Share on other sites
@Endemoniada: Interesting idea. Never thought of using subsets this way. Maybe I experiment on this when I have some time this weekend.

The different count can only be achieved through resetting instanceCount in your first stream. Still needs two draw calls IMHO.

For mixing geometry and using [i]one[/i] draw call only ? Hmmmm. Off the top of my head: How about tagging your instance data with a index to select the geometry and nullify the other one by scaling it to 0 in the vertex shader (look into bone indices and think of a zero bone matrix to get an idea). But whether this is worth the pain is a question of your setup and only profiling will tell. Why you wanna do this anyway ? Only for performance ? Or does e.g. draw order matter ?

@iedoc: Sorry, I can't quite follow, but it's late and likely just me. I thought the draw call defines everything that is needed (meaning: is independant of the previous draw calls). But yeah, since you experience an unexpected behaviour, try what he suggests and report back.

Slightly off topic: Jeez, that MSDN entry is strange, fortunately there's a community entry pointing out the problem. Never occurred to me. Doc rot ?

Share this post


Link to post
Share on other sites
Hey guys, thanks for trying to help.

I don't mind having a draw call for each object, I don't think there is a way around that. I'm trying to have a single geometry buffer and not separate ones for each and every object.

iedoc, I tried what you suggested and unfortunately it didn't work.

When you guys say reset the stream do you mean call SetStreamSourceFreq() again ? I tried that too.

It's a good thing I found that MSDN page because I never would have figured out that the vertex declarations need to be combined.

I'll keep working on this.

Share this post


Link to post
Share on other sites
Your right unbird, that was my bad, I guess I thought it was worth a suggestion, but I haven't used direct3d 9 for a while, and his problem made me think its possible the draw calls are not independent of each other... hehe

Endemoniada, just another suggestion, try doing this instead:

[color=#1C2837][font=CourierNew, monospace][size=2][color=#000000]d3dDevice[/color][color=#666600]->[/color][color=#660066]SetStreamSourceFreq[/color][color=#666600]([/color][color=#006666]0[/color][color=#666600],([/color][color=#000000]D3DSTREAMSOURCE_INDEXEDDATA[/color][color=#666600]|[/color][color=#000000]2[/color][color=#666600]));[/color][/size][/font][/color]
[color=#1C2837][font=CourierNew, monospace][size=2][color=#666600]
[/color][/size][/font][/color]
[color=#1C2837][size=2][color=#666600][font="Arial"]Otherwise, could you post more of the code thats relevant? Like where you set your stream source and stuff like that[/font][/color][/size][/color]

Share this post


Link to post
Share on other sites
@Endemoniada: Ok, misread your intention and obviously went too far :-).

Now I remember: The parameters of DrawIndexedPrimitive are a bit tricky, you definitively want to look into [url="http://msdn.microsoft.com/en-us/library/bb147325(v=VS.85).aspx"]this[/url]. I think you rather want to play around with the StartIndex parameter (and PrimitiveCount, of course).

@iedoc: That's what I meant. If you want to draw just two instances, that's the call you need.

But I agree: To make the discussion easier show us your buffer contents and some code.

Share this post


Link to post
Share on other sites
Hi, I tried a lot of things and the second set of objects still isn't being drawn. Here is more code:

[code]

// the geometryBuffer has 9 vertices which define two objects (6 for objectA and 3 for objectB)
// to keep it simple the indexBuffer also has 9 vertices, corresponding 1:1 with the geometryBuffer

int instanceCount=4;

d3dDevice->SetStreamSourceFreq(0,(D3DSTREAMSOURCE_INDEXEDDATA|instanceCount));
d3dDevice->SetStreamSource(0,geometryBuffer,0,sizeof(Vertex));

d3dDevice->SetStreamSourceFreq(1,(D3DSTREAMSOURCE_INSTANCEDATA|1));
d3dDevice->SetStreamSource(1,instanceBuffer,0,sizeof(Instance));

// draw 4 instances of objectA

effect->Begin(&numPasses,0);
effect->BeginPass(0);

d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,6,0,2);

effect->EndPass();
effect->End();


// draw 4 instances of objectB - doesn't draw anything
// this will draw correctly if above DrawIndexedPrimitive() is commented out

// reseting doesn't help

// d3dDevice->SetStreamSourceFreq(0,(D3DSTREAMSOURCE_INDEXEDDATA|instanceCount));
// d3dDevice->SetStreamSource(0,geometryBuffer,0,sizeof(Vertex));

// d3dDevice->SetStreamSourceFreq(1,(D3DSTREAMSOURCE_INSTANCEDATA|1));
// d3dDevice->SetStreamSource(1,instanceBuffer,0,sizeof(Instance));

effect->Begin(&numPasses,0);
effect->BeginPass(0);

d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,3,6,1);

effect->EndPass();
effect->End();


d3dDevice->SetStreamSourceFreq(0,1);
d3dDevice->SetStreamSourceFreq(1,1);

[/code]

It seems like it has to be reset to draw a new set of objects but that doesn't help (if I'm resetting it properly). I think it can be done somehow but maybe not ?

Thanks for helping.

Share this post


Link to post
Share on other sites
Hidden
I'm just going to throw out another suggestion, what do you have "instanceCount" set to? Try setting it to the number of triangles to draw instead of the number of objects like i thought in my last post

So:

[font="CourierNew, monospace"][size="2"][color="#000000"]d3dDevice[/color][color="#666600"]->[/color][color="#660066"]SetStreamSourceFreq[/color][color="#666600"]([/color][color="#006666"]0[/color][color="#666600"],([/color][color="#000000"]D3DSTREAMSOURCE_INDEXEDDATA[/color][color="#666600"]|[/color]3[color="#666600"]));[/color][/size][/font]
[font="CourierNew, monospace"] [/font]
[font="CourierNew, monospace"][size="2"][color="#666600"]3 because 2 for the square, and 1 for the triangle[/color][/size][/font]
[font="CourierNew, monospace"][size="2"] [/size][/font]
[font="CourierNew, monospace"][size="2"][color="#666600"]Wait... My bad, I need to look at this again[/color][/size][/font]

Share this post


Link to post
I was reading through that article since i didn't before. This instancing technique would be really useful for something such as a forest of trees.

Anyways, one thing I noticed is they only seem to make one draw call per instance group or whatever you want to call it. Try this: (Probably wrong, but worth i try i suppose)

[color="#1C2837"][size="2"][color="#880000"]// the geometryBuffer has 9 vertices which define two objects (6 for objectA and 3 for objectB)[/color] [/size][/color]
[color="#1C2837"][size="2"][color="#880000"]// to keep it simple the indexBuffer also has 9 vertices, corresponding 1:1 with the geometryBuffer[/color][/size][/color]
[color="#1C2837"] [/color]
[color="#1C2837"][size="2"] [color="#000088"]int[/color][color="#000000"] instanceCount[/color][color="#666600"]=[/color][color="#006666"]4[/color][color="#666600"];[/color][color="#000000"]

d3dDevice[/color][color="#666600"]->[/color][color="#660066"]SetStreamSourceFreq[/color][color="#666600"]([/color][color="#006666"]0[/color][color="#666600"],([/color][color="#000000"]D3DSTREAMSOURCE_INDEXEDDATA[/color][color="#666600"]|[/color][color="#000000"]instanceCount[/color][color="#666600"]));[/color][color="#000000"]
d3dDevice[/color][color="#666600"]->[/color][color="#660066"]SetStreamSource[/color][color="#666600"]([/color][color="#006666"]0[/color][color="#666600"],[/color][color="#000000"]geometryBuffer[/color][color="#666600"],[/color][color="#006666"]0[/color][color="#666600"],[/color][color="#000088"]sizeof[/color][color="#666600"]([/color][color="#660066"]Vertex[/color][color="#666600"]));[/color][color="#000000"]

d3dDevice[/color][color="#666600"]->[/color][color="#660066"]SetStreamSourceFreq[/color][color="#666600"]([/color][color="#006666"]1[/color][color="#666600"],([/color][color="#000000"]D3DSTREAMSOURCE_INSTANCEDATA[/color][color="#666600"]|[/color][color="#006666"]1[/color][color="#666600"]));[/color][color="#000000"]
d3dDevice[/color][color="#666600"]->[/color][color="#660066"]SetStreamSource[/color][color="#666600"]([/color][color="#006666"]1[/color][color="#666600"],[/color][color="#000000"]instanceBuffer[/color][color="#666600"],[/color][color="#006666"]0[/color][color="#666600"],[/color][color="#000088"]sizeof[/color][color="#666600"]([/color][color="#660066"]Instance[/color][color="#666600"]));[/color] [color="#880000"]// draw 4 instances of objectA[/color][color="#000000"]

effect[/color][color="#666600"]->[/color][color="#660066"]Begin[/color][color="#666600"](&[/color][color="#000000"]numPasses[/color][color="#666600"],[/color][color="#006666"]0[/color][color="#666600"]);[/color][color="#000000"]
effect[/color][color="#666600"]->[/color][color="#660066"]BeginPass[/color][color="#666600"]([/color][color="#006666"]0[/color][color="#666600"]);[/color][color="#000000"]

d3dDevice[/color][color="#666600"]->[/color][color="#660066"]DrawIndexedPrimitive[/color][color="#666600"]([/color][color="#000000"]D3DPT_TRIANGLELIST[/color][color="#666600"],[/color][color="#006666"]0[/color][color="#666600"],[/color][color="#006666"]0[/color][color="#666600"],[/color][color="#006666"]6[/color][color="#666600"],[/color][color="#006666"]0[/color][color="#666600"],[/color][color="#006666"]2[/color][color="#666600"]);[/color][color="#000000"]

effect[/color][color="#666600"]->[/color][color="#660066"]EndPass[/color][color="#666600"]();[/color][color="#000000"]
effect[/color][color="#666600"]->[/color][color="#660066"]End[/color][color="#666600"]();[/color][color="#000000"]

[color="#000000"][color="#1C2837"]d3dDevice[/color][/color][color="#666600"][color="#1C2837"]->[/color][/color][color="#660066"][color="#1C2837"]SetStreamSourceFreq[/color][/color][color="#666600"][color="#1C2837"]([/color][/color][color="#006666"][color="#1C2837"]0[/color][/color][color="#666600"][color="#1C2837"],[/color][/color][color="#006666"][color="#1C2837"]1[/color][/color][color="#666600"][color="#1C2837"]);[/color][/color][color="#000000"][color="#1C2837"]
d3dDevice[/color][/color][color="#666600"][color="#1C2837"]->[/color][/color][color="#660066"][color="#1C2837"]SetStreamSourceFreq[/color][/color][color="#666600"][color="#1C2837"]([/color][/color][color="#006666"][color="#1C2837"]1[/color][/color][color="#666600"][color="#1C2837"],[/color][/color][color="#006666"][color="#1C2837"]1[/color][/color][color="#666600"][color="#1C2837"]);[/color][/color]

[/color][color="#880000"]// draw 4 instances of objectB - doesn't draw anything[/color][/size][/color]
[color="#1C2837"][size="2"] [color="#880000"]// this will draw correctly if above DrawIndexedPrimitive() is commented out[/color][/size][/color]
[color="#1C2837"] [/color]
[color="#1C2837"][size="2"][color="#880000"]// reseting doesn't help[/color][/size][/color]
[color="#1C2837"] [/color]
[color="#1C2837"][size="2"] [color="#880000"]// d3dDevice->SetStreamSourceFreq(0,(D3DSTREAMSOURCE_INDEXEDDATA|instanceCount));[/color][/size][/color]
[color="#1C2837"][size="2"] [color="#880000"]// d3dDevice->SetStreamSource(0,geometryBuffer,0,sizeof(Vertex));[/color][/size][/color]
[color="#1C2837"] [/color]
[color="#1C2837"][size="2"] [color="#880000"]// d3dDevice->SetStreamSourceFreq(1,(D3DSTREAMSOURCE_INSTANCEDATA|1));[/color][/size][/color]
[color="#1C2837"][size="2"] [color="#880000"]// d3dDevice->SetStreamSource(1,instanceBuffer,0,sizeof(Instance));[/color][color="#000000"]

[color="#1C2837"][color="#000000"]d3dDevice[/color][color="#666600"]->[/color][color="#660066"]SetStreamSourceFreq[/color][color="#666600"]([/color][color="#006666"]0[/color][color="#666600"],([/color][color="#000000"]D3DSTREAMSOURCE_INDEXEDDATA[/color][color="#666600"]|[/color][color="#000000"]instanceCount[/color][color="#666600"]));[/color][color="#000000"]
d3dDevice[/color][color="#666600"]->[/color][color="#660066"]SetStreamSource[/color][color="#666600"]([/color][color="#006666"]0[/color][color="#666600"],[/color][color="#000000"]geometryBuffer[/color][color="#666600"],[/color][color="#006666"]0[/color][color="#666600"],[/color][color="#000088"]sizeof[/color][color="#666600"]([/color][color="#660066"]Vertex[/color][color="#666600"]));[/color][color="#000000"]

d3dDevice[/color][color="#666600"]->[/color][color="#660066"]SetStreamSourceFreq[/color][color="#666600"]([/color][color="#006666"]1[/color][color="#666600"],([/color][color="#000000"]D3DSTREAMSOURCE_INSTANCEDATA[/color][color="#666600"]|[/color][color="#006666"]1[/color][color="#666600"]));[/color][color="#000000"]
d3dDevice[/color][color="#666600"]->[/color][color="#660066"]SetStreamSource[/color][color="#666600"]([/color][color="#006666"]1[/color][color="#666600"],[/color][color="#000000"]instanceBuffer[/color][color="#666600"],[/color][color="#006666"]0[/color][color="#666600"],[/color][color="#000088"]sizeof[/color][color="#666600"]([/color][color="#660066"]Instance[/color][color="#666600"]));[/color][/color][/color][/size][/color]
[size="2"][color="#666600"]
[/color][/size][size="2"] [color="#1c2837"]effect[/color][color="#666600"][color="#1C2837"]->[/color][/color][color="#660066"][color="#1C2837"]Begin[/color][/color][color="#666600"][color="#1C2837"](&[/color][/color][color="#000000"][color="#1C2837"]numPasses[/color][/color][color="#666600"][color="#1C2837"],[/color][/color][color="#006666"][color="#1C2837"]0[/color][/color][color="#666600"][color="#1C2837"]);[/color][/color][color="#000000"][color="#1C2837"]
effect[/color][/color][color="#666600"][color="#1C2837"]->[/color][/color][color="#660066"][color="#1C2837"]BeginPass[/color][/color][color="#666600"][color="#1C2837"]([/color][/color][color="#006666"][color="#1C2837"]0[/color][/color][color="#666600"][color="#1C2837"]);[/color][/color][color="#000000"][color="#1C2837"]

d3dDevice[/color][/color][color="#666600"][color="#1C2837"]->[/color][/color][color="#660066"][color="#1C2837"]DrawIndexedPrimitive[/color][/color][color="#666600"][color="#1C2837"]([/color][/color][color="#000000"][color="#1C2837"]D3DPT_TRIANGLELIST[/color][/color][color="#666600"][color="#1C2837"],[/color][/color][color="#006666"][color="#1C2837"]0[/color][/color][color="#666600"][color="#1C2837"],[/color][/color][color="#006666"][color="#1C2837"]0[/color][/color][color="#666600"][color="#1C2837"],[/color][/color][color="#006666"][color="#1C2837"]3[/color][/color][color="#666600"][color="#1C2837"],[/color][/color][color="#006666"][color="#1C2837"]6[/color][/color][color="#666600"][color="#1C2837"],[/color][/color][color="#006666"][color="#1C2837"]1[/color][/color][color="#666600"][color="#1C2837"]);[/color][/color][color="#000000"][color="#1C2837"]

effect[/color][/color][color="#666600"][color="#1C2837"]->[/color][/color][color="#660066"][color="#1C2837"]EndPass[/color][/color][color="#666600"][color="#1C2837"]();[/color][/color][color="#000000"][color="#1C2837"]
effect[/color][/color][color="#666600"][color="#1C2837"]->[/color][/color][color="#660066"][color="#1C2837"]End[/color][/color][color="#666600"][color="#1C2837"]();[/color][/color][color="#000000"][color="#1C2837"]


d3dDevice[/color][/color][color="#666600"][color="#1C2837"]->[/color][/color][color="#660066"][color="#1C2837"]SetStreamSourceFreq[/color][/color][color="#666600"][color="#1C2837"]([/color][/color][color="#006666"][color="#1C2837"]0[/color][/color][color="#666600"][color="#1C2837"],[/color][/color][color="#006666"][color="#1C2837"]1[/color][/color][color="#666600"][color="#1C2837"]);[/color][/color][color="#000000"][color="#1C2837"]
d3dDevice[/color][/color][color="#666600"][color="#1C2837"]->[/color][/color][color="#660066"][color="#1C2837"]SetStreamSourceFreq[/color][/color][color="#666600"][color="#1C2837"]([/color][/color][color="#006666"][color="#1C2837"]1[/color][/color][color="#666600"][color="#1C2837"],[/color][/color][color="#006666"][color="#1C2837"]1[/color][/color][color="#666600"][color="#1C2837"]);[/color][/color][/size]
[size="2"][color="#666600"] [/color][/size]
[size="2"][color="#666600"] [/color][/size]
[size="2"][color="#1c2837"](I'm so sick of trying to add code on gamedev, I can't get the formatting to work at all, spend more time playing with the code and source tags than I do trying to answer the actual problem)[/color][/size] Edited by iedoc

Share this post


Link to post
Share on other sites
Ok, guys (and girls), long post ahead. I experimented and that's what I got. First my setup - I don't duplicate vertices, because, well, that's what indexing is all about ;-)

Vertex buffer:
[code]
0: {X:-0.5, Y:-0.5} quad vertices
1: {X:-0.5, Y: 0.5}
2: {X: 0.5, Y: 0.5}
3: {X: 0.5, Y:-0.5}
4: {X: 0 , Y: 0.7} "the" triangle vertices
5: {X: 0.7, Y:-0.7}
6: {X:-0.7, Y:-0.7}
[/code]

Index Buffer:
[code]
0: 0 quads 1st triangle
1: 1
2: 2
3: 2 quads 2nd triangle
4: 3
5: 0
6: 4 "the" triangles triangle
7: 5
8: 6
[/code]

Position offsets and color come from the instance stream, but I will concentrate on the geometry now:

First, drawing all geometry. Not your intention, just to check if the overall setup is fine.
Ignore that this is C#/SlimDX code, the parameters are the same:
[code]
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 7, 0, 3);
[/code]
[URL=http://www.imagebam.com/image/4f1f4b152086146][IMG]http://thumbnails51.imagebam.com/15209/4f1f4b152086146.gif[/IMG][/URL]

Drawing just the quads:
[code]
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 4, 0, 2); // (A)
[/code]
[URL=http://www.imagebam.com/image/8a3bd7152086148][IMG]http://thumbnails42.imagebam.com/15209/8a3bd7152086148.gif[/IMG][/URL]

Drawing just the triangles:
[code]
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 4, 3, 6, 1); // (B)
[/code]
[URL=http://www.imagebam.com/image/4492cf152086151][IMG]http://thumbnails36.imagebam.com/15209/4492cf152086151.gif[/IMG][/URL]

To elaborate:
In (A) we don't need more than the first four vertices, NumVertices = 4 instead of 7.
In (B) we select a subset for "the" triangle, namely vertcies 4,5,6 (so MinIndex = 4 and NumVertices = 3), the StartIndex is now 6.

An alternative I've found is this:
[code]
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 4, 0, 3, 6, 1);
[/code]

BUT then the indices for "the" triangle have to be
[code]
...
6: 0
7: 1
8: 2
[/code]
... since a BaseVertexIndex of 4 offsets them by 4.

You can also select all vertices:
[code]
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 7, 6, 1);
[/code]

On my system, I can even do a:
[code]
device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 0, 6, 1);
[/code]

I don't even get a fail. The driver obviously ignores the vertex range altogether. But neither do PIX (index out of range) nor the reference device (nothing gets drawn). Also the debug runtimes should complain if fully enabled.

("Should", because I currently have yet to discover why they sometimes don't. I just recently switched to Win7 and VS 2010 Express. Sometimes they show up in the VS output, sometimes in DebugView (using C#/SlimDX), but mostly they don't, even if I start my app NOT from VS. As said, dunno why yet, so PIX is my reference here).

Conclusion: It is possible - and I would have been surprised if it wasn't: as if we were the first to get instanced subsets on a 10-year-old API ;-)

For why you get your behavior on the other hand I can still only guess: I don't see you check the result codes, so maybe the device is in some erroneous state after the first (failing) call which lets your second call fail. Do check them, enable full debug runtimes, run it through PIX, use the reference device... and then get the numbers right ;-)

And, yeah, you don't need to reset the streams or the frequencies (I didn't in my setup).

You could try - if you haven't already - this:

[code]
d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,0,9,6,1); // full range
[/code]

or

[code]
d3dDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST,0,6,3,6,1); // subrange
[/code]

if I got your numbers right. If you still can't figure out on your own, attach a minimal project and I'll take a look.

@iedoc: Using the "rich" editor ? Oh yeah, it's really bad. I disabled it pretty soon (can be done in your profile settings) and used tags again.

Share this post


Link to post
Share on other sites
[quote name='unbird' timestamp='1317592990' post='4868404']
I don't even get a fail. The driver obviously ignores the vertex range altogether. But neither do PIX (index out of range) nor the reference device (nothing gets drawn). Also the debug runtimes should complain if fully enabled.
[/quote]

I can answer this one. You're most likely using a Hardware T&L device; switch to software vertex processing and you should see it kicking and screaming quite nicely there too (it may even crash, lock up your machine - unlikely with WDDM but beware on XP machines - or do other exciting things). Hardware T&L seems much more forgiving of bad params to your DIP call (this may be restricted to certain drivers).

I've used this technique quite successfully in the past, and it does work very well, but - as was said above - the params can be quite tricksy to get correct. Brain's too fried at the moment to set up some test code, but I may get round to it tomorrow.

Share this post


Link to post
Share on other sites
Hi unbird, I had been doing something idiotic. My triangle and squares were totally opaque so the squares were covering the triangles, they were being drawn the whole time. I would have thought it was something else if I didn't see your screen shots, so you definitely solved my problem.

In between my draw calls I added this:

d3dDevice->SetStreamSource(1,instanceBuffer,sizeof(Instance)*instanceCount,sizeof(Instance));

...notice the third parameter. This way I can have a single instance buffer as well as a single geometry buffer.

I wonder if there is a way around that SetStreamSource() call or if it's even worth trying to get around it. I have about 20 different objects so I don't think 20 calls will slow anything down.

I really appreciate the time and effort you put into this.

Share this post


Link to post
Share on other sites
You're welcome. Yeah, looking for a bug in the wrong place is pretty frustrating.

[quote name='Endemoniada' timestamp='1317673417' post='4868690']
d3dDevice->SetStreamSource(1,instanceBuffer,sizeof(Instance)*instanceCount,sizeof(Instance));

...notice the third parameter. This way I can have a single instance buffer as well as a single geometry buffer.
[/quote]

Interesting: I was about to put that as a third possibility to select a subset - in the geometry stream of course. I haven't checked and I did not want to add further confusion.
Just so you know: This stream offset needs a cap bit : [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb172537(v=vs.85).aspx"]D3DDEVCAPS2_STREAMOFFSET[/url]. But using instancing - which needs SM 3 anyway - this will hardly pose a problem (a quick check on the cap dumps I have lying around here shows this cap is even set for a FFP only hardware).

Thanks to you too: Maybe I gonna "steal" this idea some day :)

Share this post


Link to post
Share on other sites
Just so you know, the only devices I've seen that don't report support for stream offset are older Intel integrated thingies, and even then they do actually support it. The caps bit seems to be only for hardware VP, but these run software VP and so the caps bit doesn't actually seem to apply.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this