MCPcopy Create free account
hub / github.com/TheRealMJP/DXRPathTracer / Initialize

Method Initialize

SampleFramework12/v1.02/Graphics/GraphicsTypes.cpp:230–316  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

228}
229
230void Buffer::Initialize(uint64 size, uint64 alignment, bool32 dynamic, bool32 cpuAccessible,
231 bool32 allowUAV, const void* initData, D3D12_RESOURCE_STATES initialState,
232 ID3D12Heap* heap, uint64 heapOffset, const wchar* name)
233{
234 Assert_(size > 0);
235 Assert_(alignment > 0);
236
237 Size = AlignTo(size, alignment);
238 Alignment = alignment;
239 Dynamic = dynamic;
240 CPUAccessible = cpuAccessible;
241 CurrBuffer = 0;
242 CPUAddress = nullptr;
243 GPUAddress = 0;
244 Heap = nullptr;
245 HeapOffset = 0;
246 CreateFrame = DX12::CurrentCPUFrame;
247
248 Assert_(allowUAV == false || dynamic == false);
249 Assert_(dynamic || cpuAccessible == false);
250
251 D3D12_RESOURCE_DESC resourceDesc = { };
252 resourceDesc.Dimension = D3D12_RESOURCE_DIMENSION_BUFFER;
253 resourceDesc.Width = dynamic ? Size * DX12::RenderLatency : Size;
254 resourceDesc.Height = 1;
255 resourceDesc.DepthOrArraySize = 1;
256 resourceDesc.MipLevels = 1;
257 resourceDesc.Format = DXGI_FORMAT_UNKNOWN;
258 resourceDesc.Flags = allowUAV ? D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS : D3D12_RESOURCE_FLAG_NONE;
259 resourceDesc.SampleDesc.Count = 1;
260 resourceDesc.SampleDesc.Quality = 0;
261 resourceDesc.Layout = D3D12_TEXTURE_LAYOUT_ROW_MAJOR;
262 resourceDesc.Alignment = 0;
263
264 const D3D12_HEAP_PROPERTIES* heapProps = cpuAccessible ? DX12::GetUploadHeapProps() : DX12::GetDefaultHeapProps();
265 D3D12_RESOURCE_STATES resourceState = initialState;
266 if(cpuAccessible)
267 resourceState = D3D12_RESOURCE_STATE_GENERIC_READ;
268 else if(initData)
269 resourceState = D3D12_RESOURCE_STATE_COMMON;
270
271 if(heap)
272 {
273 Heap = heap;
274 HeapOffset = heapOffset;
275 DXCall(DX12::Device->CreatePlacedResource(heap, heapOffset, &resourceDesc, resourceState,
276 nullptr, IID_PPV_ARGS(&Resource)));
277 }
278 else
279 {
280 DXCall(DX12::Device->CreateCommittedResource(heapProps, D3D12_HEAP_FLAG_NONE, &resourceDesc,
281 resourceState, nullptr, IID_PPV_ARGS(&Resource)));
282 }
283
284 if(name)
285 Resource->SetName(name);
286
287 GPUAddress = Resource->GetGPUVirtualAddress();

Callers

nothing calls this directly

Calls 12

AlignToFunction · 0.85
GetUploadHeapPropsFunction · 0.85
GetDefaultHeapPropsFunction · 0.85
DXCallFunction · 0.85
ResourceUploadBeginFunction · 0.85
ResourceUploadEndFunction · 0.85
GetReadbackHeapPropsFunction · 0.85
RTReadStateFunction · 0.85
AllocatePersistentMethod · 0.80
ShutdownFunction · 0.70
MapMethod · 0.45
InitMethod · 0.45

Tested by

no test coverage detected