From ae840d5e615616a7322d38027083ce7e9995f7c5 Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Thu, 5 Aug 2021 14:02:49 +0000 Subject: [PATCH] D3D12: Check for device lost after ID3D12Fence::GetCompletedValue The D3D12 docs say it returns UINT64_MAX if the device was removed Fixed: dawn:1051 Change-Id: Ide3731e9389bdb4a5a81c9f65aa9bcad1b049446 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/60961 Reviewed-by: Bryan Bernhart Reviewed-by: Austin Eng Commit-Queue: Austin Eng --- src/dawn_native/d3d12/DeviceD3D12.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/dawn_native/d3d12/DeviceD3D12.cpp b/src/dawn_native/d3d12/DeviceD3D12.cpp index fd3502d343..628b48e941 100644 --- a/src/dawn_native/d3d12/DeviceD3D12.cpp +++ b/src/dawn_native/d3d12/DeviceD3D12.cpp @@ -288,13 +288,21 @@ namespace dawn_native { namespace d3d12 { } ResultOrError Device::CheckAndUpdateCompletedSerials() { - ExecutionSerial completeSerial = ExecutionSerial(mFence->GetCompletedValue()); + ExecutionSerial completedSerial = ExecutionSerial(mFence->GetCompletedValue()); + if (DAWN_UNLIKELY(completedSerial == ExecutionSerial(UINT64_MAX))) { + // GetCompletedValue returns UINT64_MAX if the device was removed. + // Try to query the failure reason. + DAWN_TRY(CheckHRESULT(mD3d12Device->GetDeviceRemovedReason(), + "ID3D12Device::GetDeviceRemovedReason")); + // Otherwise, return a generic device lost error. + return DAWN_DEVICE_LOST_ERROR("Device lost"); + } - if (completeSerial <= GetCompletedCommandSerial()) { + if (completedSerial <= GetCompletedCommandSerial()) { return ExecutionSerial(0); } - return completeSerial; + return completedSerial; } void Device::ReferenceUntilUnused(ComPtr object) {