Skip to content

Commit

Permalink
EXP : WIP but not working
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastiii committed Oct 8, 2016
1 parent 96400ae commit 0b5ef2c
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 67 deletions.
204 changes: 138 additions & 66 deletions mediaportal/MediaPortal.Application/D3D.cs
Expand Up @@ -38,6 +38,7 @@
using MediaPortal.UserInterface.Controls;
using MediaPortal.Util;
using MediaPortal.Video.Database;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using WPFMediaKit.DirectX;

Expand Down Expand Up @@ -147,7 +148,7 @@ protected struct RECT

#region private attributes

private readonly Control _renderTarget; // render target object
private Control _renderTarget; // render target object
protected readonly PresentParameters _presentParams; // D3D presentation parameters
protected PresentParameters _presentParamsBackup; // D3D presentation parameters Backup
internal D3DEnumeration _enumerationSettings; //
Expand Down Expand Up @@ -614,73 +615,113 @@ internal void RecreateSwapChain(bool useBackup)
GUIWindowManager.UnRoute();
GUIWindowManager.Dispose();
GUIFontManager.Dispose();
GUITextureManager.Dispose();
if (GUIGraphicsContext.DX9Device != null)
GUITextureManager.Dispose();
if (GUIGraphicsContext.DX9Device != null)
{
GUIGraphicsContext.DX9Device.EvictManagedResources();

if (useBackup)
{
try
{
Log.Debug("Main: RecreateSwapChain() by restoring startup DirectX values");
GUIGraphicsContext.DirectXPresentParameters = _presentParamsBackup;
GUIGraphicsContext.DX9Device.Reset(_presentParamsBackup);
}
catch (InvalidCallException)
{
Log.Error("D3D: D3DERR_INVALIDCALL - presentation parameters might contain an invalid value");
}
catch (DeviceLostException)
{
Log.Error("D3D: D3DERR_DEVICELOST - device is lost but cannot be reset at this time");
}
catch (DriverInternalErrorException)
{
Log.Error("D3D: D3DERR_DRIVERINTERNALERROR - internal driver error");
}
catch (OutOfVideoMemoryException)
{
Log.Error("D3D: D3DERR_OUTOFVIDEOMEMORY - not enough available display memory to perform the operation");
}
catch (OutOfMemoryException)
{
Log.Error("D3D: D3DERR_OUTOFMEMORY - could not allocate sufficient memory to complete the call");
}
}
else
{
GUIGraphicsContext.DX9Device.EvictManagedResources();

if (useBackup)
{
try
{
Log.Debug("Main: RecreateSwapChain() by restoring startup DirectX values");
GUIGraphicsContext.DirectXPresentParameters = _presentParamsBackup;
GUIGraphicsContext.DX9Device.Reset(_presentParamsBackup);
}
catch (InvalidCallException)
{
Log.Error("D3D: D3DERR_INVALIDCALL - presentation parameters might contain an invalid value");
//Util.Utils.RestartMePo();
}
catch (DeviceLostException)
{
Log.Error("D3D: D3DERR_DEVICELOST - device is lost but cannot be reset at this time");
}
catch (DriverInternalErrorException)
{
Log.Error("D3D: D3DERR_DRIVERINTERNALERROR - internal driver error");
}
catch (OutOfVideoMemoryException)
{
Log.Error("D3D: D3DERR_OUTOFVIDEOMEMORY - not enough available display memory to perform the operation");
}
catch (OutOfMemoryException)
{
Log.Error("D3D: D3DERR_OUTOFMEMORY - could not allocate sufficient memory to complete the call");
}
// ADDED FOR TESTING START
catch (Exception ex)
{
//Util.Utils.RestartMePo();
//_renderTarget = new Form();
//_renderTarget = new MediaPortalApp();
//successful = false;
//successfulInit = false;
//Init();
//BuildPresentParams(Windowed);
//CreateDirectX9ExDevice();

Log.Error(ex);
Log.Error("D3D: RecreateSwapChain Exception {0} {1} {2}", ex.Message, ex.Source, ex.StackTrace);

//_renderTarget.Dispose();
//_renderTarget = this;

//GUIGraphicsContext.form = this;
//GUIGraphicsContext.ActiveForm = Handle;
_renderTarget = new MediaPortalApp();
successful = false;
successfulInit = false;
Init();
//BuildPresentParams(Windowed);
//CreateDirectX9ExDevice();

GUIGraphicsContext.DX9Device.Reset(_presentParams);
GUIGraphicsContext.DX9Device.Present();
//SwapChain sc = new SwapChain(GUIGraphicsContext.DX9Device, _presentParams);
//sc.Present();
}
// ADDED FOR TESTING END
}
else
{
// build new D3D presentation parameters and reset device
Log.Debug("Main: RecreateSwapChain() by rebuild PresentParams");
BuildPresentParams(Windowed);
try
{
GUIGraphicsContext.DX9Device.Reset(_presentParams);
}
catch (InvalidCallException)
{
Log.Error("D3D: D3DERR_INVALIDCALL - presentation parametters might contain an invalid value");
}
catch (DeviceLostException)
{
// Indicate that the device has been lost
Log.Error("D3D: D3DERR_DEVICELOST - device is lost but cannot be reset at this time");
}
catch (DriverInternalErrorException)
{
Log.Error("D3D: D3DERR_DRIVERINTERNALERROR - internal driver error");
}
catch (OutOfVideoMemoryException)
{
Log.Error("D3D: D3DERR_OUTOFVIDEOMEMORY - not enough available display memory to perform the operation");
}
catch (OutOfMemoryException)
{
Log.Error("D3D: D3DERR_OUTOFMEMORY - could not allocate sufficient memory to complete the call");
}
}
}

Log.Debug("Main: RecreateSwapChain() by rebuild PresentParams");
BuildPresentParams(Windowed);
try
{
GUIGraphicsContext.DX9Device.Reset(_presentParams);
}
catch (InvalidCallException)
{
Log.Error("D3D: D3DERR_INVALIDCALL - presentation parametters might contain an invalid value");
}
catch (DeviceLostException)
{
// Indicate that the device has been lost
Log.Error("D3D: D3DERR_DEVICELOST - device is lost but cannot be reset at this time");
}
catch (DriverInternalErrorException)
{
Log.Error("D3D: D3DERR_DRIVERINTERNALERROR - internal driver error");
}
catch (OutOfVideoMemoryException)
{
Log.Error("D3D: D3DERR_OUTOFVIDEOMEMORY - not enough available display memory to perform the operation");
}
catch (OutOfMemoryException)
{
Log.Error("D3D: D3DERR_OUTOFMEMORY - could not allocate sufficient memory to complete the call");
}
// ADDED FOR TESTING START
catch (Exception ex)
{
//Util.Utils.RestartMePo();
}
// ADDED FOR TESTING END
}
}

// load resources
GUIGraphicsContext.Load();
GUITextureManager.Init();
Expand Down Expand Up @@ -841,6 +882,37 @@ protected void RecoverDevice()
}
}

//// ADDED FOR TESTING START
//while (true)
//{
// try
// {
// if (GUIGraphicsContext.DX9Device != null)
// {
// // Check device
// GUIGraphicsContext.DX9Device.Present();
// break;
// }
// }
// catch (DirectXException dex)
// {
// switch (dex.ErrorCode)
// {
// default:
// Log.Error(dex);
// //Util.Utils.RestartMePo();
// break;
// }
// }
// catch (Exception ex)
// {
// Log.Error(ex);
// //Util.Utils.RestartMePo();
// break;
// }
//}
//// ADDED FOR TESTING END

// lock rendering loop and recreate the backbuffer for the current D3D device
RecreateSwapChain(true);

Expand Down
13 changes: 12 additions & 1 deletion mediaportal/MediaPortal.Application/MediaPortal.cs
Expand Up @@ -183,6 +183,7 @@ public class MediaPortalApp : D3D, IRender
private const int D3DERR_DEVICEHUNG = -2005530508; // http://msdn.microsoft.com/en-us/library/windows/desktop/bb172554(v=vs.85).aspx
private const int D3DERR_DEVICEREMOVED = -2005530512; // http://msdn.microsoft.com/en-us/library/windows/desktop/bb172554(v=vs.85).aspx
private const int D3DERR_INVALIDCALL = -2005530516; // http://msdn.microsoft.com/en-us/library/windows/desktop/bb172554(v=vs.85).aspx
private const int D3DERR_NOTAVAILABLE = -2005530518; // http://msdn.microsoft.com/en-us/library/windows/desktop/bb172554(v=vs.85).aspx

private const int DEVICE_NOTIFY_WINDOW_HANDLE = 0;
private const int DEVICE_NOTIFY_ALL_INTERFACE_CLASSES = 4;
Expand Down Expand Up @@ -3666,15 +3667,25 @@ protected override void Render(float timePassed)
break;

case D3DERR_DEVICEHUNG:
case D3DERR_DEVICEREMOVED:
Log.Info("Main: GPU_HUNG - {0}", dex.ToString());
//Utils.RestartMePo();
break;

case D3DERR_DEVICEREMOVED:
Log.Info("Main: GPU_REMOVED - {0}", dex.ToString());
if (!RefreshRateChanger.RefreshRateChangePending)
{
g_Player.Stop();
}
//Utils.RestartMePo();
GUIGraphicsContext.CurrentState = GUIGraphicsContext.State.LOST;
break;

case D3DERR_NOTAVAILABLE:
Log.Info("Main: GPU_NOT_AVAILABLE - {0}", dex.ToString());
//Utils.RestartMePo();
break;

default:
Log.Error(dex);
break;
Expand Down
4 changes: 4 additions & 0 deletions mediaportal/MediaPortal.Application/d3denumeration.cs
Expand Up @@ -20,6 +20,7 @@

using System.Collections;
using System.Diagnostics;
using MediaPortal.GUI.Library;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;

Expand Down Expand Up @@ -191,10 +192,13 @@ public void Enumerate()
{
foreach (AdapterInformation ai in Manager.Adapters)
{
// Here after GPU recovery or crash or disable/enable Manager.Adapters are not filled correctly anymore
Manager.Adapters.Reset();
ArrayList adapterFormatList = new ArrayList();
GraphicsAdapterInfo adapterInfo = new GraphicsAdapterInfo();
adapterInfo.AdapterOrdinal = ai.Adapter;
adapterInfo.AdapterDetails = ai.Information;
Log.Debug("D3DEnumeration ai.Information : {0}", ai.Information.Description);

// Get list of all display modes on this adapter.
// Also build a temporary list of all display adapter formats.
Expand Down

0 comments on commit 0b5ef2c

Please sign in to comment.