2017-12-21 00:45:38 +01:00
/*
2024-01-22 07:28:27 +00:00
* Copyright ( C ) 2018 - 2024 Intel Corporation
2017-12-21 00:45:38 +01:00
*
2018-09-18 09:11:08 +02:00
* SPDX - License - Identifier : MIT
2017-12-21 00:45:38 +01:00
*
*/
# pragma once
2024-02-07 16:19:02 +00:00
# include "shared/source/debug_settings/debug_settings_manager.h"
2020-02-23 22:44:01 +01:00
# include "shared/source/helpers/options.h"
2021-05-26 23:45:38 +02:00
# include "shared/source/os_interface/windows/d3dkmthk_wrapper.h"
2022-08-08 17:37:04 +00:00
# include "shared/source/os_interface/windows/gdi_interface_logging.h"
2024-02-07 16:19:02 +00:00
# include "shared/source/os_interface/windows/gdi_profiling.h"
2021-05-19 20:12:09 +00:00
# include "shared/source/os_interface/windows/windows_wrapper.h"
2020-02-23 22:44:01 +01:00
# include "shared/source/utilities/api_intercept.h"
2017-12-21 00:45:38 +01:00
2024-02-07 16:19:02 +00:00
# include <chrono>
# include <iostream>
# include <string>
2024-01-30 03:25:36 +01:00
2024-02-07 16:19:02 +00:00
namespace NEO {
2021-05-19 20:12:09 +00:00
2019-12-09 15:29:30 +01:00
template < typename Param >
2017-12-21 00:45:38 +01:00
class ThkWrapper {
typedef NTSTATUS ( APIENTRY * Func ) ( Param ) ;
2024-02-07 16:19:02 +00:00
GdiProfiler & profiler ;
const std : : string name { } ;
const uint32_t id { } ;
2017-12-21 00:45:38 +01:00
public :
2024-02-07 16:19:02 +00:00
ThkWrapper ( GdiProfiler & profiler , const char * name , uint32_t id ) : profiler ( profiler ) , name ( name ) , id ( id ) { } ;
2018-04-19 14:11:45 +02:00
Func mFunc = nullptr ;
2017-12-21 00:45:38 +01:00
inline NTSTATUS operator ( ) ( Param param ) const {
2024-02-07 16:19:02 +00:00
if constexpr ( GdiLogging : : gdiLoggingSupport ) {
2022-08-08 17:37:04 +00:00
GdiLogging : : logEnter < Param > ( param ) ;
2024-02-07 16:19:02 +00: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 05:41:28 +01:00
} else {
return mFunc ( param ) ;
2017-12-21 00:45:38 +01:00
}
}
2021-05-19 20:12:09 +00:00
ThkWrapper & operator = ( void * func ) {
mFunc = reinterpret_cast < decltype ( mFunc ) > ( func ) ;
return * this ;
2017-12-21 00:45:38 +01:00
}
2021-08-03 18:29:50 +02:00
ThkWrapper & operator = ( Func func ) {
mFunc = func ;
return * this ;
}
2017-12-21 00:45:38 +01: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-19 20:12:09 +00:00
2019-03-26 11:59:46 +01:00
} // namespace NEO