@@ -9,10 +9,8 @@ namespace DX12
99
1010 {
1111 this ->type = type;
12- D3D12_COMMAND_LIST_TYPE t = static_cast <D3D12_COMMAND_LIST_TYPE>(type);
13- Device::get ().get_native_device ()->CreateCommandAllocator (t, IID_PPV_ARGS (&m_commandAllocator));
14- Device::get ().get_native_device ()->CreateCommandList (0 , t, m_commandAllocator.Get (), nullptr , IID_PPV_ARGS (&m_commandList));
15- m_commandList->Close ();
12+
13+ compiler.create (type);
1614
1715 if (type == CommandListType::DIRECT || type == CommandListType::COMPUTE)
1816 compute.reset (new ComputeContext (*this ));
@@ -23,7 +21,7 @@ namespace DX12
2321 if (type == CommandListType::DIRECT)
2422 graphics.reset (new GraphicsContext (*this ));
2523
26- m_commandList-> SetName (L" SpectrumCommandList" );
24+ compiler. SetName (L" SpectrumCommandList" );
2725
2826
2927 debug_buffer = std::make_shared<StructuredBuffer<Table::DebugStruct>>(64 , counterType::NONE, D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS);
@@ -69,6 +67,7 @@ namespace DX12
6967
7068 void CommandList::begin (std::string name, Timer* t)
7169 {
70+ compiled = CommandListCompiled ();
7271#ifdef DEV
7372 begin_stack = Exceptions::get_stack_trace ();
7473#endif
@@ -79,8 +78,7 @@ namespace DX12
7978 global_id = _global_id++;
8079
8180 // Log::get() << "begin" << Log::endl;
82- m_commandAllocator->Reset ();
83- TEST (m_commandList->Reset (m_commandAllocator.Get (), nullptr ));
81+ compiler.reset ();
8482 // resource_index = 0;
8583
8684 if (graphics) graphics->begin ();
@@ -149,14 +147,21 @@ namespace DX12
149147 on_execute_funcs.emplace_back (f);
150148
151149 }
152-
153- std::shared_future<FenceWaiter> Sendable::execute (std::function<void ()> f)
150+ void Sendable::compile ()
154151 {
155152 CommandList* list = static_cast <CommandList*>(this ); // :(
156153
157154 list->flush_transitions ();
158- TEST (m_commandList->Close ());
159155
156+ compiled = compiler.compile ();
157+ }
158+ std::shared_future<FenceWaiter> Sendable::execute (std::function<void ()> f)
159+ {
160+
161+ // TEST(compiler.Close());
162+ if (!compiled)
163+ compile ();
164+
160165 execute_fence = std::promise<FenceWaiter>();
161166 execute_fence_result = execute_fence.get_future ();
162167 if (f)
@@ -175,7 +180,7 @@ namespace DX12
175180
176181 void Eventer::insert_time (QueryHeap& pQueryHeap, uint32_t QueryIdx)
177182 {
178- m_commandList-> EndQuery (pQueryHeap.get_native (), D3D12_QUERY_TYPE_TIMESTAMP, QueryIdx);
183+ compiler. EndQuery (pQueryHeap.get_native (), D3D12_QUERY_TYPE_TIMESTAMP, QueryIdx);
179184 }
180185
181186 void Eventer::resolve_times (QueryHeap& pQueryHeap, uint32_t NumQueries, std::function<void (std::span<UINT64>)> f)
@@ -184,7 +189,7 @@ namespace DX12
184189 auto info = list->read_data (NumQueries* sizeof (UINT64));
185190
186191 list->flush_transitions ();
187- m_commandList-> ResolveQueryData (pQueryHeap.get_native (), D3D12_QUERY_TYPE_TIMESTAMP, 0 , NumQueries, info.resource ->get_native ().Get (), info.offset );
192+ compiler. ResolveQueryData (pQueryHeap.get_native (), D3D12_QUERY_TYPE_TIMESTAMP, 0 , NumQueries, info.resource ->get_native ().Get (), info.offset );
188193
189194
190195 on_execute_funcs.emplace_back ([info, f, NumQueries]() {
@@ -200,7 +205,7 @@ namespace DX12
200205 assert (s);
201206 if (current_root_signature != s)
202207 {
203- base. get_native_list () ->SetGraphicsRootSignature (s->get_native ().Get ());
208+ list ->SetGraphicsRootSignature (s->get_native ().Get ());
204209 current_root_signature = s;
205210 }
206211 }
@@ -215,13 +220,13 @@ namespace DX12
215220 if (b)
216221 heaps[1 ] = b->get_native ().Get ();
217222
218- base. get_native_list () ->SetDescriptorHeaps (b ? 2 : 1 , heaps);
223+ list ->SetDescriptorHeaps (b ? 2 : 1 , heaps);
219224 }
220225
221226
222227 void GraphicsContext::set (UINT i, const HandleTableLight& table)
223228 {
224- base. get_native_list () ->SetGraphicsRootDescriptorTable (i, table.gpu );
229+ list ->SetGraphicsRootDescriptorTable (i, table.gpu );
225230 }
226231
227232
@@ -339,7 +344,7 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
339344 base.flush_transitions ();
340345 auto info = base.place_data (size);
341346 memcpy (info.get_cpu_data (), data, size);
342- base. get_native_list () ->CopyBufferRegion (
347+ list ->CopyBufferRegion (
343348 resource->get_native ().Get (), offset, info.resource ->get_native ().Get (), info.offset , size);
344349 }
345350
@@ -398,7 +403,7 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
398403 base.flush_transitions ();
399404 UINT64 uploadBufferSize = GetRequiredIntermediateSize (resource->get_native ().Get (), first_subresource, sub_count);
400405 auto info = base.place_data (uploadBufferSize, D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT);
401- UpdateSubresources (base. get_native_list () .Get (), resource->get_native ().Get (), info.resource ->get_native ().Get (), info.offset , first_subresource, sub_count, data);
406+ // UpdateSubresources(list .Get(), resource->get_native().Get(), info.resource->get_native().Get(), info.offset, first_subresource, sub_count, data);
402407 }
403408 void CopyContext::update_texture (Resource::ptr resource, ivec3 offset, ivec3 box, UINT sub_resource, const char * data, UINT row_stride, UINT slice_stride)
404409 {
@@ -473,7 +478,7 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
473478 Src.PlacedFootprint .Footprint .Depth = box.z ;
474479 Src.PlacedFootprint .Footprint .RowPitch = res_stride;
475480 Src.PlacedFootprint .Footprint .Format = Layouts.Footprint .Format ;
476- base. get_native_list () ->CopyTextureRegion (&Dst, offset.x , offset.y , offset.z , &Src, nullptr );
481+ list ->CopyTextureRegion (&Dst, offset.x , offset.y , offset.z , &Src, nullptr );
477482 }
478483
479484 void GraphicsContext::set_pipeline (PipelineState::ptr state)
@@ -525,7 +530,7 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
525530 dest.PlacedFootprint .Footprint .Depth = box.z ;
526531 dest.PlacedFootprint .Footprint .RowPitch = res_stride;
527532 dest.PlacedFootprint .Footprint .Format = to_srv (Layouts.Footprint .Format );
528- base. get_native_list () ->CopyTextureRegion (&dest, offset.x , offset.y , offset.z , &source, nullptr );
533+ list ->CopyTextureRegion (&dest, offset.x , offset.y , offset.z , &source, nullptr );
529534 auto result = std::make_shared<std::promise<bool >>();
530535 base.on_execute_funcs .push_back ([result, info, f, res_stride, NumRows]()
531536 {
@@ -550,8 +555,8 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
550555 base.flush_transitions ();
551556 // auto size = resource->get_size();
552557 auto info = base.read_data (size);
553- // m_commandList-> CopyResource(info.resource->get_resource()->get_native().Get(), resource->get_native().Get());
554- base. get_native_list () ->CopyBufferRegion (info.resource ->get_native ().Get (), info.offset , resource->get_native ().Get (), offset, size);
558+ // compiler. CopyResource(info.resource->get_resource()->get_native().Get(), resource->get_native().Get());
559+ list ->CopyBufferRegion (info.resource ->get_native ().Get (), info.offset , resource->get_native ().Get (), offset, size);
555560 base.on_execute_funcs .push_back ([result, info, f, size]()
556561 {
557562 f (reinterpret_cast <char *>(info.get_cpu_data ()), size);
@@ -573,8 +578,8 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
573578 base.flush_transitions ();
574579 // auto size = resource->get_size();
575580 auto info = base.read_data (size);
576- // m_commandList-> CopyResource(info.resource->get_resource()->get_native().Get(), resource->get_native().Get());
577- base. get_native_list () ->ResolveQueryData (query_heap->get_native (), D3D12_QUERY_TYPE_PIPELINE_STATISTICS, 0 , 1 , info.resource ->get_native ().Get (), info.offset );
581+ // compiler. CopyResource(info.resource->get_resource()->get_native().Get(), resource->get_native().Get());
582+ list ->ResolveQueryData (query_heap->get_native (), D3D12_QUERY_TYPE_PIPELINE_STATISTICS, 0 , 1 , info.resource ->get_native ().Get (), info.offset );
578583 auto result = std::make_shared<std::promise<bool >>();
579584 base.on_execute_funcs .push_back ([result, info, f, size]()
580585 {
@@ -618,7 +623,7 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
618623 if (!transitions.empty ())
619624 {
620625 PROFILE_GPU (L" flush_transitions" );
621- m_commandList-> ResourceBarrier ((UINT)transitions.size (), transitions.data ());
626+ compiler. ResourceBarrier ((UINT)transitions.size (), transitions.data ());
622627 transitions.clear ();
623628 }
624629 }
@@ -793,7 +798,7 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
793798 base.transition (dest, Render::ResourceState::COPY_DEST);
794799 }
795800 base.flush_transitions ();
796- base. get_native_list () ->CopyBufferRegion (dest->get_native ().Get (), s_dest, source->get_native ().Get (), s_source, size);
801+ list ->CopyBufferRegion (dest->get_native ().Get (), s_dest, source->get_native ().Get (), s_source, size);
797802 }
798803 void CopyContext::copy_resource (Resource* dest, Resource* source)
799804 {
@@ -803,7 +808,7 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
803808 base.transition (dest, Render::ResourceState::COPY_DEST);
804809 }
805810 base.flush_transitions ();
806- base. get_native_list () ->CopyResource (dest->get_native ().Get (), source->get_native ().Get ());
811+ list ->CopyResource (dest->get_native ().Get (), source->get_native ().Get ());
807812 }
808813 void CopyContext::copy_resource (const Resource::ptr& dest, const Resource::ptr& source)
809814 {
@@ -815,7 +820,7 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
815820 base.transition (dest, Render::ResourceState::COPY_DEST);
816821 }
817822 base.flush_transitions ();
818- base. get_native_list () ->CopyResource (dest->get_native ().Get (), source->get_native ().Get ());
823+ list ->CopyResource (dest->get_native ().Get (), source->get_native ().Get ());
819824 }
820825 void CopyContext::copy_texture (const Resource::ptr& dest, int dest_subres, const Resource::ptr& source, int source_subres)
821826 {
@@ -827,7 +832,7 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
827832 base.flush_transitions ();
828833 CD3DX12_TEXTURE_COPY_LOCATION Dst (dest->get_native ().Get (), dest_subres);
829834 CD3DX12_TEXTURE_COPY_LOCATION Src (source->get_native ().Get (), source_subres);
830- base. get_native_list () ->CopyTextureRegion (&Dst, 0 , 0 , 0 , &Src, nullptr );
835+ list ->CopyTextureRegion (&Dst, 0 , 0 , 0 , &Src, nullptr );
831836 }
832837
833838 void CopyContext::copy_texture ( const Resource::ptr& to, ivec3 to_pos, const Resource::ptr& from, ivec3 from_pos, ivec3 size)
@@ -851,7 +856,7 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
851856 box.right = from_pos.x + size.x ;
852857 box.bottom = from_pos.y + size.y ;
853858 box.back = from_pos.z + size.z ;
854- base. get_native_list () ->CopyTextureRegion (&Dst, to_pos.x , to_pos.y , to_pos.z , &Src, &box);
859+ list ->CopyTextureRegion (&Dst, to_pos.x , to_pos.y , to_pos.z , &Src, &box);
855860 }
856861
857862
@@ -927,7 +932,7 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
927932 {
928933 if (pipeline)
929934 {
930- get_native_list ()-> SetPipelineState (pipeline->get_native ().Get ());
935+ compiler. SetPipelineState (pipeline->get_native ().Get ());
931936 tracked_psos.emplace_back (pipeline->get_native ());
932937 }
933938 current_pipeline = pipeline;
@@ -1013,17 +1018,17 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
10131018
10141019 void Eventer::start_event (std::wstring str)
10151020 {
1016- ::PIXBeginEvent (m_commandList.Get(), 0, str.c_str());
1021+ // ::PIXBeginEvent(m_commandList.Get(), 0, str.c_str());
10171022 }
10181023
10191024 void Eventer::end_event ()
10201025 {
1021- ::PIXEndEvent (m_commandList.Get());
1026+ // ::PIXEndEvent(m_commandList.Get());
10221027 }
10231028
10241029 void Eventer::set_marker (const wchar_t * label)
10251030 {
1026- ::PIXSetMarker (m_commandList.Get(), 0, label);
1031+ // ::PIXSetMarker(m_commandList.Get(), 0, label);
10271032 }
10281033
10291034 FrameResources::ptr FrameResourceManager::begin_frame ()
@@ -1141,7 +1146,7 @@ void GraphicsContext::set_rtv(std::initializer_list<Handle> rt, Handle h)
11411146
11421147 for (auto e : discards)
11431148 {
1144- // m_commandList-> DiscardResource(e->get_native().Get(), nullptr);
1149+ // compiler. DiscardResource(e->get_native().Get(), nullptr);
11451150 }
11461151 m_commandList->Close ();
11471152 }
0 commit comments