@@ -22,6 +22,17 @@ using namespace loader_driver_ddi;
2222
2323namespace loader
2424{
25+ __${ x} dlllocal ze_result_t ${ X} _APICALL
26+ ${ n} loaderInitDriverDDITables(loader::driver_t *driver) {
27+ ze_result_t result = ZE_RESULT_SUCCESS;
28+ % for tbl in th.get_pfntables(specs, meta, n, tags):
29+ result = ${ tbl[' export' ][' name' ]} FromDriver(driver);
30+ if (result != ZE_RESULT_SUCCESS) {
31+ return result;
32+ }
33+ %endfor
34+ return result;
35+ }
2536 % for obj in th.extract_objs(specs, r " function" ):
2637 <%
2738 ret_type = obj[' return_type' ]
@@ -65,6 +76,14 @@ namespace loader
6576 if(drv.initStatus != ZE_RESULT_SUCCESS)
6677 continue;
6778 %endif
79+ if (!drv.handle) {
80+ % if namespace != " zes" :
81+ bool sysmanInit = false;
82+ % else :
83+ bool sysmanInit = true;
84+ %endif
85+ loader::context->init_driver( drv, flags, nullptr, nullptr, nullptr, sysmanInit );
86+ }
6887 % if re.match(r " Init" , obj[' name' ]) and namespace == " zes" :
6988 if (!drv.dditable.${ n} .${ th.get_table_name(n, tags, obj)} .${ th.make_pfn_name(n, tags, obj)} ) {
7089 drv.initSysManStatus = ZE_RESULT_ERROR_UNINITIALIZED;
@@ -90,6 +109,13 @@ namespace loader
90109
91110 % elif re.match(r " \w + DriverGet$ " , th.make_func_name(n, tags, obj)) or re.match(r " \w + InitDrivers$ " , th.make_func_name(n, tags, obj)):
92111 uint32_t total_driver_handle_count = 0;
112+ % if re.match(r " \w + InitDrivers$ " , th.make_func_name(n, tags, obj)):
113+ for( auto& drv : loader::context->zeDrivers ) {
114+ if (!drv.handle) {
115+ loader::context->init_driver( drv, 0, desc, nullptr, nullptr, false );
116+ }
117+ }
118+ %endif
93119
94120 {
95121 std::lock_guard<std::mutex > lock(loader::context->sortMutex);
@@ -495,6 +521,52 @@ ${tbl['export']['name']}Legacy()
495521
496522%endfor
497523
524+ % for tbl in th.get_pfntables(specs, meta, n, tags):
525+ ///////////////////////////////////////////////////////////////////////////////
526+ /// @brief Exported function for filling application's ${ tbl[' name' ]} table
527+ /// with current process' addresses
528+ ///
529+ /// @returns
530+ /// - ::${ X} _RESULT_SUCCESS
531+ /// - ::${ X} _RESULT_ERROR_UNINITIALIZED
532+ /// - ::${ X} _RESULT_ERROR_INVALID_NULL_POINTER
533+ /// - ::${ X} _RESULT_ERROR_UNSUPPORTED_VERSION
534+ __${ x} dlllocal ${ x} _result_t ${ X} _APICALL
535+ ${ tbl[' export' ][' name' ]} FromDriver(loader::driver_t *driver)
536+ {
537+ ${ x} _result_t result = ${ X} _RESULT_SUCCESS;
538+ if(driver->initStatus != ZE_RESULT_SUCCESS)
539+ return driver->initStatus;
540+ auto getTable = reinterpret_cast<${ tbl[' pfn' ]} >(
541+ GET_FUNCTION_PTR( driver->handle, "${ tbl[' export' ][' name' ]} ") );
542+ if(!getTable)
543+ % if th.isNewProcTable(tbl[' export' ][' name' ]) is True :
544+ {
545+ //It is valid to not have this proc addr table
546+ return ${ X} _RESULT_SUCCESS;
547+ }
548+ % else :
549+ return driver->initStatus;
550+ %endif
551+ % if tbl[' experimental' ] is False : # //Experimental Tables may not be implemented in driver
552+ auto getTableResult = getTable( loader::context->ddi_init_version, &driver->dditable.${ n} .${ tbl[' name' ]} );
553+ if(getTableResult == ZE_RESULT_SUCCESS) {
554+ loader::context->configured_version = loader::context->ddi_init_version;
555+ } else
556+ driver->initStatus = getTableResult;
557+ % if namespace != " zes" :
558+ % if tbl[' name' ] == " Global" :
559+ if (driver->dditable.ze.Global.pfnInitDrivers) {
560+ loader::context->initDriversSupport = true;
561+ }
562+ %endif
563+ %endif
564+ % else :
565+ result = getTable( loader::context->ddi_init_version, &driver->dditable.${ n} .${ tbl[' name' ]} );
566+ %endif
567+ return result;
568+ }
569+ %endfor
498570% for tbl in th.get_pfntables(specs, meta, n, tags):
499571///////////////////////////////////////////////////////////////////////////////
500572/// @brief Exported function for filling application's ${ tbl[' name' ]} table
@@ -526,63 +598,17 @@ ${tbl['export']['name']}(
526598 if( loader::context->version < version )
527599 return ${ X} _RESULT_ERROR_UNSUPPORTED_VERSION;
528600
529- ${ x} _result_t result = ${ X} _RESULT_SUCCESS;
530-
531- % if tbl[' experimental' ] is False : # //Experimental Tables may not be implemented in driver
532- bool atLeastOneDriverValid = false;
533- %endif
534- // Load the device-driver DDI tables
535- % if namespace != " zes" :
536- for( auto& drv : loader::context->zeDrivers )
537- % else :
538- for( auto& drv : *loader::context->sysmanInstanceDrivers )
539- %endif
540- {
541- if(drv.initStatus != ZE_RESULT_SUCCESS)
542- continue;
543- auto getTable = reinterpret_cast<${ tbl[' pfn' ]} >(
544- GET_FUNCTION_PTR( drv.handle, "${ tbl[' export' ][' name' ]} ") );
545- if(!getTable)
546- % if th.isNewProcTable(tbl[' export' ][' name' ]) is True :
547- {
548- atLeastOneDriverValid = true;
549- //It is valid to not have this proc addr table
550- continue;
551- }
552- % else :
553- continue;
554- %endif
555- % if tbl[' experimental' ] is False : # //Experimental Tables may not be implemented in driver
556- auto getTableResult = getTable( version, &drv.dditable.${ n} .${ tbl[' name' ]} );
557- if(getTableResult == ZE_RESULT_SUCCESS) {
558- atLeastOneDriverValid = true;
559- loader::context->configured_version = version;
560- } else
561- drv.initStatus = getTableResult;
562- % if namespace != " zes" :
563- % if tbl[' name' ] == " Global" :
564- if (drv.dditable.ze.Global.pfnInitDrivers) {
565- loader::context->initDriversSupport = true;
566- }
567- %endif
568- %endif
569- % else :
570- result = getTable( version, &drv.dditable.${ n} .${ tbl[' name' ]} );
571- %endif
572- }
601+ loader::context->ddi_init_version = version;
573602
574- % if tbl[' experimental' ] is False : # //Experimental Tables may not be implemented in driver
575- if(!atLeastOneDriverValid)
576- result = ${ X} _RESULT_ERROR_UNINITIALIZED;
577- else
578- result = ${ X} _RESULT_SUCCESS;
579- %endif
603+ ${ x} _result_t result = ${ X} _RESULT_SUCCESS;
580604
581605 if( ${ X} _RESULT_SUCCESS == result )
582606 {
583- % if namespace != " zes" :
607+ % if tbl[' name' ] == " Global" :
608+ if( true )
609+ % elif namespace != " zes" :
584610 if( ( loader::context->zeDrivers.size() > 1 ) || loader::context->forceIntercept )
585- % else :
611+ % elif namespace == " zes " :
586612 if( ( loader::context->sysmanInstanceDrivers->size() > 1 ) || loader::context->forceIntercept )
587613 %endif
588614 {
0 commit comments