Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
14 replies to this topic

#1 lomateron   Members   -  Reputation: 363

Like
0Likes
Like

Posted 04 February 2012 - 08:54 AM

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.

Sponsor:

#2 lomateron   Members   -  Reputation: 363

Like
0Likes
Like

Posted 05 February 2012 - 08:55 PM

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.

#3 Tsus   Members   -  Reputation: 1050

Like
1Likes
Like

Posted 06 February 2012 - 06:28 AM

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. Posted Image

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! Posted Image
Cheers!

#4 lomateron   Members   -  Reputation: 363

Like
0Likes
Like

Posted 06 February 2012 - 09:41 AM

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.

#5 lomateron   Members   -  Reputation: 363

Like
0Likes
Like

Posted 06 February 2012 - 01:28 PM

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

#6 Tsus   Members   -  Reputation: 1050

Like
0Likes
Like

Posted 06 February 2012 - 04:19 PM

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.

#7 lomateron   Members   -  Reputation: 363

Like
0Likes
Like

Posted 06 February 2012 - 05:08 PM

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.

#8 Tsus   Members   -  Reputation: 1050

Like
0Likes
Like

Posted 06 February 2012 - 07:23 PM

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.

#9 lomateron   Members   -  Reputation: 363

Like
0Likes
Like

Posted 06 February 2012 - 07:57 PM

:( .... 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?

#10 lomateron   Members   -  Reputation: 363

Like
0Likes
Like

Posted 06 February 2012 - 08:23 PM

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?

#11 Tsus   Members   -  Reputation: 1050

Like
0Likes
Like

Posted 07 February 2012 - 02:33 AM

The stream output captures the triangles, not the vertices. Since the draw call emits 12 vertices and the vertex buffer bound to the stream output has only room for 4 we get an overflow. When looking at the index buffer we see that the first four vertices are: 0,1,2,0. More isn’t written. This matches with my observations with PIX. Vertex 3 became equal to vertex 0, when using pointlists.

If the index buffer would start with 0,1,2,3,… then it would be a hack, but it would be fine, except:
The stream output only writes, if the primitive fits into the available space, so the second triangle starting with 3,… would never be written, because there is no room for the remaining two vertices.
Well, but if you make your vertex buffer bigger, by extending it with two dummy vertices (which are never used for rendering and only receive two vertices from the stream output we already know), everything works as it should.

It is a little hack though. Posted Image
So adapt your index buffer to start with 0,1,2,3 and add two more vertices to your vertex buffer.

Cheers!

#12 lomateron   Members   -  Reputation: 363

Like
0Likes
Like

Posted 07 February 2012 - 10:33 AM

skills!!!
ohhhh shiii that thing was in front of my face look
http://msdn.microsoft.com/en-us/library/windows/desktop/bb509661%28v=vs.85%29.aspx

so by default it is returning the triangle stream because i am compiling the vertex shader intead of the geometry, so i have to make a geometry shader and define to return a pointStream, and because i will most likely use the geometry shader in the future, i am gona put it there, doing nothing for now.

damm i tried and now at the end rendered image is drawing points, but its working! but its drawing points hahaha. It didnt matter if i put
g_pd3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
before drawing.
So finally i am gona go for the way you told me, its working too! thanks!

#13 lomateron   Members   -  Reputation: 363

Like
-2Likes
Like

Posted 10 February 2012 - 09:34 PM

.

Edited by lomateron, 10 October 2012 - 08:45 PM.


#14 ankhd   Members   -  Reputation: 1325

Like
0Likes
Like

Posted 13 February 2012 - 03:09 AM

Damn Directx is to limited. No

I have stream out working fine using dx10 Irender a point list to a buffer of a skinned mesh then to shadows and colur render with the streamed out VB works fine.
I think there is a sample in the sdk stream out skinning or something like that.
Also try looking at you index buffer it will need to be same as the original Indexbuffer.

#15 lomateron   Members   -  Reputation: 363

Like
0Likes
Like

Posted 13 February 2012 - 06:51 PM

.

Edited by lomateron, 10 October 2012 - 08:45 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS