diff --git a/shared/source/gmm_helper/client_context/gmm_client_context.cpp b/shared/source/gmm_helper/client_context/gmm_client_context.cpp index 2f50c2a247..a801675e88 100644 --- a/shared/source/gmm_helper/client_context/gmm_client_context.cpp +++ b/shared/source/gmm_helper/client_context/gmm_client_context.cpp @@ -17,7 +17,10 @@ #include "shared/source/sku_info/operations/sku_info_transfer.h" namespace NEO { -GmmClientContext::GmmClientContext(const RootDeviceEnvironment &rootDeviceEnvironment) { +GmmClientContext::GmmClientContext() = default; +GmmClientContext::~GmmClientContext() = default; + +void GmmClientContext::initialize(const RootDeviceEnvironment &rootDeviceEnvironment) { auto hardwareInfo = rootDeviceEnvironment.getHardwareInfo(); _SKU_FEATURE_TABLE gmmFtrTable = {}; _WA_TABLE gmmWaTable = {}; @@ -46,14 +49,13 @@ GmmClientContext::GmmClientContext(const RootDeviceEnvironment &rootDeviceEnviro UNRECOVERABLE_IF(ret != GMM_SUCCESS); - clientContext = outArgs.pGmmClientContext; + auto deleter = [](auto clientContextHandle) { + GMM_INIT_OUT_ARGS outArgs; + outArgs.pGmmClientContext = clientContextHandle; + GmmInterface::destroy(&outArgs); + }; + clientContext = {outArgs.pGmmClientContext, deleter}; } -GmmClientContext::~GmmClientContext() { - GMM_INIT_OUT_ARGS outArgs; - outArgs.pGmmClientContext = clientContext; - - GmmInterface::destroy(&outArgs); -}; MEMORY_OBJECT_CONTROL_STATE GmmClientContext::cachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE usage) { return clientContext->CachePolicyGetMemoryObject(pResInfo, usage); @@ -72,7 +74,7 @@ void GmmClientContext::destroyResInfoObject(GMM_RESOURCE_INFO *pResInfo) { } GMM_CLIENT_CONTEXT *GmmClientContext::getHandle() const { - return clientContext; + return clientContext.get(); } uint8_t GmmClientContext::getSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT format) { diff --git a/shared/source/gmm_helper/client_context/gmm_client_context.h b/shared/source/gmm_helper/client_context/gmm_client_context.h index 5d4b2bd505..a2c23416fb 100644 --- a/shared/source/gmm_helper/client_context/gmm_client_context.h +++ b/shared/source/gmm_helper/client_context/gmm_client_context.h @@ -8,6 +8,7 @@ #pragma once #include "shared/source/gmm_helper/gmm_lib.h" +#include #include namespace NEO { @@ -20,8 +21,9 @@ class DeallocateGmm; class GmmClientContext { public: - GmmClientContext(const RootDeviceEnvironment &rootDeviceEnvironment); + GmmClientContext(); MOCKABLE_VIRTUAL ~GmmClientContext(); + MOCKABLE_VIRTUAL void initialize(const RootDeviceEnvironment &rootDeviceEnvironment); MOCKABLE_VIRTUAL MEMORY_OBJECT_CONTROL_STATE cachePolicyGetMemoryObject(GMM_RESOURCE_INFO *pResInfo, GMM_RESOURCE_USAGE_TYPE usage); MOCKABLE_VIRTUAL uint32_t cachePolicyGetPATIndex(GMM_RESOURCE_INFO *gmmResourceInfo, GMM_RESOURCE_USAGE_TYPE usage, bool compressed, bool cacheable); @@ -35,7 +37,9 @@ class GmmClientContext { GMM_CLIENT_CONTEXT *getHandle() const; template static std::unique_ptr create(const RootDeviceEnvironment &rootDeviceEnvironment) { - return std::make_unique(rootDeviceEnvironment); + auto retVal = std::make_unique(); + retVal->initialize(rootDeviceEnvironment); + return retVal; } MOCKABLE_VIRTUAL uint8_t getSurfaceStateCompressionFormat(GMM_RESOURCE_FORMAT format); @@ -50,7 +54,7 @@ class GmmClientContext { } protected: - GMM_CLIENT_CONTEXT *clientContext; + std::unique_ptr> clientContext; std::unique_ptr handleAllocator; }; } // namespace NEO diff --git a/shared/test/unit_test/gmm_helper/gmm_resource_info_drm_or_wddm_tests.cpp b/shared/test/unit_test/gmm_helper/gmm_resource_info_drm_or_wddm_tests.cpp index cc41a74ebd..5cbd2ba407 100644 --- a/shared/test/unit_test/gmm_helper/gmm_resource_info_drm_or_wddm_tests.cpp +++ b/shared/test/unit_test/gmm_helper/gmm_resource_info_drm_or_wddm_tests.cpp @@ -64,7 +64,8 @@ class GmmResourceInfoDrmOrWddmTest : public ::testing::Test { void SetUp() override { hwInfo = *defaultHwInfo; executionEnvironment = std::make_unique(&hwInfo); - gmmClientContext = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); + gmmClientContext = std::make_unique(); + gmmClientContext->initialize(*executionEnvironment->rootDeviceEnvironments[0]); GMM_RESCREATE_PARAMS createParams = {}; createParams.Type = RESOURCE_BUFFER; diff --git a/shared/test/unit_test/gmm_helper/gmm_resource_info_drm_tests.cpp b/shared/test/unit_test/gmm_helper/gmm_resource_info_drm_tests.cpp index 331abfaac9..151d193701 100644 --- a/shared/test/unit_test/gmm_helper/gmm_resource_info_drm_tests.cpp +++ b/shared/test/unit_test/gmm_helper/gmm_resource_info_drm_tests.cpp @@ -21,7 +21,8 @@ class GmmResourceInfoDrmTest : public ::testing::Test { void SetUp() override { hwInfo = *defaultHwInfo; executionEnvironment = std::make_unique(&hwInfo); - gmmClientContext = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); + gmmClientContext = std::make_unique(); + gmmClientContext->initialize(*executionEnvironment->rootDeviceEnvironments[0]); GMM_RESCREATE_PARAMS createParams = {}; createParams.Type = RESOURCE_BUFFER; diff --git a/shared/test/unit_test/gmm_helper/gmm_resource_info_tests.cpp b/shared/test/unit_test/gmm_helper/gmm_resource_info_tests.cpp index e961248e73..5e3928a9c2 100644 --- a/shared/test/unit_test/gmm_helper/gmm_resource_info_tests.cpp +++ b/shared/test/unit_test/gmm_helper/gmm_resource_info_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2024 Intel Corporation + * Copyright (C) 2021-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -47,7 +47,8 @@ struct MockGmmHandleAllocator : NEO::GmmHandleAllocator { TEST(GmmResourceInfo, WhenGmmHandleAllocatorIsPresentThenItsBeingUsedForCreatingGmmResourceInfoHandles) { auto hwInfo = *defaultHwInfo; MockExecutionEnvironment executionEnvironment{&hwInfo}; - NEO::MockGmmClientContext gmmClientCtx{*executionEnvironment.rootDeviceEnvironments[0]}; + NEO::MockGmmClientContext gmmClientCtx{}; + gmmClientCtx.initialize(*executionEnvironment.rootDeviceEnvironments[0]); gmmClientCtx.setHandleAllocator(std::make_unique()); auto handleAllocator = static_cast(gmmClientCtx.getHandleAllocator()); @@ -80,7 +81,8 @@ TEST(GmmResourceInfo, WhenGmmHandleAllocatorIsPresentThenItsBeingUsedForCreating TEST(GmmResourceInfo, GivenGmmResourceInfoAndHandleAllocatorInClientContextWhenDecodingResourceInfoThenExistingHandleIsOpened) { auto hwInfo = *defaultHwInfo; MockExecutionEnvironment executionEnvironment{&hwInfo}; - NEO::MockGmmClientContext gmmClientCtx{*executionEnvironment.rootDeviceEnvironments[0]}; + NEO::MockGmmClientContext gmmClientCtx{}; + gmmClientCtx.initialize(*executionEnvironment.rootDeviceEnvironments[0]); gmmClientCtx.setHandleAllocator(std::make_unique()); auto handleAllocator = static_cast(gmmClientCtx.getHandleAllocator()); @@ -138,7 +140,8 @@ TEST(GmmResourceInfo, GivenGmmResourceInfoAndHandleAllocatorInClientContextWhenD TEST(GmmResourceInfo, GivenResourceInfoWhenRefreshIsCalledTiwceThenOpenHandleIsCalledTwice) { auto hwInfo = *defaultHwInfo; MockExecutionEnvironment executionEnvironment{&hwInfo}; - NEO::MockGmmClientContext gmmClientCtx{*executionEnvironment.rootDeviceEnvironments[0]}; + NEO::MockGmmClientContext gmmClientCtx{}; + gmmClientCtx.initialize(*executionEnvironment.rootDeviceEnvironments[0]); gmmClientCtx.setHandleAllocator(std::make_unique()); auto handleAllocator = static_cast(gmmClientCtx.getHandleAllocator()); diff --git a/shared/test/unit_test/gmm_helper/gmm_resource_info_wddm_tests.cpp b/shared/test/unit_test/gmm_helper/gmm_resource_info_wddm_tests.cpp index 6045ea5132..573bb950c7 100644 --- a/shared/test/unit_test/gmm_helper/gmm_resource_info_wddm_tests.cpp +++ b/shared/test/unit_test/gmm_helper/gmm_resource_info_wddm_tests.cpp @@ -21,7 +21,8 @@ class GmmResourceInfoWddmTest : public ::testing::Test { void SetUp() override { hwInfo = *defaultHwInfo; executionEnvironment = std::make_unique(&hwInfo); - gmmClientContext = std::make_unique(*executionEnvironment->rootDeviceEnvironments[0]); + gmmClientContext = std::make_unique(); + gmmClientContext->initialize(*executionEnvironment->rootDeviceEnvironments[0]); GMM_RESCREATE_PARAMS createParams = {}; createParams.Type = RESOURCE_BUFFER;