Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question DrawMeshInstancedIndirect - is it better to calculate TRS matrices on the GPU or CPU?

Discussion in 'Shaders' started by JSmithIR, Aug 13, 2023.

  1. JSmithIR

    JSmithIR

    Joined:
    Apr 13, 2023
    Posts:
    111
    I am using Graphics.DrawMeshInstancedIndirect to make tens of thousands of mesh instances. Each one needs to have use a unique TRS matrix in its material. the TRS matrix is highly customized because I am working in non-euclidean space. The details of that arent important.

    The point here is that typically Matrix4x4.TRS is used on the CPU to construct the matrix that I pass into the shader. But if I need tens of thousands of unique matrices, is it faster to implement the TRS calculations in a compute shader rather than on the CPU?

    I know the answer is ordinarily a resounding NO - but does this change when the number of matrices is in the ten thousands. Seems to me like mass parallelization.
     
  2. Rukhanka

    Rukhanka

    Joined:
    Dec 14, 2022
    Posts:
    193
    Final performance will depend on the speed of slowest part of all processing pipeline. If CPU TRS calculation is slowing down entire rendering so it is benefical to speed it up by moving to GPU.