dx12 memory management

minggoddess發表於2018-04-13

https://msdn.microsoft.com/en-us/library/windows/desktop/dn508285(v=vs.85).aspx

Map with D3D11_MAP_WRITE_DISCARD, the runtime returns a pointer to a new region of memory instead of the old buffer data.

This allows the GPU to continue using the old data while the app places data in the new buffer.

No additional memory management is required in the app; the old buffer is reused or destroyed automatically when the GPU is finished with it.

好神奇

Note  When you map a buffer with D3D11_MAP_WRITE_DISCARD, the runtime always discards the entire buffer.

You can't preserve info in unmapped areas of the buffer by specifying a nonzero offset or limited size field.

 

When you call Map on a static vertex buffer while the GPU is using the buffer, you get a significant performance penalty. In this situation,

 Map must wait until the GPU is finished reading vertex or index data from the buffer before Map can return to the calling app, which causes a significant delay.

Calling Map and then rendering from a static buffer several times per frame also prevents the GPU from buffering rendering commands

because it must finish commands before returning the map pointer.

Without buffered commands, the GPU remains idle until after the app is finished filling the vertex buffer or index buffer and issues a rendering command.

 

D3D11_USAGE_IMMUTABLE is well-suited to data such as textures because such data is typically read into memory from some file format.

Therefore, when you create a texture with D3D11_USAGE_IMMUTABLE, the GPU directly reads that texture into memory.

=============

shit原先那個頁面被更新了。。。

https://docs.microsoft.com/zh-cn/windows/desktop/api/d3d11/ne-d3d11-d3d11_usage

https://docs.microsoft.com/en-us/windows/desktop/api/d3d11/ne-d3d11-d3d11_map

====================

兜兜轉轉 又回來繼續弄這個

先捋一下dx11

map是為了可以拿到這塊memory的地址 來操作裡面的內容

如果memory型別用static 就需要gpu等cpu用完再用 hang在那裡 很慢 所以memory型別要選dynamic

這樣顯示卡會自己處理這些事情不會hang在那裡等gpu用完再用 處理的方式取決於map type

D3D11_MAP_WRITE_DISCARD --如果是write discard,這時 如果gpu在用cpu就直接開一塊新的往裡寫,所以裡面的內容是未定義的。舊內容discard了

D3D11_USAGE_DEFAULT         GPU讀寫--預設的GPU資源

D3D11_USAGE_IMMUTABLE GPU讀   CPU不能操作---不變

D3D11_USAGE_DYNAMIC         CPU寫 GPU讀  map出來

D3D11_USAGE_STAGING         GPUcopy to CPU --save GPU和CPU讀寫

================================

https://docs.microsoft.com/en-us/windows/desktop/direct3d12/memory-management-strategies

下面寫dx12了

有三種

committed

placed

reserved

如果cpu要寫資源 不會像dx11 的write discard那樣driver管理資源,就等於只有NO_OVERWRITE flag需要自己管理資源

保證GPU要用的資源沒有被cpu寫壞 比如加fence 用uploading resorces

就是每份gpu要用的資料cpu copy一份出來操作 等於手動 write discard

我現在用的fence就讓他hang在那裡了,dynamic的map unmap肯定不能這樣,這樣太慢了 但應該是可以用的

https://docs.microsoft.com/en-us/windows/desktop/direct3d12/uploading-resources

 

相關文章