99#include < imgui_impl/win32.h>
1010#include < window/window.h>
1111
12- bool D3D12::ResetState (const bool acClearDownlevelBackbuffers, const bool acDestroyContext)
12+ bool D3D12::ResetState (const bool acDestroyContext)
1313{
1414 if (m_initialized)
1515 {
@@ -32,10 +32,6 @@ bool D3D12::ResetState(const bool acClearDownlevelBackbuffers, const bool acDest
3232 m_frameContexts.clear ();
3333 m_outSize = {0 , 0 };
3434
35- if (acClearDownlevelBackbuffers)
36- m_downlevelBackbuffers.clear ();
37- m_downlevelBufferIndex = 0 ;
38-
3935 m_pd3d12Device.Reset ();
4036 m_pd3dRtvDescHeap.Reset ();
4137 m_pd3dSrvDescHeap.Reset ();
@@ -144,137 +140,6 @@ bool D3D12::Initialize()
144140 return true ;
145141}
146142
147- bool D3D12::InitializeDownlevel (ID3D12CommandQueue* apCommandQueue, ID3D12Resource* apSourceTex2D, HWND ahWindow)
148- {
149- if (!apCommandQueue || !apSourceTex2D)
150- return false ;
151-
152- const HWND hWnd = m_window.GetWindow ();
153- if (!hWnd)
154- {
155- Log::Warn (" D3D12::InitializeDownlevel() - window not yet hooked!" );
156- return false ;
157- }
158-
159- if (m_initialized)
160- {
161- if (hWnd != ahWindow)
162- Log::Warn (
163- " D3D12::InitializeDownlevel() - current output window does not match hooked window! Currently hooked "
164- " to {} while current output window is {}." ,
165- reinterpret_cast <void *>(hWnd), reinterpret_cast <void *>(ahWindow));
166-
167- return true ;
168- }
169-
170- const auto cmdQueueDesc = apCommandQueue->GetDesc ();
171- if (cmdQueueDesc.Type != D3D12_COMMAND_LIST_TYPE_DIRECT)
172- {
173- Log::Warn (" D3D12::InitializeDownlevel() - ignoring command queue - invalid type of command list!" );
174- return false ;
175- }
176-
177- m_pCommandQueue = apCommandQueue;
178-
179- const auto st2DDesc = apSourceTex2D->GetDesc ();
180- m_outSize = {static_cast <LONG>(st2DDesc.Width ), static_cast <LONG>(st2DDesc.Height )};
181-
182- if (hWnd != ahWindow)
183- Log::Warn (
184- " D3D12::InitializeDownlevel() - current output window does not match hooked window! Currently hooked to {} "
185- " while current output window is {}." ,
186- reinterpret_cast <void *>(hWnd), reinterpret_cast <void *>(ahWindow));
187-
188- if (FAILED (apSourceTex2D->GetDevice (IID_PPV_ARGS (&m_pd3d12Device))))
189- {
190- Log::Error (" D3D12::InitializeDownlevel() - failed to get device!" );
191- return ResetState ();
192- }
193-
194- const size_t buffersCounts = m_downlevelBackbuffers.size ();
195- m_frameContexts.resize (buffersCounts);
196- if (buffersCounts == 0 )
197- {
198- Log::Error (" D3D12::InitializeDownlevel() - no backbuffers were found!" );
199- return ResetState ();
200- }
201- if (buffersCounts < g_numDownlevelBackbuffersRequired)
202- {
203- Log::Info (" D3D12::InitializeDownlevel() - backbuffer list is not complete yet; assuming window was resized" );
204- return false ;
205- }
206-
207- D3D12_DESCRIPTOR_HEAP_DESC rtvdesc;
208- rtvdesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
209- rtvdesc.NumDescriptors = static_cast <UINT>(buffersCounts);
210- rtvdesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
211- rtvdesc.NodeMask = 1 ;
212- if (FAILED (m_pd3d12Device->CreateDescriptorHeap (&rtvdesc, IID_PPV_ARGS (&m_pd3dRtvDescHeap))))
213- {
214- Log::Error (" D3D12::InitializeDownlevel() - failed to create RTV descriptor heap!" );
215- return ResetState ();
216- }
217-
218- const SIZE_T rtvDescriptorSize = m_pd3d12Device->GetDescriptorHandleIncrementSize (D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
219- D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = m_pd3dRtvDescHeap->GetCPUDescriptorHandleForHeapStart ();
220- for (auto & context : m_frameContexts)
221- {
222- context.MainRenderTargetDescriptor = rtvHandle;
223- rtvHandle.ptr += rtvDescriptorSize;
224- }
225-
226- D3D12_DESCRIPTOR_HEAP_DESC srvdesc = {};
227- srvdesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
228- srvdesc.NumDescriptors = 2 ;
229- srvdesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
230- if (FAILED (m_pd3d12Device->CreateDescriptorHeap (&srvdesc, IID_PPV_ARGS (&m_pd3dSrvDescHeap))))
231- {
232- Log::Error (" D3D12::InitializeDownlevel() - failed to create SRV descriptor heap!" );
233- return ResetState ();
234- }
235-
236- for (auto & context : m_frameContexts)
237- {
238- if (FAILED (m_pd3d12Device->CreateCommandAllocator (D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS (&context.CommandAllocator ))))
239- {
240- Log::Error (" D3D12::InitializeDownlevel() - failed to create command allocator!" );
241- return ResetState ();
242- }
243- }
244-
245- if (FAILED (m_pd3d12Device->CreateCommandList (0 , D3D12_COMMAND_LIST_TYPE_DIRECT, m_frameContexts[0 ].CommandAllocator .Get (), nullptr , IID_PPV_ARGS (&m_pd3dCommandList))))
246- {
247- Log::Error (" D3D12::InitializeDownlevel() - failed to create command list!" );
248- return ResetState ();
249- }
250-
251- if (FAILED (m_pd3dCommandList->Close ()))
252- {
253- Log::Error (" D3D12::InitializeDownlevel() - failed to close command list!" );
254- return ResetState ();
255- }
256-
257- for (size_t i = 0 ; i < buffersCounts; i++)
258- {
259- auto & context = m_frameContexts[i];
260- context.BackBuffer = m_downlevelBackbuffers[i];
261- m_pd3d12Device->CreateRenderTargetView (context.BackBuffer .Get (), nullptr , context.MainRenderTargetDescriptor );
262- }
263-
264- if (!InitializeImGui (buffersCounts))
265- {
266- Log::Error (" D3D12::InitializeDownlevel() - failed to initialize ImGui!" );
267- return ResetState ();
268- }
269-
270- Log::Info (" D3D12::InitializeDownlevel() - initialization successful!" );
271- m_initialized = true ;
272-
273- OnInitialized.Emit ();
274-
275- return true ;
276- }
277-
278143void D3D12::ReloadFonts ()
279144{
280145 std::lock_guard _ (m_imguiLock);
@@ -525,8 +390,8 @@ void D3D12::Update()
525390 if (!m_imguiDrawDataBuffers[0 ].Valid )
526391 return ;
527392
528- const auto bufferIndex = m_pdxgiSwapChain != nullptr ? m_pdxgiSwapChain-> GetCurrentBackBufferIndex () : m_downlevelBufferIndex ;
529- auto & frameContext = m_frameContexts[bufferIndex ];
393+ assert (m_pdxgiSwapChain) ;
394+ auto & frameContext = m_frameContexts[m_pdxgiSwapChain-> GetCurrentBackBufferIndex () ];
530395 frameContext.CommandAllocator ->Reset ();
531396
532397 D3D12_RESOURCE_BARRIER barrier;
0 commit comments