#glsl #wgsl #shader #lsp #hlsl #language-server #shader-compiler

app shader_language_server

Language server for HLSL / GLSL / WGSL shaders using LSP protocol

2 unstable releases

0.4.0 Nov 23, 2024
0.3.1 Oct 2, 2024

#620 in Development tools

Download history 104/week @ 2024-09-27 40/week @ 2024-10-04 11/week @ 2024-10-11 139/week @ 2024-11-22 15/week @ 2024-11-29 8/week @ 2024-12-06

162 downloads per month

Custom license

225KB
5K SLoC

Shader language server

This application is a language server for shaders (HLSL, GLSL, WGSL) that is mainly meant to be used as a server for vscode extension shader-validator. It is following the LSP protocol to communicate with the extension so it could be used with any editor supporting it. It can be built to desktop or WASI. WASI will let the extension run even in web version of vscode, but it suffer from limitations. See below for more informations.

Features

This language server only support a few options :

  • Diagnostics: lint the code as you type.
  • Completion: suggest completion values as you type.
  • Signature: view the signatures of the current function.
  • Hover: view the declaration of an element by hovering it.
  • Goto: allow to go to declaration of an element.

The server support HLSL, GLSL, WGSL diagnostics, but as of now, only GLSL provides some symbols for completion, signatures, hover & goto.

Diagnostics

Diagnostics are generated following language specifics API:

  • GLSL uses glslang-rs as backend. It provide complete linting for GLSL trough glslang API bindings from C.
  • HLSL uses hassle-rs as backend. It provides bindings to directx shader compiler in rust.
  • WGSL uses naga as backend for linting.

Build for WASI

The server can be built using WASI to interface with VS Code WASI support. We are using threads so we target the thread version.

To build it, install target first :

rustup target add wasm32-wasip1-threads

Then build the app with:

cargo build --target wasm32-wasip1-threads

Dependencies

You will need to install clang. You will need to setup the environment variable WASI_SYSROOT as well targetting the wasi sysroot folder which you can find at WASI SDK repo in releases so that cc-rs can build c++ correctly.

DirectX Shader Compiler issue

Right now, the server can lint hlsl sm 6.0 through hassle-rs. It relies on DirectX Shader Compiler which cannot be built statically. Or, WASI cannot handle dll as of now, and so we need to compile it statically to link it. There is an ongoing issue for that at hassle rs, but it seems to be complicated, as explained here. So with WASI, this extension relies instead on glslang to lint hlsl. It only support basic features of shader models 6.0 and some of upper versions, but many recent added features will be missing from linter. As of now, there is not much way to fix this easily, except hoping that Microsoft does something about this.

Dependencies

~55MB
~1M SLoC