Skip to content

Commit 71dac76

Browse files
markg-unityEvergreen
authored andcommitted
Add new task pages and fixes to render graph system documentation
Update render graph documentation with common tasks we missed, and fixes. Additions/changes are: - Add framebuffer fetch page - Add basic compute shader pages - Add relevant links to package samples - Fix issues raised by @adrien-moulin - Fix issues with render graph viewer reference raised by @arttu-peltonen - Fix other issues We've moved blit helper documentation to a separate ticket (https://jira.unity3d.com/browse/DOCG-5682) while we wait for a fix. Jira ticket: https://jira.unity3d.com/browse/DOCG-5214
1 parent e608f8f commit 71dac76

17 files changed

+390
-57
lines changed

Packages/com.unity.render-pipelines.universal/Documentation~/TableOfContents.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,17 @@
177177
* [Introduction to the render graph system](render-graph-introduction.md)
178178
* [Write a render pass using the render graph system](render-graph-write-render-pass.md)
179179
* [Use textures](working-with-textures.md)
180-
* [Create a render graph system texture](render-graph-create-a-texture.md)
180+
* [Create a texture in the render graph system](render-graph-create-a-texture.md)
181181
* [Import a texture into the render graph system](render-graph-import-a-texture.md)
182182
* [Access a texture in a custom render pass](render-graph-read-write-texture.md)
183183
* [Transfer a texture between render passes](render-graph-pass-textures-between-passes.md)
184184
* [URP blit best practices](customize/blit-overview.md)
185-
* [Draw objects in a render pass](render-graph-draw-objects-in-a-pass.md)
186185
* [Use frame data](accessing-frame-data.md)
186+
* [Get the current framebuffer with framebuffer fetch](render-graph-framebuffer-fetch.md)
187+
* [Draw objects in a render pass](render-graph-draw-objects-in-a-pass.md)
188+
* [Use a compute shader in a render pass](render-graph-compute-shader.md)
189+
* [Run a compute shader in a render pass](render-graph-compute-shader-run.md)
190+
* [Create input data for a compute shader](render-graph-compute-shader-input.md)
187191
* [Analyze a render graph](render-graph-view.md)
188192
* [Use Compatibility Mode APIs in render graph render passes](render-graph-unsafe-pass.md)
189193
* [Render Graph Viewer window reference](render-graph-viewer-reference.md)

Packages/com.unity.render-pipelines.universal/Documentation~/accessing-frame-data.md

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ You can fetch the textures the Universal Render Pipeline (URP) creates for the c
44

55
These textures are called frame data, resource data, or frame resources.
66

7-
Some textures might not exist in the frame data, depending on which injection point you use to insert your custom render pass into the URP frame rendering loop. Refer to the following for information about which textures exist when:
8-
9-
- [Injection points reference](customize/custom-pass-injection-points.md)
7+
Some textures might not exist in the frame data, depending on which injection point you use to insert your custom render pass into the URP frame rendering loop. For more information about which textures exist when, refer to [Injection points reference](customize/custom-pass-injection-points.md).
108

119
## Get frame data
1210

@@ -21,7 +19,7 @@ Follow these steps to get a handle to a texture in the frame data:
2119
```csharp
2220
public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer frameContext)
2321
{
24-
using (var builder = renderGraph.AddPass<PassData>("Get frame data", out var passData))
22+
using (var builder = renderGraph.AddRasterRenderPass<PassData>("Get frame data", out var passData))
2523
{
2624
UniversalResourceData frameData = frameContext.Get<UniversalResourceData>();
2725
}
@@ -36,7 +34,9 @@ Follow these steps to get a handle to a texture in the frame data:
3634
TextureHandle activeColorTexture = frameData.activeColorTexture;
3735
```
3836

39-
You can then read from and write to the texture. Refer to [Use a texture in a render pass](render-graph-read-write-texture.md) for more information.
37+
You can then read from and write to the texture. Refer to [Use a texture in a render pass](render-graph-read-write-texture.md).
38+
39+
The texture handle is valid only for the current render graph in the current frame.
4040

4141
You can use the [ConfigureInput](xref:UnityEngine.Rendering.Universal.ScriptableRenderPass.ConfigureInput(UnityEngine.Rendering.Universal.ScriptableRenderPassInput)) API to make sure URP generates the texture you need in the frame data.
4242

@@ -57,23 +57,21 @@ You can fetch the following textures from the frame data.
5757
| `cameraDepthTexture` | A copy of the depth texture, if you enable **Depth Priming Mode** in the [renderer](urp-universal-renderer.md) or **Depth Texture** in the active [URP Asset](universalrp-asset.md). | `CopyDepth` or `DepthPrepass` |
5858
| `cameraNormalsTexture` | The scene normals texture. Contains the scene depth for objects with shaders that have a `DepthNormals` pass. | `DepthNormals` prepass |
5959
| `cameraOpaqueTexture` | A texture with the opaque objects in the scene, if you enable **Opaque Texture** in the [URP Asset](universalrp-asset.md). | `CopyColor` |
60-
| `dBuffer` | The Decals texture. Refer to [DBuffer](renderer-feature-decal.md#dbuffer) for more information. | `Decals` |
61-
| `dBufferDepth` | The Decals depth texture. Refer to [DBuffer](renderer-feature-decal.md#dbuffer) for more information. | `Decals` |
60+
| `dBuffer` | The Decals texture. For more information about the decals texture, refer to [DBuffer](renderer-feature-decal.md#dbuffer). | `Decals` |
61+
| `dBufferDepth` | The Decals depth texture. Refer to [DBuffer](renderer-feature-decal.md#dbuffer). | `Decals` |
6262
| `debugScreenTexture` | If you enable [HDR Debug Views](post-processing/hdr-output.md#hdr-debug-views), URP writes the output of [post-processing](integration-with-post-processing.md) to this texture instead of `backBufferColor`. | `uberPost` and `finalPost` |
63-
| `gBuffer` | The G-buffer textures. Refer to [G-buffer](rendering/deferred-rendering-path.md#g-buffer-layout) for more information. | `GBuffer` |
63+
| `gBuffer` | The G-buffer textures. Refer to [G-buffer](rendering/deferred-rendering-path.md#g-buffer-layout). | `GBuffer` |
6464
| `internalColorLut` | The internal look-up textures (LUT) texture. | `InternalLut` |
6565
| `mainShadowsTexture ` | The main shadow map. | `ShadowCaster` |
66-
| `motionVectorColor` | The motion vectors color texture. Refer to [motion vectors](features/motion-vectors.md) for more information. | `Camera Motion Vectors` and `MotionVectors` |
67-
| `motionVectorDepth` | The motion vectors depth texture. Refer to [motion vectors](features/motion-vectors.md) for more information. | `Camera Motion Vectors` and `MotionVectors` |
66+
| `motionVectorColor` | The motion vectors color texture. Refer to [motion vectors](features/motion-vectors.md). | `Camera Motion Vectors` and `MotionVectors` |
67+
| `motionVectorDepth` | The motion vectors depth texture. Refer to [motion vectors](features/motion-vectors.md). | `Camera Motion Vectors` and `MotionVectors` |
6868
| `overlayUITexture` | The overlay UI texture. | `DrawScreenSpaceUI` |
6969
| `renderingLayersTexture` | The Rendering Layers texture. Refer to [Rendering layers](features/rendering-layers.md) | `DrawOpaques` or the `DepthNormals` prepass, depending on your settings. |
70-
| `ssaoTexture` | The Screen Space Ambient Occlusion (SSAO) texture. Refer to [Ambient occlusion](post-processing-ssao.md) for more information. | `SSAO` |
70+
| `ssaoTexture` | The Screen Space Ambient Occlusion (SSAO) texture. Refer to [Ambient occlusion](post-processing-ssao.md). | `SSAO` |
7171

7272
## Example
7373

74-
Refer to the following for examples of custom render passes that use the frame data:
75-
76-
- The render graph system samples in the [URP package samples](package-sample-urp-package-samples.md)
74+
For a full example, refer to the example called **TextureReference w. FrameData** in the [Universal Render Pipeline (URP) package samples](package-samples.md).
7775

7876
## Additional resources
7977

Packages/com.unity.render-pipelines.universal/Documentation~/package-samples.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,5 @@ To open a package sample:
2727

2828
The package samples that URP provides are:
2929

30-
* URP Package Samples: A collection of example shaders, C# scripts, and other assets you can build upon or use in your application. For more information, refer to [URP Package Samples](package-sample-urp-package-samples.md).
30+
* URP Package Samples: A collection of example shaders, C# scripts, and other assets you can build upon or use in your application. Refer to [URP Package Samples](package-sample-urp-package-samples.md).
31+
* URP RenderGraph Samples: A collection of example [Scriptable Renderer Features](renderer-features/scriptable-renderer-features/scriptable-renderer-features-landing.md) demonstrating how to use the render graph system. For more information about the render graph samples, refer to [Render graph system](render-graph.md).
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
## Create input data for a compute shader
3+
4+
When you [run a compute shader in a render pass](render-graph-compute-shader-run.md), you can allocate a buffer to provide input data for the compute shader.
5+
6+
Follow these steps:
7+
8+
1. Create a graphics buffer, then add a handle to it in your pass data. For example:
9+
10+
```csharp
11+
// Declare an input buffer
12+
public GraphicsBuffer inputBuffer;
13+
14+
// Add a handle to the input buffer in your pass data
15+
class PassData
16+
{
17+
...
18+
public BufferHandle input;
19+
}
20+
21+
// Create the buffer in the render pass constructor
22+
public ComputePass(ComputeShader computeShader)
23+
{
24+
// Create the input buffer as a structured buffer
25+
// Create the buffer with a length of 5 integers, so you can input 5 values.
26+
inputBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Structured, 5, sizeof(int));
27+
}
28+
```
29+
30+
2. Set the data in the buffer. For example:
31+
32+
```csharp
33+
var inputValues = new List<int> { 1, 2, 3, 4, 5 };
34+
inputBuffer.SetData(inputValues);
35+
```
36+
37+
3. Use the `ImportBuffer` render graph API to convert the buffer to a handle the render graph system can use, then set the `BufferHandle` field in the pass data. For example:
38+
39+
```csharp
40+
BufferHandle inputHandleRG = renderGraph.ImportBuffer(inputBuffer);
41+
passData.input = inputHandleRG;
42+
```
43+
44+
4. Use the `UseBuffer` method to set the buffer as a readable buffer in the render graph system. For example:
45+
46+
```csharp
47+
builder.UseBuffer(passData.input, AccessFlags.Read);
48+
```
49+
5. In your `SetRenderFunc` method, use the [`SetComputeBufferParam`](https://docs.unity3d.com/ScriptReference/Rendering.CommandBuffer.SetComputeBufferParam.html) API to attach the buffer to the compute shader. For example:
50+
51+
```csharp
52+
// The first parameter is the compute shader
53+
// The second parameter is the function that uses the buffer
54+
// The third parameter is the RWStructuredBuffer input variable to attach the buffer to
55+
// The fourth parameter is the handle to the input buffer
56+
context.cmd.SetComputeBufferParam(passData.computeShader, passData.computeShader.FindKernel("Main"), "inputData", passData.input);
57+
```
58+
59+
## Example
60+
61+
For a full example, refer to the example called **Compute** in the [Universal Render Pipeline (URP) package samples](package-samples.md).
62+
63+
## Additional resources
64+
65+
- [Compute shaders](https://docs.unity3d.com/6000.0/Documentation/Manual/class-ComputeShader.html)
66+
- [Writing shaders](https://docs.unity3d.com/6000.0/Documentation/Manual/shader-writing.html)
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Run a compute shader in a render pass
2+
3+
To create a render pass that runs a compute shader, do the following:
4+
5+
1. Set up the render pass to use a compute shader.
6+
2. Add an output buffer.
7+
3. Pass in and execute the compute shader.
8+
4. Get the output data from the output buffer.
9+
10+
To check if a platform supports compute shaders, use the [`SystemInfo.supportsComputeShaders`](https://docs.unity3d.com/ScriptReference/SystemInfo-supportsComputeShaders.html) API
11+
12+
## Set up the render pass to use a compute shader
13+
14+
When you [create a `ScriptableRenderPass`](render-graph-write-render-pass.md), do the following:
15+
16+
1. Use `AddComputePass` instead of `AddRasterRenderPass`.
17+
2. Use `ComputeGraphContext` instead of `RasterGraphContext`.
18+
19+
For example:
20+
21+
```csharp
22+
class ComputePass : ScriptableRenderPass
23+
{
24+
...
25+
26+
public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer contextData)
27+
{
28+
...
29+
// Use AddComputePass instead of AddRasterRenderPass.
30+
using (var builder = renderGraph.AddComputePass("MyComputePass", out PassData data))
31+
{
32+
...
33+
34+
// Use ComputeGraphContext instead of RasterGraphContext.
35+
builder.SetRenderFunc((PassData data, ComputeGraphContext context) => ExecutePass(data, context));
36+
37+
...
38+
}
39+
}
40+
}
41+
42+
```
43+
44+
## Add an output buffer
45+
46+
To create a buffer the compute shader outputs to, follow these steps:
47+
48+
1. Create a graphics buffer, then add a handle to it in your pass data.
49+
50+
```csharp
51+
// Declare an output buffer
52+
public GraphicsBuffer outputBuffer;
53+
54+
// Add a handle to the output buffer in your pass data
55+
class PassData
56+
{
57+
public BufferHandle output;
58+
}
59+
60+
// Create the buffer in the render pass constructor
61+
public ComputePass(ComputeShader computeShader)
62+
{
63+
// Create the output buffer as a structured buffer
64+
// Create the buffer with a length of 5 integers, so the compute shader can output 5 values.
65+
outputBuffer = new GraphicsBuffer(GraphicsBuffer.Target.Structured, 5, sizeof(int));
66+
}
67+
```
68+
69+
2. Use the `ImportBuffer` render graph API to convert the buffer to a handle the render graph system can use, then set the `BufferHandle` field in the pass data. For example:
70+
71+
```csharp
72+
BufferHandle outputHandleRG = renderGraph.ImportBuffer(outputBuffer);
73+
passData.output = outputHandleRG;
74+
```
75+
76+
77+
3. Use the `UseBuffer` method to set the buffer as a writeable buffer in the render graph system.
78+
79+
```csharp
80+
builder.UseBuffer(passData.output, AccessFlags.Write);
81+
```
82+
83+
## Pass in and execute the compute shader
84+
85+
Follow these steps:
86+
87+
1. Pass the compute shader to the render pass. For example, in a `ScriptableRendererFeature` class, expose a `ComputeShader` property, then pass the compute shader into the render pass class.
88+
89+
2. Add a `ComputeShader` field to your pass data, and set it to the compute shader. For example:
90+
91+
```csharp
92+
// Add a `ComputeShader` field to your pass data
93+
class PassData
94+
{
95+
...
96+
public ComputeShader computeShader;
97+
}
98+
99+
// Set the `ComputeShader` field to the compute shader
100+
passData.computeShader = yourComputeShader;
101+
```
102+
103+
3. In your `SetRenderFunc` method, use the [`SetComputeBufferParam`](https://docs.unity3d.com/ScriptReference/Rendering.CommandBuffer.SetComputeBufferParam.html) API to attach the buffer to the compute shader. For example:
104+
105+
```csharp
106+
// The first parameter is the compute shader
107+
// The second parameter is the function that uses the buffer
108+
// The third parameter is the StructuredBuffer output variable to attach the buffer to
109+
// The fourth parameter is the handle to the output buffer
110+
context.cmd.SetComputeBufferParam(passData.computeShader, passData.computeShader.FindKernel("Main"), "outputData", passData.output);
111+
```
112+
113+
4. Use the [`DispatchCompute`](https://docs.unity3d.com/ScriptReference/Rendering.CommandBuffer.DispatchCompute.html) API to execute the compute shader.
114+
115+
```csharp
116+
context.cmd.DispatchCompute(passData.computeShader, passData.computeShader.FindKernel("CSMain"), 1, 1, 1);
117+
```
118+
119+
## Get the output data from the output buffer
120+
121+
To fetch the data from the output buffer, use the [`GraphicsBuffer.GetData`](https://docs.unity3d.com/ScriptReference/GraphicsBuffer.GetData.html) API.
122+
123+
You can only fetch the data after the render pass executes and the compute shader finishes running.
124+
125+
For example:
126+
127+
```csharp
128+
// Create an array to store the output data
129+
outputData = new int[5];
130+
131+
// Copy the output data from the output buffer to the array
132+
outputBuffer.GetData(outputData);
133+
```
134+
135+
## Example
136+
137+
For a full example, refer to the example called **Compute** in the [render graph system URP package samples](package-samples.md).
138+
139+
## Additional resources
140+
141+
- [Compute shaders](https://docs.unity3d.com/6000.0/Documentation/Manual/class-ComputeShader.html)
142+
- [Writing shaders](https://docs.unity3d.com/6000.0/Documentation/Manual/shader-writing.html)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Use a compute shader in a render pass
2+
3+
To create a render pass that runs a compute shader, use the render graph system.
4+
5+
| Page | Description |
6+
|-|-|
7+
| [Run a compute shader in a render pass](render-graph-compute-shader-run.md) | Create a render pass that allocates a buffer and runs a compute shader to output data into the buffer. |
8+
| [Create input data for a compute shader](render-graph-compute-shader-input.md) | Allocate a buffer that provides input data for a compute shader in a render pass. |
9+
10+
## Additional resources
11+
12+
- [Compute shaders](https://docs.unity3d.com/6000.0/Documentation/Manual/class-ComputeShader.html)
13+
- [Writing shaders](https://docs.unity3d.com/6000.0/Documentation/Manual/shader-writing.html)

Packages/com.unity.render-pipelines.universal/Documentation~/render-graph-create-a-texture.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Create a render graph system texture
1+
# Create a texture in the render graph system
22

3-
You can create a render graph texture in a custom render pass. You can then [read from or write to the texture](render-graph-read-write-texture.md).
3+
To create a texture in the render graph system, use the `UniversalRenderer.CreateRenderGraphTexture` API.
44

5-
When the Universal Render Pipeline (URP) optimizes the render graph, it might not create a texture if the final frame doesn't use the texture, to reduce the memory and bandwidth the render passes use. Refer to [Introduction to the render graph system](render-graph-introduction.md) for more information.
5+
When the Universal Render Pipeline (URP) optimizes the render graph, it might not create a texture if the final frame doesn't use the texture, to reduce the memory and bandwidth the render passes use. For more information about how URP optimizes render graphs, refer to [Introduction to the render graph system](render-graph-introduction.md).
66

7-
If you need to use a texture in multiple frames or on multiple cameras, for example a texture asset you imported in your project, refer to [Import a texture into the render graph system](render-graph-import-a-texture.md).
7+
For more information about using a texture in multiple frames or on multiple cameras, for example a texture asset you imported in your project, refer to [Import a texture into the render graph system](render-graph-import-a-texture.md).
88

99
## Create a texture
1010

@@ -28,7 +28,7 @@ The render graph system manages the lifetime of textures you create with `Create
2828

2929
### Example
3030

31-
The following Scriptable Renderer Feature contains an example render pass that creates a texture and clears it to yellow. Refer to [Inject a pass using a Scriptable Renderer Feature](renderer-features/scriptable-renderer-features/inject-a-pass-using-a-scriptable-renderer-feature.md#add-renderer-feature-to-asset) for instructions on how to add the render pass to a project.
31+
The following Scriptable Renderer Feature contains an example render pass that creates a texture and clears it to yellow. For more information about adding the render pass to the render pipeline, refer to [Inject a pass using a Scriptable Renderer Feature](renderer-features/scriptable-renderer-features/inject-a-pass-using-a-scriptable-renderer-feature.md#add-renderer-feature-to-asset).
3232

3333
Use the [Frame Debugger](https://docs.unity3d.com/2023.3/Documentation/Manual/frame-debugger-window.html) to check the texture the render pass adds.
3434

@@ -89,6 +89,8 @@ public class CreateYellowTextureFeature : ScriptableRendererFeature
8989
}
9090
```
9191

92+
For another example, refer to the example called **OutputTexture** in the [Universal Render Pipeline (URP) package samples](package-samples.md).
93+
9294
## Additional resources
9395

9496
* [Import a texture into the render graph system](render-graph-import-a-texture.md)

0 commit comments

Comments
 (0)