Search Unity

Question CommandBuffer.SetGlobal.... Performance Implications

Discussion in 'Shaders' started by magebuzzcutt, May 28, 2023.

  1. magebuzzcutt

    magebuzzcutt

    Joined:
    Jun 20, 2021
    Posts:
    17
    Hi,

    How much does using CommandBuffer.SetGlobal... commands impact performance? I've read that its generally best to avoid sending data from the CPU to the GPU and vice versa for performance reasons. However, I've got about 40-50 of these to send post-fx parameters to my shaders.

    So I was wondering if the performance impact of this command is significant enough that I should cut down on the number of times I call it. Also, is batching multiple SetGlobalFloats/Ints into a SetGlobalVector better for performance?

    TIA
     
  2. Invertex

    Invertex

    Joined:
    Nov 7, 2013
    Posts:
    1,550
    Pulling data *from* the GPU tends to be the much more impactful. SetGlobal shouldn't have much issue since it's applying values to existing memory space. But, if the values aren't changing each frame, you could also create a GraphicsBuffer and just update values in that when you need to and it will persist between frames.