* Builds the frame's DXR command list. */
| 1655 | * Builds the frame's DXR command list. |
| 1656 | */ |
| 1657 | void BuildCommandList(D3D12Global &d3d, DXRGlobal &dxr, D3D12Resources &resources, Gui* gui, InputInfo* input) |
| 1658 | { |
| 1659 | D3D12_RESOURCE_BARRIER Barriers[3] = {}; |
| 1660 | |
| 1661 | // Transition the back buffer to a copy destination |
| 1662 | Barriers[0].Transition.pResource = d3d.backBuffer[d3d.frameIndex]; |
| 1663 | Barriers[0].Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT; |
| 1664 | Barriers[0].Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_DEST; |
| 1665 | Barriers[0].Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; |
| 1666 | |
| 1667 | // Transition the DXR output buffer to a copy source |
| 1668 | Barriers[1].Transition.pResource = resources.DXROutput; |
| 1669 | Barriers[1].Transition.StateBefore = D3D12_RESOURCE_STATE_COPY_SOURCE; |
| 1670 | Barriers[1].Transition.StateAfter = D3D12_RESOURCE_STATE_UNORDERED_ACCESS; |
| 1671 | Barriers[1].Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES; |
| 1672 | |
| 1673 | // Transition the DXR output buffer to a copy source |
| 1674 | Barriers[2].UAV.pResource = resources.accumulationBuffer; |
| 1675 | Barriers[2].Type = D3D12_RESOURCE_BARRIER_TYPE_UAV; |
| 1676 | Barriers[2].Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE; |
| 1677 | |
| 1678 | // Wait for the transitions to complete |
| 1679 | d3d.cmdList->ResourceBarrier(_countof(Barriers), Barriers); |
| 1680 | |
| 1681 | // Set the UAV/SRV/CBV heap |
| 1682 | ID3D12DescriptorHeap* ppHeaps[] = { resources.descriptorHeap }; |
| 1683 | d3d.cmdList->SetDescriptorHeaps(_countof(ppHeaps), ppHeaps); |
| 1684 | d3d.cmdList->SetComputeRootSignature(dxr.globalRootSignature); |
| 1685 | d3d.cmdList->SetComputeRootDescriptorTable(0, resources.descriptorHeap->GetGPUDescriptorHandleForHeapStart()); |
| 1686 | |
| 1687 | // Dispatch rays |
| 1688 | D3D12_DISPATCH_RAYS_DESC desc = {}; |
| 1689 | desc.MissShaderTable.StartAddress = dxr.shaderTable->GetGPUVirtualAddress(); |
| 1690 | desc.MissShaderTable.SizeInBytes = UINT64(dxr.shaderTableRecordSize) * 2; //< Two Miss programs (normal & shadows) |
| 1691 | desc.MissShaderTable.StrideInBytes = dxr.shaderTableRecordSize; |
| 1692 | |
| 1693 | desc.HitGroupTable.StartAddress = dxr.shaderTable->GetGPUVirtualAddress() + (UINT64(dxr.shaderTableRecordSize) * 2); //< Higroups start after 2 other records (miss shaders) |
| 1694 | desc.HitGroupTable.SizeInBytes = UINT64(dxr.shaderTableRecordSize) * 2; //< Two hit groups (normal & shadows) |
| 1695 | desc.HitGroupTable.StrideInBytes = dxr.shaderTableRecordSize; |
| 1696 | |
| 1697 | desc.RayGenerationShaderRecord.StartAddress = dxr.shaderTable->GetGPUVirtualAddress() + (UINT64(dxr.shaderTableRecordSize) * 4);//< Raygen starts after 4 other records |
| 1698 | desc.RayGenerationShaderRecord.SizeInBytes = dxr.shaderTableRecordSize; //< One raygen shader |
| 1699 | |
| 1700 | desc.Width = d3d.width; |
| 1701 | desc.Height = d3d.height; |
| 1702 | desc.Depth = 1; |
| 1703 | |
| 1704 | d3d.cmdList->SetPipelineState1(dxr.rtpso); |
| 1705 | d3d.cmdList->DispatchRays(&desc); |
| 1706 | |
| 1707 | // Transition DXR output to a copy source |
| 1708 | Barriers[1].Transition.StateBefore = D3D12_RESOURCE_STATE_UNORDERED_ACCESS; |
| 1709 | Barriers[1].Transition.StateAfter = D3D12_RESOURCE_STATE_COPY_SOURCE; |
| 1710 | |
| 1711 | // Wait for the transitions to complete |
| 1712 | d3d.cmdList->ResourceBarrier(1, &Barriers[1]); |
| 1713 | |
| 1714 | // Copy the DXR output to the back buffer |
no test coverage detected