Provides programmatic access to graphics API debug layer validation errors.
Use this class to detect and respond to graphics API validation errors at runtime. It's intended for test frameworks, diagnostic tools, and other systems that need to react to validation errors rather than just log them.
Validation is implemented per graphics backend, so the way you enable it depends on the active GraphicsDeviceType. With Direct3D 12, launch Unity with the -force-d3d12-debug-as-errors command line argument. When you don't specify a backend-specific argument, or when the debug layer fails to initialize, GraphicsApiValidation.IsValidationActive returns false and Unity doesn't report errors.
Call GraphicsApiValidation.IsValidationSupported first to check whether the current graphics backend exposes a validation implementation. When it returns false the other members have no effect and return default values.
Additional resources: GraphicsApiValidation.IsValidationSupported, GraphicsApiValidation.IsValidationActive, GraphicsApiValidation.IsValidationRequested, GraphicsApiValidation.GetValidationErrorCount, GraphicsApiValidation.ClearValidationErrors.
using UnityEngine; using UnityEngine.Rendering;
public static class GraphicsApiValidationExample { public static void CheckForErrors() { if (!GraphicsApiValidation.IsValidationSupported() || !GraphicsApiValidation.IsValidationActive()) return;
GraphicsApiValidation.ClearValidationErrors();
// ... run code that issues graphics commands ...
int count = GraphicsApiValidation.GetValidationErrorCount(); for (int i = 0; i < count; i++) { Debug.LogError(GraphicsApiValidation.GetValidationError(i)); } } }
| Method | Description |
|---|---|
| ClearValidationErrors | Clears any accumulated graphics API validation errors. |
| GetValidationError | Returns a specific graphics API validation error message by index. |
| GetValidationErrorCount | Returns the number of graphics API validation errors accumulated since the last call to GraphicsApiValidation.ClearValidationErrors. |
| GetValidationErrorsDroppedCount | Returns the number of graphics API validation errors that were dropped because the internal error buffer was full. |
| IsValidationActive | Returns whether graphics API validation is active and the debug layer initialized successfully. |
| IsValidationErrorLoggingSuppressed | Returns whether immediate logging of graphics API validation errors is currently suppressed. |
| IsValidationRequested | Returns whether graphics API validation was requested via a backend-specific command line argument (for example, -force-d3d12-debug-as-errors on Direct3D 12). |
| IsValidationSupported | Returns whether the current graphics backend exposes a validation implementation. |
| SetValidationErrorLoggingSuppressed | Controls whether graphics API validation errors are logged immediately as the debug layer reports them. |