ID3D12GraphicsCommandList::Close() returns E_INVALIDARG - c++

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.

Related

Vulkan CommandBuffer in use after vkDeviceWait Idle

During initialization of my program I want to use some single time command buffers for image layout transitions and acceleration structure building etc.
However, I can't seem to free the command buffer once it's finished.
VkCommandBuffer AppContext::singleTimeCommandBuffer() const {
VkCommandBuffer ret;
auto allocInfo = vks::initializers::commandBufferAllocateInfo(vkCommandPool, VK_COMMAND_BUFFER_LEVEL_PRIMARY, 1);
vkCheck(vkAllocateCommandBuffers(vkDevice, &allocInfo, &ret));
auto beginInfo = vks::initializers::commandBufferBeginInfo();
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
vkCheck(vkBeginCommandBuffer(ret, &beginInfo));
return ret;
}
void AppContext::endSingleTimeCommands(VkCommandBuffer cmdBuffer) const {
vkCheck(vkEndCommandBuffer(cmdBuffer));
auto submitInfo = vks::initializers::submitInfo(&cmdBuffer);
vkQueueSubmit(queues.graphics, 1, &submitInfo, VK_NULL_HANDLE);
vkQueueWaitIdle(queues.graphics);
// Overkill, I know
vkDeviceWaitIdle(vkDevice);
vkFreeCommandBuffers(vkDevice, vkCommandPool, 1, &cmdBuffer);
}
Which produces the following validation error:
VUID-vkFreeCommandBuffers-pCommandBuffers-00047(ERROR / SPEC): msgNum: 448332540 - Validation Error: [ VUID-vkFreeCommandBuffers-pCommandBuffers-00047 ] Object 0: handle = 0x5586acaeff78, type = VK_OBJECT_TYPE_COMMAND_BUFFER; | MessageID = 0x1ab902fc | Attempt to free VkCommandBuffer 0x5586acaeff78[] which is in use. The Vulkan spec states: All elements of pCommandBuffers must not be in the pending state (https://vulkan.lunarg.com/doc/view/1.2.182.0/linux/1.2-extensions/vkspec.html#VUID-vkFreeCommandBuffers-pCommandBuffers-00047)
Objects: 1
[0] 0x5586acaeff78, type: 6, name: NULL
I don't see how this makes sense since the VkQueueWaitIdle as well as the vkDeviceWaitIdle should ensure the command buffer to not be in the pending state. Am I misunderstanding the Vulkan specs or might I have stumbled upon a bug in the video driver, or perhaps the validation layer?
You aren't checking the return values of vkQueueSubmit(), vkQueueWaitIdle() or vkDeviceWaitIdle(). Are any of them failing? That could cause this error.

CreateDepthStencilView() is failing

I'm trying to create a shadow map in my DirectX application, but currently having trouble when creating the Depth Stencil view. CreateDepthStencilView() is leaving my ID3D11DepthStencilView* variable as NULL.
The only error I've managed to get from the HRESULT is "The parameter is incorrect". It seems the problem is with both the D3D11_TEXTURE2D_DESC and the ID3D11_DEPTH_STENCIL_VIEW_DESC as when I've replaced them with the depth texture and nullptr respectively, it works. I then replaced the working function parameters with the shadow map values one at a time and it did not work with either.
I have also tried setting shadowDsv.Flags = 0 , as suggested in this post, but had the same result.
I'm following this tutorial, the code is the same as his (except mine is DX11 not DX10), I'm unsure what the problem could be. This is my code:
Application.h
ID3D11Texture2D* _shadowMapTexture;
ID3D11DepthStencilView* _shadowMapStencil;
ID3D11ShaderResourceView* _shadowMapRV;
Application.cpp
//Set up shadow map
D3D11_TEXTURE2D_DESC shadowTexDesc;
shadowTexDesc.Width = _WindowWidth;
shadowTexDesc.Height = _WindowHeight;
shadowTexDesc.MipLevels = 1;
shadowTexDesc.ArraySize = 1;
shadowTexDesc.Format = DXGI_FORMAT_R32_TYPELESS;
shadowTexDesc.SampleDesc.Count = 1;
shadowTexDesc.SampleDesc.Quality = 0;
shadowTexDesc.Usage = D3D11_USAGE_DEFAULT;
shadowTexDesc.BindFlags = D3D11_BIND_DEPTH_STENCIL | D3D11_BIND_SHADER_RESOURCE;
shadowTexDesc.CPUAccessFlags = 0;
shadowTexDesc.MiscFlags = 0;
D3D11_DEPTH_STENCIL_VIEW_DESC shadowDsv;
shadowDsv.Format = shadowTexDesc.Format;
shadowDsv.ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
shadowDsv.Texture2D.MipSlice = 0;
D3D11_SHADER_RESOURCE_VIEW_DESC shadowSrv;
shadowSrv.Format = DXGI_FORMAT_R32_FLOAT;
shadowSrv.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
shadowSrv.Texture2D.MipLevels = shadowTexDesc.MipLevels;
shadowSrv.Texture2D.MostDetailedMip = 0;
hr = _pd3dDevice->CreateTexture2D(&shadowTexDesc, nullptr, &_shadowMapTexture);
hr = _pd3dDevice->CreateDepthStencilView(_shadowMapTexture, &shadowDsv, &_shadowMapStencil);
hr = _pd3dDevice->CreateShaderResourceView(_shadowMapTexture, &shadowSrv, &_shadowMapRV);
EDIT:
This is the console output when CreateDepthStencilView() is called. Thank you for the help so far.
D3D11 ERROR: ID3D11Device::CreateDepthStencilView: The Format (0x27, R32_TYPELESS) is invalid, when creating a View; it is not a fully qualified Format castable from the Format of the Resource (0x27, R32_TYPELESS). [ STATE_CREATION ERROR #144: CREATEDEPTHSTENCILVIEW_INVALIDFORMAT]
D3D11 ERROR: ID3D11Device::CreateDepthStencilView: The format (0x27, R32_TYPELESS) cannot be used with a DepthStencil view. [ STATE_CREATION ERROR #144: CREATEDEPTHSTENCILVIEW_INVALIDFORMAT]
D3D11 ERROR: ID3D11Device::CreateDepthStencilView: There were unrecognized flags specified in the DepthStencilView Flags field. The flags value was 0xcccccccc, while the valid flags are limited to 0x3. [ STATE_CREATION ERROR #2097153: CREATEDEPTHSTENCILVIEW_INVALIDFLAGS]
Exception thrown at 0x76D235D2 in DX11 Framework.exe: Microsoft C++ exception: _com_error at memory location 0x00B3EE98.
D3D11 ERROR: ID3D11Device::CreateDepthStencilView: Returning E_INVALIDARG, meaning invalid parameters were passed. [ STATE_CREATION ERROR #148: CREATEDEPTHSTENCILVIEW_INVALIDARG_RETURN]
It seems the R32_TYPELESS format is what's causing the error. After looking at the documentation I see there are only a few allowable formats. Does anyone recommend a specific format for a shadow map? I've not done this before so unsure if any of the following would be a good subsitute:
DXGI_FORMAT_D16_UNORM
DXGI_FORMAT_D24_UNORM_S8_UINT
DXGI_FORMAT_D32_FLOAT
DXGI_FORMAT_D32_FLOAT_S8X24_UINT
DXGI_FORMAT_UNKNOWN
Thanks again :)
To anyone else having this problem: my fix was to set the D3D11_DEPTH_STENCIL_VIEW_DESC format to DXGI_FORMAT_D32_FLOAT, and the D3D11_DEPTH_STENCIL_VIEW_DESC Flags equal to 0.

Reforging (Rochet2) to AzerothCore

Does anyone has already successfully added Rochet2's Reforging script on AC ?
Mine works but not completely.
On character login the script should re-apply bonuses on reforged (& equipped) items, but it seems "player->GetItemByGuid()" can't find the requested item, so it's returning nothing.
TrinityCore code (works) :
uint32 lowGUID = (*result)[0].GetUInt32();
Item* invItem = player->GetItemByGuid(ObjectGuid(HighGuid::Item, 0, lowGUID));
if (invItem)
player->_ApplyItemMods(invItem, invItem->GetSlot(), false);
ReforgeData& data = player->reforgeMap[lowGUID];
data.increase = (*result)[1].GetUInt32();
data.decrease = (*result)[2].GetUInt32();
data.stat_value = (*result)[3].GetInt32();
if (invItem)
player->_ApplyItemMods(invItem, invItem->GetSlot(), true);
AzerothCore code (works, but "if (invItem)" condition never satisfied.
uint32 lowGUID = (*result)[0].GetUInt32();
Item* invItem = player->GetItemByGuid((uint64) MAKE_NEW_GUID(HIGHGUID_ITEM, 0, lowGUID));
if (invItem /*&& invItem->IsEquipped()*/)
player->_ApplyItemMods(invItem, invItem->GetSlot(), false);
ReforgeData& data = player->reforgeMap[lowGUID];
data.increase = (*result)[1].GetUInt32();
data.decrease = (*result)[2].GetUInt32();
data.stat_value = (*result)[3].GetInt32();
if (invItem /*&& invItem->IsEquipped()*/)
player->_ApplyItemMods(invItem, invItem->GetSlot(), true);
MAKE_NEW_GUID() returns something that looks like a guid.
But I don't know why "player->GetItemByGuid()" can't find the item.
The order of arguments to MAKE_NEW_GUID is different from ObjectGuid constructor. So since your arguments are in wrong order then the result is also wrong and item is not found. See the definition and use of MAKE_NEW_GUID for the correct order of arguments.

DirectX12 commandList execution error

I've started to learn DirectX12 and i try to make some kind of simple engine.
I follow the Frank D. Luna "Introduction to 3D programming with DirectX12" and i have got some problems.
First during creating swapChain, filling description like this:
DXGI_SWAP_CHAIN_DESC swapChainDesc;
swapChainDesc.BufferDesc.Width = Core::displayWidth;
swapChainDesc.BufferDesc.Height = Core::displayHeight;
swapChainDesc.BufferDesc.RefreshRate.Numerator = 60;
swapChainDesc.BufferDesc.RefreshRate.Denominator = 1;
swapChainDesc.BufferDesc.Format = Core::pixelDefinitionFormat;
swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
swapChainDesc.SampleDesc.Count = Core::multiSamplingLevel ? 4 : 1;
swapChainDesc.SampleDesc.Quality = Core::multiSamplingEnabled ? (Core::multiSamplingLevel - 1) : 0;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
swapChainDesc.BufferCount = (INT) Core::buffering;
swapChainDesc.OutputWindow = Core::mainWindow;
swapChainDesc.Windowed = true;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
// Note: Swap chain uses queue to perform flush.
ThrowIfFailed(Core::factory->CreateSwapChain(
Core::commandQueue.Get(),
&swapChainDesc,
Core::swapChain.GetAddressOf()
));
I recive "bad parameter" error. I've already found solution on MSDN but i want to know what i'am doing wrong.
Second question is why have i:
D3D12 ERROR: ID3D12GraphicsCommandList::*: A single command list cannot write to multiple buffers within a particular swapchain. [ STATE_SETTING ERROR #904: COMMAND_LIST_MULTIPLE_SWAPCHAIN_BUFFER_REFERENCES]
Durning execution of this clearing screen code fragment:
void Renderer::drawSomething() {
// Reuse the memory associated with command recording.
// We can only reset when the associated command lists have finished
// execution on the GPU.
ThrowIfFailed(Core::commandAllocator->Reset());
// A command list can be reset after it has been added to the 
// command queue via ExecuteCommandList. Reusing the command list reuses memory.
ThrowIfFailed(Core::commandList->Reset(Core::commandAllocator.Get(), NULL));
// Set the viewport and scissor rect. This needs to be reset 
// whenever the command list is reset.
Core::commandList->RSSetViewports(1, &Core::viewport);
Core::commandList->RSSetScissorRects(1, &Core::scissorsRectangle);
// Indicate a state transition on the resource usage.
Core::commandList->ResourceBarrier(
1,
&CD3DX12_RESOURCE_BARRIER::Transition(
Core::getCurrentBackBuffer().Get(),
D3D12_RESOURCE_STATES::D3D12_RESOURCE_STATE_PRESENT,
D3D12_RESOURCE_STATES::D3D12_RESOURCE_STATE_RENDER_TARGET
)
);
// Specify the buffers we are going to render to.
Core::commandList->OMSetRenderTargets(
1,
&Core::getCurrentBackBufferView(),
true,
&Core::getDSVHeapStartDescriptorHandle()
);
// Clear the back buffer and depth buffer.
Core::commandList->ClearRenderTargetView(
Core::getCurrentBackBufferView(),
DirectX::Colors::LightSteelBlue,
0,
NULL
);
Core::commandList->ClearDepthStencilView(
Core::getDSVHeapStartDescriptorHandle(),
D3D12_CLEAR_FLAGS::D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAGS::D3D12_CLEAR_FLAG_STENCIL,
1.0f,
0,
0,
NULL
);
//// Indicate a state transition on the resource usage.
Core::commandList->ResourceBarrier(
1,
&CD3DX12_RESOURCE_BARRIER::Transition(
Core::getCurrentBackBuffer().Get(),
D3D12_RESOURCE_STATES::D3D12_RESOURCE_STATE_RENDER_TARGET,
D3D12_RESOURCE_STATES::D3D12_RESOURCE_STATE_PRESENT
)
);
// Done recording commands.
ThrowIfFailed(Core::commandList->Close());
// Add the command list to the queue for execution.
ID3D12CommandList* cmdsLists[] = {Core::commandList.Get()};
Core::commandQueue->ExecuteCommandLists(_countof(cmdsLists), cmdsLists);
// swap the back and front buffers
ThrowIfFailed(Core::swapChain->Present(0, 0));
UINT buffering = Core::buffering;
Core::currentBackBuffer = (Core::currentBackBuffer + 1) % buffering;
Core::flushCommandQueue();
}
To not making big mess in this post, i won't place all code here, but if you would like to look how does it look like, or it would be important in this case, my whole repository is here:
repository
It's very small and simlple, almost all code is placed in Core class.
Thank you in advance!
Edit:
I found solution to second question.
Problem was in this loop:
void Core::createSwapChainBuffersIntoRTVHeap() {
for (UINT i = 0; i < Core::buffering; i++) {
CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHeapHandle(rtvDescriptorHeap->GetCPUDescriptorHandleForHeapStart());
ErrorUtils::messageAndExitIfFailed(
swapChain->GetBuffer(i, IID_PPV_ARGS(&swapChainBackBuffers[i])),
L"B³¹d pobierania backBuffera!",
GET_SWAPCHAIN_BACK_BUFFER_ERROR
);
device->CreateRenderTargetView(swapChainBackBuffers[i].Get(), NULL, rtvHeapHandle);
//Zapamiêtuje offset, to jest sterta po prostu zwyk³a
rtvHeapHandle.Offset(1, rtvDescriptorSize);
}
}
I did only one move to made this code look like this:
void Core::createSwapChainBuffersIntoRTVHeap() {
CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHeapHandle(rtvDescriptorHeap->GetCPUDescriptorHandleForHeapStart());
for (UINT i = 0; i < Core::buffering; i++) {
ErrorUtils::messageAndExitIfFailed(
swapChain->GetBuffer(i, IID_PPV_ARGS(&swapChainBackBuffers[i])),
L"B³¹d pobierania backBuffera!",
GET_SWAPCHAIN_BACK_BUFFER_ERROR
);
device->CreateRenderTargetView(swapChainBackBuffers[i].Get(), NULL, rtvHeapHandle);
//Zapamiêtuje offset, to jest sterta po prostu zwyk³a
rtvHeapHandle.Offset(1, rtvDescriptorSize);
}
}
After that. When the commandList closing gone right, i've got AccessViolationException in D3D12.dll on:
ThrowIfFailed(Core::swapChain->Present(0, 0));
Which after few hours of internet research i fixed by forcing WARP on this application using "dxcpl.exe".
I assume that was because i work on laptop with HD4000 and Nvidia as second card, but i'm not sure.
This will not help you to fix the problem at once, but will give you much more information. DirectX12 wants you to push all commands into commandlists and it will only report an error when you call Close() on it. Note that you can not "resurrect" the commandlist that failed on Close() by resetting it, the best thing you can do is to delete it and then create a new commandlist. In this case you however may not update referenced resources. Don't really recommend you doing that.
What you indeed can do is to use the ID3D12InfoQueue interface to make your program break on D3D12 errors if the debugger is attached.
Get it from your device:
ID3D12InfoQueue* InfoQueue = nullptr;
Core::device->QueryInterface(IID_PPV_ARGS(&InfoQueue));
Enable "break on severity":
InfoQueue->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_ERROR, true);
InfoQueue->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_CORRUPTION, true);
InfoQueue->SetBreakOnSeverity(D3D12_MESSAGE_SEVERITY_WARNING, false);
And let it go:
InfoQueue->Release();
You can also set your InfoQueue to whitelist or blacklist sets of D3D12 error ids. Your error ID is D3D12_MESSAGE_ID_COMMAND_LIST_MULTIPLE_SWAPCHAIN_BUFFER_REFERENCES (code 904).
Hope that this will help someone to deal with this graphics API.

TaskDialogIndirect is returning an unusual error code

I'm using TaskDialogIndirect to display prompts to the user. Normally this works just fine, but sometimes, after the program has been running for a while, it begins returning an error code that the MSDN entry does not list as being one of the error codes this function can return.
0x80040001 OLE_E_ADVF "Invalid advise flags"
I have checked all the inputs to the function against previous successful calls in the same run. Aside from differences in the string to be displayed, they are identical. (the strings are even the same length.)
// create task dialog struct
TASKDIALOGCONFIG tdc;
ZeroMemory(&tdc, sizeof(TASKDIALOGCONFIG));
tdc.cbSize = sizeof(tdc);
tdc.dwFlags = (((dwMessageBoxFlags & MB_OKCANCEL) == MB_OKCANCEL) ? TDF_ALLOW_DIALOG_CANCELLATION : 0) | TDF_POSITION_RELATIVE_TO_WINDOW;
tdc.hwndParent = hwndOwner;
tdc.hInstance = LGetHInstance();
tdc.pszContent = usrText.wsz;
tdc.pButtons = _pButtons;
tdc.cButtons = nButtons;
tdc.pszMainIcon = pszTaskDialogIcon;
tdc.pszWindowTitle = usrCaption.wsz;
tdc.nDefaultButton = nDefaultButton;
// display it now
int iButton = 0;
BOOL b = 0;
HRESULT hResult = TaskDialogIndirect(&tdc, &iButton, NULL, &b);
NEW INFORMATION
At the same time that TaskDialogIndirect stops behaving correctly, ShellExecute also stops working, as does CreateFile.
This was actually caused by an event handle leak elsewhere. When the available handles ran out, no more API calls which needed to create a handle could succeed. They did return a rather odd set of error codes though, none of which was "out of handles".