This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Drawcall will fail on Mali gpu when there is large index value diff in index buffer

We are currently developing a new render technique for which we need to store non-trivial index value in index buffer and later use gl_VertexID to obtain vertex attributes manually(of course not directly using gl_VertexId but after some calculation) in the vertex shader.

I found that on the devices I have(kirin960/kirin970/kirin980 socs, featuring G71 G76 gpu), both vkDrawIndexedIndirect and vkDrawIndexed will fail if there's a large diff between some indices in the index buffer, for example, an index buffer with content of [0, 1, 2, 0x0xb8fffa, 0xb8fffb, 0xb8fffc] will fail. I also tested the same apk on several adreno devices and does't seen any bugs there.

More specifically on the condition to reproduce the problem, I found that

(1)about the "index diff value": smaller diff value is require to cause the bug to happen for vkDrawIndexed and a larger value is required for vkDrawIndexedIndirect, for vkDrawIndexedIndirect I found the value to be 0x0xb8fff8 for kirin980(G76).

(2)only diff matters: adding big value to all indices won't trigger the bug, so I suspect that the hardware may be doing some compression technique to index list while assuming the diff value won't be very large since the max size of vertex buffer is bounded but ignoring someone may be doing vertex fetch manually

 

 

About the demo:

It draws 2 triangles covering the same area, triangle position is completely derived from VertexID. On my huawei phone with mali G76, it's ok with index buffer [0,1,2, 0xb8fff9, 0xb8fffa, 0xb8fffb], but won't render triangles when index buffer is [0,1,2,0xb8fffa,0xb8fffb,0xb8fffc]

ok on g76 with index diff of 0xb8fff7

  

render bug on g76 with index diff of 0xb8fff8

adreno devices is ok with index diff of 0xb8fff8

So my questions are:

(1)Is this a hardware or software driver issue? More specifically, will a software driver patch be able to fix it?

(2)if this is a hardware issue, what is the first generation of GPU that is free from this bug?

(3)How can I circumvent this? For example, if big index diff value is the cause, is there a safe index value range so that if I can avoid the bug by keep all index value within the given range.

Parents
  • Hi lxdeng, 

    Older Mali GPUs assume the index is a simple index, so encoding property bits in high index values is liable to cause problems.

    Mali-G77 onwards should have better behavior here as long as you are not using geometry/tessellation shaders, but you may have a significant vertex overshading rate if the additional property bit values vary at high frequency. This is because Mali shades vertices in groups of 4 contiguous indices, so if a group of 4 verts have different properties the vertex data will get shaded 4 times. 

    The best workaround on old GPUs is to keep the index buffer simple, converting any high-bit properties into a normal vertex attribute, e.g. packed into a GL_UNSIGNED_BYTE.

    Kind regards,
    Pete

Reply
  • Hi lxdeng, 

    Older Mali GPUs assume the index is a simple index, so encoding property bits in high index values is liable to cause problems.

    Mali-G77 onwards should have better behavior here as long as you are not using geometry/tessellation shaders, but you may have a significant vertex overshading rate if the additional property bit values vary at high frequency. This is because Mali shades vertices in groups of 4 contiguous indices, so if a group of 4 verts have different properties the vertex data will get shaded 4 times. 

    The best workaround on old GPUs is to keep the index buffer simple, converting any high-bit properties into a normal vertex attribute, e.g. packed into a GL_UNSIGNED_BYTE.

    Kind regards,
    Pete

Children