Skip to content

Commit bd5d5c4

Browse files
authored
Merge branch 'master' into cheneym2/harmless2
2 parents c6c38b0 + 78a6389 commit bd5d5c4

12 files changed

+220
-2
lines changed

CONTRIBUTING.md

+11
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ Or you can build with the following command:
9393
C:\git\slang> cmake.exe --build --preset release
9494
```
9595

96+
On Windows ARM64, prebuilt binaries for LLVM isn't available.
97+
Please build Slang without LLVM dependency by running:
98+
99+
```
100+
cmake.exe --preset vs2022 -DSLANG_SLANG_LLVM_FLAVOR=DISABLE
101+
```
102+
103+
during configuration step.
104+
96105
#### Linux
97106
Install CMake and Ninja.
98107
```
@@ -136,6 +145,8 @@ Follow the instructions below if you wish to build `slang-llvm` locally.
136145
$ external/build-llvm.sh --source-dir build/slang-llvm_src --install-prefix build/slang-llvm_install
137146
```
138147

148+
> Note: On Windows you can use `external/build-llvm.ps1` in Powershell.
149+
139150
You need to use the following command to regenerate the Makefile:
140151
```
141152
$ cmake --preset default --fresh -DSLANG_SLANG_LLVM_FLAVOR=USE_SYSTEM_LLVM -DLLVM_DIR=build/slang-llvm_install/lib/cmake/llvm -DClang_DIR=build/slang-llvm_install/lib/cmake/clang

examples/stacktrace-windows/common.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ static bool printStack(FILE* file, HANDLE process, HANDLE thread, CONTEXT const&
7474
{
7575
#if defined(_M_AMD64)
7676
DWORD constexpr machineType = IMAGE_FILE_MACHINE_AMD64;
77+
#elif defined(_M_ARM64)
78+
DWORD constexpr machineType = IMAGE_FILE_MACHINE_ARM64;
7779
#else
7880
#error Unsupported machine type
7981
#endif

external/build-llvm.ps1

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
# PowerShell script to fetch, build, and install LLVM for Slang
2+
3+
# Set script to fail on errors
4+
$ErrorActionPreference = "Stop"
5+
6+
function Show-Help {
7+
Write-Host "Fetch, build and install LLVM for Slang
8+
9+
Options:
10+
--repo: The source git repo, default: $repo
11+
--branch: The branch (or tag) to fetch, default: $branch
12+
--source-dir: Unpack and build in this directory: default $source_dir
13+
--config: The configuration to build, default $config
14+
--install-prefix: Install under this prefix
15+
--: Any following arguments will be passed to the CMake configuration command
16+
"
17+
}
18+
19+
function Msg {
20+
Write-Host "$args" -ForegroundColor Yellow
21+
}
22+
23+
function Fail {
24+
Msg "$args"
25+
exit 1
26+
}
27+
28+
function New-TemporaryDirectory {
29+
$tmp = [System.IO.Path]::GetTempPath() # Not $env:TEMP, see https://stackoverflow.com/a/946017
30+
$name = (New-Guid).ToString("N")
31+
New-Item -ItemType Directory -Path (Join-Path $tmp $name)
32+
}
33+
34+
# Check if required programs are available
35+
$requiredPrograms = "cmake", "git"
36+
foreach ($prog in $requiredPrograms) {
37+
if (-not (Get-Command $prog -ErrorAction SilentlyContinue)) {
38+
Msg "This script needs $prog, but it isn't in PATH"
39+
$missingBin = $true
40+
}
41+
}
42+
if ($missingBin) {
43+
exit 1
44+
}
45+
46+
# Temp directory with cleanup on exit
47+
$tempDir = New-TemporaryDirectory
48+
$cleanup = {
49+
if ($tempDir) {
50+
Remove-Item -Recurse -Force $tempDir
51+
}
52+
exit $lastExitCode
53+
}
54+
$null = Register-EngineEvent PowerShell.Exiting -Action $cleanup
55+
56+
# Default values
57+
$repo = "https://github.com/llvm/llvm-project"
58+
$branch = "llvmorg-13.0.1"
59+
$sourceDir = $tempDir.FullName
60+
$installPrefix = ""
61+
$config = "Release"
62+
$extraArguments = @()
63+
64+
# Argument parsing
65+
for ($i = 0; $i -lt $args.Length; $i++) {
66+
switch ($args[$i]) {
67+
"--help" {
68+
Show-Help
69+
exit
70+
}
71+
"--repo" {
72+
$repo = $args[++$i]
73+
}
74+
"--branch" {
75+
$branch = $args[++$i]
76+
}
77+
"--source-dir" {
78+
$sourceDir = $args[++$i]
79+
}
80+
"--config" {
81+
$config = $args[++$i]
82+
}
83+
"--install-prefix" {
84+
$installPrefix = $args[++$i]
85+
}
86+
"--" {
87+
$extraArguments = $args[$i + 1..$args.Length]
88+
break
89+
}
90+
default {
91+
Msg "Unknown parameter passed: $($args[$i])"
92+
Show-Help
93+
exit 1
94+
}
95+
}
96+
}
97+
98+
if (-not $repo) { Fail "please set --repo" }
99+
if (-not $branch) { Fail "please set --branch" }
100+
if (-not $sourceDir) { Fail "please set --source-dir" }
101+
if (-not $config) { Fail "please set --config" }
102+
if (-not $installPrefix) { Fail "please set --install-prefix" }
103+
104+
# Fetch LLVM from the repo
105+
Msg "##########################################################"
106+
Msg "# Fetching LLVM from $repo at $branch"
107+
Msg "##########################################################"
108+
# git clone --depth 1 --branch $branch $repo $sourceDir
109+
110+
# Configure LLVM with CMake
111+
Msg "##########################################################"
112+
Msg "# Configuring LLVM in $sourceDir"
113+
Msg "##########################################################"
114+
$msvcRuntimeLib = "MultiThreaded"
115+
if ($config -eq 'Debug')
116+
{
117+
$msvcRuntimeLib = "MultiThreadedDebug"
118+
}
119+
$cmakeArgumentsForSlang = @(
120+
"-DLLVM_BUILD_LLVM_C_DYLIB=0"
121+
"-DLLVM_INCLUDE_BENCHMARKS=0"
122+
"-DLLVM_INCLUDE_DOCS=0"
123+
"-DLLVM_INCLUDE_EXAMPLES=0"
124+
"-DLLVM_INCLUDE_TESTS=0"
125+
"-DLLVM_ENABLE_TERMINFO=0"
126+
"-DCLANG_BUILD_TOOLS=0"
127+
"-DCLANG_ENABLE_STATIC_ANALYZER=0"
128+
"-DCLANG_ENABLE_ARCMT=0"
129+
"-DCLANG_INCLUDE_DOCS=0"
130+
"-DCLANG_INCLUDE_TESTS=0"
131+
"-DLLVM_ENABLE_PROJECTS=clang"
132+
"-DLLVM_TARGETS_TO_BUILD=X86;ARM;AArch64"
133+
"-DLLVM_BUILD_TOOLS=0"
134+
"-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded$<$<CONFIG:Debug>:Debug>"
135+
"-DLLVM_USE_CRT_RELEASE=MT"
136+
"-DLLVM_USE_CRT_DEBUG=MTd"
137+
)
138+
139+
$buildDir = Join-Path $sourceDir "build"
140+
New-Item -Path $buildDir -ItemType Directory -Force
141+
142+
cmake -S $sourceDir\llvm -B $buildDir $cmakeArgumentsForSlang + $extraArguments
143+
144+
# Build LLVM
145+
Msg "##########################################################"
146+
Msg "# Building LLVM in $buildDir"
147+
Msg "##########################################################"
148+
cmake --build $buildDir -j --config $config
149+
150+
# Install LLVM
151+
Msg "##########################################################"
152+
Msg "# Installing LLVM to $installPrefix"
153+
Msg "##########################################################"
154+
cmake --install $buildDir --prefix $installPrefix --config $config
155+
156+
Msg "##########################################################"
157+
Msg "LLVM installed in $installPrefix"
158+
Msg "Please add $installPrefix to CMAKE_PREFIX_PATH"
159+
Msg "##########################################################"

source/slang/slang-ir-glsl-legalize.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -3722,7 +3722,8 @@ void legalizeEntryPointForGLSL(
37223722

37233723
// Rename the entrypoint to "main" to conform to GLSL standard,
37243724
// if the compile options require us to do it.
3725-
if (!shouldUseOriginalEntryPointName(codeGenContext))
3725+
if (!shouldUseOriginalEntryPointName(codeGenContext) &&
3726+
codeGenContext->getEntryPointCount() == 1)
37263727
{
37273728
entryPointDecor->setName(builder.getStringValue(UnownedStringSlice("main")));
37283729
}

source/slang/slang-parameter-binding.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,13 @@ static void _maybeDiagnoseMissingVulkanLayoutModifier(
10731073
ParameterBindingContext* context,
10741074
DeclRef<VarDeclBase> const& varDecl)
10751075
{
1076+
// Don't warn if the declaration is a vk::push_constant or shaderRecordEXT
1077+
if (varDecl.getDecl()->hasModifier<PushConstantAttribute>() ||
1078+
varDecl.getDecl()->hasModifier<ShaderRecordAttribute>())
1079+
{
1080+
return;
1081+
}
1082+
10761083
// If the user didn't specify a `binding` (and optional `set`) for Vulkan,
10771084
// but they *did* specify a `register` for D3D, then that is probably an
10781085
// oversight on their part.

source/slang/slang-parser.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -2352,6 +2352,7 @@ static Expr* tryParseGenericApp(Parser* parser, Expr* base)
23522352
case TokenType::OpEql:
23532353
case TokenType::OpNeq:
23542354
case TokenType::OpGreater:
2355+
case TokenType::OpRsh:
23552356
case TokenType::EndOfFile:
23562357
{
23572358
return parseGenericApp(parser, base);

tests/diagnostics/vk-bindings.slang

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ struct S { float4 a; };
1414
[[vk::binding(2,1)]]
1515
ParameterBlock<S> b;
1616

17+
[[vk::push_constant]] \
18+
ConstantBuffer<int> gint : register(b0, space0);
19+
20+
layout(shaderRecordEXT) ConstantBuffer<int> GeometrySBT : register(b0, space99999);
21+
1722
[shader("compute")]
1823
void main()
19-
{}
24+
{}

tests/diagnostics/vk-bindings.slang.expected

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ Texture2D t : register(t0);
66
tests/diagnostics/vk-bindings.slang(14): error 39015: shader parameter 'b' consumes whole descriptor sets, so the binding must be in the form '[[vk::binding(0, ...)]]'; the non-zero binding '2' is not allowed
77
[[vk::binding(2,1)]]
88
^~~~~~~
9+
tests/diagnostics/vk-bindings.slang(18): warning 39001: explicit binding for parameter 'gint' overlaps with parameter 't'
10+
ConstantBuffer<int> gint : register(b0, space0);
11+
^~~~
12+
tests/diagnostics/vk-bindings.slang(6): note: see declaration of 't'
13+
Texture2D t : register(t0);
14+
^
915
}
1016
standard output = {
1117
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
//TEST_IGNORE_FILE:
2+
struct Foo<T> {}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
//TEST:SIMPLE(filecheck=CHECK): -target spirv
2+
import "generic-disambiguate-module";
3+
4+
// CHECK: OpEntryPoint
5+
6+
[numthreads(1,1,1)]
7+
void main()
8+
{
9+
var x : Foo<Foo<Foo<Foo<float>>>>; // error 20002: syntax error.
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//TEST:SIMPLE(filecheck=CHECK): -entry missShader -entry missShader2 -target spirv
2+
//TEST:SIMPLE(filecheck=CHECK): -target spirv
3+
4+
// CHECK: OpEntryPoint MissKHR %missShader "missShader"
5+
// CHECK: OpEntryPoint MissKHR %missShader2 "missShader2"
6+
7+
struct RayPayload{};
8+
[shader("miss")]
9+
void missShader(inout RayPayload payload) { }
10+
11+
[shader("miss")]
12+
void missShader2(inout RayPayload payload) { }

tools/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ if(SLANG_ENABLE_GFX)
140140
$<$<BOOL:${SLANG_ENABLE_XLIB}>:X11::X11>
141141
$<$<BOOL:${SLANG_ENABLE_CUDA}>:CUDA::cuda_driver>
142142
SPIRV-Tools-link
143+
$<$<BOOL:${SLANG_ENABLE_NVAPI}>:${NVAPI_LIBRARIES}>
143144
LINK_WITH_FRAMEWORK Foundation Cocoa QuartzCore Metal
144145
EXTRA_COMPILE_DEFINITIONS_PRIVATE
145146
$<$<BOOL:${SLANG_ENABLE_CUDA}>:GFX_ENABLE_CUDA>
@@ -154,6 +155,7 @@ if(SLANG_ENABLE_GFX)
154155
INCLUDE_DIRECTORIES_PUBLIC
155156
${slang_SOURCE_DIR}
156157
${slang_SOURCE_DIR}/include
158+
INCLUDE_DIRECTORIES_PRIVATE ${NVAPI_INCLUDE_DIRS}
157159
REQUIRES copy-gfx-slang-modules
158160
INSTALL
159161
EXPORT_SET_NAME SlangTargets

0 commit comments

Comments
 (0)