Sign in to follow this  
ozkill

problem of Vertex Buffer Declarations for Mesh instancing at DX9

Recommended Posts

ozkill    107
hi gentleman :-) at first, sorry to my bad english. I have a dilemma by improving my H/W instancing. help me plz.... I have a success of Mesh instancing as "Instancing " in DX sample (March 2009) but, I have a problem of Mesh instancing as "Efficiently Drawing Multiple Instances of Geometry (Direct3D 9)" in DX helper document. http://msdn.microsoft.com/en-us/library/ee418549%28VS.85%29.aspx Both method are not perfect exactly the same. Vertex Declaration is different. "Instancing " in DX sample (March 2009) - define one declaration variable. and split inside by stream. D3DVERTEXELEMENT9 g_VertexElemHardware[] = { { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, { 0, 3 * 4, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 }, { 0, 6 * 4, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 }, { 1, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 }, { 1, 4 * 4, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 2 }, D3DDECL_END() }; - And set Declaration this(g_VertexElemHardware) to Device - I imitate this way. It run well. "Efficiently Drawing Multiple Instances of Geometry (Direct3D 9)" in DX helper document - define two declaration variables. const D3DVERTEXELEMENT9 g_VBDecl_Geometry[] = { {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0}, {0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0}, {0, 24, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0}, {0, 36, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0}, {0, 48, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0}, D3DDECL_END() }; const D3DVERTEXELEMENT9 g_VBDecl_InstanceData[] = { {1, 0, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1}, {1, 16, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 2}, {1, 32, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 3}, {1, 48, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 4}, {1, 64, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0}, D3DDECL_END() }; - How set duble different Declaration to Device??? - If I set g_VBDecl_Geometry to Device use SetVertexDeclaration, then show message fllow: - "Vertex shader function usage does not have corresponding usage in the current vertex declaration" What can i do for second case? How set duble different Declaration to Device? I got a define two declaration variables split by stream. Help me ToT lol [Edited by - ozkill on March 18, 2010 11:25:04 AM]

Share this post


Link to post
Share on other sites
JohnnyCode    1046
Quote:
Original post by ozkill
- How set duble different Declaration to Device???
- If I set g_VBDecl_Geometry to Device use SetVertexDeclaration, then show message fllow:
- "Vertex shader function usage does not have corresponding usage in the current vertex declaration"

Vertexdeclaration is a class instance, you need as much instancies of this object as much different vertex formats you have and best practice is to make it a member of shader instance responsible class.

Becouse the shader is written to accept an input stream with a certain declaration.
You need to make sure that it matches the current vertex declaration set with device::SetVertexDeclaration when you render with the shader.

Best practice is to set render calls like this

Device::SetVertexDeclaration(dclsforshaderA)
Effect::Begin
Effect::BeginPass
Device::SetStreamSource
Effect::SetTexture
Effect::SetUniforms
Device::DrawIndexedPrimitive

Effect::EndPass
Effect::End

Share this post


Link to post
Share on other sites
ozkill    107
dear JohnnyCode.
Really really Thank for yor answer.
but, It is not the appropriate answer to my question.
I guess you have misunderstood my question.
My intent was not "How to use Vertexdeclaration to maching with Shader"

I knew that Vertexdeclaration and Shader Usage should match.
That is why I have doubts.

I have been using to only one Declaration pair with Shader. and I have no problem of H/W instancing use method of "Instancing " in DX sample (March 2009)
but "Efficiently Drawing Multiple Instances of Geometry (Direct3D 9)" in DX document show peculiar way.
This is link :
http://msdn.microsoft.com/en-us/library/ee418549%28VS.85%29.aspx

They make duble D3DVERTEXELEMENT9 instance. one is information of stream 0 (g_VBDecl_Geometry). and other one is information of stream 1 (g_VBDecl_InstanceData). but, For H/W Mesh instancing, Both g_VBDecl_Geometry and g_VBDecl_InstanceData is needed all at once 'cause It need stream 0 and 1.

I put stream data 0 and 1 in a D3DVERTEXELEMENT9 instance was used. It works...
But document show way use two Declaration instance. My wondering is How this possible.
How to set duble D3DVERTEXELEMENT9 instance to Device?

Does they lie to me? Please advise. plz plz plz ...

Share this post


Link to post
Share on other sites
MJP    19790
You can't set multiple declarations. That page just separated the two declarations for the purpose of demonstration. You'll have to manually combine the declarations for your vertex stream and instance data stream into a single declaration.

Share this post


Link to post
Share on other sites
ozkill    107
dear MJP.
very very thank your answer.

Is this just demonstration? Damn...
That page make me confused talk like it possible.

your says give me belife what to do.
and your post "inferred rendering" at blog is very useful to my work.
very thank. bless u :-)

[Edited by - ozkill on March 18, 2010 8:37:22 PM]

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