using System; using UnityEngine.Scripting.APIUpdating; namespace UnityEngine.Rendering.RenderGraphModule { /// /// Common base interface for the different render graph builders. These functions are supported on all builders. /// [MovedFrom(true, "UnityEngine.Experimental.Rendering.RenderGraphModule", "UnityEngine.Rendering.RenderGraphModule")] public interface IBaseRenderGraphBuilder : IDisposable { /// /// Declare that this pass uses the input texture. /// /// The texture resource to use during the pass. /// A combination of flags indicating how the resource will be used during the pass. Default value is set to AccessFlag.Read public void UseTexture(in TextureHandle input, AccessFlags flags = AccessFlags.Read); /// /// Declare that this pass uses the texture assigned to the global texture slot. The actual texture referenced is indirectly specified here it depends /// on the value previous passes that were added to the graph set for the global texture slot. If no previous pass set a texture to the global slot an /// exception will be raised. /// /// The global texture slot read by shaders in this pass. Use Shader.PropertyToID to generate these ids. /// A combination of flags indicating how the resource will be used during the pass. Default value is set to AccessFlag.Read public void UseGlobalTexture(int propertyId, AccessFlags flags = AccessFlags.Read); /// /// Indicate that this pass will reference all textures in global texture slots known to the graph. The default setting is false. /// It is highly recommended if you know which globals you pass will access to use UseTexture(glboalTextureSlotId) with individual texture slots instead of /// UseAllGlobalTextures(true) to ensure the graph can maximally optimize resource use and lifetimes. /// /// This function should only be used in cases where it is difficult/impossible to know which globals a pass will access. This is for example true if your pass /// renders objects in the scene (e.g. using CommandBuffer.DrawRendererList) that might be using arbitrary shaders which in turn may access arbitrary global textures. /// To avoid having to do a UseAllGlobalTextures(true) in this situation, you will either have to ensure *all* shaders are well behaved and do not access spurious /// globals our make sure your renderer list filters allow only shaders that are known to be well behaved to pass. /// /// If true the pass from which this is called will reference all global textures. public void UseAllGlobalTextures(bool enable); /// /// Make this pass set a global texture slot *at the end* of this pass. During this pass the global texture will still have it's /// old value. Only after this pass the global texture slot will take on the new value specified. /// Generally this pass will also do a UseTexture(write) on this texture handle to indicate it is generating this texture, but this is not really a requirement /// you can have a pass that simply sets up a new value in a global texture slot but doesn't write it. /// Although counter-intuitive at first, this call doesn't actually have a dependency on the passed in texture handle. It's only when a subsequent pass has /// a dependency on the global texture slot that subsequent pass will get a dependency on the currently set global texture for that slot. This means /// globals slots can be set without overhead if you're unsure if a resource will be used or not, the graph will still maintain the correct lifetimes. /// /// NOTE: When the `RENDER_GRAPH_CLEAR_GLOBALS` define is set, all shader bindings set through this function will be cleared once graph execution completes. /// /// The texture value to set in the global texture slot. This can be an null handle to clear the global texture slot. /// The global texture slot to set the value for. Use Shader.PropertyToID to generate the id. public void SetGlobalTextureAfterPass(in TextureHandle input, int propertyId); /// /// Declare that this pass uses the input compute buffer. /// /// The compute buffer resource to use during the pass. /// A combination of flags indicating how the resource will be used during the pass. Default value is set to AccessFlag.Read /// The value passed to 'input'. You should not use the returned value it will be removed in the future. public BufferHandle UseBuffer(in BufferHandle input, AccessFlags flags = AccessFlags.Read); /// /// Create a new Render Graph Texture resource. /// This texture will only be available for the current pass and will be assumed to be both written and read so users don't need to add explicit read/write declarations. /// /// Texture descriptor. /// A new transient TextureHandle. public TextureHandle CreateTransientTexture(in TextureDesc desc); /// /// Create a new Render Graph Texture resource using the descriptor from another texture. /// This texture will only be available for the current pass and will be assumed to be both written and read so users don't need to add explicit read/write declarations. /// /// Texture from which the descriptor should be used. /// A new transient TextureHandle. public TextureHandle CreateTransientTexture(in TextureHandle texture); /// /// Create a new Render Graph Graphics Buffer resource. /// This Graphics Buffer will only be available for the current pass and will be assumed to be both written and read so users don't need to add explicit read/write declarations. /// /// Compute Buffer descriptor. /// A new transient BufferHandle. public BufferHandle CreateTransientBuffer(in BufferDesc desc); /// /// Create a new Render Graph Graphics Buffer resource using the descriptor from another Graphics Buffer. /// This Graphics Buffer will only be available for the current pass and will be assumed to be both written and read so users don't need to add explicit read/write declarations. /// /// Graphics Buffer from which the descriptor should be used. /// A new transient BufferHandle. public BufferHandle CreateTransientBuffer(in BufferHandle computebuffer); /// /// This pass will read from this renderer list. RendererLists are always read-only in the graph so have no access flags. /// /// The Renderer List resource to use during the pass. public void UseRendererList(in RendererListHandle input); /// /// Enable asynchronous compute for this pass. /// /// Set to true to enable asynchronous compute. public void EnableAsyncCompute(bool value); /// /// Allow or not pass culling. /// By default all passes can be culled out if the render graph detects it's not actually used. /// In some cases, a pass may not write or read any texture but rather do something with side effects (like setting a global texture parameter for example). /// This function can be used to tell the system that it should not cull this pass. /// /// True to allow pass culling. public void AllowPassCulling(bool value); /// /// Allow commands in the command buffer to modify global state. This will introduce a render graph sync-point in the frame and cause all passes after this pass to never be /// reordered before this pass. This may nave negative impact on performance and memory use if not used carefully so it is recommended to only allow this in specific use cases. /// This will also set AllowPassCulling to false. /// /// True to allow global state modification. public void AllowGlobalStateModification(bool value); /// /// Enable foveated rendering for this pass. /// /// True to enable foveated rendering. public void EnableFoveatedRasterization(bool value); /// /// Generates debugging data for this pass, intended for visualization in the RenderGraph Viewer. /// /// True to enable debug data generation for this pass. public void GenerateDebugData(bool value); } /// /// An intermediary interface for builders that can set render attachments and random access attachments (UAV). /// public interface IRenderAttachmentRenderGraphBuilder : IBaseRenderGraphBuilder { /// /// Binds the texture as a color render target (MRT attachment) for this pass. /// /// The texture to bind as a render target for this pass. /// The MRT slot the shader writes to. This maps to `SV_Target` in the shader, for example, a value of `1` maps to `SV_Target1`. /// The access mode for the texture. The default value is `AccessFlags.Write`. /// /// Potential access flags: /// - Write: This pass outputs to the texture using render target rasterization. The render graph binds /// the texture to the specified MRT slot (index). In HLSL, write to the slot using /// `float4 outColor : SV_Target{index} = value;`. /// To use random-access writes, use `SetRandomAccessAttachment` (UAV). /// Don't write to this target with UAV-style indexed access (`operator[]`). /// - Read: This pass might read the current contents of the render target implicitly, depending /// on rasterization state (for example, blending operations that read before writing). /// /// The render graph can't determine how much of the target you overwrite. By default, it /// assumes partial updates and preserves existing content. If you fully overwrite the target /// (for example, in a fullscreen pass), use `AccessFlags.WriteAll` for better performance. /// void SetRenderAttachment(TextureHandle tex, int index, AccessFlags flags = AccessFlags.Write) { SetRenderAttachment(tex, index, flags, 0, -1); } /// /// Binds the texture as a color render target (MRT attachment) for this pass. /// /// The texture to bind as a render target for this pass. /// The MRT slot the shader writes to (corresponds to `SV_Target{index}`). /// How this pass accesses the texture. Defaults to `AccessFlags.Write`. /// The mip level to bind. /// The array slice to bind. Use -1 to bind all slices. /// /// Potential access flags: /// - Write: This pass outputs to the texture using render target rasterization. The render graph binds /// the texture to the specified MRT slot (index). In HLSL, write to the slot using /// `float4 outColor : SV_Target{index} = value;`. /// To use random-access writes, use `SetRandomAccessAttachment` (UAV). /// Don't write to this target with UAV-style indexed access (`operator[]`). /// - Read: This pass might read the current contents of the render target implicitly, depending /// on rasterization state (for example, blending operations that read before writing). /// /// The render graph can't determine how much of the target you overwrite. By default, it /// assumes partial updates and preserves existing content. If you fully overwrite the target /// (for example, in a fullscreen pass), use `AccessFlags.WriteAll` for better performance. /// /// Using the same texture handle with different depth slices at different render target indices is not supported. /// void SetRenderAttachment(TextureHandle tex, int index, AccessFlags flags, int mipLevel, int depthSlice); /// /// Binds the texture as the depth buffer for this pass. /// /// The texture to use as the depth buffer for this pass. /// Access mode for the texture in this pass. Defaults to `AccessFlag.ReadWrite`. /// /// /// Potential access flags: /// - Write: The pass writes fragment depth to the bound depth buffer (required if `ZWrite` is enabled in shader code). /// - Read: The pass reads from the bound depth buffer for depth testing (required if `ZTest` is set to an operation other than `Disabled`, `Never`, or `Always` in shader code). /// /// Only one depth buffer can be tested against or written to in a single pass. /// To output depth to multiple textures, register the additional texture as a color /// attachment using `SetRenderAttachment()`, then compute and write the depth value in the shader. /// If you call `SetRenderAttachmentDepth()` more than once on the same builder, it results in an error. /// void SetRenderAttachmentDepth(TextureHandle tex, AccessFlags flags = AccessFlags.ReadWrite) { SetRenderAttachmentDepth(tex, flags, 0, -1); } /// /// Binds the texture as the depth buffer for this pass. /// /// The texture to use as the depth buffer for this pass. /// How this pass will access the depth texture (for example, `AccessFlags.Read`, `AccessFlags.Write`, `AccessFlags.ReadWrite`). /// The mip level to bind. /// The array slice to bind. Use -1 to bind all slices. /// /// Potential access flags: /// - Write: The pass writes fragment depth to the bound depth buffer (required if `ZWrite` is enabled in shader code). /// - Read: The pass reads from the bound depth buffer for depth testing (required if `ZTest` is set to an operation other than `Disabled`, `Never`, or `Always` in shader code). /// /// Only one depth texture can be read from or written to in a single pass. /// To output depth to multiple textures, register the additional texture as a color /// attachment using `SetRenderAttachment()`, then compute and write the depth value in the shader. /// If you call `SetRenderAttachmentDepth()` more than once on the same builder, it results in an error. /// /// Using the same texture handle with different depth slices at different render target indices is not supported. /// void SetRenderAttachmentDepth(TextureHandle tex, AccessFlags flags, int mipLevel, int depthSlice); /// /// Binds the texture as a random-access attachment for this pass /// (DX12: Unordered Access View, Vulkan: Storage Image). /// /// The texture to expose as a UAV in this pass. /// The binding slot the shader uses to access this UAV (HLSL: `register(u[index])`). /// Access mode for this texture in the pass. Defaults to `AccessFlags.ReadWrite`. /// /// This declares that shaders in the pass will access the texture via /// `RWTexture2D`, `RWTexture3D`, etc., enabling read/write operations, /// atomics, and other UAV-style operations using standard HLSL. /// /// The value passed to the `tex` parameter. The return value is deprecated. /// /// /// Random-access (UAV) textures share index-based binding slots with /// render targets and input attachments. Refer to `CommandBuffer.SetRandomWriteTarget` /// for platform-specific details and constraints. /// TextureHandle SetRandomAccessAttachment(TextureHandle tex, int index, AccessFlags flags = AccessFlags.ReadWrite); /// /// Binds the buffer as a random-access attachment for this pass /// (DX12: Unordered Access View, Vulkan: Storage Buffer). /// /// The buffer to expose as a UAV in this pass. /// The binding slot the shader uses to access this UAV (HLSL: `register(u[index])`). /// Access mode for this buffer in the pass. Defaults to `AccessFlags.Read`. /// /// The value passed to the `buffer` parameter. The return value is deprecated. /// /// /// This declares that shaders in the pass will access the buffer via /// `RWStructuredBuffer`, `RWByteAddressBuffer`, etc., enabling read/write, /// atomics, and other UAV-style operations using standard HLSL. /// /// Random-access (UAV) buffers share index-based binding slots with /// render targets and input attachments. Refer to `CommandBuffer.SetRandomWriteTarget` /// for platform-specific details and constraints. /// BufferHandle UseBufferRandomAccess(BufferHandle tex, int index, AccessFlags flags = AccessFlags.Read); /// /// Binds the buffer as a random-access attachment for this pass /// (DX12: Unordered Access View, Vulkan: Storage Buffer). /// /// The buffer to expose as a UAV in this pass. /// The binding slot the shader uses to access this UAV (HLSL: `register(u[index])`). /// Whether to keep the current append/consume counter unchanged for this UAV buffer. Defaults to preserving the existing counter value. /// Access mode for this buffer in the pass. Defaults to `AccessFlags.Read`. /// /// The value passed to the `buffer` parameter. The return value is deprecated. /// /// /// This declares that shaders in the pass will access the buffer via /// `RWStructuredBuffer`, `RWByteAddressBuffer`, etc., enabling read/write, /// atomics, and other UAV-style operations using standard HLSL. /// /// Random-access (UAV) buffers share index-based binding slots with /// render targets and input attachments. Refer to `CommandBuffer.SetRandomWriteTarget` /// for platform-specific details and constraints. /// BufferHandle UseBufferRandomAccess(BufferHandle tex, int index, bool preserveCounterValue, AccessFlags flags = AccessFlags.Read); } /// /// A builder for a compute render pass. /// /// [MovedFrom(true, "UnityEngine.Experimental.Rendering.RenderGraphModule", "UnityEngine.Rendering.RenderGraphModule")] public interface IComputeRenderGraphBuilder : IBaseRenderGraphBuilder { /// /// Specify the render function to use for this pass. /// A call to this is mandatory for the pass to be valid. /// /// The Type of the class that provides data to the Render Pass. /// Render function for the pass. public void SetRenderFunc(BaseRenderFunc renderFunc) where PassData : class, new(); } /// /// A builder for an unsafe render pass. /// /// [MovedFrom(true, "UnityEngine.Experimental.Rendering.RenderGraphModule", "UnityEngine.Rendering.RenderGraphModule")] public interface IUnsafeRenderGraphBuilder : IRenderAttachmentRenderGraphBuilder { /// /// Specify the render function to use for this pass. /// A call to this is mandatory for the pass to be valid. /// /// The Type of the class that provides data to the Render Pass. /// Render function for the pass. public void SetRenderFunc(BaseRenderFunc renderFunc) where PassData : class, new(); } /// /// A builder for a raster render pass. /// /// [MovedFrom(true, "UnityEngine.Experimental.Rendering.RenderGraphModule", "UnityEngine.Rendering.RenderGraphModule")] public interface IRasterRenderGraphBuilder : IRenderAttachmentRenderGraphBuilder { /// /// Binds the texture as an input attachment for this pass. /// /// Shaders might read this texture at the current fragment using /// `LOAD_FRAMEBUFFER_INPUT(idx)` or `LOAD_FRAMEBUFFER_INPUT_MS(idx, sampleIdx)`. /// The `idx` used in the shader must match the `index` provided to `SetInputAttachment`. /// /// /// Platform support varies. Input attachments, especially with MSAA, might be unsupported on /// some targets. Use `RenderGraphUtils.IsFramebufferFetchSupportedOnCurrentPlatform` at /// runtime to check compatibility. /// /// The texture to expose as an input attachment. /// The binding index used by the shader macros (`idx`). /// The access mode for this texture. Defaults to `AccessFlags.Read`. Writing is currently not supported on any platform. void SetInputAttachment(TextureHandle tex, int index, AccessFlags flags = AccessFlags.Read) { SetInputAttachment(tex, index, flags, 0, -1); } /// /// Binds the texture as an input attachment for this pass. /// /// Shaders might read this texture at the current fragment using /// `LOAD_FRAMEBUFFER_INPUT(idx)` or `LOAD_FRAMEBUFFER_INPUT_MS(idx, sampleIdx)`. /// The `idx` used in the shader must match the `index` provided in `SetInputAttachment`. /// /// /// Platform support varies. Input attachments, especially with MSAA, might be unsupported on /// some targets. Use `RenderGraphUtils.IsFramebufferFetchSupportedOnCurrentPlatform` at /// runtime to check compatibility. /// /// The texture to expose as an input attachment. /// The binding index used by the shader macros (`idx`). /// The access mode for the texture. Defaults to `AccessFlags.Read`. Writing is currently not supported on any platform. /// The mip level to bind. /// The array slice to bind. Use -1 to bind all slices. void SetInputAttachment(TextureHandle tex, int index, AccessFlags flags, int mipLevel, int depthSlice); /// /// Enables Variable Rate Shading (VRS) on the current rasterization pass. Rasterization will use the texture to determine the rate of fragment shader invocation. /// /// Shading rate image (SRI) Texture to use during this pass. void SetShadingRateImageAttachment(in TextureHandle tex); /// /// Set shading rate fragment size. /// /// Shading rate fragment size to set. void SetShadingRateFragmentSize(ShadingRateFragmentSize shadingRateFragmentSize); /// /// Set shading rate combiner. /// /// Shading rate combiner stage to apply combiner to. /// Shading rate combiner to set. void SetShadingRateCombiner(ShadingRateCombinerStage stage, ShadingRateCombiner combiner); /// /// Enables the configuration of extended pass properties that may allow platform-specific optimizations. /// /// Specifies additional pass properties that may enable optimizations on certain platforms. public void SetExtendedFeatureFlags(ExtendedFeatureFlags extendedFeatureFlags); /// /// Specify the render function to use for this pass. /// A call to this is mandatory for the pass to be valid. /// /// The Type of the class that provides data to the Render Pass. /// Render function for the pass. public void SetRenderFunc(BaseRenderFunc renderFunc) where PassData : class, new(); } }