I'm using ID3D12Resource::Map
method to update a GPU resource. Is that the most efficient way? What alternatives do exist?

- 7,709
- 6
- 64
- 90

- 43
- 1
- 4
1 Answers
Upload heap resources have an associated cost for reading, which is higher than a default resource.
In case of Constant buffers, this is generally fine (as you are in a write once/read once scenario), but in other cases (large Vertex/Index buffers), this is generally not desirable.
A general approach is to create two resources (one within an upload heap, one within a default heap),copy your data into the upload resource (using map as you mentioned), then perform a gpu copy using either CopyResource or CopyBufferRegion in the default resource.
Please make sure that you have the Right resource state set up before/after the resource copy, using ResourceBarrier and a transition state.
Before to call copy, resource should be in the D3D12_RESOURCE_STATE_COPY_DEST before copy, and any of the read flag that is dependent on your resource.
Please also note that you can use a Copy Command queue for the GPU copy (so you can avoid to perform in in the Direct Command list), but you will need to ensure that the copy is completed before to use the resource (by using Fences).
Multi engine is described in msdn here

- 8,523
- 1
- 27
- 61
-
Note that if you are only _writing_ to a resource, you may get faster performance by writing directly, and not using an upload - since you can use write combined memory (particularly if you are doing this frequently). It's one of those things you have to optimize/check for your scenario. – cmaughan Jun 09 '17 at 09:47
-
@cmaughan It is worth to say that this is only true for buffers, there is no way to map a texture that way. – galop1n Aug 04 '17 at 20:45
-
@galop1n Nope; you can do that with textures too. But again, you have to profile which is faster. – cmaughan Aug 21 '17 at 11:28