Windows: correct creating shareable allocation

Change-Id: If3f67a9d3c4df072a8d23dcc2ccaa4b04a8bbb67
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2020-02-25 18:58:09 +01:00
committed by sys_ocldev
parent 6094072504
commit e2d69f7a7c
10 changed files with 70 additions and 16 deletions

View File

@@ -122,17 +122,17 @@ NTSTATUS __stdcall D3DKMTDestroyContext(IN CONST D3DKMT_DESTROYCONTEXT *destroyC
return STATUS_SUCCESS;
}
static D3DKMT_CREATEALLOCATION *pallocation = nullptr;
static D3DKMT_CREATEALLOCATION pallocation{};
NTSTATUS __stdcall D3DKMTCreateAllocation(IN OUT D3DKMT_CREATEALLOCATION *allocation) {
D3DDDI_ALLOCATIONINFO *allocationInfo;
int numOfAllocations;
bool createResource;
bool globalShare;
pallocation = allocation;
if (allocation == nullptr || allocation->hDevice != DEVICE_HANDLE) {
return STATUS_INVALID_PARAMETER;
}
pallocation = *allocation;
allocationInfo = allocation->pAllocationInfo;
if (allocationInfo == NULL) {
return STATUS_INVALID_PARAMETER;
@@ -452,7 +452,7 @@ void SetMockCreateDeviceParams(D3DKMT_CREATEDEVICE params) {
}
D3DKMT_CREATEALLOCATION *getMockAllocation() {
return pallocation;
return &pallocation;
}
ADAPTER_INFO *getAdapterInfoAddress() {

View File

@@ -75,14 +75,14 @@ bool WddmMock::freeGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t si
}
NTSTATUS WddmMock::createAllocation(WddmAllocation *wddmAllocation) {
if (wddmAllocation) {
return createAllocation(wddmAllocation->getAlignedCpuPtr(), wddmAllocation->getDefaultGmm(), wddmAllocation->getHandleToModify(0u), false);
return createAllocation(wddmAllocation->getAlignedCpuPtr(), wddmAllocation->getDefaultGmm(), wddmAllocation->getHandleToModify(0u), wddmAllocation->resourceHandle, wddmAllocation->getSharedHandleToModify());
}
return false;
}
NTSTATUS WddmMock::createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKMT_HANDLE &outHandle, uint32_t shareable) {
NTSTATUS WddmMock::createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKMT_HANDLE &outHandle, D3DKMT_HANDLE &outResourceHandle, D3DKMT_HANDLE *outSharedHandle) {
createAllocationResult.called++;
if (callBaseDestroyAllocations) {
createAllocationStatus = Wddm::createAllocation(alignedCpuPtr, gmm, outHandle, shareable);
createAllocationStatus = Wddm::createAllocation(alignedCpuPtr, gmm, outHandle, outResourceHandle, outSharedHandle);
createAllocationResult.success = createAllocationStatus == STATUS_SUCCESS;
} else {
createAllocationResult.success = true;

View File

@@ -50,7 +50,7 @@ class WddmMock : public Wddm {
bool mapGpuVirtualAddress(Gmm *gmm, D3DKMT_HANDLE handle, D3DGPU_VIRTUAL_ADDRESS minimumAddress, D3DGPU_VIRTUAL_ADDRESS maximumAddress, D3DGPU_VIRTUAL_ADDRESS preferredAddress, D3DGPU_VIRTUAL_ADDRESS &gpuPtr) override;
bool mapGpuVirtualAddress(WddmAllocation *allocation);
bool freeGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size) override;
NTSTATUS createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKMT_HANDLE &outHandle, uint32_t shareable) override;
NTSTATUS createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKMT_HANDLE &outHandle, D3DKMT_HANDLE &outResource, D3DKMT_HANDLE *outSharedHandle) override;
bool createAllocation64k(const Gmm *gmm, D3DKMT_HANDLE &outHandle) override;
bool destroyAllocations(const D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle) override;

View File

@@ -402,6 +402,48 @@ TEST_F(Wddm20Tests, givenNullAllocationWhenCreateThenAllocateAndMap) {
mm.freeSystemMemory(allocation.getUnderlyingBuffer());
}
TEST_F(WddmTestWithMockGdiDll, givenShareableAllocationWhenCreateThenCreateResourceFlagIsEnabled) {
init();
WddmAllocation allocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, MemoryConstants::pageSize, nullptr, MemoryPool::MemoryNull, true);
auto gmm = std::unique_ptr<Gmm>(GmmHelperFunctions::getGmm(nullptr, MemoryConstants::pageSize));
allocation.setDefaultGmm(gmm.get());
auto status = wddm->createAllocation(&allocation);
EXPECT_EQ(STATUS_SUCCESS, status);
auto passedCreateAllocation = getMockAllocationFcn();
EXPECT_EQ(TRUE, passedCreateAllocation->Flags.CreateShared);
EXPECT_EQ(TRUE, passedCreateAllocation->Flags.CreateResource);
}
TEST_F(WddmTestWithMockGdiDll, givenShareableAllocationWhenCreateThenSharedHandleAndResourceHandleAreSet) {
init();
struct MockWddmMemoryManager : public WddmMemoryManager {
using WddmMemoryManager::createGpuAllocationsWithRetry;
using WddmMemoryManager::WddmMemoryManager;
};
MemoryManagerCreate<MockWddmMemoryManager> memoryManager(false, false, *executionEnvironment);
WddmAllocation allocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, MemoryConstants::pageSize, nullptr, MemoryPool::MemoryNull, true);
auto gmm = std::unique_ptr<Gmm>(GmmHelperFunctions::getGmm(nullptr, MemoryConstants::pageSize));
allocation.setDefaultGmm(gmm.get());
auto status = memoryManager.createGpuAllocationsWithRetry(&allocation);
EXPECT_TRUE(status);
EXPECT_NE(0u, allocation.resourceHandle);
EXPECT_NE(0u, allocation.peekSharedHandle());
}
TEST(WddmAllocationTest, whenAllocationIsShareableThenSharedHandleToModifyIsSharedHandleOfAllocation) {
WddmAllocation allocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, MemoryConstants::pageSize, nullptr, MemoryPool::MemoryNull, true);
auto sharedHandleToModify = allocation.getSharedHandleToModify();
EXPECT_NE(nullptr, sharedHandleToModify);
*sharedHandleToModify = 1234u;
EXPECT_EQ(*sharedHandleToModify, allocation.peekSharedHandle());
}
TEST(WddmAllocationTest, whenAllocationIsNotShareableThenItDoesntReturnSharedHandleToModify) {
WddmAllocation allocation(0, GraphicsAllocation::AllocationType::UNKNOWN, nullptr, MemoryConstants::pageSize, nullptr, MemoryPool::MemoryNull, false);
auto sharedHandleToModify = allocation.getSharedHandleToModify();
EXPECT_EQ(nullptr, sharedHandleToModify);
}
TEST_F(Wddm20Tests, makeResidentNonResident) {
OsAgnosticMemoryManager mm(*executionEnvironment);
WddmAllocation allocation(0, GraphicsAllocation::AllocationType::UNKNOWN, mm.allocateSystemMemory(100, 0), 100, nullptr, MemoryPool::MemoryNull);

View File

@@ -132,9 +132,10 @@ TEST_F(WddmKmDafListenerTest, givenWddmWhenEvictIsCalledThenKmDafListenerNotifyE
TEST_F(WddmKmDafListenerTest, givenWddmWhenCreateAllocationIsCalledThenKmDafListenerNotifyWriteTargetIsFedWithCorrectParams) {
auto gmm = std::make_unique<Gmm>(rootDeviceEnvironment->getGmmClientContext(), nullptr, 1, false);
auto handle = 0u;
auto resourceHandle = 0u;
auto ptr = reinterpret_cast<void *>(0x10000);
wddmWithKmDafMock->createAllocation(ptr, gmm.get(), handle, false);
wddmWithKmDafMock->createAllocation(ptr, gmm.get(), handle, resourceHandle, nullptr);
EXPECT_EQ(wddmWithKmDafMock->featureTable->ftrKmdDaf, wddmWithKmDafMock->getKmDafListenerMock().notifyWriteTargetParametrization.ftrKmdDaf);
EXPECT_EQ(wddmWithKmDafMock->getAdapter(), wddmWithKmDafMock->getKmDafListenerMock().notifyWriteTargetParametrization.hAdapter);

View File

@@ -460,12 +460,12 @@ TEST_F(WddmMemoryManagerTest, AllocateGpuMemHostPtr) {
alignedFree(ptr);
}
TEST_F(WddmMemoryManagerTest, givenDefaultMemoryManagerWhenAllocateWithSizeIsCalledThenResourceHandleIsZero) {
TEST_F(WddmMemoryManagerTest, givenDefaultMemoryManagerWhenAllocateWithSizeIsCalledThenSharedHandleIsZero) {
auto *gpuAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
auto wddmAllocation = static_cast<WddmAllocation *>(gpuAllocation);
EXPECT_EQ(0u, wddmAllocation->resourceHandle);
EXPECT_EQ(0u, wddmAllocation->peekSharedHandle());
memoryManager->freeGraphicsMemory(gpuAllocation);
}