I'm following the Rastertek Tutorials on Direct3D12, which can be found here.
I've double-checked to make sure all my code is the same as his, but I'm running into issues with the Command List. When I close the command list after just clearing the back buffer, the method ID3D12GraphicsCommandList::Close()
returns E_INVALIDARG
, which means that I've done something wrong during recording of the Command List. However, nothing I'm doing seems to be wrong.
D3D12_RESOURCE_BARRIER Barrier;
hr = CommandAllocator->Reset(); HANDLE_HR(__LINE__);
hr = CommandList->Reset (
CommandAllocator,
nullptr
); HANDLE_HR(__LINE__);
Barrier.Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE;
Barrier.Transition.pResource = RenderTargetResource[BufferIndex];
Barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_PRESENT;
Barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_RENDER_TARGET;
Barrier.Transition.Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES;
Barrier.Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION;
CommandList->ResourceBarrier(1, &Barrier);
RenderTargetViewPtr.ptr = RenderTargetViewHandle.ptr + BufferIndex * RenderTargetBytes;
CommandList->OMSetRenderTargets(1, &RenderTargetViewPtr, FALSE, nullptr);
FLOAT color[] = { 1.0, 1.0, 1.0, 1.0 };
CommandList->ClearRenderTargetView(RenderTargetViewHandle, color, 0, nullptr);
Barrier.Transition.StateBefore = D3D12_RESOURCE_STATE_RENDER_TARGET;
Barrier.Transition.StateAfter = D3D12_RESOURCE_STATE_PRESENT;
CommandList->ResourceBarrier(1, &Barrier);
hr = CommandList->Close(); HANDLE_HR(__LINE__);
The entirety of my project can be found at this github branch.
What is the issue with this code?
It seems like the resource barriers are the problem, but they're rather innocuous. Commenting out OMSetRenderTargets()
and ClearRenderTargetView()
still results in E_INVALIDARG
being returned from Close()
.
I've also tried using the ID3D12InfoQueue
interface to find out what the problem was. There are no messages in the queue when Close()
returns the error - I've checked to make sure the interface is working properly, since messages do show up when other errors occur.