Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Indirect Instancing in the Editor

Discussion in 'General Graphics' started by JackieDevelops, Apr 1, 2018.

  1. JackieDevelops

    JackieDevelops

    Joined:
    May 11, 2017
    Posts:
    27
    So I have been using Graphics.DrawMeshInstancedIndirect for rendering some objects in my game. I would however like to also see these objects in the editor as well. If I use [ExecuteInEditMode] they draw perfectly fine, however things go wrong whenever I do a certain action in the editor.

    Actions include: Saving the scene, modifying a script, moving an asset in the database.

    What confuses me, is my drawcalls still exist, I can see my GPU load is high (reflecting that these objects are being requested for drawing), but the scene is just blank. Its like my drawcalls are rendering empty objects.
    Also, how are these draw calls even issued? The editor renders my objects every frame and I can see my gpu load, however its not through my Graphics.DrawMeshInstancedIndirect, because the method that contains this draw call (the Update() ) is not being called every frame (I put a Debug.Log i it).

    There is a lot of mystery surrounding how the editor is issueing its draw calls, and why making a modification to the project (save the scene, or save a script etc) causes everything to just collapse.

    Is it even possible to safely use drawmeshinstancedindirect with the editor?
     
  2. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    What happens is that the computebuffers on the GPU are cleared.
    I ended out falling back to normal instanced rendering while in the editor, only using the indirect in playmode.
     
    PutridEx likes this.
  3. JackieDevelops

    JackieDevelops

    Joined:
    May 11, 2017
    Posts:
    27
    Cleared in what sense?

    Because, my compute shader decides all the LODs and frustum culls putting the results in append buffers.
    If I read this data back to the CPU with GetData on each of the append buffers, the values are all correct. That is to say the number of lod0s/lod1s/lod2s all properly update as I move the scene camera around (so the compute shader is frustum culling something and appending to the correct buffers). I just get a blank scene drawn while issueing all the draw calls matching the append buffers.

    I figured if the computebuffers were cleared then that would all fall apart no?
     
  4. LennartJohansen

    LennartJohansen

    Joined:
    Dec 1, 2014
    Posts:
    2,394
    Yes. I never actually tried to read back the data. I just assumed some GPU data was cleared.
     
  5. JackieDevelops

    JackieDevelops

    Joined:
    May 11, 2017
    Posts:
    27
    I also noticed something else. If I simply release compute buffers from code inside my script while working in the editor... things dont fully clear properly. Say I use OnDisable/OnEnable to clear and re-initialize, I get extra things appended to my append buffers.

    If I do a save scene however, it works properly. I assume saving the scene does something more (deserialize/serialize?), which properly deallocates my gpu buffers.

    I am definitely confused, the whole editor rendering seems like a black box with no documentation that I can find. I dont even understand how its rendering something to screen without using my draw call in the update loop.
     
  6. NathBar

    NathBar

    Joined:
    Jan 18, 2022
    Posts:
    11
    I am also interested, I have the exact same issue/wierd behavior, Did you find any news about it ?