using System;
namespace UnityEngine.Rendering
{
///
/// Modes for improved draw submission.
///
public enum GPUResidentDrawerMode : byte
{
///
/// Default mode, GPU resident drawer will be disabled.
///
Disabled,
///
/// If used, the BatchRendererGroup will be used for draw submission whenever possible.
///
InstancedDrawing
}
///
/// Utility struct to pass GPU resident drawer settings together
///
public struct GPUResidentDrawerSettings
{
///
/// Serialized settings of GPUResidentDrawer
///
public GPUResidentDrawerMode mode;
///
/// Does the implementor support dithered crossfade
///
public bool supportDitheringCrossFade;
///
/// Enable GPU data for occlusion culling
///
public bool enableOcclusionCulling;
///
/// Allows the GPU Resident Drawer to run in edit mode
///
public bool allowInEditMode;
///
/// Default minimum screen percentage (0-20%) gpu-driven Renderers can cover before getting culled.
///
public float smallMeshScreenPercentage;
#if UNITY_EDITOR
///
/// Shader used if no custom picking pass has been implemented
///
public Shader pickingShader;
#endif
///
/// Shader used when an error is detected
///
public Shader errorShader;
///
/// Shader used while compiling shaders
///
public Shader loadingShader;
}
///
/// Interface that can be added to a RenderPipelineAsset
/// which indicates that it can support the GPUResidentDrawer.
///
public interface IGPUResidentRenderPipeline
{
///
/// Gets the GPU resident drawer settings
///
GPUResidentDrawerSettings gpuResidentDrawerSettings { get; }
///
/// The mode the GPUResidentDrawer is configured for on this RenderPipeline
///
GPUResidentDrawerMode gpuResidentDrawerMode
{
get;
set;
}
///
/// Callback for use when the GPUResidentDrawer needs to be reinitialized.
///
static void ReinitializeGPUResidentDrawer()
{
GPUResidentDrawer.Reinitialize();
}
///
/// Is the GPU resident drawer supported on this render pipeline.
///
/// Should the reason for non support be logged?
/// true if supported
bool IsGPUResidentDrawerSupportedBySRP(bool logReason = false)
{
bool supported = IsGPUResidentDrawerSupportedBySRP(out var message, out var severity);
if (logReason && !supported)
GPUResidentDrawer.LogMessage(message, severity);
return supported;
}
///
/// Is the GPU resident drawer supported on this render pipeline.
///
/// Why the system is not supported
/// The severity of the message
/// true if supported
bool IsGPUResidentDrawerSupportedBySRP(out string message, out LogType severity)
{
message = string.Empty;
severity = LogType.Log;
return true;
}
///
/// Is GPUResidentDrawer supported on this current configuration?
///
/// Should the reason for non support be logged?
/// true if supported
static bool IsGPUResidentDrawerSupportedByProjectConfiguration(bool logReason = false)
{
bool supported = GPUResidentDrawer.IsProjectSupported(out var message, out var severity);
if (logReason && !string.IsNullOrEmpty(message))
{
Debug.LogWarning(message);
}
return supported;
}
///
/// Is GPUResidentDrawer currently enabled
///
/// true if enabled
static bool IsGPUResidentDrawerEnabled()
{
return GPUResidentDrawer.IsEnabled();
}
}
}