Skip to content

Commit 62ad5f8

Browse files
vincent-breysseEvergreen
authored andcommitted
Fix Profilers.EndSample error with custom render passes calling Submit()
Fix https://jira.unity3d.com/browse/UUM-69066 This bug happens when an user calls `Submit()` inside `ScriptableRenderPass.Execute()`. This is causing the profiler marker order to be ill-formed. Here is more detailled explanation of what happens. URP `ScriptableRenderer.Execute` function looks like this: ``` void ScriptableRendererExecute() { using (new ProfilingScope(cmd, profilingExecute)) { /* ... */ foreach (ScriptableRenderPass renderPass in renderPassBlock) { renderPass.Execute(); } /* ... */ } } ``` And `ProfilingScope` ctor/dtor look like this: ``` ProfilingScope(CommandBuffer cmd, ProfilingSampler sampler) { cmd.BeginSample(sampler); sampler.inlineSampler.Begin(); } void Dispose() { cmd.EndSample(sampler); sampler.inlineSampler.End(); } ``` So here is what happens with this setup when Submit() is called inside ScriptableRenderPass.Execute() : ``` void ScriptableRendererExecute() { cmd.BeginSample(sampler); // Deferred profiler_begin() which will be called in Submit() sampler.inlineSampler.Begin(); // Calls profiler_begin() immediately // Inside renderPass.Execute() context.Submit(); // Calls the deferred profiler_begin() cmd.EndSample(sampler); // Deferred profiler_end() which will be called in Submit() sampler.inlineSampler.End(); / Calls profiler_end() immediately -> Error. The previous profiler_begin() call has no corresponding profiler_end() } ``` Since we have no way to know in advance whether a render pass will call `Submit()` or not, we can't know if it is fine to use command buffer based profiling scope without causing errors. So the fix proposed here is to simply not use that when there is a risk that Submit() is called inside of the profiling scope. We can simply stick to normal immediate profiler markers instead.
1 parent 8dbb5c0 commit 62ad5f8

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Packages/com.unity.render-pipelines.universal/Documentation~/renderer-features/scriptable-renderer-features/scriptable-render-pass-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ You can use the following methods within a Scriptable Render Pass to handle its
66
77
| **Method** | **Description** |
88
| ---------- | --------------- |
9-
| `Execute` | Use this method to implement the rendering logic for the Scriptable Renderer Feature.<br/><br/>**Note**: You do not need to call `ScriptableRenderContext.submit`. URP handles this and calls it at specific points in the pipeline. |
9+
| `Execute` | Use this method to implement the rendering logic for the Scriptable Renderer Feature.<br/><br/>**Note**: You must not call `ScriptableRenderContext.Submit` on a command buffer provided by URP. The render pipeline handles this at specific points in the pipeline. |
1010
| `OnCameraCleanup` | Use this method to clean up any resources that were allocated during the render pass. |
1111
| `OnCameraSetup` | Use this method to configure render targets and their clear state. You can also use it to create temporary render target textures.<br/><br/>**Note**: When this method is empty, the render pass renders to the active camera render target. |
1212

0 commit comments

Comments
 (0)