Skip to content

Commit

Permalink
Merge branch 'shader-slang:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
obhi-d authored Nov 30, 2024
2 parents a72f926 + 136c2e2 commit bf474bb
Show file tree
Hide file tree
Showing 86 changed files with 786 additions and 458 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/check-toc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Check Table of Contents (comment /regenerate-toc to auto-fix)

on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
check-formatting:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: ./docs/build_toc.sh --check-only
82 changes: 82 additions & 0 deletions .github/workflows/regenerate-toc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Regenerate TOC
on:
repository_dispatch:
types: [regenerate-toc-command]
jobs:
regenerate-toc:
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
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 }}
path: pr-branch

- name: Checkout target branch
uses: actions/checkout@v4
with:
token: ${{ secrets.SLANGBOT_PAT }}
repository: ${{ github.event.client_payload.pull_request.base.repo.full_name }}
ref: ${{ github.event.client_payload.pull_request.base.ref }}
path: target-branch

- name: Regenerate Table of Contents
id: regen
run: |
./target-branch/docs/build_toc.sh --source ./pr-branch
- name: Configure Git commit signing
id: git-info
run: |
echo "${{ secrets.SLANGBOT_SIGNING_KEY }}" > "${{runner.temp}}"/signing_key
chmod 600 "${{runner.temp}}"/signing_key
git -C pr-branch config commit.gpgsign true
git -C pr-branch config gpg.format ssh
git -C pr-branch config user.signingkey "${{runner.temp}}"/signing_key
bot_info=$(curl -s -H "Authorization: Bearer ${{ secrets.SLANGBOT_PAT }}" \
"https://api.github.com/user")
echo "bot_identity=$(echo $bot_info | jq --raw-output '.login + " <" + (.id|tostring) + "+" + .login + "@users.noreply.github.com>"')" >> $GITHUB_OUTPUT
echo "bot_name=$(echo $bot_info | jq --raw-output '.login')" >> $GITHUB_OUTPUT
- name: Create Pull Request
id: create-pr
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.SLANGBOT_PAT }}
path: pr-branch
commit-message: "regenerate documentation Table of Contents"
title: "Regenerate documentation ToC for PR #${{ github.event.client_payload.pull_request.number }}"
body: "Automated ToC generation for ${{ github.event.client_payload.pull_request.html_url }}"
committer: ${{ steps.git-info.outputs.bot_identity }}
author: ${{ steps.git-info.outputs.bot_identity }}
branch: regenerate-toc-${{ github.event.client_payload.pull_request.number }}-${{ github.event.client_payload.pull_request.head.ref }}
base: ${{ github.event.client_payload.pull_request.head.ref }}
push-to-fork: ${{ steps.git-info.outputs.bot_name }}/slang
delete-branch: true

- name: Comment on PR
uses: peter-evans/create-or-update-comment@v4
if: always()
with:
token: ${{ secrets.SLANGBOT_PAT }}
repository: ${{ github.event.client_payload.github.payload.repository.full_name }}
issue-number: ${{ github.event.client_payload.pull_request.number }}
body: |
${{
steps.regen.conclusion == 'failure'
&& format('❌ Table of Contents generation failed. Please check the [workflow run](https://github.com/{0}/actions/runs/{1})', github.repository, github.run_id)
|| (steps.create-pr.conclusion == 'failure'
&& format('❌ Failed to create regenerate ToC pull request. Please check the [workflow run](https://github.com/{0}/actions/runs/{1})', github.repository, github.run_id)
|| format('🌈 Regenerated Table of Contents, please merge the changes from [this PR]({0})', steps.create-pr.outputs.pull-request-url))
}}
- 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
5 changes: 5 additions & 0 deletions .github/workflows/slash-command-dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ jobs:
"command": "format",
"permission": "none",
"issue_type": "pull-request"
},
{
"command": "regenerate-toc",
"permission": "none",
"issue_type": "pull-request"
}
]
Expand Down
53 changes: 31 additions & 22 deletions cmake/FetchedSharedLibrary.cmake
Original file line number Diff line number Diff line change
@@ -1,35 +1,44 @@
# Helper function to download and extract an archive
function(download_and_extract archive_name url)
get_filename_component(extension ${url} EXT)
set(archive_path "${CMAKE_CURRENT_BINARY_DIR}/${archive_name}${extension}")
set(extract_dir "${CMAKE_CURRENT_BINARY_DIR}/${archive_name}")
cmake_path(GET url FILENAME filename_with_ext)
cmake_path(GET url STEM LAST_ONLY file_stem)
set(archive_path "${CMAKE_CURRENT_BINARY_DIR}/${filename_with_ext}")
set(extract_dir "${CMAKE_CURRENT_BINARY_DIR}/${file_stem}")

if(EXISTS ${url})
message(STATUS "Using local file for ${archive_name}: ${url}")
set(archive_path ${url})
# Check if already extracted
file(GLOB EXTRACT_DIR_CONTENTS "${extract_dir}/*")
if(EXTRACT_DIR_CONTENTS)
message(STATUS "Using existing extracted files in ${extract_dir}")
else()
message(STATUS "Fetching ${archive_name} from ${url}")
file(
DOWNLOAD ${url} ${archive_path}
# SHOW_PROGRESS
STATUS status
)

list(GET status 0 status_code)
list(GET status 1 status_string)
if(NOT status_code EQUAL 0)
# Check if archive already exists
if(EXISTS ${url})
message(STATUS "Using local file for ${archive_name}: ${url}")
set(archive_path ${url})
elseif(EXISTS ${archive_path})
message(
WARNING
"Failed to download ${archive_name} from ${url}: ${status_string}"
STATUS
"Using existing archive for ${archive_name}: ${archive_path}"
)
return()
else()
message(STATUS "Fetching ${archive_name} from ${url}")
file(DOWNLOAD ${url} ${archive_path} STATUS status)

list(GET status 0 status_code)
list(GET status 1 status_string)
if(NOT status_code EQUAL 0)
message(
WARNING
"Failed to download ${archive_name} from ${url}: ${status_string}"
)
return()
endif()
endif()
endif()

file(ARCHIVE_EXTRACT INPUT ${archive_path} DESTINATION ${extract_dir})
file(ARCHIVE_EXTRACT INPUT ${archive_path} DESTINATION ${extract_dir})
message(STATUS "${archive_name} extracted to ${extract_dir}")
endif()

set(${archive_name}_SOURCE_DIR ${extract_dir} PARENT_SCOPE)
message(STATUS "${archive_name} downloaded and extracted to ${extract_dir}")
endfunction()

# Add rules to copy & install shared library of name 'library_name' in the 'module_subdir' directory.
Expand Down
6 changes: 3 additions & 3 deletions docs/64bit-type-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Slang 64-bit Type Support
* 64 bit integers generally require later APIs/shader models
* When specifying 64 bit literals *always* use the type suffixes (ie `L`, `ULL`, `LL`)
* GPU target/s generally do not support all double intrinsics
* Typically missing are trascendentals (sin, cos etc), logarithm and exponental functions
* Typically missing are trascendentals (sin, cos etc), logarithm and exponential functions
* CUDA is the exception supporting nearly all double intrinsics
* D3D
* D3D targets *appear* to support double intrinsics (like sin, cos, log etc), but behind the scenes they are actually being converted to float
Expand All @@ -26,7 +26,7 @@ The Slang language supports 64 bit built in types. Such as

This also applies to vector and matrix versions of these types.

Unfortunately if a specific target supports the type or the typical HLSL instrinsic functions (such as sin/cos/max/min etc) depends very much on the target.
Unfortunately if a specific target supports the type or the typical HLSL intrinsic functions (such as sin/cos/max/min etc) depends very much on the target.

Special attention has to be made with respect to literal 64 bit types. By default float and integer literals if they do not have an explicit suffix are assumed to be 32 bit. There is a variety of reasons for this design choice - the main one being around by default behavior of getting good performance. The suffixes required for 64 bit types are as follows

Expand Down Expand Up @@ -107,7 +107,7 @@ On dxc the following intrinsics are available with double::

These are tested in the test `tests/hlsl-intrinsic/scalar-double-d3d-intrinsic.slang`.

There is no suport for transcendentals (`sin`, `cos` etc) or `log`/`exp`. More surprising is that`sqrt`, `rsqrt`, `frac`, `ceil`, `floor`, `trunc`, `step`, `lerp`, `smoothstep` are also not supported.
There is no support for transcendentals (`sin`, `cos` etc) or `log`/`exp`. More surprising is that `sqrt`, `rsqrt`, `frac`, `ceil`, `floor`, `trunc`, `step`, `lerp`, `smoothstep` are also not supported.

uint64_t and int64_t Support
============================
Expand Down
2 changes: 1 addition & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ The [target compatibility guide](target-compatibility.md) gives an overview of f

The [CPU target guide](cpu-target.md) gives information on compiling Slang or C++ source into shared libraries/executables or functions that can be directly executed. It also covers how to generate C++ code from Slang source.

The [CUDA target guide](cuda-target.md) provides information on compiling Slang/HLSL or CUDA source. Slang can compile to equivalent CUDA source, as well as to PTX via the nvrtc CUDA complier.
The [CUDA target guide](cuda-target.md) provides information on compiling Slang/HLSL or CUDA source. Slang can compile to equivalent CUDA source, as well as to PTX via the nvrtc CUDA compiler.

Contributors
------------
Expand Down
127 changes: 127 additions & 0 deletions docs/build_toc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
#!/usr/bin/env bash
set -e

script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
project_root="$(dirname "$script_dir")"
check_only=0

show_help() {
me=$(basename "$0")
cat <<EOF
$me: Build table of contents for documentation directories
Usage: $me [--help] [--source <path>] [--check-only]
Options:
--help Show this help message
--source Path to project root directory (defaults to parent of the script directory)
--check-only Check if TOC needs updating, exit 1 if changes needed
EOF
}

while [[ "$#" -gt 0 ]]; do
case $1 in
-h | --help)
show_help
exit 0
;;
--source)
project_root="$2"
shift
;;
--check-only)
check_only=1
;;
*)
echo "unrecognized argument: $1" >&2
show_help >&2
exit 1
;;
esac
shift
done

missing_bin=0

require_bin() {
local name="$1"
if ! command -v "$name" &>/dev/null; then
echo "This script needs $name, but it isn't in \$PATH" >&2
missing_bin=1
return
fi
}

require_bin "mcs"
require_bin "mono"

if [ "$missing_bin" -eq 1 ]; then
exit 1
fi

temp_dir=$(mktemp -d)
trap 'rm -rf "$temp_dir"' EXIT

docs_dir="$project_root/docs"

cat >"$temp_dir/temp_program.cs" <<EOL
$(cat "$script_dir/scripts/Program.cs")
namespace toc
{
class Program
{
static int Main(string[] args)
{
if (args.Length < 1)
{
Console.WriteLine("Please provide a directory path");
return 1;
}
try
{
Builder.Run(args[0]);
return 0;
}
catch (Exception ex)
{
Console.WriteLine(\$"Error: {ex.Message}");
return 1;
}
}
}
}
EOL

if ! mcs -r:System.Core "$temp_dir/temp_program.cs" -out:"$temp_dir/toc-builder.exe"; then
echo "Compilation of $script_dir/scripts/Program.cs failed" >&2
exit 1
fi

for dir in "user-guide" "gfx-user-guide"; do
if [ -d "$docs_dir/$dir" ]; then
if [ "$check_only" -eq 1 ]; then
# Ensure working directory is clean
if ! git -C "$project_root" diff --quiet "docs/$dir/toc.html" 2>/dev/null; then
echo "Working directory not clean, cannot check TOC" >&2
exit 1
fi
fi

if ! mono "$temp_dir/toc-builder.exe" "$docs_dir/$dir"; then
echo "TOC generation failed for $dir" >&2
exit 1
fi

if [ "$check_only" -eq 1 ]; then
if ! git -C "$project_root" diff --quiet "docs/$dir/toc.html" 2>/dev/null; then
git -C "$project_root" diff --color "docs/$dir/toc.html"
git -C "$project_root" checkout -- "docs/$dir/toc.html" 2>/dev/null
exit 1
fi
fi
else
echo "Directory $dir not found" >&2
fi
done
8 changes: 4 additions & 4 deletions docs/cpu-target.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ The global can now be set from host code via
}
```
In terms of reflection `__global` variables are not visibile.
In terms of reflection `__global` variables are not visible.
## NativeString
Expand All @@ -309,7 +309,7 @@ TODO(JS): What happens with String with shader compile style on CPU? Shouldn't i
It is currently not possible to step into LLVM-JIT code when using [slang-llvm](#slang-llvm). Fortunately it is possible to step into code compiled via a [regular C/C++ compiler](#regular-cpp).
Below is a code snippet showing how to swich to a [regular C/C++ compiler](#regular-cpp) at runtime.
Below is a code snippet showing how to switch to a [regular C/C++ compiler](#regular-cpp) at runtime.
```C++
SlangPassThrough findRegularCppCompiler(slang::IGlobalSession* slangSession)
Expand Down Expand Up @@ -401,7 +401,7 @@ struct ComputeVaryingInput

`ComputeVaryingInput` allows specifying a range of groupIDs to execute - all the ids in a grid from startGroup to endGroup, but not including the endGroupIDs. Most compute APIs allow specifying an x,y,z extent on 'dispatch'. This would be equivalent as having startGroupID = { 0, 0, 0} and endGroupID = { x, y, z }. The exported function allows setting a range of groupIDs such that client code could dispatch different parts of the work to different cores. This group range mechanism was chosen as the 'default' mechanism as it is most likely to achieve the best performance.

There are two other functions that consist of the entry point name postfixed with `_Thread` and `_Group`. For the entry point 'computeMain' these functions would be accessable from the shared library interface as `computeMain_Group` and `computeMain_Thread`. `_Group` has the same signature as the listed for computeMain, but it doesn't execute a range, only the single group specified by startGroupID (endGroupID is ignored). That is all of the threads within the group (as specified by `[numthreads]`) will be executed in a single call.
There are two other functions that consist of the entry point name postfixed with `_Thread` and `_Group`. For the entry point 'computeMain' these functions would be accessible from the shared library interface as `computeMain_Group` and `computeMain_Thread`. `_Group` has the same signature as the listed for computeMain, but it doesn't execute a range, only the single group specified by startGroupID (endGroupID is ignored). That is all of the threads within the group (as specified by `[numthreads]`) will be executed in a single call.

It may be desirable to have even finer control of how execution takes place down to the level of individual 'thread's and this can be achieved with the `_Thread` style. The signature looks as follows

Expand Down Expand Up @@ -566,7 +566,7 @@ It may be useful to be able to include `slang-cpp-types.h` in C++ code to access

Would wrap all the Slang prelude types in the namespace `CPPPrelude`, such that say a `StructuredBuffer<int32_t>` could be specified in C++ source code as `CPPPrelude::StructuredBuffer<int32_t>`.

The code that sets up the prelude for the test infrastucture and command line usage can be found in ```TestToolUtil::setSessionDefaultPrelude```. Essentially this determines what the absolute path is to `slang-cpp-prelude.h` is and then just makes the prelude `#include "the absolute path"`.
The code that sets up the prelude for the test infrastructure and command line usage can be found in ```TestToolUtil::setSessionDefaultPrelude```. Essentially this determines what the absolute path is to `slang-cpp-prelude.h` is and then just makes the prelude `#include "the absolute path"`.

The *default* prelude is set to the contents of the files for C++ held in the prelude directory and is held within the Slang shared library. It is therefore typically not necessary to distribute Slang with prelude files.

Expand Down
Loading

0 comments on commit bf474bb

Please sign in to comment.