ShaderStageFlags
Represents one or several GPU shader stages.
Read time 2 minutesLast updated 7 days ago
Definition
- Type: Enum
- Namespace: UnityEngine.Shaders
- Assembly: UnityEngine.CoreModule
[Flags]public enum ShaderStageFlags
Remarks
This enum is used in various APIs that allow specifying multiple GPU shader stages simultaneuously. APIs that need to specify individual shader stages use the ShaderStage enum instead.
The traditional graphics shader stages used in rasterization are represented by the following enum values:
- ShaderStageFlags.Vertex
- ShaderStageFlags.Fragment
- ShaderStageFlags.Geometry
- ShaderStageFlags.Hull
- ShaderStageFlags.Domain
The compute shader stage and the ray tracing shader stage are represented as ShaderStageFlags.Compute and ShaderStageFlags.RayTracing, respectively.
In addition to that, the following enum values can be used for convenient representation of common shader stage combinations:
- ShaderStageFlags.Basic has ShaderStageFlags.Vertex and ShaderStageFlags.Fragment enabled
- ShaderStageFlags.Tessellation has ShaderStageFlags.Hull and ShaderStageFlags.Domain enabled
- ShaderStageFlags.Graphics has ShaderStageFlags.Basic, ShaderStageFlags.Tessellation, and ShaderStageFlags.Geometry enabled
- ShaderStageFlags.Any has all possible shader stages enabled
Use Utility.IsShaderStageEnabled to check if the ShaderStageFlags value has the given stage enabled. Utility.ShaderStageToFlags can be used to convert an individual shader stage to ShaderStageFlags.
Additional Resources: ShaderStage, Utility.
Examples
using UnityEngine;using UnityEngine.Shaders;/* Attach this script to a GameObject and enter Play mode. "Shader stages: Basic, Tessellation" will be printed in the console.*/public class ShaderTypes : MonoBehaviour{ void Start() { ShaderStageFlags stages = (ShaderStageFlags.Graphics & (~ShaderStageFlags.Geometry)); // Iterate over all possible shader stages and check if the only stages enabled are Vertex, Fragment, Hull, and Domain // Log a message if a stage is enabled or disabled incorrectly. for (ShaderStage stage = ShaderStage.FirstStage; stage < ShaderStage.Count; ++stage) { bool shouldBeEnabled = stage < ShaderStage.GraphicsStageCount && stage != ShaderStage.Geometry; if (Utility.IsShaderStageEnabled(stages, stage) != shouldBeEnabled) Debug.Log("Unexpected stage " + stage + (shouldBeEnabled ? " not enabled" : " enabled")); } Debug.Log("Shader stages: " + stages); }}
Fields
Value | Description |
|---|---|
| Any | Specifies that all shader stages are enabled. |
| Basic | Specifies that vertex and fragment shader stages are enabled. |
| Compute | Specifies that compute shader stage is enabled. |
| Domain | Specifies that domain shader stage is enabled. |
| Fragment | Specifies that fragment shader stage is enabled. |
| Geometry | Specifies that geometry shader stage is enabled. |
| Graphics | Specifies that vertex, fragment, geometry, hull, and domain shader stages are enabled. |
| Hull | Specifies that hull shader stage is enabled. |
| None | Specifies that no shader stages are enabled. |
| RayTracing | Specifies that ray tracing shader stage is enabled. |
| Tessellation | Specifies that hull and domain shader stages are enabled. |
| Vertex | Specifies that vertex shader stage is enabled. |