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

Draw Procedural Indexed?

Discussion in '5.4 Beta' started by Arycama, Apr 11, 2016.

  1. Arycama

    Arycama

    Joined:
    May 25, 2014
    Posts:
    185
    I've been using the new Compute Shader features from the beta, such as ComputeBuffer.SetCounterValue and ComputeShader.DispatchIndirect with great results! Currently I'm generating a terrain with Marching Cubes and rendering it using Graphics.DrawProceduralIndirect, all done on the GPU.

    I noticed in the docs, that DrawProceduralIndirect "very much maps to Direct3D11 DrawInstancedIndirect", and I noticed in Microsoft's documentation there in addition to this method, there is a DrawIndexedInstanced function. Would this allow Draw Procedural to work with an index list, instead of resubmitting vertices multiple times when they are shared by faces? If so, it would be a great addition to compute shaders, and would tie in nicely with the other new features.
     
    Last edited: Apr 11, 2016
    pragmascript and Noisecrime like this.
  2. Noisecrime

    Noisecrime

    Joined:
    Apr 7, 2010
    Posts:
    2,054
    I recently asked about this myself having been working on a skinned compute shader it would be really useful.

    This is my original post about it.


    Is it possible to have some form of DX11 DrawIndexedInstance ( cross -api support) to match the existing DrawProcedural method? Whilst we have DrawMesh it obviously requires a Unity mesh to work and i'm trying to avoid that overhead especially as my vertex data is already constructed in a compute buffer.

    A good use case for this is my current work on a Skinning compute Shader, that puts the skinned vertex data into a compute buffer that a VS/PS then uses to render the mesh. However as I wanted to easily integrate this with the Unity pipeline ( i.e. MeshRenderer) i'm already using a workaround, where by the MeshRenderer has a dummy mesh to fullfill its Draw() requirements and then I replace all the native vertex stream data in the vertex shader with the values from the computeBuffer. This works great for cases where I need to replace/supplement Unity's SkinnedMeshRenderer and I can easily render hundreds of copies of the same pose of the animated mesh, but that results in a large drawcall overhead.

    So the next step would be to make it work with instances. I was going to try with the 5.4 Instance feature, but sadly there are bugs in the current beta that means my ComputeShader method fails and frankly for a specific use case like this I probably would want to use my own custom version for greater control anyway.

    My plan then was to use a combination of DrawProcedural with CommandBuffers supplemented with a computeBuffer for instance data. Sadly there is an obvious problem here, my mesh data is indexed and until I remembered that I just got garbled triangles rendered on screen, hence the request for DrawIndexedInstance.

    I guess as another workaround I could create a new ComputeShader that outputs the vertex data into a non-indexed version and that would then let me use DrawProcedural, but its a bit wasteful, requiring more effort by the computeShader and generating more data (memory usage).
     
  3. Arycama

    Arycama

    Joined:
    May 25, 2014
    Posts:
    185
    They've added MaterialPropertyBlock.SetBuffer and ComputeShader.GetKernelThreadGroupSizes in the last two betas, so maybe DrawProceduralIndexed (And DrawProceduralIndexedIndirect) are close behind?
     
  4. JulienF_Unity

    JulienF_Unity

    Unity Technologies

    Joined:
    Dec 17, 2015
    Posts:
    326
    Hi,

    Sorry for the late reply.

    Being able to pass an index buffer to DrawProcedural and DrawProceduralIndirect is something we clearly want to support in the near future.

    However we first need to have a nive way to handle index buffers on the c# side as at the moment index buffers are encapsulated within meshes.
     
    Arycama likes this.