Search Unity

  1. Unity 2018.1 has arrived! Read about it here
    Dismiss Notice
  2. Scriptable Render Pipeline improvements, Texture Mipmap Streaming, and more! Check out what we have in store for you in the 2018.2 Beta.
    Dismiss Notice
  3. If you couldn't join the live stream, take a peek at what you missed.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  5. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  6. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  7. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

MonoDevelop Syntax Highlighting for compute shaders

Discussion in 'Shaders' started by RC-1290, Jan 5, 2013.

  1. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    Hey fellow DX11 shader programmers.

    Here's a little MonoDevelop addin that might help you out. It adds syntax highlighting for .compute files.

    $Compute_shader_syntax_highlighting.png

    Background info
    Syntax highlighting for compute files in MonoDevelop didn't work for me, so I spent some time learning how to define new language syntax in MonoDevelop. Perhaps that wasn't necessary, because there's a chance my installation of Unity4 is simply corrupt, and reinstalling could fix it, but I happen to dislike reinstalling software, and I like learning a new skill.

    So I made a basic addin for the Unity4 version of MonoDevelop 2.8 that makes it handle .compute files like the other shader files (mimetype text/x-shader). I didn't bother making it a proper addin with compatibility checks (it simply assumes you are using the Unity version of MonoDevelop 2.8 ), because I want to get back to working on the DirectX11 contest. But it might still help some of you guys out, so I've attached the dll to this post.

    Functionality
    v1.0
    • .compute files are highlighted as if they're shaderlab shaders.
    • Massages your eyes with your chosen syntax highlighting color scheme
    • Reduces stress caused by code that is supposed to be commented out, but isn't
    • It also magically makes 'Toggle Line Comment(s)' work :)
    v1.2
    • Texture1D
    • Texture1DArray
    • Texture2D
    • Texture2DArray
    • Texture3D
    • RWTexture2D
    • TextureCube
    • uint, uint2, uint3
    v1.3
    • uint, dword double matrices
    • SM5 Semantics
    • SM5 Objects
    v1.4
    • This version is compiled for MonoDevelop 4.0.1

    Installation
    Download the latest zipfile. It contains a dll file inside a bunch of folders which, if you're using Windows 7, need to go into the
    Code (csharp):
    1. %USERPROFILE%/AppData/Local/MonoDevelop-Unity-2.8
    folder. So the actual dll file ends up here:
    Code (csharp):
    1. %USERPROFILE%/AppData/Local/MonoDevelop-Unity-2.8/LocalInstall/Addins/MonoDevelop.DirectComputeSyntax/MonoDevelop.DirectComputeSyntax.dll
    Since Unity 4.3 uses Mono Develop 4.0.1, the correct location is:
    Code (csharp):
    1. %USERPROFILE%/AppData/Local/MonoDevelop-Unity-4.0
    If you happen to be using MonoDevelop 4 on OS X, this should be the install location:
    Code (csharp):
    1. ~/Library/Application Support/XamarinStudio-4.0/LocalInstall/Addins
    Downloads
    version 1.4 (for MonoDevelop 4.0.1)
    version 1.3 (for MonoDevelop 2.8 )
    version 1.2 was not released
    version 1.1
    version 1.0(only default shaderlab syntax)

    Or create it yourself
    If you distrust dll files, here's the xml file you need to create the addin yourself:

    DirectComputeSyntax.addin.xml:
    Code (csharp):
    1. <Addin    namespace    = "MonoDevelop"
    2.         id            = "DirectComputeSyntax"
    3.         name        = "DirectCompute Syntax Mode"
    4.         author        = "Laurens Mathot"
    5.         copyright    = "MIT X11"
    6.         url            = "http://codeanimo.com"
    7.         description    = "Adds basic Syntax Highlighting support for DirectCompute .compute files"
    8.         category    = "Language bindings"
    9.         version        = "1.0">
    10.    
    11.     <Dependencies>
    12.         <Addin id="Core" version="2.8" />
    13.         <Addin id="Ide" version="2.8" />
    14.         <Addin id="SourceEditor2" version="2.8" />
    15.     </Dependencies>
    16.    
    17.     <Extension path="/MonoDevelop/Core/MimeTypes">  
    18.         <MimeType id="text/x-shader" _description="DirectCompute file" isText="true">  
    19.             <File pattern="*.compute" />
    20.         </MimeType>
    21.     </Extension>    
    22. </Addin>
    That probably still has some remains from the experiments with custom Syntax Highlighting, but it should do the trick.


    Good luck with the DX11 contest, please make something that is awesome, but somehow does not win, and gives me a chance ;)
     

    Attached Files:

    Last edited: Nov 12, 2013
  2. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    It turned out that it was relatively easy to extend the shaderlab syntax highlighting, now that I understood the basics.
    Here is is Basic Compute Shader Syntax Highlighting v1.1 with support for some extra types you might use in your compute shaders.

    Preview (using a custom syntax highlighting color scheme 'Something Something Dark'):
    $Compute shader syntax highlighting v1-1 preview.png

    The following keywords should now be highlighted as type:

    • Texture1D
    • Texture1DArray
    • Texture2D
    • Texture2DArray
    • Texture3D
    • RWTexture2D
    • TextureCube
    • uint
    • uint2
    • uint3
    struct is being original, so it shows up differently, and '.a' is the only recognized vector component. (This is the default x-shader highlighting behavior).
     

    Attached Files:

    Last edited: Jan 7, 2013
  3. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    Version 1.3
    Added support for highlighting Shader model 5 Semantics, Objects and Matrices

    You can download and copy the attached dll to the MonoDevelop addin folder as described in the first post.

    Alternatively you can create the addin manually.

    Here are the new keywords defined in DirectComputeSyntax.xml
    Code (csharp):
    1. <SyntaxMode name="DirectCompute" mimeTypes="text/x-directcompute" extends="text/x-shader">
    2.    
    3.     <EolSpan color = "text.preprocessor" rule="text.preprocessor">#</EolSpan>
    4.     <EolSpan color = "comment.line" rule="Comment" tagColor="comment.tag.line">//</EolSpan>
    5.    
    6.     <Keywords color = "keyword.type">
    7.        
    8.        
    9.         <Word>TextureCube</Word>
    10.         <Word>TextureCubeArray</Word>
    11.        
    12.         <Word>AppendStructuredBuffer</Word>
    13.         <Word>Buffer</Word>
    14.         <Word>ByteAddressBuffer</Word>
    15.         <Word>ConsumeStructuredBuffer</Word>
    16.         <Word>InputPatch</Word>
    17.         <Word>OutputPatch</Word>
    18.        
    19.         <Word>RWBuffer</Word>
    20.         <Word>RWByteAddressBuffer</Word>
    21.         <Word>RWStructuredBuffer</Word>
    22.        
    23.         <Word>RWTexture1D</Word>
    24.         <Word>RWTexture1DArray</Word>
    25.         <Word>RWTexture2D</Word>
    26.         <Word>RWTexture2DArray</Word>
    27.         <Word>RWTexture3D</Word>
    28.         <Word>StructuredBuffer</Word>
    29.        
    30.         <Word>Texture1D</Word>
    31.         <Word>Texture1DArray</Word>
    32.         <Word>Texture2D</Word>
    33.         <Word>Texture2DArray</Word>
    34.         <Word>Texture2DMS</Word>
    35.         <Word>Texture2DMSArray</Word>        
    36.         <Word>Texture3D</Word>
    37.        
    38.        
    39.         <Word>struct</Word>
    40.        
    41.         <Word>uint</Word>
    42.         <Word>uint2</Word>
    43.         <Word>uint3</Word>
    44.        
    45.        
    46.         <Word>struct</Word>
    47.     </Keywords>
    48.    
    49.     <!--Some Matrices are already supported by Unity's shaderlab syntax highlighting-->
    50. <!--    <Match color = "keyword.type">bool[1-4]x[1-4]</Match>-->
    51.    
    52. <!--    <Match color = "keyword.type">int[1-4]x[1-4]</Match>-->
    53. <!--    <Match color = "keyword.type">half[1-4]x[1-4]</Match>-->
    54. <!--    <Match color = "keyword.type">float[1-4]x[1-4]</Match>-->
    55.    
    56.    <Match color = "keyword.type">uint[1-4]x[1-4]</Match>
    57.    <Match color = "keyword.type">dword[1-4]x[1-4]</Match>
    58.    <Match color = "keyword.type">double[1-4]x[1-4]</Match>
    59.    
    60.    
    61.    
    62.    
    63.    <Match color = "constant.language">BINORMAL\d</Match>
    64.    <Match color = "constant.language">BLENDINDICES\d</Match>
    65.    <Match color = "constant.language">BLENDWEIGHT\d</Match>
    66.    <Match color = "constant.language">NORMAL\d</Match>
    67.    <Match color = "constant.language">TANGENT\d</Match>
    68.    <Match color = "constant.language">POSITION\d</Match>
    69.    
    70.    <Match color = "constant.language">TESSFACTOR\d</Match>
    71.    <Match color = "constant.language">TEXCOORD\d</Match>
    72.    <Match color = "constant.language">COLOR\d</Match>
    73.    <Match color = "constant.language">DEPTH\d</Match>    
    74.    
    75.    <Match color = "constant.language">SV_ClipDistance\d</Match>
    76.    <Match color = "constant.language">SV_CullDistance\d</Match>
    77.    <Match color = "constant.language">SV_Target[0-7]</Match>
    78.    
    79.    <Keywords color = "constant.language" ignorecase="true">
    80.        <Word>POSITIONT</Word>
    81.        <Word>FOG</Word>
    82.        <Word>PSIZE</Word>
    83.        
    84.        <Word>VFACE</Word>
    85.            
    86.        <Word>SV_Coverage</Word>
    87.        <Word>SV_Depth</Word>
    88.        <Word>SV_DomainLocation</Word>
    89.        
    90.        <Word>SV_DispatchThreadId</Word>
    91.        <Word>SV_GroupID</Word>
    92.        <Word>SV_GroupIndex</Word>
    93.        <Word>SV_GroupThreadID</Word>
    94.        
    95.        <Word>SV_GSInstanceID</Word>
    96.        <Word>SV_InsideTessFactor</Word>
    97.        <Word>SV_IsFrontFace</Word>
    98.        <Word>SV_OutputControlPointID</Word>
    99.        <Word>SV_Position</Word>
    100.        <Word>SV_RenderTargetArrayIndex</Word>
    101.        <Word>SV_SampleIndex</Word>
    102.        
    103.        <Word>SV_TessFactor</Word>
    104.        <Word>SV_ViewportArrayIndex </Word>
    105.        
    106.        <Word>SV_InstanceID </Word>
    107.        <Word>SV_PrimitiveID </Word>
    108.        <Word>SV_VertexID</Word>        
    109.    </Keywords>
    110.    
    111.    
    112.    <!--Comments and numbers need to be redefined, because extending syntax highlighting somehow removes these rules-->
    113.    <Match color = "constant.digit">CSharpNumber</Match>
    114.    
    115.    <Span color = "comment.block" rule="Documentation" tagColor="comment.tag.block">
    116.        <Begin>/**</Begin>
    117.        <End>*/</End>
    118.    </Span>
    119.    
    120.    <Span color = "comment.block" rule="Comment" tagColor="comment.tag.block">
    121.        <Begin>/*</Begin>
    122.        <End>*/</End>
    123.    </Span>
    124.    
    125.    
    126. </SyntaxMode>
     

    Attached Files:

  4. Pyromuffin

    Pyromuffin

    Joined:
    Aug 5, 2012
    Posts:
    62
    great work. This is really helpful!
     
  5. cavila

    cavila

    Joined:
    Jun 4, 2013
    Posts:
    67
    Any pointers as to installing this for OS X? found the addin folder and was hoping the same logic for Win7 would work on Mac but no dice. Maybe because I'm using MonoDevelop 4?
     
  6. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    According to one of the addin creation tutorials you should be able to find it under
     
  7. cavila

    cavila

    Joined:
    Jun 4, 2013
    Posts:
    67
    Thank you! that was indeed the right location.
     
  8. lzt120

    lzt120

    Joined:
    Apr 13, 2010
    Posts:
    93
    Thanks very much.
    It would be much better If it can auto complete.
     
  9. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    I agree!
    That requires a lot more research though. So I can't really work on that right now.
     
  10. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    The install location has changed slightly since Unity 4.3, so I've updated the installation instructions.
    The new location is:
    Code (csharp):
    1. %USERPROFILE%/AppData/Local/MonoDevelop-Unity-4.0
    on Windows.

    [edit] Updated Addin dependencies for MonoDevelop 4.0.1; make sure you grab download v1.4
     
    Last edited: Nov 12, 2013
  11. landon912

    landon912

    Joined:
    Nov 8, 2011
    Posts:
    1,570
    This is awesome!
     
  12. scrawk

    scrawk

    Joined:
    Nov 22, 2012
    Posts:
    765
    This deserves a bump. Works great.
     
  13. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    I'm glad you like it!
     
  14. TarAlacrin

    TarAlacrin

    Joined:
    Apr 15, 2014
    Posts:
    1
    Hey, this thing is great! Thanks for doing this!

    Also I just wanted to say, this actually works with unity 5 too, with whatever version of Monodevelop that has. (I just used the latest dll and its working splendedly)
     
    RC-1290 likes this.
  15. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    41
    Any update for unity 5.4 ? It's not working anymore :-(
    (I also tried the xml, but it only works for the first time, after reopen a compute file it's all gone.)
     
    Last edited: Apr 10, 2016
  16. JovanD

    JovanD

    Joined:
    Jan 5, 2014
    Posts:
    205
    I had to switch to Visual studio for 5.4, highlighting works there
     
  17. Nexusmaster

    Nexusmaster

    Joined:
    Jun 13, 2015
    Posts:
    41
    I got it working, I had to change the version numbers in the xml:


    Code (CSharp):
    1.     <Addin    namespace    = "MonoDevelop"
    2.             id            = "DirectComputeSyntax"
    3.             name        = "DirectCompute Syntax Mode"
    4.             author        = "Laurens Mathot"
    5.             copyright    = "MIT X11"
    6.             url            = "http://codeanimo.com"
    7.             description    = "Adds basic Syntax Highlighting support for DirectCompute .compute files"
    8.             category    = "Language bindings"
    9.             version        = "1.0">
    10.      
    11.         <Dependencies>
    12.             <Addin id="Core" version="5.9.6" />
    13.             <Addin id="Ide" version="5.9.6" />
    14.             <Addin id="SourceEditor2" version="5.9.6" />
    15.         </Dependencies>
    16.      
    17.         <Extension path="/MonoDevelop/Core/MimeTypes">
    18.             <MimeType id="text/x-shader" _description="DirectCompute file" isText="true">
    19.                 <File pattern="*.compute" />
    20.             </MimeType>
    21.         </Extension>  
    22.     </Addin>
     
    RC-1290 likes this.
  18. RC-1290

    RC-1290

    Joined:
    Jul 2, 2012
    Posts:
    630
    I haven't worked in Unity for a while now, so thanks for the update Nexusmaster
     
  19. sonny-ad

    sonny-ad

    Joined:
    Jan 22, 2014
    Posts:
    4
    I am not sure how to make it work for Unity 5.
    What should I do with the 2 xml files? DirectComputeSyntax and DirectComputeSyntax.addin ?
    Should I rebuild the dll with those?
    @Nexusmaster
     
  20. sonny-ad

    sonny-ad

    Joined:
    Jan 22, 2014
    Posts:
    4
    Oh Nevermind I directly edited the dll contents with Notepad++ and it worked ^^

    I attached the .dll
     

    Attached Files:

    RC-1290 likes this.