Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  3. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question Help with Compute Shader new Mesh API 2021.2

Discussion in '2021.2 Beta' started by murphymen, Aug 6, 2021.

  1. murphymen

    murphymen

    Joined:
    Mar 18, 2020
    Posts:
    3
    Hi to all.

    I desperately need help with this piece of (s***) code. I am struggling with the transfer of the blocky voxel engine completely to the GPU, more closely to the Compute Shader.

    To accomplish this, I used a great series of tutorials from b3agz : Code a game like Minecraft in Unity and examples of using the new mesh API from Keijiro: https://github.com/keijiro/ComputeMarchingCubes.

    To the point. Compute Shader composes the mesh for entire 8x8x8 chunk of voxels using predefined arrays. After many adventures with appropriate adressing of RWByteAddressBuffers, I got stuck witch such results:




    For some reason the chunk is not displayed completely which is strange because each thread reports activity by storing its own id into the buffer. Similar buffers are for vertices and indices.

    I'm begging for help. Every day I work for a long time and I don't have little time for this passion of programming and now it has stopped me. Here is the source code in three files:
    Sorry. I don't know how to post code. Best regards to the Unity team. I am your fan
     
    Last edited: Aug 11, 2021
    Ruchir likes this.
  2. npatch

    npatch

    Joined:
    Jun 26, 2015
    Posts:
    248
    I didn't look that much into your code. Just an observation, but most of DrawMesh is redundant per-frame. If things don't change somehow, running them once in Start/AllocateXXXX is enough. Keijiro's code has a change condition in Update and only does the stuff below if sth has actually changed, other than that, shader.Sets being run per frame etc.

    As for debugging your issue, RenderDoc is your friend! Use it to debug the CS calculations and memory. No need for debug buffers if you can see their values on the fly. You can choose a specific workload and run through the CS kernels line by line looking at registers and stuff. Also Mesh Viewer can give you a visual for your generated mesh resource.

    One tip. Since debugging CS usually involves an iterative process where you capture new frames every time you change sth in the code, the Search Event by String will help a lot with locating your dispatches. You can search for "Dispatch" or even better something else that's unique to your dispatch events (e.g. a parent name) so you don't waste time every capture, navigating towards the dispatch you want to debug.
     
  3. murphymen

    murphymen

    Joined:
    Mar 18, 2020
    Posts:
    3
    Thank you sir for response. I finally found bug in "mesh.SetSubMesh()". Must learn how to use RenderDoc.

    Live long and prosper.
     
    npatch likes this.