diff options
author | dan sinclair <dsinclair@google.com> | 2019-05-27 20:07:26 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-27 20:07:26 -0400 |
commit | 47dfd3c7f3e337153ee84556a4558b2ede08c3ab (patch) | |
tree | e6f18252668b6ed50b18881a0a4634918ba6cdfc | |
parent | dbfc621216f3771e1ce5b1863f9be5443f3da9a4 (diff) | |
download | amber-47dfd3c7f3e337153ee84556a4558b2ede08c3ab.tar.gz |
Add HLSL support through DXC (#511)
This Cl adds DXC to the Amber third_party directory and enables using
HLSL as the shader language in AmberScript.
Fixes #34
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | CMakeLists.txt | 32 | ||||
-rw-r--r-- | DEPS | 5 | ||||
-rw-r--r-- | README.md | 5 | ||||
-rw-r--r-- | include/amber/shader_info.h | 1 | ||||
-rw-r--r-- | src/CMakeLists.txt | 20 | ||||
-rw-r--r-- | src/amberscript/parser.cc | 2 | ||||
-rw-r--r-- | src/dxc_helper.cc | 162 | ||||
-rw-r--r-- | src/dxc_helper.h | 36 | ||||
-rw-r--r-- | src/shader_compiler.cc | 35 | ||||
-rw-r--r-- | src/shader_compiler.h | 1 | ||||
-rw-r--r-- | tests/cases/draw_triangle_list_hlsl.amber | 131 | ||||
-rwxr-xr-x | tests/run_tests.py | 14 | ||||
-rw-r--r-- | third_party/CMakeLists.txt | 55 |
14 files changed, 492 insertions, 8 deletions
@@ -1,5 +1,6 @@ out third_party/cpplint +third_party/dxc third_party/glslang third_party/googletest third_party/lodepng diff --git a/CMakeLists.txt b/CMakeLists.txt index c8042b7..10864c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,7 +44,8 @@ option(AMBER_SKIP_SAMPLES option(AMBER_USE_LOCAL_VULKAN "Build with vulkan in third_party" OFF) option(AMBER_ENABLE_SWIFTSHADER "Build using SwiftShader" ${AMBER_ENABLE_SWIFTSHADER}) -option(AMBER_USE_LOCAL_VULKAN "Build with vulkan in third_party" OFF) +option(AMBER_USE_DXC "Enable DXC integration" ${AMBER_USE_DXC}) + if(WIN32) # On Windows, CMake by default compiles with the shared CRT. # Default it to the static CRT. @@ -53,7 +54,6 @@ if(WIN32) ${AMBER_ENABLE_SHARED_CRT}) endif(WIN32) - if (${AMBER_SKIP_SPIRV_TOOLS}) set(AMBER_ENABLE_SPIRV_TOOLS FALSE) set(AMBER_ENABLE_SHADERC FALSE) @@ -66,11 +66,13 @@ else() set(AMBER_ENABLE_SHADERC TRUE) endif() endif() + if (${AMBER_SKIP_TESTS}) set(AMBER_ENABLE_TESTS FALSE) else() set(AMBER_ENABLE_TESTS TRUE) endif() + if (${AMBER_SKIP_SAMPLES}) set(AMBER_ENABLE_SAMPLES FALSE) else() @@ -82,17 +84,21 @@ if (${AMBER_ENABLE_SWIFTSHADER}) set(AMBER_USE_LOCAL_VULKAN TRUE) endif() -if (${AMBER_USE_LOCAL_VULKAN}) - message(STATUS "Using python3") - # vulkan-loaders requires python 3 - find_package(PythonInterp 3 REQUIRED) +if (${AMBER_USE_DXC}) + set(AMBER_ENABLE_DXC TRUE) +else() + set(AMBER_ENABLE_DXC FALSE) endif() +message(STATUS "Using python3") +find_package(PythonInterp 3 REQUIRED) + message(STATUS "Amber enable SPIRV-Tools: ${AMBER_ENABLE_SPIRV_TOOLS}") message(STATUS "Amber enable Shaderc: ${AMBER_ENABLE_SHADERC}") message(STATUS "Amber enable tests: ${AMBER_ENABLE_TESTS}") message(STATUS "Amber enable samples: ${AMBER_ENABLE_SAMPLES}") message(STATUS "Amber enable SwiftShader: ${AMBER_ENABLE_SWIFTSHADER}") +message(STATUS "Amber enable DXC: ${AMBER_ENABLE_DXC}") include_directories("${PROJECT_SOURCE_DIR}/include") include_directories("${PROJECT_SOURCE_DIR}") @@ -112,6 +118,20 @@ add_definitions(-DAMBER_ENGINE_VULKAN=$<BOOL:${Vulkan_FOUND}>) add_definitions(-DAMBER_ENGINE_DAWN=$<BOOL:${Dawn_FOUND}>) add_definitions(-DAMBER_ENABLE_SPIRV_TOOLS=$<BOOL:${AMBER_ENABLE_SPIRV_TOOLS}>) add_definitions(-DAMBER_ENABLE_SHADERC=$<BOOL:${AMBER_ENABLE_SHADERC}>) +add_definitions(-DAMBER_ENABLE_DXC=$<BOOL:${AMBER_ENABLE_DXC}>) + +set(CMAKE_DEBUG_POSTFIX "") + +# This has to be done very early so the link path will get set correctly for all +# the various libraries and binaries. +if (${AMBER_ENABLE_DXC}) + link_directories("${CMAKE_BINARY_DIR}/third_party/dxc/lib") + + if (MSVC) + # DXC turns this off all over the place so we have to do the same. + add_definitions(/D_ITERATOR_DEBUG_LEVEL=0) + endif() +endif() if ("${CMAKE_BUILD_TYPE}" STREQUAL "") message(STATUS "No build type selected, default to Debug") @@ -5,8 +5,10 @@ vars = { 'khronos_git': 'https://github.com/KhronosGroup', 'lvandeve_git': 'https://github.com/lvandeve', 'swiftshader_git': 'https://swiftshader.googlesource.com', + 'microsoft_git': 'https://github.com/Microsoft', 'cpplint_revision': '9f41862c0efa7681e2147910d39629c73a2b2702', + 'dxc_revision': '7342a3b9be25bd4787fd24a4041795796e7ec49f', 'glslang_revision': 'f44b17ee135d5e153ce000e88b806b5377812b11', 'googletest_revision': 'd5932506d6eed73ac80b9bcc47ed723c8c74eb1e', 'lodepng_revision': 'ba9fc1f084f03b5fbf8c9a5df9448173f27544b1', @@ -22,6 +24,9 @@ deps = { 'third_party/cpplint': vars['google_git'] + '/styleguide.git@' + vars['cpplint_revision'], + 'third_party/dxc': vars['microsoft_git'] + '/DirectXShaderCompiler.git@' + + vars['dxc_revision'], + 'third_party/googletest': vars['google_git'] + '/googletest.git@' + vars['googletest_revision'], @@ -121,6 +121,11 @@ The available flags which can be defined are: cmake -DAMBER_SKIP_TESTS=True -DAMBER_SKIP_SPIRV_TOOLS=True -GNinja ../.. ``` +#### DXC + +DXC can be enabled in Amber by adding the `-DAMBER_USE_DXC=true` flag when +running cmake. + ## Build Bots There are a number of build bots to verify Amber continues to compile and run diff --git a/include/amber/shader_info.h b/include/amber/shader_info.h index 367c385..d016441 100644 --- a/include/amber/shader_info.h +++ b/include/amber/shader_info.h @@ -24,6 +24,7 @@ enum ShaderFormat { kShaderFormatDefault = 0, kShaderFormatText, kShaderFormatGlsl, + kShaderFormatHlsl, kShaderFormatSpirvAsm, kShaderFormatSpirvHex, }; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 3b29bf8..ff1a15e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,11 +51,31 @@ if (${Dawn_FOUND}) list(APPEND AMBER_SOURCES dawn_engine_config.cc) endif() +if (${AMBER_ENABLE_DXC}) + list(APPEND AMBER_SOURCES dxc_helper.cc) +endif() + add_library(libamber ${AMBER_SOURCES}) amber_default_compile_options(libamber) target_include_directories(libamber PRIVATE "${CMAKE_BINARY_DIR}") set_target_properties(libamber PROPERTIES OUTPUT_NAME "amber") +if (${AMBER_ENABLE_DXC}) + target_include_directories(libamber PRIVATE + "${PROJECT_SOURCE_DIR}/third_party/dxc/include" + "${CMAKE_BINARY_DIR}/third_party/dxc/include" + ) + + add_dependencies(libamber dxcompiler) + target_link_libraries(libamber + dxcompiler + LLVMDxcSupport + LLVMOption + LLVMHLSL + LLVMScalarOpts + ) +endif() + if (${AMBER_ENABLE_SPIRV_TOOLS}) target_link_libraries(libamber SPIRV-Tools) endif() diff --git a/src/amberscript/parser.cc b/src/amberscript/parser.cc index 7e1dbf0..dabeecb 100644 --- a/src/amberscript/parser.cc +++ b/src/amberscript/parser.cc @@ -181,6 +181,8 @@ Result Parser::ToShaderFormat(const std::string& str, ShaderFormat* fmt) { if (str == "GLSL") *fmt = kShaderFormatGlsl; + else if (str == "HLSL") + *fmt = kShaderFormatHlsl; else if (str == "SPIRV-ASM") *fmt = kShaderFormatSpirvAsm; else if (str == "SPIRV-HEX") diff --git a/src/dxc_helper.cc b/src/dxc_helper.cc new file mode 100644 index 0000000..d9bb367 --- /dev/null +++ b/src/dxc_helper.cc @@ -0,0 +1,162 @@ +// Copyright 2019 The Amber Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "src/dxc_helper.h" + +#include <algorithm> +#include <sstream> + +#include "src/platform.h" + +#if AMBER_PLATFORM_WINDOWS +#pragma warning(push) +#pragma warning(disable : 4267) +#pragma warning(disable : 4003) +#endif // AMBER_PLATFORM_WINDOWS + +// clang-format off +// The order here matters, so don't reformat. +#include "third_party/dxc/include/dxc/Support/WinAdapter.h" +#include "third_party/dxc/include/dxc/Support/WinIncludes.h" +#include "third_party/dxc/include/dxc/Support/Global.h" +#include "third_party/dxc/include/dxc/Support/HLSLOptions.h" +#include "third_party/dxc/include/dxc/Support/dxcapi.use.h" +#include "third_party/dxc/include/dxc/dxcapi.h" +// clang-format on + +#if AMBER_PLATFORM_WINDOWS +#pragma warning(pop) +#endif // AMBER_PLATFORM_WINDOWS + +namespace amber { +namespace dxchelper { +namespace { + +const wchar_t* kDxcFlags[] = { + L"-spirv", // SPIR-V compilation + L"-Vd" // Disable validation. +}; +const size_t kDxcFlagsCount = sizeof(kDxcFlags) / sizeof(const wchar_t*); + +// Converts an IDxcBlob into a vector of 32-bit unsigned integers which +// is returned via the 'binaryWords' argument. +void ConvertIDxcBlobToUint32(IDxcBlob* blob, + std::vector<uint32_t>* binaryWords) { + size_t num32BitWords = (blob->GetBufferSize() + 3) / 4; + std::string binaryStr(static_cast<char*>(blob->GetBufferPointer()), + blob->GetBufferSize()); + binaryStr.resize(num32BitWords * 4, 0); + binaryWords->resize(num32BitWords, 0); + memcpy(binaryWords->data(), binaryStr.data(), binaryStr.size()); +} + +} // namespace + +Result Compile(const std::string& src, + const std::string& entry, + const std::string& profile, + std::vector<uint32_t>* generated_binary) { + DxcInitThreadMalloc(); + + if (hlsl::options::initHlslOptTable()) { + DxcCleanupThreadMalloc(); + return Result("DXC compile failure: initHlslOptTable"); + } + + IDxcLibrary* dxc_lib; + if (DxcCreateInstance(CLSID_DxcLibrary, __uuidof(IDxcLibrary), + reinterpret_cast<void**>(&dxc_lib)) < 0) { + DxcCleanupThreadMalloc(); + return Result("DXCCreateInstance for DXCLibrary failed"); + } + + IDxcBlobEncoding* source; + if (dxc_lib->CreateBlobWithEncodingOnHeapCopy( + src.data(), static_cast<uint32_t>(src.size()), CP_UTF8, &source) < + 0) { + DxcCleanupThreadMalloc(); + return Result("DXC compile failure: CreateBlobFromFile"); + } + + IDxcIncludeHandler* include_handler; + if (dxc_lib->CreateIncludeHandler(&include_handler) < 0) { + DxcCleanupThreadMalloc(); + return Result("DXC compile failure: CreateIncludeHandler"); + } + + IDxcCompiler* compiler; + if (DxcCreateInstance(CLSID_DxcCompiler, __uuidof(IDxcCompiler), + reinterpret_cast<void**>(&compiler)) < 0) { + DxcCleanupThreadMalloc(); + return Result("DXCCreateInstance for DXCCompiler failed"); + } + + IDxcOperationResult* result; + std::wstring src_filename = + L"amber." + std::wstring(profile.begin(), profile.end()); + if (compiler->Compile(source, /* source text */ + src_filename.c_str(), /* original file source */ + std::wstring(entry.begin(), entry.end()) + .c_str(), /* entry point name */ + std::wstring(profile.begin(), profile.end()) + .c_str(), /* shader profile to compile */ + kDxcFlags, /* arguments */ + kDxcFlagsCount, /* argument count */ + nullptr, /* defines */ + 0, /* define count */ + include_handler, /* handler for #include */ + &result /* output status */) < 0) { + DxcCleanupThreadMalloc(); + return Result("DXC compile failure: Compile"); + } + + // Compilation is done. We can clean up the HlslOptTable. + hlsl::options::cleanupHlslOptTable(); + + // Get compilation results. + HRESULT result_status; + if (result->GetStatus(&result_status) < 0) { + DxcCleanupThreadMalloc(); + return Result("DXC compile failure: GetStatus"); + } + + // Get diagnostics string. + IDxcBlobEncoding* error_buffer; + if (result->GetErrorBuffer(&error_buffer)) { + DxcCleanupThreadMalloc(); + return Result("DXC compile failure: GetErrorBuffer"); + } + + const std::string diagnostics( + static_cast<char*>(error_buffer->GetBufferPointer()), + error_buffer->GetBufferSize()); + + bool success = true; + if (SUCCEEDED(result_status)) { + IDxcBlob* compiled_blob; + if (result->GetResult(&compiled_blob) < 0) { + DxcCleanupThreadMalloc(); + return Result("DXC compile failure: GetResult"); + } + ConvertIDxcBlobToUint32(compiled_blob, generated_binary); + } else { + success = false; + } + + DxcCleanupThreadMalloc(); + return success ? Result() : Result("DXC compile failure: " + diagnostics); +} + +} // namespace dxchelper +} // namespace amber diff --git a/src/dxc_helper.h b/src/dxc_helper.h new file mode 100644 index 0000000..76ad94d --- /dev/null +++ b/src/dxc_helper.h @@ -0,0 +1,36 @@ +// Copyright 2019 The Amber Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef SRC_DXC_HELPER_H_ +#define SRC_DXC_HELPER_H_ + +#include <string> +#include <vector> + +#include "amber/result.h" + +namespace amber { +namespace dxchelper { + +// Passes the HLSL source code to the DXC compiler with SPIR-V CodeGen. +// Returns the generated SPIR-V binary via |generated_binary| argument. +Result Compile(const std::string& src_str, + const std::string& entry_str, + const std::string& profile_str, + std::vector<uint32_t>* generated_binary); + +} // namespace dxchelper +} // namespace amber + +#endif // SRC_DXC_HELPER_H_ diff --git a/src/shader_compiler.cc b/src/shader_compiler.cc index 7065b5f..aba0d98 100644 --- a/src/shader_compiler.cc +++ b/src/shader_compiler.cc @@ -34,6 +34,10 @@ #pragma clang diagnostic pop #endif // AMBER_ENABLE_SHADERC +#if AMBER_ENABLE_DXC +#include "src/dxc_helper.h" +#endif // AMBER_ENABLE_DXC + namespace amber { ShaderCompiler::ShaderCompiler() = default; @@ -97,6 +101,13 @@ std::pair<Result, std::vector<uint32_t>> ShaderCompiler::Compile( return {r, {}}; #endif // AMBER_ENABLE_SHADERC +#if AMBER_ENABLE_DXC + } else if (shader->GetFormat() == kShaderFormatHlsl) { + Result r = CompileHlsl(shader, &results); + if (!r.IsSuccess()) + return {r, {}}; +#endif // AMBER_ENABLE_DXC + #if AMBER_ENABLE_SPIRV_TOOLS } else if (shader->GetFormat() == kShaderFormatSpirvAsm) { if (!tools.Assemble(shader->GetData(), &results, @@ -182,4 +193,28 @@ Result ShaderCompiler::CompileGlsl(const Shader*, } #endif // AMBER_ENABLE_SHADERC +#if AMBER_ENABLE_DXC +Result ShaderCompiler::CompileHlsl(const Shader* shader, + std::vector<uint32_t>* result) const { + std::string target; + if (shader->GetType() == kShaderTypeCompute) + target = "cs_6_0"; + else if (shader->GetType() == kShaderTypeFragment) + target = "ps_6_0"; + else if (shader->GetType() == kShaderTypeGeometry) + target = "gs_6_0"; + else if (shader->GetType() == kShaderTypeVertex) + target = "vs_6_0"; + else + return Result("Unknown shader type"); + + return dxchelper::Compile(shader->GetData(), "main", target, result); +} +#else +Result ShaderCompiler::CompileHlsl(const Shader*, + std::vector<uint32_t>*) const { + return {}; +} +#endif // AMBER_ENABLE_DXC + } // namespace amber diff --git a/src/shader_compiler.h b/src/shader_compiler.h index e60b02d..3c0067d 100644 --- a/src/shader_compiler.h +++ b/src/shader_compiler.h @@ -43,6 +43,7 @@ class ShaderCompiler { private: Result ParseHex(const std::string& data, std::vector<uint32_t>* result) const; Result CompileGlsl(const Shader* shader, std::vector<uint32_t>* result) const; + Result CompileHlsl(const Shader* shader, std::vector<uint32_t>* result) const; std::string spv_env_; }; diff --git a/tests/cases/draw_triangle_list_hlsl.amber b/tests/cases/draw_triangle_list_hlsl.amber new file mode 100644 index 0000000..6d7a707 --- /dev/null +++ b/tests/cases/draw_triangle_list_hlsl.amber @@ -0,0 +1,131 @@ +#!amber +# Copyright 2019 The Amber Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +SHADER vertex vtex_shader HLSL +struct VS_OUTPUT { + float4 pos : SV_POSITION; + float4 color : COLOR; +}; + +VS_OUTPUT main(float4 pos : POSITION, + float4 color : COLOR) { + VS_OUTPUT vout; + vout.pos = pos; + vout.color = color; + return vout; +} +END + +SHADER fragment frag_shader HLSL +float4 main(float4 color : COLOR) : SV_TARGET { + return color; +} +END + +BUFFER position_buf DATA_TYPE R8G8_SNORM DATA +# Full frame +-128 -128 + 127 127 +-128 127 +-128 -128 + 127 127 + 127 -128 + +# Half frame + 0 -128 + 127 127 + 0 127 + 0 -128 + 127 127 + 127 -128 + +# Quarter frame +-128 0 + 0 127 +-128 127 +-128 0 + 0 127 + 0 0 + +# Quarter frame + 0 0 + 127 127 + 0 127 + 0 0 + 127 127 + 127 0 +END + +BUFFER vert_color DATA_TYPE R8G8B8A8_UNORM DATA +255 0 0 255 +255 0 0 255 +255 0 0 255 +255 0 0 255 +255 0 0 255 +255 0 0 255 + + 0 255 0 255 + 0 255 0 255 + 0 255 0 255 + 0 255 0 255 + 0 255 0 255 + 0 255 0 255 + + 0 0 255 255 + 0 0 255 255 + 0 0 255 255 + 0 0 255 255 + 0 0 255 255 + 0 0 255 255 + +127 127 127 255 +127 127 127 255 +127 127 127 255 +127 127 127 255 +127 127 127 255 +127 127 127 255 +END + +BUFFER framebuffer FORMAT B8G8R8A8_UNORM + +PIPELINE graphics pipeline + ATTACH vtex_shader + ATTACH frag_shader + + VERTEX_DATA position_buf LOCATION 0 + VERTEX_DATA vert_color LOCATION 1 + + BIND BUFFER framebuffer AS color LOCATION 0 +END + +CLEAR pipeline + +RUN pipeline DRAW_ARRAY AS TRIANGLE_LIST START_IDX 0 COUNT 6 +EXPECT framebuffer IDX 0 0 SIZE 250 250 EQ_RGB 255 0 0 + +RUN pipeline DRAW_ARRAY AS TRIANGLE_LIST START_IDX 6 COUNT 6 +EXPECT framebuffer IDX 0 0 SIZE 125 250 EQ_RGB 255 0 0 +EXPECT framebuffer IDX 125 0 SIZE 125 250 EQ_RGB 0 255 0 + +RUN pipeline DRAW_ARRAY AS TRIANGLE_LIST START_IDX 12 COUNT 6 +EXPECT framebuffer IDX 0 0 SIZE 125 125 EQ_RGB 255 0 0 +EXPECT framebuffer IDX 125 0 SIZE 125 250 EQ_RGB 0 255 0 +EXPECT framebuffer IDX 0 125 SIZE 125 125 EQ_RGB 0 0 255 + +RUN pipeline DRAW_ARRAY AS TRIANGLE_LIST START_IDX 18 COUNT 6 +EXPECT framebuffer IDX 0 0 SIZE 125 125 EQ_RGB 255 0 0 +EXPECT framebuffer IDX 125 0 SIZE 125 125 EQ_RGB 0 255 0 +EXPECT framebuffer IDX 0 125 SIZE 125 125 EQ_RGB 0 0 255 +EXPECT framebuffer IDX 125 125 SIZE 125 125 EQ_RGB 127 127 127 diff --git a/tests/run_tests.py b/tests/run_tests.py index 75d2db3..bb3f755 100755 --- a/tests/run_tests.py +++ b/tests/run_tests.py @@ -40,8 +40,18 @@ SUPPRESSIONS = { # a value to the rasterizer rdar://48348476 # https://github.com/KhronosGroup/MoltenVK/issues/527 "multiple_ssbo_update_with_graphics_pipeline.vkscript", - "multiple_ubo_update_with_graphics_pipeline.vkscript" - ] + "multiple_ubo_update_with_graphics_pipeline.vkscript", + # DXC not currently building on bot + "draw_triangle_list_hlsl.amber" + ], + "Linux": [ + # DXC not currently building on bot + "draw_triangle_list_hlsl.amber" + ], + "Win": [ + # DXC not currently building on bot + "draw_triangle_list_hlsl.amber" + ] } class TestCase: diff --git a/third_party/CMakeLists.txt b/third_party/CMakeLists.txt index a7e6c3d..8b7364a 100644 --- a/third_party/CMakeLists.txt +++ b/third_party/CMakeLists.txt @@ -64,3 +64,58 @@ if (${AMBER_ENABLE_SWIFTSHADER}) set(WARNINGS_AS_ERRORS FALSE CACHE BOOL FALSE) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/swiftshader) endif() + +if (${AMBER_ENABLE_DXC}) + set(DXC_EXTERNAL_ROOT_DIR "${CMAKE_CURRENT_SOURCE_DIR}" CACHE STRING "" FORCE) + set(DXC_SPIRV_HEADERS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/spirv-headers" CACHE PATH "" FORCE) + set(DXC_SPIRV_TOOLS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/spirv-tools" CACHE PATH "" FORCE) + + set(CMAKE_EXPORT_COMPILE_COMMANDS ON CACHE BOOL "") + set(LLVM_APPEND_VC_REV ON CACHE BOOL "") + set(LLVM_DEFAULT_TARGET_TRIPLE "dxil-ms-dx" CACHE STRING "") + set(LLVM_ENABLE_EH ON CACHE BOOL "") + set(LLVM_ENABLE_RTTI ON CACHE BOOL "") + set(LLVM_INCLUDE_DOCS OFF CACHE BOOL "") + set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "") + set(LLVM_BUILD_TESTS ON CACHE BOOL "") + set(LLVM_INCLUDE_TESTS OFF CACHE BOOL "") + set(LLVM_INCLUDE_TOOLS ON CACHE BOOL "") + set(LLVM_INCLUDE_UTILS OFF CACHE BOOL "") + set(LLVM_BUILD_EXAMPLES OFF CACHE BOOL "") + set(LLVM_INCLUDE_EXAMPLES OFF CACHE BOOL "") + set(LLVM_USE_CRT_DEBUG MTd CACHE STRING "") + set(LLVM_USE_CRT_RELEASE MT CACHE STRING "") + set(LLVM_USE_CRT_RELWITHDEBINFO MT CACHE STRING "") + + set(LLVM_OPTIMIZED_TABLEGEN OFF CACHE BOOL "") + set(LLVM_REQUIRES_EH ON CACHE BOOL "") + set(LLVM_REQUIRES_RTTI ON CACHE BOOL "") + set(LLVM_TARGETS_TO_BUILD None CACHE STRING "") + set(LIBCLANG_BUILD_STATIC ON CACHE BOOL "") + set(CLANG_BUILD_EXAMPLES OFF CACHE BOOL "") + set(CLANG_CL OFF CACHE BOOL "") + set(CLANG_ENABLE_ARCMT OFF CACHE BOOL "") + set(CLANG_ENABLE_STATIC_ANALYZER OFF CACHE BOOL "") + set(CLANG_INCLUDE_TESTS OFF CACHE BOOL "") + set(HLSL_INCLUDE_TESTS OFF CACHE BOOL "") + set(ENABLE_SPIRV_CODEGEN ON CACHE BOOL "enable spirv codegen") + set(SPIRV_BUILD_TESTS OFF CACHE BOOL "Enable dxc spirv tests") + + set(LLVM_BUILD_STATIC ON CACHE BOOL "") + set(BUILD_SHARED_LIBS OFF CACHE BOOL "") + + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/dxc EXCLUDE_FROM_ALL) + + if (MSVC) + add_custom_target(dxc-binary ALL + DEPENDS "${CMAKE_BINARY_DIR}/third_party/dxc/bin/dxcompiler.dll" + COMMENT "dxc-binary custom target") + + ADD_CUSTOM_COMMAND( + TARGET dxc-binary + POST_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -E copy ${CMAKE_BINARY_DIR}/third_party/dxc/bin/dxcompiler.dll ${CMAKE_BINARY_DIR} + ) + endif() +endif() |