Search Unity

[Solved] Trouble with ComputeBuffer in OpenGL

Discussion in 'Shaders' started by NeonTanto, Aug 8, 2016.

  1. NeonTanto

    NeonTanto

    Joined:
    Jun 19, 2013
    Posts:
    156
    Hi all! I'll try implement Order Independent Transparency with SM5.0 (using UAV and linked lists).
    In first step, I create UAV buffers:

    Code (CSharp):
    1. private ComputeBuffer transparancyBuffer;
    2. private RenderTexture renderTexture;
    3. //....
    4. renderTexture = new RenderTexture(targetCamera.pixelWidth,targetCamera.pixelHeight,0,RenderTextureFormat.RInt,RenderTextureReadWrite.Linear);
    5. renderTexture.enableRandomWrite = true;
    6. transparancyBuffer = new ComputeBuffer(12 * targetCamera.pixelWidth * targetCamera.pixelHeight, sizeof(uint) * 3, ComputeBufferType.Counter);
    7.  
    After it my shaders will fill it. In texture I save current head of linked list, in buffer I save elements of list. After all I compose this data in post process effect:
    1) Per pixel sort of current list
    2) Compose with opaque render.
    In shaders I declare my buffers like this:

    Code (CSharp):
    1. struct NodeData {
    2.     uint nextNode;
    3.     uint packedColor;
    4.     uint depth;
    5. };
    6.  
    7. globallycoherent uniform RWTexture2D<uint> _NodeHeads : register(u1);
    8. globallycoherent uniform RWStructuredBuffer<NodeData> _NodeList : register(u2) ;
    In DX11 all work as expected, I see this picture:
    Screenshot_2.png
    But in OpenGL (4.5) its look like this:
    Screenshot_3.png

    In my opinion its happens because my RWStructuredBuffer will flushed between threads groups and results not shared... I cant find any solution, because my knowlege in OpenGL very small...
    Maybe somebody can help me with it? Code or another information can be provided if it help.
     
  2. NeonTanto

    NeonTanto

    Joined:
    Jun 19, 2013
    Posts:
    156
    So. Its solved. I get some very weird expirience with Unity OpenGL compiler...But, if anybody intrested in this theme, I can explain some key points and give some code for experements after optimisation will done.
     
  3. candycat

    candycat

    Joined:
    Jun 5, 2014
    Posts:
    29
    Hi, how did you fix the bug? Can you share some key points?
     
  4. NeonTanto

    NeonTanto

    Joined:
    Jun 19, 2013
    Posts:
    156
    Its was long time ago =) Write to me on andreich@holyshovelsoft.com, and I'll try find this code and explain details.