1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| D3D12_RESOURCE_BARRIER barrierDesc = {}; barrierDesc.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION; barrierDesc.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE; barrierDesc.Transition.pResource = msaaRenderTarget; barrierDesc.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; barrierDesc.Transition.StateBefore = D3D12_RESOURCE_STATE_RESOLVE_SOURCE; barrierDesc.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET; cmdList->ResourceBarrier(1, &barrierDesc);
auto rtvH = msaaRTVHeap->GetCPUDescriptorHandleForHeapStart(); auto dsvH = msaaDSVHeap->GetCPUDescriptorHandleForHeapStart(); cmdList->ClearRenderTargetView(rtvH, Colors::LightSteelBlue, 0, nullptr); cmdList->ClearDepthStencilView(dsvH, D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAG_STENCIL, 1.0f, 0, 0, nullptr); cmdList->OMSetRenderTargets(1, &rtvH, true, &dsvH);
ID3D12DescriptorHeap* descriptorHeaps[] = {cbvHeap}; cmdList->SetGraphicsRootSignature(rootSignature); cmdList->SetDescriptorHeaps(_countof(descriptorHeaps), descriptorHeaps); cmdList->SetGraphicsRootDescriptorTable (0, cbvHeap->GetGPUDescriptorHandleForHeapStart());
cmdList->IASetVertexBuffers(0, 1, &vbView); cmdList->IASetIndexBuffer(&ibView); cmdList->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
cmdList->DrawIndexedInstanced(indices.size(), 1, 0, 0, 0);
barrierDesc.Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET; barrierDesc.Transition.StateAfter = D3D12_RESOURCE_STATE_RESOLVE_SOURCE; cmdList->ResourceBarrier(1, &barrierDesc);
D3D12_RESOURCE_BARRIER barriers[2] = { CD3DX12_RESOURCE_BARRIER::Transition( _msaaRenderTargetBuffer.Get(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_RESOLVE_SOURCE ), CD3DX12_RESOURCE_BARRIER::Transition( backBuffers[currentBackBuffer], D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RESOLVE_DEST ) }; cmdList->ResourceBarrier(2, &barriers);
cmdList->ResolveSubresource(backBuffers[currentBackBuffer], 0, msaaRenderTarget, 0, DXGI_FORMAT_R8G8B8A8_UNORM);
barrierDesc = CD3DX12_RESOURCE_BARRIER::Transition( backBuffers[currentBackBuffer], D3D12_RESOURCE_STATE_RESOLVE_DEST, D3D12_RESOURCE_STATE_PRESENT ); cmdList->ResourceBarrier (1, &barrierDesc);
cmdList->Close ();
ID3D12CommandList* cmdLists[] = {cmdList}; cmdQueue->ExecuteCommandLists (_countof (cmdLists), cmdLists);
swapChain->Present (0, 0); currentBackBuffer = (currentBackBuffer + 1) % 2;
cmdQueue->Signal (fence, ++fenceValue); if (fence->GetCompletedValue () != fenceValue) { auto event = CreateEvent (nullptr, false, false, nullptr); fence->SetEventOnCompletion (fenceValue, event); WaitForSingleObject (event, INFINITE); CloseHandle (event); }
|