A game about forced loneliness, made by TACStudios
at master 339 lines 24 kB view raw
1using System; 2using UnityEngine.Scripting.APIUpdating; 3 4namespace UnityEngine.Rendering.RenderGraphModule 5{ 6 /// <summary> 7 /// Common base interface for the different render graph builders. These functions are supported on all builders. 8 /// </summary> 9 [MovedFrom(true, "UnityEngine.Experimental.Rendering.RenderGraphModule", "UnityEngine.Rendering.RenderGraphModule")] 10 public interface IBaseRenderGraphBuilder : IDisposable 11 { 12 /// <summary> 13 /// Declare that this pass uses the input texture. 14 /// </summary> 15 /// <param name="input">The texture resource to use during the pass.</param> 16 /// <param name="flags">A combination of flags indicating how the resource will be used during the pass. Default value is set to AccessFlag.Read </param> 17 public void UseTexture(in TextureHandle input, AccessFlags flags = AccessFlags.Read); 18 19 /// <summary> 20 /// Declare that this pass uses the texture assigned to the global texture slot. The actual texture referenced is indirectly specified here it depends 21 /// 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 22 /// exception will be raised. 23 /// </summary> 24 /// <param name="propertyId">The global texture slot read by shaders in this pass. Use Shader.PropertyToID to generate these ids.</param> 25 /// <param name="flags">A combination of flags indicating how the resource will be used during the pass. Default value is set to AccessFlag.Read </param> 26 public void UseGlobalTexture(int propertyId, AccessFlags flags = AccessFlags.Read); 27 28 /// <summary> 29 /// Indicate that this pass will reference all textures in global texture slots known to the graph. The default setting is false. 30 /// It is highly recommended if you know which globals you pass will access to use UseTexture(glboalTextureSlotId) with individual texture slots instead of 31 /// UseAllGlobalTextures(true) to ensure the graph can maximally optimize resource use and lifetimes. 32 /// 33 /// 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 34 /// renders objects in the scene (e.g. using CommandBuffer.DrawRendererList) that might be using arbitrary shaders which in turn may access arbitrary global textures. 35 /// 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 36 /// globals our make sure your renderer list filters allow only shaders that are known to be well behaved to pass. 37 /// </summary> 38 /// <param name="enable">If true the pass from which this is called will reference all global textures.</param> 39 public void UseAllGlobalTextures(bool enable); 40 41 /// <summary> 42 /// 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 43 /// old value. Only after this pass the global texture slot will take on the new value specified. 44 /// 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 45 /// you can have a pass that simply sets up a new value in a global texture slot but doesn't write it. 46 /// 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 47 /// 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 48 /// 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. 49 /// 50 /// NOTE: When the `RENDER_GRAPH_CLEAR_GLOBALS` define is set, all shader bindings set through this function will be cleared once graph execution completes. 51 /// </summary> 52 /// <param name="input">The texture value to set in the global texture slot. This can be an null handle to clear the global texture slot.</param> 53 /// <param name="propertyId">The global texture slot to set the value for. Use Shader.PropertyToID to generate the id.</param> 54 public void SetGlobalTextureAfterPass(in TextureHandle input, int propertyId); 55 56 /// <summary> 57 /// Declare that this pass uses the input compute buffer. 58 /// </summary> 59 /// <param name="input">The compute buffer resource to use during the pass.</param> 60 /// <param name="flags">A combination of flags indicating how the resource will be used during the pass. Default value is set to AccessFlag.Read </param> 61 /// <returns>The value passed to 'input'. You should not use the returned value it will be removed in the future.</returns> 62 public BufferHandle UseBuffer(in BufferHandle input, AccessFlags flags = AccessFlags.Read); 63 64 /// <summary> 65 /// Create a new Render Graph Texture resource. 66 /// 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. 67 /// </summary> 68 /// <param name="desc">Texture descriptor.</param> 69 /// <returns>A new transient TextureHandle.</returns> 70 public TextureHandle CreateTransientTexture(in TextureDesc desc); 71 72 /// <summary> 73 /// Create a new Render Graph Texture resource using the descriptor from another texture. 74 /// 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. 75 /// </summary> 76 /// <param name="texture">Texture from which the descriptor should be used.</param> 77 /// <returns>A new transient TextureHandle.</returns> 78 public TextureHandle CreateTransientTexture(in TextureHandle texture); 79 80 /// <summary> 81 /// Create a new Render Graph Graphics Buffer resource. 82 /// 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. 83 /// </summary> 84 /// <param name="desc">Compute Buffer descriptor.</param> 85 /// <returns>A new transient BufferHandle.</returns> 86 public BufferHandle CreateTransientBuffer(in BufferDesc desc); 87 88 /// <summary> 89 /// Create a new Render Graph Graphics Buffer resource using the descriptor from another Graphics Buffer. 90 /// 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. 91 /// </summary> 92 /// <param name="computebuffer">Graphics Buffer from which the descriptor should be used.</param> 93 /// <returns>A new transient BufferHandle.</returns> 94 public BufferHandle CreateTransientBuffer(in BufferHandle computebuffer); 95 96 /// <summary> 97 /// This pass will read from this renderer list. RendererLists are always read-only in the graph so have no access flags. 98 /// </summary> 99 /// <param name="input">The Renderer List resource to use during the pass.</param> 100 public void UseRendererList(in RendererListHandle input); 101 102 /// <summary> 103 /// Enable asynchronous compute for this pass. 104 /// </summary> 105 /// <param name="value">Set to true to enable asynchronous compute.</param> 106 public void EnableAsyncCompute(bool value); 107 108 /// <summary> 109 /// Allow or not pass culling. 110 /// By default all passes can be culled out if the render graph detects it's not actually used. 111 /// 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). 112 /// This function can be used to tell the system that it should not cull this pass. 113 /// </summary> 114 /// <param name="value">True to allow pass culling.</param> 115 public void AllowPassCulling(bool value); 116 117 /// <summary> 118 /// 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 119 /// 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. 120 /// This will also set AllowPassCulling to false. 121 /// </summary> 122 /// <param name="value">True to allow global state modification.</param> 123 public void AllowGlobalStateModification(bool value); 124 125 /// <summary> 126 /// Enable foveated rendering for this pass. 127 /// </summary> 128 /// <param name="value">True to enable foveated rendering.</param> 129 public void EnableFoveatedRasterization(bool value); 130 } 131 132 /// <summary> 133 /// A builder for a compute render pass 134 /// <see cref="RenderGraph.AddComputePass"/> 135 /// </summary> 136 [MovedFrom(true, "UnityEngine.Experimental.Rendering.RenderGraphModule", "UnityEngine.Rendering.RenderGraphModule")] 137 public interface IComputeRenderGraphBuilder : IBaseRenderGraphBuilder 138 { 139 140 /// <summary> 141 /// Specify the render function to use for this pass. 142 /// A call to this is mandatory for the pass to be valid. 143 /// </summary> 144 /// <typeparam name="PassData">The Type of the class that provides data to the Render Pass.</typeparam> 145 /// <param name="renderFunc">Render function for the pass.</param> 146 public void SetRenderFunc<PassData>(BaseRenderFunc<PassData, ComputeGraphContext> renderFunc) 147 where PassData : class, new(); 148 } 149 150 /// <summary> 151 /// A builder for an unsafe render pass. 152 /// <see cref="RenderGraph.AddUnsafePass"/> 153 /// </summary> 154 [MovedFrom(true, "UnityEngine.Experimental.Rendering.RenderGraphModule", "UnityEngine.Rendering.RenderGraphModule")] 155 public interface IUnsafeRenderGraphBuilder : IBaseRenderGraphBuilder 156 { 157 /// <summary> 158 /// Specify the render function to use for this pass. 159 /// A call to this is mandatory for the pass to be valid. 160 /// </summary> 161 /// <typeparam name="PassData">The Type of the class that provides data to the Render Pass.</typeparam> 162 /// <param name="renderFunc">Render function for the pass.</param> 163 public void SetRenderFunc<PassData>(BaseRenderFunc<PassData, UnsafeGraphContext> renderFunc) 164 where PassData : class, new(); 165 } 166 167 /// <summary> 168 /// A builder for a raster render pass 169 /// <see cref="RenderGraph.AddRasterRenderPass"/> 170 /// </summary> 171 [MovedFrom(true, "UnityEngine.Experimental.Rendering.RenderGraphModule", "UnityEngine.Rendering.RenderGraphModule")] 172 public interface IRasterRenderGraphBuilder : IBaseRenderGraphBuilder 173 { 174 /// <summary> 175 /// Use the texture as an rendertarget attachment. 176 /// 177 /// Writing: 178 /// Indicate this pass will write a texture through rendertarget rasterization writes. 179 /// The graph will automatically bind the texture as an MRT output on the indicated index slot. 180 /// Write in shader as float4 out : SV_Target{index} = value; This texture always needs to be written as an 181 /// render target (SV_Targetx) writing using other methods (like `operator[] =` ) may not work even if 182 /// using the current fragment+sampleIdx pos. When using operator[] please use the UseTexture function instead. 183 /// Reading: 184 /// Indicates this pass will read a texture on the current fragment position but not unnecessarily modify it. Although not explicitly visible in shader code 185 /// Reading may happen depending on the rasterization state, e.g. Blending (read and write) or Z-Testing (read only) may read the buffer. 186 /// 187 /// Note: The rendergraph does not know what content will be rendered in the bound texture. By default it assumes only partial data 188 /// is written (e.g. a small rectangle is drawn on the screen) so it will preserve the existing rendertarget content (e.g. behind/around the triangle) 189 /// if you know you will write the full screen the AccessFlags.WriteAll should be used instead as it will give better performance. 190 /// </summary> 191 /// <param name="tex">Texture to use during this pass.</param> 192 /// <param name="index">Index the shader will use to access this texture.</param> 193 /// <param name="flags">How this pass will access the texture. Default value is set to AccessFlag.Write </param> 194 void SetRenderAttachment(TextureHandle tex, int index, AccessFlags flags = AccessFlags.Write) 195 { 196 SetRenderAttachment(tex, index, flags, 0, -1); 197 } 198 199 /// <summary> 200 /// Use the texture as an rendertarget attachment. 201 /// 202 /// Writing: 203 /// Indicate this pass will write a texture through rendertarget rasterization writes. 204 /// The graph will automatically bind the texture as an MRT output on the indicated index slot. 205 /// Write in shader as float4 out : SV_Target{index} = value; This texture always needs to be written as an 206 /// render target (SV_Targetx) writing using other methods (like `operator[] =` ) may not work even if 207 /// using the current fragment+sampleIdx pos. When using operator[] please use the UseTexture function instead. 208 /// Reading: 209 /// Indicates this pass will read a texture on the current fragment position but not unnecessarily modify it. Although not explicitly visible in shader code 210 /// Reading may happen depending on the rasterization state, e.g. Blending (read and write) or Z-Testing (read only) may read the buffer. 211 /// 212 /// Note: The rendergraph does not know what content will be rendered in the bound texture. By default it assumes only partial data 213 /// is written (e.g. a small rectangle is drawn on the screen) so it will preserve the existing rendertarget content (e.g. behind/around the triangle) 214 /// if you know you will write the full screen the AccessFlags.WriteAll should be used instead as it will give better performance. 215 /// </summary> 216 /// <param name="tex">Texture to use during this pass.</param> 217 /// <param name="index">Index the shader will use to access this texture.</param> 218 /// <param name="flags">How this pass will access the texture. </param> 219 /// <param name="mipLevel">Selects which mip map to used.</param> 220 /// <param name="depthSlice">Used to index into a texture array. Use -1 to use bind all slices.</param> 221 void SetRenderAttachment(TextureHandle tex, int index, AccessFlags flags, int mipLevel, int depthSlice); 222 223 /// <summary> 224 /// Use the texture as an input attachment. 225 /// 226 /// This informs the graph that any shaders in pass will only read from this texture at the current fragment position using the 227 /// LOAD_FRAMEBUFFER_INPUT(idx)/LOAD_FRAMEBUFFER_INPUT_MS(idx,sampleIdx) macros. The index passed to LOAD_FRAMEBUFFER_INPUT needs 228 /// to match the index passed to SetInputAttachment for this texture. 229 /// 230 /// </summary> 231 /// <param name="tex">Texture to use during this pass.</param> 232 /// <param name="index">Index the shader will use to access this texture.</param> 233 /// <param name="flags">How this pass will access the texture. Default value is set to AccessFlag.Read. Writing is currently not supported on any platform. </param> 234 void SetInputAttachment(TextureHandle tex, int index, AccessFlags flags = AccessFlags.Read) 235 { 236 SetInputAttachment(tex, index, flags, 0, -1); 237 } 238 239 /// <summary> 240 /// Use the texture as an input attachment. 241 /// 242 /// This informs the graph that any shaders in pass will only read from this texture at the current fragment position using the 243 /// LOAD_FRAMEBUFFER_INPUT(idx)/LOAD_FRAMEBUFFER_INPUT_MS(idx,sampleIdx) macros. The index passed to LOAD_FRAMEBUFFER_INPUT needs 244 /// to match the index passed to SetInputAttachment for this texture. 245 /// 246 /// </summary> 247 /// <param name="tex">Texture to use during this pass.</param> 248 /// <param name="index">Index the shader will use to access this texture.</param> 249 /// <param name="flags">How this pass will access the texture. Writing is currently not supported on any platform. </param> 250 /// <param name="mipLevel">Selects which mip map to used.</param> 251 /// <param name="depthSlice">Used to index into a texture array. Use -1 to use bind all slices.</param> 252 void SetInputAttachment(TextureHandle tex, int index, AccessFlags flags, int mipLevel, int depthSlice); 253 254 /// <summary> 255 /// Use the texture as a depth buffer for the Z-Buffer hardware. Note you can only test-against and write-to a single depth texture in a pass. 256 /// If you want to write depth to more than one texture you will need to register the second texture as SetRenderAttachment and manually calculate 257 /// and write the depth value in the shader. 258 /// Calling SetRenderAttachmentDepth twice on the same builder is an error. 259 /// Write: 260 /// Indicate a texture will be written with the current fragment depth by the ROPs (but not for depth reading (i.e. z-test == always)). 261 /// Read: 262 /// Indicate a texture will be used as an input for the depth testing unit. 263 /// </summary> 264 /// <param name="tex">Texture to use during this pass.</param> 265 /// <param name="flags">How this pass will access the texture. Default value is set to AccessFlag.Write </param> 266 void SetRenderAttachmentDepth(TextureHandle tex, AccessFlags flags = AccessFlags.Write) 267 { 268 SetRenderAttachmentDepth(tex, flags, 0, -1); 269 } 270 271 /// <summary> 272 /// Use the texture as a depth buffer for the Z-Buffer hardware. Note you can only test-against and write-to a single depth texture in a pass. 273 /// If you want to write depth to more than one texture you will need to register the second texture as SetRenderAttachment and manually calculate 274 /// and write the depth value in the shader. 275 /// Calling SetRenderAttachmentDepth twice on the same builder is an error. 276 /// Write: 277 /// Indicate a texture will be written with the current fragment depth by the ROPs (but not for depth reading (i.e. z-test == always)). 278 /// Read: 279 /// Indicate a texture will be used as an input for the depth testing unit. 280 /// </summary> 281 /// <param name="tex">Texture to use during this pass.</param> 282 /// <param name="flags">How this pass will access the texture.</param> 283 /// <param name="mipLevel">Selects which mip map to used.</param> 284 /// <param name="depthSlice">Used to index into a texture array. Use -1 to use bind all slices.</param> 285 void SetRenderAttachmentDepth(TextureHandle tex, AccessFlags flags, int mipLevel, int depthSlice); 286 287 /// <summary> 288 /// Use the texture as an random access attachment. This is called "Unordered Access View" in DX12 and "Storage Image" in Vulkan. 289 /// 290 /// This informs the graph that any shaders in the pass will access the texture as a random access attachment through RWTexture2d&lt;T&gt;, RWTexture3d&lt;T&gt;,... 291 /// The texture can then be read/written by regular HLSL commands (including atomics, etc.). 292 /// 293 /// As in other parts of the Unity graphics APIs random access textures share the index-based slots with render targets and input attachments. See CommandBuffer.SetRandomWriteTarget for details. 294 /// </summary> 295 /// <param name="tex">Texture to use during this pass.</param> 296 /// <param name="index">Index the shader will use to access this texture. This is set in the shader through the `register(ux)` keyword.</param> 297 /// <param name="flags">How this pass will access the texture. Default value is set to AccessFlag.ReadWrite.</param> 298 /// <returns>The value passed to 'input'. You should not use the returned value it will be removed in the future.</returns> 299 TextureHandle SetRandomAccessAttachment(TextureHandle tex, int index, AccessFlags flags = AccessFlags.ReadWrite); 300 301 /// <summary> 302 /// Use the buffer as an random access attachment. This is called "Unordered Access View" in DX12 and "Storage Buffer" in Vulkan. 303 /// 304 /// This informs the graph that any shaders in the pass will access the buffer as a random access attachment through RWStructuredBuffer, RWByteAddressBuffer,... 305 /// The buffer can then be read/written by regular HLSL commands (including atomics, etc.). 306 /// 307 /// As in other parts of the Unity graphics APIs random access buffers share the index-based slots with render targets and input attachments. See CommandBuffer.SetRandomWriteTarget for details. 308 /// </summary> 309 /// <param name="tex">Buffer to use during this pass.</param> 310 /// <param name="index">Index the shader will use to access this texture. This is set in the shader through the `register(ux)` keyword.</param> 311 /// <param name="flags">How this pass will access the buffer. Default value is set to AccessFlag.Read.</param> 312 /// <returns>The value passed to 'input'. You should not use the returned value it will be removed in the future.</returns> 313 BufferHandle UseBufferRandomAccess(BufferHandle tex, int index, AccessFlags flags = AccessFlags.Read); 314 315 /// <summary> 316 /// Use the buffer as an random access attachment. This is called "Unordered Access View" in DX12 and "Storage Buffer" in Vulkan. 317 /// 318 /// This informs the graph that any shaders in the pass will access the buffer as a random access attachment through RWStructuredBuffer, RWByteAddressBuffer,... 319 /// The buffer can then be read/written by regular HLSL commands (including atomics, etc.). 320 /// 321 /// As in other parts of the Unity graphics APIs random access buffers share the index-based slots with render targets and input attachments. See CommandBuffer.SetRandomWriteTarget for details. 322 /// </summary> 323 /// <param name="tex">Buffer to use during this pass.</param> 324 /// <param name="index">Index the shader will use to access this texture. This is set in the shader through the `register(ux)` keyword.</param> 325 /// <param name="preserveCounterValue">Whether to leave the append/consume counter value unchanged. The default is to preserve the value.</param> 326 /// <param name="flags">How this pass will access the buffer. Default value is set to AccessFlag.Read.</param> 327 /// <returns>The value passed to 'input'. You should not use the returned value it will be removed in the future.</returns> 328 BufferHandle UseBufferRandomAccess(BufferHandle tex, int index, bool preserveCounterValue, AccessFlags flags = AccessFlags.Read); 329 330 /// <summary> 331 /// Specify the render function to use for this pass. 332 /// A call to this is mandatory for the pass to be valid. 333 /// </summary> 334 /// <typeparam name="PassData">The Type of the class that provides data to the Render Pass.</typeparam> 335 /// <param name="renderFunc">Render function for the pass.</param> 336 public void SetRenderFunc<PassData>(BaseRenderFunc<PassData, RasterGraphContext> renderFunc) 337 where PassData : class, new(); 338 } 339}