microsoft / DirectXTK12

The DirectX Tool Kit (aka DirectXTK12) is a collection of helper classes for writing DirectX 12 code in C++
https://walbourn.github.io/directx-tool-kit-for-directx-12/
MIT License
1.47k stars 393 forks source link

Model::LoadStaticBuffers to use static VB/IB instead of dynamic #38

Closed walbourn closed 6 years ago

walbourn commented 6 years ago

In the original implementation, all Model vertex buffers and index buffers are allocated by GraphicsMemory. This means that they are in a upload heap which is accessible to both the CPU and GPU, equivalent to the Direct3D 11 version of USAGE_DYNAMIC. This is simple and easy to use, but has performance impacts--which on Xbox One can be quite noticeable due to the caching behavior.

This change adds an optional call to LoadStaticBuffers which uses a ResourceUploadBatch to create static VB/IBs for rendering copying the data from the loaded GraphicsMemory resources. This is equivalent to USAGE_DEFAULT in Direct3D 11.

The ModelMeshPart now contains four new members:

There is a small breaking change here in that all custom Model loaders must populate the new vertexBufferSize and indexBufferSize members of ModelMeshPart.

Custom Model renderers should be updated for all four new member variables.

To support this I added a new Upload method overload for ResourceUploadBatch. The existing Upload method copies the data into a staging upload heap resource for use in the copy to the GPU, but here the data is already in an upload heap managed by GraphicsMemory which we can use directly.

Also did a little SAL annotation cleanup in a few places, and added comparison operators for SharedGraphicsResource