ScriptableRenderPass.OnCameraSetup()　と　ScriptableRenderPass.Configure()　の呼び出し比較

Unity2021.1.16f1で
ふとタイトルの　OnCameraSetup()　と　Configure()　を調べてみると困ったことに、コメントの記述がほぼ同じになっていた

```cs
        /// <summary>
        /// This method is called by the renderer before rendering a camera
        /// Override this method if you need to to configure render targets and their clear state, and to create temporary render target textures.
        /// If a render pass doesn't override this method, this render pass renders to the active Camera's render target.
        /// You should never call CommandBuffer.SetRenderTarget. Instead call <c>ConfigureTarget</c> and <c>ConfigureClear</c>.
        /// </summary>
        /// <param name="cmd">CommandBuffer to enqueue rendering commands. This will be executed by the pipeline.</param>
        /// <param name="renderingData">Current rendering state information</param>
        /// <seealso cref="ConfigureTarget"/>
        /// <seealso cref="ConfigureClear"/>
        public virtual void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
        {}
```

```cs
        /// <summary>
        /// This method is called by the renderer before executing the render pass.
        /// Override this method if you need to to configure render targets and their clear state, and to create temporary render target textures.
        /// If a render pass doesn't override this method, this render pass renders to the active Camera's render target.
        /// You should never call CommandBuffer.SetRenderTarget. Instead call <c>ConfigureTarget</c> and <c>ConfigureClear</c>.
        /// </summary>
        /// <param name="cmd">CommandBuffer to enqueue rendering commands. This will be executed by the pipeline.</param>
        /// <param name="cameraTextureDescriptor">Render texture descriptor of the camera render target.</param>
        /// <seealso cref="ConfigureTarget"/>
        /// <seealso cref="ConfigureClear"/>
        public virtual void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
        {}
```
引数のコメントは違うけどsummaryはほぼ同じ…。違いと言えば、

OnCameraSetup　は　This method is called by the renderer before rendering a camera　　　→　カメラの描画前
Configure　は　This method is called by the renderer before executing the render pass.　→　パスの実行前

せっかくなので呼ばれている箇所を比較してみた。

# ScriptableRenderPass.OnCameraSetup()　の呼び出しスタックトレース

* UniversalRenderPipeline.RenderSingleCamera()
* ScriptableRenderer.Execute()
* ScriptableRenderer.InternalStartRendering()
* ScriptableRenderPass.OnCameraSetup()

# ScriptableRenderPass.Configure()　の呼び出しスタックトレース

* UniversalRenderPipeline.RenderSingleCamera()
* ScriptableRenderer.Execute()
* ScriptableRenderer.ExecuteBlock()
* ScriptableRenderer.ExecuteRenderPass
* ScriptableRenderPass.Configure()

# 呼び出される順番を見る

お互いが呼び出されている　ScriptableRenderer.Execute()　を見てみます

```cs:ScriptableRenderer.csの一部抜粋
        public void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
        {
            ：//コマンドバッファの初期化など

            using (new ProfilingScope(cmdScope, profilingExecute))
            {
                InternalStartRendering(context, ref renderingData);//←OnCameraSetup()！

                ：//deltaTime周りの準備

                ：//RenderStateの準備など

                ：//Lightの準備など

                ：//RenderStateの準備など

                using (new ProfilingScope(cmd, Profiling.RenderBlock.beforeRendering))
                {
                    // Before Render Block. This render blocks always execute in mono rendering.
                    // Camera is not setup. Lights are not setup.
                    // Used to render input textures like shadowmaps.
                    ExecuteBlock(RenderPassBlock.BeforeRendering, in renderBlocks, context, ref renderingData);　//←ここでConfigure()！
                }

                ：//この後もRenderPassBlock毎にExecuteBlock()が連なっている

                InternalFinishRendering(context, cameraData.resolveFinalTarget);//←OnCameraSetup()と対のOnCameraCleanup()はここで呼ばれる
            }
        }
```
という事で、順番としては

```
OnCameraSetup()
RenderPassBlock.BeforeRendering　　　　　に含まれるRenderPassEventのPassのConfigure()
RenderPassBlock.MainRenderingOpaque　　　に含まれるRenderPassEventのPassのConfigure()
RenderPassBlock.MainRenderingTransparent に含まれるRenderPassEventのPassのConfigure()
RenderPassBlock.AfterRendering　　　　　　に含まれるRenderPassEventのPassのConfigure()
OnCameraCleanup()
```

な感じ。

---

描画時最初に行いたいカメラ設定はOnCameraSetup()で、その後にRenderPassBlockごとに行う調整はConfigure()で行うのが良さそうです

# 追記
RenderPassBlockについては別の記事を書きました↓

https://qiita.com/ScreenPocket/items/dcd0e8b6345988e01edd