docs.unity.cn

Core RP Library 17.0.3

Search Results for

    Show / Hide Table of Contents

    Class RenderGraphUtils

    Helper functions used for RenderGraph.

    Inheritance
    object
    RenderGraphUtils
    Inherited Members
    object.Equals(object)
    object.Equals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    object.ReferenceEquals(object, object)
    object.ToString()
    Namespace: UnityEngine.Rendering.RenderGraphModule.Util
    Assembly: Unity.RenderPipelines.Core.Runtime.dll
    Syntax
    public static class RenderGraphUtils

    Methods

    AddBlitPass(RenderGraph, TextureHandle, TextureHandle, Vector2, Vector2, int, int, int, int, int, int, BlitFilterMode, string)

    Add a render graph pass to blit an area of the source texture into the destination texture. Blitting is a high-level way to transfer texture data from a source to a destination texture. It may scale and texture-filter the transferred data as well as doing data transformations on it (e.g. R8Unorm to float).

    This function does not have special handling for MSAA textures. This means that when the source is sampled this will be a resolved value (standard Unity behavior when sampling an MSAA render texture) and when the destination is MSAA all written samples will contain the same values (e.g. as you would expect when rendering a full screen quad to an msaa buffer). If you need special MSAA handling or custom resolving please use the overload that takes a Material and implement the appropriate behavior in the shader.

    This function works transparently with regular textures and XR textures (which may depending on the situation be 2D array textures). In the case of an XR array texture the operation will be repeated for each slice in the texture if numSlices is set to -1.

    Declaration
    public static void AddBlitPass(this RenderGraph graph, TextureHandle source, TextureHandle destination, Vector2 scale, Vector2 offset, int sourceSlice = 0, int destinationSlice = 0, int numSlices = -1, int sourceMip = 0, int destinationMip = 0, int numMips = 1, RenderGraphUtils.BlitFilterMode filterMode = BlitFilterMode.ClampBilinear, string passName = "Blit Pass Utility")
    Parameters
    Type Name Description
    RenderGraph graph

    The RenderGraph adding this pass to.

    TextureHandle source

    The texture the data is copied from.

    TextureHandle destination

    The texture the data is copied to.

    Vector2 scale

    The scale that is applied to the texture coordinates used to sample the source texture.

    Vector2 offset

    The offset that is added to the texture coordinates used to sample the source texture.

    int sourceSlice

    The first slice to copy from if the texture is an 3D or array texture. Must be zero for regular textures.

    int destinationSlice

    The first slice to copy to if the texture is an 3D or array texture. Must be zero for regular textures.

    int numSlices

    The number of slices to copy. -1 to copy all slices until the end of the texture. Arguments that copy invalid slices to be copied will lead to an error.

    int sourceMip

    The first mipmap level to copy from. Must be zero for non-mipmapped textures. Must be a valid index for mipmapped textures.

    int destinationMip

    The first mipmap level to copy to. Must be zero for non-mipmapped textures. Must be a valid index for mipmapped textures.

    int numMips

    The number of mipmaps to copy. -1 to copy all mipmaps. Arguments that copy invalid mips to be copied will lead to an error.

    RenderGraphUtils.BlitFilterMode filterMode

    The filtering used when blitting from source to destination.

    string passName

    A name to use for debugging and error logging. This name will be shown in the rendergraph debugger.

    AddBlitPass(RenderGraph, BlitMaterialParameters, string)

    Add a render graph pass to blit an area of the source texture into the destination texture. Blitting is a high-level way to transfer texture data from a source to a destination texture. In this overload the data may be transformed by an arbitrary material.

    This function works transparently with regular textures and XR textures (which may depending on the situation be 2D array textures) if numSlices is set to -1 and the slice property works correctly.

    This is a helper function to schedule a simple pass calling a single blit. If you want to call a number of blits in a row (e.g. to a slice-by-slice or mip-by-mip blit) it's generally faster to simple schedule a single pass and then do schedule blits directly on the command buffer.

    This function schedules a pass for execution on the rendergraph execution timeline. It's important to ensure the passed material and material property blocks correctly account for this behavior in particular the following code will likely not behave as intented: material.SetFloat("Visibility", 0.5); renderGraph.AddBlitPass(... material ...); material.SetFloat("Visibility", 0.8); renderGraph.AddBlitPass(... material ...);

    This will result in both passes using the float value "Visibility" as when the graph is executed the value in the material is assigned 0.8. The correct way to handle such use cases is either using two separate materials or using two separate material property blocks. E.g. :

    propertyBlock1.SetFloat("Visibility", 0.5); renderGraph.AddBlitPass(... material, propertyBlock1, ...); propertyBlock2.SetFloat("Visibility", 0.8); renderGraph.AddBlitPass(... material, propertyBlock2, ...);

    Notes on using this function:

    • If you need special handling of MSAA buffers this can be implemented using the bindMS flag on the source texture and per-sample pixel shader invocation on the destination texture (e.g. using SV_SampleIndex).
    • MaterialPropertyBlocks used for this function should not contain any textures added by MaterialPropertyBlock.SetTexture(...) as it will cause untracked textures when using RenderGraph causing uninstended behaviour.
    Declaration
    public static void AddBlitPass(this RenderGraph graph, RenderGraphUtils.BlitMaterialParameters blitParameters, string passName = "Blit Pass Utility w. Material")
    Parameters
    Type Name Description
    RenderGraph graph

    The RenderGraph adding this pass to.

    RenderGraphUtils.BlitMaterialParameters blitParameters

    Parameters used for rendering.

    string passName

    A name to use for debugging and error logging. This name will be shown in the rendergraph debugger.

    AddCopyPass(RenderGraph, TextureHandle, TextureHandle, int, int, int, int, string)

    Adds a pass to copy data from a source texture to a destination texture. The data in the texture is copied pixel by pixel. The copy function can only do 1:1 copies it will not allow scaling the data or doing texture filtering. Furthermore it requires the source and destination surfaces to be the same size in pixels and have the same number of MSAA samples. If the textures are multi sampled individual samples will be copied.

    Copy is intentionally limited in functionally so it can be implemented using frame buffer fetch for optimal performance on tile based GPUs. If you are looking for a more generic function please use the AddBlitPass function.

    For XR textures you will have to copy for each eye seperatly.

    For MSAA textures please use the CanAddCopyPassMSAA() function first to check if the CopyPass is supported on current platform.

    Declaration
    public static void AddCopyPass(this RenderGraph graph, TextureHandle source, TextureHandle destination, int sourceSlice = 0, int destinationSlice = 0, int sourceMip = 0, int destinationMip = 0, string passName = "Copy Pass Utility")
    Parameters
    Type Name Description
    RenderGraph graph

    The RenderGraph adding this pass to.

    TextureHandle source

    The texture the data is copied from.

    TextureHandle destination

    The texture the data is copied to. This has to be different from souce.

    int sourceSlice

    The source slice of a Array of 3D texture to use. Must be 0 for regular 2D textures.

    int destinationSlice

    The destination slice of a Array of 3D texture to use. Must be 0 for regular 2D textures.

    int sourceMip

    The first mipmap level to copy from. Must be zero for non-mipmapped textures. Must be a valid index for mipmapped textures.

    int destinationMip

    The first mipmap level to copy to. Must be zero for non-mipmapped textures. Must be a valid index for mipmapped textures.

    string passName

    A name to use for debugging and error logging. This name will be shown in the rendergraph debugger.

    CanAddCopyPassMSAA()

    Checks if the shader features required by the MSAA version of the copy pass is supported on current platform.

    Declaration
    public static bool CanAddCopyPassMSAA()
    Returns
    Type Description
    bool

    Returns true if the shader features required by the copy pass is supported for MSAA, otherwise will it return false.

    In This Article
    • Methods
      • AddBlitPass(RenderGraph, TextureHandle, TextureHandle, Vector2, Vector2, int, int, int, int, int, int, BlitFilterMode, string)
      • AddBlitPass(RenderGraph, BlitMaterialParameters, string)
      • AddCopyPass(RenderGraph, TextureHandle, TextureHandle, int, int, int, int, string)
      • CanAddCopyPassMSAA()
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)