diff --git a/shared/source/gmm_helper/resource_info.h b/shared/source/gmm_helper/resource_info.h index 4d39498eb2..595b78cb48 100644 --- a/shared/source/gmm_helper/resource_info.h +++ b/shared/source/gmm_helper/resource_info.h @@ -83,6 +83,8 @@ class GmmResourceInfo { MOCKABLE_VIRTUAL size_t peekHandleSize() const { return handleSize; } + MOCKABLE_VIRTUAL void refreshHandle(); + protected: using UniquePtrType = std::unique_ptr>; @@ -95,7 +97,7 @@ class GmmResourceInfo { GmmResourceInfo(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmmResourceInfo, bool openingHandle); void createResourceInfo(GMM_RESOURCE_INFO *resourceInfoPtr); - void createResourceInfo(GMM_RESOURCE_INFO *resourceInfoPtr, GMM_RESOURCE_INFO *inputGmmResourceInfo); + void decodeResourceInfo(GMM_RESOURCE_INFO *resourceInfoPtr, GMM_RESOURCE_INFO *inputGmmResourceInfo); UniquePtrType resourceInfo; diff --git a/shared/source/gmm_helper/resource_info_impl.cpp b/shared/source/gmm_helper/resource_info_impl.cpp index e5153eac83..1ec4e80121 100644 --- a/shared/source/gmm_helper/resource_info_impl.cpp +++ b/shared/source/gmm_helper/resource_info_impl.cpp @@ -21,13 +21,13 @@ GmmResourceInfo::GmmResourceInfo(GmmClientContext *clientContext, GMM_RESOURCE_I GmmResourceInfo::GmmResourceInfo(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmmResourceInfo, bool openingHandle) : clientContext(clientContext) { auto resourceInfoPtr = clientContext->copyResInfoObject(inputGmmResourceInfo); if (openingHandle) { - createResourceInfo(resourceInfoPtr, inputGmmResourceInfo); + decodeResourceInfo(resourceInfoPtr, inputGmmResourceInfo); } else { createResourceInfo(resourceInfoPtr); } } -void GmmResourceInfo::createResourceInfo(GMM_RESOURCE_INFO *resourceInfoPtr, GMM_RESOURCE_INFO *inputGmmResourceInfo) { +void GmmResourceInfo::decodeResourceInfo(GMM_RESOURCE_INFO *resourceInfoPtr, GMM_RESOURCE_INFO *inputGmmResourceInfo) { auto customDeleter = [this](GMM_RESOURCE_INFO *gmmResourceInfo) { this->clientContext->destroyResInfoObject(gmmResourceInfo); }; @@ -56,6 +56,12 @@ void GmmResourceInfo::createResourceInfo(GMM_RESOURCE_INFO *resourceInfoPtr) { } } +void GmmResourceInfo::refreshHandle() { + if (this->clientContext) { + this->decodeResourceInfo(this->resourceInfo.release(), static_cast(this->handle)); + } +} + GmmResourceInfo::~GmmResourceInfo() { if (this->clientContext && this->clientContext->getHandleAllocator()) { this->clientContext->getHandleAllocator()->destroyHandle(this->handle); diff --git a/shared/source/os_interface/windows/wddm/wddm.cpp b/shared/source/os_interface/windows/wddm/wddm.cpp index b6c461b33c..480a8e3049 100644 --- a/shared/source/os_interface/windows/wddm/wddm.cpp +++ b/shared/source/os_interface/windows/wddm/wddm.cpp @@ -521,6 +521,8 @@ NTSTATUS Wddm::createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKM return status; } + gmm->gmmResourceInfo->refreshHandle(); + outHandle = allocationInfo.hAllocation; outResourceHandle = createAllocation.hResource; if (outSharedHandle) { diff --git a/shared/test/common/mocks/mock_gmm_resource_info.h b/shared/test/common/mocks/mock_gmm_resource_info.h index 283c643e55..3908ec2d41 100644 --- a/shared/test/common/mocks/mock_gmm_resource_info.h +++ b/shared/test/common/mocks/mock_gmm_resource_info.h @@ -100,8 +100,14 @@ class MockGmmResourceInfo : public GmmResourceInfo { void setAuxQPitch(uint32_t value); void setMipTailStartLod(uint32_t newMipTailStartLod) { mipTailStartLod = newMipTailStartLod; } + void refreshHandle() override { + refreshHandleCalled++; + GmmResourceInfo::refreshHandle(); + }; + using GmmResourceInfo::clientContext; using GmmResourceInfo::createResourceInfo; + using GmmResourceInfo::decodeResourceInfo; uint64_t driverProtectionBits = 0; uint32_t getOffsetCalled = 0u; @@ -113,6 +119,7 @@ class MockGmmResourceInfo : public GmmResourceInfo { uint8_t cpuBltResult = 1u; static constexpr uint32_t getHAlignSurfaceStateResult = 2u; static constexpr uint32_t yMajorTileModeValue = 3u; + uint32_t refreshHandleCalled = 0u; protected: MockGmmResourceInfo(); 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 ea614a50eb..4b273ba5e5 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 @@ -69,7 +69,7 @@ TEST(GmmResourceInfo, WhenGmmHandleAllocatorIsPresentThenItsBeingUsedForCreating EXPECT_NE(destroyed.end(), std::find(destroyed.begin(), destroyed.end(), handle)); } -TEST(GmmResourceInfo, GivenGmmResourceInfoAndHandleAllocatorInClientContextWhenCreatingResourceInfoThenExistingHandleIsOpened) { +TEST(GmmResourceInfo, GivenGmmResourceInfoAndHandleAllocatorInClientContextWhenDecodingResourceInfoThenExistingHandleIsOpened) { NEO::HardwareInfo hwInfo; hwInfo.platform.eProductFamily = productFamily; NEO::MockGmmClientContext gmmClientCtx{nullptr, &hwInfo}; @@ -94,7 +94,7 @@ TEST(GmmResourceInfo, GivenGmmResourceInfoAndHandleAllocatorInClientContextWhenC ASSERT_NE(nullptr, resInfo2); resInfo2->clientContext = &gmmClientCtx; auto resourceInfoPtr = resInfo2->clientContext->copyResInfoObject(static_cast(resInfo->GmmResourceInfo::peekHandle())); - resInfo2->createResourceInfo(resourceInfoPtr, static_cast(resInfo->GmmResourceInfo::peekHandle())); + resInfo2->decodeResourceInfo(resourceInfoPtr, static_cast(resInfo->GmmResourceInfo::peekHandle())); EXPECT_EQ(1U, created.size()); EXPECT_EQ(1U, opened.size()); @@ -110,11 +110,20 @@ TEST(GmmResourceInfo, GivenGmmResourceInfoAndHandleAllocatorInClientContextWhenC auto handle2 = resInfo2->GmmResourceInfo::peekHandle(); EXPECT_NE(nullptr, handle2); + EXPECT_EQ(0u, resInfo2->refreshHandleCalled); + + resInfo2->refreshHandle(); + + EXPECT_EQ(1U, created.size()); + EXPECT_EQ(2U, opened.size()); + EXPECT_EQ(0U, destroyed.size()); + EXPECT_EQ(1u, resInfo2->refreshHandleCalled); + delete resInfo; delete resInfo2; EXPECT_EQ(1U, created.size()); - EXPECT_EQ(1U, opened.size()); + EXPECT_EQ(2U, opened.size()); EXPECT_EQ(2U, destroyed.size()); EXPECT_NE(destroyed.end(), std::find(destroyed.begin(), destroyed.end(), handle)); }