Advertisement

Memory management, Evict, MakeResident, Placed resources, etc.

Started by November 27, 2018 11:06 AM
4 comments, last by Hodgman 6 years, 2 months ago

I have a few questions about DirectX 12 memory management:

1) When you call the ID3D12Device::Evict() function, how do you specify that the contents of the resource is no longer needed and therefor can be discarded? For example, if I have a resource that I am done with, but will need it again later as a render target, I don't want the contents to be swapped out and restored because that would just be a waste of bandwidth.

2) When you call the QueryVideoMemoryInfo() function and find that your memory budget has been reduced and that you are now over budget, how much time do you have to rectify the situation?

3) Am I correct when saying that Placed Resources cannot be used when you want to use a resource as both a render target and a shader resource? (The reason being that you cannot create a heap that support both uses on heap tier 1 hardware (almost all current NVidia hardware). )

3) For resources in your RT heap, you can create SRVs, UAVs and RTV/DSVs for them. The restriction is upon the flags used when creating the resource (not the view) -- e.g. if D3D12_RESOURCE_DIMENSION_TEXTURE2D is set, then  D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET or D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL must also be set.

2) Not sure, but I assume as soon as possible - e.g. before the next Present... In my experience, your budget is typically somewhere from 55% to 85% of total GPU memory, which probably leaves the OS a little bit of wriggle room for you to mess up? If your calls to MakeResident begin to fail, then you're out of time :D

1) ID3D12GraphicsCommandList::DiscardResource lets the driver know that you no longer require the contents of a render target to be preserved. I imagine that calling this as soon as you're done with some data wouldn't be a bad idea here.

Advertisement

Thanks for your help. I am not sure I understand #3. I would like to create a large heap and then sub-allocate 2D textures within the heap using ID3D12Device::CreatePlacedResource(). I would like to use these textures as both render targets and as shader resources. The documentation says that when calling ID3D12Device::CreateHeap(), you have to specify D3D12_HEAP_FLAGS such that:

Adapters that only support heap tier 1 must set two out of the three following flags.
  D3D12_HEAP_FLAG_DENY_BUFFERS
  D3D12_HEAP_FLAG_DENY_RT_DS_TEXTURES
  D3D12_HEAP_FLAG_DENY_NON_RT_DS_TEXTURES

What then is the purpose of these flags and how should you set them?

Oh, I think I figured it out... On tier 1 hardware you will be forced to create all placed textures with D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET if you want to render to any of the textures in that heap. The disadvantage is that this will use more memory. From the documentation on D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET:

Quote

Allows a render target view to be created for the resource, as well as enables the resource to transition into the state of D3D12_RESOURCE_STATE_RENDER_TARGET. Some adapter architectures allocate extra memory for textures with this flag to reduce the effective bandwidth during common rendering. This characteristic may not be beneficial for textures that are never rendered to, nor is it available for textures compressed with BC formats. Applications should avoid setting this flag when rendering will never occur.

On tier 2 hardware the advantage is that you can create placed textures with or without the flag as needed.

Is this correct?

On 11/28/2018 at 1:19 AM, Barnett said:

Is this correct?

Yep :)

So you can put 'normal' textures in a RT heap, but you have to flag them as RT's, which means no use of features that are incompatible with RTs (block compressed formats, etc) ... 

This topic is closed to new replies.

Advertisement