Search Unity

Canonical Compute Dispatch Setup for OGL ES 3.x ?

Discussion in 'General Graphics' started by DaveCowling, Mar 6, 2019.

  1. DaveCowling

    DaveCowling

    Joined:
    Oct 10, 2017
    Posts:
    7
    This is something I haven't found documented anywhere, feedback would be really useful!

    I'm seeking to do a fair amount of compute-driven effects work on OpenGL ES using the standard render pipeline. One example use case is some effects I'm running based on locations of game objects, where the effect is composed of a vertex stream generated each frame in a compute shader and then subsequently rendered via a DrawProcedural() call.

    My current setup is as follows, driven from a control script MonoBehavior:

    - At controlscript::Start(), generate a CommandBuffer which handles the DrawProcedural command to consume my compute-generated verts, add this CommandBuffer to the Camera at the appropriate rendering spot (in this case, post alpha)
    - At controlscript::Update(), query latest game object locations, set these to the uniform input values on my compute shader, and Dispatch() the compute shader that generates the verts for consumption

    This works. But it *feels* wrong - it feels like the Dispatch should be similarly driven from a command buffer attached to a specific point in the render pipeline (early as possible), rather than being driven from a "game side" Update() call. More importantly, empirically I am seeing large frame time variances with this approach, even with a scene empty of everything other than this effect, which makes me wonder if there is a pipeline stall happening over contention on the shared vertex buffer... (I haven't proven this yet, could be entirely unrelated).

    But if I drive the Dispatch() from a Command Buffer, how do I efficiently set the input values to the compute shader that are derived from game object location, etc?

    Any advice from a Unity rendering expert here - especially specific to the OGLES pipeline - would be super valuable, thanks!