HXSL (HexaEngine Shading Language) is a modern shading language designed as a more flexible, readable, and user-friendly alternative to HLSL (High-Level Shading Language). Built with features like user-defined operators, member functions, and namespace support, HXSL enhances the shader programming experience by providing additional syntactical sugar. The goal is to improve developer productivity and code maintainability while keeping performance and compatibility with graphics hardware.
Currently, HXSL is in the Intermediate Language (IL) Optimization stage of development. The frontend (lexer, parser, semantic analyzer) and the middle-end (IL generation, SSA conversion, and optimizations) are complete. Active work is now focused on backend code generation.
- HLSL-inspired syntax: HXSL takes inspiration from HLSL, making it familiar to developers with experience in DirectX shader programming.
- User-defined Operators: Allows for the creation of custom operators for greater expressiveness and readability in shader code.
- Member Functions: Supports defining functions within structures and types, improving modularity and code reuse.
- Namespaces and Usings: Removes the need for
#includedirectives, allowing for better organization and cleaner code. - C API: A C API is available for integration with other languages like C#.
The compiler is structured into the following stages:
- Preprocessing: Macro expansion and preprocessor directive handling.
- Lexical Analysis: Tokenization of HXSL source code.
- Parsing: Full parsing support for declarations, expressions, and statements using a hybrid Pratt parser.
- Semantic Analysis: Complete type checking, symbol resolution, and expression validation.
- IL Generation: Conversion of the AST to an intermediate representation (Module Builder).
- Control Flow Analysis: Construction and analysis of control flow graphs.
- SSA Conversion: Static Single Assignment form conversion for optimization.
- IL Optimizations:
- Constant Folding
- Algebraic Simplification
- Common Subexpression Elimination
- Dead Code Elimination
- Strength Reduction
- Function Inlining
- Backend Code Generation: Implementation of code generation targeting HLSL, GLSL, and SPIR-V.
- Cross-compilation: HXSL will be transpiled to HLSL, with plans to extend support for generating GLSL and SPIR-V, enabling wider compatibility across different platforms and graphics APIs.
- Extended Language Features: More language features and optimizations will be added as development progresses.
- HXSL uses the C++20 standard library.
Refer to the documentation or your specific use cases for syntax examples. (Being worked on)
Build the HXSLGui CMake target and launch the executable from the build's
gui directory. The GUI uses the bundled Dear ImGui and GLFW submodules and
requires OpenGL. For a command-line-only build, configure with -DBUILD_GUI=OFF.
Choose Load bundled example or supply one source file path per line. To compile against other assemblies, enter their paths under Reference assemblies. Set the output path and, optionally, the entry point, then choose Compile. A successful compile replaces an existing output assembly. Relative paths are resolved from the application's working directory.
Open Source editor and select a file from the source list to edit it. Save writes your changes to that file. Save the edits before compiling, or choose Discard edits to reload the version on disk. Loading the bundled example opens its source in the editor.
Diagnostics shows compiler messages. Assembly IL shows the executable IL read back from the generated assembly and marks the entry point. Compiler trace shows intermediate compiler output, including optimizer pass dumps in Debug builds. Each tab displays numbered, color-coded lines with search and clipboard copying.
Compile with an entry point, then open Interpreter to run that assembly.
Enter space-separated scalar arguments and choose Run. For the bundled
example, entering 5 returns 15. The GUI limits each run to one million IL
instructions and 128 call frames so runaway shaders stop with an error.
We welcome contributions! If you would like to help improve HXSL, feel free to open an issue or submit a pull request. Here's how you can contribute:
-
Fork the repository.
-
Clone your fork locally:
git clone https://github.com/HexaEngine/HexaEngine.ShaderLang.git
-
Create a new branch for your feature or bug fix.
-
Commit your changes and push them to your fork.
-
Open a pull request to propose your changes.
This project is licensed under the MIT License. See the LICENSE file for more details.