Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

DrawMeshInstancedIndirect Error

Discussion in '2019.3 Beta' started by GilCat, Aug 8, 2019.

  1. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    After moving to Unity 2019.3.0a11 my console started spamming this DrawMeshInstancedIndirect error:
    DrawMeshInstancedIndirect should not be called with a shader does not use procedural instancing. Either add procedural instancing to your shader by using "#pragma instancing_options procedural", or use a different rendering function such as DrawMeshInstanced.
    UnityEngine.Graphics:DrawMeshInstancedIndirect(Mesh, Int32, Material, Bounds, ComputeBuffer)

    I've added #pragma instancing_options procedural:setup and a dummy setup method but nothing changed.
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,281
    GilCat likes this.
  3. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,683
    @richardkettlewell Same here, after upgrading to 2019.3.0b2. My shader already have #pragma multi_compile_instancing. Any suggestions?
    Cause errors spamming make performance bad.
    DrawMeshInstancedIndirect should not be called with a shader does not use procedural instancing. Either add procedural instancing to your shader by using "#pragma instancing_options procedural", or use a different rendering function such as DrawMeshInstanced.
    0x00007FF68BD2E85C (Unity) StackWalker::GetCurrentCallstack
    0x00007FF68BD31CC1 (Unity) StackWalker::ShowCallstack
    0x00007FF68A4BE935 (Unity) GetStacktrace
    0x00007FF68C9B7AD0 (Unity) DebugStringToFile
    0x00007FF68A3A8D4C (Unity) ValidateProceduralInstancingShader
    0x00007FF68A39D955 (Unity) CreateIndirectMeshIntermediateRenderer
    0x00007FF68B3C6A6F (Unity) GraphicsScripting::DrawMeshInstancedIndirect
    0x00007FF68BDC2B3E (Unity) Graphics_CUSTOM_Internal_DrawMeshInstancedIndirect_Injected
    0x00000172CD6A9DB8 (Mono JIT Code) (wrapper managed-to-native) UnityEngine.Graphics:Internal_DrawMeshInstancedIndirect_Injected (UnityEngine.Mesh,int,UnityEngine.Material,UnityEngine.Bounds&,UnityEngine.ComputeBuffer,int,UnityEngine.MaterialPropertyBlock,UnityEngine.Rendering.ShadowCastingMode,bool,int,UnityEngine.Camera,UnityEngine.Rendering.LightProbeUsage,UnityEngine.LightProbeProxyVolume)
    0x00000172CD6A9BAB (Mono JIT Code) UnityEngine.Graphics:Internal_DrawMeshInstancedIndirect (UnityEngine.Mesh,int,UnityEngine.Material,UnityEngine.Bounds,UnityEngine.ComputeBuffer,int,UnityEngine.MaterialPropertyBlock,UnityEngine.Rendering.ShadowCastingMode,bool,int,UnityEngine.Camera,UnityEngine.Rendering.LightProbeUsage,UnityEngine.LightProbeProxyVolume)
    0x00000172CD6A947B (Mono JIT Code) UnityEngine.Graphics:DrawMeshInstancedIndirect (UnityEngine.Mesh,int,UnityEngine.Material,UnityEngine.Bounds,UnityEngine.ComputeBuffer,int,UnityEngine.MaterialPropertyBlock,UnityEngine.Rendering.ShadowCastingMode,bool,int,UnityEngine.Camera,UnityEngine.Rendering.LightProbeUsage,UnityEngine.LightProbeProxyVolume)
    0x00000172CD6A8B83 (Mono JIT Code) UnityEngine.Graphics:DrawMeshInstancedIndirect (UnityEngine.Mesh,int,UnityEngine.Material,UnityEngine.Bounds,UnityEngine.ComputeBuffer,int,UnityEngine.MaterialPropertyBlock,UnityEngine.Rendering.ShadowCastingMode,bool)
    0x00000172CD69E8D3 (Mono JIT Code) [AnimationDrawSystem.cs:114] AnimationDrawSystem:OnUpdate (Unity.Jobs.JobHandle)
    0x00000172C44E868B (Mono JIT Code) [ComponentSystem.cs:924] Unity.Entities.JobComponentSystem:InternalUpdate ()
    0x00000172C44C8FE5 (Mono JIT Code) [ComponentSystem.cs:284] Unity.Entities.ComponentSystemBase:Update ()
    0x00000172C44CB1F3 (Mono JIT Code) [ComponentSystemGroup.cs:602] Unity.Entities.ComponentSystemGroup:OnUpdate ()
    0x00000172C44C937B (Mono JIT Code) [ComponentSystem.cs:800] Unity.Entities.ComponentSystem:InternalUpdate ()
    0x00000172C44C8FE5 (Mono JIT Code) [ComponentSystem.cs:284] Unity.Entities.ComponentSystemBase:Update ()
    0x00000172C44C8E9B (Mono JIT Code) [ScriptBehaviourUpdateOrder.cs:144] Unity.Entities.ScriptBehaviourUpdateOrder/DummyDelegateWrapper:TriggerUpdate ()
    0x00000172C339E738 (Mono JIT Code) (wrapper runtime-invoke) object:runtime_invoke_void__this__ (object,intptr,intptr,intptr)
    0x00007FF8A948C8B0 ((<unknown>))
    0x00007FF8A9411DA2 ((<unknown>))
    0x00007FF8A941AD9F ((<unknown>))
    0x00007FF68BCB4EBE (Unity) scripting_method_invoke
    0x00007FF68BCAECBD (Unity) ScriptingInvocation::Invoke
    0x00007FF68B75025F (Unity) ExecutePlayerLoop
    0x00007FF68B75027D (Unity) ExecutePlayerLoop
    0x00007FF68B755463 (Unity) PlayerLoop
    0x00007FF689BBD82B (Unity) PlayerLoopController::UpdateScene
    0x00007FF689BBB528 (Unity) Application::TickTimer
    0x00007FF68A4E50F0 (Unity) MainMessageLoop
    0x00007FF68A4EEDFA (Unity) WinMain
    0x00007FF68D4580C2 (Unity) __scrt_common_main_seh
    0x00007FF94AA44034 (KERNEL32) BaseThreadInitThunk
    0x00007FF94BCF3691 (ntdll) RtlUserThreadStart

    EDIT: Forgot about #pragma instancing_options procedural:setup which solves error spamming, but stops rendering at all.
    It's for our animation system, and we using this code for setup matrices, which worked fine before:
    Code (CSharp):
    1. v2f vert (appdata v, uint vid : SV_VertexID, uint inst : SV_InstanceID)
    2.             {
    3.                 float4x4 data = float4x4(1, 0, 0, 0,
    4.                     0, 1, 0, 0,
    5.                     0, 0, 1, 0,
    6.                     0, 0, 0, 1);
    7.                 if(ObjectToWorldBuffer[inst].Value[0][0] != 0)
    8.                     data = ObjectToWorldBuffer[inst].Value;
    9.  
    10.                 unity_ObjectToWorld = data;
    11.                 unity_WorldToObject = unity_ObjectToWorld;
    12. ...
    And side note, my custom shadowcaster pass seems works without problem, and problem happens only in forwardbase pass, cause shadows rendered fine even without procedural instanced options.
    upload_2019-9-9_18-27-40.png
     
    Last edited: Sep 9, 2019
  4. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    Did you add the dummy setup method?
     
  5. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,683
    Yep it stops rendering main passes, only shadowcaster pass works, cause I guess it breaks unity matrices
     
    Last edited: Sep 9, 2019
  6. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    I'm not yet on 2019.3.0b2 but once I'm back home I'll test if I have that problem
     
  7. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,281
    If the workaround isn’t working then you may have to wait for the bugfix. It’s landed internally so should be out soon. Keep an eye on the issuetracker link I shared above.

    I’m on vacation so can’t find out a version number.
     
    GilCat and eizenhorn like this.
  8. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,683
    Yep, thanks, untill that we'll switch back to latest 2019.2... eh, our artist was so happy by new UX...:rolleyes:
    Wish you good vacation ending! And if you not mind, after vacation, can you tell version number with fix :)
     
    Last edited: Sep 9, 2019
    GilCat and richardkettlewell like this.
  9. GilCat

    GilCat

    Joined:
    Sep 21, 2013
    Posts:
    676
    I just tested my project with 2019.3.0b2 without any spamming and with everything rendering just fine.
    Here is my shader code:
    Code (CSharp):
    1. Shader "Sprites/Instanced"
    2. {
    3.     Properties
    4.     {
    5.         _BaseColor("Main Color", Color) = (1,1,1,1)
    6.         _MainTex("Texture", 2D) = "white" {}
    7.         _TransitionTex("Transition Texture", 2D) = "transparent" {}
    8.         _Cutoff("Cutoff", Range(0, 1)) = 1
    9.         _TileOffset("Tile Offset", Vector) = (1,1,0,0)
    10.         _Scale("Mesh Scale", Vector) = (1,1,1)
    11.         _Pivot("Pivot", Vector) = (0,0,0)
    12.     }
    13.         SubShader
    14.         {
    15.             Tags { "Queue" = "Transparent" "IgnoreProjector" = "True" "RenderType" = "Transparent" }
    16.             LOD 100
    17.             Blend SrcAlpha OneMinusSrcAlpha
    18.             ZWrite Off
    19.             Pass
    20.             {            
    21.                 CGPROGRAM
    22.                 #pragma vertex vert
    23.                 #pragma fragment frag
    24.                 #pragma multi_compile_local __ USE_COMPUTE
    25.                 #pragma multi_compile_instancing
    26.                 #pragma instancing_options procedural:setup
    27.                 #include "UnityCG.cginc"
    28.  
    29.                 void setup() {}
    30.  
    31.                 struct appdata
    32.                 {
    33.                     float4 vertex : POSITION;
    34.                     float2 uv : TEXCOORD0;
    35.                 };
    36.  
    37.                 struct v2f
    38.                 {
    39.                     float2 uv1 : TEXCOORD0;
    40.                     fixed2 uv2 : TEXCOORD1;
    41.                     float4 vertex : SV_POSITION;
    42.                     fixed4 color : COLOR0;
    43.                     float cutoff : CUTOFF;
    44.                 };
    45.  
    46.                 float f16tof32(uint x)
    47.                 {
    48.                     const uint shifted_exp = (0x7c00 << 13);
    49.                     uint uf = (x & 0x7fff) << 13;
    50.                     uint e = uf & shifted_exp;
    51.                     uf += (127 - 15) << 23;
    52.                     uf += lerp(0, (128u - 16u) << 23, e == shifted_exp);
    53.                     uf = lerp(uf, asuint(asfloat(uf + (1 << 23)) - 6.10351563e-05f), e == 0);
    54.                     uf |= (x & 0x8000) << 16;
    55.                     return asfloat(uf);
    56.                 }
    57.  
    58.                 float2 uintToFloat2(uint input) {
    59.                     return float2(f16tof32(input & 0x0000FFFF), f16tof32((input & 0xFFFF0000) >> 16));
    60.                 }
    61.  
    62.                 float4 uint2ToFloat4(uint2 input) {
    63.                     float2 xy = uintToFloat2(input.x);
    64.                     float2 zw = uintToFloat2(input.y);
    65.                     return float4(xy.x, xy.y, zw.x, zw.y);
    66.                 }
    67.  
    68.                 float4x4 uint4x2ToFloat4x4(uint4x2 input) {
    69.                     float4 c0 = uint2ToFloat4(float2(input[0].x, input[1].x));
    70.                     float4 c2 = uint2ToFloat4(float2(input[0].y, input[1].y));
    71.                     float4 c1 = uint2ToFloat4(float2(input[2].x, input[3].x));
    72.                     float4 c3 = uint2ToFloat4(float2(input[2].y, input[3].y));
    73.                     return float4x4(
    74.                         c0.x, c1.x, c2.x, c3.x,
    75.                         c0.y, c1.y, c2.y, c3.y,
    76.                         c0.z, c1.z, c2.z, c3.z,
    77.                         c0.w, c1.w, c2.w, c3.w);
    78.                 }
    79.  
    80.                 sampler2D _MainTex;
    81.                 float4 _MainTex_ST;
    82.                 float4 _TransitionTex_ST;
    83.                 sampler2D _TransitionTex;
    84.  
    85.                 float4 _TileOffset;
    86.                 float3 _Scale;
    87.                 float2 _Pivot;
    88.                 fixed4 _BaseColor;
    89.                 float _Cutoff;
    90.  
    91.                 // uint is 32 bit and is filled with half2 (2 * 16 bit)
    92.                 StructuredBuffer<uint4x2> localToWorldBuffer; // half4x4
    93.                 StructuredBuffer<uint2> tileOffsetBuffer; // half4
    94.                 StructuredBuffer<uint2> scaleBuffer; // half4
    95.                 StructuredBuffer<uint> pivotBuffer; // half2
    96.                 StructuredBuffer<uint2> colorBuffer; // half4
    97.                 StructuredBuffer<uint> cutoffBuffer; // half
    98.  
    99.                 v2f vert(appdata v, uint instanceID : SV_InstanceID)
    100.                 {
    101.                     v2f o;
    102. #ifdef USE_COMPUTE
    103.                     float3 scale = uint2ToFloat4(scaleBuffer[instanceID]);
    104.                     float2 pivot = uintToFloat2(pivotBuffer[instanceID]);
    105.                     float4 tileOffset = uint2ToFloat4(tileOffsetBuffer[instanceID]);
    106.                     float4x4 localToWorld = uint4x2ToFloat4x4(localToWorldBuffer[instanceID]);
    107.                     float4 color = uint2ToFloat4(colorBuffer[instanceID]);
    108.                     float cutoff = cutoffBuffer[instanceID];
    109. #else
    110.                     float3 scale = _Scale;
    111.                     float2 pivot = _Pivot;
    112.                     float4 tileOffset = _TileOffset;
    113.                     float4x4 localToWorld = float4x4(
    114.                         1, 0, 0, 0,
    115.                         0, 1, 0, 0,
    116.                         0, 0, 1, 0,
    117.                         0, 0, 0, 1);
    118.                     float4 color = _BaseColor;
    119.                     float cutoff = _Cutoff;
    120. #endif
    121.                     float4x4 scaleMatrix = float4x4(
    122.                         scale.x, 0, 0, 0,
    123.                         0, scale.y, 0, 0,
    124.                         0, 0, scale.z, 0,
    125.                         0, 0, 0, 1);
    126.                     float4 localVertexPos = mul(scaleMatrix, v.vertex) + mul(scaleMatrix, float4(pivot.x, pivot.y, 0, 0));
    127.                     float4 localTranslated = mul(localToWorld, localVertexPos);
    128.                     o.vertex = UnityObjectToClipPos(localTranslated);
    129.                     o.uv1 = TRANSFORM_TEX(v.uv * tileOffset.xy + tileOffset.zw, _MainTex);
    130.                     o.uv2 = TRANSFORM_TEX(v.uv, _TransitionTex);
    131.                     o.color = color;
    132.                     o.cutoff = cutoff;
    133.                     return o;
    134.                 }
    135.  
    136.                 fixed4 frag(v2f i) : SV_Target
    137.                 {
    138.                     float4 transit = tex2D(_TransitionTex, i.uv2);
    139.                     fixed4 col = tex2D(_MainTex, i.uv1) * i.color;
    140.                     fixed alpha = max(transit.a < 1, i.cutoff);            
    141.                     col.a = step(transit.b, alpha) * col.a;
    142.                     return col;                  
    143.                 }
    144.                 ENDCG
    145.             }
    146.         }
    147. }
     
  10. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,683
    Thanks, but I already rewrited my shader a bit to get it work :) Problem was in my
    unity_ObjectToWorld override.
    upload_2019-9-10_9-46-47.png
     
    GilCat likes this.
  11. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,281
    Thanks :)

    Vacation over! Fix is heading to 2019.3.0b4
     
    GilCat and eizenhorn like this.
  12. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,683
    Thanks, anyway I solved my probem :D
     
    richardkettlewell likes this.