0

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.

NmdMystery
  • 2,778
  • 3
  • 32
  • 60
  • Your initialization of Barrier looks kind of suspicious. Transition, Aliasing and UAV fields are members of union - only one of them has to be set. – c-smile Dec 12 '15 at 03:03
  • @c-smile Ah so it's a union... I removed them though, and it's still not working :/ – NmdMystery Dec 12 '15 at 03:47
  • What happens if you comment out **everything** from the command list and simply do `Reset` and then `Close`? – legalize Dec 14 '15 at 21:31
  • @legalize All methods return S_OK. – NmdMystery Dec 16 '15 at 06:15
  • OK, then by process of elimination, it's one of the commands you are adding to the command list. Comment out all but one of the commands, one by one, until you find the offending command. This is just debugging 101 here, nothing special to Direct3D. – legalize Dec 16 '15 at 17:39
  • @legalize I've already done that. There's only 2 commands besides the barriers, and as mentioned at the bottom of the question, I already know it's the barriers. But there's no information anywhere about why these barriers are wrong. – NmdMystery Dec 17 '15 at 02:37
  • You have no diagnostic messages in the [debug layer output](http://blogs.msdn.com/b/chuckw/archive/2012/11/30/direct3d-sdk-debug-layer-tricks.aspx)? – legalize Dec 17 '15 at 15:11
  • @legalize Nope, no messages at all. I know that I'm using the debug layer correctly because messages are being posted when I intentionally cause a different error. – NmdMystery Dec 17 '15 at 22:47
  • Update your code to include the full declaration of `Barriers` and any other statements that modify that variable. – legalize Dec 18 '15 at 21:09
  • Also, try creating a minimally complete verifiable example instead of a code snippet. – legalize Dec 18 '15 at 21:20
  • @legalize The only thing I do with the barrier structure beyond this code snippet is declare it. My minimally complete verifiable example is on github, as linked in the question (it doesn't get any smaller than that). – NmdMystery Dec 18 '15 at 21:56
  • IMO your "entire project on github" is not an [mcve](http://stackoverflow.com/help/mcve). Keep deleting code until absolutely nothing but your error remains. – legalize Dec 19 '15 at 00:33
  • @legalize The thing is in order to run this, you need to deal with DXGI, which is a lot of code. You need a window, you need a bunch of stuff before you can even call `Present()`. That's exactly what my library does, no less. If I were to make a unique mcve just for this question, it would maybe be 50 - 100 lines shorter, out of a few 1000s. Not only is it in an easily runnable form, the issue is highlighted because it's the only content in `Main.cpp`. Nothing would be gained from deleting anything, because the code that needs to be looked at is in one place. – NmdMystery Dec 19 '15 at 01:17
  • @legalize An mcve is more suitable for questions that deal with basic usage of the standard template library, or something like that. Those can be boiled down to 50 lines or less, this can't. The actual source of the problem can be anywhere, from me using the wrong version of DXGI to using the wrong swap effect... DirectX is just a pain sometimes. – NmdMystery Dec 19 '15 at 01:20
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/98389/discussion-between-nmdmystery-and-legalize). – NmdMystery Dec 19 '15 at 01:28
  • BTW, I've seen this ``E_INVALIDARG`` coming back from a ``Close`` during a 'lost device' case when I hadn't fully cleaned up all the resources when re-creating. – Chuck Walbourn Aug 17 '16 at 00:39
  • You should reset the command list first then reset the command allocator I guess – Max Hazard Apr 23 '18 at 02:59

0 Answers0