Sign in to follow this  
Downie

Stream Out - GeoShader

Recommended Posts

Hey I am having trouble streaming out from the GS to a vertex buffer. Is it possible to stream out and continue down the pipeline to the pixel shader? Since I converted to stream out nothing is appearing on screen. I set up 3 VB's I manually put vertex data in the first one and render as normal, from that frame on I stream out to the second buffer and render using drawauto(). Swapping the two buffers every frame. But as I say nothing appears. If anyone can be bothered trawling through my code I would be delighted. Thanks
void CWorldTerrain::CreateWorldVBO()
{
	D3D10_BUFFER_DESC BuffDesc;
	memset(&BuffDesc, 0, sizeof(BuffDesc));
	BuffDesc.Usage = D3D10_USAGE_DYNAMIC;						//Setup a dynamic vertex buffer as it will change frequently
	BuffDesc.ByteWidth = sizeof(ColourVertex) * mNumVerts;		//Allocates a contiguous block of memory to hold all vertices
	BuffDesc.BindFlags = D3D10_BIND_VERTEX_BUFFER;				//Its a vertex buffer not an index buffer
	BuffDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;			//Allow the CPU to write to the buffer and the GPU will read from it
	BuffDesc.MiscFlags = 0;

	D3D10_SUBRESOURCE_DATA ResData;
	memset(&ResData, 0, sizeof(ResData));
	ResData.pSysMem = &mVertexList[0];
	mDevice->CreateBuffer(&BuffDesc, &ResData, &mVB);			//Create the vertex buffer
}

void CWorldTerrain::CreateStreamOutBuffer()
{
	D3D10_BUFFER_DESC BD;
	BD.Usage = D3D10_USAGE_DEFAULT;
	BD.ByteWidth = sizeof(ColourVertex) * MAXVERTS;
	BD.BindFlags = D3D10_BIND_VERTEX_BUFFER | D3D10_BIND_STREAM_OUTPUT;
	BD.CPUAccessFlags = 0;
	BD.MiscFlags = 0;

	mDevice->CreateBuffer(&BD, 0, &mStreamBuff);
	mDevice->CreateBuffer(&BD, 0, &mDrawBuff);
}

I then setup all the shader handles etc, get the tech pass...then call the render function
UINT Stride = sizeof(ColourVertex);							//Set how large each chunk of vertex data is in memory, so that DX knows where one begins and ends
	UINT Offset = 0;											//NULL as we only have one type of data in the VB

	if(FirstRun)
		//Draw with pre-built vertices
		mDevice->IASetVertexBuffers(0, 1, &mVB, &Stride, &Offset);	
	else	
		//From now on use the vertices created by the GeoShader, pass these back in for recursion
		mDevice->IASetVertexBuffers(0, 1, &mDrawBuff, &Stride, &Offset);

	//Updated vertices are streamed to here
	mDevice->SOSetTargets(1, &mStreamBuff, &Offset);			

	if(FirstRun)
	{
		mDevice->Draw(mNumVerts, 0);
		FirstRun = false;
	}
	else
	{
		mDevice->DrawAuto();
	}

	ID3D10Buffer* BlankBuff = NULL;
	mDevice->SOSetTargets(1, &BlankBuff, &Offset);

	//Swap the buffers
	std::swap(mDrawBuff, mStreamBuff);

My GS code - I should add that ColourVertex contains D3DXVECTOR3 Pos, D3DXVECTOR3 Norm, D3DXVECTOR2 TexCoord.
GeometryShader gsStreamOut = ConstructGSWithSO(CompileShader(gs_4_0, GS()), "POSITION.xyz; NORMAL.xyz; TEXCOORD.xy");

Share this post


Link to post
Share on other sites
Yes, you can still render when SO is enabled. The special case is that you can 'render' to SO and NOT rasterize pixels but thats not the default case.

I was recently using SO with D3D11 which is a bit different, but I did break my code a couple of times by getting some of the input/output signatures mis-matching. It was very easy to get the output of the GS to no longer match the input of the PS thus it disables the PS and simply screams at you via the debug runtimes.

Can you check the debug runtimes? Are they telling you about bad pipeline state?

What are the contents of the SO and appropriate rendering? Is it possible that its all working ok, just that the rubbish stored in the SO buffer is causing things to be rendered off-screen or in some other invisible way?

Have you tried using PIX to investigate what actually happens? You can also set up pipeline queries to try and determine what (and how much) work was done in a frame...


hth
Jack

Share this post


Link to post
Share on other sites
Hey thanks for replying.

Quote:

I was recently using SO with D3D11 which is a bit different, but I did break my code a couple of times by getting some of the input/output signatures mis-matching. It was very easy to get the output of the GS to no longer match the input of the PS thus it disables the PS and simply screams at you via the debug runtimes.

I checked my input/output sigs and they seem to match up ok. As i said it rendered fine when I wasn't using stream out and therefore had no recursion. The input to the pixel shader hasn't changed since I added the stream out functionality.
Quote:

What are the contents of the SO and appropriate rendering? Is it possible that its all working ok, just that the rubbish stored in the SO buffer is causing things to be rendered off-screen or in some other invisible way?

I am not sure if the data in the SO buffer is rubbish; as I say the original output before stream out was fine. I am using stream out to perform recursive subdivision of a sphere.

I've never used PIX before so I'll download it and give it a try.

Thanks

Share this post


Link to post
Share on other sites
Fixed my problem thanks to PIX...was streaming too many vertices out from the GS apparently this will cause a return 0.

Thanks for the help

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