Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: DX3D12 crash in Debug mode #3176

Closed
etodanik opened this issue Sep 20, 2023 · 7 comments · Fixed by #3222
Closed

Bug: DX3D12 crash in Debug mode #3176

etodanik opened this issue Sep 20, 2023 · 7 comments · Fixed by #3222

Comments

@etodanik
Copy link

etodanik commented Sep 20, 2023

Describe the bug
bgfx crashes in Debug mode when using DX3D12.

Crash log is:
Exception: Exception 0xc0000409 encountered at address 0x7ffd0164f61e (ucrtbase.dll)

This issue is related to #3059 which for some reason was erroneously disregarded as not a bug and moved to discussions as a question. This is most certainly, however, a bug.

To Reproduce
Steps to reproduce the behavior:

  1. Open any of the examples, and set init.type = bgfx::RendererType::Direct3D12;
  2. Try to run in Release mode: It works
  3. Try to run in Debug mode: It crashes

Expected behavior
It should work both in Release & Debug

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Windows, Nvidia RTX 4090 with latest drivers bgfx from master branch.

@bkaradzic
Copy link
Owner

This issue is related to #3059 which for some reason was erroneously disregarded as not a bug and moved to discussions as a question. This is most certainly, however, a bug.

Provide full stack.

@etodanik
Copy link
Author

etodanik commented Sep 20, 2023

 	ucrtbase.dll!abort()	Unknown
 	ucrtbase.dll!terminate()	Unknown
 	ucrtbase.dll!FindHandler<__FrameHandler3>()	Unknown
 	ucrtbase.dll!__InternalCxxFrameHandler<class __FrameHandler3>(struct EHExceptionRecord *,unsigned __int64 *,struct _CONTEXT *,struct _xDISPATCHER_CONTEXT *,struct _s_FuncInfo const *,int,unsigned __int64 *,unsigned char)	Unknown
 	ucrtbase.dll!__CxxFrameHandler3()	Unknown
 	ntdll.dll!RtlpExecuteHandlerForException()	Unknown
 	ntdll.dll!RtlDispatchException()	Unknown
 	ntdll.dll!KiUserExceptionDispatch()	Unknown
 	KernelBase.dll!RaiseException()	Unknown
 	ucrtbase.dll!_CxxThrowException()	Unknown
 	d3d12SDKLayers.dll!std::_Throw_bad_optional_access(void)	Unknown
 	d3d12SDKLayers.dll!NDebug::CCommandQueue::ValidateResourceStateBarriers(class NDebug::CInterfaceSentinel::CFunctionSentinel &,class NDebug::CCastableCommandList<struct ID3D12CommandList> *,class NDebug::CCastableCommandList<struct ID3D12CommandList> *)	Unknown
 	d3d12SDKLayers.dll!NDebug::CCommandQueue::ExecuteCommandListsImpl(class NDebug::CInterfaceSentinel::CFunctionSentinel &,unsigned int,struct ID3D12CommandList * const *,class NDebug::CCastableCommandList<struct ID3D12CommandList> * const *)	Unknown
 	d3d12SDKLayers.dll!NDebug::CCommandQueue::ExecuteCommandLists(unsigned int,struct ID3D12CommandList * const *)	Unknown
>	example-00-helloworldDebug.exe!bgfx::d3d12::CommandQueueD3D12::kick() Line 4043	C++
 	example-00-helloworldDebug.exe!bgfx::d3d12::RendererContextD3D12::submit(bgfx::Frame * _render, bgfx::ClearQuad & __formal, bgfx::TextVideoMemBlitter & _textVideoMemBlitter) Line 6498	C++
 	example-00-helloworldDebug.exe!bgfx::Context::renderFrame(int _msecs) Line 2471	C++
 	example-00-helloworldDebug.exe!bgfx::renderFrame(int _msecs) Line 1491	C++
 	example-00-helloworldDebug.exe!entry::Context::run(int _argc, const char * const * _argv) Line 523	C++
 	example-00-helloworldDebug.exe!main(int _argc, const char * const * _argv) Line 1192	C++
 	example-00-helloworldDebug.exe!invoke_main() Line 79	C++
 	example-00-helloworldDebug.exe!__scrt_common_main_seh() Line 288	C++
 	example-00-helloworldDebug.exe!__scrt_common_main() Line 331	C++
 	example-00-helloworldDebug.exe!mainCRTStartup(void * __formal) Line 17	C++
 	kernel32.dll!BaseThreadInitThunk()	Unknown
 	ntdll.dll!RtlUserThreadStart()	Unknown


image

EDIT:
If it's helpful, I'm also attaching my DXDiag output
DxDiag.txt

EDIT 2:
The same project builds and runs absolutely fine on D3D12 on Release configuration:
image

@bkaradzic
Copy link
Owner

There is bug in those validation layers. So you can disable validation and it will work.

Here:

 	KernelBase.dll!RaiseException()	Unknown
 	ucrtbase.dll!_CxxThrowException()	Unknown
 	d3d12SDKLayers.dll!std::_Throw_bad_optional_access(void)	Unknown
>>>> 	d3d12SDKLayers.dll!NDebug::CCommandQueue::ValidateResourceStateBarriers(class NDebug::CInterfaceSentinel::CFunctionSentinel &,class NDebug::CCastableCommandList<struct ID3D12CommandList> *,class NDebug::CCastableCommandList<struct ID3D12CommandList> *)	Unknown
 	d3d12SDKLayers.dll!NDebug::CCommandQueue::ExecuteCommandListsImpl(class NDebug::CInterfaceSentinel::CFunctionSentinel &,unsigned int,struct ID3D12CommandList * const *,class NDebug::CCastableCommandList<struct ID3D12CommandList> * const *)	Unknown
 	d3d12SDKLayers.dll!NDebug::CCommandQueue::ExecuteCommandLists(unsigned int,struct ID3D12CommandList * const *)	Unknown

@etodanik
Copy link
Author

There is bug in those validation layers. So you can disable validation and it will work.

I see. Yeah, I can see that this change here makes D3D12 in debug mode completely crash:

// debug1->SetEnableGPUBasedValidation(true);

debug1->SetEnableSynchronizedCommandQueueValidation(false); seems to be the culprit. If I revert that change and just have debug1->SetEnableGPUBasedValidation(true) on, everything works great & debug doesn't have to be off.

It seems that this fix broke D3D12 completely in debug mode.

@bkaradzic
Copy link
Owner

It seems that this fix broke D3D12 completely in debug mode.

That fix was introduced 3 years ago. Don't assume that things are static... And bug is inside D3D12, not bgfx, this was work around another issue.

436b7fa#diff-001017d02e7808ecc953fdb7b17a87e856a26ba6a3b153dd10dcfee90b60f011

@etodanik
Copy link
Author

Ah, yes. Not making any assumptions. Just observing that rolling back the fix makes Debug work fine.

@kingscallop
Copy link
Contributor

Hi!

Hey @kingscallop do you know how to find text of this bug number? It seems their Discord channel is gone.
(436b7fa?diff=unified#r127893892)

The discord server can be reached here: discord.gg/directx

I went there and asked about the status of the bug '26131261' here is the reply:

Adam Miles
Jesse pointed me to the archive. The bug was fixed in July 2020, so, long since fixed in both Windows and Agility SDKs.

Jesse Natalie
I expect a fix date around then would mean fixed in Win11, but not Win10
Unless using the Agility SDK of course

From their reply it seems the bug has been fixed, so these lines can be reverted from:

//				debug1->SetEnableGPUBasedValidation(true);

				// https://discordapp.com/channels/590611987420020747/593519198995742733/703642988345032804
				// D3D12 Bug Number: 26131261
				// There is a bug in the D3D12 validation that causes example-21 to fail when using UAV
				// Setting this function below to false avoids the bug
				debug1->SetEnableSynchronizedCommandQueueValidation(false);

to:

//				debug1->SetEnableGPUBasedValidation(true);
//				debug1->SetEnableSynchronizedCommandQueueValidation(true);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants