You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Packages/com.unity.render-pipelines.core/Documentation~/UnifiedRayTracing/create-ray-tracing-context.md
+7-4Lines changed: 7 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,7 @@ Follow these steps:
9
9
## Load the ray tracing resources
10
10
The [`RayTracingContext`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingContext) needs a few utility shaders that the [`RayTracingResources`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingResources) object supplies. You can load these resources in several different ways.
11
11
12
-
If your project uses SRP (Scriptable Render Pipeline), load the resources via [`RayTracingResources.LoadFromRenderPipelineResources`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingContext.LoadFromRenderPipelineResources()). This always works in the Editor.
12
+
If your project uses SRP (Scriptable Render Pipeline), load the resources via [`RayTracingResources.LoadFromRenderPipelineResources`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingResources.LoadFromRenderPipelineResources()). This always works in the Editor.
Once the [`RayTracingResources`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingResources) are loaded, use them to create the [`RayTracingContext`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingContext).
By default, Unity checks if the device supports hardware ray tracing, and selects either hardware ray tracing or compute shaders. To manually select the backend, pass in a `RayTracingBackend`. For example:
You must free up the memory your ray tracing objects use after you finish with them.
4
+
5
+
Dispose of the following:
6
+
7
+
- Scratch buffers. Use [`GraphicsBuffer.Dispose`](xref:UnityEngine.GraphicsBuffer.Dispose()) after you've executed the final command buffer.
8
+
- Ray tracing acceleration structures. Use [`IRayTracingAccelStruct.Dispose`](xref:UnityEngine.Rendering.UnifiedRayTracing.IRayTracingAccelStruct.Dispose()) after you've executed the final command buffer.
9
+
- Ray tracing context. Use [`RayTracingContext.Dispose`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingContext.Dispose()) after you dispose of all its acceleration structures.
10
+
11
+
**Note**: Unity automatically disposes of [`RayTracingResources`](xref:UnityEngine.Rendering.UnifiedRayTracing.RayTracingResources) and [`IRayTracingShader`](xref:UnityEngine.Rendering.UnifiedRayTracing.IRayTracingShader).
Copy file name to clipboardExpand all lines: Packages/com.unity.render-pipelines.core/Runtime/UnifiedRayTracing/RayTracingContext.cs
+6-2Lines changed: 6 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -332,7 +332,9 @@ static public GraphicsBuffer CreateScratchBufferForTrace(IRayTracingShader shade
332
332
/// Resizes a scratch buffer if its size doesn't fit the requirement of <see cref="IRayTracingShader.Dispatch"/>.
333
333
/// </summary>
334
334
/// <remarks>
335
-
/// The resize is accomplished by disposing of the GraphicsBuffer and instanciating a new one at the proper size.
335
+
/// Unity resizes the buffer by disposing of the `GraphicsBuffer` and instantiating a new one with the proper size.
336
+
/// **Important:** If you reference the current <paramref name="scratchBuffer"/> in a command buffer, you must
337
+
/// only call this method after you submit the command buffer. See <see cref="Graphics.ExecuteCommandBuffer"/> or <see cref="ScriptableRenderContext.ExecuteCommandBuffer"/>.
336
338
/// </remarks>
337
339
/// <param name="shader">The shader that will be passed to <see cref="IRayTracingShader.Dispatch"/>.</param>
338
340
/// <param name="dispatchWidth">Number of threads in the X dimension that will be passed to <see cref="IRayTracingShader.Dispatch"/>.</param>
@@ -362,7 +364,9 @@ static public void ResizeScratchBufferForTrace(
362
364
/// Resizes a scratch buffer if its size doesn't fit the requirement of <see cref="IRayTracingAccelStruct.Build"/>.
363
365
/// </summary>
364
366
/// <remarks>
365
-
/// The resize is accomplished by disposing of the GraphicsBuffer and instanciating a new one at the proper size.
367
+
/// Unity resizes the buffer by disposing of the `GraphicsBuffer` and instantiating a new one with the proper size.
368
+
/// **Important:** If you reference the current <paramref name="scratchBuffer"/> in a command buffer, you must
369
+
/// only call this method after you submit the command buffer. See <see cref="Graphics.ExecuteCommandBuffer"/> or <see cref="ScriptableRenderContext.ExecuteCommandBuffer"/>.
366
370
/// </remarks>
367
371
/// <param name="accelStruct">The acceleration structure that will be passed to <see cref="IRayTracingAccelStruct.Build"/>.</param>
0 commit comments