MonoDevelop Syntax Highlighting for compute shaders

Hey fellow DX11 shader programmers.

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

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 :slight_smile:

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 %USERPROFILE%/AppData/Local/MonoDevelop-Unity-2.8 folder. So the actual dll file ends up here: %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:

%USERPROFILE%/AppData/Local/MonoDevelop-Unity-4.0

If you happen to be using MonoDevelop 4 on OS X, this should be the install location:

~/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:

<Addin    namespace    = "MonoDevelop"
        id            = "DirectComputeSyntax"
        name        = "DirectCompute Syntax Mode"
        author        = "Laurens Mathot"
        copyright    = "MIT X11"
        url            = "http://codeanimo.com"
        description    = "Adds basic Syntax Highlighting support for DirectCompute .compute files"
        category    = "Language bindings"
        version        = "1.0">
    
    <Dependencies>
        <Addin id="Core" version="2.8" />
        <Addin id="Ide" version="2.8" />
        <Addin id="SourceEditor2" version="2.8" />
    </Dependencies>
    
    <Extension path="/MonoDevelop/Core/MimeTypes">  
        <MimeType id="text/x-shader" _description="DirectCompute file" isText="true">  
            <File pattern="*.compute" />
        </MimeType>
    </Extension>    
</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 :wink:

1127569–74253–$MonoDevelop DirectCompute Highlighting 1.4.zip (3.26 KB)

5 Likes

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’):

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).

1127667–42657–$MonoDevelop Unity 2-8 basic compute file syntax highlighting v1-1.zip (2.41 KB)

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

<SyntaxMode name="DirectCompute" mimeTypes="text/x-directcompute" extends="text/x-shader">
    
    <EolSpan color = "text.preprocessor" rule="text.preprocessor">#</EolSpan>
    <EolSpan color = "comment.line" rule="Comment" tagColor="comment.tag.line">//</EolSpan>
    
    <Keywords color = "keyword.type">
        
        
        <Word>TextureCube</Word>
        <Word>TextureCubeArray</Word>
        
        <Word>AppendStructuredBuffer</Word>
        <Word>Buffer</Word>
        <Word>ByteAddressBuffer</Word>
        <Word>ConsumeStructuredBuffer</Word>
        <Word>InputPatch</Word>
        <Word>OutputPatch</Word>
        
        <Word>RWBuffer</Word>
        <Word>RWByteAddressBuffer</Word>
        <Word>RWStructuredBuffer</Word>
        
        <Word>RWTexture1D</Word>
        <Word>RWTexture1DArray</Word>
        <Word>RWTexture2D</Word>
        <Word>RWTexture2DArray</Word>
        <Word>RWTexture3D</Word>
        <Word>StructuredBuffer</Word>
        
        <Word>Texture1D</Word>
        <Word>Texture1DArray</Word>
        <Word>Texture2D</Word>
        <Word>Texture2DArray</Word>
        <Word>Texture2DMS</Word>
        <Word>Texture2DMSArray</Word>        
        <Word>Texture3D</Word>
        
        
        <Word>struct</Word>
        
        <Word>uint</Word>
        <Word>uint2</Word>
        <Word>uint3</Word>
        
        
        <Word>struct</Word>
    </Keywords>
    
    <!--Some Matrices are already supported by Unity's shaderlab syntax highlighting-->
<!--    <Match color = "keyword.type">bool[1-4]x[1-4]</Match>-->
    
<!--    <Match color = "keyword.type">int[1-4]x[1-4]</Match>-->
<!--    <Match color = "keyword.type">half[1-4]x[1-4]</Match>-->
<!--    <Match color = "keyword.type">float[1-4]x[1-4]</Match>-->
    
    <Match color = "keyword.type">uint[1-4]x[1-4]</Match>
    <Match color = "keyword.type">dword[1-4]x[1-4]</Match>
    <Match color = "keyword.type">double[1-4]x[1-4]</Match>
    
    
    
    
    <Match color = "constant.language">BINORMAL\d</Match>
    <Match color = "constant.language">BLENDINDICES\d</Match>
    <Match color = "constant.language">BLENDWEIGHT\d</Match>
    <Match color = "constant.language">NORMAL\d</Match>
    <Match color = "constant.language">TANGENT\d</Match>
    <Match color = "constant.language">POSITION\d</Match>
    
    <Match color = "constant.language">TESSFACTOR\d</Match>
    <Match color = "constant.language">TEXCOORD\d</Match>
    <Match color = "constant.language">COLOR\d</Match>
    <Match color = "constant.language">DEPTH\d</Match>    
    
    <Match color = "constant.language">SV_ClipDistance\d</Match>
    <Match color = "constant.language">SV_CullDistance\d</Match>
    <Match color = "constant.language">SV_Target[0-7]</Match>
    
    <Keywords color = "constant.language" ignorecase="true">
        <Word>POSITIONT</Word>
        <Word>FOG</Word>
        <Word>PSIZE</Word>
        
        <Word>VFACE</Word>
            
        <Word>SV_Coverage</Word>
        <Word>SV_Depth</Word>
        <Word>SV_DomainLocation</Word>
        
        <Word>SV_DispatchThreadId</Word>
        <Word>SV_GroupID</Word>
        <Word>SV_GroupIndex</Word>
        <Word>SV_GroupThreadID</Word>
        
        <Word>SV_GSInstanceID</Word>
        <Word>SV_InsideTessFactor</Word>
        <Word>SV_IsFrontFace</Word>
        <Word>SV_OutputControlPointID</Word>
        <Word>SV_Position</Word>
        <Word>SV_RenderTargetArrayIndex</Word>
        <Word>SV_SampleIndex</Word>
        
        <Word>SV_TessFactor</Word>
        <Word>SV_ViewportArrayIndex </Word>
        
        <Word>SV_InstanceID </Word>
        <Word>SV_PrimitiveID </Word>
        <Word>SV_VertexID</Word>        
    </Keywords>
    
    
    <!--Comments and numbers need to be redefined, because extending syntax highlighting somehow removes these rules-->
    <Match color = "constant.digit">CSharpNumber</Match>
    
    <Span color = "comment.block" rule="Documentation" tagColor="comment.tag.block">
        <Begin>/**</Begin>
        <End>*/</End>
    </Span>
    
    <Span color = "comment.block" rule="Comment" tagColor="comment.tag.block">
        <Begin>/*</Begin>
        <End>*/</End>
    </Span>
    
    
</SyntaxMode>

1128842–42718–$DirectCompute Syntax Highlighting v1-3 for MonoDevelopUnity2-8.zip (2.91 KB)

great work. This is really helpful!

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?

According to one of the addin creation tutorials you should be able to find it under

Thank you! that was indeed the right location.

Thanks very much.
It would be much better If it can auto complete.

I agree!
That requires a lot more research though. So I can’t really work on that right now.

The install location has changed slightly since Unity 4.3, so I’ve updated the installation instructions.
The new location is:

%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

This is awesome!

This deserves a bump. Works great.

I’m glad you like it!

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)

1 Like

Any update for unity 5.4 ? It’s not working anymore :frowning:
(I also tried the xml, but it only works for the first time, after reopen a compute file it’s all gone.)

I had to switch to Visual studio for 5.4, highlighting works there

I got it working, I had to change the version numbers in the xml:

    <Addin    namespace    = "MonoDevelop"
            id            = "DirectComputeSyntax"
            name        = "DirectCompute Syntax Mode"
            author        = "Laurens Mathot"
            copyright    = "MIT X11"
            url            = "http://codeanimo.com"
            description    = "Adds basic Syntax Highlighting support for DirectCompute .compute files"
            category    = "Language bindings"
            version        = "1.0">
      
        <Dependencies>
            <Addin id="Core" version="5.9.6" />
            <Addin id="Ide" version="5.9.6" />
            <Addin id="SourceEditor2" version="5.9.6" />
        </Dependencies>
      
        <Extension path="/MonoDevelop/Core/MimeTypes"> 
            <MimeType id="text/x-shader" _description="DirectCompute file" isText="true"> 
                <File pattern="*.compute" />
            </MimeType>
        </Extension>   
    </Addin>
1 Like

I haven’t worked in Unity for a while now, so thanks for the update Nexusmaster

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

Oh Nevermind I directly edited the dll contents with Notepad++ and it worked ^^

I attached the .dll

2631621–184991–MonoDevelop.DirectComputeSyntax.zip (2.69 KB)

1 Like