Search Unity

Question RenderMeshIndirect : startInstance doesn't appear to work?

Discussion in 'General Graphics' started by Trindenberg, Sep 18, 2022.

  1. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    396
    Hi,

    Trying to use this for high performance instancing. Was hoping to offset from the buffer to draw on a proportion of instances. Say I have 10000 instances, I want to draw just 1000-1500, so startInstance = 1000, instanceCount = 500.

    But startInstance seems to be 0 regardless, or am I reading wrong what it does?

    Code (CSharp):
    1.         // Indexes per mesh
    2.         GB_commandData[0].indexCountPerInstance = mesh.GetIndexCount(0);
    3.         // Initial vertex index in mesh
    4.         GB_commandData[0].baseVertexIndex = 0;
    5.         // Instances to draw
    6.         GB_commandData[0].instanceCount = (uint)drawInstances;
    7.         // Initial instance/offset to draw?
    8.         GB_commandData[0].startInstance = (uint)startInstance;
    9.  
    10.         GB_commandBuffer.SetData(GB_commandData);
    11.  
    12.         Graphics.RenderMeshIndirect(in renderParams, mesh, GB_commandBuffer);
     
  2. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    396
    Thought maybe it's due to using ShaderGraph, but on using a basic instancing shader still doesn't appear to start at startInstance.
     
  3. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    396
    Ok figured it out only for non-ShaderGraph, on Vulkan it's GetIndirectInstanceID, but DX is GetIndirectInstanceID_Base (in shader code if using "UnityIndirect.cginc"). So how to access in ShaderGraph without a custom property?