Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Draw procedural API produce un-expected result on mobile

Discussion in 'General Graphics' started by cyberjoys, Nov 15, 2022.

  1. cyberjoys

    cyberjoys

    Joined:
    Dec 1, 2020
    Posts:
    64
    hi guys,
    recently i was trying out DrawProceduralIndirect API, the produced result is as expected when in window editor, but result is messed up while running on android device.

    Window Editor:
    Editor.png


    Android Device
    Device.png


    i have attatched the .cs and .shader files, is there something extra i need to do for mobile platform to work right?
    the device i tested this on seems to meet the minimum graphic requirement for this API (Shader Lv 45)

    another question here is that, i assume those Max Buffer inputs is like i can have lets say buff#0 all the way to buff#15 all used in lets say vertex shader, right ?



    updated :: also tried with vulkan build, still seeing messed up result
     

    Attached Files:

    Last edited: Nov 15, 2022
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    2,844
    Hi!
    Please report a bug.
    Thanks!
     
  3. cyberjoys

    cyberjoys

    Joined:
    Dec 1, 2020
    Posts:
    64
    CASE IN-23168
    filed
     
    aleksandrk likes this.
  4. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    692
    Make sure you are getting a valid instance index on mobile. Try displaying the instance index as a color. We use DrawProceduralIndirect extensively on mobile and it works fine, although there are a few gotchas. You can also compile your shader for GLES in the inspector window for your shader and take a look, see if anything seems odd.
     
  5. cyberjoys

    cyberjoys

    Joined:
    Dec 1, 2020
    Posts:
    64
    thx for the reply mate, although i have another test generating multiple instances of the animtor mesh, but this particular case(the attatched codes), only 1 instance of the copy was drawn, and instance id was not utilized.
    i actually suspect there might be something not right with the somewhat new unity graphic buffer wrapper. speaking of which, i should defintely try using compute buffer later and see
     
  6. cyberjoys

    cyberjoys

    Joined:
    Dec 1, 2020
    Posts:
    64
    with multi-instances draw would look something like this, instance id does not seems to be of problem

    editor:
    Editor_MultiInstances.png

    device:
    Device_MultiInstances_2.png
     
  7. joshuacwilde

    joshuacwilde

    Joined:
    Feb 4, 2018
    Posts:
    692
    oh ok I just took a look at your code. I noticed you are hard coding the byte offsets for the vertex streams in your shader. But those are platform dependent. So you can't use the same values you use in the editor. That's why your meshes are in the right place, but look all messed up. The correct way to do this is to query the byte offsets at runtime using https://docs.unity3d.com/ScriptReference/Mesh.GetVertexAttributes.html and its related methods.
     
  8. cyberjoys

    cyberjoys

    Joined:
    Dec 1, 2020
    Posts:
    64
    ha, thx for the enlightment, i had read about byte offset platform dependant stuff while i was preparing this trial, its a shame that this never came to my mind until now, this could be the problem, i will give it shot later to confirm.
    thx mate
     
    joshuacwilde likes this.
  9. kyriew

    kyriew

    Joined:
    Sep 10, 2019
    Posts:
    7
    Maybe you can close this optional "Project Settings-> Player-> Other Settings->Optimize Mesh Data"
     
  10. cyberjoys

    cyberjoys

    Joined:
    Dec 1, 2020
    Posts:
    64
    man, you nailed it.:)
    when "Optimize Mesh Data" is enabled, the tangent got removed upon player build, stream0 stride is 24 in this case (without optimize mesh data, stream0 stride is 40).


    so, like joshuacwilde suggested, it should really be done with those VertexAttribute API. its all working right now la
    Device_0004_OK.png


    thx guys, cheers
     
    joshuacwilde and aleksandrk like this.