1 unstable release
new 0.1.0 | Dec 21, 2024 |
---|
#10 in #hlsl
145KB
3.5K
SLoC
Shader sense
Shader sense is a library trying to unify shader exploration at runtime with validation and symbol request, intended as use in a language server. This works through the use of standard API. It can be built to desktop or WASI. WASI will let the extension run even in browser, but it suffer from limitations. See below for more informations.
- 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.
For symbol, the API is relying on abstract syntax tree. As we want to support different language, and to ease this process, we are using the tree-sitter API (instead of standard API), which generate AST with query support, and is already available in a lot of languages.
Binaries
Shader language server
This library is used in a language server as shader-language-server.
Shader intrinsic parser
This library is used to parse intrinsic language documentations with shader-intrinsic-parser.
Example
You can find example of the library here.
Build for WASI
The library can be built using WASI for web 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 also 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 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
~51MB
~1M SLoC