diff --git a/runtime/gmm_helper/client_context/gmm_client_context.cpp b/runtime/gmm_helper/client_context/gmm_client_context.cpp index d08efe30f1..a4bae5a28e 100644 --- a/runtime/gmm_helper/client_context/gmm_client_context.cpp +++ b/runtime/gmm_helper/client_context/gmm_client_context.cpp @@ -23,5 +23,5 @@ #include "gmm_client_context.h" namespace OCLRT { -GmmClientContext::GmmClientContext(GMM_CLIENT clientType) : GmmClientContextBase(clientType){}; +GmmClientContext::GmmClientContext(GMM_CLIENT clientType, GmmExportEntries &gmmEntries) : GmmClientContextBase(clientType, gmmEntries){}; } // namespace OCLRT diff --git a/runtime/gmm_helper/client_context/gmm_client_context.h b/runtime/gmm_helper/client_context/gmm_client_context.h index 86ca5d0066..e3033e9048 100644 --- a/runtime/gmm_helper/client_context/gmm_client_context.h +++ b/runtime/gmm_helper/client_context/gmm_client_context.h @@ -26,6 +26,6 @@ namespace OCLRT { class GmmClientContext : public GmmClientContextBase { public: - GmmClientContext(GMM_CLIENT clientType); + GmmClientContext(GMM_CLIENT clientType, GmmExportEntries &gmmEntries); }; } // namespace OCLRT diff --git a/runtime/gmm_helper/client_context/gmm_client_context_base.cpp b/runtime/gmm_helper/client_context/gmm_client_context_base.cpp index ecb87bd83c..ce5368123c 100644 --- a/runtime/gmm_helper/client_context/gmm_client_context_base.cpp +++ b/runtime/gmm_helper/client_context/gmm_client_context_base.cpp @@ -23,11 +23,11 @@ #include "runtime/gmm_helper/client_context/gmm_client_context_base.h" namespace OCLRT { -GmmClientContextBase::GmmClientContextBase(GMM_CLIENT clientType) { - clientContext = GmmHelper::createClientContextFunc(clientType); +GmmClientContextBase::GmmClientContextBase(GMM_CLIENT clientType, GmmExportEntries &gmmEntries) : gmmEntries(gmmEntries) { + clientContext = gmmEntries.pfnCreateClientContext(clientType); } GmmClientContextBase::~GmmClientContextBase() { - GmmHelper::deleteClientContextFunc(clientContext); + gmmEntries.pfnDeleteClientContext(clientContext); }; MEMORY_OBJECT_CONTROL_STATE GmmClientContextBase::cachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE usage) { diff --git a/runtime/gmm_helper/client_context/gmm_client_context_base.h b/runtime/gmm_helper/client_context/gmm_client_context_base.h index 2f1de094b0..92c9e43f53 100644 --- a/runtime/gmm_helper/client_context/gmm_client_context_base.h +++ b/runtime/gmm_helper/client_context/gmm_client_context_base.h @@ -37,12 +37,13 @@ class GmmClientContextBase { MOCKABLE_VIRTUAL void destroyResInfoObject(GMM_RESOURCE_INFO *pResInfo); GMM_CLIENT_CONTEXT *getHandle() const; template - static std::unique_ptr create(GMM_CLIENT clientType) { - return std::make_unique(clientType); + static std::unique_ptr create(GMM_CLIENT clientType, GmmExportEntries &gmmEntries) { + return std::make_unique(clientType, gmmEntries); } protected: GMM_CLIENT_CONTEXT *clientContext; - GmmClientContextBase(GMM_CLIENT clientType); + GmmClientContextBase(GMM_CLIENT clientType, GmmExportEntries &gmmEntries); + GmmExportEntries &gmmEntries; }; } // namespace OCLRT diff --git a/runtime/gmm_helper/gmm_helper.cpp b/runtime/gmm_helper/gmm_helper.cpp index 9a52133841..033bcbe359 100644 --- a/runtime/gmm_helper/gmm_helper.cpp +++ b/runtime/gmm_helper/gmm_helper.cpp @@ -54,9 +54,9 @@ void GmmHelper::initContext(const PLATFORM *pPlatform, SkuInfoTransfer::transferFtrTableForGmm(&gmmFtrTable, pSkuTable); SkuInfoTransfer::transferWaTableForGmm(&gmmWaTable, pWaTable); loadLib(); - bool success = GMM_SUCCESS == GmmHelper::initGlobalContextFunc(*pPlatform, &gmmFtrTable, &gmmWaTable, pGtSysInfo); + bool success = GMM_SUCCESS == gmmEntries.pfnCreateSingletonContext(*pPlatform, &gmmFtrTable, &gmmWaTable, pGtSysInfo); UNRECOVERABLE_IF(!success); - gmmClientContext = GmmHelper::createGmmContextWrapperFunc(GMM_CLIENT::GMM_OCL_VISTA); + gmmClientContext = GmmHelper::createGmmContextWrapperFunc(GMM_CLIENT::GMM_OCL_VISTA, gmmEntries); UNRECOVERABLE_IF(!gmmClientContext); } @@ -164,7 +164,7 @@ GmmHelper::GmmHelper(const HardwareInfo *pHwInfo) { initContext(pHwInfo->pPlatform, pHwInfo->pSkuTable, pHwInfo->pWaTable, pHwInfo->pSysInfo); } GmmHelper::~GmmHelper() { - GmmHelper::destroyGlobalContextFunc(); + gmmEntries.pfnDestroySingletonContext(); }; bool GmmHelper::useSimplifiedMocsTable = false; decltype(GmmHelper::createGmmContextWrapperFunc) GmmHelper::createGmmContextWrapperFunc = GmmClientContextBase::create; diff --git a/runtime/gmm_helper/gmm_helper.h b/runtime/gmm_helper/gmm_helper.h index 32795d126b..ecea812395 100644 --- a/runtime/gmm_helper/gmm_helper.h +++ b/runtime/gmm_helper/gmm_helper.h @@ -63,12 +63,7 @@ class GmmHelper { static uint32_t getRenderMultisamplesCount(uint32_t numSamples); static GMM_YUV_PLANE convertPlane(OCLPlane oclPlane); - static decltype(GmmExportEntries::pfnCreateSingletonContext) initGlobalContextFunc; - static decltype(GmmExportEntries::pfnDestroySingletonContext) destroyGlobalContextFunc; - static decltype(GmmExportEntries::pfnCreateClientContext) createClientContextFunc; - static decltype(GmmExportEntries::pfnDeleteClientContext) deleteClientContextFunc; - - static std::unique_ptr (*createGmmContextWrapperFunc)(GMM_CLIENT); + static std::unique_ptr (*createGmmContextWrapperFunc)(GMM_CLIENT, GmmExportEntries &); static bool useSimplifiedMocsTable; static const HardwareInfo *hwInfo; @@ -79,5 +74,6 @@ class GmmHelper { std::unique_ptr gmmLib; std::unique_ptr gmmClientContext; + GmmExportEntries gmmEntries = {}; }; } // namespace OCLRT diff --git a/runtime/gmm_helper/gmm_interface_dynamic.cpp b/runtime/gmm_helper/gmm_interface_dynamic.cpp index 1277433d4c..d6bca4503e 100644 --- a/runtime/gmm_helper/gmm_interface_dynamic.cpp +++ b/runtime/gmm_helper/gmm_interface_dynamic.cpp @@ -30,10 +30,6 @@ extern const char *gmmEntryName; } // namespace Os namespace OCLRT { -decltype(GmmHelper::initGlobalContextFunc) GmmHelper::initGlobalContextFunc = nullptr; -decltype(GmmHelper::destroyGlobalContextFunc) GmmHelper::destroyGlobalContextFunc = nullptr; -decltype(GmmHelper::createClientContextFunc) GmmHelper::createClientContextFunc = nullptr; -decltype(GmmHelper::deleteClientContextFunc) GmmHelper::deleteClientContextFunc = nullptr; void GmmHelper::loadLib() { gmmLib.reset(OsLibrary::load(Os::gmmDllName)); @@ -41,14 +37,12 @@ void GmmHelper::loadLib() { UNRECOVERABLE_IF(!gmmLib); if (gmmLib->isLoaded()) { auto openGmmFunc = reinterpret_cast(gmmLib->getProcAddress(Os::gmmEntryName)); - GmmExportEntries entries; - auto status = openGmmFunc(&entries); + auto status = openGmmFunc(&gmmEntries); if (status == GMM_SUCCESS) { - GmmHelper::initGlobalContextFunc = entries.pfnCreateSingletonContext; - GmmHelper::destroyGlobalContextFunc = entries.pfnDestroySingletonContext; - GmmHelper::createClientContextFunc = entries.pfnCreateClientContext; - GmmHelper::deleteClientContextFunc = entries.pfnDeleteClientContext; - isLoaded = GmmHelper::initGlobalContextFunc && GmmHelper::destroyGlobalContextFunc && GmmHelper::createClientContextFunc && GmmHelper::deleteClientContextFunc; + isLoaded = gmmEntries.pfnCreateClientContext && + gmmEntries.pfnCreateSingletonContext && + gmmEntries.pfnDeleteClientContext && + gmmEntries.pfnDestroySingletonContext; } } UNRECOVERABLE_IF(!isLoaded); diff --git a/runtime/gmm_helper/gmm_interface_static.cpp b/runtime/gmm_helper/gmm_interface_static.cpp index 53c9ed2e5d..ca71cba9a4 100644 --- a/runtime/gmm_helper/gmm_interface_static.cpp +++ b/runtime/gmm_helper/gmm_interface_static.cpp @@ -26,15 +26,11 @@ namespace OCLRT { GMM_STATUS GMM_STDCALL myPfnCreateSingletonContext(const PLATFORM platform, const void *pSkuTable, const void *pWaTable, const void *pGtSysInfo) { return GmmInitGlobalContext(platform, reinterpret_cast(pSkuTable), reinterpret_cast(pWaTable), reinterpret_cast(pGtSysInfo), GMM_CLIENT::GMM_OCL_VISTA); } -decltype(GmmHelper::initGlobalContextFunc) GmmHelper::initGlobalContextFunc = nullptr; -decltype(GmmHelper::destroyGlobalContextFunc) GmmHelper::destroyGlobalContextFunc = nullptr; -decltype(GmmHelper::createClientContextFunc) GmmHelper::createClientContextFunc = nullptr; -decltype(GmmHelper::deleteClientContextFunc) GmmHelper::deleteClientContextFunc = nullptr; void GmmHelper::loadLib() { - GmmHelper::initGlobalContextFunc = myPfnCreateSingletonContext; - GmmHelper::destroyGlobalContextFunc = GmmDestroyGlobalContext; - GmmHelper::createClientContextFunc = GmmCreateClientContext; - GmmHelper::deleteClientContextFunc = GmmDeleteClientContext; + gmmEntries.pfnCreateSingletonContext = myPfnCreateSingletonContext; + gmmEntries.pfnDestroySingletonContext = GmmDestroyGlobalContext; + gmmEntries.pfnCreateClientContext = GmmCreateClientContext; + gmmEntries.pfnDeleteClientContext = GmmDeleteClientContext; } } // namespace OCLRT diff --git a/unit_tests/mocks/mock_gmm_client_context.cpp b/unit_tests/mocks/mock_gmm_client_context.cpp index ab93bc9d51..eeca8aee29 100644 --- a/unit_tests/mocks/mock_gmm_client_context.cpp +++ b/unit_tests/mocks/mock_gmm_client_context.cpp @@ -23,6 +23,6 @@ #include "mock_gmm_client_context.h" namespace OCLRT { -MockGmmClientContext::MockGmmClientContext(GMM_CLIENT clientType) : MockGmmClientContextBase(clientType) { +MockGmmClientContext::MockGmmClientContext(GMM_CLIENT clientType, GmmExportEntries &gmmExportEntries) : MockGmmClientContextBase(clientType, gmmExportEntries) { } } // namespace OCLRT diff --git a/unit_tests/mocks/mock_gmm_client_context.h b/unit_tests/mocks/mock_gmm_client_context.h index a7ca0d0a5a..ba7ee14180 100644 --- a/unit_tests/mocks/mock_gmm_client_context.h +++ b/unit_tests/mocks/mock_gmm_client_context.h @@ -26,6 +26,6 @@ namespace OCLRT { class MockGmmClientContext : public MockGmmClientContextBase { public: - MockGmmClientContext(GMM_CLIENT clientType); + MockGmmClientContext(GMM_CLIENT clientType, GmmExportEntries &gmmExportEntries); }; } // namespace OCLRT diff --git a/unit_tests/mocks/mock_gmm_client_context_base.cpp b/unit_tests/mocks/mock_gmm_client_context_base.cpp index 5b886aeecf..c5aca9c664 100644 --- a/unit_tests/mocks/mock_gmm_client_context_base.cpp +++ b/unit_tests/mocks/mock_gmm_client_context_base.cpp @@ -23,7 +23,7 @@ #include "unit_tests/mocks/mock_gmm_client_context.h" namespace OCLRT { -MockGmmClientContextBase::MockGmmClientContextBase(GMM_CLIENT clientType) : GmmClientContext(clientType) { +MockGmmClientContextBase::MockGmmClientContextBase(GMM_CLIENT clientType, GmmExportEntries &gmmExportEntries) : GmmClientContext(clientType, gmmExportEntries) { } MEMORY_OBJECT_CONTROL_STATE MockGmmClientContextBase::cachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE usage) { diff --git a/unit_tests/mocks/mock_gmm_client_context_base.h b/unit_tests/mocks/mock_gmm_client_context_base.h index 8ae1f1406b..b1a180cabe 100644 --- a/unit_tests/mocks/mock_gmm_client_context_base.h +++ b/unit_tests/mocks/mock_gmm_client_context_base.h @@ -32,6 +32,6 @@ class MockGmmClientContextBase : public GmmClientContext { void destroyResInfoObject(GMM_RESOURCE_INFO *pResInfo) override; protected: - MockGmmClientContextBase(GMM_CLIENT clientType); + MockGmmClientContextBase(GMM_CLIENT clientType, GmmExportEntries &gmmExportEntries); }; } // namespace OCLRT