Skip to content

Commit ece1b7c

Browse files
committed
test: assert zero GPU validation errors after each game test
1 parent bda8a30 commit ece1b7c

6 files changed

Lines changed: 52 additions & 7 deletions

File tree

sources/engine/Stride.Graphics.Regression/GameTestBase.cs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,38 @@ protected static void RunGameTest(GameTestBase game)
611611

612612
game.ScreenShotAutomationEnabled = !ForceInteractiveMode;
613613

614-
GameTester.RunGameTest(game);
614+
// Track GPU validation errors and warnings during the test
615+
var gpuValidationErrors = new List<string>();
616+
var gpuValidationWarnings = new List<string>();
617+
void OnGlobalMessage(ILogMessage msg)
618+
{
619+
if (msg.Module != nameof(GraphicsDevice))
620+
return;
621+
if (msg.Type == LogMessageType.Error)
622+
gpuValidationErrors.Add(msg.Text);
623+
else if (msg.Type == LogMessageType.Warning && !IsKnownHarmlessWarning(msg.Text))
624+
gpuValidationWarnings.Add(msg.Text);
625+
}
626+
GlobalLogger.GlobalMessageLogged += OnGlobalMessage;
627+
628+
try
629+
{
630+
GameTester.RunGameTest(game);
631+
}
632+
finally
633+
{
634+
GlobalLogger.GlobalMessageLogged -= OnGlobalMessage;
635+
}
636+
637+
// Assert no GPU validation errors
638+
if (gpuValidationErrors.Count > 0)
639+
Assert.Fail($"GPU validation reported {gpuValidationErrors.Count} error(s):" + Environment.NewLine
640+
+ string.Join(Environment.NewLine, gpuValidationErrors));
641+
642+
// Assert no GPU validation warnings
643+
if (gpuValidationWarnings.Count > 0)
644+
Assert.Fail($"GPU validation reported {gpuValidationWarnings.Count} warning(s):" + Environment.NewLine
645+
+ string.Join(Environment.NewLine, gpuValidationWarnings));
615646

616647
// If there were comparison failures, assert them now
617648
if (game.ScreenShotAutomationEnabled)
@@ -637,6 +668,21 @@ void AssertMissingComparisonImages()
637668
}
638669
}
639670

671+
/// <summary>
672+
/// Filters out known harmless D3D11 debug layer warnings that cannot be avoided
673+
/// without significant refactoring.
674+
/// </summary>
675+
private static bool IsKnownHarmlessWarning(string text)
676+
{
677+
return false
678+
// || text.Contains("still bound on input") // D3D11: RT set while SRV still bound (auto-unbinds)
679+
// || text.Contains("Forcing PS shader resource") // D3D11: consequence of the above
680+
|| text.Contains("SetPrivateData") // D3D11: debug name size mismatch on reuse
681+
|| text.Contains("NULL Sampler maps to default") // D3D11: unbound sampler uses default state
682+
|| text.Contains("Live ") // D3D11/D3D12: ReportLiveObjects at shutdown
683+
|| text.Contains("SetPrivateData"); // D3D11: debug name size mismatch on reuse
684+
}
685+
640686
/// <summary>
641687
/// Searches for the root folder of the Stride solution by traversing upward from the test's binary directory.
642688
/// </summary>

sources/engine/Stride.Graphics/Direct3D11/CommandList.Direct3D11.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ internal void SetSamplerState(ShaderStage stage, int slot, SamplerState samplerS
373373
{
374374
samplerStates[slotIndex] = samplerState;
375375

376-
var nativeSampler = samplerState is not null ? samplerState.NativeSamplerState : default;
376+
var nativeSampler = (samplerState ?? GraphicsDevice.SamplerStates.LinearClamp).NativeSamplerState;
377377

378378
switch (stage)
379379
{

sources/engine/Stride.Graphics/Direct3D11/GraphicsDevice.Direct3D11.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Stride.Graphics
2323
{
2424
public unsafe partial class GraphicsDevice
2525
{
26-
private static readonly Logger Log = GlobalLogger.GetLogger("GraphicsDevice");
26+
private static readonly Logger Log = GlobalLogger.GetLogger(nameof(GraphicsDevice));
2727

2828
internal readonly int ConstantBufferDataPlacementAlignment = 16;
2929

sources/engine/Stride.Graphics/Direct3D12/GraphicsDevice.Direct3D12.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace Stride.Graphics
2222
{
2323
public unsafe partial class GraphicsDevice
2424
{
25-
private static readonly Logger Log = GlobalLogger.GetLogger("GraphicsDevice");
25+
private static readonly Logger Log = GlobalLogger.GetLogger(nameof(GraphicsDevice));
2626

2727
internal readonly int ConstantBufferDataPlacementAlignment = D3D12.ConstantBufferDataPlacementAlignment;
2828

sources/engine/Stride.Graphics/OpenGL/GraphicsDevice.OpenGL.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public partial class GraphicsDevice
3232
{
3333
internal readonly int ConstantBufferDataPlacementAlignment = 16;
3434

35-
private static readonly Logger Log = GlobalLogger.GetLogger("GraphicsDevice");
35+
private static readonly Logger Log = GlobalLogger.GetLogger(nameof(GraphicsDevice));
3636

3737
internal int FrameCounter;
3838

sources/engine/Stride.Graphics/Vulkan/GraphicsAdapterFactory.Vulkan.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ internal class GraphicsAdapterFactoryInstance : IDisposable
9898
internal bool HasXlibSurfaceSupport;
9999
internal bool HasSurfaceSupport;
100100

101-
// We use GraphicsDevice (similar to OpenGL)
102-
private static readonly Logger Log = GlobalLogger.GetLogger("GraphicsDevice");
101+
private static readonly Logger Log = GlobalLogger.GetLogger(nameof(GraphicsDevice));
103102

104103
public unsafe GraphicsAdapterFactoryInstance(bool enableValidation)
105104
{

0 commit comments

Comments
 (0)