Saturday, December 29, 2018

Studying D3D12HelloWorld desktop project

Studying D3D12HelloWindow desktop project



D3D12HelloWorld

Main.cpp
  • There is WinMain() function, the entry point of the program.
  • Instanciate D3D12HelloWindow and pass it to Win32Application::Run() function.
Win32Application.cpp
  • Handles Windows API calls such as CreateWindow() and WindowProc() callback.
DXSample.cpp
  • DXSample::GetHardwareAdapter() calls D3D12CreateDevice to get ID3D12Device ptr.
  • ParseCommandLineArgs() reads argc and argv and decide to use Warp(reference rasterizer) or not.
D3D12HelloWindow.cpp
  • Contains interesting DirectX12 code.
  • D3D12HelloWindow::OnInit() prepares DirectX 12 resources.
  • D3D12HelloWindow::OnRender() redraws image of render buffer and swap foreground render buffer with background render buffer.

D3D12HelloWindow members


m_swapChain
  • Has two Output Render Targets, its size is window size and pixel format is RGBA8888
  • m_swapChain->Present() is called to swap front buffer and back buffer on the next display vbrank event. this mechanism exists to prevent 都creen tearing・ it happens when displaying render target is overwritten by graphics redraw.
m_commandQueue
  • prepared on D3D12HelloWindow::OnInit()
  • associated to m_swapChain for force flush. (?)
  • on OnRender() m_commandQueue->ExecuteCommandLists() is called.
  • m_commandQueue->Signal() is used to wait frame redraw update.
m_commandList
  • contains draw call to run on GPU.
  • ClearRenderTargetView() with blue color specified.


Render target state management

 It is necessary to change render target state to RENDER_TARGET before drawing and revert to PRESENT state when drawing finished.

m_commandList->ResourceBarrier() do this task.



Double Buffering




VBlank event waiting


D3D12HelloWindow.cpp implementation is not optimal. D3DHelloFrameBuffering is more efficient. So VBlank event waiting code review will be performed with D3DHelloFrameBuffering



Next: Draw a triangle!


https://yamamoto2002.blogspot.com/2018/12/studying-d3d12hellotriangle-project.html


No comments:

Post a Comment