Skip to content

Commit

Permalink
[XB1] Reset d3dx device and retry texture creation (#4147)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
TyHolc authored Sep 24, 2024
1 parent b41f909 commit 46db6b0
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions starboard/shared/win32/video_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -416,12 +416,34 @@ SbDecodeTarget VideoDecoder::CreateDecodeTarget() {
video_processor_, video_sample, video_area, is_hdr_supported_);
auto hardware_decode_target =
reinterpret_cast<HardwareDecodeTargetPrivate*>(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<HardwareDecodeTargetPrivate*>(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;
}
}
}

Expand Down

0 comments on commit 46db6b0

Please sign in to comment.