Custom SRP with Multiple Render Targets in Unity 2022

Hi,

I’ve upgraded from Unity 2021.3.40f1 to 2022.3.38f1. Everything works the same except for the frame debugger. When I select a drawcall in the frame debugger that is rendering to the MRT the details do not appear and I get the following errors -

GUI Error: Invalid GUILayout state in FrameDebuggerWindow view. Verify that all layout Begin/End calls match
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

IndexOutOfRangeException: Index was outside the bounds of the array.
UnityEditorInternal.FrameDebuggerInternal.FrameDebuggerEventDetailsView.DrawRenderTargetToolbar () (at <043e10ec4a0f4999a2729072194b9cfe>:0)
UnityEditorInternal.FrameDebuggerInternal.FrameDebuggerEventDetailsView.DrawEventDetails (UnityEngine.Rect rect, UnityEditorInternal.FrameDebuggerInternal.FrameDebuggerEvent descs, System.Boolean isDebuggingEditor) (at <043e10ec4a0f4999a2729072194b9cfe>:0)
UnityEditor.FrameDebuggerWindow.DrawEnabledFrameDebugger (System.Boolean repaint) (at <043e10ec4a0f4999a2729072194b9cfe>:0)
UnityEditor.FrameDebuggerWindow.OnGUI () (at <043e10ec4a0f4999a2729072194b9cfe>:0)
UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition) (at <043e10ec4a0f4999a2729072194b9cfe>:0)
UnityEditor.DockArea.DrawView (UnityEngine.Rect dockAreaRect) (at <043e10ec4a0f4999a2729072194b9cfe>:0)
UnityEditor.DockArea.OldOnGUI () (at <043e10ec4a0f4999a2729072194b9cfe>:0)
UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <02b90f1c0dfb49a1adfd6da071d5b611>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced.
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

I’ve found that the source of this seems to be something to do with the render target being a MRT, since when I change the MRT to a single render texture, it works fine with errors. The way I’ve implemented the MRT is as follows:


static RenderTargetIdentifier[] mrt = new RenderTargetIdentifier[8];

.........

buffer.GetTemporaryRT(litBufferId, bufferSize.x, bufferSize.y, 0, FilterMode.Point, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear);
        RenderTargetIdentifier litBufferID = new RenderTargetIdentifier(litBufferId);

        buffer.GetTemporaryRT(normalBufferId, bufferSize.x, bufferSize.y, 0, FilterMode.Point, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear);
        RenderTargetIdentifier normalBufferID = new RenderTargetIdentifier(normalBufferId);

        buffer.GetTemporaryRT(outlineParamBufferId, bufferSize.x, bufferSize.y, 0, FilterMode.Point, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear);
        RenderTargetIdentifier outlineParam0BufferID = new RenderTargetIdentifier(outlineParamBufferId);

        buffer.GetTemporaryRT(idBufferId, bufferSize.x, bufferSize.y, 0, FilterMode.Point, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear);
        RenderTargetIdentifier outlineParam1BufferID = new RenderTargetIdentifier(idBufferId);

        buffer.GetTemporaryRT(freeBufferId, bufferSize.x, bufferSize.y, 0, FilterMode.Point, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear);
        RenderTargetIdentifier outlineParam2BufferID = new RenderTargetIdentifier(freeBufferId);

        buffer.GetTemporaryRT(waterBufferId, bufferSize.x, bufferSize.y, 0, FilterMode.Point, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear);
        RenderTargetIdentifier outlineParam3BufferID = new RenderTargetIdentifier(waterBufferId);

        buffer.GetTemporaryRT(smoothnessBufferId, bufferSize.x, bufferSize.y, 0, FilterMode.Point, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear);
        RenderTargetIdentifier smoothnessBufferID = new RenderTargetIdentifier(smoothnessBufferId);

        buffer.GetTemporaryRT(particleBufferId, bufferSize.x, bufferSize.y, 0, FilterMode.Point, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear);
        RenderTargetIdentifier particleBufferID = new RenderTargetIdentifier(particleBufferId);

        buffer.SetGlobalTexture(litBufferId, litBufferID);
        buffer.SetGlobalTexture(normalBufferId, normalBufferID);
        buffer.SetGlobalTexture(outlineParamBufferId, outlineParam0BufferID);
        buffer.SetGlobalTexture(idBufferId, outlineParam1BufferID);
        buffer.SetGlobalTexture(freeBufferId, outlineParam2BufferID);
        buffer.SetGlobalTexture(waterBufferId, outlineParam3BufferID);
        buffer.SetGlobalTexture(smoothnessBufferId, smoothnessBufferID);
        buffer.SetGlobalTexture(depthBufferTempId, depthBufferTempID);
        buffer.SetGlobalTexture(particleBufferId, particleBufferID);
    
        mrt[0] = litBufferID;
        mrt[1] = normalBufferID;
        mrt[2] = outlineParam0BufferID;
        mrt[3] = outlineParam1BufferID;
        mrt[4] = outlineParam2BufferID;
        mrt[5] = outlineParam3BufferID;
        mrt[6] = smoothnessBufferID;
        mrt[7] = particleBufferID;

        buffer.SetRenderTarget(mrt, depthBufferTempId);
        buffer.ClearRenderTarget(true, true, Color.clear);
        ExecuteBuffer();

So when I change mrt to something like litBufferID, I get those error messages when using the frame debugger. Could someone give me some pointers on how to fix this issue please?

TIA

I figured out that the code is fine, everything works normally when I reduced the MRT size/buffer count from 8 to 7. Is there a way to get the frame debugger it to work with 8 buffers in Unity 2022 like it does in Unity 2021? Also, does the depth buffer add to the number of render targets I’m using, so I might actually be trying to do 9 render targets?