public void CreateAccelerationStructures() { acs = new AccelerationStructures(); long mTlasSize = 0; ID3D12Resource[] mpVertexBuffer = new ID3D12Resource[2]; mpVertexBuffer[0] = acs.CreateTriangleVB(mpDevice); mpVertexBuffer[1] = acs.CreatePlaneVB(mpDevice); // The first bottom-level buffer is for the plane and the triangle int[] vertexCount = new int[] { 3, 6 }; // Triangle has 3 vertices, plane has 6 AccelerationStructureBuffers[] bottomLevelBuffers = new AccelerationStructureBuffers[2]; bottomLevelBuffers[0] = acs.CreateBottomLevelAS(mpDevice, mpCmdList, mpVertexBuffer, vertexCount, 2); mpBottomLevelAS = new ID3D12Resource[2]; mpBottomLevelAS[0] = bottomLevelBuffers[0].pResult; // The second bottom-level buffer is for the triangle only bottomLevelBuffers[1] = acs.CreateBottomLevelAS(mpDevice, mpCmdList, mpVertexBuffer, vertexCount, 1); mpBottomLevelAS[1] = bottomLevelBuffers[1].pResult; // Create the TLAS AccelerationStructureBuffers topLevelBuffers = acs.CreateTopLevelAS(mpDevice, mpCmdList, mpBottomLevelAS, ref mTlasSize); // The tutorial doesn't have any resource lifetime management, so we flush and sync here. This is not required by the DXR spec - you can submit the list whenever you like as long as you take care of the resources lifetime. mFenceValue = context.SubmitCommandList(mpCmdList, mpCmdQueue, mpFence, mFenceValue); mpFence.SetEventOnCompletion(mFenceValue, mFenceEvent); mFenceEvent.WaitOne(); int bufferIndex = mpSwapChain.GetCurrentBackBufferIndex(); mpCmdList.Reset(mFrameObjects[0].pCmdAllocator, null); // Store the AS buffers. The rest of the buffers will be released once we exit the function mpTopLevelAS = topLevelBuffers.pResult; }
public void CreateAccelerationStructures() { acs = new AccelerationStructures(); long mTlasSize = 0; var mpVertexBuffer = acs.CreateTriangleVB(mpDevice); AccelerationStructureBuffers bottomLevelBuffers = acs.CreateBottomLevelAS(mpDevice, mpCmdList, mpVertexBuffer); AccelerationStructureBuffers topLevelBuffers = acs.CreateTopLevelAS(mpDevice, mpCmdList, bottomLevelBuffers.pResult, ref mTlasSize); // The tutorial doesn't have any resource lifetime management, so we flush and sync here. This is not required by the DXR spec - you can submit the list whenever you like as long as you take care of the resources lifetime. mFenceValue = context.SubmitCommandList(mpCmdList, mpCmdQueue, mpFence, mFenceValue); mpFence.SetEventOnCompletion(mFenceValue, mFenceEvent); mFenceEvent.WaitOne(); int bufferIndex = mpSwapChain.GetCurrentBackBufferIndex(); mpCmdList.Reset(mFrameObjects[0].pCmdAllocator, null); // Store the AS buffers. The rest of the buffers will be released once we exit the function mpTopLevelAS = topLevelBuffers.pResult; mpBottomLevelAS = bottomLevelBuffers.pResult; }