Search Unity

Question Graphics.Render* API in CommandBuffers

Discussion in 'General Graphics' started by Per-Morten, Oct 15, 2021.

  1. Per-Morten

    Per-Morten

    Joined:
    Aug 23, 2019
    Posts:
    119
    I just noticed that we've gotten new render functions in the Graphics class, such as Graphics.RenderMesh and Graphics.RenderPrimitives. Is support for these functions planned for CommandBuffers as well?

    (I already asked about this in the beta forum but didn't get any response, and this subforum seems more appropriate)
     
  2. JarkkoUnity

    JarkkoUnity

    Unity Technologies

    Joined:
    Feb 1, 2021
    Posts:
    17
    Hi Per-Morten,

    There is currently no plan to implement these functions in CommandBuffer. The new Render functions operate in higher level potentially issuing draws in multiple passes, while for CommandBuffer draw commands you explicitly specify the pass. There are some new functionality though (namely multi-command draws) that may in some form eventually find their way to CommandBuffer though.

    Cheers, Jarkko
     
  3. Per-Morten

    Per-Morten

    Joined:
    Aug 23, 2019
    Posts:
    119
    I see. That's a shame. When I saw the Graphics.RenderPrimitivesIndexed function I was hoping we could finally get a way to render using index buffers that didn't require indirect rendering.
     
  4. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    Hi, I wander to known the difference between 'DrawMesh' and 'RenderMesh'.
    It seems only to pack the parameters into a struct. Is there any functional difference? What is the purpose of the new 'RenderXXX' APIs?
     
  5. JarkkoUnity

    JarkkoUnity

    Unity Technologies

    Joined:
    Feb 1, 2021
    Posts:
    17
    @Per-Morten Does DrawProcedural work for you (takes index buffer as well)?

    @watsonsong Correct, many of the parameters are now passed in RenderParams struct for better maintenance to avoid duplicating the draw functions every time new functionality is added. From the top of my head there's at least control for renderingLayerMask and motion vector rendering added to the new functions. The Indirect functions also support multi-draw, which is currently implemented as issuing draw for each command, but for improved performance we hope to provide hardware MDI implementation in the future that's supported by many platforms. For RenderMeshInstanced you can also pass custom structs, which in addition to defining instance object->world transforms allows you to control for example per-instance renderingLayerMask
     
  6. Per-Morten

    Per-Morten

    Joined:
    Aug 23, 2019
    Posts:
    119
    Unfortunately no, I didn't formulate myself properly. We not only need the ability to draw via an index buffer but also to be able to specify index count, index start, instance count, etc. Essentially, the same stuff that we can get today via the indirect arguments in CommandBuffer.DrawProceduralIndirect. Ideally, we would also be able to not supply bounding boxes and skip Unity's frustum culling as we do that on our own. So, essentially, a CommandBuffer.DrawProceduralIndirect but the DrawArgs are supplied on the CPU, not on the GPU. :)
     
  7. watsonsong

    watsonsong

    Joined:
    May 13, 2015
    Posts:
    555
    I have a quest about the multi-draw support. The multi-draw method(RenderMeshIndirect), the parameters 'commandBuffer' maybe store on the GPU side. Is that means the cpu read parameter from a gpu buffer and issuing draw for each command?
     
  8. JarkkoUnity

    JarkkoUnity

    Unity Technologies

    Joined:
    Feb 1, 2021
    Posts:
    17
    No, we just issue several indirect draws with increasing offsets to the commandBuffer, so no CPU readback is needed.

    Cheers, Jarkko