Version: Unity 6.7 Beta (6000.7)
LanguageEnglish
  • C#

FSR2TextureTable

struct in UnityEngine.AMD

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Description

The set of texture slots available for the FSR2Context and FSRUpscalerContext.

Use this struct to specify input and output textures for FSR2, FSR3, and FSR4 upscaling.

Note: You must create output color texture colorOutput with enableRandomWrite parameter set to true when initializing the RTHandle of the texture. This is due to FSR passes requiring access to the resources in a compute shader.

Refer to the Input resources section in AMD's documentation for more details:

Additional resources: AMDUnityPlugin, GraphicsDevice, FSR2Context, FSRUpscalerContext, FSR2CommandInitializationData, FSRUpscalerCommandInitializationData, FSR2CommandExecutionData

using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.Experimental.Rendering;
using UnityEngine.AMD;

// Example HDRP custom pass public class CustomFSRPass : CustomPass { void InitializeAMDDevice() { // device initialization code } bool HasOutputResolutionChanged(CustomPassContext ctx) { // detect resolution change } bool HasInputResolutionChanged(CustomPassContext ctx) { // detect resolution change }

protected override void Setup(ScriptableRenderContext renderContext, CommandBuffer cmd) { if (amdDevice == null) { InitializeAMDDevice(); }

float scalingRatio = fsr2Context == null ? 1.0f : amdDevice.GetUpscaleRatioFromQualityMode(m_Quality); fsr2OutputColorBuffer = RTHandles.Alloc( new Vector2(scalingRatio, scalingRatio), slices: 1, dimension: TextureDimension.Tex2D, colorFormat: GraphicsFormat.R16G16B16A16_SFloat, name: "fsr2OutputColorBuffer", enableRandomWrite: true ); }

protected override void Execute(CustomPassContext ctx) { bool initializeFsr2Context = fsr2Context == null || HasInputResolutionChanged(ctx) || HasOutputResolutionChanged(ctx); if (initializeFsr2Context) { // fsr2Context initialization code }

fsr2Context.executeData.enableSharpening = m_EnableSharpening ? 1 : 0; // populate rest of the fsr2Context.executeData

FSR2TextureTable fsr2TextureTable = new FSR2TextureTable() { // Mandatory inputs colorInput = ctx.cameraColorBuffer, colorOutput = fsr2OutputColorBuffer, depth = ctx.cameraDepthBuffer, motionVectors = ctx.cameraMotionVectorsBuffer,

// Optional inputs transparencyMask = null, exposureTexture = null, reactiveMask = null, biasColorMask = null };

amdDevice.ExecuteFSR2(ctx.cmd, fsr2Context, fsr2TextureTable); }

protected override void Cleanup() { // cleanup code }

private GraphicsDevice amdDevice = null; private FSR2Context fsr2Context = null; private RTHandle fsr2OutputColorBuffer;

[SerializeField] public float m_Sharpness = 0.92f; [SerializeField] public bool m_EnableSharpening = true; [SerializeField] public FSR2Quality m_Quality = FSR2Quality.Quality; FSR2Quality m_QualityBefore = FSR2Quality.Quality; Vector2Int m_InputTextureSize = new Vector2Int(0,0); }

Properties

Property Description
biasColorMaskThis is obsolete. Use transparencyMask instead. If both are specified, then transparencyMask is used and this is ignored.
colorInputThe input color texture to upsample for FSR2Context or FSRUpscalerContext. This texture is mandatory and you must set it to a non-null value.
colorOutputThe output color texture. This texture is mandatory and you must set it to a non-null value.
depthThe input depth texture. This must be the same size as the input color texture. This texture is mandatory and you must set it to a non-null value.
exposureTextureA 1x1 texture with pre-exposure values. See AMD's documentation for details. If you do not use pre-exposure, do not set this texture. Also if there's no particular reason then it's recommended to enable auto exposure via FfxFsr2InitializationFlags or FfxApiCreateContextUpscaleFlags instead of using this texture. This texture is optional.
motionVectorsThe motion vectors texture. Depending on the FfxFsr2InitializationFlags specified in FSR2Context.initData or FfxApiCreateContextUpscaleFlags specified in FSRUpscalerContext.initData, this texture can have the input resolution or output resolution. This texture is mandatory and you must set it to a non-null value.
reactiveMaskA texture of format R8_UNORM and same size as colorInput that adjusts the temporal accumulation balance. See AMD's documentation for details. This texture is optional in FSR2, FSR3 and ignored in FSR4.
transparencyMaskA texture of format R8_UNORM and same size as colorInput that adjusts the pixel history protection mechanisms. See AMD's documentation for details. This texture is optional in FSR2, FSR3 and ignored in FSR4.