Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Bug Build on IOS crashing when multiple SetComputeBufferData are called in one frame

Discussion in 'Universal Render Pipeline' started by CodeRoadOne, Jun 30, 2021.

  1. CodeRoadOne

    CodeRoadOne

    Joined:
    Mar 9, 2014
    Posts:
    52
    Hi,

    I'm using Unity 2020.3.10f1 with an URP project.
    I have a very simple code that can be used to repro this bug. Just attach the MonoBehaviour to an object in an empty scene and build for IOS.
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Rendering;
    5. using UnityEngine.UI;
    6.  
    7. public class TestCompute : MonoBehaviour
    8. {
    9.     private ComputeBuffer _gpuData1RB;
    10.     private List<byte> _dat1 = new List<byte>();
    11.     private int _frame = 0;
    12.  
    13.     private void Awake()
    14.     {
    15.         int dataSoupSize1 = 128 * 1024 * 1024;
    16.  
    17.         _gpuData1RB = new ComputeBuffer(dataSoupSize1, sizeof(int), ComputeBufferType.Raw);
    18.         _frame = 0;
    19.  
    20.         for(int i = 0; i < 10 * 1024 * 1024; ++i)
    21.         {
    22.             _dat1.Add(0);
    23.         }
    24.     }
    25.  
    26.     private void OnDestroy()
    27.     {
    28.         if (_gpuData1RB != null)
    29.         {
    30.             _gpuData1RB.Release();
    31.             _gpuData1RB = null;
    32.         }
    33.         RenderPipelineManager.beginFrameRendering -= BeginFrameRendering;
    34.     }
    35.  
    36.     // Start is called before the first frame update
    37.     void Start()
    38.     {
    39.         RenderPipelineManager.beginFrameRendering += BeginFrameRendering;
    40.     }
    41.  
    42.     // Update is called once per frame
    43.     void Update()
    44.     {
    45.     }
    46.  
    47.     void BeginFrameRendering(ScriptableRenderContext context, Camera[] cameras)
    48.     {
    49.         if(Application.isPlaying)
    50.         {
    51.             ComputeTest(context);
    52.         }
    53.     }
    54.  
    55.     void ComputeTest(ScriptableRenderContext context)
    56.     {
    57.         Debug.LogFormat("Ver 1 - frame {0}", ++_frame);
    58.         CommandBuffer cmd;
    59.  
    60.         cmd = CommandBufferPool.Get();
    61.  
    62.         if((_frame % 3)  == 0)
    63.         {
    64.             cmd.SetComputeBufferData(_gpuData1RB, _dat1, 0, 0, 1 * 1024 * 1024);
    65.             cmd.SetComputeBufferData(_gpuData1RB, _dat1, 0, 2 * 1024 * 1024, 1 * 1024 * 1024);
    66.             cmd.SetComputeBufferData(_gpuData1RB, _dat1, 0, 3 * 1024 * 1024, 1 * 1024 * 1024);
    67.         }
    68.  
    69.         context.ExecuteCommandBuffer(cmd);
    70.         CommandBufferPool.Release(cmd);
    71.     }
    72. }
    73.  
    This code is running perfectly on PC and Android. On IOS it is crashing inside Unity:
    IOS_bug.jpeg
    CopyScratchArea[inlined] IsPrivate at MetalScratchBuffer.h:68

    We did a test where we disabled the multithreaded rendering, but no luck:
    IOS_bugNoMultithreading.jpeg
    As you can see it is crashing in the same place.

    Any help with this will be appreciated.

    Thank you!
     
  2. CodeRoadOne

    CodeRoadOne

    Joined:
    Mar 9, 2014
    Posts:
    52
    Does anyone has an workaround the issue until (I hope), someone from Unity can fix the actual problem?
     
  3. kactus223

    kactus223

    Joined:
    May 20, 2014
    Posts:
    35
    We face this bug too.
     
  4. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,845
    Did anyone report a bug?
     
  5. CodeRoadOne

    CodeRoadOne

    Joined:
    Mar 9, 2014
    Posts:
    52
    Hi @aleksandrk,
    I'm not sure how to report it, so that's the reason I added everything with a simple example that can help re-create the issue.
    By the way there is a problem also with the DX12 implementation. I have similar crashes with similar code.

    Thank you
     
  6. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,845