Create Geometry Shader with Stream Output

Started by
3 comments, last by Jason Z 9 years, 4 months ago

Hello everyone,

I'm trying to create a geometry shader from the stream out, in order to build a GPU particle system. For the particle system, I have the Frank Luna book as reference, but I'm not using effect files. The relevant code is this:


struct Particle{
		D3DXVECTOR3 speed;
		D3DXVECTOR3 position;
		D3DXVECTOR2 size;
		float	age;
		int	type;
	};

bool result = D3DX11CompileFromFile(gsFilename, NULL, NULL, "main" , "gs_5_0", D3D10_SHADER_ENABLE_STRICTNESS | D3D10_SHADER_PACK_MATRIX_ROW_MAJOR, 0, NULL, &geometryShaderBuffer, &errorMessage, NULL);
	/*error checking*/

	//define the system output declaration entry, i.e. what will be written in the SO
	D3D11_SO_DECLARATION_ENTRY pDecl[] = 
	{
		//position, semantic name, semantic index, start component, component count, output slot
		{0,"TEXCOORD", 0, 0, 3, 0 }, // output first 3 components of SPEED
		{0, "POSITION", 0, 0, 3, 0 }, // output first 3 components of "POSITION"
		{0, "TEXCOORD", 1, 0, 2, 0 }, // output first 2 components of SIZE
		{0, "TEXCOORD", 2, 0, 1, 0 }, // output AGE
		{0, "TEXCOORD", 3, 0, 1, 0 }, // output TYPE
				
	};

	UINT strides [] = {sizeof(Particle) };
	device->CreateGeometryShaderWithStreamOutput(geometryShaderBuffer->GetBufferPointer(),geometryShaderBuffer->GetBufferSize(),pDecl,sizeof(pDecl),strides,0,D3D11_SO_NO_RASTERIZED_STREAM,NULL,&geometryShader);

	

The geometry shader is compiling, but the "CreateGeometryShaderWithStreamOutput" call will give me a null geometryShader value. I have been changing the value inside it to make it work, but debugging with RenderDoc showed me that this geometry shader is not binded.

vertex shader


struct Particle
{
	float3		speed : TEXCOORD0;
	float3		position : POSITION;
	float2		size : TEXCOORD1;
	float		age : TEXCOORD2;
	int		type : TEXCOORD3;

};


Particle main (Particle vin){
	return vin;
}

geometry shader


#define PT_EMITTER 0
#define PARTICLE 1

cbuffer GameInfo
{
	float3 emitterPosition;
	float gameTime;
	float frameTime;
	float3 padding;
};


struct Particle
{
	float3		speed : TEXCOORD0;
	float3		position : POSITION;
	float2		size : TEXCOORD1;
	float		age : TEXCOORD2;
	int		type : TEXCOORD3;

};



Texture1D randomTexture;
SamplerState linearSampler;


/*UTILITY*/

[maxvertexcount(1)]

void main (point Particle input[1], inout PointStream<Particle> outStream){
	
	//compute stuff
	
}

Any suggestion?

Advertisement

Did you create your device with the D3D11_CREATE_DEVICE_DEBUG flag enabled? If you do that, you'll get error messages in the debugger output telling you why API calls failed.

The geometry shader is compiling, but the "CreateGeometryShaderWithStreamOutput" call will give me a null geometryShader value.

This is an indicator that your GS code is valid but the actual GS bytecode created by compilation won't run on your hardware (compilation doesn't do hardware validation, creation does). I see that you're compiling with "gs_5_0" so the first thing you should check is that your hardware actually supports shader model 5.

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Thank you for your replies.

Did you create your device with the D3D11_CREATE_DEVICE_DEBUG flag enabled? If you do that, you'll get error messages in the debugger output telling you why API calls failed.

I create the device without that flag, I'll try to put it in and see if there will be error messages.

The geometry shader is compiling, but the "CreateGeometryShaderWithStreamOutput" call will give me a null geometryShader value.

This is an indicator that your GS code is valid but the actual GS bytecode created by compilation won't run on your hardware (compilation doesn't do hardware validation, creation does). I see that you're compiling with "gs_5_0" so the first thing you should check is that your hardware actually supports shader model 5.

I'm running the program with a geforce gtx 860m, which fully supports shaders v. 5!

Thank you for your replies.

Did you create your device with the D3D11_CREATE_DEVICE_DEBUG flag enabled? If you do that, you'll get error messages in the debugger output telling you why API calls failed.

I create the device without that flag, I'll try to put it in and see if there will be error messages.

The geometry shader is compiling, but the "CreateGeometryShaderWithStreamOutput" call will give me a null geometryShader value.

This is an indicator that your GS code is valid but the actual GS bytecode created by compilation won't run on your hardware (compilation doesn't do hardware validation, creation does). I see that you're compiling with "gs_5_0" so the first thing you should check is that your hardware actually supports shader model 5.

I'm running the program with a geforce gtx 860m, which fully supports shaders v. 5!

Which feature level did you create your device with? Even if your hardware is capable, you can easily request a lower feature level and cap yourself regarding shader level!

This topic is closed to new replies.

Advertisement