Skip to content

Commit

Permalink
Merge branch 'master' into doc
Browse files Browse the repository at this point in the history
  • Loading branch information
csyonghe authored Oct 28, 2024
2 parents b3241a8 + 0432907 commit b2c9e72
Show file tree
Hide file tree
Showing 97 changed files with 2,156 additions and 756 deletions.
46 changes: 7 additions & 39 deletions .github/actions/common-setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,55 +73,23 @@ runs:
echo "bin_dir=$bin_dir" >> "$GITHUB_ENV"
echo "lib_dir=$lib_dir" >> "$GITHUB_ENV"
# Try to restore a LLVM build cache, and build it otherwise
- name: "Restore cache (attempt: 1/2)"
uses: actions/cache/restore@v4
# Try to restore an LLVM install, and build it otherwise
- uses: actions/cache/restore@v4
id: cache-llvm
if: inputs.build-llvm == 'true'
with:
path: ${{ github.workspace }}/build/llvm-project-install
# Use os*compiler*platform in lieu of an ABI key here, which is what we really want
key: llvm-${{ inputs.os }}-${{ inputs.compiler }}-${{ inputs.platform }}-${{ hashFiles('external/build-llvm.sh') }}

# Checkout while waiting for the second try of restoring the cache
- name: Checkout LLVM project if restore cache failed
uses: actions/checkout@v4
id: checkout-llvm
if: inputs.build-llvm == 'true' && steps.cache-llvm.outputs.cache-hit != 'true'
with:
#repository: llvm/llvm-project
repository: shader-slang/llvm-project
ref: llvmorg-13.0.1
path: build/llvm-source
fetch-depth: '1'
fetch-tags: true

# Once the cache server is busy, it usually becomes busy for awhile.
# The second attempt here is more likely to fail again.
# But the overhead of retry is very low, and let's try after spending some time checking out LLVM repo.
- name: "Restore cache (attempt: 2/2)"
uses: actions/cache/restore@v4
id: cache-llvm-2
if: inputs.build-llvm == 'true' && steps.cache-llvm.outputs.cache-hit != 'true'
with:
path: ${{ github.workspace }}/build/llvm-project-install
key: ${{ steps.cache-llvm.outputs.cache-primary-key }}

# Build LLVM only if all attempts of the restoring the cache failed.
- name: Build LLVM
id: build-llvm
if: steps.checkout-llvm.outcome == 'success' && steps.cache-llvm-2.outputs.cache-hit != 'true'
if: inputs.build-llvm == 'true' && steps.cache-llvm.outputs.cache-hit != 'true'
shell: bash
run: |
./external/build-llvm.sh \
--install-prefix "${{ github.workspace }}/build/llvm-project-install" \
--repo "${{github.workspace}}/build/llvm-source" \
--branch llvmorg-13.0.1
# Save LLVM cache if the building step was successful
- name: Save LLVM cache
uses: actions/cache/save@v4
if: steps.build-llvm.outcome == 'success'
--install-prefix "${{github.workspace}}/build/llvm-project-install" \
--repo "https://${{github.token}}@github.com/llvm/llvm-project"
- uses: actions/cache/save@v4
if: inputs.build-llvm == 'true' && steps.cache-llvm.outputs.cache-hit != 'true'
with:
path: ${{ github.workspace }}/build/llvm-project-install
key: ${{ steps.cache-llvm.outputs.cache-primary-key }}
Expand Down
49 changes: 49 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Format
on:
repository_dispatch:
types: [format-command]
jobs:
format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.SLANGBOT_PAT }}
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}
ref: ${{ github.event.client_payload.pull_request.head.ref }}

- run: pip3 install gersemi

- name: install clang-format
run: |
tmpdir=$(mktemp -d)
curl -L -H "Authorization: token ${{ secrets.SLANGBOT_PAT }}" \
-o "$tmpdir/clang-format" \
https://github.com/shader-slang/slang-binaries/raw/4e88845ec51641b4c92e68027e359090bdb219e0/clang-format/x86_64-linux/bin/clang-format
chmod +x "$tmpdir/clang-format"
echo "$tmpdir" >> $GITHUB_PATH
- run: ./extras/formatting.sh

- name: Configure Git commit signing
run: |
echo "${{ secrets.SLANGBOT_SIGNING_KEY }}" > "${{runner.temp}}"/signing_key
chmod 600 "${{runner.temp}}"/signing_key
git config commit.gpgsign true
git config gpg.format ssh
git config user.signingkey "${{runner.temp}}"/signing_key
- uses: EndBug/add-and-commit@v9
with:
fetch: false
message: "format code"
push: true

- name: Add reaction
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.SLANGBOT_PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
reactions-edit-mode: replace
reactions: hooray
31 changes: 31 additions & 0 deletions .github/workflows/slash-command-dispatch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Slash Command Dispatch
on:
issue_comment:
types: [created]
jobs:
slashCommandDispatch:
runs-on: ubuntu-latest
steps:
- name: Slash Command Dispatch
id: scd
uses: peter-evans/slash-command-dispatch@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
reaction-token: ${{ secrets.SLANGBOT_PAT }}
config: >
[
{
"command": "format",
"permission": "none",
"issue_type": "pull-request"
}
]
- name: Edit comment with error message
if: steps.scd.outputs.error-message
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.SLANGBOT_PAT }}
comment-id: ${{ github.event.comment.id }}
body: |
> ${{ steps.scd.outputs.error-message }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ prelude/*.h.cpp
/docs/Gemfile.lock
/docs/Gemfile
/docs/stdlib-reference
/source/slang/slang-stdlib-generated.h
/source/slang/slang-core-module-generated.h

/examples/heterogeneous-hello-world/shader.cpp
/multiple-definitions.hlsl
Expand Down
8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ auto_option(
advanced_option(SLANG_ENABLE_DX_ON_VK "Use dxvk and vkd3d-proton for DirectX support" OFF)
advanced_option(SLANG_ENABLE_SLANG_RHI "Use slang-rhi as dependency" ON)

option(SLANG_EMBED_STDLIB_SOURCE "Embed stdlib source in the binary" ON)
option(SLANG_EMBED_STDLIB "Build slang with an embedded version of the stdlib")
option(SLANG_EMBED_CORE_MODULE_SOURCE "Embed core module source in the binary" ON)
option(SLANG_EMBED_CORE_MODULE "Build slang with an embedded version of the core module")

option(SLANG_ENABLE_FULL_IR_VALIDATION "Enable full IR validation (SLOW!)")
option(SLANG_ENABLE_IR_BREAK_ALLOC, "Enable _debugUID on IR allocation")
Expand Down Expand Up @@ -201,10 +201,10 @@ endif()
# Option validation
#

if(NOT SLANG_EMBED_STDLIB AND NOT SLANG_EMBED_STDLIB_SOURCE)
if(NOT SLANG_EMBED_CORE_MODULE AND NOT SLANG_EMBED_CORE_MODULE_SOURCE)
message(
SEND_ERROR
"One of SLANG_EMBED_STDLIB and SLANG_EMBED_STDLIB_SOURCE must be enabled"
"One of SLANG_EMBED_CORE_MODULE and SLANG_EMBED_CORE_MODULE_SOURCE must be enabled"
)
endif()

Expand Down
43 changes: 28 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,43 @@ Slang
Slang is a shading language that makes it easier to build and maintain large shader codebases in a modular and extensible fashion, while also maintaining the highest possible performance on modern GPUs and graphics APIs.
Slang is based on years of collaboration between researchers at NVIDIA, Carnegie Mellon University, Stanford, MIT, UCSD and the University of Washington.

Key Features
------------

The Slang system is designed to provide developers of real-time graphics applications with the services they need when working with shader code.
Why Slang?
---------------

The Slang shading language is designed to enable real-time graphics developers to work with large-scale, high-performance shader code.

### Write Shaders Once, Run Anywhere

The Slang compiler can generate code for a wide variety of targets: D3D12, Vulkan, Metal, D3D11, OpenGL, CUDA, and even generate code to run on a CPU. For textual targets, such as Metal Shading Language (MSL) and CUDA, Slang produces readable code that preserves original identifier names, as well as the type and call structure, making it easier to debug.

### Access the Latest GPU Features

Slang code is highly portable, but can still leverage unique platform capabilities, including the latest features in Direct3D and Vulkan. For example, developers can make full use of [pointers](https://shader-slang.com/slang/user-guide/convenience-features.html#pointers-limited) when generating SPIR-V.
Slang's [capability system](https://shader-slang.com/slang/user-guide/capabilities.html) helps applications manage feature set differences across target platforms by ensuring code only uses available features during the type-checking step, before generating final code. Additionally, Slang provides [flexible interop](https://shader-slang.com/slang/user-guide/a1-04-interop.html) features to enable directly embedding target code or SPIR-V into generated shaders.

### Leverage Neural Graphics with Automatic Differentiation

* Slang is backwards-compatible with most existing HLSL code. It is possible to start taking advantage of Slang's benefits without rewriting or porting your shader codebase.
Slang can [automatically generate both forward and backward derivative propagation code](https://shader-slang.com/slang/user-guide/autodiff.html) for complex functions that involve arbitrary control flow and dynamic dispatch. This allows existing rendering codebases to easily become differentiable, or for Slang to serve as the kernel language in a PyTorch-driven machine learning framework via [`slangtorch`](https://shader-slang.com/slang/user-guide/a1-02-slangpy.html).

* The Slang compiler can generate code for a wide variety of targets and APIs: D3D12, Vulkan, Metal, D3D11, OpenGL, CUDA, and CPU. Slang code can be broadly portable, but still take advantage of the unique features of each platform. For textual targets such as Metal Shading Language(MSL) and CUDA, Slang generates readable code that preserves the original identifier names and the type + call structure for ease of debugging.
### Scalable Software Development with Modules

* [Automatic differentiation](https://shader-slang.com/slang/user-guide/autodiff.html) as a first-class language feature. Slang can automatically generate both forward and backward derivative propagation code for complex functions that involve arbitrary control flow and dynamic dispatch. This allows users to easily make existing rendering codebases differentiable, or to use Slang as the kernel language in a PyTorch driven machine learning framework via [`slangtorch`](https://shader-slang.com/slang/user-guide/a1-02-slangpy.html).
Slang provides a [module system](https://shader-slang.com/slang/user-guide/modules.html) that enables logical organization of code for separate compilation. Slang modules can be independently compiled offline to a custom IR (with optional obfuscation) and then linked at runtime to generate code in formats such as DXIL or SPIR-V.

* Generics and interfaces allow shader specialization to be expressed cleanly without resort to preprocessor techniques or string-pasting. Unlike C++ templates, Slang's generics are checked ahead of time and don't produce cascading error messages that are difficult to diagnose. The same generic shader can be specialized for a variety of different types to produce specialized code ahead of time, or on the fly, completely under application control.
### Code Specialization that Works with Modules

* Slang provides a module system that can be used to logically organize code and benefit from separate compilation. Slang modules can be compiled offline to a custom IR (with optional obfuscation) and then linked at runtime to generate DXIL, SPIR-V etc.
Slang supports [generics and interfaces](https://shader-slang.com/slang/user-guide/interfaces-generics.html) (a.k.a. type traits/protocols), allowing for clear expression of shader specialization without the need for preprocessor techniques or string-pasting. Unlike C++ templates, Slang's generics are pre-checked and don't produce cascading error messages that are difficult to diagnose. The same generic shader can be specialized for a variety of different types to produce specialized code ahead of time, or on the fly, entirely under application control.

* Parameter blocks (exposed as `ParameterBlock<T>`) provide a first-class language feature for grouping related shader parameters and specifying that they should be passed to the GPU as a coherent block. Parameter blocks make it easy for applications to use the most efficient parameter-binding model of each API, such as descriptor tables/sets in D3D12/Vulkan.
### Easy On-ramp for HLSL and GLSL Codebases

* Rather than require tedious explicit `register` and `layout` specifications on each shader parameter, Slang supports completely automate and deterministic assignment of binding locations to parameter. You can write simple and clean code and still get the deterministic layout your application wants.
Slang's syntax is similar to HLSL, and most existing HLSL code can be compiled with the Slang compiler out-of-the-box, or with just minor modifications. This allows existing shader codebases to immediately benefit from Slang without requiring a complete rewrite or port.

* For applications that want it, Slang provides full reflection information about the parameters of your shader code, with a consistent API across all target platforms and graphics APIs. Unlike some other compilers, Slang does not reorder or drop shader parameters based on how they are used, so you can always see the full picture.
Slang provides a compatibility module that enables the use of most GLSL intrinsic functions and GLSL's parameter binding syntax.

* Full intellisense features in Visual Studio Code and Visual Studio through the Language Server Protocol.
### Comprehensive Tooling Support

* Full debugging experience with SPIRV and RenderDoc.
Slang comes with full support of IntelliSense editing features in Visual Studio Code and Visual Studio through the Language Server Protocol.
Full debugging capabilities are also available through RenderDoc and SPIR-V based tools.

Getting Started
---------------
Expand All @@ -40,7 +53,7 @@ Slang binaries are also included in the [Vulkan SDK](https://vulkan.lunarg.com/s
There are packages built for 32- and 64-bit Windows, as well as 64-bit Ubuntu.
Each binary release includes the command-line `slangc` compiler, a shared library for the compiler, and the `slang.h` header.

If you want to try out the Slang language without installing anything, a fast and simple way is to use the [Shader Playground](docs/shader-playground.md).
If you want to try out the Slang language without installing anything, a fast and simple way is to use the [Slang Playground](https://shader-slang.com/slang-playground). The playground allows you to compile Slang code to a variety of targets, and even run some simple shaders directly within the browser. The playground loads Slang compiler to your browser and runs all compilation locally. No data will be sent to any servers.

If you would like to build Slang from source, please consult the [build instructions](docs/building.md).

Expand All @@ -49,7 +62,7 @@ Documentation

The Slang project provides a variety of different [documentation](docs/), but most users would be well served starting with the [User's Guide](https://shader-slang.github.io/slang/user-guide/).

For developers writing Slang code, the [Slang Standard Library Reference](https://shader-slang.com/stdlib-reference/) provides detailed documentation on Slang's built-in types and functions.
For developers writing Slang code, the [Slang Core Module Reference](https://shader-slang.com/stdlib-reference/) provides detailed documentation on Slang's built-in types and functions.

We also provide a few [examples](examples/) of how to integrate Slang into a rendering application.

Expand Down
8 changes: 4 additions & 4 deletions docs/build_reference.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# This script uses `slangc` to generate stdlib reference documentation and push the updated
# This script uses `slangc` to generate the core module reference documentation and push the updated
# documents to shader-slang/stdlib-reference repository.
# The stdlib-reference repository has github-pages setup so that the markdown files we generate
# in this step will be rendered as html pages by Jekyll upon a commit to the repository.
Expand Down Expand Up @@ -33,12 +33,12 @@ Remove-Item -Path ".\stdlib-reference\attributes" -Recurse -Force
git describe --tags | Out-File -FilePath ".\stdlib-reference\_includes\version.inc" -Encoding ASCII

cd stdlib-reference
& ../../build/Release/bin/slangc -compile-stdlib -doc
& ../../build/Release/bin/slangc -compile-core-module -doc
Move-Item -Path ".\toc.html" -Destination ".\_includes\stdlib-reference-toc.html" -Force
git config user.email "[email protected]"
git config user.name "Stdlib Reference Bot"
git add .
git commit -m "Update stdlib reference"
git commit -m "Update the core module reference"
git push
cd ../

Expand All @@ -49,4 +49,4 @@ cd ../
# Copy-Item -Path .\stdlib-reference\global-decls -Destination D:\git_repo\stdlib-reference\global-decls -Recurse -Force
# Copy-Item -Path .\stdlib-reference\interfaces -Destination D:\git_repo\stdlib-reference\interfaces -Recurse -Force
# Copy-Item -Path .\stdlib-reference\types -Destination D:\git_repo\stdlib-reference\types -Recurse -Force
# Copy-Item -Path .\stdlib-reference\_includes\stdlib-reference-toc.html -Destination D:\git_repo\stdlib-reference\_includes\stdlib-reference-toc.html -Force
# Copy-Item -Path .\stdlib-reference\_includes\stdlib-reference-toc.html -Destination D:\git_repo\stdlib-reference\_includes\stdlib-reference-toc.html -Force
4 changes: 2 additions & 2 deletions docs/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ See the [documentation on testing](../tools/slang-test/README.md) for more infor
| Option | Default | Description |
|-----------------------------------|----------------------------|----------------------------------------------------------------------------------------------|
| `SLANG_VERSION` | Latest `v*` tag | The project version, detected using git if available |
| `SLANG_EMBED_STDLIB` | `FALSE` | Build slang with an embedded version of the stdlib |
| `SLANG_EMBED_STDLIB_SOURCE` | `TRUE` | Embed stdlib source in the binary |
| `SLANG_EMBED_CORE_MODULE` | `FALSE` | Build slang with an embedded version of the core module |
| `SLANG_EMBED_CORE_MODULE_SOURCE` | `TRUE` | Embed the core module source in the binary |
| `SLANG_ENABLE_ASAN` | `FALSE` | Enable ASAN (address sanitizer) |
| `SLANG_ENABLE_FULL_IR_VALIDATION` | `FALSE` | Enable full IR validation (SLOW!) |
| `SLANG_ENABLE_IR_BREAK_ALLOC` | `FALSE` | Enable IR BreakAlloc functionality for debugging. |
Expand Down
2 changes: 1 addition & 1 deletion docs/cpu-target.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ The `shader` style implies

* The code *can* be executed in a GPU-kernel like execution model, launched across multiple threads (as described in the [ABI](#abi))
* Currently no reference counting
* Only functionality from the Slang stdlib, built in HLSL or anything supplied by a [COM interfaces](#com-interface) is available
* Only functionality from the Slang core module, built in HLSL or anything supplied by a [COM interfaces](#com-interface) is available
* Currently [slang-llvm](#slang-llvm) only supports the `shader` style

The `host` style implies
Expand Down
Loading

0 comments on commit b2c9e72

Please sign in to comment.