| 186 | } |
| 187 | |
| 188 | void Buffer::Initialize(uint64 size, uint64 alignment, bool32 dynamic, BufferLifetime lifetime, bool32 allowUAV, const void* initData, D3D12_RESOURCE_STATES initialState) |
| 189 | { |
| 190 | Assert_(size > 0); |
| 191 | Assert_(alignment > 0); |
| 192 | |
| 193 | Size = AlignTo(size, alignment); |
| 194 | Alignment = alignment; |
| 195 | Lifetime = lifetime; |
| 196 | Dynamic = dynamic; |
| 197 | CurrBuffer = 0; |
| 198 | CPUAddress = nullptr; |
| 199 | GPUAddress = 0; |
| 200 | |
| 201 | Assert_(Lifetime == BufferLifetime::Persistent || dynamic); |
| 202 | Assert_(allowUAV == false || dynamic == false); |
| 203 | |
| 204 | if(Lifetime == BufferLifetime::Persistent) |
| 205 | { |
| 206 | D3D12_RESOURCE_DESC resourceDesc = { }; |
| 207 | resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER; |
| 208 | resourceDesc.Width = uint32(dynamic ? Size * DX12::RenderLatency : Size); |
| 209 | resourceDesc.Height = 1; |
| 210 | resourceDesc.DepthOrArraySize = 1; |
| 211 | resourceDesc.MipLevels = 1; |
| 212 | resourceDesc.Format = DXGI_FORMAT_UNKNOWN; |
| 213 | resourceDesc.Flags = allowUAV ? D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS : D3D12_RESOURCE_FLAG_NONE; |
| 214 | resourceDesc.SampleDesc.Count = 1; |
| 215 | resourceDesc.SampleDesc.Quality = 0; |
| 216 | resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR; |
| 217 | resourceDesc.Alignment = 0; |
| 218 | |
| 219 | const D3D12_HEAP_PROPERTIES* heapProps = dynamic ? DX12::GetUploadHeapProps() : DX12::GetDefaultHeapProps(); |
| 220 | D3D12_RESOURCE_STATES resourceState = initialState; |
| 221 | if(initData && dynamic == false) |
| 222 | resourceState = D3D12_RESOURCE_STATE_COPY_DEST; |
| 223 | |
| 224 | DXCall(DX12::Device->CreateCommittedResource(heapProps, D3D12_HEAP_FLAG_NONE, &resourceDesc, |
| 225 | resourceState, nullptr, IID_PPV_ARGS(&Resource))); |
| 226 | |
| 227 | GPUAddress = Resource->GetGPUVirtualAddress(); |
| 228 | |
| 229 | if(dynamic) |
| 230 | { |
| 231 | D3D12_RANGE readRange = { }; |
| 232 | DXCall(Resource->Map(0, &readRange, reinterpret_cast<void**>(&CPUAddress))); |
| 233 | } |
| 234 | |
| 235 | if(initData && dynamic) |
| 236 | { |
| 237 | for(uint64 i = 0; i < DX12::RenderLatency; ++i) |
| 238 | { |
| 239 | uint8* dstMem = CPUAddress + Size * i; |
| 240 | memcpy(dstMem, initData, size); |
| 241 | } |
| 242 | |
| 243 | } |
| 244 | else if(initData) |
| 245 | { |
nothing calls this directly
no test coverage detected