File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111#include " param_validation.h"
1212#include < memory>
1313
14+ // Forward declaration — resolves at link time against ze_loader.so.
15+ extern " C" ZE_DLLEXPORT std::shared_ptr<loader::ZeLogger> *ZE_APICALL zelLoaderGetLogger ();
16+
1417namespace validation_layer
1518{
1619 context_t & context = context_t ::getInstance();
@@ -25,7 +28,18 @@ namespace validation_layer
2528 enableThreadingValidation = getenv_tobool ( " ZE_ENABLE_THREADING_VALIDATION" );
2629 verboseLogging = getenv_tobool ( " ZEL_LOADER_LOGGING_ENABLE_SUCCESS_PRINT" );
2730
28- logger = loader::createLogger (" Validation Layer" );
31+ // Prefer the loader's already-constructed logger so both components
32+ // share a single file handle, mutex, and startup banner.
33+ // Fall back to creating an independent logger (e.g. static build).
34+ #ifndef L0_STATIC_LOADER_BUILD
35+ auto *loaderLog = zelLoaderGetLogger ();
36+ if (loaderLog && *loaderLog) {
37+ logger = *loaderLog;
38+ } else
39+ #endif
40+ {
41+ logger = loader::createLogger (" Validation Layer" );
42+ }
2943 }
3044
3145 // /////////////////////////////////////////////////////////////////////////////
Original file line number Diff line number Diff line change @@ -59,6 +59,19 @@ zelLoaderGetContext() {
5959 return loader::context;
6060}
6161
62+ // /////////////////////////////////////////////////////////////////////////////
63+ // / @brief Get the loader's shared logger instance.
64+ // /
65+ ZE_DLLEXPORT std::shared_ptr<loader::ZeLogger> *ZE_APICALL
66+ zelLoaderGetLogger () {
67+ if (loader::context == nullptr )
68+ return nullptr ;
69+ auto &log = loader::context->zel_logger ;
70+ if (!log)
71+ return nullptr ;
72+ return &log;
73+ }
74+
6275// /////////////////////////////////////////////////////////////////////////////
6376// / @brief Internal function for Setting the ZE ddi table for the Tracing Layer.
6477// /
Original file line number Diff line number Diff line change @@ -61,10 +61,21 @@ zeLoaderGetTracingHandle();
6161// / @brief Get pointer to Loader Context
6262// /
6363// / @returns
64- // / - ::handle to tracing library
64+ // / - ::Pointer to the Loader's Context
6565ZE_DLLEXPORT loader::context_t *ZE_APICALL
6666zelLoaderGetContext ();
6767
68+ // /////////////////////////////////////////////////////////////////////////////
69+ // / @brief Get the loader's shared logger instance.
70+ // / Returns nullptr if the loader context is not yet initialized.
71+ // / Callers (e.g. the validation layer) should adopt this logger
72+ // / instead of creating their own to share a single file handle and mutex.
73+ // /
74+ // / @returns
75+ // / - ::Pointer to the shared ZeLogger, or nullptr
76+ ZE_DLLEXPORT std::shared_ptr<loader::ZeLogger> *ZE_APICALL
77+ zelLoaderGetLogger ();
78+
6879
6980// /////////////////////////////////////////////////////////////////////////////
7081// / @brief Exported function for getting version
You can’t perform that action at this time.
0 commit comments