Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


GraphicsApiValidation

Provides programmatic access to graphics API debug layer validation errors.
Read time 2 minutesLast updated 6 days ago

Definition

public static class GraphicsApiValidation

Remarks

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.

Examples

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)); } }}

Static Methods

Method

Description

ClearValidationErrorsClears any accumulated graphics API validation errors.
GetValidationErrorReturns a specific graphics API validation error message by index.
GetValidationErrorCountReturns the number of graphics API validation errors accumulated since the last call to GraphicsApiValidation.ClearValidationErrors.
GetValidationErrorsDroppedCountReturns the number of graphics API validation errors that were dropped because the internal error buffer was full.
IsValidationActiveReturns whether graphics API validation is active and the debug layer initialized successfully.
IsValidationErrorLoggingSuppressedReturns whether immediate logging of graphics API validation errors is currently suppressed.
IsValidationRequestedReturns whether graphics API validation was requested via a backend-specific command line argument (for example,
-force-d3d12-debug-as-errors
on Direct3D 12).
IsValidationSupportedReturns whether the current graphics backend exposes a validation implementation.
SetValidationErrorLoggingSuppressedControls whether graphics API validation errors are logged immediately as the debug layer reports them.