main.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. // ImGui - standalone example application for DirectX 12
  2. // If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
  3. // FIXME: 64-bit only for now! (Because sizeof(ImTextureId) == sizeof(void*))
  4. #include "imgui.h"
  5. #include "imgui_impl_win32.h"
  6. #include "imgui_impl_dx12.h"
  7. #include <d3d12.h>
  8. #include <dxgi1_4.h>
  9. #include <tchar.h>
  10. #define DX12_ENABLE_DEBUG_LAYER 0
  11. struct FrameContext
  12. {
  13. ID3D12CommandAllocator* CommandAllocator;
  14. UINT64 FenceValue;
  15. };
  16. // Data
  17. static int const NUM_FRAMES_IN_FLIGHT = 3;
  18. static FrameContext g_frameContext[NUM_FRAMES_IN_FLIGHT] = {};
  19. static UINT g_frameIndex = 0;
  20. static int const NUM_BACK_BUFFERS = 3;
  21. static ID3D12Device* g_pd3dDevice = NULL;
  22. static ID3D12DescriptorHeap* g_pd3dRtvDescHeap = NULL;
  23. static ID3D12DescriptorHeap* g_pd3dSrvDescHeap = NULL;
  24. static ID3D12CommandQueue* g_pd3dCommandQueue = NULL;
  25. static ID3D12GraphicsCommandList* g_pd3dCommandList = NULL;
  26. static ID3D12Fence* g_fence = NULL;
  27. static HANDLE g_fenceEvent = NULL;
  28. static UINT64 g_fenceLastSignaledValue = 0;
  29. static IDXGISwapChain3* g_pSwapChain = NULL;
  30. static HANDLE g_hSwapChainWaitableObject = NULL;
  31. static ID3D12Resource* g_mainRenderTargetResource[NUM_BACK_BUFFERS] = {};
  32. static D3D12_CPU_DESCRIPTOR_HANDLE g_mainRenderTargetDescriptor[NUM_BACK_BUFFERS] = {};
  33. void CreateRenderTarget()
  34. {
  35. ID3D12Resource* pBackBuffer;
  36. for (UINT i = 0; i < NUM_BACK_BUFFERS; i++)
  37. {
  38. g_pSwapChain->GetBuffer(i, IID_PPV_ARGS(&pBackBuffer));
  39. g_pd3dDevice->CreateRenderTargetView(pBackBuffer, NULL, g_mainRenderTargetDescriptor[i]);
  40. g_mainRenderTargetResource[i] = pBackBuffer;
  41. }
  42. }
  43. void WaitForLastSubmittedFrame()
  44. {
  45. FrameContext* frameCtxt = &g_frameContext[g_frameIndex % NUM_FRAMES_IN_FLIGHT];
  46. UINT64 fenceValue = frameCtxt->FenceValue;
  47. if (fenceValue == 0)
  48. return; // No fence was signaled
  49. frameCtxt->FenceValue = 0;
  50. if (g_fence->GetCompletedValue() >= fenceValue)
  51. return;
  52. g_fence->SetEventOnCompletion(fenceValue, g_fenceEvent);
  53. WaitForSingleObject(g_fenceEvent, INFINITE);
  54. }
  55. FrameContext* WaitForNextFrameResources()
  56. {
  57. UINT nextFrameIndex = g_frameIndex + 1;
  58. g_frameIndex = nextFrameIndex;
  59. HANDLE waitableObjects[] = { g_hSwapChainWaitableObject, NULL };
  60. DWORD numWaitableObjects = 1;
  61. FrameContext* frameCtxt = &g_frameContext[nextFrameIndex % NUM_FRAMES_IN_FLIGHT];
  62. UINT64 fenceValue = frameCtxt->FenceValue;
  63. if (fenceValue != 0) // means no fence was signaled
  64. {
  65. frameCtxt->FenceValue = 0;
  66. g_fence->SetEventOnCompletion(fenceValue, g_fenceEvent);
  67. waitableObjects[1] = g_fenceEvent;
  68. numWaitableObjects = 2;
  69. }
  70. WaitForMultipleObjects(numWaitableObjects, waitableObjects, TRUE, INFINITE);
  71. return frameCtxt;
  72. }
  73. void ResizeSwapChain(HWND hWnd, int width, int height)
  74. {
  75. DXGI_SWAP_CHAIN_DESC1 sd;
  76. g_pSwapChain->GetDesc1(&sd);
  77. sd.Width = width;
  78. sd.Height = height;
  79. IDXGIFactory4* dxgiFactory = NULL;
  80. g_pSwapChain->GetParent(IID_PPV_ARGS(&dxgiFactory));
  81. g_pSwapChain->Release();
  82. CloseHandle(g_hSwapChainWaitableObject);
  83. IDXGISwapChain1* swapChain1 = NULL;
  84. dxgiFactory->CreateSwapChainForHwnd(g_pd3dCommandQueue, hWnd, &sd, NULL, NULL, &swapChain1);
  85. swapChain1->QueryInterface(IID_PPV_ARGS(&g_pSwapChain));
  86. swapChain1->Release();
  87. dxgiFactory->Release();
  88. g_pSwapChain->SetMaximumFrameLatency(NUM_BACK_BUFFERS);
  89. g_hSwapChainWaitableObject = g_pSwapChain->GetFrameLatencyWaitableObject();
  90. assert(g_hSwapChainWaitableObject != NULL);
  91. }
  92. void CleanupRenderTarget()
  93. {
  94. WaitForLastSubmittedFrame();
  95. for (UINT i = 0; i < NUM_BACK_BUFFERS; i++)
  96. if (g_mainRenderTargetResource[i]) { g_mainRenderTargetResource[i]->Release(); g_mainRenderTargetResource[i] = NULL; }
  97. }
  98. HRESULT CreateDeviceD3D(HWND hWnd)
  99. {
  100. // Setup swap chain
  101. DXGI_SWAP_CHAIN_DESC1 sd;
  102. {
  103. ZeroMemory(&sd, sizeof(sd));
  104. sd.BufferCount = NUM_BACK_BUFFERS;
  105. sd.Width = 0;
  106. sd.Height = 0;
  107. sd.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
  108. sd.Flags = DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT;
  109. sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
  110. sd.SampleDesc.Count = 1;
  111. sd.SampleDesc.Quality = 0;
  112. sd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
  113. sd.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
  114. sd.Scaling = DXGI_SCALING_STRETCH;
  115. sd.Stereo = FALSE;
  116. }
  117. if (DX12_ENABLE_DEBUG_LAYER)
  118. {
  119. ID3D12Debug* dx12Debug = NULL;
  120. if (SUCCEEDED(D3D12GetDebugInterface(IID_PPV_ARGS(&dx12Debug))))
  121. {
  122. dx12Debug->EnableDebugLayer();
  123. dx12Debug->Release();
  124. }
  125. }
  126. D3D_FEATURE_LEVEL featureLevel = D3D_FEATURE_LEVEL_11_0;
  127. if (D3D12CreateDevice(NULL, featureLevel, IID_PPV_ARGS(&g_pd3dDevice)) != S_OK)
  128. return E_FAIL;
  129. {
  130. D3D12_DESCRIPTOR_HEAP_DESC desc = {};
  131. desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
  132. desc.NumDescriptors = NUM_BACK_BUFFERS;
  133. desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
  134. desc.NodeMask = 1;
  135. if (g_pd3dDevice->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&g_pd3dRtvDescHeap)) != S_OK)
  136. return E_FAIL;
  137. SIZE_T rtvDescriptorSize = g_pd3dDevice->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
  138. D3D12_CPU_DESCRIPTOR_HANDLE rtvHandle = g_pd3dRtvDescHeap->GetCPUDescriptorHandleForHeapStart();
  139. for (UINT i = 0; i < NUM_BACK_BUFFERS; i++)
  140. {
  141. g_mainRenderTargetDescriptor[i] = rtvHandle;
  142. rtvHandle.ptr += rtvDescriptorSize;
  143. }
  144. }
  145. {
  146. D3D12_DESCRIPTOR_HEAP_DESC desc = {};
  147. desc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
  148. desc.NumDescriptors = 1;
  149. desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
  150. if (g_pd3dDevice->CreateDescriptorHeap(&desc, IID_PPV_ARGS(&g_pd3dSrvDescHeap)) != S_OK)
  151. return E_FAIL;
  152. }
  153. {
  154. D3D12_COMMAND_QUEUE_DESC desc = {};
  155. desc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
  156. desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
  157. desc.NodeMask = 1;
  158. if (g_pd3dDevice->CreateCommandQueue(&desc, IID_PPV_ARGS(&g_pd3dCommandQueue)) != S_OK)
  159. return E_FAIL;
  160. }
  161. for (UINT i = 0; i < NUM_FRAMES_IN_FLIGHT; i++)
  162. if (g_pd3dDevice->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&g_frameContext[i].CommandAllocator)) != S_OK)
  163. return E_FAIL;
  164. if (g_pd3dDevice->CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, g_frameContext[0].CommandAllocator, NULL, IID_PPV_ARGS(&g_pd3dCommandList)) != S_OK ||
  165. g_pd3dCommandList->Close() != S_OK)
  166. return E_FAIL;
  167. if (g_pd3dDevice->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&g_fence)) != S_OK)
  168. return E_FAIL;
  169. g_fenceEvent = CreateEvent(NULL, FALSE, FALSE, NULL);
  170. if (g_fenceEvent == NULL)
  171. return E_FAIL;
  172. {
  173. IDXGIFactory4* dxgiFactory = NULL;
  174. IDXGISwapChain1* swapChain1 = NULL;
  175. if (CreateDXGIFactory1(IID_PPV_ARGS(&dxgiFactory)) != S_OK ||
  176. dxgiFactory->CreateSwapChainForHwnd(g_pd3dCommandQueue, hWnd, &sd, NULL, NULL, &swapChain1) != S_OK ||
  177. swapChain1->QueryInterface(IID_PPV_ARGS(&g_pSwapChain)) != S_OK)
  178. return E_FAIL;
  179. swapChain1->Release();
  180. dxgiFactory->Release();
  181. g_pSwapChain->SetMaximumFrameLatency(NUM_BACK_BUFFERS);
  182. g_hSwapChainWaitableObject = g_pSwapChain->GetFrameLatencyWaitableObject();
  183. }
  184. CreateRenderTarget();
  185. return S_OK;
  186. }
  187. void CleanupDeviceD3D()
  188. {
  189. CleanupRenderTarget();
  190. if (g_pSwapChain) { g_pSwapChain->Release(); g_pSwapChain = NULL; }
  191. if (g_hSwapChainWaitableObject != NULL) { CloseHandle(g_hSwapChainWaitableObject); }
  192. for (UINT i = 0; i < NUM_FRAMES_IN_FLIGHT; i++)
  193. if (g_frameContext[i].CommandAllocator) { g_frameContext[i].CommandAllocator->Release(); g_frameContext[i].CommandAllocator = NULL; }
  194. if (g_pd3dCommandQueue) { g_pd3dCommandQueue->Release(); g_pd3dCommandQueue = NULL; }
  195. if (g_pd3dCommandList) { g_pd3dCommandList->Release(); g_pd3dCommandList = NULL; }
  196. if (g_pd3dRtvDescHeap) { g_pd3dRtvDescHeap->Release(); g_pd3dRtvDescHeap = NULL; }
  197. if (g_pd3dSrvDescHeap) { g_pd3dSrvDescHeap->Release(); g_pd3dSrvDescHeap = NULL; }
  198. if (g_fence) { g_fence->Release(); g_fence = NULL; }
  199. if (g_fenceEvent) { CloseHandle(g_fenceEvent); g_fenceEvent = NULL; }
  200. if (g_pd3dDevice) { g_pd3dDevice->Release(); g_pd3dDevice = NULL; }
  201. }
  202. extern LRESULT ImGui_ImplWin32_WndProcHandler(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
  203. LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
  204. {
  205. if (ImGui_ImplWin32_WndProcHandler(hWnd, msg, wParam, lParam))
  206. return true;
  207. switch (msg)
  208. {
  209. case WM_SIZE:
  210. if (g_pd3dDevice != NULL && wParam != SIZE_MINIMIZED)
  211. {
  212. ImGui_ImplDX12_InvalidateDeviceObjects();
  213. CleanupRenderTarget();
  214. ResizeSwapChain(hWnd, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam));
  215. CreateRenderTarget();
  216. ImGui_ImplDX12_CreateDeviceObjects();
  217. }
  218. return 0;
  219. case WM_SYSCOMMAND:
  220. if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
  221. return 0;
  222. break;
  223. case WM_DESTROY:
  224. PostQuitMessage(0);
  225. return 0;
  226. }
  227. return DefWindowProc(hWnd, msg, wParam, lParam);
  228. }
  229. int main(int, char**)
  230. {
  231. // Create application window
  232. WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L, GetModuleHandle(NULL), NULL, NULL, NULL, NULL, _T("ImGui Example"), NULL };
  233. RegisterClassEx(&wc);
  234. HWND hwnd = CreateWindow(_T("ImGui Example"), _T("ImGui DirectX12 Example"), WS_OVERLAPPEDWINDOW, 100, 100, 1280, 800, NULL, NULL, wc.hInstance, NULL);
  235. // Initialize Direct3D
  236. if (CreateDeviceD3D(hwnd) < 0)
  237. {
  238. CleanupDeviceD3D();
  239. UnregisterClass(_T("ImGui Example"), wc.hInstance);
  240. return 1;
  241. }
  242. // Show the window
  243. ShowWindow(hwnd, SW_SHOWDEFAULT);
  244. UpdateWindow(hwnd);
  245. // Setup Dear ImGui binding
  246. IMGUI_CHECKVERSION();
  247. ImGui::CreateContext();
  248. ImGuiIO& io = ImGui::GetIO(); (void)io;
  249. //io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;
  250. //io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
  251. ImGui_ImplWin32_Init(hwnd);
  252. ImGui_ImplDX12_Init(g_pd3dDevice, NUM_FRAMES_IN_FLIGHT,
  253. DXGI_FORMAT_R8G8B8A8_UNORM,
  254. g_pd3dSrvDescHeap->GetCPUDescriptorHandleForHeapStart(),
  255. g_pd3dSrvDescHeap->GetGPUDescriptorHandleForHeapStart());
  256. // Setup style
  257. ImGui::StyleColorsDark();
  258. //ImGui::StyleColorsClassic();
  259. // Load Fonts
  260. // - If no fonts are loaded, dear imgui will use the default font. You can also load multiple fonts and use ImGui::PushFont()/PopFont() to select them.
  261. // - AddFontFromFileTTF() will return the ImFont* so you can store it if you need to select the font among multiple.
  262. // - If the file cannot be loaded, the function will return NULL. Please handle those errors in your application (e.g. use an assertion, or display an error and quit).
  263. // - The fonts will be rasterized at a given size (w/ oversampling) and stored into a texture when calling ImFontAtlas::Build()/GetTexDataAsXXXX(), which ImGui_ImplXXXX_NewFrame below will call.
  264. // - Read 'misc/fonts/README.txt' for more instructions and details.
  265. // - Remember that in C/C++ if you want to include a backslash \ in a string literal you need to write a double backslash \\ !
  266. //io.Fonts->AddFontDefault();
  267. //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Roboto-Medium.ttf", 16.0f);
  268. //io.Fonts->AddFontFromFileTTF("../../misc/fonts/Cousine-Regular.ttf", 15.0f);
  269. //io.Fonts->AddFontFromFileTTF("../../misc/fonts/DroidSans.ttf", 16.0f);
  270. //io.Fonts->AddFontFromFileTTF("../../misc/fonts/ProggyTiny.ttf", 10.0f);
  271. //ImFont* font = io.Fonts->AddFontFromFileTTF("c:\\Windows\\Fonts\\ArialUni.ttf", 18.0f, NULL, io.Fonts->GetGlyphRangesJapanese());
  272. //IM_ASSERT(font != NULL);
  273. bool show_demo_window = true;
  274. bool show_another_window = false;
  275. ImVec4 clear_color = ImVec4(0.45f, 0.55f, 0.60f, 1.00f);
  276. // Main loop
  277. MSG msg;
  278. ZeroMemory(&msg, sizeof(msg));
  279. while (msg.message != WM_QUIT)
  280. {
  281. // Poll and handle messages (inputs, window resize, etc.)
  282. // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your inputs.
  283. // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application.
  284. // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
  285. // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
  286. if (PeekMessage(&msg, NULL, 0U, 0U, PM_REMOVE))
  287. {
  288. TranslateMessage(&msg);
  289. DispatchMessage(&msg);
  290. continue;
  291. }
  292. // Start the ImGui frame
  293. ImGui_ImplDX12_NewFrame(g_pd3dCommandList);
  294. ImGui_ImplWin32_NewFrame();
  295. ImGui::NewFrame();
  296. // 1. Show a simple window.
  297. // Tip: if we don't call ImGui::Begin()/ImGui::End() the widgets automatically appears in a window called "Debug".
  298. {
  299. static float f = 0.0f;
  300. static int counter = 0;
  301. ImGui::Text("Hello, world!"); // Display some text (you can use a format string too)
  302. ImGui::SliderFloat("float", &f, 0.0f, 1.0f); // Edit 1 float using a slider from 0.0f to 1.0f
  303. ImGui::ColorEdit3("clear color", (float*)&clear_color); // Edit 3 floats representing a color
  304. ImGui::Checkbox("Demo Window", &show_demo_window); // Edit bools storing our windows open/close state
  305. ImGui::Checkbox("Another Window", &show_another_window);
  306. if (ImGui::Button("Button")) // Buttons return true when clicked (NB: most widgets return true when edited/activated)
  307. counter++;
  308. ImGui::SameLine();
  309. ImGui::Text("counter = %d", counter);
  310. ImGui::Text("Application average %.3f ms/frame (%.1f FPS)", 1000.0f / ImGui::GetIO().Framerate, ImGui::GetIO().Framerate);
  311. }
  312. // 2. Show another simple window. In most cases you will use an explicit Begin/End pair to name your windows.
  313. if (show_another_window)
  314. {
  315. ImGui::Begin("Another Window", &show_another_window);
  316. ImGui::Text("Hello from another window!");
  317. if (ImGui::Button("Close Me"))
  318. show_another_window = false;
  319. ImGui::End();
  320. }
  321. // 3. Show the ImGui demo window. Most of the sample code is in ImGui::ShowDemoWindow(). Read its code to learn more about Dear ImGui!
  322. if (show_demo_window)
  323. {
  324. ImGui::SetNextWindowPos(ImVec2(650, 20), ImGuiCond_FirstUseEver); // Normally user code doesn't need/want to call this because positions are saved in .ini file anyway. Here we just want to make the demo initial state a bit more friendly!
  325. ImGui::ShowDemoWindow(&show_demo_window);
  326. }
  327. // Rendering
  328. FrameContext* frameCtxt = WaitForNextFrameResources();
  329. UINT backBufferIdx = g_pSwapChain->GetCurrentBackBufferIndex();
  330. frameCtxt->CommandAllocator->Reset();
  331. D3D12_RESOURCE_BARRIER barrier = {};
  332. barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
  333. barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
  334. barrier.Transition.pResource = g_mainRenderTargetResource[backBufferIdx];
  335. barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
  336. barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT;
  337. barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET;
  338. g_pd3dCommandList->Reset(frameCtxt->CommandAllocator, NULL);
  339. g_pd3dCommandList->ResourceBarrier(1, &barrier);
  340. g_pd3dCommandList->ClearRenderTargetView(g_mainRenderTargetDescriptor[backBufferIdx], (float*)&clear_color, 0, NULL);
  341. g_pd3dCommandList->OMSetRenderTargets(1, &g_mainRenderTargetDescriptor[backBufferIdx], FALSE, NULL);
  342. g_pd3dCommandList->SetDescriptorHeaps(1, &g_pd3dSrvDescHeap);
  343. ImGui::Render();
  344. ImGui_ImplDX12_RenderDrawData(ImGui::GetDrawData());
  345. barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET;
  346. barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_PRESENT;
  347. g_pd3dCommandList->ResourceBarrier(1, &barrier);
  348. g_pd3dCommandList->Close();
  349. g_pd3dCommandQueue->ExecuteCommandLists(1, (ID3D12CommandList* const*)&g_pd3dCommandList);
  350. // Update and Render additional Platform Windows
  351. if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
  352. {
  353. ImGui::UpdatePlatformWindows();
  354. ImGui::RenderPlatformWindowsDefault();
  355. }
  356. g_pSwapChain->Present(1, 0); // Present with vsync
  357. //g_pSwapChain->Present(0, 0); // Present without vsync
  358. UINT64 fenceValue = g_fenceLastSignaledValue + 1;
  359. g_pd3dCommandQueue->Signal(g_fence, fenceValue);
  360. g_fenceLastSignaledValue = fenceValue;
  361. frameCtxt->FenceValue = fenceValue;
  362. }
  363. WaitForLastSubmittedFrame();
  364. ImGui_ImplDX12_Shutdown();
  365. ImGui_ImplWin32_Shutdown();
  366. ImGui::DestroyContext();
  367. CleanupDeviceD3D();
  368. DestroyWindow(hwnd);
  369. UnregisterClass(_T("ImGui Example"), wc.hInstance);
  370. return 0;
  371. }