Search Unity

Issue registering UAV buffer to shader within HDRP

Discussion in 'High Definition Render Pipeline' started by TarAlacrin, Jun 19, 2020.

  1. TarAlacrin

    TarAlacrin

    Joined:
    Apr 15, 2014
    Posts:
    8
    I'm writing a program that uses compute shaders to perform some calculations on a mesh at runtime, then generate a new mesh from those computations. I'm looking to do this in a fast manner, so using GetData() every frame is out of the question.
    Previously (in the legacy program) the program worked fine end to end with this system setup:

    Code (CSharp):
    1.     Start()
    2.     {
    3.         triVertexPositionBuffer[WRITE] = new ComputeBuffer(vertCount/3, sizeof(float)*4*3, ComputeBufferType.Append, ComputeBufferMode.Immutable);
    4.     }
    5.  
    6.     Update()
    7.     {
    8.         Graphics.ClearRandomWriteTargets();
    9.         triVertexPositionBuffer[WRITE].SetCounterValue(0);
    10.         material.SetPass(0);
    11.         material.SetBuffer("WATriVertexPositionBuffer", triVertexPositionBuffer[WRITE]);
    12.         Graphics.SetRandomWriteTarget(1, triVertexPositionBuffer[WRITE], false);
    13.     }
    This function registered the append buffer triVertexPositionBuffer as a UAV buffer within the material, which allowed the geometry shader to append the vertex positions of the triangles.

    Code (CSharp):
    1.         struct tridata {
    2.             float4 p1;
    3.             float4 p2;
    4.             float4 p3;
    5.         };
    6.  
    7.         uniform AppendStructuredBuffer<tridata> WATriVertexPositionBuffer : register(u1);
    8.         [maxvertexcount(3)]
    9.  
    10.         void geom(triangle v2g input[3], inout TriangleStream<g2f> tristream) {
    11.             tridata t;
    12.             t.p1 = input[0].worldPos;
    13.             t.p2 = input[1].worldPos;
    14.             t.p3 = input[2].worldPos;
    15.             WATriVertexPositionBuffer.Append(t);              
    16.         }

    This worked perfectly in Unity 2018, in the legacy rendering pipeline. However, when I upgraded the project and began to work within HDRP it seems that this broke.

    The geometry shader is perfectly functional still (I edited the shader so that it just passes the vertex positions through and it renders fine in HDRP)

    And the rest of my compute shaders are working perfectly after some modification. The calculations run and update every frame and the final display properly with dummy data.

    In fact, when I pass intial data into buffer on creation. That data never gets overwritten by the geometry shader at all. Despite the geometry shader definitely running and completing properly. Its like within the HDRP my buffer is never actually being assigned as a UAV buffer within the shader, so its never allowed to actually modify the data.

    Does anyone know how to fix this issue? Or some other workaround to get vertex data into a computebuffer without transfering that data off the GPU and back every frame? Any help would be very much appreciated, I've been googling and pulling my hair out for days here.

    EDIT: to clarify, I've tested this out in 2019.2.16f1, 2019.1.14f1, and 2019.3.7f1 with the most up to date versions of HDRP for each version.
     
    Last edited: Jun 19, 2020
  2. TarAlacrin

    TarAlacrin

    Joined:
    Apr 15, 2014
    Posts:
    8
    Nvm, this was a bug that got fixed. I updated to 2019.3.13f1 and that seemed to fix it :)