Create and implement WSL handle refreshing

Additionally rename createResourceInfo overload to decodeResourceInfo.
createResourceInfo(GMM_RESOURCE_INFO *, GMM_RESOURCE_INFO) does not
create a new ResourceInfo, but decodes one on the basis of the provided
existing gmmResourceInfo.

Signed-off-by: Fabian Zwolinski <fabian.zwolinski@intel.com>
This commit is contained in:
Fabian Zwolinski
2022-06-08 11:52:47 +00:00
committed by Compute-Runtime-Automation
parent d5bc7e66e7
commit 0966651a78
5 changed files with 32 additions and 6 deletions

View File

@ -83,6 +83,8 @@ class GmmResourceInfo {
MOCKABLE_VIRTUAL size_t peekHandleSize() const { return handleSize; }
MOCKABLE_VIRTUAL void refreshHandle();
protected:
using UniquePtrType = std::unique_ptr<GMM_RESOURCE_INFO, std::function<void(GMM_RESOURCE_INFO *)>>;
@ -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;

View File

@ -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<GMM_RESOURCE_INFO *>(this->handle));
}
}
GmmResourceInfo::~GmmResourceInfo() {
if (this->clientContext && this->clientContext->getHandleAllocator()) {
this->clientContext->getHandleAllocator()->destroyHandle(this->handle);

View File

@ -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) {

View File

@ -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();

View File

@ -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<GMM_RESOURCE_INFO *>(resInfo->GmmResourceInfo::peekHandle()));
resInfo2->createResourceInfo(resourceInfoPtr, static_cast<GMM_RESOURCE_INFO *>(resInfo->GmmResourceInfo::peekHandle()));
resInfo2->decodeResourceInfo(resourceInfoPtr, static_cast<GMM_RESOURCE_INFO *>(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));
}