DirectX 12 – Modern High‑Performance Graphics
Welcome to the discussion thread for DirectX 12. Below you will find an overview, sample code snippets, and a place to ask questions or share tips with the community.
Key Features
- Explicit multi‑GPU support
- Reduced driver overhead
- Low‑level resource management
- Enhanced threading and command-list capabilities
Sample: Creating a Device and Swap Chain
// Initialize COM
CoInitializeEx(nullptr, COINITBASE_MULTITHREADED);
// Create DXGI Factory
IDXGIFactory4* factory = nullptr;
CreateDXGIFactory1(IID_PPV_ARGS(&factory));
// Choose adapter
IDXGIAdapter1* adapter = nullptr;
factory->EnumAdapters1(0, &adapter);
// Create device
ID3D12Device* device = nullptr;
D3D12CreateDevice(adapter, D3D_FEATURE_LEVEL_12_0, IID_PPV_ARGS(&device));
// Describe and create the swap chain
DXGI_SWAP_CHAIN_DESC1 swapDesc = {};
swapDesc.BufferCount = 2;
swapDesc.Width = 1280;
swapDesc.Height = 720;
swapDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
swapDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
swapDesc.SampleDesc.Count = 1;
IDXGISwapChain1* swapChain = nullptr;
factory->CreateSwapChainForHwnd(
commandQueue,
hwnd,
&swapDesc,
nullptr,
nullptr,
&swapChain);
CommandQueue::SignalandCommandQueue::Waitcorrectly. It helped me a lot.