Jump to content
  • Advertisement
Sign in to follow this  
artisticdude

Creating A Geometry Shader With Stream-Output Fails

This topic is 713 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I'm trying to create a geometry shader with a stream-output in the SharpDX DirectX11 wrapper, but for some reason the code I have refuses to create the geometry shader (it throws an unhelpful exception about being initialized to null).

 

For broader context, I'm trying to create a (very simple) GPU-side particle system where the vertices are passed to the pipeline, the vertex shader shifts their positions by a delta-time variable passed in via a constant buffer, then the pass-through geometry shader streams the updated vertex positions back to the CPU via the stream-output stage. Then for the next frame I use the contents of the stream-output buffer (which contains the updated vertex positions) from the previous frame as the new vertex buffer.

 

A few ideas about the source of the error:

  1. Are my semantics right? In the StreamOutputElement I specify the SV_Position semantic, because that's the semantic used in the PS_IN structure that the Geometry shader outputs. I've tried changing this to Position both in the initialization code and in the shader, but it hasn't made a difference.
  2. Should the GS function in the shader be returning void? I'm operating under the assumption that appending the output to the stream also sends it down the pipeline to the pixel shader, but come to think of it, this may not be correct... I'm going to go play around with that. I don't see why that would make the geometry shader fail to initialize though.

 

Here's how I'm attempting to create the geometry shader:

using (var geometryShaderByteCode = ShaderBytecode.CompileFromFile("shaders.hlsl", "GS", "gs_4_0", ShaderFlags.Debug))
{
    SharpDX.Direct3D11.StreamOutputElement[] outputElements = new SharpDX.Direct3D11.StreamOutputElement[]
    {
        new SharpDX.Direct3D11.StreamOutputElement(0, "SV_POSITION", 0, 0, 1, 0)
    };
    //the following line is the troublesome one
    geometryShader = new SharpDX.Direct3D11.GeometryShader(defaultDevice, geometryShaderByteCode, outputElements, null, 0);
}

And my shaders.hlsl:

// Constant Buffer
cbuffer CbChangesEveryFrame : register(b0)    // register b0 is slot 0 for constant buffers
{
    float time;
};

// Shader input types
struct VS_IN
{
    float4 pos : POSITION;
};

struct GS_IN
{
    float4 pos : POSITION;
};

struct PS_IN
{
    float4 pos : SV_POSITION;
};

// Vertex Shader
GS_IN VS(VS_IN input)
{
    GS_IN output;
    output.pos = input.pos;
    output.pos.x += time;  //adjust the x-position by the timestep in the constant buffer
    return output;
}

// Geometry Shader
[maxvertexcount(1)]
void GS(point GS_IN input[1], inout PointStream<PS_IN> pointStream)
{
    PS_IN output;
    output.pos = input[0].pos;
    pointStream.Append(output);
}

// Pixel Shader
float4 PS(PS_IN input) : SV_TARGET
{
    float4 color = float4(1.0, 0.0, 0.0, 1.0);
    return color;
}

And the entirety of my code can be found here, if anyone wants to look at the full picture.

Share this post


Link to post
Share on other sites
Advertisement

it throws an unhelpful exception about being initialized to null...

geometryShader = new SharpDX.Direct3D11.GeometryShader(defaultDevice, geometryShaderByteCode, outputElements, null, 0);


A null array for the stride(s) doesn't sound right.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!