Search Unity

StructuredBuffer from Compute to Fragment-Shader on OpenGLES3

Discussion in 'Shaders' started by DHein, Dec 2, 2019.

  1. DHein

    DHein

    Joined:
    Jan 26, 2016
    Posts:
    38
    Hello,

    in my case I want to use a RWStructuredBuffer<float3> in a compute shader to which I write to in fixed time intervals and read the resulting value in a fragment shader. The Buffer itself only contains one element.

    Code (CSharp):
    1. StructuredBuffer<float3> _Buffer : register(t1);
    2.  
    3. fixed4 frag(v2f i) : COLOR
    4. {
    5.     return float4(_Buffer[0], 1);
    6. }

    After experimenting for a bit I have noticed that on the target platform which is Android with OpenGLES3, reading from the buffer in the fragment shader has a very noticable overhead (XR.WaitForGPU) for consistently 2/3 frames, even when the data in the buffers does not change (I assumed it was a read/write blocking issue).



    Is this expected behaviour when using a structured buffer in a fragment shader rather than compute shaders? Is there a certain setup that I somehow missed except for the ComputeBufferType? Is a specific size necessary to make reading more efficient? I also tried using a ConstantBuffer for this, but did not have any luck getting it to work.

    I would appreciate any hints concerning this issue.

    Thanks in advance!
     
    AverageCG likes this.