Jump to content
  • Advertisement
Sign in to follow this  
cozzie

DX11 'Timing' BeginDraw / EndDraw - 3D and 2D interop

Recommended Posts

Hi all,

I was wondering it it matters in which order you draw 2D and 3D items, looking at the BeginDraw/EndDraw calls on a D2D rendertarget.
The order in which you do the actual draw calls is clear, 3D first then 2D, means the 2D (DrawText in this case) is in front of the 3D scene.

The question is mainly about when to call the BeginDraw and EndDraw.
Note that I'm drawing D2D stuff through a DXGI surface linked to the 3D RT.

Option 1:

A - Begin frame, clear D3D RT
B - Draw 3D
C - BeginDraw D2D RT
D - Draw 2D
E - EndDraw D2D RT
F - Present

Option 2:

A - Begin frame, clear D3D RT + BeginDraw D2D RT
B - Draw 3D
C - Draw 2D
D - EndDraw D2D RT
E- Present

Would there be a difference (performance/issue?) in using option 2? (versus 1)

Any input is appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Posted (edited)
5 hours ago, cozzie said:

The order in which you do the actual draw calls is clear, 3D first then 2D, means the 2D (DrawText in this case) is in front of the 3D scene.

This part is not necessarily true.

 

Drawing 3D first then 2D will cause a little bit of overdraw where the rasterized pixels from the 2D part are hiding what's behind.

In my project I draw 2D first on both my color buffer and stencil buffer. Then I draw the 3D part only where the stencil has not been written. This part save heavy calculation of the 3D scene on pixels that would never be displayed otherwise but it can introduce some problems if you wish to use post-processing effects such as bloom/blur or anything that could cause pixels to bleed around.

 

I handle the skybox in pretty much the same manner. At the last stage of my deferred pipeline I sample and write the skybox color where neither the 3D or the 2D has written anything to the stencil buffer. (I dont rasterize a box / dome around the camera like the common old way)

 

Knowing that, I never need to clear my render targets when I know that a skybox is bound to my scene as all the pixel are guaranteed to be overwritten and that saves a lot of precious bandwidth.

Edited by ChuckNovice

Share this post


Link to post
Share on other sites
Posted (edited)

Thanks.Good to know different strategies that can be used.
Do you know if the moment when you call BeginDraw/EndDraw on the D2D RT, has any influence? (As in the original post/question)

Edited by cozzie

Share this post


Link to post
Share on other sites
4 minutes ago, cozzie said:

Thanks.Good to know different strategies that can be used.
Do you know if the moment when you call BeginDraw/EndDraw on the D2D RT, has any influence? (As in the original post/question)

I omitted that part in my previous comment because I prefer letting someone more experienced than me answer that one. I haven't used immediate mode for my draw calls in almost 10 years.

Share this post


Link to post
Share on other sites

For future reference/ who's interested, answer from the GD chat:

- because in this case you use the same RT for 3D and 2D, it's better to prevent trying to do stuff with the same resource and get possible conflicts. Therefor option 1 is preferred (could also be 2D first, then 3D, as long as you either BeginDraw after 3D is done, or EndDraw before you draw 3D)

@jpetrie: thanks!

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  

  • 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!