• Stars
    star
    500
  • Rank 88,178 (Top 2 %)
  • Language HLSL
  • License
    Other
  • Created about 9 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Visual Studio extension that provides enhanced support for editing High Level Shading Language (HLSL) files

HLSL Tools for Visual Studio Join the chat at https://gitter.im/tgjones/HlslTools Build Status

This extension is for Visual Studio 2019 / 2022. Go here for the Visual Studio Code extension.

HLSL Tools is a Visual Studio 2019 / 2022 extension that provides enhanced support for editing High Level Shading Language (HLSL) files.

Download the extension at the Visual Studio Marketplace.

See the changelog for changes.

Why use HLSL Tools?

Since Visual Studio 2012, Visual Studio has shipped with basic support for editing HLSL files. In addition to that basic feature set, HLSL Tools includes many more navigational and editing features:

VS2019 / VS2022 VS2019 / VS2022 with HLSL Tools
Syntax highlighting Syntax highlighting
Automatic formatting Automatic formatting
Brace matching Brace matching
Brace completion Brace completion
Outlining Outlining
Statement completion
Signature help
Reference highlighting
Navigation bar
Navigate to (Ctrl+,)
Live errors
Go to definition
Quick info
Gray out code excluded by preprocessor
HLSL-specific preferences

There are more features on the roadmap.

Features

Statement completion

Just start typing, and HLSL Tools will show you a list of the available symbols (variables, functions, etc.) at that location. You can manually trigger this with the usual shortcuts: Ctrl+J, Ctrl+Space, etc.

Statement completion demo

Signature help

Signature help (a.k.a. parameter info) shows you all the overloads for a function call, along with information (from MSDN) about the function, its parameters, and return types. Typing an open parenthesis will trigger statement completion, as will the standard Ctrl+Shift+Space shortcut. Signature help is available for all HLSL functions and methods, including the older tex2D-style texture sampling functions, and the newer Texture2D.Sample-style methods.

Signature help demo

Reference highlighting

Placing the cursor within a symbol (local variable, function name, etc.) will cause all references to that symbol to be highlighted. Navigate between references using Ctrl+Shift+Up and Ctrl+Shift+Down.

Reference highlighting demo

Navigation bar

Navigation bar demo

Navigate To

HLSL Tools supports Visual Studio's Navigate To feature. Activate it with Ctrl+,, and start typing the name of the variable, function, or other symbol that you want to find.

Navigate To demo

Live errors

HLSL Tools shows you syntax and semantic errors immediately. No need to wait till compilation! Errors are shown as squigglies and in the error list.

Live errors demo

Go to definition

Press F12 to go to a symbol definition. Go to definition works for variables, fields, functions, classes, macros, and more.

Go to definition demo

Quick info

Hover over almost anything (variable, field, function call, macro, semantic, type, etc.) to see a Quick Info tooltip.

Quick info demo

Preprocessor support

HLSL Tools evaluates preprocessor directives as it parses your code, and grays out excluded code. If you want to make a code block visible to, or hidden from, HLSL Tools, use the __INTELLISENSE__ macro:

INTELLISENSE macro demo

Options

Configure HLSL-specific IntelliSense and formatting options. If you really want to, you can disable IntelliSense altogether and just use HLSL Tools' other features. You can also set HLSL-specific highlighting colours in Tools > Options > Environment > Fonts and Colors.

Options demo

Extras

The code

HLSL Tools includes a handwritten HLSL parser. It initially used an ANTLR lexer and parser, but the handwritten version was faster, and offered better error recovery.

HLSL Tools has a reasonable test suite - although it can certainly be improved. Amongst more granular tests, it includes a suite of 433 shaders, including all of the shaders from the DirectX and Nvidia SDKs. If you want to contribute gnarly source files which push HLSL to its limit, that would be great!

Syntax visualizer

Inspired by Roslyn, HLSL Tools includes a syntax visualizer. It's primarily of interest to HLSL Tools developers, but may be of interest to language nerds, so it's included in the main extension. Open it using View > Other Windows > HLSL Syntax Visualizer.

Syntax visualizer demo

Custom preprocessor definitions and additional include directories

HLSL Tools has a built-in preprocessor to handle #define and #include directives. The behavior of this preprocessor can be customised by creating a file named shadertoolsconfig.json:

{
  "hlsl.preprocessorDefinitions": {
    "MY_PREPROCESSOR_DEFINE_1": "Foo",
    "MY_PREPROCESSOR_DEFINE_2": 1
  },
  "hlsl.additionalIncludeDirectories": [
    "C:\\Code\\MyDirectoryA",
    "C:\\Code\\MyDirectoryB",
    ".",
    "..\\RelativeDirectory"
  ],
  "hlsl.virtualDirectoryMappings": {
    "/Project": "C:\\MyProject\\Shaders"
  }
}
  • hlsl.preprocessorDefinitions: It's normal for additional preprocessor definitions to be defined as part of a project build. In some cases, the shader won't compile correcty without these. To handle this, you can add those additional preprocessor definitions here.
  • hlsl.additionalIncludeDirectories: HLSL Tools will, by default, only use the directory containing the source file to search for #include files. Additional include directories can be added here.
  • hlsl.virtualDirectoryMappings: Use this to configure the virtual directory mappings required by Unreal Engine. The virtual directory (/Project in the example above) must start with a forward slash or backslash.

HLSL Tools will look for a file named shadertoolsconfig.json in the directory of an opened file, and in every parent directory. A search for shadertoolsconfig.json files will stop when the drive root is reached or a shadertoolsconfig.json file with "root": true is found. If multiple config files are found during this search, they will be combined, with properties in closer files taking precedence.

Config files are cached for performance reasons. If you make make changes to a config file, you'll need to close and re-open any source files that use that config file.

Getting involved

You can ask questions in our Gitter room. If you find a bug or want to request a feature, create an issue here . You can find me on Twitter at @_tim_jones_ and I tweet about HLSL Tools using the #hlsltools hashtag.

Contributions are always welcome. Please read the contributing guide first.

Maintainer(s)

Acknowledgements

  • Much of the code structure, and some of the actual code, comes from Roslyn.
  • NQuery-vnext is a nice example of a simplified Roslyn-style API, and HLSL Tools borrows some of its ideas and code.
  • Node.js Tools for Visual Studio and Python Tools for Visual Studio are amongst the best examples of how to build a language service for Visual Studio, and were a great help.
  • ScriptSharp is one of the older open-source .NET-related compilers, and is still a great example of how to structure a compiler.
  • LangSvcV2 includes many nice abstractions for some of the more complicated parts of Visual Studio's language service support.

More Repositories

1

gemini

Gemini is an IDE framework similar in concept to the Visual Studio Shell. It uses AvalonDock and has an MVVM architecture based on Caliburn Micro.
C#
1,032
star
2

shader-playground

Shader playground website for exploring HLSL, GLSL, SPIR-V compilers
C
494
star
3

slimshader

SlimShader is a Direct3D shader bytecode parser for .NET and C++
Assembly
152
star
4

rasterizr

Software rasterizer written in C#, with an API based on Direct3D 10 / 11. Programmable parts of the pipeline execute "real" HLSL shaders.
C#
95
star
5

mini-c

F# implementation of a Mini-C compiler targeting MSIL
F#
81
star
6

meshellator

3D asset import library for .NET 4.0. Supported formats are Autodesk 3DS and Lightwave OBJ.
C#
44
star
7

nexus

Small and lightweight 3D vector and matrix library for .NET 4.0.
C#
23
star
8

slimshader-cpp

SlimShader is a Direct3D shader bytecode parser for .NET and C++
C++
21
star
9

monogame-samples

Collection of samples for the MonoGame framework
C#
15
star
10

hlsl-parser-nitra

HLSL parser for .NET
C
15
star
11

xbuilder

XBuilder is an extension for Visual Studio 2010 which adds the ability to preview models, effects and textures from your XNA content projects, right inside Visual Studio.
C#
12
star
12

dryrunner

Isolated integration testing for ASP.NET
C#
10
star
13

stitchup

StitchUp is an XNA 4.0 implementation of Shawn Hargreaves' article "Generating Shaders From HLSL Fragments". It integrates with the XNA Content Pipeline to provide compile-time linking of shader fragments.
C#
10
star
14

dotwarp

DotWarp is an easy-to-use 3D software rasterization library, which produces 2D rendered images from 3D mesh files. It uses WARP, a 3D software rasterizer built-in to Windows Vista / 7 / Server 2008 R2, for the actual rasterization. It is a .NET 4.0 project.
C#
9
star
15

make-santa-jump

Endless runner game written in F# using MonoGame
F#
9
star
16

CLILL

Proof-of-concept LLVM IR to MSIL translator (opposite of LLILC, hence the name)
LLVM
8
star
17

SimdDoors

Example project demonstrating SIMD intrinsics in .NET Core 3.0
C#
8
star
18

ormongo

Ormongo is a very lightweight implementation of the ActiveRecord pattern, built on top of the 10gen Mongo C# driver.
C#
5
star
19

zia.js

Object-oriented WebGL-based game framework
CSS
5
star
20

xna-tutorials

Little XNA projects that I post as tutorials on my blog
C#
5
star
21

osiris

Some XNA 4.0 Content Pipeline extensions
C#
5
star
22

DotNetDxc

NuGet package for .NET wrapper of Microsoft's DirectXShaderCompiler
C#
4
star
23

weaver

HLSL surface shader parser for XNA / MonoGame
C#
4
star
24

particlephysics

Simple XNA particle physics demo
C#
3
star
25

idx3dsharp

Port of the idx3d software rasterizer
C#
3
star
26

aether

Ray tracer in C#
C#
3
star
27

rasteracer

Hybrid ray tracer / XNA renderer
C#
3
star
28

awesome-game-2

The "sequel" to Awesome Game. It was supposed to be a resource trading game played out on a world stage...
C#
2
star
29

aemula-csharp

Emulator playground written in C#
Assembly
2
star
30

apesharp

Port of ActionScript Physics Engine into C#
C#
2
star
31

aether-fsharp

Port of PBRT ray tracer to F#
F#
2
star
32

awesome-game

A top-down racing game some friends and I wrote during a "geekathon" coding weekend
C#
2
star
33

torq2

A 3D car game I've been trying to write for a little while now. This is an old version of it. Perhaps the main point of interest is the geoclipmapping implementation.
C#
2
star
34

Hlsl2GlslSharp

.NET bindings for Aras Pranckevičius's hlsl2glslfork
C#
1
star
35

robosharp

RoboSharp is a very old .NET port of RoboCode
C#
1
star
36

mincamlsharp

F#
1
star
37

aether-cpp

Ray tracer
C
1
star
38

shaders-tmLanguage

Syntax grammars used for HLSL and ShaderLab colorization
1
star
39

jolt

Simple physics engine. Currently a straightforward C# port of Cyclone Physics (https://github.com/idmillington/cyclone-physics)
C#
1
star
40

software-sandbox

Miscellaneous, and quite useless, little projects
C#
1
star