Search Unity

Question Why do constant buffers require compute shader support?

Discussion in 'General Graphics' started by MateiGiurgiu, Feb 2, 2023.

  1. MateiGiurgiu

    MateiGiurgiu

    Joined:
    Aug 13, 2013
    Posts:
    23
    I noticed that creating a constant buffer using
    new GraphicsBuffer(GraphicsBuffer.Target.Constant ... )
    on a platform that doesn't support compute shader fails with this error:

    Attempting to create a graphics buffer that requires compute shader support, but compute shaders are not supported on this platform. Target: Constant

    My question is why do constant buffers require compute shader support? I am personally using them only to upload data to a non-compute (regular) shader, and I believe constant buffers are the most widely supported ways to upload data to a shader.
     
  2. wwWwwwW1

    wwWwwwW1

    Joined:
    Oct 31, 2021
    Posts:
    769
    Hi, I'm not sure how to answer your question. Maybe it was added along with compute shader support, so older GPU or drivers don't support it.

    You can check the #pragma documentation.
    ComputeBuffer.jpg

    If you only need to read the data, I think you can try (uncompressed) texture sampling?
     
  3. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    Which platform is that?
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,352
    @wwWwwwW1 The OP's question is about GraphicsBuffers, not specifically structured buffers / compute buffers. They're different (though compute buffers can also be used as constants now).

    Unity's own documentation has this to say about a constant GraphicsBuffer:
    https://docs.unity3d.com/ScriptReference/GraphicsBuffer.Target.html
    That would imply they should work even without compute shader support, which means that error is likely a bug.

    @MateiGiurgiu I would suggest reporting this as a bug via the in-editor bug reporting menu.
     
  5. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    Not all platforms support constant buffers. At the very least GLES 2.0 and DX9 don't. If either of those are your target the bug is actually the message, not the fact it doesn't work.
     
  6. MateiGiurgiu

    MateiGiurgiu

    Joined:
    Aug 13, 2013
    Posts:
    23
    We are not supporting GLES 2.0 and neither DX9. This issue happened on a GLES 3.0 device with shader level 3.5.
     
  7. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    AFAIK constant buffers need shader model 4.0 at the very least.
     
  8. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,026
    @MateiGiurgiu FWIW we disable constant buffer support on some GLES 3.0 devices (Adreno 3xx).
     
    eizenhorn likes this.