1

I'm building a game/DirectX12 renderer in c++. I've got most things working and I'm able to statically create in game objects with textures, normalmapping, lighting etc. Since i'm a programmer noob and not an engineer, i'm unsure of how to structure different stuff.

I would like to get some ideas of how to handle low level bufferers when rendering a frame. I've included a rough graph of the area of interest Rough graph

I create StructuredBufferers with instance data of every object in the game. I pass raw data and it gets translated into structures which are compitable with the low level directx bufferers.

I'm currently unsure how to handle the StructuredBufferers in terms of their entire lifetime. They are kinda static, but sometimes the translation matrix or texture might change and therefore need an update or an entirely new bufferer.

I'm wondering what's most reasonable and open to suggestions. I'll build the code myself (in c++) and don't mind pseudo-code, since i'm struggling a bit with the engineering side

For example:

Should i create buffers at the start of preperation of all frames (in flight) before submission to the draw-call and destroy them after each frame has been rendered? This means a lot of bufferer creation and destruction and of course fence syncronization

Should i create an allocator with a pagesystem, where bufferers are allocated, kept and updated, only recreated if the allocation is too small (due to more instances of the object)? Thereby keeping the buffers alive over many frames? In terms of culling this might be wasteful memory wise

Other ideas?

Martin
  • 33
  • 5
  • 1
    You may want to take a look at *DirectX Tool Kit for DX 12* and specifically the **LinearAllocator** class [.cpp](https://github.com/microsoft/DirectXTK12/blob/main/Src/LinearAllocator.cpp) / [.h](https://github.com/microsoft/DirectXTK12/blob/main/Src/LinearAllocator.h). – Chuck Walbourn May 05 '23 at 20:10
  • @ChuckWalbourn : Yeah, i figured i'd do a class that just allocates - but thanks a lot - is it possible to give you the "answer" for it? – Martin May 07 '23 at 16:15

1 Answers1

1

DirectX 12 by design leaves a lot of details to the developer/application.

There are different strategies you can use, but one 'generalized' solution for handling ephemeral data like Constant Buffers, Instance Buffers, and dynamic-usage IBs/VBs is to use a linear allocator. You then use fences each frame to determine when that memory use by the GPU is complete before you reclaim it.

For an example implementation, see DirectX Tool Kit for DX12's LinearAllocator class.

https://github.com/microsoft/DirectXTK12/blob/main/Src/LinearAllocator.h https://github.com/microsoft/DirectXTK12/blob/main/Src/LinearAllocator.cpp

Chuck Walbourn
  • 38,259
  • 2
  • 58
  • 81
  • Is _LinearAllocator_ a new class @ChuckWalbourn? Wasn't aware of its presence in DXTK12 until now. Perhaps it would be a good idea to include it as a link attached to to the docs discussing memory management, perhaps in **GraphicsMemory** or **BufferHelpers**? – Maico De Blasio May 08 '23 at 02:56
  • 1
    LinearAllocator is a purely internal class used by GraphicsMemory. If you are using the *DirectX Tool Kit*, the best option is to use GraphicsMemory interfaces. – Chuck Walbourn May 08 '23 at 03:50
  • Ah that makes sense! Yes I'm a huge advocate for **GraphicsMemory**. I was wondering where _LinearAllocator_ could be useful to my app and I've been using it all along! – Maico De Blasio May 08 '23 at 04:04
  • Yeah, it's certainly more elegant than my own solution! Thanks for your answers :-) – Martin May 13 '23 at 05:14