Search Unity

Compute Buffer/Structured Buffer support in Unity 2021.2.0b4.3123

Discussion in 'Visual Effect Graph' started by PraetorBlue, Jul 25, 2021.

  1. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    According to the roadmap, compute buffer support was released in 2021.2 beta: https://portal.productboard.com/8uf...ort?utm_medium=social&utm_source=portal_share

    I'm trying to figure out how to use it. I'm using Unity 2021.2.0b4.3123. But I only see GraphicsBuffer in the list for possible VFX Graph properties:


    Likewise the VisualEffect scripting component only has a
    SetGraphicsBuffer
    method exposed, with no way to set a compute buffer.

    What am I missing here? How can I used a ComputeBuffer/StructuredBuffer in VFX graph? Did I misread this feature?
     
    Last edited: Jul 25, 2021
  2. PaulDemeulenaere

    PaulDemeulenaere

    Unity Technologies

    Joined:
    Sep 29, 2016
    Posts:
    154
    Hello,

    The ComputeBuffer and GraphicsBuffer objects are more or less the same, both can be used in a compute dispatch.
    But in VFX, we are only providing SetGraphicsBuffer which can be sampled in Graph with the SampleBuffer operator.

    We don't have a self explanatory sample yet. However, some teasing (warning for arachnophobia) from @VladVNeykov !

    Meanwhile, you can check the Graphic Test we used to verify this feature with the attached unity package, it has been extracted from the Graphics repository, this sample requires Unity 2021.2.0b2 or greater.
     

    Attached Files:

    laurentlavigne and PolyCrusher like this.
  3. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    Thank you Paul. I guess the approach is to use a GraphicsBuffer in my Compute Shader. I'll try that out, thank you.
     
  4. andybak

    andybak

    Joined:
    Jan 14, 2017
    Posts:
    569
    PaulDemeulenaere likes this.
  5. svenneve

    svenneve

    Joined:
    May 14, 2013
    Posts:
    80
    Any idea why this isn't working? 2022.1.0b16.3733
    Visual Effects Graph 12.1.0

    upload_2021-10-25_17-18-48.png
     

    Attached Files:

    Last edited: Oct 25, 2021
  6. PaulDemeulenaere

    PaulDemeulenaere

    Unity Technologies

    Joined:
    Sep 29, 2016
    Posts:
    154
    Hello !
    I'm a bit confused, the latest version of 2022.1.0 is 2022.1.0b8. I suppose you meant 2021.2.0b16 ?

    I've locally double checked and it seems fine:
    21_2b16.gif
    (this project is shared with attachement of this post)

    Maybe, you can verify two things:
    - The VisualEffect Graph package is be installed (Windows > Package Manager > In Project)
    - If you are importing this script where an asmdef is active, it will require the reference to Visual Effect Graph Runtime (VFXTypeAttribute is defined in package code)
    upload_2022-2-18_13-53-19.png
    Code (JavaScript):
    1. {
    2.     "name": "GraphicsBuffer",
    3.     "rootNamespace": "",
    4.     "references": [
    5.         "Unity.VisualEffectGraph.Runtime"
    6.     ],
    7.     "includePlatforms": [],
    8.     "excludePlatforms": [],
    9.     "allowUnsafeCode": false,
    10.     "overrideReferences": false,
    11.     "precompiledReferences": [],
    12.     "autoReferenced": true,
    13.     "defineConstraints": [],
    14.     "versionDefines": [],
    15.     "noEngineReferences": false
    16. }
    Hope this helps!
     

    Attached Files:

  7. svenneve

    svenneve

    Joined:
    May 14, 2013
    Posts:
    80
    Sorry for not updating the thread.

    It's been a while and I did solve it eventually, I think I did something as simple as trashing the library or maybe the editor settings where borked and I had to set the external editor to visual studio again.

    Again, my appologies for sending you on a ghost chase.
     
  8. PolyCrusher

    PolyCrusher

    Joined:
    Jul 3, 2012
    Posts:
    15
    Got a VFX compile error when using more than one GraphicsBuffer.

    Unity 2021.2.12f1 / URP 12.1.4

    Shader error in '[New Graph] [System] Update Particle': redefinition of 'SampleStructuredBuffer' at kernel CSMain at Graph.vfx(38) (on vulkan)

    It looks like only one SampleStructuredBuffer is possible at this time?
     

    Attached Files:

  9. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hi @PolyCrusher ,
    I tried in 2021.2.13f1.4426 on URP on vulkan with sampling two graphics buffers and using the Shader Graph integration (both with a Visual Effect and a Universal target), but unfortunately could not reproduce the issue.

    Can you please log a bug, or provide a min. reproduction package here so we can investigate?
    Thanks!
     
  10. PolyCrusher

    PolyCrusher

    Joined:
    Jul 3, 2012
    Posts:
    15
    Hey VladVNeykov,

    i reported a bug: (Case 1406873)

    Thanks!
     
    VladVNeykov and PaulDemeulenaere like this.
  11. VladVNeykov

    VladVNeykov

    Unity Technologies

    Joined:
    Sep 16, 2016
    Posts:
    550
    Hi @PolyCrusher ,

    Thanks for reporting the issue! @PaulDemeulenaere found the root cause; we are generating a variant function for every type usage of the SampleGraphicsBuffer. However, in HLSL, the Color and Float4 are bound to the same type "float4", so it generates unexpected conflicts.

    As a workaround until the fix lands, you can just set both types to float4:
     

    Attached Files:

    Last edited: Feb 25, 2022
    PaulDemeulenaere and PolyCrusher like this.
  12. PolyCrusher

    PolyCrusher

    Joined:
    Jul 3, 2012
    Posts:
    15
    The graphicsbuffer connection with vfx graph is a absolutely cool feature.
    Endless possibilties. Fall in love that!
     
    PaulDemeulenaere and VladVNeykov like this.
  13. NullMoniker

    NullMoniker

    Joined:
    Aug 20, 2021
    Posts:
    2
    This looks like exactly what I am looking for to get deformed mesh data into the VFX Graph. The issue is I am using Shader Graph to do the deformations. Is it possible to fill the Graphics Buffer from the Shader Graph VIA a custom node?