mirror of
https://github.com/intel/compute-runtime.git
synced 2025-11-15 10:14:56 +08:00
Add proper handling decoding resource while import on WSL
- create resource info and handle when needed Signed-off-by: Kamil Diedrich <kamil.diedrich@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
7829364e67
commit
4d35a76931
@@ -981,7 +981,6 @@ TEST_F(GmmTests, whenResourceIsCreatedThenHandleItsOwnership) {
|
||||
|
||||
MyMockResourecInfo(GmmClientContext *clientContext, GMM_RESCREATE_PARAMS *inputParams) : GmmResourceInfo(clientContext, inputParams){};
|
||||
MyMockResourecInfo(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmmResourceInfo) : GmmResourceInfo(clientContext, inputGmmResourceInfo){};
|
||||
MyMockResourecInfo(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmmResourceInfo, bool openingHandle) : GmmResourceInfo(clientContext, inputGmmResourceInfo, openingHandle){};
|
||||
};
|
||||
|
||||
GMM_RESCREATE_PARAMS gmmParams = {};
|
||||
@@ -1001,11 +1000,7 @@ TEST_F(GmmTests, whenResourceIsCreatedThenHandleItsOwnership) {
|
||||
MyMockResourecInfo myMockResourceInfo2(getGmmClientContext(), myMockResourceInfo1.resourceInfo.get());
|
||||
EXPECT_NE(nullptr, myMockResourceInfo2.resourceInfo.get());
|
||||
|
||||
MyMockResourecInfo myMockResourceInfo3(getGmmClientContext(), myMockResourceInfo2.resourceInfo.get(), true);
|
||||
EXPECT_NE(nullptr, myMockResourceInfo3.resourceInfo.get());
|
||||
|
||||
EXPECT_NE(myMockResourceInfo1.resourceInfo.get(), myMockResourceInfo2.resourceInfo.get());
|
||||
EXPECT_NE(myMockResourceInfo2.resourceInfo.get(), myMockResourceInfo3.resourceInfo.get());
|
||||
}
|
||||
|
||||
using GmmEnvironmentTest = MockExecutionEnvironmentGmmFixtureTest;
|
||||
|
||||
@@ -97,7 +97,7 @@ class GmmResourceInfo {
|
||||
GmmResourceInfo(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmmResourceInfo, bool openingHandle);
|
||||
|
||||
void createResourceInfo(GMM_RESOURCE_INFO *resourceInfoPtr);
|
||||
void decodeResourceInfo(GMM_RESOURCE_INFO *resourceInfoPtr, GMM_RESOURCE_INFO *inputGmmResourceInfo);
|
||||
void decodeResourceInfo(GMM_RESOURCE_INFO *inputGmmResourceInfo);
|
||||
|
||||
UniquePtrType resourceInfo;
|
||||
|
||||
|
||||
@@ -19,26 +19,28 @@ GmmResourceInfo::GmmResourceInfo(GmmClientContext *clientContext, GMM_RESCREATE_
|
||||
GmmResourceInfo::GmmResourceInfo(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmmResourceInfo) : GmmResourceInfo(clientContext, inputGmmResourceInfo, false) {}
|
||||
|
||||
GmmResourceInfo::GmmResourceInfo(GmmClientContext *clientContext, GMM_RESOURCE_INFO *inputGmmResourceInfo, bool openingHandle) : clientContext(clientContext) {
|
||||
auto resourceInfoPtr = clientContext->copyResInfoObject(inputGmmResourceInfo);
|
||||
if (openingHandle) {
|
||||
decodeResourceInfo(resourceInfoPtr, inputGmmResourceInfo);
|
||||
decodeResourceInfo(inputGmmResourceInfo);
|
||||
} else {
|
||||
auto resourceInfoPtr = clientContext->copyResInfoObject(inputGmmResourceInfo);
|
||||
createResourceInfo(resourceInfoPtr);
|
||||
}
|
||||
}
|
||||
|
||||
void GmmResourceInfo::decodeResourceInfo(GMM_RESOURCE_INFO *resourceInfoPtr, GMM_RESOURCE_INFO *inputGmmResourceInfo) {
|
||||
void GmmResourceInfo::decodeResourceInfo(GMM_RESOURCE_INFO *inputGmmResourceInfo) {
|
||||
auto customDeleter = [this](GMM_RESOURCE_INFO *gmmResourceInfo) {
|
||||
this->clientContext->destroyResInfoObject(gmmResourceInfo);
|
||||
};
|
||||
if (this->clientContext->getHandleAllocator()) {
|
||||
this->resourceInfo = UniquePtrType(resourceInfoPtr, [](GMM_RESOURCE_INFO *gmmResourceInfo) {});
|
||||
this->clientContext->getHandleAllocator()->openHandle(inputGmmResourceInfo, resourceInfoPtr, this->clientContext->getHandleAllocator()->getHandleSize());
|
||||
this->handle = resourceInfoPtr;
|
||||
this->handleSize = this->clientContext->getHandleAllocator()->getHandleSize();
|
||||
return;
|
||||
}
|
||||
|
||||
UNRECOVERABLE_IF(this->handle != nullptr);
|
||||
|
||||
auto resourceInfoPtr = this->clientContext->copyResInfoObject(inputGmmResourceInfo);
|
||||
this->resourceInfo = UniquePtrType(resourceInfoPtr, customDeleter);
|
||||
|
||||
this->handle = this->clientContext->getHandleAllocator()->createHandle(inputGmmResourceInfo);
|
||||
this->handleSize = this->clientContext->getHandleAllocator()->getHandleSize();
|
||||
|
||||
this->clientContext->getHandleAllocator()->openHandle(inputGmmResourceInfo, this->resourceInfo.get(), this->clientContext->getHandleAllocator()->getHandleSize());
|
||||
}
|
||||
|
||||
void GmmResourceInfo::createResourceInfo(GMM_RESOURCE_INFO *resourceInfoPtr) {
|
||||
@@ -57,8 +59,8 @@ void GmmResourceInfo::createResourceInfo(GMM_RESOURCE_INFO *resourceInfoPtr) {
|
||||
}
|
||||
|
||||
void GmmResourceInfo::refreshHandle() {
|
||||
if (this->clientContext) {
|
||||
this->decodeResourceInfo(this->resourceInfo.release(), static_cast<GMM_RESOURCE_INFO *>(this->handle));
|
||||
if (this->clientContext && this->clientContext->getHandleAllocator()) {
|
||||
this->clientContext->getHandleAllocator()->openHandle(this->handle, this->resourceInfo.get(), this->clientContext->getHandleAllocator()->getHandleSize());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -95,10 +95,9 @@ TEST(GmmResourceInfo, GivenGmmResourceInfoAndHandleAllocatorInClientContextWhenD
|
||||
auto resInfo2 = static_cast<NEO::MockGmmResourceInfo *>(NEO::GmmResourceInfo::create(nullptr, reinterpret_cast<GMM_RESOURCE_INFO *>(resInfo), true));
|
||||
ASSERT_NE(nullptr, resInfo2);
|
||||
resInfo2->clientContext = &gmmClientCtx;
|
||||
auto resourceInfoPtr = resInfo2->clientContext->copyResInfoObject(static_cast<GMM_RESOURCE_INFO *>(resInfo->GmmResourceInfo::peekHandle()));
|
||||
resInfo2->decodeResourceInfo(resourceInfoPtr, static_cast<GMM_RESOURCE_INFO *>(resInfo->GmmResourceInfo::peekHandle()));
|
||||
resInfo2->decodeResourceInfo(static_cast<GMM_RESOURCE_INFO *>(resInfo->GmmResourceInfo::peekHandle()));
|
||||
|
||||
EXPECT_EQ(1U, created.size());
|
||||
EXPECT_EQ(2U, created.size());
|
||||
EXPECT_EQ(1U, opened.size());
|
||||
EXPECT_EQ(0U, destroyed.size());
|
||||
|
||||
@@ -116,7 +115,7 @@ TEST(GmmResourceInfo, GivenGmmResourceInfoAndHandleAllocatorInClientContextWhenD
|
||||
|
||||
resInfo2->refreshHandle();
|
||||
|
||||
EXPECT_EQ(1U, created.size());
|
||||
EXPECT_EQ(2U, created.size());
|
||||
EXPECT_EQ(2U, opened.size());
|
||||
EXPECT_EQ(0U, destroyed.size());
|
||||
EXPECT_EQ(1u, resInfo2->refreshHandleCalled);
|
||||
@@ -124,12 +123,71 @@ TEST(GmmResourceInfo, GivenGmmResourceInfoAndHandleAllocatorInClientContextWhenD
|
||||
delete resInfo;
|
||||
delete resInfo2;
|
||||
|
||||
EXPECT_EQ(1U, created.size());
|
||||
EXPECT_EQ(2U, created.size());
|
||||
EXPECT_EQ(2U, opened.size());
|
||||
EXPECT_EQ(2U, destroyed.size());
|
||||
EXPECT_NE(destroyed.end(), std::find(destroyed.begin(), destroyed.end(), handle));
|
||||
}
|
||||
|
||||
TEST(GmmResourceInfo, GivenResourceInfoWhenRefreshIsCalledTiwceThenOpenHandleIsCalledTwice) {
|
||||
NEO::HardwareInfo hwInfo;
|
||||
hwInfo.platform.eProductFamily = productFamily;
|
||||
NEO::MockGmmClientContext gmmClientCtx{nullptr, &hwInfo};
|
||||
gmmClientCtx.setHandleAllocator(std::make_unique<MockGmmHandleAllocator>());
|
||||
auto handleAllocator = static_cast<MockGmmHandleAllocator *>(gmmClientCtx.getHandleAllocator());
|
||||
|
||||
GMM_RESCREATE_PARAMS createParams = {};
|
||||
createParams.Type = RESOURCE_BUFFER;
|
||||
createParams.Format = GMM_FORMAT_R8G8B8A8_SINT;
|
||||
auto resInfo = static_cast<NEO::MockGmmResourceInfo *>(NEO::GmmResourceInfo::create(nullptr, &createParams));
|
||||
ASSERT_NE(nullptr, resInfo);
|
||||
resInfo->clientContext = &gmmClientCtx;
|
||||
resInfo->createResourceInfo(nullptr);
|
||||
|
||||
auto &created = handleAllocator->createdHandles;
|
||||
auto &opened = handleAllocator->openedHandles;
|
||||
auto &destroyed = handleAllocator->destroyedHandles;
|
||||
|
||||
EXPECT_EQ(0U, opened.size());
|
||||
|
||||
auto resInfo2 = static_cast<NEO::MockGmmResourceInfo *>(NEO::GmmResourceInfo::create(nullptr, reinterpret_cast<GMM_RESOURCE_INFO *>(resInfo), true));
|
||||
ASSERT_NE(nullptr, resInfo2);
|
||||
resInfo2->clientContext = &gmmClientCtx;
|
||||
resInfo2->decodeResourceInfo(static_cast<GMM_RESOURCE_INFO *>(resInfo->GmmResourceInfo::peekHandle()));
|
||||
|
||||
EXPECT_EQ(2U, created.size());
|
||||
EXPECT_EQ(1U, opened.size());
|
||||
EXPECT_EQ(0U, destroyed.size());
|
||||
|
||||
EXPECT_EQ(handleAllocator->getHandleSize(), resInfo->GmmResourceInfo::peekHandleSize());
|
||||
|
||||
auto handle = resInfo->GmmResourceInfo::peekHandle();
|
||||
EXPECT_NE(nullptr, handle);
|
||||
EXPECT_NE(created.end(), std::find(created.begin(), created.end(), handle));
|
||||
EXPECT_NE(opened.end(), std::find(opened.begin(), opened.end(), handle));
|
||||
|
||||
auto handle2 = resInfo2->GmmResourceInfo::peekHandle();
|
||||
EXPECT_NE(nullptr, handle2);
|
||||
|
||||
EXPECT_EQ(0u, resInfo2->refreshHandleCalled);
|
||||
|
||||
resInfo2->refreshHandle();
|
||||
resInfo2->refreshHandle();
|
||||
|
||||
EXPECT_EQ(2U, created.size());
|
||||
EXPECT_EQ(3U, opened.size());
|
||||
EXPECT_EQ(0U, destroyed.size());
|
||||
EXPECT_EQ(2u, resInfo2->refreshHandleCalled);
|
||||
|
||||
delete resInfo;
|
||||
delete resInfo2;
|
||||
|
||||
EXPECT_EQ(2U, created.size());
|
||||
EXPECT_EQ(3U, opened.size());
|
||||
EXPECT_EQ(2U, destroyed.size());
|
||||
EXPECT_NE(destroyed.end(), std::find(destroyed.begin(), destroyed.end(), handle));
|
||||
}
|
||||
|
||||
TEST(GmmResourceInfo, WhenUsingBaseHandleAllocatorThenHandlesAreEmpty) {
|
||||
NEO::GmmHandleAllocator defaultAllocator;
|
||||
EXPECT_EQ(0U, defaultAllocator.getHandleSize());
|
||||
|
||||
Reference in New Issue
Block a user