Add option LLVM_ASSERTIONS_NO_STRINGS
When defined, drop the stringized expression, __FILE__, and __FUNCTION__
strings passed to llvm_assert. This dramatically reduces the binary
size, which is useful when enabling assertions in a non-debug build.
Add option LLVM_ASSERTIONS_TRAP
When enabled, this forces asserts to always trap. Currently, on Windows
asserts calls RaiseException, while they trap on non-Windows. This
option makes the assertion behaviour consistent across platforms.
This change adds a new CMake configuration option
`HLSL_DISABLE_SOURCE_GENERATION` which allows a user to disable
generating the in-tree sources which contributte to DXC's source
releases. This option should only be used by users building DXC and not
modifying it.
Resolves#6728
When not updating the in-tree sources, the compare step would always run
because the comparison was part of the target. This prevents that by
having the comparison be its own custom command that produces an output
and the target depends on the "output" of the comparison step.
The build is failing due to clang-format modifying these lines. I've
changed them to what clang-format wants even though it's a bit odd, and
updated the CMake script to make the error message more clear when this
type of failure occurs.
FindD3D12.cmake sets WIN10_SDK_VERSION to
CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION; however, this latter variable
is only defined when using a Visual Studio CMake generator. When using
Ninja instead, for example, this variable will be empty, and
WIN10_SDK_VERSION will remain unset.
This change detects when CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION and
attempts to retrieve the latest SDK by listing directories under
${WIN10_SDK_PATH}/Include.
Fail to find DIASDK when using VisualStudio "Open a local folder". Both
VS_DIA_INC_PATH and VSWHERE_LATEST are empty. But MSVC_DIA_SDK_DIR is
set correctly.
Add MSVC_DIA_SDK_DIR/include as hint for DIASDK_INCLUDE_DIR.
These changes allow us to use DXC as as CMake subproject (via
add_subdirectory).
Commit comments from each commit:
===
cmake: allow CMAKE_INSTALL_RPATH to be defined in superproject on APPLE
platforms
As on Linux, allow CMAKE_INSTALL_RPATH to be defined in a CMake
superproject.
===
cmake: Allow LLVM_ENABLE_ASSERTIONS=OFF to disable assertions in Debug
builds
Currently, this flag is only used to enable assertions in non-Debug
builds, but is not respected in Debug builds. That is, if set to false,
Debug builds will still assert. This change fixes that.
Note that by default, LLVM_ENABLE_ASSERTIONS is true in Debug builds, so
unless it's explicitly set to false, this is a no-op for most people.
===
cmake: Allow DIRECTX_HEADERS_INCLUDE_DIR to be defined from superproject
Useful for when DXC is included as a subdirectory. In Dawn/Chrome, we
use our own mirror of DirectX-Headers instead of checking out the repo's
submodules, so we need to override this variable.
The previous PR #5881 didn't do what it meant to and had a lot of debug
code due to a mistaken commit. This reverts that commit and restores the
setting of the build type flag
A slightly complex series of events causes invocations of hctbuild after
the first to enable asserts in release builds. This sets the build type
even when it isn't needed to avoid it.
Because the build type was not being set when generating for visual
studio in hctbuild, when generating the cmake files using CMakeLists, it
would produce an alarming message saying it was defaulting to debug,
but, in fact, since it didn't care for the purposes of sln file
generation, that wasn't actually a problem, just confusing. It did set a
variable to enable asserts, but didn't do this for release variant
builds
The real problem occurs if hctbuild is invoked again, at that point,
instead of defaulting to Debug, it leaves the build type empty because
of another variable set in the cache.
Additionally, since the first invocation enabled asserts, that also
comes from the cache and so code that strips NDEBUG from all build
variants is invoked because the build type is, in fact, not debug, it's
an empty string.
Clang-format determines if a header is the "main" header by looking at
the header name without the last extension and matching it against the
source file (with some extra handling for cuda files).
The automation generating temporary files with a `.tmp` suffix tripped
this up so it wasn't matching the "main" header when sorting includes.
This corrects the issue by writing temporaries to a tmp directory
instead of munging the suffix.
This integrates formatting generated sources with clang-format with the
hctgen generation process.
This change makes a few small adjustments to how the build-time header
generation works. This change, disables automated build-time generation
for C++ sources if you don't have clang-format available on your system.
CMake can automatically detect clang-format installed as part of Visual
Studio, or based on your PATH. You can also explicitly set
`CLANG_FORMAT_EXE` when configuring to manually override. **Developers
on macOS** will need to install clang-format manually and place it on
their path to generate DXC's generated sources.
If clang-format cannot be found and `HLSL_COPY_GENERATED_SOURCES` is On
a fatal error will be reported at configuration time.
This change _does not_ make clang-format a requirement to build DXC, but
it does make it a requirement if you are modifying the generated
sources.
Add -Wno-unused-parameter -Wno-unknown-pragams -Wno-switch which are
enabled for clang in linux build.
Fix
-Wimplicit-fallthrough
-Wconstant-logical-operand (Thanks patch from Chris)
-Wunused-function
-Wunused-variable
-Wtrigraphs
-Wnonportable-include-path
Still more warnings to be fixed.
The standard TAEF install paths use the x64 and x86 paths just like the
TAEF_ARCH. I'm not entirely sure where the alternative TAEF_BIN_ARCH
naming is used, but it seems to be used in the custom tooling for
fetching and building TAEF.
This only alters the parts of the code that I've been able to verify
locally.
* Enable lit by default.
* Update README for git user bin.
* Add DXC_DISABLE_LIT to replace DXC_ENABLE_LIT
* Set -DDXC_DISABLE_LIT=Off for appveyor.
* Keep original name for ClangSPIRVTests
* Set correct path for unit tests binary.
* Remove doc about DXC_DISABLE_LIT
* Remove extra space.
* Remove DxcOnUnix.rst.
This pulls in a couple upstream commits by myself and @bogner.
commit 3adaa8cf4a6df45430b47a62c649c7cb54bb1626
Author: Justin Bogner <mail@justinbogner.com>
Date: Wed Jun 8 22:36:37 2016 +0000
cmake: Simplify add_lit_testsuites
cmake 3.4 introduced LIST_DIRECTORIES to glob recurse, which can be
used to simplify this code greatly.
llvm-svn: 272217
commit 25ef9e34c9de7b1edc327189b78200459337f7e5
Author: Justin Bogner <mail@justinbogner.com>
Date: Mon Jul 25 18:07:14 2016 +0000
cmake: When adding lit testsuites, ignore Output directories
With in-tree builds we can get Output directories scattered among
our
tests. Recursing into those to find tests doesn't make sense.
Thanks to nlewycky for noticing this!
llvm-svn: 276667
commit a44ef999fb5e9243df9c4459df1b17b66aa3fd23
Author: Chris Bieneman <chris.bieneman@me.com>
Date: Mon Jan 3 11:52:44 2022 -0600
[NFC][CMake] Add FOLDER to utility targets
As Visual Studio's CMake support is getting better and better the
line
between IDE generator and non-IDE generators is blurring. Visual
Studio
2019 and later have a very useful UI that can handle all of the
various
targets we create, but if they are unsorted it is wildly unwieldy.
This change sorts the lit testsuite targets and per-component
install
targets into folders, which are not generated for IDE generators but
are generated by default under Visual Studio's CMake + Ninja
integration.
1. added dxc_batch as dependent for clang tests.
2. Not run exec test by default.
3. Strip directory which has dxil.dll from %PATH% for taef test which not need it.
4. Add select_filter and use @Name for TestName.
* Enable mix select filter by use shell=True when open subprocess.
5. Only run execution test when dxil.dll exist or experimental mode enabled.
Having this enabled makes dxc depends on ncurses5. This is required by
LLVM when supporting colored message output, but DXC doesn't supports it
for now.
Fixes#4892
A common source of bugs. Although many of these were harmless, some were
not. By eliminating them and enabling this warning as an error, we won't
add more in the future.
Fixed a real SPIRV bug that required a test update to expect the correct behavior.
SPIRV testing was expecting incorrect results that came from a fallthrough error
The `LLVM_REQUIRES_*` variables are internal variables in LLVM's
configuration used to determine if a build setting is required, they
don't actually control the build setting itself, so we shouldn't be
setting them.
`LLVM_ENABLE_*` variables control the build settings, and we do set
those correctly.
* Update Linux build and test workflows to use lit
This change updates the build and test workflows in our azure pipelines
and the GitHub action for code coverage data to use lit instead of ctest
as the test runner. This adds additional test coverage by running some
of the LLVM & Clang tests.
* Fix missing dependency between LLVMAnalysis & DXIL
The default Linux linker fails because LLVMAnalysis depends on LLVMDXIL
and BFD doesn't cycle libraries.
* Updating pipelines to remove mkdir and cd
This just cleans up the pipeline shell commands to avoid unnecissary
mkdir and cd invocations.
Based on feedback from @Keenuts. Thanks!
* Disable LLVM LIT tests that use garbage collection
DXC disabled support for the LLVM garbage collection intrinsics.
* Enable running tests under LIT
If `CLANG_INCLUDE_TESTS=On`, the googletest unit tests are built as
part of the clang unit test suite. This allows them to run via lit
using the `check-clang-unit` target.
* Configure DXILConv tests to run under check-all
* Remove DXC_BUILD_ARCH variable
This commit simplifies the cross-targeting build support to not require
specifying the build architecture explicitly. Instead it is derived from
the build tools used in the generation.
I've tested this change locally for Win32, x64 and arm64.
* Special handling for arm64ec
* Bump required CMake to 3.10
CMake 3.10 is very old, but has a feature this PR uses. Raising the
requirement should have no impact on our users.
* Fix build issues caused by changes in CMake 3.10
* [CMake] Simplify code coverage CMake configuration
This just addes an option processed by the CMake cache file to configure
code coverage for DXC. With this patch you can generate a coverage
report locally if you build with Clang using the following commnads:
cmake -G Ninja -DDXC_COVERAGE=On <other options> -C
<path to dxc>/cmake/caches/PredefinedParams.cmake <path to dxc>
ninja
ctest
ninja generate-coverage-report
* Adding code comment explaining caches
CMake cache scripts aren't super common, but are very useful. Adding a
comment to explain how they work is probably generally valuable.
This cherry-picks in a bunch of upstream LLVM changes and has a few small modifications for DXC.
* [CMake] Add LLVM_BUILD_INSTRUMENTED option to enable building with
-fprofile-instr-generate
This is the first step in supporting PGO data generation via CMake.
I've marked the option as advanced and experimental until it is fleshed
out further.
llvm-svn: 255298
* Add support for collating profiles for use with code coverage
Differential Revision: http://reviews.llvm.org/D20993
llvm-svn: 272599
Patch by: Vedant Kumar <vsk@apple.com>
* [CMake] Add targets for generating coverage reports
This is a pretty small bit of CMake goop to generate code coverage
reports. I always forget the right script invocation and end up
fumbling around too much.
Wouldn't it be great to have targets that "Just Work"?
Well, I thought so.
At present this only really works correctly for LLVM, but I'll extend
it in subsequent patches to work for subprojects.
Reviewed By: phosek
Differential Revision: https://reviews.llvm.org/D109019
* Update prepare-code-coverage.py from llvm/main
Theres's a swath of changes that went in here. Cherry-picking them all
indivudially is not worth it. Contained commits:
8773822c578a [Zequan Wu] [Utils] Add -compilation-dir flag to
prepare-code-coverage-artifact.py
577d59bc679d [Nico Weber] svn propset svn:executable on
utils/prepare-code-coverage-artifact.py
9a10eac663dd [Chris Bieneman] [Coverage] Apply filtered paths to summary
16776315460e [Vedant Kumar] [utils] coverage: Add help text about the
--restrict flag (NFC)
f4df0edf3ea3 [Vedant Kumar] [utils] Add a '--unified-report' option to
the code coverage prep script
7466987cb7ba [Vedant Kumar] [utils] Use print_function in the code
coverage prep script, NFC.
273b6dc3e2f7 [Vedant Kumar] [utils] Add an '--only-merge' option to the
code coverage prep script
547ebad0b984 [Vedant Kumar] [utils] Teach the code coverage prep script
about --restrict
05ee94f1b573 [Vedant Kumar] [utils] Generate html reports with the code
coverage utility script
d9aed82cf7e2 [Vedant Kumar] Add support for collating profiles for use
with code coverage
* HLSL-specific change to coverage reporting
This works around DXC not having a cmake target to run tests by
exposing a new variable which can configure which target gets run to
produce profiles. A similar change will be useful upstream, so I'll add
a change there too.
* WinAdapter: Remove virtual dtors from IUnknown to fix vtable ABI
The vtable for `IUnknown` and its subclasses contain two deletion
pointers when compiled on non-Windows systems with `IUnknown` from
`WinAdapter.h`:
vtable for 'DxcLibrary' @ 0x7ffff7cbc5f8 (subobject @ 0x5555556bb9e0):
[0]: 0x7ffff6a56d40 <DxcLibrary::QueryInterface(_GUID const&, void**)>
[1]: 0x7ffff6a56d20 <DxcLibrary::AddRef()>
[2]: 0x7ffff6a56d30 <DxcLibrary::Release()>
[3]: 0x7ffff6b36bc0 <IUnknown::~IUnknown()> // Complete object destructor
[4]: 0x7ffff6a57130 <DxcLibrary::~DxcLibrary()> // Deleting destructor
[5]: 0x7ffff6a56d50 <DxcLibrary::SetMalloc(IMalloc*)>
[6]: 0x7ffff6a56d60 <DxcLibrary::CreateBlobFromBlob(IDxcBlob*, unsigned int, unsigned int, IDxcBlob**)>
... More DxcLibrary virtual functions
This shifts the the pointers for functions for all subclasses, and is
[annoying] to deal with in otherwise cross-platform applications using
DirectXShaderCompiler as library. `dxcompiler.dll` compiled on/for
Windows without `WinAdapter.h` does not suffer this problem, and only
has three function pointers for `IUnknown`.
Fortunately, it is easily solved by removing the virtual destructor from
`IUnknown`. LLVM enables `-Wnon-virtual-dtor` that warns against
classes with virtual methods but no virtual destructor, though this
warning is best not enabled akin to Windows builds where `IUnknown` from
`windows.h` (`unknwn.h`) results in the same warning on MSVC ([1]/[2]).
[annoying]: 1e624792fc/src/unknown.rs
[1]: https://github.com/microsoft/DirectXShaderCompiler/issues/3783#issuecomment-844189358
[2]: https://godbolt.org/z/hKPT6ThEf
* WinAdapter: Make `IUnknown` and `IMalloc` pure-virtual classes
`IUnknown` in Windows' `unknwn.h` and `IMalloc` in `ObjIdl.h` are marked
as pure virtual, and are best marked as such in `WinAdapter` for
non-Windows platforms too [1]. Only the shim for `IMalloc` was relying
on the default refcounting implementation, all other subclasses either
contain pure-virtual methods themselves or provide an implementation for
`AddRef`/`Release` as required. Likewise the default implementation for
`IMalloc` was only instantiated once by `CoGetMalloc`, and has been
moved into a local class implementing the `IMalloc` interface instead.
[1]: https://github.com/microsoft/DirectXShaderCompiler/pull/3793#issuecomment-846459741
* WinAdapter: Add three missing virtual functions to `IMalloc` interface
To prevent unexpected vtable breakage, add the missing functions from
the [documentation]. Note that they are listed in the wrong order, the
right order is retrieved from the `ObjIdl.h` header and implementations
for `IMalloc` in DirectXShaderCompiler. All implementations are now
properly using the `override` keyword too, to enforce virtual method
existence in the base class.
[documentation]: https://docs.microsoft.com/en-us/windows/win32/api/objidl/nn-objidl-imalloc
* Make all WinAdapter destructions explicit
This prevents warnings about non-virtual destructor usage that trip up
the Linux build. It represents status quo on Windows.
Co-authored-by: Greg Roth <grroth@microsoft.com>
I added this upstream a few years ago so that you can control passing
`-O1` to the compiler when building debug sanitized builds. Without
being able to disable optimizing sanitizer builds it is really tricky to
debug sanitizer failures, but without optimizing the build ASan builds
take _forever_ to run tests which makes them difficult to use.
This adds a new option to the build to enable link-time optimzied builds
of DXC. On Windows with MSVC this seems to give about a 4% runtime
performance boost on my one locally run test case... and on Linux I'm
seeing about 6% on that same locally run test case.
LTO/LTCG is enabled by default for "Official" builds.
It's free performance so yay :D
Backport an LLVM cmake option to specify the C/C++ linker to use.
This implementation is simplified and unlike the llvm-project one
does not contain any linker-specific tweaks.
On my system, setting `-DLLVM_USE_LINKER=mold` reduces the full build
time from 81s to 43s.
* Clean up debug preprocessor macros
This change removes the `DBG` macro value in favor of `NDEBUG`, and
also converts many uses of `_DEBUG` with `NDEBUG`.
_DEBUG is set by MSVC when debug information generation is enabled.
NDEBUG is set by CMake debug configurations and by LLVM on all
configurations when `LLVM_ENABLE_ASSERTIONS` is set.
Aligning with LLVM's NDEBUG usage allows a consistent pattern
throughout the codebase.
* Address PR feedback
Use environment variable HLSL_AGILITYSDK_DIR which you can point to
extracted contents of an AgilitySDK.
Automatically copy binaries to appropriate location when set.
Look for MinTe binary set from TAEF. If found, set a local TAEF binary
location.
If this is set when running execution tests, copy MinTe there, and if the
HLSL_AGILITYSDK_DIR was set, also copy agility SDK binaries under the
.\D3D12\ subdir there, so the test can automatically pick it up.
Add hctbins.cmd to copy extra bins necessary for running things out of
the ...\bin or ...\test directories such as HLSLHost.exe. This includes
AgilitySDK bins if set.
Update FindTAEF.cmake to set binary dir based on HLSL_TAEF_DIR
Since we don't actually support a single project building to multiple
architectures, we look for te.exe in x86 OR x64 subdir.
Whichever one is set in hctstart.cmd should be the one that will be used.