Search Unity

Procedural Mesh keeps disappearing

Discussion in 'Shaders' started by Christoph01755, Nov 5, 2018.

  1. Christoph01755

    Christoph01755

    Joined:
    Oct 8, 2018
    Posts:
    4
    Hello together,

    some time ago I'd managed to get procedurally generated meshes working in my unity project. Here is my original thread: https://forum.unity.com/threads/fee...t-with-vertices-from-structuredbuffer.566206/

    So the setup is quite simple: In a unity c-sharp monobehaviour skript I create a ComputeBuffer and a Mesh. The mesh gets indices, uvs and dummy-vertices. The ComputeBuffer gets filled with the actual vertex data of multiple instances. Then, in the mono behaviour's Update function, I call Graphics.DrawMeshInstancedIndirect() with very large bounds, because I'm doing my own frustum culling.

    This works fine, however, if i minimize the window, or click on my windows desktop and then again into the unity editor, all procedurally generated meshes disappear. How can this be? What's happening here?

    Thanks for hints or answers in advance!
     
  2. CharlieBudd

    CharlieBudd

    Joined:
    Jul 24, 2017
    Posts:
    17
    I am also getting this whilst using Graphics.DrawProcedural() to draw vertex data from a StructuredBuffer. The procedural draw calls still appear in the frame debugger and reading the data back from the buffer shows that the gpu vertex data is all still intact. Fairly certain that this is a bug but would be happy to be proved wrong
     
  3. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    That may just mean the data is intact on the CPU, it may even mean the data is still on the GPU, but there's a good chance the buffer is no longer properly bound on the GPU.

    Unity has some odd behavior during context switching, any non-serialized GPU data seems to get forgotten. Another example of this is if you use material property blocks to modify a material, and do so by just setting the value once on Start() or Awake(), after an application context switch that data may no longer be applied. For checking on GPU values I always check my assumptions using RenderDoc as that pulls the data directly from the GPU and not from Unity, so if there's a disparity between what the data Unity is saying and showing I can confirm my assumptions about where and why.

    I would try calling SetData() again on the buffer during OnApplicationFocus(true) and see if that solves it.
     
  4. CharlieBudd

    CharlieBudd

    Joined:
    Jul 24, 2017
    Posts:
    17
    Thanks for the heads up on RenderDoc, it looks very useful.Sounds like that may well be the problem, I will have to cache the data on exiting focus and re set it on enter focus. Thanks for the help