Sign in to follow this  
~Helgon

Linestrip with GeometryShader

Recommended Posts

Hi,

my problem is that if i try to expand my vertex with the GeometryShader DirectX seems to not connect the lines anymore and also it doesn't draw all lines

[code]md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_LINESTRIP); // SAME PROBLEM WITH LINELIST[/code]


[CODE]
UINT count = 10;
std::vector<Vertex::Geo> vertices(count);
for(UINT i = 0; i < count; ++i)
{
vertices[i].Pos = XMFLOAT3(i*1.0f, 1.0f, 1.0f);
vertices[i].Size = XMFLOAT2(16.0f, 16.0f);
}
[/CODE]


[CODE]
[maxvertexcount(2)]
void GS(point VertexOut gin[1],
inout LineStream<GeoOut> stream)
{

float3 up = float3(0.0f, 1.0f, 0.0f);
float3 look = gEyePosW - gin[0].CenterW;
look.y = 0.0f; // y-axis aligned, so project to xz-plane
look = normalize(look);
float3 right = cross(up, look);

float halfWidth = 0.5f*gin[0].SizeW.x;
float halfHeight = 0.5f*gin[0].SizeW.y;

float4 v[2];
v[0] = float4(gin[0].CenterW + halfHeight*up, 1.0f);
v[1] = float4(gin[0].CenterW - halfHeight*up, 1.0f);

GeoOut gout;
[unroll]
for(int i = 0; i < 2; ++i)
{
gout.PosH = mul(v[i], gViewProj);
gout.PosW = v[i].xyz;
gout.NormalW = look;

stream.Append(gout);
}
}

[/CODE]

I have 2 Problems. First that i get this warning:
[CODE]D3D11 ERROR: ID3D11DeviceContext::DrawIndexed: The declared input primitive type in the current Geometry Shader does not match the current input topology. [ EXECUTION ERROR #360: DEVICE_DRAW_GS_INPUT_PRIMITIVE_MISMATCH][/CODE]

EDIT: Seems that if i use D3D11_PRIMITIVE_TOPOLOGY_POINTLIST as primitiveTopology i dont get the warnig (but why if the inout is LineStream?)

the inout is LineStream so that should not be the problem :/ and as IASetPrimitiveTopology i tried line list and line strip.. both gave me this error

and the second probem is: as u can see i create 10 vertices - should mean at least 5 lines.. and after adding one point with the geometry shader it should be 10 (or?) but all i get are 2 lines

hope that someone can give me a hint

regards helgon

EDIT 2: pretty strange if i use the Draw Method it at least draw 9 lines (count - 1) if i want all 10 i have to draw 11.. pretty strange also
[code]md3dImmediateContext->Draw(10, 0);[/code]

if i draw indexed i get just the two lines like in the screenshot (independent which indexCount i use)
[code]md3dImmediateContext->DrawIndexed(10, 0, 0);[/code]

but the lines still are linelists and not linestrips

Edited by ~Helgon

Share this post


Link to post
Share on other sites
The geometry shader will be executed once for each primitive it is passed. In this case, you are using point lists as the input primitive type, so for each point that makes its way to the input of the geometry shader, you will execute your geometry shader program. From what I see there, you are creating two points and the output primitive type is a line stream. In this scenario, the image you have shown is perfectly correct - you should get one line consisting of two vertices for each point that was passed into the GS.

Where I think you are getting mixed up is that the stream is only active for a given geometry shader invocation. So subsequent point primitives won't add their lines to the same output stream - only the vertices that are added within one GS invocation are included in the same stream!

Share this post


Link to post
Share on other sites
Ah thanks for the answer. it helped me a bit to understand better what happens

so i changed the topology to:

[quote]md3dImmediateContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_POINTLIST);[/quote]

and if i expand one point in the GS it works.. for testing reasons i expended one point to 20

[CODE]
[maxvertexcount(20)]
void GS(point VertexOut gin[1],
inout LineStream<GeoOut> stream)
{
float3 up = float3(0.0f, 1.0f, 0.0f);
float3 look = gEyePosW - gin[0].CenterW;
look.y = 0.0f; // y-axis aligned, so project to xz-plane
look = normalize(look);
float3 right = cross(up, look);

float4 v[20];
for(int i = 0; i < 20; ++i)
{
if(i%2 == 0)
{
v[i] = float4(gin[0].CenterW + i*1.0f, 1.0f);
}
else
{
v[i] = float4(gin[0].CenterW - i*1.0f, 1.0f);
}
}
GeoOut gout;
[unroll]
for(int i = 0; i < 20; ++i)
{
gout.PosH = mul(v[i], gViewProj);
gout.PosW = v[i].xyz;
gout.NormalW = look;

stream.Append(gout);
}
}
[/CODE]

it works fine.. if i set the inout in the GS to PointStream directx draws all the single points and if i set it to LineStream i get single lines, but that is the problem. what i in fact want are connected lines (like the LINESTRIP topology) so how can i achieve that?

my thought was that maybe something like stream.ContinueStrip() exists (like RestartStrip()) but i didn't found anything

would be happy if u can give me another hint or short give me a snippet how to implement a LineStrip (with the points generated by the GS)


regards helgon Edited by ~Helgon

Share this post


Link to post
Share on other sites
If you want to produce connected lines then each invocation of the GS has to know where the previous invocation put its last point, otherwise it won't know where to start its own line. So you sould use a line strip as your input primitive to the pipeline, then the GS would know both the current and the next point's location, and you could act accordingly when placing the output vertices. However, this would require double computation in the GS, which probably isn't that efficient - but if efficiency isn't what you are after, then that might work for you.

Otherwise, you could probably use the tessellation stages to produce the primitives that you want to manipulate in the GS, then you just amplify the data in the GS... It really just depends on what you are looking to do...

One other option is to do a stream out to a buffer of the point data that you are generating now, and then to re-render them in the pipeline... That would work fairly easily too!

Share this post


Link to post
Share on other sites
[quote name='Jason Z' timestamp='1354146366' post='5005129']
If you want to produce connected lines then each invocation of the GS has to know where the previous invocation put its last point, otherwise it won't know where to start its own line. So you sould use a line strip as your input primitive to the pipeline, then the GS would know both the current and the next point's location, and you could act accordingly when placing the output vertices. However, this would require double computation in the GS, which probably isn't that efficient - but if efficiency isn't what you are after, then that might work for you.
[/quote]

Did i understand it right that i just shall add another point to the location where the second line is draw? so its just a "faked" connection because there are two points on the exakt same location?

[quote]So you sould use a line strip as your input primitive to the pipeline[/quote]
Sorry if this question is dumb, but what is my input primitive ? IASetPrimitiveTopology this one? if you mean that - if i use something beside the POINTLIST i get the error

[code]D3D11 ERROR: ID3D11DeviceContext::DrawIndexed: The declared input primitive type in the current Geometry Shader does not match the current input topology. [ EXECUTION ERROR #360: DEVICE_DRAW_GS_INPUT_PRIMITIVE_MISMATCH]
[/code] Edited by ~Helgon

Share this post


Link to post
Share on other sites
[quote name='~Helgon' timestamp='1354147117' post='5005137']
Did i understand it right that i just shall add another point to the location where the second line is draw? so its just a "faked" connection because there are two points on the exakt same location?
[/quote]

You are partially right. By specifying that the input primitive to the input assembler is a line strip, you are actually providing a list of points that will produce n-1 lines for n points. Your vertex buffer will remain the same, just your topology is changed so that lines are assembled instead of points to be passed into the pipeline.

[quote name='~Helgon' timestamp='1354147117' post='5005137']
Sorry if this question is dumb, but what is my input primitive ? IASetPrimitiveTopology this one? if you mean that - if i use something beside the POINTLIST i get the error

[code]D3D11 ERROR: ID3D11DeviceContext::DrawIndexed: The declared input primitive type in the current Geometry Shader does not match the current input topology. [ EXECUTION ERROR #360: DEVICE_DRAW_GS_INPUT_PRIMITIVE_MISMATCH]
[/code]
[/quote]

That is because after you change your input assembler setting (via IASetPrimitiveTopology) then the pipeline is creating lines, but your geometry shader is expecting points (as indicated by the stream type declared as the input to the GS function). So you need to change your stream type back to a linestream, and then you will have access to both the current and the next vertices from within that line. It will then be up to you to determine how many output vertices and where you should put them - but you have access to both of the points that should be needed for your calculations.

Share this post


Link to post
Share on other sites
The problem is, that it doesn't matter which inout type i set in the GS - i also get this error if inout is specified as a LineStream (and the IA as TPOLOGY_LINELSTRIP)

In fact it's so that i always get the error if the IA is set to something else beside POINTLIST

Share this post


Link to post
Share on other sites
Hi Helgon,

The primitive topology that is specified at the input assembler defines the primitives fed into the pipeline (D3D11_PRIMITIVE_TOPOLOGY_X). The topology needs to match the type you specified at the input struct of the geometry shader:
[CODE]void GS(point VertexOut gin[1],
inout LineStream<GeoOut> stream)[/CODE]
This would require a D3D11_PRIMITIVE_TOPOLOGY_POINTLIST.

[CODE]void GS(line VertexOut gin[2],
inout LineStream<GeoOut> stream)[/CODE]
This would require a D3D11_PRIMITIVE_TOPOLOGY_LINE{LIST|STRIP}. Note that you now have two vertices coming in (gin[2]).
The output topology is defined by the geometry shader’s output stream, i.e. LineStream. Input and output topologies don’t necessarily have to coincide.

Jason suggested to use a line strip as input, as it allows you to fake the connections between your lines. (See the attachment for a small example.)

Best regards!

Share this post


Link to post
Share on other sites
Hi Helgon, what problem are you trying to solve? Do you want to draw line strip of arbitrary width with D3D? If yes, here is a pixel shader solution at [url="http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter22.html"]http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter22.html[/url].

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