mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-08 14:02:58 +08:00
Improve error handling for shared handles in wddm.
Change-Id: I93d33d89cb4b6333924c362b54e0638174e44091
This commit is contained in:
committed by
sys_ocldev
parent
aba7dc637d
commit
b006972d07
@@ -695,6 +695,10 @@ bool Wddm::openSharedHandle(D3DKMT_HANDLE handle, WddmAllocation *alloc) {
|
||||
auto status = gdi->queryResourceInfo(&QueryResourceInfo);
|
||||
DEBUG_BREAK_IF(status != STATUS_SUCCESS);
|
||||
|
||||
if (QueryResourceInfo.NumAllocations == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::unique_ptr<char[]> allocPrivateData(new char[QueryResourceInfo.TotalPrivateDriverDataSize]);
|
||||
std::unique_ptr<char[]> resPrivateData(new char[QueryResourceInfo.ResourcePrivateDriverDataSize]);
|
||||
std::unique_ptr<char[]> resPrivateRuntimeData(new char[QueryResourceInfo.PrivateRuntimeDataSize]);
|
||||
@@ -721,7 +725,7 @@ bool Wddm::openSharedHandle(D3DKMT_HANDLE handle, WddmAllocation *alloc) {
|
||||
|
||||
alloc->gmm = Gmm::create((PGMM_RESOURCE_INFO)(allocationInfo[0].pPrivateDriverData));
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Wddm::openNTHandle(HANDLE handle, WddmAllocation *alloc) {
|
||||
@@ -757,7 +761,7 @@ bool Wddm::openNTHandle(HANDLE handle, WddmAllocation *alloc) {
|
||||
|
||||
alloc->gmm = Gmm::create((PGMM_RESOURCE_INFO)(allocationInfo2[0].pPrivateDriverData));
|
||||
|
||||
return STATUS_SUCCESS;
|
||||
return true;
|
||||
}
|
||||
|
||||
void *Wddm::lockResource(WddmAllocation *wddmAllocation) {
|
||||
|
||||
@@ -83,7 +83,7 @@ class Wddm {
|
||||
MOCKABLE_VIRTUAL bool createAllocation64k(WddmAllocation *alloc);
|
||||
bool createAllocationsAndMapGpuVa(OsHandleStorage &osHandles);
|
||||
MOCKABLE_VIRTUAL bool destroyAllocations(D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, D3DKMT_HANDLE resourceHandle);
|
||||
bool openSharedHandle(D3DKMT_HANDLE handle, WddmAllocation *alloc);
|
||||
MOCKABLE_VIRTUAL bool openSharedHandle(D3DKMT_HANDLE handle, WddmAllocation *alloc);
|
||||
bool openNTHandle(HANDLE handle, WddmAllocation *alloc);
|
||||
MOCKABLE_VIRTUAL void *lockResource(WddmAllocation *wddmAllocation);
|
||||
MOCKABLE_VIRTUAL void unlockResource(WddmAllocation *wddmAllocation);
|
||||
|
||||
@@ -211,7 +211,9 @@ GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(osHandle handl
|
||||
if (ntHandle) {
|
||||
wddm->openNTHandle((HANDLE)((UINT_PTR)handle), &allocation);
|
||||
} else {
|
||||
wddm->openSharedHandle(handle, &allocation);
|
||||
if (wddm->openSharedHandle(handle, &allocation) == false) {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// Shared objects are passed without size
|
||||
@@ -230,8 +232,7 @@ GraphicsAllocation *WddmMemoryManager::createAllocationFromHandle(osHandle handl
|
||||
|
||||
allocation.setGpuAddress(allocation.gpuPtr);
|
||||
|
||||
auto *wddmAllocation = new WddmAllocation(allocation);
|
||||
return wddmAllocation;
|
||||
return new WddmAllocation(allocation);
|
||||
}
|
||||
|
||||
GraphicsAllocation *WddmMemoryManager::createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness, bool /*isReused*/) {
|
||||
|
||||
@@ -142,6 +142,15 @@ class WddmMock : public Wddm {
|
||||
releaseGpuPtr(gpuPtr);
|
||||
return success;
|
||||
}
|
||||
|
||||
bool openSharedHandle(D3DKMT_HANDLE handle, WddmAllocation *alloc) {
|
||||
if (failOpenSharedHandle) {
|
||||
return false;
|
||||
} else {
|
||||
return Wddm::openSharedHandle(handle, alloc);
|
||||
}
|
||||
}
|
||||
|
||||
D3DKMT_HANDLE createContext() override {
|
||||
createContextResult.called++;
|
||||
D3DKMT_HANDLE context = Wddm::createContext();
|
||||
@@ -238,6 +247,7 @@ class WddmMock : public Wddm {
|
||||
CallResult waitFromCpuResult;
|
||||
CallResult releaseGpuPtrResult;
|
||||
bool callBaseDestroyAllocations = true;
|
||||
bool failOpenSharedHandle = false;
|
||||
};
|
||||
|
||||
class WddmFixture {
|
||||
|
||||
@@ -227,6 +227,21 @@ HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerSizeZeroWhenCreateFromShar
|
||||
mm->freeGraphicsMemory(gpuAllocation);
|
||||
}
|
||||
|
||||
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenCreateFromSharedHandleFailsThenReturnNull) {
|
||||
SetUpMm<FamilyType>();
|
||||
auto osHandle = 1u;
|
||||
auto size = 4096u;
|
||||
void *pSysMem = (void *)0x1000;
|
||||
|
||||
std::unique_ptr<Gmm> gmm(Gmm::create(pSysMem, size));
|
||||
auto status = setSizesFunction(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u);
|
||||
|
||||
mockWddm->failOpenSharedHandle = true;
|
||||
|
||||
auto *gpuAllocation = mm->createGraphicsAllocationFromSharedHandle(osHandle, false);
|
||||
EXPECT_EQ(nullptr, gpuAllocation);
|
||||
}
|
||||
|
||||
HWTEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenTiledImageIsBeingCreatedThenallocateGraphicsMemoryForImageIsUsed) {
|
||||
SetUpMm<FamilyType>();
|
||||
MockContext context;
|
||||
|
||||
@@ -744,3 +744,24 @@ HWTEST_F(WddmWithMockGdiTest, createMonitoredFenceIsInitializedWithFenceValueZer
|
||||
EXPECT_EQ(0u, gdi.getCreateSynchronizationObject2Arg().Info.MonitoredFence.InitialFenceValue);
|
||||
EXPECT_EQ(1u, wddm.getMonitoredFence().currentFenceValue);
|
||||
}
|
||||
|
||||
NTSTATUS queryResourceInfoMock(D3DKMT_QUERYRESOURCEINFO *pData) {
|
||||
pData->NumAllocations = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
HWTEST_F(WddmWithMockGdiTest, givenOpenSharedHandleWhenZeroAllocationsThenReturnNull) {
|
||||
|
||||
MockGdi gdi;
|
||||
WddmMock wddm(&gdi);
|
||||
|
||||
wddm.init<FamilyType>();
|
||||
|
||||
D3DKMT_HANDLE handle = 0;
|
||||
WddmAllocation *alloc = nullptr;
|
||||
|
||||
gdi.queryResourceInfo = reinterpret_cast<PFND3DKMT_QUERYRESOURCEINFO>(queryResourceInfoMock);
|
||||
auto ret = wddm.openSharedHandle(handle, alloc);
|
||||
|
||||
EXPECT_EQ(false, ret);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user