Jump to content
  • Advertisement
Sign in to follow this  
Vilem Otte

OpenGL DirectX 12 few notes and questions

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

So, I've finally found time to start playing around with DirectX and Direct3D 12 - I've went through documentation, basic samples and even a simple engine sample. Now as I've been OpenCL/OpenGL guy for most of the time, I don't have that much experience with DirectX (last one I've used was version Direct3D 9). If somebody would be kind enough to read through my thoughts and possibly tell me if I'm thinking about it right, or wrong.


I will not go into basic samples, as I've went through them - I'm now trying to add Direct3D 12 renderer into my framework which still has OpenGL support (which I'm trying to replace). First of all, let me approx. state out how my Scene works - I have a graph structure (scene-graph like) holding entities, some of these point to one or more Model class instances (along with pointing to Transformation - which is actually just a 4x4 matrix). A Model class points a set of Mesh instances (plus it holds additional things like bounding box, etc. etc.). A Mesh points to Material and VertexBuffer/IndexBuffer, and also Texture, contains a descriptor for the VertexBuffer (describing how the data are interlanced), and Texture (describing what each texture represents), and ShaderParams - which is a constant buffer (along with pipeline state items). Material points only to a Shader.


Note. I know I could move ShaderParams up to Entity and I most likely will at some point, but I wanted to keep the description simple for start.


So, once I'm actually rendering with a camera - I obtain a set of pointers to Mesh instance that are going to be rendered (of course with matrices). This is all processed outside of actually doing rendering with OpenGL right now. For D3D12 I'm still thinking about structures and how to work with them. Let's jump ahead, so I have this set of pointers (with some additional info for each record). In OpenGL when I don't do any sorting (most basic rendering), I just loop through all these, set pipeline state, attach shader, bind textures, set shader parameters, draw, and continue in loop.


In D3D12 this will be a lot different though:


1.) I am not doing any immediate changes like in OpenGL case - once I start application, I create CommandQueue, which I will fill with CommandLists every frame and let it draw (I can either pre-build CommandLists, or build them each frame - when necessary). Anyways I think I understand the command queue and command list concept - so the problem is not here.


2.) Each of my Mesh instance should contain a PipelineStateObject, which will be attached during the rendering. This will completely describe which shader is attached and part of the ShaderParams that hold info about F.e. Blending.


3.) I don't fully understand RootSignature - as far as I got it, this is a object holding some parameters description I'm sending to shader. So technically for each shader I should have a RootSignature (or respectively have one, but change its content)..


4.) How am I passing uniforms into shader - only through RootSignature? (Assuming I don't want to use constant buffer)


If you got here and have an answer on my curious questions I'd be glad. Thank you!

Share this post

Link to post
Share on other sites

It's probably worth bearing in mind that you might not even get all 16 DWORDs if the hardware needs some for another purpose like storing BaseVertexLocation, though this might depend on how the compiler implements the fetch shader. If you do spill by even 1 DWORD then it may have to take a couple of DWORDs back from your 16 to store an address where it can find the spilled DWORDs. So don't necessarily assume that you always get all 16 all the time.


I've yet to see this extra level of indirection making any measurable difference in performance. In terms of numbers of levels of indirection, you can refer to the following table. Avoiding the '3' case is not that difficult (just make sure descriptor tables are early in your root signature), and the "1" and "2" cases for spilling are no worse in terms of indirection count to using a root descriptor or descriptor table when it doesn't spill.


For example, a Root Constant outside the first 16 will spill and require an extra indirection to get at. However, a spilled root constant is no worse than fetching a DWORD from a constant buffer was on DX11, so it's not the end of the world.



Edited by Adam Miles

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!