https://github.com/dimforge/slang-hal
Slang for Scientific Computing
https://github.com/dimforge/slang-hal
Last synced: 7 days ago
JSON representation
Slang for Scientific Computing
- Host: GitHub
- URL: https://github.com/dimforge/slang-hal
- Owner: dimforge
- License: apache-2.0
- Created: 2025-06-14T13:11:03.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2026-02-23T13:50:03.000Z (17 days ago)
- Last Synced: 2026-03-03T09:33:22.093Z (9 days ago)
- Language: Rust
- Size: 82 KB
- Stars: 11
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE-APACHE.txt
Awesome Lists containing this project
README
# slang-hal - A hardware abstraction for Slang
The **slang-hal** library provides abstractions for running slang shaders on any platform supported by the slang compiler.
> **Warning**
> **slang-hal** is still very incomplete and under heavy development and is lacking a lot of features and backends.
### Using Slang
In order to compile and run any slang project, be sure to define the `SLANG_DIR` environment variable:
1. Download the Slang compiler libraries for your platform:
2. Unzip the downloaded directory, and use its path as value to the `SLANG_DIR` environment variable: `SLANG_DIR=/path/to/slang`.
Note that the variable must point to the root of the slang installation (i.e. the directory that contains `bin` and `lib`).
We recommend adding that as a system-wide environment variables so that it also becomes available to your IDE.
### Supported backends
**slang-hal** exposes a unified API for interacting with the GPU in a backend-agnostic way.
| Backend | Shader compilation | Compute pipelines | Render pipelines | Buffer read/write | Non-Pod types | Indirect dispatch | GPU timestamps | Link-time specialization | Comptime |
|---------|--------------------|-------------------|------------------|---------------------|---------------|-------------------|----------------|------------------------|----------|
| WebGpu | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ |
| Cuda | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ |
| Vulkan | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | |
| Metal | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | |
| DirectX | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | |
| CPU | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | |
| PyTorch | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | |
| OptiX | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | |
| OpenCL | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | |
### Other features
**slang-hal** also provides utilities for:
- Writing device-side gpu code in a backend-agnostic way, with the ability to reuse the same code on multiple backend
even within the same executable.
- Sharing Slang shaders across Rust crates (directly through `cargo`. No need to deal with include paths).
- Checking slang shader validity at compile-time (i.e. when running `cargo build`, `cargo check`, etc.)
- Generating boilerplate and helper functions for loading a shader from Rust and launching its compute pipeline.