2017-12-21 07:45:38 +08:00
/*
2024-01-22 15:28:27 +08:00
* Copyright ( C ) 2018 - 2024 Intel Corporation
2017-12-21 07:45:38 +08:00
*
2018-09-18 15:11:08 +08:00
* SPDX - License - Identifier : MIT
2017-12-21 07:45:38 +08:00
*
*/
# pragma once
2024-02-08 00:19:02 +08:00
# include "shared/source/debug_settings/debug_settings_manager.h"
2020-02-24 05:44:01 +08:00
# include "shared/source/helpers/options.h"
2021-05-27 05:45:38 +08:00
# include "shared/source/os_interface/windows/d3dkmthk_wrapper.h"
2022-08-09 01:37:04 +08:00
# include "shared/source/os_interface/windows/gdi_interface_logging.h"
2024-02-08 00:19:02 +08:00
# include "shared/source/os_interface/windows/gdi_profiling.h"
2021-05-20 04:12:09 +08:00
# include "shared/source/os_interface/windows/windows_wrapper.h"
2020-02-24 05:44:01 +08:00
# include "shared/source/utilities/api_intercept.h"
2017-12-21 07:45:38 +08:00
2024-02-08 00:19:02 +08:00
# include <chrono>
# include <iostream>
# include <string>
2024-01-30 10:25:36 +08:00
2024-02-08 00:19:02 +08:00
namespace NEO {
2021-05-20 04:12:09 +08:00
2019-12-09 22:29:30 +08:00
template < typename Param >
2017-12-21 07:45:38 +08:00
class ThkWrapper {
typedef NTSTATUS ( APIENTRY * Func ) ( Param ) ;
2024-02-08 00:19:02 +08:00
GdiProfiler & profiler ;
const std : : string name { } ;
const uint32_t id { } ;
2017-12-21 07:45:38 +08:00
public :
2024-02-08 00:19:02 +08:00
ThkWrapper ( GdiProfiler & profiler , const char * name , uint32_t id ) : profiler ( profiler ) , name ( name ) , id ( id ) { } ;
2018-04-19 20:11:45 +08:00
Func mFunc = nullptr ;
2017-12-21 07:45:38 +08:00
inline NTSTATUS operator ( ) ( Param param ) const {
2024-02-08 00:19:02 +08:00
if constexpr ( GdiLogging : : gdiLoggingSupport ) {
2022-08-09 01:37:04 +08:00
GdiLogging : : logEnter < Param > ( param ) ;
2024-02-08 00:19:02 +08:00
auto measureTime = debugManager . flags . PrintKmdTimes . get ( ) ;
std : : chrono : : steady_clock : : time_point start ;
std : : chrono : : steady_clock : : time_point end ;
if ( measureTime ) {
start = std : : chrono : : steady_clock : : now ( ) ;
}
auto ret = mFunc ( param ) ;
if ( measureTime ) {
end = std : : chrono : : steady_clock : : now ( ) ;
long long elapsedTime = std : : chrono : : duration_cast < std : : chrono : : nanoseconds > ( end - start ) . count ( ) ;
profiler . recordElapsedTime ( elapsedTime , this - > name . c_str ( ) , this - > id ) ;
}
GdiLogging : : logExit < Param > ( ret , param ) ;
return ret ;
2024-01-23 12:41:28 +08:00
} else {
return mFunc ( param ) ;
2017-12-21 07:45:38 +08:00
}
}
2021-05-20 04:12:09 +08:00
ThkWrapper & operator = ( void * func ) {
mFunc = reinterpret_cast < decltype ( mFunc ) > ( func ) ;
return * this ;
2017-12-21 07:45:38 +08:00
}
2021-08-04 00:29:50 +08:00
ThkWrapper & operator = ( Func func ) {
mFunc = func ;
return * this ;
}
2017-12-21 07:45:38 +08:00
// This operator overload is for implicit casting ThkWrapper struct to Function Pointer in GetPfn methods like GetEscapePfn() or for comparing against NULL function pointer
operator Func ( ) const {
return mFunc ;
}
} ;
2021-05-20 04:12:09 +08:00
2019-03-26 18:59:46 +08:00
} // namespace NEO