Jump to content

  • Log In with Google      Sign In   
  • Create Account

Geometry shader with stream output


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
6 replies to this topic

#1 _undex   Members   -  Reputation: 171

Like
0Likes
Like

Posted 16 February 2013 - 04:36 PM

Hello folks,

I tried to generate a stream output with a geometry shader.
But when I "draw" it, the window turns black.
Could someone show me some sample code on geometry shader with stream out or could someone correct my existing code?

Draw call:

 

bool GeometrySh::Render(ID3D11DeviceContext* deviceContext, int count)
{
	HRESULT result;
	D3D11_MAPPED_SUBRESOURCE mappedResource;
	unsigned int bufferNumber;
	BufferType* dataPtr;

	result = deviceContext->Map(m_cBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
	if(FAILED(result))
	{
		return false;
	}

	dataPtr = (BufferType*)mappedResource.pData;
	dataPtr->lightdir = D3DXVECTOR4(4.0f, 5.0f, 10.0f, 1.0f);
	deviceContext->Unmap(m_cBuffer, 0);

	bufferNumber = 0;

	deviceContext->GSSetConstantBuffers(bufferNumber, 1, &m_cBuffer);

	unsigned int stride;
	unsigned int offset;

	stride = sizeof(VertexType); 
	offset = 0;

	deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

	deviceContext->IASetInputLayout(m_gslayout);

	deviceContext->SOSetTargets(1, &m_outBuffer, &offset);
	deviceContext->GSSetShader(gsshader, NULL, 0);
	deviceContext->PSSetShader(NULL, NULL, 0);
	deviceContext->VSSetShader(NULL, NULL, 0);
	
	deviceContext->DrawIndexed(count, 0, 0); // If I disable this line that bug dosen't occur
	
	deviceContext->GSSetShader(NULL, NULL, 0);
	ID3D11Buffer* pBuffer[1];
	pBuffer[0] = NULL;
	deviceContext->SOSetTargets(1, pBuffer, &offset);

	return true;
}

Shader code:
 

cbuffer BufferConType
{
	float4 lightdir;
}

struct GIN
{
	float4 pos : POSITION;
    float2 tex : TEXCOORD0;
    float3 normal : NORMAL;
};

struct GOUT
{
	float4 pos : POSITION;
};

[maxvertexcount(3)]
void GS(triangleadj GIN input[6], inout TriangleStream<GOUT> OutputStream)
{
        //Test geometry shader
	GOUT p;
	p.pos = input[0].pos;
	p.pos.w = 1.0f;
	OutputStream.Append(p);
	p.pos = input[2].pos;
	p.pos.w = 1.0f;
	OutputStream.Append(p);
	p.pos = input[4].pos;
	p.pos.w = 1.0f;
	OutputStream.Append(p);
	OutputStream.RestartStrip();
}

 



Sponsor:

#2 MJP   Moderators   -  Reputation: 11761

Like
1Likes
Like

Posted 17 February 2013 - 02:49 AM

You can't just use a geometry shader, you always need a vertex shader bound in order to draw geometry. Do you create your device with the D3D11_CREATE_DEVICE_DEBUG flag? If you do, it should warn you about issues like this.


Edited by MJP, 17 February 2013 - 02:54 AM.


#3 _undex   Members   -  Reputation: 171

Like
0Likes
Like

Posted 17 February 2013 - 04:22 AM

I tried to set it to D3D11_CREATE_DEVICE_DEBUG but i still get no output.

And I also set my debugtype to mixed.

Anyway thank you, this was the solution smile.png



#4 ankhd   Members   -  Reputation: 1358

Like
0Likes
Like

Posted 17 February 2013 - 07:03 AM

Hi.

Is the pos member in screen space , you need a view and a projection matrix if not you may need a colour member to as well, and you need a vertex shader

a pass through type if not needed

struc vsin

{

//stuff

};

 

vsin VS(vsin in)

{

      return in;

}



#5 Jason Z   Crossbones+   -  Reputation: 5320

Like
0Likes
Like

Posted 17 February 2013 - 09:27 AM

What did you pass as the rasterized stream number to the function ID3D11Device::CreateGeometryShaderWithStreamOutput?  You are allowed to rasterize one of the output streams, and the rest have to be stream output only.  If you set it to not output a rasterized stream (see here for details) then you will not get any rendered output at all.



#6 _undex   Members   -  Reputation: 171

Like
0Likes
Like

Posted 17 February 2013 - 11:09 AM

Edit: Thanks for all that help but I solved my first problem with the help MJP ^^. But......

I have a new problem. The output of my geometry shader, which should only output what it gets for input, is really wierd.

I pass 36 vertices to the shader but I get 12.

Here they are (in this format ;x;y;z;w;):

-1;-1;-1;1;

;0;0;0;0;

;0;-1;-1;1;

;1;0;0;0;

;0;0;1;-1;

;1;1;0;0;

;0;0;0;1;

;-1;-1;1;0;

;0;0;0;0;

;-1;-1;-1;1;

;0;0;0;0;

;0;1;-1;1;

As you can see, some w-values are 0.

But the values that I've send have no 0 as w-values. Here is my new geometry shader:

struct GIN
{
	float4 pos : POSITION;
};

struct GOUT
{
	float4 pos : POSITION;
};

[maxvertexcount(3)]
void GS(triangle GIN input[3], inout TriangleStream<GOUT> OutputStream)
{
//Test shader
	GOUT p;
	p.pos = input[0].pos;
	OutputStream.Append(p);
	p.pos = input[1].pos;
	OutputStream.Append(p);
	p.pos = input[2].pos;
	OutputStream.Append(p);
	OutputStream.RestartStrip();
}
 

It is very hard to make geometry shader with stream out work, as there is no sample code on it on the net.



#7 _undex   Members   -  Reputation: 171

Like
0Likes
Like

Posted 17 February 2013 - 01:09 PM

Nevermind I found the solution myself. But I still don't know what the reason of this (new) problem was. I just tweaked at all settings and now it works ^^






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