using UnityEngine.Rendering.RenderGraphModule;
namespace UnityEngine.Rendering.HighDefinition
{
///
/// Pipeline specifics for VRS
///
public partial class HDRenderPipeline
{
///
/// Preprocess VRS resources once at initialization
///
void VrsInitializeResources()
{
if (!currentPlatformRenderPipelineSettings.supportVariableRateShading)
return;
Vrs.InitializeResources();
}
///
/// Dispose of preprocessed VRS resources
///
void VrsDisposeResources()
{
Vrs.DisposeResources();
}
///
/// Get or create VRS image.
///
/// Camera to get shading rate image from.
/// Number of buffer in history.
/// The created shading rate image handle or null if not possible.
static RTHandle RequestVrsHistory(HDCamera hdCamera, int bufferCount)
{
if (bufferCount > 0)
return RequestVrsRTHandle(hdCamera, bufferCount, (int)HDCameraFrameHistoryType.Vrs);
return null;
}
///
/// Helper function for RequestVrsHistory
///
static RTHandle RequestVrsRTHandle(HDCamera hdCamera, int bufferCount, int id)
{
if (!ShadingRateInfo.supportsPerImageTile)
return null; // Tile size will be 0x0 and alloc fails.
return hdCamera.GetCurrentFrameRT(id) ??
hdCamera.AllocHistoryFrameRT(id,
VrsAllocatorFunction,
bufferCount);
}
// Static allocator function to avoid allocations.
static RTHandle VrsAllocatorFunction(string viewName, int frameIndex, RTHandleSystem rtHandleSystem)
{
return rtHandleSystem.Alloc(Vector2.one, new RTHandleAllocInfo(name: string.Format("{0}_VrsHistoryBuffer{1}", viewName, frameIndex))
{
slices = 1,
dimension = TextureDimension.Tex2D,
format = ShadingRateInfo.graphicsFormat,
enableRandomWrite = true,
useDynamicScale = true,
useMipMap = false,
autoGenerateMips = false,
enableShadingRate = true,
});
}
}
}