Skip to content

Commit

Permalink
Fix D3D12 debug crash due to validation layers SDK bug
Browse files Browse the repository at this point in the history
  • Loading branch information
RazielXYZ committed Dec 13, 2023
1 parent e2631c1 commit 4758bea
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/renderer_d3d12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -844,13 +844,31 @@ namespace bgfx { namespace d3d12

if (SUCCEEDED(hr))
{
// debug1->SetEnableGPUBasedValidation(true);
//This is the least ugly way to get the windows build that still works past win10 without deprecation warnings or needing app manifests
RTL_OSVERSIONINFOW osver;
bx::memSet(&osver, 0 , sizeof(RTL_OSVERSIONINFOW));
const HMODULE hMod = ::GetModuleHandleW(L"ntdll.dll");
if (hMod) {
LONG (WINAPI* rtlGetVersionPtr) (PRTL_OSVERSIONINFOW) = reinterpret_cast<LONG (WINAPI*)(PRTL_OSVERSIONINFOW)>(::GetProcAddress(hMod, "RtlGetVersion"));
if (rtlGetVersionPtr != nullptr) {
rtlGetVersionPtr(&osver);
if (osver.dwBuildNumber > 0) {
osver.dwOSVersionInfoSize = sizeof(RTL_OSVERSIONINFOW);
}
}
}

// 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);
// Setting SetEnableSynchronizedCommandQueueValidation below to false avoids the bug
// It was fixed in (probably) the first windows 11 sdk, 22000
// However, the fix causes any dx12 context with validation to break if this is set to false, so we can't do that anymore
if (osver.dwOSVersionInfoSize > 0 && osver.dwBuildNumber >= 22000) {
debug1->SetEnableGPUBasedValidation(true);
} else {
debug1->SetEnableSynchronizedCommandQueueValidation(false);
}
}

DX_RELEASE(debug1, 1);
Expand Down

0 comments on commit 4758bea

Please sign in to comment.