Cleanup Wddm interface 3/3

don't pass the entire WddmAllocation when only handle is needed

Change-Id: I208a64c81767589a2ac8aba0e717d54426209ecd
Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
Mateusz Jablonski
2019-03-06 08:39:06 +01:00
parent 4605a48170
commit e721f7c08c
9 changed files with 120 additions and 123 deletions

View File

@@ -146,24 +146,25 @@ bool WddmMock::waitOnGPU(D3DKMT_HANDLE context) {
return waitOnGPUResult.success = Wddm::waitOnGPU(context);
}
void *WddmMock::lockResource(WddmAllocation &allocation) {
void *WddmMock::lockResource(const D3DKMT_HANDLE &handle, bool applyMakeResidentPriorToLock) {
lockResult.called++;
auto ptr = Wddm::lockResource(allocation);
auto ptr = Wddm::lockResource(handle, applyMakeResidentPriorToLock);
lockResult.success = ptr != nullptr;
lockResult.uint64ParamPassed = applyMakeResidentPriorToLock;
return ptr;
}
void WddmMock::unlockResource(WddmAllocation &allocation) {
void WddmMock::unlockResource(const D3DKMT_HANDLE &handle) {
unlockResult.called++;
unlockResult.success = true;
Wddm::unlockResource(allocation);
Wddm::unlockResource(handle);
}
void WddmMock::kmDafLock(WddmAllocation *allocation) {
void WddmMock::kmDafLock(D3DKMT_HANDLE handle) {
kmDafLockResult.called++;
kmDafLockResult.success = true;
kmDafLockResult.lockedAllocations.push_back(allocation);
Wddm::kmDafLock(allocation);
kmDafLockResult.lockedAllocations.push_back(handle);
Wddm::kmDafLock(handle);
}
bool WddmMock::isKmDafEnabled() const {
@@ -242,15 +243,15 @@ EvictionStatus WddmMock::evictAllTemporaryResources() {
return evictAllTemporaryResourcesResult.status;
}
EvictionStatus WddmMock::evictTemporaryResource(WddmAllocation &allocation) {
EvictionStatus WddmMock::evictTemporaryResource(const D3DKMT_HANDLE &handle) {
evictTemporaryResourceResult.called++;
evictTemporaryResourceResult.status = Wddm::evictTemporaryResource(allocation);
evictTemporaryResourceResult.status = Wddm::evictTemporaryResource(handle);
return evictTemporaryResourceResult.status;
}
void WddmMock::applyBlockingMakeResident(WddmAllocation &allocation) {
void WddmMock::applyBlockingMakeResident(const D3DKMT_HANDLE &handle) {
applyBlockingMakeResidentResult.called++;
return Wddm::applyBlockingMakeResident(allocation);
return Wddm::applyBlockingMakeResident(handle);
}
std::unique_lock<SpinLock> WddmMock::acquireLock(SpinLock &lock) {

View File

@@ -36,7 +36,7 @@ struct EvictCallResult : public CallResult {
EvictionStatus status = EvictionStatus::UNKNOWN;
};
struct KmDafLockCall : public CallResult {
std::vector<GraphicsAllocation *> lockedAllocations;
std::vector<D3DKMT_HANDLE> lockedAllocations;
};
} // namespace WddmMockHelpers
@@ -76,9 +76,9 @@ class WddmMock : public Wddm {
bool queryAdapterInfo() override;
bool submit(uint64_t commandBuffer, size_t size, void *commandHeader, OsContextWin &osContext) override;
bool waitOnGPU(D3DKMT_HANDLE context) override;
void *lockResource(WddmAllocation &allocation) override;
void unlockResource(WddmAllocation &allocation) override;
void kmDafLock(WddmAllocation *allocation) override;
void *lockResource(const D3DKMT_HANDLE &handle, bool applyMakeResidentPriorToLock) override;
void unlockResource(const D3DKMT_HANDLE &handle) override;
void kmDafLock(D3DKMT_HANDLE handle) override;
bool isKmDafEnabled() const override;
void setKmDafEnabled(bool state);
void setHwContextId(unsigned long hwContextId);
@@ -91,8 +91,8 @@ class WddmMock : public Wddm {
void releaseReservedAddress(void *reservedAddress) override;
VOID *registerTrimCallback(PFND3DKMT_TRIMNOTIFICATIONCALLBACK callback, WddmResidencyController &residencyController) override;
EvictionStatus evictAllTemporaryResources() override;
EvictionStatus evictTemporaryResource(WddmAllocation &allocation) override;
void applyBlockingMakeResident(WddmAllocation &allocation) override;
EvictionStatus evictTemporaryResource(const D3DKMT_HANDLE &handle) override;
void applyBlockingMakeResident(const D3DKMT_HANDLE &handle) override;
std::unique_lock<SpinLock> acquireLock(SpinLock &lock) override;
bool reserveValidAddressRange(size_t size, void *&reservedMem);
GmmMemory *getGmmMemory() const;

View File

@@ -404,7 +404,7 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithResi
LinearStream cs(commandBuffer);
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
auto linearStreamAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
auto linearStreamAllocation = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}));
ASSERT_NE(nullptr, linearStreamAllocation);
linearStreamAllocation->setAllocationType(GraphicsAllocation::AllocationType::LINEAR_STREAM);
@@ -417,7 +417,7 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithResi
EXPECT_EQ(1u, wddm->kmDafLockResult.called);
EXPECT_EQ(1u, wddm->kmDafLockResult.lockedAllocations.size());
EXPECT_EQ(linearStreamAllocation, wddm->kmDafLockResult.lockedAllocations[0]);
EXPECT_EQ(linearStreamAllocation->handle, wddm->kmDafLockResult.lockedAllocations[0]);
memoryManager->freeGraphicsMemory(commandBuffer);
memoryManager->freeGraphicsMemory(linearStreamAllocation);
@@ -429,7 +429,7 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllo
LinearStream cs(commandBuffer);
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
auto linearStreamAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
auto linearStreamAllocation = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}));
ASSERT_NE(nullptr, linearStreamAllocation);
linearStreamAllocation->setAllocationType(GraphicsAllocation::AllocationType::LINEAR_STREAM);
ResidencyContainer allocationsForResidency = {linearStreamAllocation};
@@ -439,7 +439,7 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllo
EXPECT_EQ(1u, wddm->kmDafLockResult.called);
EXPECT_EQ(1u, wddm->kmDafLockResult.lockedAllocations.size());
EXPECT_EQ(linearStreamAllocation, wddm->kmDafLockResult.lockedAllocations[0]);
EXPECT_EQ(linearStreamAllocation->handle, wddm->kmDafLockResult.lockedAllocations[0]);
memoryManager->freeGraphicsMemory(commandBuffer);
memoryManager->freeGraphicsMemory(linearStreamAllocation);
@@ -451,7 +451,7 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllo
LinearStream cs(commandBuffer);
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
auto fillPatternAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
auto fillPatternAllocation = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}));
ASSERT_NE(nullptr, fillPatternAllocation);
fillPatternAllocation->setAllocationType(GraphicsAllocation::AllocationType::FILL_PATTERN);
ResidencyContainer allocationsForResidency = {fillPatternAllocation};
@@ -461,7 +461,7 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllo
EXPECT_EQ(1u, wddm->kmDafLockResult.called);
EXPECT_EQ(1u, wddm->kmDafLockResult.lockedAllocations.size());
EXPECT_EQ(fillPatternAllocation, wddm->kmDafLockResult.lockedAllocations[0]);
EXPECT_EQ(fillPatternAllocation->handle, wddm->kmDafLockResult.lockedAllocations[0]);
memoryManager->freeGraphicsMemory(commandBuffer);
memoryManager->freeGraphicsMemory(fillPatternAllocation);
@@ -473,7 +473,7 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllo
LinearStream cs(commandBuffer);
BatchBuffer batchBuffer{cs.getGraphicsAllocation(), 0, 0, nullptr, false, false, QueueThrottle::MEDIUM, cs.getUsed(), &cs};
auto commandBufferAllocation = memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize});
auto commandBufferAllocation = static_cast<WddmAllocation *>(memoryManager->allocateGraphicsMemoryWithProperties(MockAllocationProperties{MemoryConstants::pageSize}));
ASSERT_NE(nullptr, commandBufferAllocation);
commandBufferAllocation->setAllocationType(GraphicsAllocation::AllocationType::COMMAND_BUFFER);
ResidencyContainer allocationsForResidency = {commandBufferAllocation};
@@ -483,7 +483,7 @@ TEST_F(WddmCommandStreamTest, givenWddmWithKmDafEnabledWhenFlushIsCalledWithAllo
EXPECT_EQ(1u, wddm->kmDafLockResult.called);
EXPECT_EQ(1u, wddm->kmDafLockResult.lockedAllocations.size());
EXPECT_EQ(commandBufferAllocation, wddm->kmDafLockResult.lockedAllocations[0]);
EXPECT_EQ(commandBufferAllocation->handle, wddm->kmDafLockResult.lockedAllocations[0]);
memoryManager->freeGraphicsMemory(commandBuffer);
memoryManager->freeGraphicsMemory(commandBufferAllocation);

View File

@@ -21,6 +21,7 @@
#include "runtime/os_interface/windows/wddm_memory_manager.h"
#include "unit_tests/helpers/debug_manager_state_restore.h"
#include "unit_tests/mocks/mock_gmm_resource_info.h"
#include "unit_tests/os_interface/windows/mock_wddm_allocation.h"
#include "unit_tests/os_interface/windows/wddm_fixture.h"
#include "gtest/gtest.h"
@@ -835,60 +836,55 @@ TEST_F(Wddm20Tests, givenNullTrimCallbackHandleWhenUnregisteringTrimCallbackThen
EXPECT_EQ(trimCallbackHandleBefore, gdi->getUnregisterTrimNotificationArg().Handle);
}
TEST_F(Wddm20Tests, givenAllocationThatDoesntNeedMakeResidentBeforeLockWhenLockThenDontStoreItOrCallMakeResident) {
WddmAllocation allocation{GraphicsAllocation::AllocationType::UNDECIDED, nullptr, 0, nullptr, MemoryPool::MemoryNull, false};
EXPECT_FALSE(allocation.needsMakeResidentBeforeLock);
using WddmLockWithMakeResidentTests = Wddm20Tests;
TEST_F(WddmLockWithMakeResidentTests, givenAllocationThatDoesntNeedMakeResidentBeforeLockWhenLockThenDontStoreItOrCallMakeResident) {
EXPECT_TRUE(wddm->temporaryResources.empty());
EXPECT_EQ(0u, wddm->makeResidentResult.called);
wddm->lockResource(allocation);
wddm->lockResource(ALLOCATION_HANDLE, false);
EXPECT_TRUE(wddm->temporaryResources.empty());
EXPECT_EQ(0u, wddm->makeResidentResult.called);
wddm->unlockResource(allocation);
wddm->unlockResource(ALLOCATION_HANDLE);
}
TEST_F(Wddm20Tests, givenAllocationThatNeedsMakeResidentBeforeLockWhenLockThenCallBlockingMakeResident) {
WddmAllocation allocation{GraphicsAllocation::AllocationType::UNDECIDED, nullptr, 0, nullptr, MemoryPool::MemoryNull, false};
allocation.needsMakeResidentBeforeLock = true;
wddm->lockResource(allocation);
TEST_F(WddmLockWithMakeResidentTests, givenAllocationThatNeedsMakeResidentBeforeLockWhenLockThenCallBlockingMakeResident) {
wddm->lockResource(ALLOCATION_HANDLE, true);
EXPECT_EQ(1u, wddm->applyBlockingMakeResidentResult.called);
}
TEST_F(Wddm20Tests, givenAllocationWhenApplyBlockingMakeResidentThenAcquireUniqueLock) {
WddmAllocation allocation{GraphicsAllocation::AllocationType::UNDECIDED, nullptr, 0, nullptr, MemoryPool::MemoryNull, false};
wddm->applyBlockingMakeResident(allocation);
TEST_F(WddmLockWithMakeResidentTests, givenAllocationWhenApplyBlockingMakeResidentThenAcquireUniqueLock) {
wddm->applyBlockingMakeResident(ALLOCATION_HANDLE);
EXPECT_EQ(1u, wddm->acquireLockResult.called);
EXPECT_EQ(reinterpret_cast<uint64_t>(&wddm->temporaryResourcesLock), wddm->acquireLockResult.uint64ParamPassed);
}
TEST_F(Wddm20Tests, givenAllocationWhenApplyBlockingMakeResidentThenCallMakeResidentAndStoreAllocation) {
WddmAllocation allocation{GraphicsAllocation::AllocationType::UNDECIDED, nullptr, 0, nullptr, MemoryPool::MemoryNull, false};
wddm->applyBlockingMakeResident(allocation);
TEST_F(WddmLockWithMakeResidentTests, givenAllocationWhenApplyBlockingMakeResidentThenCallMakeResidentAndStoreAllocation) {
wddm->applyBlockingMakeResident(ALLOCATION_HANDLE);
EXPECT_EQ(1u, wddm->makeResidentResult.called);
EXPECT_EQ(allocation.handle, wddm->temporaryResources.back());
EXPECT_EQ(ALLOCATION_HANDLE, wddm->temporaryResources.back());
}
TEST_F(Wddm20Tests, givenAllocationWhenApplyBlockingMakeResidentThenWaitForCurrentPagingFenceValue) {
WddmAllocation allocation{GraphicsAllocation::AllocationType::UNDECIDED, nullptr, 0, nullptr, MemoryPool::MemoryNull, false};
TEST_F(WddmLockWithMakeResidentTests, givenAllocationWhenApplyBlockingMakeResidentThenWaitForCurrentPagingFenceValue) {
wddm->mockPagingFence = 0u;
wddm->currentPagingFenceValue = 3u;
wddm->applyBlockingMakeResident(allocation);
wddm->applyBlockingMakeResident(ALLOCATION_HANDLE);
EXPECT_EQ(1u, wddm->makeResidentResult.called);
EXPECT_EQ(3u, wddm->mockPagingFence);
EXPECT_EQ(3u, wddm->getPagingFenceAddressResult.called);
}
TEST_F(Wddm20Tests, givenAllocationWhenApplyBlockingMakeResidentAndMakeResidentCallFailsThenEvictTemporaryResourcesAndRetry) {
TEST_F(WddmLockWithMakeResidentTests, givenAllocationWhenApplyBlockingMakeResidentAndMakeResidentCallFailsThenEvictTemporaryResourcesAndRetry) {
WddmAllocation allocation{GraphicsAllocation::AllocationType::UNDECIDED, nullptr, 0, nullptr, MemoryPool::MemoryNull, false};
GmockWddm gmockWddm;
EXPECT_CALL(gmockWddm, makeResident(&allocation.handle, ::testing::_, ::testing::_, ::testing::_)).Times(2).WillRepeatedly(::testing::Return(false));
gmockWddm.applyBlockingMakeResident(allocation);
gmockWddm.applyBlockingMakeResident(allocation.handle);
EXPECT_EQ(1u, gmockWddm.evictAllTemporaryResourcesResult.called);
}
TEST_F(Wddm20Tests, whenApplyBlockingMakeResidentAndTemporaryResourcesAreEvictedSuccessfullyThenCallMakeResidentOneMoreTime) {
TEST_F(WddmLockWithMakeResidentTests, whenApplyBlockingMakeResidentAndTemporaryResourcesAreEvictedSuccessfullyThenCallMakeResidentOneMoreTime) {
WddmAllocation allocation{GraphicsAllocation::AllocationType::UNDECIDED, nullptr, 0, nullptr, MemoryPool::MemoryNull, false};
GmockWddm gmockWddm;
gmockWddm.temporaryResources.push_back(allocation.handle);
EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillRepeatedly(::testing::Return(true));
EXPECT_CALL(gmockWddm, makeResident(&allocation.handle, ::testing::_, ::testing::_, ::testing::_)).Times(3).WillRepeatedly(::testing::Return(false));
gmockWddm.applyBlockingMakeResident(allocation);
gmockWddm.applyBlockingMakeResident(allocation.handle);
EXPECT_EQ(2u, gmockWddm.evictAllTemporaryResourcesResult.called);
}
TEST_F(Wddm20Tests, whenApplyBlockingMakeResidentAndMakeResidentStillFailsThenDontStoreTemporaryResource) {
TEST_F(WddmLockWithMakeResidentTests, whenApplyBlockingMakeResidentAndMakeResidentStillFailsThenDontStoreTemporaryResource) {
WddmAllocation allocation{GraphicsAllocation::AllocationType::UNDECIDED, nullptr, 0, nullptr, MemoryPool::MemoryNull, false};
allocation.handle = 0x2;
GmockWddm gmockWddm;
@@ -896,10 +892,10 @@ TEST_F(Wddm20Tests, whenApplyBlockingMakeResidentAndMakeResidentStillFailsThenDo
EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillRepeatedly(::testing::Return(true));
EXPECT_CALL(gmockWddm, makeResident(&allocation.handle, ::testing::_, ::testing::_, ::testing::_)).Times(3).WillRepeatedly(::testing::Return(false));
EXPECT_EQ(1u, gmockWddm.temporaryResources.size());
gmockWddm.applyBlockingMakeResident(allocation);
gmockWddm.applyBlockingMakeResident(allocation.handle);
EXPECT_EQ(0u, gmockWddm.temporaryResources.size());
}
TEST_F(Wddm20Tests, whenApplyBlockingMakeResidentAndMakeResidentPassesAfterEvictThenStoreTemporaryResource) {
TEST_F(WddmLockWithMakeResidentTests, whenApplyBlockingMakeResidentAndMakeResidentPassesAfterEvictThenStoreTemporaryResource) {
WddmAllocation allocation{GraphicsAllocation::AllocationType::UNDECIDED, nullptr, 0, nullptr, MemoryPool::MemoryNull, false};
allocation.handle = 0x2;
GmockWddm gmockWddm;
@@ -907,30 +903,30 @@ TEST_F(Wddm20Tests, whenApplyBlockingMakeResidentAndMakeResidentPassesAfterEvict
EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillRepeatedly(::testing::Return(true));
EXPECT_CALL(gmockWddm, makeResident(&allocation.handle, ::testing::_, ::testing::_, ::testing::_)).Times(2).WillOnce(::testing::Return(false)).WillOnce(::testing::Return(true));
EXPECT_EQ(1u, gmockWddm.temporaryResources.size());
gmockWddm.applyBlockingMakeResident(allocation);
gmockWddm.applyBlockingMakeResident(allocation.handle);
EXPECT_EQ(1u, gmockWddm.temporaryResources.size());
EXPECT_EQ(0x2, gmockWddm.temporaryResources.back());
}
TEST_F(Wddm20Tests, whenApplyBlockingMakeResidentAndMakeResidentPassesThenStoreTemporaryResource) {
TEST_F(WddmLockWithMakeResidentTests, whenApplyBlockingMakeResidentAndMakeResidentPassesThenStoreTemporaryResource) {
WddmAllocation allocation{GraphicsAllocation::AllocationType::UNDECIDED, nullptr, 0, nullptr, MemoryPool::MemoryNull, false};
allocation.handle = 0x2;
GmockWddm gmockWddm;
gmockWddm.temporaryResources.push_back(0x1);
EXPECT_CALL(gmockWddm, makeResident(&allocation.handle, ::testing::_, ::testing::_, ::testing::_)).Times(1).WillOnce(::testing::Return(true));
gmockWddm.applyBlockingMakeResident(allocation);
gmockWddm.applyBlockingMakeResident(allocation.handle);
EXPECT_EQ(2u, gmockWddm.temporaryResources.size());
EXPECT_EQ(0x2, gmockWddm.temporaryResources.back());
}
TEST_F(Wddm20Tests, givenNoTemporaryResourcesWhenEvictingAllTemporaryResourcesThenEvictionIsNotApplied) {
TEST_F(WddmLockWithMakeResidentTests, givenNoTemporaryResourcesWhenEvictingAllTemporaryResourcesThenEvictionIsNotApplied) {
wddm->evictAllTemporaryResources();
EXPECT_EQ(EvictionStatus::NOT_APPLIED, wddm->evictAllTemporaryResourcesResult.status);
}
TEST_F(Wddm20Tests, whenEvictingAllTemporaryResourcesThenAcquireTemporaryResourcesLock) {
TEST_F(WddmLockWithMakeResidentTests, whenEvictingAllTemporaryResourcesThenAcquireTemporaryResourcesLock) {
wddm->evictAllTemporaryResources();
EXPECT_EQ(1u, wddm->acquireLockResult.called);
EXPECT_EQ(reinterpret_cast<uint64_t>(&wddm->temporaryResourcesLock), wddm->acquireLockResult.uint64ParamPassed);
}
TEST_F(Wddm20Tests, whenEvictingAllTemporaryResourcesAndAllEvictionsSucceedThenReturnSuccess) {
TEST_F(WddmLockWithMakeResidentTests, whenEvictingAllTemporaryResourcesAndAllEvictionsSucceedThenReturnSuccess) {
WddmAllocation allocation{GraphicsAllocation::AllocationType::UNDECIDED, nullptr, 0, nullptr, MemoryPool::MemoryNull, false};
GmockWddm gmockWddm;
gmockWddm.temporaryResources.push_back(allocation.handle);
@@ -939,7 +935,7 @@ TEST_F(Wddm20Tests, whenEvictingAllTemporaryResourcesAndAllEvictionsSucceedThenR
EXPECT_EQ(1u, gmockWddm.evictAllTemporaryResourcesResult.called);
EXPECT_EQ(EvictionStatus::SUCCESS, gmockWddm.evictAllTemporaryResourcesResult.status);
}
TEST_F(Wddm20Tests, givenThreeAllocationsWhenEvictingAllTemporaryResourcesThenCallEvictForEachAllocationAndCleanList) {
TEST_F(WddmLockWithMakeResidentTests, givenThreeAllocationsWhenEvictingAllTemporaryResourcesThenCallEvictForEachAllocationAndCleanList) {
GmockWddm gmockWddm;
constexpr uint32_t numAllocations = 3u;
for (auto i = 0u; i < numAllocations; i++) {
@@ -949,7 +945,7 @@ TEST_F(Wddm20Tests, givenThreeAllocationsWhenEvictingAllTemporaryResourcesThenCa
gmockWddm.evictAllTemporaryResources();
EXPECT_TRUE(gmockWddm.temporaryResources.empty());
}
TEST_F(Wddm20Tests, givenThreeAllocationsWhenEvictingAllTemporaryResourcesAndOneOfThemFailsThenReturnFail) {
TEST_F(WddmLockWithMakeResidentTests, givenThreeAllocationsWhenEvictingAllTemporaryResourcesAndOneOfThemFailsThenReturnFail) {
GmockWddm gmockWddm;
constexpr uint32_t numAllocations = 3u;
for (auto i = 0u; i < numAllocations; i++) {
@@ -959,58 +955,66 @@ TEST_F(Wddm20Tests, givenThreeAllocationsWhenEvictingAllTemporaryResourcesAndOne
gmockWddm.evictAllTemporaryResources();
EXPECT_EQ(EvictionStatus::FAILED, gmockWddm.evictAllTemporaryResourcesResult.status);
}
TEST_F(Wddm20Tests, givenNoTemporaryResourcesWhenEvictingTemporaryResourceThenEvictionIsNotApplied) {
WddmAllocation allocation{GraphicsAllocation::AllocationType::UNDECIDED, nullptr, 0, nullptr, MemoryPool::MemoryNull, false};
wddm->evictTemporaryResource(allocation);
TEST_F(WddmLockWithMakeResidentTests, givenNoTemporaryResourcesWhenEvictingTemporaryResourceThenEvictionIsNotApplied) {
wddm->evictTemporaryResource(ALLOCATION_HANDLE);
EXPECT_EQ(EvictionStatus::NOT_APPLIED, wddm->evictTemporaryResourceResult.status);
}
TEST_F(Wddm20Tests, whenEvictingTemporaryResourceThenAcquireTemporaryResourcesLock) {
WddmAllocation allocation{GraphicsAllocation::AllocationType::UNDECIDED, nullptr, 0, nullptr, MemoryPool::MemoryNull, false};
wddm->evictTemporaryResource(allocation);
TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceThenAcquireTemporaryResourcesLock) {
wddm->evictTemporaryResource(ALLOCATION_HANDLE);
EXPECT_EQ(1u, wddm->acquireLockResult.called);
EXPECT_EQ(reinterpret_cast<uint64_t>(&wddm->temporaryResourcesLock), wddm->acquireLockResult.uint64ParamPassed);
}
TEST_F(Wddm20Tests, whenEvictingNonExistingTemporaryResourceThenEvictIsNotAppliedAndTemporaryResourcesAreRestored) {
WddmAllocation allocation{GraphicsAllocation::AllocationType::UNDECIDED, nullptr, 0, nullptr, MemoryPool::MemoryNull, false};
allocation.handle = 0x1;
wddm->temporaryResources.push_back(0x2);
TEST_F(WddmLockWithMakeResidentTests, whenEvictingNonExistingTemporaryResourceThenEvictIsNotAppliedAndTemporaryResourcesAreRestored) {
wddm->temporaryResources.push_back(ALLOCATION_HANDLE);
EXPECT_FALSE(wddm->temporaryResources.empty());
wddm->evictTemporaryResource(allocation);
wddm->evictTemporaryResource(ALLOCATION_HANDLE + 1);
EXPECT_FALSE(wddm->temporaryResources.empty());
EXPECT_EQ(EvictionStatus::NOT_APPLIED, wddm->evictTemporaryResourceResult.status);
}
TEST_F(Wddm20Tests, whenEvictingTemporaryResourceAndEvictFailsThenReturnFail) {
WddmAllocation allocation{GraphicsAllocation::AllocationType::UNDECIDED, nullptr, 0, nullptr, MemoryPool::MemoryNull, false};
TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceAndEvictFailsThenReturnFail) {
GmockWddm gmockWddm;
gmockWddm.temporaryResources.push_back(allocation.handle);
gmockWddm.temporaryResources.push_back(ALLOCATION_HANDLE);
EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillOnce(::testing::Return(false));
gmockWddm.evictTemporaryResource(allocation);
gmockWddm.evictTemporaryResource(ALLOCATION_HANDLE);
EXPECT_TRUE(gmockWddm.temporaryResources.empty());
EXPECT_EQ(EvictionStatus::FAILED, gmockWddm.evictTemporaryResourceResult.status);
}
TEST_F(Wddm20Tests, whenEvictingTemporaryResourceAndEvictSucceedThenReturnSuccess) {
WddmAllocation allocation{GraphicsAllocation::AllocationType::UNDECIDED, nullptr, 0, nullptr, MemoryPool::MemoryNull, false};
TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceAndEvictSucceedThenReturnSuccess) {
GmockWddm gmockWddm;
gmockWddm.temporaryResources.push_back(allocation.handle);
gmockWddm.temporaryResources.push_back(ALLOCATION_HANDLE);
EXPECT_CALL(gmockWddm, evict(::testing::_, ::testing::_, ::testing::_)).Times(1).WillOnce(::testing::Return(true));
gmockWddm.evictTemporaryResource(allocation);
gmockWddm.evictTemporaryResource(ALLOCATION_HANDLE);
EXPECT_TRUE(gmockWddm.temporaryResources.empty());
EXPECT_EQ(EvictionStatus::SUCCESS, gmockWddm.evictTemporaryResourceResult.status);
}
TEST_F(Wddm20Tests, whenEvictingTemporaryResourceThenOtherResourcesRemainOnTheList) {
TEST_F(WddmLockWithMakeResidentTests, whenEvictingTemporaryResourceThenOtherResourcesRemainOnTheList) {
wddm->temporaryResources.push_back(0x1);
wddm->temporaryResources.push_back(0x2);
wddm->temporaryResources.push_back(0x3);
WddmAllocation allocation{GraphicsAllocation::AllocationType::UNDECIDED, nullptr, 0, nullptr, MemoryPool::MemoryNull, false};
allocation.handle = 0x2;
wddm->evictTemporaryResource(allocation);
wddm->evictTemporaryResource(0x2);
EXPECT_EQ(2u, wddm->temporaryResources.size());
EXPECT_EQ(0x1, wddm->temporaryResources.front());
EXPECT_EQ(0x3, wddm->temporaryResources.back());
}
TEST_F(WddmLockWithMakeResidentTests, whenAlllocationNeedsBlockingMakeResidentBeforeLockThenLockWithBlockingMakeResident) {
WddmMemoryManager memoryManager(false, false, wddm, executionEnvironment);
MockWddmAllocation allocation;
allocation.needsMakeResidentBeforeLock = false;
memoryManager.lockResource(&allocation);
EXPECT_EQ(1u, wddm->lockResult.called);
EXPECT_EQ(0u, wddm->lockResult.uint64ParamPassed);
memoryManager.unlockResource(&allocation);
allocation.needsMakeResidentBeforeLock = true;
memoryManager.lockResource(&allocation);
EXPECT_EQ(2u, wddm->lockResult.called);
EXPECT_EQ(1u, wddm->lockResult.uint64ParamPassed);
memoryManager.unlockResource(&allocation);
}
TEST(WddmInternalHeapTest, whenConfigurationIs64BitThenInternalHeapIndexIsHeapInternalDeviceMemory) {
if (is64bit) {
EXPECT_EQ(HeapIndex::HEAP_INTERNAL_DEVICE_MEMORY, internalHeapIndex);

View File

@@ -52,29 +52,23 @@ class WddmKmDafListenerTest : public GmmEnvironmentFixture, public ::testing::Te
};
TEST_F(WddmKmDafListenerTest, givenWddmWhenLockResourceIsCalledThenKmDafListenerNotifyLockIsFedWithCorrectParams) {
MockWddmAllocation allocation;
allocation.handle = ALLOCATION_HANDLE;
wddmWithKmDafMock->lockResource(allocation);
wddmWithKmDafMock->lockResource(ALLOCATION_HANDLE, false);
EXPECT_EQ(wddmWithKmDafMock->featureTable->ftrKmdDaf, wddmWithKmDafMock->getKmDafListenerMock().notifyLockParametrization.ftrKmdDaf);
EXPECT_EQ(wddmWithKmDafMock->getAdapter(), wddmWithKmDafMock->getKmDafListenerMock().notifyLockParametrization.hAdapter);
EXPECT_EQ(wddmWithKmDafMock->getDevice(), wddmWithKmDafMock->getKmDafListenerMock().notifyLockParametrization.hDevice);
EXPECT_EQ(allocation.handle, wddmWithKmDafMock->getKmDafListenerMock().notifyLockParametrization.hAllocation);
EXPECT_EQ(ALLOCATION_HANDLE, wddmWithKmDafMock->getKmDafListenerMock().notifyLockParametrization.hAllocation);
EXPECT_EQ(0, wddmWithKmDafMock->getKmDafListenerMock().notifyLockParametrization.pLockFlags);
EXPECT_EQ(wddmWithKmDafMock->getGdi()->escape, wddmWithKmDafMock->getKmDafListenerMock().notifyLockParametrization.pfnEscape);
}
TEST_F(WddmKmDafListenerTest, givenWddmWhenUnlockResourceIsCalledThenKmDafListenerNotifyUnlockIsFedWithCorrectParams) {
MockWddmAllocation allocation;
allocation.handle = ALLOCATION_HANDLE;
wddmWithKmDafMock->unlockResource(allocation);
wddmWithKmDafMock->unlockResource(ALLOCATION_HANDLE);
EXPECT_EQ(wddmWithKmDafMock->featureTable->ftrKmdDaf, wddmWithKmDafMock->getKmDafListenerMock().notifyUnlockParametrization.ftrKmdDaf);
EXPECT_EQ(wddmWithKmDafMock->getAdapter(), wddmWithKmDafMock->getKmDafListenerMock().notifyUnlockParametrization.hAdapter);
EXPECT_EQ(wddmWithKmDafMock->getDevice(), wddmWithKmDafMock->getKmDafListenerMock().notifyUnlockParametrization.hDevice);
EXPECT_EQ(allocation.handle, *wddmWithKmDafMock->getKmDafListenerMock().notifyUnlockParametrization.phAllocation);
EXPECT_EQ(ALLOCATION_HANDLE, *wddmWithKmDafMock->getKmDafListenerMock().notifyUnlockParametrization.phAllocation);
EXPECT_EQ(1u, wddmWithKmDafMock->getKmDafListenerMock().notifyUnlockParametrization.allocations);
EXPECT_EQ(wddmWithKmDafMock->getGdi()->escape, wddmWithKmDafMock->getKmDafListenerMock().notifyUnlockParametrization.pfnEscape);
}
@@ -190,15 +184,12 @@ TEST_F(WddmKmDafListenerTest, givenWddmWhenCreateAllocationsAndMapGpuVaIsCalledT
}
TEST_F(WddmKmDafListenerTest, givenWddmWhenKmDafLockIsCalledThenKmDafListenerNotifyLockIsFedWithCorrectParams) {
MockWddmAllocation allocation;
allocation.handle = ALLOCATION_HANDLE;
wddmWithKmDafMock->kmDafLock(&allocation);
wddmWithKmDafMock->kmDafLock(ALLOCATION_HANDLE);
EXPECT_EQ(wddmWithKmDafMock->featureTable->ftrKmdDaf, wddmWithKmDafMock->getKmDafListenerMock().notifyLockParametrization.ftrKmdDaf);
EXPECT_EQ(wddmWithKmDafMock->getAdapter(), wddmWithKmDafMock->getKmDafListenerMock().notifyLockParametrization.hAdapter);
EXPECT_EQ(wddmWithKmDafMock->getDevice(), wddmWithKmDafMock->getKmDafListenerMock().notifyLockParametrization.hDevice);
EXPECT_EQ(allocation.handle, wddmWithKmDafMock->getKmDafListenerMock().notifyLockParametrization.hAllocation);
EXPECT_EQ(ALLOCATION_HANDLE, wddmWithKmDafMock->getKmDafListenerMock().notifyLockParametrization.hAllocation);
EXPECT_EQ(0, wddmWithKmDafMock->getKmDafListenerMock().notifyLockParametrization.pLockFlags);
EXPECT_EQ(wddmWithKmDafMock->getGdi()->escape, wddmWithKmDafMock->getKmDafListenerMock().notifyLockParametrization.pfnEscape);
}