Jump to content

  • Log In with Google      Sign In   
  • Create Account


Run DirectX 11 stream output without drawing

  • You cannot reply to this topic
11 replies to this topic

#1 3DModelerMan   Members   -  Reputation: 938

Like
0Likes
Like

Posted 06 June 2014 - 08:45 AM

How do you go about running a stream output shader without drawing anything to the screen? I want to use a geometry shader with stream output to skin my animated meshes, but the only way I know of to cause the geometry shader to execute is submitting a draw call. Is there any other way to execute the geometry shader so that I don't draw to the screen? The reason I'm doing it with stream output is because I'd rather incur the memory overhead of storing a deformed copy of the mesh, than the GPU overhead of having to calculate the deformation again for each rendering pass.



Sponsor:

#2 unbird   Crossbones+   -  Reputation: 4829

Like
7Likes
Like

Posted 06 June 2014 - 09:04 AM

Sure, you can omit the rasterization if you use D3D11_SO_NO_RASTERIZED_STREAM for the RasterizedStream parameter.



#3 BlackBrain   Members   -  Reputation: 240

Like
4Likes
Like

Posted 06 June 2014 - 09:38 AM

Or you can set the pixel shader to null . 



#4 3DModelerMan   Members   -  Reputation: 938

Like
0Likes
Like

Posted 06 June 2014 - 11:48 AM

Thanks. That worked great.



#5 MJP   Moderators   -  Reputation: 10231

Like
7Likes
Like

Posted 06 June 2014 - 12:34 PM

Or you can set the pixel shader to null . 

 

This will not achieve the same result as not rasterizing. If you do this, the triangles will still be rasterized, and if you have depth writes enabled the depth will be written to the depth buffer.



#6 unbird   Crossbones+   -  Reputation: 4829

Like
4Likes
Like

Posted 06 June 2014 - 01:34 PM

You're welcome. Since I haven't tried stream out with skinning, I always wondered how to go about this exactly. Because you unlikely want to operate on triangles to not blow the stream out buffer unnecessarily, does this work on points ?

Yes it does biggrin.png. Here's the setup:
  • Use a pass-through geometry shader (point->point), setup the streamout and set topology to point list.
  • Draw the whole buffer with context->Draw(). This gives a 1:1 mapping of the vertices.
  • Later bind the stream out buffer as vertex buffer. Bind the index buffer of the original mesh.
  • draw with DrawIndexed like you would with the original mesh (or whatever draw call you had).
Here a screenshot that it works. I (ab)use the texcoords from the original mesh, since they don't need skinning (only position and normal). The right spider is from the stream out buffer.

SpiderStreamout.png

(CC-BY Ricardo28roi)

#7 3DModelerMan   Members   -  Reputation: 938

Like
2Likes
Like

Posted 06 June 2014 - 01:51 PM

I've also been considering using a compute shader to do skinning, but for now I'm just going to do stream out because I haven't written a compute framework in my engine yet.



#8 unbird   Crossbones+   -  Reputation: 4829

Like
1Likes
Like

Posted 06 June 2014 - 02:48 PM

Interesting. That would save one shader stage (and hopefully gain performance). Don't forget to post your findings.



#9 french_hustler   Members   -  Reputation: 341

Like
0Likes
Like

Posted 06 June 2014 - 04:17 PM

I have a further question about SO. 

I was going to post a new topic but since this thread is "sort of" similar, I might as well ask here.

 

I basically want to voxelize my geometry. I was trying to by-pass the rasterization pipeline to do so as to avoid doing conservative rasterization by using the geometry shader. Instead I take all my objects vertices and indices, and for each object create an associated buffer of triangles.  I pass all these buffers into a kernel that creates my voxel grid datastructure.

 

Instead of pre-creating these buffers with triangles, I was thinking of rendering my scene regularly but streaming-out these triangles using an SO resource. What do I need to do to be able to use this resource in a compute kernel? Also is there a way to know how many elements are in an SO buffer?

 

Thank you.


Edited by french_hustler, 06 June 2014 - 04:17 PM.


#10 3DModelerMan   Members   -  Reputation: 938

Like
0Likes
Like

Posted 06 June 2014 - 04:25 PM

Interesting. That would save one shader stage (and hopefully gain performance). Don't forget to post your findings.

 

I will if I end up getting it working. I might have something worth writing an article about by the end of the summer, but I won't know until I've finished integrating the compute shaders, which given my engine architecture, could take some time.



#11 unbird   Crossbones+   -  Reputation: 4829

Like
3Likes
Like

Posted 06 June 2014 - 05:01 PM

What do I need to do to be able to use this resource in a compute kernel?

Apart from the obvious D3D11_BIND_STREAM_OUTPUT flag, your buffer additionally needs D3D11_BIND_SHADER_RESOURCE (or even D3D11_BIND_UNORDERED_ACCESS). You probably have to play around a bit: I once tested if one could use D3D11_BIND_VERTEX_BUFFER in combination with the latter two and it only worked with raw and typed buffers, not structured buffers, unfortunately.
Then you create the appropriate views which you bind to your compute shader (shader resource view/unordered access view).

Since I haven't done this, I can't say this works at all (the runtime is quite reluctant about combining "unusual" flags). Turn up the debug runtime, it will tell you exactly what is off.

Edit: Is this for vanilla DX11 ? Because 11.1 allows writing to UAVs from every shader stage. You wouldn't even need stream out functionality.

Also is there a way to know how many elements are in an SO buffer?

There are a couple of stream out related queries, of particular interest here is D3D11_QUERY_SO_STATISTICS (or the STREAMX versions thereof). Note that queries have a latency.

Edited by unbird, 06 June 2014 - 05:16 PM.


#12 french_hustler   Members   -  Reputation: 341

Like
0Likes
Like

Posted 07 June 2014 - 04:03 PM

Hey unbird, thanks for your reply.

 

 

Edit: Is this for vanilla DX11 ? Because 11.1 allows writing to UAVs from every shader stage. You wouldn't even need stream out functionality.
 

 

You know, I recently bought a GTX 770 card that claims to support 11.2.  Scattered RW from any stage was one feature I really wanted on my new GPU.  Turns out NVIDIA does not support the full feature set. I do find it a bit misleading when the specifications fail to mention that it isn't a full support but "capable" of the 11.2 feature set.


Edited by french_hustler, 07 June 2014 - 04:07 PM.






PARTNERS