Skip to content

Commit

Permalink
Crash Detector: Convenience OnPresent handler
Browse files Browse the repository at this point in the history
  • Loading branch information
MeFisto94 committed Apr 21, 2024
1 parent ff59558 commit d60319c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions D3D9/DriverCrashDetector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@
using System.IO;
using System.Linq;
using NLog;
using SharpDX.Direct3D9;

namespace Andraste.Payload.D3D9
{
// Idea: fill the known-bad list with all shaders that have been happening before the crash. Then gradually
// always no-op half of them and expect the game to crash. When it does, note the half that hasn't been no-opped.
// Restart the game.
//
// Another thing you can do is tracking vertex and index buffers and dumping them on crash
public class DriverCrashDetector
{
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
Expand Down Expand Up @@ -127,6 +130,11 @@ public DriverCrashDetector(float aggressivity, bool debugPixelShaders = true)
}
}

/// <summary>
/// Compare the hash of the vertex shader against known good and bad shaders.
/// </summary>
/// <param name="shaderHash">The hash of the shader bytecode</param>
/// <returns>Whether the vertex shader should be replaced with a dummy shader</returns>
public bool OnCreateVertexShader(string shaderHash)
{
if (_debugPixelShaders)
Expand All @@ -150,6 +158,11 @@ public bool OnCreateVertexShader(string shaderHash)
return false; // Shader that has been recently dropped out of the bad shaders (or first run)
}

/// <summary>
/// Compare the hash of the pixel shader against known good and bad shaders.
/// </summary>
/// <param name="shaderHash">The hash of the shader bytecode</param>
/// <returns>Whether the pixel shader should be replaced with a dummy shader</returns>
public bool OnCreatePixelShader(string shaderHash)
{
if (!_debugPixelShaders)
Expand All @@ -173,6 +186,14 @@ public bool OnCreatePixelShader(string shaderHash)
return false; // Shader that has been recently dropped out of the bad shaders (or first run)
}

public void OnPresent(int result)
{
if (result == ResultCode.DeviceLost.Code)
{
HandleCrash();
}
}

public void HandleCrash()
{
// Special case: shader that was previously in known-bad hasn't been seen this time, so it's automatically removed from that list.
Expand Down

0 comments on commit d60319c

Please sign in to comment.