Search Unity

using GraphicsBuffer in a compute shader

Discussion in 'General Graphics' started by l-a-w, Apr 2, 2020.

  1. l-a-w

    l-a-w

    Joined:
    Jan 6, 2015
    Posts:
    2
    i'm trying to use DrawProceduralIndirectNow with and index buffer calculated in a compute shader, but i can't find a way to convert from a ComputeBuffer to a GraphicsBuffer or the other way around, or use a ComputeBuffer as an index buffer directly, i tried to find and example of how to do this but there seems to be nothing. is there some tutorial or example on how to do this anywhere.

    the only way i been able to pass the index buffer is to set it directly in the Shader, but i'm not sure this is a good practice
    Code (CSharp):
    1. uniform StructuredBuffer<Vert> buffer;
    2. StructuredBuffer<int> _index;
    3.  
    4. v2f vert(uint id : SV_VertexID)
    5. {
    6.       int vertexId = _index[id];
    7.       Vert vert = buffer[vertexId];
    8.       v2f OUT;
    9.       OUT.pos = UnityObjectToClipPos(float4(vert.position, 1));
    10.       return OUT;
    11. }
     
  2. richardkettlewell

    richardkettlewell

    Unity Technologies

    Joined:
    Sep 9, 2015
    Posts:
    2,285
    Hey, we've added API to let you do what you want to do, in Unity 2020.1. (GraphicsBuffer can be used in any place where ComputeBuffer was previously the only option)

    But in older versions, it's not possible.
    If you have a workaround that works, it's probably fine :)
     
  3. l-a-w

    l-a-w

    Joined:
    Jan 6, 2015
    Posts:
    2
    thanks, i'll try 2020.1 ans see how it goes
     
    richardkettlewell likes this.
  4. tbella-leopoly

    tbella-leopoly

    Joined:
    Jul 4, 2017
    Posts:
    1
    Thank you for the response and the new API. We have tried it and found that it does not work on AMD GPU-s: we have tried to modify the content of the index buffer from compute shader and it works perfectly on nVidia and Intel GPU-s but has no effect on AMD GPU-s: the content of the index buffer is not modified. Affected version: 2020.2.4f1.