From 84742c540427d596e140771b38ef889c5aa0dd97 Mon Sep 17 00:00:00 2001 From: Tyler Holcombe Date: Mon, 23 Sep 2024 13:12:44 -0700 Subject: [PATCH] [XB1] Reset d3dx device and retry texture creation When texture creation fails, attempt to reset the d3dx device and recreate the texture. If it fails again, continue with existing behavior. b/329326128 Change-Id: I480be7418b72426220e95dd745c96b12a388a808 --- starboard/shared/win32/video_decoder.cc | 32 +++++++++++++++++++++---- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/starboard/shared/win32/video_decoder.cc b/starboard/shared/win32/video_decoder.cc index 1c89c36da592..625e6c8bff7e 100644 --- a/starboard/shared/win32/video_decoder.cc +++ b/starboard/shared/win32/video_decoder.cc @@ -416,12 +416,34 @@ SbDecodeTarget VideoDecoder::CreateDecodeTarget() { video_processor_, video_sample, video_area, is_hdr_supported_); auto hardware_decode_target = reinterpret_cast(decode_target); + if (!hardware_decode_target->d3d_texture) { - error_cb_(kSbPlayerErrorDecode, - "Failed to allocate texture with error code: " + - ::starboard::shared::win32::HResultToString( - hardware_decode_target->create_texture_2d_h_result)); - decode_target = kSbDecodeTargetInvalid; + // The HRESULT 0x887A0005 is DXGI_ERROR_DEVICE_REMOVED + // (https://learn.microsoft.com/en-us/windows/win32/direct3ddxgi/dxgi-error). + // In this case, the device is in a bad state and needs to be recreated. + // Attempt to recreate the d3d_device_ and retry initializing the + // decode_target. + if (FAILED(hardware_decode_target->create_texture_2d_h_result)) { + HardwareDecoderContext hardware_context = + GetDirectXForHardwareDecoding(); + d3d_device_ = hardware_context.dx_device_out; + + decode_target = new HardwareDecodeTargetPrivate( + d3d_device_, video_device_, video_context_, video_enumerator_, + video_processor_, video_sample, video_area, is_hdr_supported_); + hardware_decode_target = + reinterpret_cast(decode_target); + } + + // If the texture still hasn't initialized, report the error. + if (!hardware_decode_target->d3d_texture) { + error_cb_( + kSbPlayerErrorDecode, + "Failed to allocate texture with error code: " + + ::starboard::shared::win32::HResultToString( + hardware_decode_target->create_texture_2d_h_result)); + decode_target = kSbDecodeTargetInvalid; + } } }