MCPcopy Create free account
hub / github.com/carbonengine/trinity / Create

Method Create

trinityal/dx12/Tr2ResourceHelper.cpp:24–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22}
23
24ALResult Tr2ResourceHelper::Create( Strategy strategy, size_t size, D3D12_RESOURCE_FLAGS resourceFlags, D3D12_RESOURCE_STATES state, bool requiresImmediateBarriers, uint32_t initialDataCount, const D3D12_SUBRESOURCE_DATA* initialData, Tr2PrimaryRenderContextAL& renderContext )
25{
26 if( strategy != DYNAMIC )
27 {
28 CComPtr<ID3D12Resource> buffer, scratch;
29 auto heap = HeapDesc( D3D12_HEAP_TYPE_DEFAULT );
30 auto resourceDesc = BufferDesc( size, resourceFlags );
31 auto initialState = initialDataCount ? D3D12_RESOURCE_STATE_COPY_DEST : state;
32 CR_RETURN_HR( renderContext.m_device->CreateCommittedResource(
33 &heap,
34 D3D12_HEAP_FLAG_NONE,
35 &resourceDesc,
36 initialState,
37 nullptr,
38 IID_PPV_ARGS( &buffer ) ) );
39 if( initialDataCount )
40 {
41 auto scratchHeap = HeapDesc( D3D12_HEAP_TYPE_UPLOAD );
42 auto scratchDesc = BufferDesc( size );
43 CR_RETURN_HR( renderContext.m_device->CreateCommittedResource(
44 &scratchHeap,
45 D3D12_HEAP_FLAG_NONE,
46 &scratchDesc,
47 D3D12_RESOURCE_STATE_GENERIC_READ,
48 nullptr,
49 IID_PPV_ARGS( &scratch ) ) );
50 if( !UpdateSubresources(
51 renderContext.m_commandList,
52 buffer,
53 scratch,
54 0,
55 0,
56 initialDataCount,
57 initialData ) )
58 {
59 return E_FAIL;
60 }
61 if( state != initialState )
62 {
63 renderContext.ResourceBarrierDx12( Transition( buffer, initialState, state ) );
64 if( requiresImmediateBarriers )
65 {
66 renderContext.FlushBarriersDx12( buffer );
67 }
68 }
69 if( strategy == STATIC )
70 {
71 RELEASE_LATER( &renderContext, scratch );
72 }
73 else
74 {
75 Resource r = { scratch, renderContext.GetRecordingFrameNumber(), nullptr, 0 };
76 D3D12_RANGE readRange = { 0, 0 };
77 CR_RETURN_HR( scratch->Map( 0, &readRange, &r.cpuAddress ) );
78
79 m_resources.push_back( r );
80 }
81 }

Callers

nothing calls this directly

Calls 9

HeapDescFunction · 0.85
BufferDescFunction · 0.85
TransitionFunction · 0.85
ResourceBarrierDx12Method · 0.80
FlushBarriersDx12Method · 0.80
GetGPUVirtualAddressMethod · 0.80
UpdateSubresourcesFunction · 0.70
MapMethod · 0.45

Tested by

no test coverage detected