-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
309e8a5
commit 1058d53
Showing
4 changed files
with
306 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
index dc281211..c36b9bcb 100644 | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -154,6 +154,8 @@ advanced_option( | ||
"Build using system unordered dense" | ||
OFF | ||
) | ||
+advanced_option(SLANG_USE_SYSTEM_SPIRV_TOOLS "Build using system SPIR-V tools library" OFF) | ||
+advanced_option(SLANG_USE_SYSTEM_GLSLANG "Build using system glslang library" OFF) | ||
|
||
option( | ||
SLANG_SPIRV_HEADERS_INCLUDE_DIR | ||
@@ -289,6 +291,34 @@ if(${SLANG_USE_SYSTEM_UNORDERED_DENSE}) | ||
find_package(unordered_dense CONFIG QUIET) | ||
endif() | ||
|
||
+if(${SLANG_USE_SYSTEM_MINIZ}) | ||
+ find_package(miniz REQUIRED) | ||
+ add_library(miniz ALIAS miniz::miniz) | ||
+endif() | ||
+ | ||
+if(${SLANG_USE_SYSTEM_LZ4}) | ||
+ find_package(lz4 REQUIRED) | ||
+ add_library(lz4_static ALIAS LZ4::lz4) | ||
+endif() | ||
+ | ||
+if(${SLANG_USE_SYSTEM_VULKAN_HEADERS}) | ||
+ find_package(VulkanHeaders REQUIRED) | ||
+endif() | ||
+ | ||
+if(${SLANG_USE_SYSTEM_SPIRV_HEADERS}) | ||
+ find_package(SPIRV-Headers REQUIRED) | ||
+ add_library(SPIRV-Headers ALIAS SPIRV-Headers::SPIRV-Headers) | ||
+endif() | ||
+ | ||
+if(${SLANG_USE_SYSTEM_SPIRV_TOOLS}) | ||
+ find_package(SPIRV-Tools REQUIRED) | ||
+endif() | ||
+ | ||
+if(${SLANG_USE_SYSTEM_GLSLANG}) | ||
+ find_package(glslang REQUIRED) | ||
+ add_library(glslang ALIAS glslang::glslang) | ||
+endif() | ||
+ | ||
add_subdirectory(external) | ||
|
||
# webgpu_dawn is only available as a fetched shared library, since Dawn's nested source | ||
diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt | ||
index 43105a5f..8b9c0f14 100644 | ||
--- a/external/CMakeLists.txt | ||
+++ b/external/CMakeLists.txt | ||
@@ -73,19 +73,24 @@ if(NOT ${SLANG_USE_SYSTEM_SPIRV_HEADERS}) | ||
endif() | ||
|
||
if(SLANG_ENABLE_SLANG_GLSLANG) | ||
+if(NOT ${SLANG_USE_SYSTEM_SPIRV_TOOLS}) | ||
# SPIRV-Tools | ||
set(SPIRV_TOOLS_BUILD_STATIC ON) | ||
set(SPIRV_WERROR OFF) | ||
set(SPIRV_HEADER_DIR "${CMAKE_CURRENT_LIST_DIR}/spirv-headers/") | ||
set(SPIRV_SKIP_TESTS ON) | ||
add_subdirectory(spirv-tools EXCLUDE_FROM_ALL ${system}) | ||
+endif() | ||
|
||
+if(NOT ${SLANG_USE_SYSTEM_GLSLANG}) | ||
# glslang | ||
set(SKIP_GLSLANG_INSTALL ON) | ||
set(ENABLE_OPT ON) | ||
set(ENABLE_PCH OFF) | ||
+ set(ALLOW_EXTERNAL_SPIRV_TOOLS ${SLANG_USE_SYSTEM_SPIRV_TOOLS}) | ||
add_subdirectory(glslang EXCLUDE_FROM_ALL ${system}) | ||
endif() | ||
+endif() | ||
|
||
# imgui | ||
add_library(imgui INTERFACE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
diff --git a/cmake/LLVM.cmake b/cmake/LLVM.cmake | ||
index 3c7c1b54..7f66d6bd 100644 | ||
--- a/cmake/LLVM.cmake | ||
+++ b/cmake/LLVM.cmake | ||
@@ -7,7 +7,7 @@ function(llvm_target_from_components target_name) | ||
${components} | ||
) | ||
add_library(${target_name} INTERFACE) | ||
- target_link_libraries(${target_name} INTERFACE ${llvm_libs}) | ||
+ target_link_libraries(${target_name} INTERFACE LLVM) | ||
target_include_directories( | ||
${target_name} | ||
SYSTEM | ||
@@ -66,12 +66,7 @@ function(fetch_or_build_slang_llvm) | ||
llvm_target_from_components(llvm-dep filecheck native orcjit) | ||
clang_target_from_libs( | ||
clang-dep | ||
- clangBasic | ||
- clangCodeGen | ||
- clangDriver | ||
- clangLex | ||
- clangFrontend | ||
- clangFrontendTool | ||
+ clang-cpp | ||
) | ||
slang_add_target( | ||
source/slang-llvm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
diff --git a/source/slang-glslang/slang-glslang.cpp b/source/slang-glslang/slang-glslang.cpp | ||
index 4abcada6..0f63a64e 100644 | ||
--- a/source/slang-glslang/slang-glslang.cpp | ||
+++ b/source/slang-glslang/slang-glslang.cpp | ||
@@ -1,8 +1,7 @@ | ||
// slang-glslang.cpp | ||
#include "slang-glslang.h" | ||
|
||
-#include "SPIRV/GlslangToSpv.h" | ||
-#include "glslang/MachineIndependent/localintermediate.h" | ||
+#include "glslang/SPIRV/GlslangToSpv.h" | ||
#include "glslang/Public/ShaderLang.h" | ||
#include "slang.h" | ||
#include "spirv-tools/libspirv.h" | ||
@@ -17,6 +16,7 @@ | ||
#include <memory> | ||
#include <mutex> | ||
#include <sstream> | ||
+#include <cassert> | ||
|
||
// This is a wrapper to allow us to run the `glslang` compiler | ||
// in a controlled fashion. | ||
@@ -718,6 +718,11 @@ static int glslang_compileGLSLToSPIRV(glslang_CompileRequest_1_2 request) | ||
return 1; | ||
} | ||
|
||
+ if (debugLevel == SLANG_DEBUG_INFO_LEVEL_MAXIMAL) | ||
+ { | ||
+ shader->addSourceText(sourceText, sourceTextLength); | ||
+ } | ||
+ | ||
if (request.entryPointName && strlen(request.entryPointName)) | ||
shader->setEntryPoint(request.entryPointName); | ||
|
||
@@ -741,10 +746,6 @@ static int glslang_compileGLSLToSPIRV(glslang_CompileRequest_1_2 request) | ||
auto stageIntermediate = program->getIntermediate((EShLanguage)stage); | ||
if (!stageIntermediate) | ||
continue; | ||
- if (debugLevel == SLANG_DEBUG_INFO_LEVEL_MAXIMAL) | ||
- { | ||
- stageIntermediate->addSourceText(sourceText, sourceTextLength); | ||
- } | ||
|
||
std::vector<unsigned int> spirv; | ||
spv::SpvBuildLogger logger; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
{ | ||
lib, | ||
stdenv, | ||
fetchFromGitHub, | ||
cmake, | ||
ninja, | ||
python3, | ||
miniz, | ||
lz4, | ||
libxml2, | ||
libX11, | ||
apple-sdk_11, | ||
spirv-headers, | ||
glslang, | ||
llvmPackages_13, | ||
versionCheckHook, | ||
gitUpdater, | ||
|
||
# Required for compiling to SPIR-V or GLSL | ||
withGlslang ? true, | ||
# May be be used for compiling shaders to CPU targets, see: | ||
# https://github.com/shader-slang/slang/blob/master/docs/cpu-target.md | ||
# If `withLLVM` is disabled, Slang will fall back to the C++ compiler found | ||
# in the environment, if one exists. | ||
withLLVM ? false, | ||
# Dynamically link against libllvm and libclang++ (upstream defaults to static) | ||
withSharedLLVM ? withLLVM, | ||
}: | ||
|
||
stdenv.mkDerivation (finalAttrs: { | ||
pname = "shader-slang"; | ||
version = "2024.17"; | ||
|
||
src = fetchFromGitHub { | ||
owner = "shader-slang"; | ||
repo = "slang"; | ||
tag = "v${finalAttrs.version}"; | ||
hash = "sha256-zKcMoeLmqQdorRrIR2pg6vDOxNi531B79pDkj23pToU="; | ||
fetchSubmodules = true; | ||
}; | ||
|
||
patches = | ||
[ | ||
# Slang's build definitions do not supported using system provided cmake packages | ||
# for its dependencies. | ||
# While it does come with "SLANG_USE_SYSTEM_XYZ" flags, these expect Slang to be | ||
# imported into some other CMake build that already provides the necessary target. | ||
# This patch adds the required `find_package` calls and sets up target aliases where needed. | ||
./1-find-packages.patch | ||
] | ||
++ lib.optionals withSharedLLVM [ | ||
# Upstream statically links libllvm and libclang++, resulting in a ~5x increase in binary size. | ||
./2-shared-llvm.patch | ||
] | ||
++ lib.optionals withGlslang [ | ||
# Upstream depends on glslang 13 and there are minor breaking changes in glslang 15, the version | ||
# we ship in nixpkgs. | ||
./3-glslang-15.patch | ||
]; | ||
|
||
outputs = [ | ||
"out" | ||
"dev" | ||
"doc" | ||
]; | ||
|
||
strictDeps = true; | ||
|
||
nativeBuildInputs = [ | ||
cmake | ||
ninja | ||
python3 | ||
]; | ||
|
||
buildInputs = | ||
[ | ||
miniz | ||
lz4 | ||
libxml2 | ||
spirv-headers | ||
] | ||
++ (lib.optionals stdenv.hostPlatform.isLinux [ | ||
libX11 | ||
]) | ||
++ (lib.optionals stdenv.hostPlatform.isDarwin [ | ||
# Required by metal.cpp | ||
apple-sdk_11 | ||
]) | ||
++ (lib.optionals withLLVM [ | ||
# Slang only supports LLVM 13: | ||
# https://github.com/shader-slang/slang/blob/master/docs/building.md#llvm-support | ||
llvmPackages_13.llvm | ||
llvmPackages_13.libclang | ||
]) | ||
++ (lib.optionals withGlslang [ | ||
# SPIRV-tools is included in glslang. | ||
glslang | ||
]); | ||
|
||
# Required for spaces in cmakeFlags, see https://github.com/NixOS/nixpkgs/issues/114044 | ||
__structuredAttrs = true; | ||
|
||
preConfigure = | ||
lib.optionalString stdenv.hostPlatform.isLinux '' | ||
# required to handle LTO objects | ||
export AR="${stdenv.cc.targetPrefix}gcc-ar" | ||
export NM="${stdenv.cc.targetPrefix}gcc-nm" | ||
export RANLIB="${stdenv.cc.targetPrefix}gcc-ranlib" | ||
'' | ||
+ '' | ||
# cmake setup hook only sets CMAKE_AR and CMAKE_RANLIB, but not these | ||
prependToVar cmakeFlags "-DCMAKE_CXX_COMPILER_AR=$(command -v $AR)" | ||
prependToVar cmakeFlags "-DCMAKE_CXX_COMPILER_RANLIB=$(command -v $RANLIB)" | ||
''; | ||
|
||
cmakeFlags = | ||
[ | ||
"-GNinja Multi-Config" | ||
# The cmake setup hook only specifies `-DCMAKE_BUILD_TYPE=Release`, | ||
# which does nothing for "Ninja Multi-Config". | ||
"-DCMAKE_CONFIGURATION_TYPES=Release" | ||
"-DSLANG_VERSION_FULL=v${finalAttrs.version}-nixpkgs" | ||
# slang-rhi tries to download WebGPU dawn binaries, and as stated on | ||
# https://github.com/shader-slang/slang-rhi is "under active refactoring | ||
# and development, and is not yet ready for general use." | ||
"-DSLANG_ENABLE_SLANG_RHI=OFF" | ||
"-DSLANG_USE_SYSTEM_MINIZ=ON" | ||
"-DSLANG_USE_SYSTEM_LZ4=ON" | ||
"-DSLANG_USE_SYSTEM_SPIRV_HEADERS=ON" | ||
"-DSLANG_SPIRV_HEADERS_INCLUDE_DIR=${spirv-headers}/include" | ||
"-DSLANG_SLANG_LLVM_FLAVOR=${if withLLVM then "USE_SYSTEM_LLVM" else "DISABLE"}" | ||
] | ||
++ (lib.optionals withGlslang [ | ||
"-DSLANG_USE_SYSTEM_SPIRV_TOOLS=ON" | ||
"-DSLANG_USE_SYSTEM_GLSLANG=ON" | ||
]) | ||
++ lib.optional (!withGlslang) "-DSLANG_ENABLE_SLANG_GLSLANG=OFF"; | ||
|
||
nativeInstallCheckInputs = [ versionCheckHook ]; | ||
versionCheckProgram = "${placeholder "out"}/bin/slangc"; | ||
versionCheckProgramArg = [ "-v" ]; | ||
doInstallCheck = true; | ||
|
||
passthru.updateScript = gitUpdater { | ||
rev-prefix = "v"; | ||
ignoredVersions = "*-draft"; | ||
}; | ||
|
||
meta = { | ||
description = "A shading language that makes it easier to build and maintain large shader codebases in a modular and extensible fashion"; | ||
homepage = "https://github.com/shader-slang/slang"; | ||
license = lib.licenses.mit; | ||
maintainers = with lib.maintainers; [ niklaskorz ]; | ||
mainProgram = "slangc"; | ||
platforms = lib.platforms.all; | ||
}; | ||
}) |