Cmd.DrawMesh and Cmd.Blit produces visual glitches on Mac when using custom material.

Hi. I am building a post-processing effect using render passes. The idea is to blit to a temporary render texture to perform some actions with a shader and blit back to the screen.

Platform: Mac Ventura
Unity Version: 2021.3.14f1
Render Pipeline: URP

Using Cmd.Blit with a material does not work and causes visual glitches in the following image.

public class BlitPass : ScriptableRenderPass
{
    public BlitPass()
    {
        this.material = new Material(Shader.Find("Hidden/Universal Render Pipeline/Blit"));
        renderPassEvent = RenderPassEvent.AfterRenderingOpaques;
    }

    public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
    {
        colorDesc = renderingData.cameraData.cameraTargetDescriptor;
        colorDesc.depthBufferBits = 0;

        cmd.GetTemporaryRT(COLOR_BUFFER_ID, colorDesc, FilterMode.Bilinear);
    }

    public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
    {
        CommandBuffer cmd = CommandBufferPool.Get();
        using (new ProfilingScope(cmd, new ProfilingSampler("Blit")))
        {
            // doing this produces result in the image
            cmd.Blit(renderingData.cameraData.renderer.cameraColorTarget, colorBuffer, material);
            cmd.Blit(colorBuffer, renderingData.cameraData.renderer.cameraColorTarget, material);

            // doing this is fine
            //cmd.Blit(renderingData.cameraData.renderer.cameraColorTarget, colorBuffer);
            //cmd.Blit(colorBuffer, renderingData.cameraData.renderer.cameraColorTarget);
        }
           
        context.ExecuteCommandBuffer(cmd);
        CommandBufferPool.Release(cmd);
    }

    public override void OnCameraCleanup(CommandBuffer cmd)
    {
       cmd.ReleaseTemporaryRT(COLOR_BUFFER_ID);
    }
}

I am aware that there is a guide by Unity to blit xr (link). I proceeded to implement it as such. It also shows the same results.

public class BlitPass : ScriptableRenderPass
{
    public BlitPass()
    {
        this.material = new Material(Shader.Find("Hidden/Universal Render Pipeline/Blit"));
        renderPassEvent = RenderPassEvent.AfterRenderingOpaques;
    }

    public override void OnCameraSetup(CommandBuffer cmd, ref RenderingData renderingData)
    {
        colorDesc = renderingData.cameraData.cameraTargetDescriptor;
        colorDesc.depthBufferBits = 0;

        cmd.GetTemporaryRT(COLOR_BUFFER_ID, colorDesc, FilterMode.Bilinear);
    }

    private void Render(CommandBuffer cmd, RenderTargetIdentifier to, Material mat, int pass)
    {
       cmd.SetRenderTarget(to, RenderBufferLoadAction.DontCare, RenderBufferStoreAction.Store);
       cmd.DrawMesh(RenderingUtils.fullscreenMesh, Matrix4x4.identity, mat, 0, pass);
    }

    private void Render(CommandBuffer cmd, RenderTargetIdentifier from, RenderTargetIdentifier to, Material mat, int pass)
    {
       cmd.SetGlobalTexture(SOURCE_TEX_ID, from);
       Render(cmd, to, mat, pass);
    }

    public override void Execute(ScriptableRenderContext context, ref RenderingData renderingData)
    {
        CommandBuffer cmd = CommandBufferPool.Get();
        using (new ProfilingScope(cmd, new ProfilingSampler("Blit")))
        { 
            Render(cmd, renderingData.cameraData.renderer.cameraColorTarget, colorBuffer, material, 0);
            Render(cmd, colorBuffer, renderingData.cameraData.renderer.cameraColorTarget, material, 0);
        }
           
        context.ExecuteCommandBuffer(cmd);
        CommandBufferPool.Release(cmd);
    }


    public override void OnCameraCleanup(CommandBuffer cmd)
    {
       cmd.ReleaseTemporaryRT(COLOR_BUFFER_ID);
    }
}

Extra information:
Over time, the engine starts to slow down, with much stuttering and screen tearing. The engine needs to be restarted to continue working on this.

Any information on how to resolve this would be appreciated!

If this happens in 2021.3.16 make a bug report

Note that you will have to update your render feature/passes to use the RTHandle API for future URP versions. Given that you have a bug with the existing implementation, it might be worth making the move to RTHandles and seeing if it fixes the problem for you.

Do you know if the URP Blit material you link is designed for use with the Blitter API? I am able to blit with a custom shader on Mac/Metal without visual glitches, so I’d like to see the material you are using (I don’t have that version installed atm)