Jump to content
  • Advertisement
Sign in to follow this  
jbb

OpenGL Two directX12 questions

This topic is 1137 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

Although I'm a professional C++ program my 3d stuff is strictly hobby only so I'm doing mostly what I enjoy rather than what makes sense commercially :)

1) Although I'm working with directx11 at the moment I keep an eye on opengl and I'm ensuring that I could fairly easily port my drawing code to opengl if I wish in future. I would like to port to directx12 when it's practical to do so. So I want to make sure I structure my code is such as way as to make it easy/efficient to do so.

My understanding is that the main difference is that direct3d12 is stateless. That I need to submit all the render states, all the buffer mappings, all the texture mapping etc. in each rendering command at least conceptually. So I ought to organize my code that way now and ensure that my rending commands contain everything needed for the draw call (Buffers to map, Constants to set, Which render state set to use etc).

Is this correct and is it sufficient? Basically is there anything else I need to do in organizing my code to facilitate later porting to D3D12? I don't mean detail of using the API as much as how to organize the higher level code to facilitate it

2) I see some slightly older graphics cards only advertise directx 11 support even now. Are these still usable through the directx 12 API in the same way that you can use directx 9 cards through the directx11 api with a reduced feature set? Or will they not work and I'll have to have a separate directx11 interface if I want to support them? (This all assumes that relevent driver support is still available for them of course).

Thanks!

Share this post


Link to post
Share on other sites
Advertisement
1- yep, making each drae item completely stateless is a great head start!

Also - mapping/updating resources is unsynchronized d3d12. That basically means that only D3D11_MAP_WRITE_NO_OVERWRITE exists out of the box. You have to implement other kinds of map/update yourself. You can practice this now by sticking to only using D3D11_MAP_WRITE_NO_OVERWRITE (and synchronising with events where required) in your d3d11 codebase.


2- yep, dx12 has feature levels, but the lowest is 11.

For 9/10 level cards, you'll still need d3d11.

Share this post


Link to post
Share on other sites

Thanks!

Ok thanks for the comments on resources too. I can likely change my d3d11 code to work closer to that way too without any great loss.


 

Share this post


Link to post
Share on other sites

D3D11_MAP_WRITE_NO_OVERWRITE exists out of the box. You have to implement other kinds of map/update yourself. You can practice this now by sticking to only using D3D11_MAP_WRITE_NO_OVERWRITE (and synchronising with events where required) in your d3d11 codebase.

Wanted to make emphasis in that it's a "forced" no_overwrite on everything for everyone, rather than out of the box.
And that except for D3D11.1 running on Windows 8.1 or above, NO_OVERWRITE cannot be used with const and texture buffers.
Also staging buffers cannot be mapped with NO_OVERWRITE, but can be mapped with D3D11_MAP_FLAG_DO_NOT_WAIT which essentially the same except that it can fail if it's in use (whereas in D3D12 it won't fail, it will just return the address to you and you can walk straight into a race condition if you don't properly fence). Edited by Matias Goldberg

Share this post


Link to post
Share on other sites

My understanding then is that I need to create all buffers in my DX11 code fully initialized at create time and never overwrite them then? That if I want to charge the value I create a new buffer with the new contents?

If that's correct how do I handle constant buffers that I need to change every frame? Create a new one every frame? That seems expensive?

Share this post


Link to post
Share on other sites

My understanding then is that I need to create all buffers in my DX11 code fully initialized at create time and never overwrite them then? That if I want to charge the value I create a new buffer with the new contents?

If that's correct how do I handle constant buffers that I need to change every frame? Create a new one every frame? That seems expensive?

No, the NO_OVERRIDE flag is a promise that you do make to the API, that you won't modify the data until the GPU is done with it. In other words the protection of the data is in your hands, not the API nor the Driver. You can use a fence or a query, or you can rely on the fact that the GPU can't be more than 3 frames behind (not the best idea but usually works), so you can reuse the buffers when you know that the GPU is done with it.

For Constant Buffers in D3D11 you should stick to Map_Discard, unless you are targeting 11.1 and Windows 8.1 only as Matias said.

Creating a constant buffer per object per frame is not a good idea.

Edited by Sergio J. de los Santos

Share this post


Link to post
Share on other sites

Ah yes, that makes a great deal more sense.

So I can just keep a "pool" of buffers for each constant buffer and reuse them as the API finished with them.
I guess D3D11 is doing this behind the scenes for me anyway

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!