stream output to vertex buffer (not working as it should)

Started by
13 comments, last by lomateron 12 years, 2 months ago
i cant still get it working as it should, i did this in the .cpp file, first the layout:

D3D10_INPUT_ELEMENT_DESC vertexDesc[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
{"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
{ "VEL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 28, D3D10_INPUT_PER_VERTEX_DATA, 0 },
{ "MA", 0, DXGI_FORMAT_R32_FLOAT, 0, 40, D3D10_INPUT_PER_VERTEX_DATA, 0 },
};
UINT numElements = sizeof( vertexDesc) / sizeof( vertexDesc[0] );

D3D10_PASS_DESC PassDesc;
g_pTechnique->GetPassByIndex(0)->GetDesc(&PassDesc);
hr = g_pd3dDevice->CreateInputLayout(vertexDesc, numElements,PassDesc.pIAInputSignature, PassDesc.IAInputSignatureSize,&g_pVertexLayout);
if( FAILED( hr ) )
return hr;
g_pd3dDevice->IASetInputLayout(g_pVertexLayout);


now the buffer: i have 2 buffers one with the original vertex data and another where the modified vertex buffer is gonna be
SimpleVertex vertices2[] =
{
{ D3DXVECTOR3( 0.0f, 1.0f, 0.0f ), D3DXCOLOR( 0.0f, 0.0f, 1.0f, 1.0f ), D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),float(1.0f)},
{ D3DXVECTOR3( 1.0f, 0.0f, 0.0f ), D3DXCOLOR( 0.0f, 1.0f, 0.0f, 1.0f ), D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),float(1.0f)},
{ D3DXVECTOR3( 0.0f, 0.0f, -1.0f ), D3DXCOLOR( 0.0f, 1.0f, 1.0f, 1.0f ), D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),float(1.0f)},
{ D3DXVECTOR3( 0.0f, 0.0f, 0.0f ), D3DXCOLOR( 1.0f, 0.0f, 0.0f, 1.0f ), D3DXVECTOR3( 0.0f, 0.0f, 0.0f ),float(1.0f)},
};
bd.Usage = D3D10_USAGE_DEFAULT;
bd.ByteWidth = sizeof( SimpleVertex ) * 4;
bd.BindFlags = D3D10_BIND_VERTEX_BUFFER | D3D10_BIND_STREAM_OUTPUT;
bd.CPUAccessFlags = 0;
bd.MiscFlags = 0;
initData.pSysMem = vertices2;
hr = g_pd3dDevice->CreateBuffer( &bd, &initData, &g_pVertexBuffer2 );//first buffer where the original info is
if( FAILED( hr ) )
return hr;
hr = g_pd3dDevice->CreateBuffer( &bd, 0, &g_pVertexBuffer3 );//second buffer where the info form the first is gona be after modified
if( FAILED( hr ) )
return hr;


and now this is how i render it, i change the buffers each frame ping pong metod

if(g)
{
g_pd3dDevice->SOSetTargets(1, &g_pVertexBuffer3 , &offset);
g_pd3dDevice->IASetVertexBuffers(0, 1, &g_pVertexBuffer2, &stride, &offset);
g=false;
}
else
{
g_pd3dDevice->SOSetTargets(1, &g_pVertexBuffer2 , &offset);
g_pd3dDevice->IASetVertexBuffers(0, 1, &g_pVertexBuffer3, &stride, &offset);
g=true;
}
g_pd3dDevice->IASetIndexBuffer( g_pIndexBuffer2, DXGI_FORMAT_R32_UINT, 0 );
g_pWorldVariable->SetMatrix( ( float* )&g_World2 );
g_pTechnique2->GetPassByIndex( 0 )->Apply( 0 );
g_pd3dDevice->DrawIndexed( 12, 0, 0 );
g_pSwapChain->Present( 0, 0 );


the .fx is like this, there are no errors any more, the vertex shader only returns the same position, the tetrahedron never moves.

struct VS_INPUT
{
float4 Pos : POSITION;
float4 Color : COLOR;
float3 Vel : VEL;
float Ma : MA;
};
struct VS_INPUTT
{
float4 Pos : SV_POSITION;
float4 Color : COLOR;
float3 Vel : VEL;
float Ma : MA;
};
VS_INPUTT VS2( VS_INPUT input )
{
VS_INPUTT output = (VS_INPUTT)0;
output.Pos = mul( input.Pos, World );
output.Pos = mul( output.Pos, View );
output.Pos = mul( output.Pos, Projection );
output.Color = input.Color;
output.Vel.x = input.Vel.x+(Time*Force.x);
output.Vel.y = input.Vel.y+(Time*Force.y);
output.Vel.z = input.Vel.z+(Time*Force.z);
output.Ma = input.Ma;
return output;
}


and at the end of the .fx file is this

VertexShader vss = CompileShader( vs_4_0, VS2() );
GeometryShader gss= ConstructGSWithSO( vss, "SV_POSITION.xyz; COLOR.xyzw; VEL.xyz; MA.x" );
technique10 Pa
{
pass P0
{
SetVertexShader( vss );
SetGeometryShader( gss );
SetPixelShader( CompileShader( ps_4_0, PS2() ) );
}
}


what happens is that there is no error anywere,but it works rare, the first frame i render it renders ok, the tetrahedron is in its place, then the second frame some vertex of the tetrahedron are in its place and the others are like very far away up, and then in the next frame it disapears.
Advertisement
plz help me i want to know why my tetrahedron is disappearing, this is getting me into a big stuck depressing hole, i have been reading and using now a geometry shader were my tetrahedron will still be in its place but the same happens, it disappears.
Hi!

You transform your positions each frame over and over again with the transformation matrices. Points closer to the origin will stay a few iterations longer but eventually all your vertices will fly away. smile.png

So, modify a little the output of your vertex shader.
Output both the clipping space position and the world position. Write the world position back into the stream output and pass the clipping space position to the rasterizer only.

struct VS_OUTPUTT
{
float4 Pos : WORLDPOS; // position in world space (for the stream output)
float4 ClipPos : SV_POSITION; // position in clipping space (for the rasterizer)
float4 Color : COLOR;
float3 Vel : VEL;
float Ma : MA;
};

VS_OUTPUTT VS2( VS_INPUT input )
{
VS_OUTPUTT output = (VS_OUTPUTT)0;
output.Pos = input.Pos; // bypass the geometry (or deform somehow with your velocity)

// better pass in your geometry in world space!
// output.ClipPos = mul( input.Pos, World );
output.ClipPos = mul( output.Pos, View );
output.ClipPos = mul( output.ClipPos, Projection );
output.Color = input.Color;
output.Vel.x = input.Vel.x+(Time*Force.x);
output.Vel.y = input.Vel.y+(Time*Force.y);
output.Vel.z = input.Vel.z+(Time*Force.z);
output.Ma = input.Ma;
return output;
}

// Tell the geometry shader to output the world space position.
GeometryShader gss= ConstructGSWithSO( vss, "WORLDPOS.xyz; COLOR.xyzw; VEL.xyz; MA.x" );


Hope that helps! smile.png
Cheers!
hoo man this things that i dot see are insane, thank you i like will always need another person to tell me something because i become blind with my own mistakes.
hey master is my SOSetTargets()metod ok because now my problem is that the last vertex in my vertex structure isn't changing of place, color, etc, any attribute is changing
Only the last vertex causes trouble? So the first three vertices behave as they should?
That sounds to me like the number of vertices/primitives in the draw call, the input assembler or stream output setup doesn’t fit. Though, both your SOSetTarget and IASetVertexBuffer look fine, if your offset=0 and the stride=44=sizeof(SimpleVertex). 12 indices for a tet sounds reasonable, too. The primitive topology is a triangle list, I guess?

Do you unbind the vertex buffers from the input assembler and the stream output after rendering?
ID3D11Buffer* noVB[] = {NULL};
UINT noOffset[] = {0};
UINT noStride[] = {0};
g_pd3dDevice->SOSetTargets(1, noVB, noOffset);
g_pd3dDevice->IASetVertexBuffers(0, 1, noVB, noStride, noOffset);

Otherwise D3D could complain (only with warnings in d3d debug mode) in the next rendering loop, when you bind your vertex buffer to the stream output stage that the vertex buffer is still but as input at the input assembler.

Could you please paste an updated version of the input assembler setup, the shader and the creation of your vertex and index buffer, here?
Or maybe just attach the program, so that I or someone else can do a debug run. A PIX dump would work for me too.
here it is all the projects
https://rapidshare.com/files/1943985478/yea.rar

Run it and you can control the camera with the movement of the mouse, the camera is pointing up by default so move the mouse all the way down and you will see the tetrahedron moving just in one direction for simplicity, you can use your "W"S"A"D" to move the camera too.
Hi!

It seems to be a problem with the index buffer.
Your tet transforms just fine if you duplicate your vertices in the vertex buffer.

When using the index buffer, in PIX the buffer at the stream output stage is totally messed up, and if rendered with another topology but pointlists PIX crashes, when I try to look at the mesh.

If you don’t like duplicating your vertices here is an alternative: Usually I have a first pass in which I invoke one vertex shader / geometry shader per vertex by rendering the whole geometry as a pointlist. Thereby I stream the data out to another buffer and disable the rasterizer. Afterwards I render in a second pass the updated vertex buffer in combination with some index buffer to actually create geometry with topology.
:( .... thats bad news but... thanks!, do you know any complete example were they do the stream output and render? i really wana do it this way.. its faster no?
but how can the index buffer be a problem, is there something similar between the index buffer and the buffer used for stream output? i mean, do one interfere with the other in something?

This topic is closed to new replies.

Advertisement