Search Unity

Compute Shader VS2019

Discussion in 'Scripting' started by Nuvix, Sep 22, 2021.

  1. Nuvix

    Nuvix

    Joined:
    Feb 9, 2014
    Posts:
    4
    There must be a better way to work with HLSL.

    By default, there is no Intellisense support. I installed a VS extension "HLSL Tools for Visual Studio", and that helped a whole lot with that; however, VS2019 is now in the habit of mangling my code every time I write a new function.

    Note that all following code samples are HLSL. I left it on CSharp strictly for the syntax highlighting.

    For example, I might have a function like this (HLSL):
    Code (CSharp):
    1. float GetVelocity(float n, float A, float R, float S)
    2. {
    3.     return ((1.49 / n) * A * pow(R, 2 / 3) * pow(S, 1 / 2)) / A;
    4. }
    If I add a function above it, it is mangled to the following (HLSL):
    Code (CSharp):
    1.     float GetVelocity
    2.     (
    3.     float n, float A, float R, float S)
    4. {
    5.         return ((1.49 / n) * A * pow(R, 2 / 3) * pow(S, 1 / 2)) / A;
    6.     }
    It is far worse if I have used any keywords like inout or out in my parameters (HLSL):
    Code (CSharp):
    1.     float GetVelocity
    2.     (in
    3.     float n, in
    4.     float A, in
    5.     float R, in
    6.     float S)
    7. {
    8.         return ((1.49 / n) * A * pow(R, 2 / 3) * pow(S, 1 / 2)) / A;
    9.     }
    In every case, it is mangled so badly that Ctrl-K + Ctrl-D cannot fix it, and it does this to every single function in the file below the function I am adding, every single time.

    How do you all work with HLSL? This is extremely frustrating.
     
    Last edited: Sep 22, 2021
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,727
    Wow, that makes
    vi
    look pretty good!

    I have no idea... sounds like maybe something wrong with the HLSL code completer? Are there different "dialects" of that language grammar? Maybe it's using a newer dialect than Unity can handle. Perhaps look for dialect versions settings?

    Meanwhile, use
    vi
    I guess! :)
     
  3. Cameron_SM

    Cameron_SM

    Joined:
    Jun 1, 2009
    Posts:
    915
    I've never had this issue in VS2019 editing shader files.

    To be honest, I have never tried to install a plugin for it, was happy with the out-of-the-box syntax highlighting. There isn't a lot of structure to most shaders. It's not like you're dealing with large and deep class hierarchies or complex APIs. Most shaders are a handful of basic functions all in one file. Intellisense is not going to get you much as the HLSL API is fairly small and completely flat. Just open a reference in a browser tab.

    Also, never use vi. :p
     
  4. Nuvix

    Nuvix

    Joined:
    Feb 9, 2014
    Posts:
    4
    Though I do not have enough experience with shaders to say with any certainty, I think this may be a little more complicated than your average shader, and I am not so great at remembering exactly what I have called everything. I am trying to build an integrated mix of simulating very basic weather and several different types of erosion, the latter to a slightly greater depth than I have seen in the papers I have gone over. Mix that with not knowing what functions or types are available, and Intellisense is plain fantastic for productivity.

    I wound up going with VS Code. It has the exact same extension available, but it does not mangle my code in that editor.