Search Unity

Question Persist the rendered objects in the GPU

Discussion in 'General Graphics' started by Opeth001, Nov 26, 2020.

  1. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    Hello Everyone,

    I'm calculating the camera frustum on each frame to find out which objects need to be sent to the GPU for rendering using Graphics.DrawMeshInstancedIndirect, but most of the objects have already been sent to the GPU in the previous frames, which seems a waste of CPU time.

    so is there a way to persist the rendered objects in the GPU instead of resending them each frame?

    Thank you!
     
  2. weiping-toh

    weiping-toh

    Joined:
    Sep 8, 2015
    Posts:
    192
    There is no concept of "objects" in the GPU. When you render using DrawMesh(Instanced), what you are actually doing is sending a Draw command to the GPU for a set of vertices with the shader program and its respective set of shader properties (aka Material) to use for drawing.
    So in the GPU it only recognizes a set of vertices to render. The "mesh" reference is only held in the CPU.

    Now with modern improvements to GPUs and GLs, there is a concept of using constant buffers / compute buffers, which might be treated like an object. However, this solution, might be more complicated than what you might wish for.

    The only simple "persistence" for the GPU is the frame buffer, that you could choose to clear or not.
     
    Opeth001 likes this.
  3. weiping-toh

    weiping-toh

    Joined:
    Sep 8, 2015
    Posts:
    192
    Opeth001 likes this.
  4. Opeth001

    Opeth001

    Joined:
    Jan 28, 2017
    Posts:
    1,117
    That’s super clear, thank you!