From 62b74063e55ea1f53aa46396556d7d7214daa77c Mon Sep 17 00:00:00 2001 From: AnastaZIuk Date: Fri, 28 Mar 2025 09:27:07 +0100 Subject: [PATCH] Make Event Tracing for Windows optional and allow to build dxcompiler target with ETW disabled --- CMakeLists.txt | 7 ++++ include/dxc/WinAdapter.h | 15 ++------- include/dxc/WinEtwAdapter.h | 33 +++++++++++++++++++ projects/dxilconv/tools/dxilconv/dxilconv.cpp | 4 +++ tools/clang/tools/dxcompiler/CMakeLists.txt | 3 +- tools/clang/tools/dxcompiler/DXCompiler.cpp | 4 +++ tools/clang/tools/dxcompiler/DXCompiler.rc | 2 ++ tools/clang/tools/dxcompiler/dxcapi.cpp | 4 +++ .../clang/tools/dxcompiler/dxcompilerobj.cpp | 4 +++ .../clang/tools/dxcvalidator/dxcvalidator.cpp | 4 +++ tools/clang/tools/dxildll/dxildll.cpp | 4 +++ .../tools/dxrfallbackcompiler/DXCompiler.cpp | 4 +++ .../tools/dxrfallbackcompiler/DXCompiler.rc | 2 ++ .../tools/dxrfallbackcompiler/dxcapi.cpp | 4 +++ 14 files changed, 80 insertions(+), 14 deletions(-) create mode 100644 include/dxc/WinEtwAdapter.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 74244c1d58..52adf4f721 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,6 +107,13 @@ mark_as_advanced(DXC_DISABLE_ALLOCATOR_OVERRIDES) option(DXC_CODEGEN_EXCEPTIONS_TRAP "An exception in code generation generates a trap, ending the compiler process" OFF) mark_as_advanced(DXC_CODEGEN_EXCEPTIONS_TRAP) +option(DXC_ENABLE_ETW "Compile with ETW Tracing" ON) +mark_as_advanced(DXC_ENABLE_ETW) + +if(DXC_ENABLE_ETW) + add_compile_definitions(DXC_ENABLE_ETW) +endif() + # adjust link option to enable debugging from kernel mode; not compatible with incremental linking if(NOT CMAKE_VERSION VERSION_LESS "3.13" AND MSVC AND NOT CMAKE_C_COMPILER_ARCHITECTURE_ID STREQUAL "ARM64EC") add_link_options(/DEBUGTYPE:CV,FIXUP,PDATA /INCREMENTAL:NO) diff --git a/include/dxc/WinAdapter.h b/include/dxc/WinAdapter.h index b8c6646871..6c7fa25458 100644 --- a/include/dxc/WinAdapter.h +++ b/include/dxc/WinAdapter.h @@ -197,19 +197,8 @@ #define OutputDebugStringA(msg) fputs(msg, stderr) #define OutputDebugFormatA(...) fprintf(stderr, __VA_ARGS__) -// Event Tracing for Windows (ETW) provides application programmers the ability -// to start and stop event tracing sessions, instrument an application to -// provide trace events, and consume trace events. -#define DxcEtw_DXCompilerCreateInstance_Start() -#define DxcEtw_DXCompilerCreateInstance_Stop(hr) -#define DxcEtw_DXCompilerCompile_Start() -#define DxcEtw_DXCompilerCompile_Stop(hr) -#define DxcEtw_DXCompilerDisassemble_Start() -#define DxcEtw_DXCompilerDisassemble_Stop(hr) -#define DxcEtw_DXCompilerPreprocess_Start() -#define DxcEtw_DXCompilerPreprocess_Stop(hr) -#define DxcEtw_DxcValidation_Start() -#define DxcEtw_DxcValidation_Stop(hr) +// I have no idea if I don't break something like INSTALL targets, requires CI tests +#include "WinEtwAdapter.h" #define UInt32Add UIntAdd #define Int32ToUInt32 IntToUInt diff --git a/include/dxc/WinEtwAdapter.h b/include/dxc/WinEtwAdapter.h new file mode 100644 index 0000000000..67771d6c6c --- /dev/null +++ b/include/dxc/WinEtwAdapter.h @@ -0,0 +1,33 @@ +//===- WinEtwAdapter.h - Windows ETW Adapter, stub -*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_SUPPORT_WIN_ETW_ADAPTER_H +#define LLVM_SUPPORT_WIN_ETW_ADAPTER_H + +// Event Tracing for Windows (ETW) provides application programmers the ability +// to start and stop event tracing sessions, instrument an application to +// provide trace events, and consume trace events. +#define EventRegisterMicrosoft_Windows_DXCompiler_API() +#define EventUnregisterMicrosoft_Windows_DXCompiler_API() +#define DxcEtw_DXCompilerCreateInstance_Start() +#define DxcEtw_DXCompilerCreateInstance_Stop(hr) +#define DxcEtw_DXCompilerInitialization_Start() +#define DxcEtw_DXCompilerInitialization_Stop(hr) +#define DxcEtw_DXCompilerShutdown_Start() +#define DxcEtw_DXCompilerShutdown_Stop(hr) +#define DxcEtw_DXCompilerCompile_Start() +#define DxcEtw_DXCompilerCompile_Stop(hr) +#define DxcEtw_DXCompilerDisassemble_Start() +#define DxcEtw_DXCompilerDisassemble_Stop(hr) +#define DxcEtw_DXCompilerPreprocess_Start() +#define DxcEtw_DXCompilerPreprocess_Stop(hr) +#define DxcEtw_DxcValidation_Start() +#define DxcEtw_DxcValidation_Stop(hr) + +#endif // LLVM_SUPPORT_WIN_ETW_ADAPTER_H diff --git a/projects/dxilconv/tools/dxilconv/dxilconv.cpp b/projects/dxilconv/tools/dxilconv/dxilconv.cpp index 73d7f3df0e..f8dea8aa0e 100644 --- a/projects/dxilconv/tools/dxilconv/dxilconv.cpp +++ b/projects/dxilconv/tools/dxilconv/dxilconv.cpp @@ -23,7 +23,11 @@ #include "dxc/config.h" #include "dxc/dxcisense.h" #include "dxc/dxctools.h" +#ifdef DXC_ENABLE_ETW #include "dxcetw.h" +#else +#include "dxc/WinEtwAdapter.h" +#endif // DXC_ENABLE_ETW #include "DxbcConverter.h" diff --git a/tools/clang/tools/dxcompiler/CMakeLists.txt b/tools/clang/tools/dxcompiler/CMakeLists.txt index c69e276194..513045669c 100644 --- a/tools/clang/tools/dxcompiler/CMakeLists.txt +++ b/tools/clang/tools/dxcompiler/CMakeLists.txt @@ -128,7 +128,8 @@ endif (MSVC) add_clang_library(dxcompiler SHARED ${SOURCES}) add_dependencies(dxcompiler TablegenHLSLOptions) -if (MSVC) + +if (MSVC AND DXC_ENABLE_ETW) # No DxcEtw on non-Windows platforms. add_dependencies(dxcompiler DxcEtw) endif() diff --git a/tools/clang/tools/dxcompiler/DXCompiler.cpp b/tools/clang/tools/dxcompiler/DXCompiler.cpp index c548441449..b502bba398 100644 --- a/tools/clang/tools/dxcompiler/DXCompiler.cpp +++ b/tools/clang/tools/dxcompiler/DXCompiler.cpp @@ -17,7 +17,11 @@ #include "llvm/Support/FileSystem.h" #include "llvm/Support/ManagedStatic.h" #ifdef LLVM_ON_WIN32 +#ifdef DXC_ENABLE_ETW #include "dxcetw.h" +#else +#include "dxc/WinEtwAdapter.h" +#endif // DXC_ENABLE_ETW #endif #include "dxillib.h" diff --git a/tools/clang/tools/dxcompiler/DXCompiler.rc b/tools/clang/tools/dxcompiler/DXCompiler.rc index 4bec9e092e..b79f272e37 100644 --- a/tools/clang/tools/dxcompiler/DXCompiler.rc +++ b/tools/clang/tools/dxcompiler/DXCompiler.rc @@ -11,4 +11,6 @@ #define VER_ORIGINALFILENAME_STR "DXCompiler.dll" // #include +#ifdef DXC_ENABLE_ETW #include "dxcetw.rc" +#endif \ No newline at end of file diff --git a/tools/clang/tools/dxcompiler/dxcapi.cpp b/tools/clang/tools/dxcompiler/dxcapi.cpp index a6a877cba4..a0736633ed 100644 --- a/tools/clang/tools/dxcompiler/dxcapi.cpp +++ b/tools/clang/tools/dxcompiler/dxcapi.cpp @@ -22,7 +22,11 @@ #include "dxc/dxcisense.h" #include "dxc/dxctools.h" #ifdef _WIN32 +#ifdef DXC_ENABLE_ETW #include "dxcetw.h" +#else +#include "dxc/WinEtwAdapter.h" +#endif // DXC_ENABLE_ETW #endif #include "dxc/DxilContainer/DxcContainerBuilder.h" #include "dxillib.h" diff --git a/tools/clang/tools/dxcompiler/dxcompilerobj.cpp b/tools/clang/tools/dxcompiler/dxcompilerobj.cpp index ebeee380ef..6f4c5c0ea7 100644 --- a/tools/clang/tools/dxcompiler/dxcompilerobj.cpp +++ b/tools/clang/tools/dxcompiler/dxcompilerobj.cpp @@ -51,7 +51,11 @@ #include "dxc/Support/microcom.h" #ifdef _WIN32 +#ifdef DXC_ENABLE_ETW #include "dxcetw.h" +#else +#include "dxc/WinEtwAdapter.h" +#endif // DXC_ENABLE_ETW #endif #include "dxcompileradapter.h" #include "dxcshadersourceinfo.h" diff --git a/tools/clang/tools/dxcvalidator/dxcvalidator.cpp b/tools/clang/tools/dxcvalidator/dxcvalidator.cpp index 60ad35036f..ddcbdc357d 100644 --- a/tools/clang/tools/dxcvalidator/dxcvalidator.cpp +++ b/tools/clang/tools/dxcvalidator/dxcvalidator.cpp @@ -27,7 +27,11 @@ #include "dxc/Support/dxcapi.impl.h" #ifdef _WIN32 +#ifdef DXC_ENABLE_ETW #include "dxcetw.h" +#else +#include "dxc/WinEtwAdapter.h" +#endif // DXC_ENABLE_ETW #endif using namespace llvm; diff --git a/tools/clang/tools/dxildll/dxildll.cpp b/tools/clang/tools/dxildll/dxildll.cpp index 12ca2026ca..51c7aa66f6 100644 --- a/tools/clang/tools/dxildll/dxildll.cpp +++ b/tools/clang/tools/dxildll/dxildll.cpp @@ -23,8 +23,12 @@ #include "llvm/Support/ManagedStatic.h" #include #ifdef _WIN32 +#ifdef DXC_ENABLE_ETW #include "Tracing/DxcRuntimeEtw.h" #include "dxc/Tracing/dxcetw.h" +#else +#include "dxc/WinEtwAdapter.h" +#endif // DXC_ENABLE_ETW #endif #include "dxc/dxcisense.h" diff --git a/tools/clang/tools/dxrfallbackcompiler/DXCompiler.cpp b/tools/clang/tools/dxrfallbackcompiler/DXCompiler.cpp index 018bf1cf4a..bb703489fd 100644 --- a/tools/clang/tools/dxrfallbackcompiler/DXCompiler.cpp +++ b/tools/clang/tools/dxrfallbackcompiler/DXCompiler.cpp @@ -14,7 +14,11 @@ #include "dxc/Support/Global.h" #include "dxc/Support/HLSLOptions.h" #include "dxc/config.h" +#ifdef DXC_ENABLE_ETW #include "dxcetw.h" +#else +#include "dxc/WinEtwAdapter.h" +#endif // DXC_ENABLE_ETW #include "dxillib.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/ManagedStatic.h" diff --git a/tools/clang/tools/dxrfallbackcompiler/DXCompiler.rc b/tools/clang/tools/dxrfallbackcompiler/DXCompiler.rc index 5fedc5d4c4..63d45c8214 100644 --- a/tools/clang/tools/dxrfallbackcompiler/DXCompiler.rc +++ b/tools/clang/tools/dxrfallbackcompiler/DXCompiler.rc @@ -11,4 +11,6 @@ #define VER_ORIGINALFILENAME_STR "DxrFallbackCompiler.dll" // #include +#ifdef DXC_ENABLE_ETW #include "dxcetw.rc" +#endif diff --git a/tools/clang/tools/dxrfallbackcompiler/dxcapi.cpp b/tools/clang/tools/dxrfallbackcompiler/dxcapi.cpp index f640ee6f47..9807956f52 100644 --- a/tools/clang/tools/dxrfallbackcompiler/dxcapi.cpp +++ b/tools/clang/tools/dxrfallbackcompiler/dxcapi.cpp @@ -16,7 +16,11 @@ #include "dxc/Support/Global.h" #include "dxc/dxcdxrfallbackcompiler.h" #include "dxc/dxctools.h" +#ifdef DXC_ENABLE_ETW #include "dxcetw.h" +#else +#include "dxc/WinEtwAdapter.h" +#endif // DXC_ENABLE_ETW #include HRESULT CreateDxcDxrFallbackCompiler(REFIID riid, LPVOID *ppv);