22 std::expected<SwapChain, std::string>
SwapChain::Create(ID3D12Device* device, IDXGIFactory6* factory,
23 ID3D12CommandQueue* directQueue, HWND window,
24 uint32_t maxFrameLatency) {
27 const DXGI_SWAP_CHAIN_DESC1 desc{
31 .SampleDesc = {.Count = 1},
32 .BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT,
34 .Scaling = DXGI_SCALING_NONE,
35 .SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD,
36 .AlphaMode = DXGI_ALPHA_MODE_IGNORE,
37 .Flags = SWAP_CHAIN_FLAGS_BASE | (swapChain.
m_tearingSupported ? DXGI_SWAP_CHAIN_FLAG_ALLOW_TEARING : 0u),
40 ComPtr<IDXGISwapChain1> swapChain1;
41 HRESULT result = factory->CreateSwapChainForHwnd(directQueue, window, &desc,
nullptr,
nullptr, &swapChain1);
45 factory->MakeWindowAssociation(window, DXGI_MWA_NO_ALT_ENTER);
48 return std::unexpected(
"IDXGISwapChain3 が無い: " +
DescribeHresult(result));
50 result = swapChain.
m_swapChain->SetMaximumFrameLatency(maxFrameLatency);
52 return std::unexpected(
"先行するフレームの数を設定できない: " +
DescribeHresult(result));
56 const D3D12_DESCRIPTOR_HEAP_DESC heapDesc{.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV,
58 result = device->CreateDescriptorHeap(&heapDesc, IID_PPV_ARGS(&swapChain.
m_rtvHeap));
62 swapChain.
m_rtvStride = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
64 return std::unexpected(
"バックバッファを取れない");
static std::expected< SwapChain, std::string > Create(ID3D12Device *device, IDXGIFactory6 *factory, ID3D12CommandQueue *directQueue, HWND window, uint32_t maxFrameLatency)