Search Unity

Question Trying to render a BatchRendererGroup (or Entities Graphics) batch with wrong cbuffer setup. Missing

Discussion in 'Graphics for ECS' started by Knedlo, Apr 16, 2023.

  1. Knedlo

    Knedlo

    Joined:
    Oct 15, 2012
    Posts:
    54
    Hello,

    we are trying to render using a custom shader. The mesh changes every frame. We are passing the data to shader using components marked with MaterialProperty attribute. Unity is complaining about the cbuffer setup with this error message: "Trying to render a BatchRendererGroup (or Entities Graphics) batch with wrong cbuffer setup. Missing DOTS_INSTANCING_ON variant?". Our shader is set up similarly to another working shader that handles property transfer and instancing but has a static mesh on input, so i suspect the dynamic mesh changes to be the problem.

    I am attaching a system that handles the mesh updates as well as the shader.

    Any help would be appreciated!
    Cheers!
     

    Attached Files:

    redcoff likes this.
  2. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
    It looks like the shader might be missing
    #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl"
    .

    Also, as a general GPU performance tip, I would recommend avoiding geometry shaders, and using a regular vertex + fragment shader configuration instead. That is likely to have better performance on pretty much every GPU.
     
  3. nishikinohojo

    nishikinohojo

    Joined:
    Aug 31, 2014
    Posts:
    46
    What is causing this error exactly? When does this error log appear?

    I'm trying to use custom BRG with custom SRP and now this error happens.
    I think I've prepared cbuffer correctly, which apparently not though. If I could know what this is more precisely than what log says vaguely, problem would be much easier to solve:)

    BTW, can I bind other cbuffers alongside BuiltinPropertyMetadata? This is the only related thing I can think of, as it mentions "cbuffer setup". It does not exceed 14 or 15 in total, of course though.
     
    Last edited: May 31, 2023
  4. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
    The error occurs when Unity can't find the "UnityInstancingDOTS_InstanceVisibility" cbuffer, which it uses to tell the shader which instance IDs to actually render (the cbuffer contains the IDs from "visibleOffset", plus some internal data), and which is in turn used by all DOTS instanced property loading in the shader. If that cbuffer can't be found, then the shader will not render correctly, and the draw is skipped.

    The typical reasons for getting this error are:
    • Not declaring any DOTS instanced properties at all in a custom shader (i.e. not even the matrix), in which case the cbuffer is not used, and the compiler removes it. Regular Unity shaders and Shader Graphs always use at least the matrix, but custom shaders could contain anything.
    • Not initializing instance ID correctly in the shader, in which case the cbuffer might end up unused and the compiler might again remove it.
     
    andrew-lukasik and nishikinohojo like this.
  5. JussiKnuuttila

    JussiKnuuttila

    Unity Technologies

    Joined:
    Jun 7, 2019
    Posts:
    351
    You can have up to three metadata cbuffers: BuiltinPropertyMetadata, MaterialPropertyMetadata, and UserPropertyMetadata. You don't bind them manually, they are automatically filled and bound by Unity based on the MetadataValues that you pass to AddBatch.
     
    andrew-lukasik and nishikinohojo like this.
  6. nishikinohojo

    nishikinohojo

    Joined:
    Aug 31, 2014
    Posts:
    46
    Oh dear sorry, my shadow shader apparently did forget receiving value from unity_DOTSVisibleInstances thanks.
    You saved my life and really sorry I annoyed you with this easy thing.
     
  7. NathanPhil

    NathanPhil

    Joined:
    Oct 2, 2023
    Posts:
    1
    I have the same error message on iOS and nothing was rendered. However:
    - it works on the Editor
    - it works on Android
    - I tried Keep All on BatchRendererGroup Variants and Instancing Variants
    - I used only Shader Graphs, no custom shaders. The Shader Graphs do have property with Shader Declaration set to Hybrid Per Instance
    - I tried pre-warm Shader Variant Collection (I saw all of the shaders I used have DOTS_INSTANCING_ON in the collection)

    none of the above work. What else can I try?