OsInterface cleanup.

- OsInterface is now a part of execution environment
- it is created when getDevice is being called
- move ownership of wddm from Wddm Memory manager to OSInterface
- reuse osInterface on Linux in Command Stream Receiver
- currently OsInterface is not reused upon command stream receiver creation
on Windows this will change in further commits.
- make enumAdapters non static function

Change-Id: I10f36c01e6729f48653e3b5c11cbc32e811ce754
This commit is contained in:
Mrozek, Michal
2018-08-10 11:07:17 +02:00
committed by sys_ocldev
parent 2845e34c12
commit ae9134233d
24 changed files with 193 additions and 153 deletions

View File

@ -91,7 +91,7 @@ class CommandStreamReceiver {
void waitForTaskCountAndCleanAllocationList(uint32_t requiredTaskCount, uint32_t allocationType);
LinearStream &getCS(size_t minRequiredSize = 1024u);
OSInterface *getOSInterface() { return osInterface.get(); };
OSInterface *getOSInterface() { return osInterface; };
MOCKABLE_VIRTUAL void setTagAllocation(GraphicsAllocation *allocation);
GraphicsAllocation *getTagAllocation() const {
@ -190,7 +190,7 @@ class CommandStreamReceiver {
GraphicsAllocation *debugSurface = nullptr;
MemoryManager *memoryManager = nullptr;
std::unique_ptr<OSInterface> osInterface;
OSInterface *osInterface = nullptr;
std::unique_ptr<SubmissionAggregator> submissionAggregator;
bool nTo1SubmissionModelEnabled = false;

View File

@ -27,6 +27,7 @@
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/memory_manager/memory_manager.h"
#include "runtime/os_interface/device_factory.h"
#include "runtime/os_interface/os_interface.h"
namespace OCLRT {
ExecutionEnvironment::ExecutionEnvironment() = default;

View File

@ -29,6 +29,7 @@ class CommandStreamReceiver;
class MemoryManager;
class SourceLevelDebugger;
struct HardwareInfo;
class OSInterface;
class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment> {
private:
DeviceFactoryCleaner cleaner;
@ -47,6 +48,7 @@ class ExecutionEnvironment : public ReferenceTrackedObject<ExecutionEnvironment>
GmmHelper *getGmmHelper() const;
std::unique_ptr<OSInterface> osInterface;
std::unique_ptr<MemoryManager> memoryManager;
std::unique_ptr<CommandStreamReceiver> commandStreamReceiver;
std::unique_ptr<SourceLevelDebugger> sourceLevelDebugger;

View File

@ -51,14 +51,16 @@ bool DeviceFactory::getDevices(HardwareInfo **pHWInfos, size_t &numDevices, Exec
if (!drm) {
return false;
}
std::unique_ptr<OSInterface> osInterface = std::unique_ptr<OSInterface>(new OSInterface());
osInterface.get()->get()->setDrm(drm);
executionEnvironment.osInterface.reset(new OSInterface());
executionEnvironment.osInterface->get()->setDrm(drm);
const HardwareInfo *pCurrDevice = platformDevices[devNum];
while (devNum < requiredDeviceCount) {
HardwareInfo tmpHwInfo;
HwInfoConfig *hwConfig = HwInfoConfig::get(pCurrDevice->pPlatform->eProductFamily);
if (hwConfig->configureHwInfo(pCurrDevice, &tmpHwInfo, osInterface.get())) {
if (hwConfig->configureHwInfo(pCurrDevice, &tmpHwInfo, executionEnvironment.osInterface.get())) {
return false;
}
tHwInfos.push_back(tmpHwInfo);

View File

@ -46,8 +46,11 @@ DrmCommandStreamReceiver<GfxFamily>::DrmCommandStreamReceiver(const HardwareInfo
this->drm = drm ? drm : Drm::get(0);
residency.reserve(512);
execObjectsStorage.reserve(512);
CommandStreamReceiver::osInterface = std::unique_ptr<OSInterface>(new OSInterface());
CommandStreamReceiver::osInterface.get()->get()->setDrm(this->drm);
if (!executionEnvironment.osInterface) {
executionEnvironment.osInterface.reset(new OSInterface());
}
executionEnvironment.osInterface->get()->setDrm(this->drm);
CommandStreamReceiver::osInterface = executionEnvironment.osInterface.get();
auto gmmHelper = platform()->peekExecutionEnvironment()->getGmmHelper();
gmmHelper->setSimplifiedMocsTableUsage(this->drm->getSimplifiedMocsTableUsage());
}

View File

@ -45,10 +45,14 @@ bool DeviceFactory::getDevices(HardwareInfo **pHWInfos, size_t &numDevices, Exec
numDevices = 0;
while (numDevices < totalDeviceCount) {
if (!Wddm::enumAdapters(tempHwInfos[numDevices])) {
std::unique_ptr<Wddm> wddm(Wddm ::createWddm(Wddm::pickWddmInterfaceVersion(tempHwInfos[numDevices])));
if (!wddm->enumAdapters(tempHwInfos[numDevices])) {
return false;
}
executionEnvironment.osInterface.reset(new OSInterface());
executionEnvironment.osInterface->get()->setWddm(wddm.release());
HwInfoConfig *hwConfig = HwInfoConfig::get(tempHwInfos[numDevices].pPlatform->eProductFamily);
if (hwConfig->configureHwInfo(&tempHwInfos[numDevices], &tempHwInfos[numDevices], nullptr)) {
return false;

View File

@ -45,9 +45,7 @@ uint32_t OSInterface::getDeviceHandle() const {
return static_cast<uint32_t>(osInterfaceImpl->getDeviceHandle());
}
OSInterface::OSInterfaceImpl::OSInterfaceImpl() {
wddm = nullptr;
}
OSInterface::OSInterfaceImpl::OSInterfaceImpl() = default;
D3DKMT_HANDLE OSInterface::OSInterfaceImpl::getAdapterHandle() const {
return wddm->getAdapter();
@ -73,11 +71,11 @@ bool OSInterface::are64kbPagesEnabled() {
}
Wddm *OSInterface::OSInterfaceImpl::getWddm() const {
return wddm;
return wddm.get();
}
void OSInterface::OSInterfaceImpl::setWddm(Wddm *wddm) {
this->wddm = wddm;
this->wddm.reset(wddm);
}
HANDLE OSInterface::OSInterfaceImpl::createEvent(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset, BOOL bInitialState,

View File

@ -26,6 +26,7 @@
#include "runtime/os_interface/windows/windows_wrapper.h"
#include <d3dkmthk.h>
#include <memory>
#include "profileapi.h"
#include "umKmInc/sharedata.h"
@ -48,6 +49,6 @@ class OSInterface::OSInterfaceImpl {
MOCKABLE_VIRTUAL BOOL closeHandle(HANDLE hObject);
protected:
Wddm *wddm;
std::unique_ptr<Wddm> wddm;
};
} // namespace OCLRT

View File

@ -91,32 +91,29 @@ Wddm::~Wddm() {
}
bool Wddm::enumAdapters(HardwareInfo &outHardwareInfo) {
std::unique_ptr<Wddm> wddm(createWddm(Wddm::pickWddmInterfaceVersion(outHardwareInfo)));
UNRECOVERABLE_IF(!wddm.get());
if (!wddm->gdi->isInitialized()) {
if (!gdi->isInitialized()) {
return false;
}
if (!wddm->openAdapter()) {
if (!openAdapter()) {
return false;
}
if (!wddm->queryAdapterInfo()) {
if (!queryAdapterInfo()) {
return false;
}
auto productFamily = wddm->gfxPlatform->eProductFamily;
auto productFamily = gfxPlatform->eProductFamily;
if (!hardwareInfoTable[productFamily]) {
return false;
}
outHardwareInfo.pPlatform = new PLATFORM(*wddm->gfxPlatform);
outHardwareInfo.pSkuTable = new FeatureTable(*wddm->featureTable);
outHardwareInfo.pWaTable = new WorkaroundTable(*wddm->waTable);
outHardwareInfo.pSysInfo = new GT_SYSTEM_INFO(*wddm->gtSystemInfo);
outHardwareInfo.pPlatform = new PLATFORM(*gfxPlatform);
outHardwareInfo.pSkuTable = new FeatureTable(*featureTable);
outHardwareInfo.pWaTable = new WorkaroundTable(*waTable);
outHardwareInfo.pSysInfo = new GT_SYSTEM_INFO(*gtSystemInfo);
outHardwareInfo.capabilityTable = hardwareInfoTable[productFamily]->capabilityTable;
outHardwareInfo.capabilityTable.maxRenderFrequency = wddm->maxRenderFrequency;
outHardwareInfo.capabilityTable.instrumentationEnabled &= wddm->instrumentationEnabled;
outHardwareInfo.capabilityTable.maxRenderFrequency = maxRenderFrequency;
outHardwareInfo.capabilityTable.instrumentationEnabled &= instrumentationEnabled;
HwInfoConfig *hwConfig = HwInfoConfig::get(productFamily);
hwConfig->adjustPlatformForProductFamily(&outHardwareInfo);

View File

@ -64,7 +64,7 @@ class Wddm {
static Wddm *createWddm(WddmInterfaceVersion interfaceVersion);
static WddmInterfaceVersion pickWddmInterfaceVersion(const HardwareInfo &hwInfo);
static bool enumAdapters(HardwareInfo &outHardwareInfo);
bool enumAdapters(HardwareInfo &outHardwareInfo);
MOCKABLE_VIRTUAL bool evict(D3DKMT_HANDLE *handleList, uint32_t numOfHandles, uint64_t &sizeToTrim);
MOCKABLE_VIRTUAL bool makeResident(D3DKMT_HANDLE *handles, uint32_t count, bool cantTrimFurther, uint64_t *numberOfBytesToTrim);

View File

@ -59,8 +59,9 @@ WddmCommandStreamReceiver<GfxFamily>::WddmCommandStreamReceiver(const HardwareIn
this->wddm->setNode(nodeOrdinal);
PreemptionMode preemptionMode = PreemptionHelper::getDefaultPreemptionMode(hwInfoIn);
this->wddm->setPreemptionMode(preemptionMode);
this->osInterface = std::unique_ptr<OSInterface>(new OSInterface());
this->osInterface.get()->get()->setWddm(this->wddm);
executionEnvironment.osInterface.reset(new OSInterface());
this->osInterface = executionEnvironment.osInterface.get();
this->osInterface->get()->setWddm(this->wddm);
commandBufferHeader = new COMMAND_BUFFER_HEADER;
*commandBufferHeader = CommandBufferHeader;

View File

@ -39,7 +39,6 @@ namespace OCLRT {
WddmMemoryManager::~WddmMemoryManager() {
applyCommonCleanup();
delete this->wddm;
}
WddmMemoryManager::WddmMemoryManager(bool enable64kbPages, Wddm *wddm) : MemoryManager(enable64kbPages), residencyLock(false) {

View File

@ -25,6 +25,7 @@
#include "runtime/gmm_helper/gmm_helper.h"
#include "runtime/helpers/options.h"
#include "runtime/memory_manager/os_agnostic_memory_manager.h"
#include "runtime/os_interface/os_interface.h"
#include "runtime/platform/platform.h"
#include "test.h"
#include "unit_tests/mocks/mock_csr.h"
@ -112,14 +113,21 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWhenInitializeMemoryManagerI
}
auto destructorId = 0u;
static_assert(sizeof(ExecutionEnvironment) == (is64bit ? 56 : 32), "New members detected in ExecutionEnvironment, please ensure that destruction sequence of objects is correct");
static_assert(sizeof(ExecutionEnvironment) == (is64bit ? 64 : 36), "New members detected in ExecutionEnvironment, please ensure that destruction sequence of objects is correct");
TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDestroyedThenDeleteSequenceIsSpecified) {
destructorId = 0u;
struct OsInterfaceMock : public OSInterface {
~OsInterfaceMock() override {
EXPECT_EQ(destructorId, 3u);
destructorId++;
}
};
struct GmmHelperMock : public GmmHelper {
using GmmHelper::GmmHelper;
~GmmHelperMock() override {
EXPECT_EQ(destructorId, 3u);
EXPECT_EQ(destructorId, 4u);
destructorId++;
}
};
@ -154,9 +162,10 @@ TEST(ExecutionEnvironment, givenExecutionEnvironmentWithVariousMembersWhenItIsDe
executionEnvironment->memoryManager.reset(new MemoryMangerMock);
executionEnvironment->commandStreamReceiver.reset(new CommandStreamReceiverMock);
executionEnvironment->sourceLevelDebugger.reset(new SourceLevelDebuggerMock);
executionEnvironment->osInterface.reset(new OsInterfaceMock);
executionEnvironment.reset(nullptr);
EXPECT_EQ(4u, destructorId);
EXPECT_EQ(5u, destructorId);
}
TEST(ExecutionEnvironment, givenMultipleDevicesWhenTheyAreCreatedTheyAllReuseTheSameMemoryManagerAndCommandStreamReceiver) {

View File

@ -43,5 +43,5 @@ CompletionStamp MockCommandStreamReceiver::flushTask(
}
void MockCommandStreamReceiver::setOSInterface(OSInterface *osInterface) {
this->osInterface.reset(osInterface);
this->osInterface = osInterface;
}

View File

@ -180,3 +180,12 @@ TEST_F(DeviceFactoryTest, givenCreateMultipleDevicesDebugFlagWhenGetDevicesIsCal
ASSERT_TRUE(success);
EXPECT_EQ(requiredDeviceCount, numDevices);
}
TEST_F(DeviceFactoryTest, givenGetDevicesCallWhenItIsDoneThenOsInterfaceIsAllocated) {
DeviceFactoryCleaner cleaner;
HardwareInfo *hwInfo = nullptr;
size_t numDevices = 0;
bool success = DeviceFactory::getDevices(&hwInfo, numDevices, executionEnvironment);
EXPECT_TRUE(success);
EXPECT_NE(nullptr, executionEnvironment.osInterface);
}

View File

@ -20,6 +20,8 @@
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "runtime/os_interface/os_interface.h"
#include "runtime/os_interface/linux/os_interface.h"
#include "unit_tests/os_interface/linux/device_factory_tests.h"
TEST_F(DeviceFactoryLinuxTest, GetDevicesCheckEUCntSSCnt) {
@ -90,3 +92,13 @@ TEST_F(DeviceFactoryLinuxTest, ReleaseDevices) {
EXPECT_TRUE(mockDeviceFactory.getNumDevices() == 0);
EXPECT_TRUE(pDrm->getFileDescriptor() == -1);
}
TEST_F(DeviceFactoryLinuxTest, givenGetDeviceCallWhenItIsDoneThenOsInterfaceIsAllocatedAndItContainDrm) {
MockDeviceFactory mockDeviceFactory;
HardwareInfo *hwInfo = nullptr;
size_t numDevices = 0;
bool success = mockDeviceFactory.getDevices(&hwInfo, numDevices, executionEnvironment);
EXPECT_TRUE(success);
EXPECT_NE(nullptr, executionEnvironment.osInterface);
EXPECT_EQ(pDrm, executionEnvironment.osInterface->get()->getDrm());
}

View File

@ -117,7 +117,7 @@ struct MockWddmCsr : public WddmCommandStreamReceiver<GfxFamily> {
class WddmCommandStreamWithMockGdiFixture {
public:
DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *csr = nullptr;
MockWddmCsr<DEFAULT_TEST_FAMILY_NAME> *csr = nullptr;
MemoryManager *memManager = nullptr;
MockDevice *device = nullptr;
WddmMock *wddm = nullptr;
@ -133,9 +133,8 @@ class WddmCommandStreamWithMockGdiFixture {
wddm->gdi.reset(gdi);
ASSERT_NE(wddm, nullptr);
DebugManager.flags.CsrDispatchMode.set(static_cast<uint32_t>(DispatchMode::ImmediateDispatch));
csr = new WddmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>(*platformDevices[0], wddm, *executionEnvironment);
ASSERT_NE(nullptr, csr);
executionEnvironment->commandStreamReceiver = std::make_unique<MockWddmCsr<DEFAULT_TEST_FAMILY_NAME>>(*platformDevices[0], wddm, *executionEnvironment);
this->csr = static_cast<MockWddmCsr<DEFAULT_TEST_FAMILY_NAME> *>(executionEnvironment->commandStreamReceiver.get());
memManager = csr->createMemoryManager(false);
ASSERT_NE(nullptr, memManager);
executionEnvironment->memoryManager.reset(memManager);
@ -150,7 +149,6 @@ class WddmCommandStreamWithMockGdiFixture {
if (preemptionAllocation) {
memManager->freeGraphicsMemory(preemptionAllocation);
}
delete csr;
wddm = nullptr;
delete device;
}
@ -162,16 +160,16 @@ using WddmDefaultTest = ::Test<WddmCommandStreamFixture>;
using DeviceCommandStreamTest = ::Test<GmmEnvironmentFixture>;
TEST_F(DeviceCommandStreamTest, CreateWddmCSR) {
std::unique_ptr<DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>> csr(static_cast<DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *>(DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>::create(DEFAULT_TEST_PLATFORM::hwInfo, false, this->executionEnvironment)));
std::unique_ptr<WddmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>> csr(static_cast<WddmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *>(WddmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>::create(DEFAULT_TEST_PLATFORM::hwInfo, false, this->executionEnvironment)));
EXPECT_NE(nullptr, csr);
std::unique_ptr<Wddm> wddm(static_cast<WddmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *>(csr.get())->peekWddm());
auto wddm = csr->peekWddm();
EXPECT_NE(nullptr, wddm);
}
TEST_F(DeviceCommandStreamTest, CreateWddmCSRWithAubDump) {
std::unique_ptr<DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>> csr(static_cast<DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *>(DeviceCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>::create(DEFAULT_TEST_PLATFORM::hwInfo, true, this->executionEnvironment)));
std::unique_ptr<WddmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>> csr(static_cast<WddmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *>(WddmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>::create(DEFAULT_TEST_PLATFORM::hwInfo, true, this->executionEnvironment)));
EXPECT_NE(nullptr, csr);
std::unique_ptr<Wddm> wddm(static_cast<WddmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME> *>(csr.get())->peekWddm());
auto wddm = csr->peekWddm();
EXPECT_NE(nullptr, wddm);
auto aubCSR = static_cast<CommandStreamReceiverWithAUBDump<WddmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>> *>(csr.get())->aubCSR;
EXPECT_NE(nullptr, aubCSR);
@ -287,22 +285,22 @@ TEST(WddmPreemptionHeaderTests, givenWddmCommandStreamReceiverWhenPreemptionIsOn
}
TEST(WddmPreemptionHeaderTests, givenDeviceSupportingPreemptionWhenCommandStreamReceiverIsCreatedThenHeaderContainsPreemptionFieldSet) {
std::unique_ptr<WddmMock> wddm(static_cast<WddmMock *>(Wddm::createWddm(WddmInterfaceVersion::Wddm20)));
auto wddm = static_cast<WddmMock *>(Wddm::createWddm(WddmInterfaceVersion::Wddm20));
auto localHwInfo = *platformDevices[0];
localHwInfo.capabilityTable.defaultPreemptionMode = PreemptionMode::MidThread;
ExecutionEnvironment executionEnvironment;
auto commandStreamReceiver = std::make_unique<MockWddmCsr<DEFAULT_TEST_FAMILY_NAME>>(localHwInfo, wddm.get(), executionEnvironment);
auto commandStreamReceiver = std::make_unique<MockWddmCsr<DEFAULT_TEST_FAMILY_NAME>>(localHwInfo, wddm, executionEnvironment);
auto commandHeader = commandStreamReceiver->commandBufferHeader;
auto header = reinterpret_cast<COMMAND_BUFFER_HEADER *>(commandHeader);
EXPECT_TRUE(header->NeedsMidBatchPreEmptionSupport);
}
TEST(WddmPreemptionHeaderTests, givenDevicenotSupportingPreemptionWhenCommandStreamReceiverIsCreatedThenHeaderPreemptionFieldIsNotSet) {
std::unique_ptr<WddmMock> wddm(static_cast<WddmMock *>(Wddm::createWddm(WddmInterfaceVersion::Wddm20)));
auto wddm = static_cast<WddmMock *>(Wddm::createWddm(WddmInterfaceVersion::Wddm20));
auto localHwInfo = *platformDevices[0];
localHwInfo.capabilityTable.defaultPreemptionMode = PreemptionMode::Disabled;
ExecutionEnvironment executionEnvironment;
auto commandStreamReceiver = std::make_unique<MockWddmCsr<DEFAULT_TEST_FAMILY_NAME>>(localHwInfo, wddm.get(), executionEnvironment);
auto commandStreamReceiver = std::make_unique<MockWddmCsr<DEFAULT_TEST_FAMILY_NAME>>(localHwInfo, wddm, executionEnvironment);
auto commandHeader = commandStreamReceiver->commandBufferHeader;
auto header = reinterpret_cast<COMMAND_BUFFER_HEADER *>(commandHeader);
EXPECT_FALSE(header->NeedsMidBatchPreEmptionSupport);
@ -700,21 +698,19 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt
tmpAllocation = GlobalMockSipProgram::sipProgram->getAllocation();
GlobalMockSipProgram::sipProgram->resetAllocation(memManager->allocateGraphicsMemory(1024));
}
auto mockCsr = new MockWddmCsr<FamilyType>(*platformDevices[0], this->wddm, *device->executionEnvironment);
mockCsr->setMemoryManager(memManager);
mockCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch);
csr->overrideDispatchPolicy(DispatchMode::BatchedDispatch);
auto mockedSubmissionsAggregator = new mockSubmissionsAggregator();
mockCsr->overrideSubmissionAggregator(mockedSubmissionsAggregator);
csr->overrideSubmissionAggregator(mockedSubmissionsAggregator);
auto commandBuffer = memManager->allocateGraphicsMemory(1024);
auto dshAlloc = memManager->allocateGraphicsMemory(1024);
auto iohAlloc = memManager->allocateGraphicsMemory(1024);
auto sshAlloc = memManager->allocateGraphicsMemory(1024);
this->device->resetCommandStreamReceiver(mockCsr);
auto tagAllocation = mockCsr->getTagAllocation();
mockCsr->setPreemptionCsrAllocation(preemptionAllocation);
auto tagAllocation = csr->getTagAllocation();
csr->setPreemptionCsrAllocation(preemptionAllocation);
LinearStream cs(commandBuffer);
IndirectHeap dsh(dshAlloc);
@ -725,7 +721,7 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt
dispatchFlags.guardCommandBufferWithPipeControl = true;
dispatchFlags.requiresCoherency = true;
dispatchFlags.preemptionMode = PreemptionHelper::getDefaultPreemptionMode(device->getHardwareInfo());
mockCsr->flushTask(cs, 0u, dsh, ioh, ssh, 0u, dispatchFlags, *device);
csr->flushTask(cs, 0u, dsh, ioh, ssh, 0u, dispatchFlags, *device);
auto &cmdBuffers = mockedSubmissionsAggregator->peekCommandBuffers();
auto storedCommandBuffer = cmdBuffers.peekHead();
@ -733,12 +729,12 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt
ResidencyContainer copyOfResidency = storedCommandBuffer->surfaces;
copyOfResidency.push_back(storedCommandBuffer->batchBuffer.commandBufferAllocation);
mockCsr->flushBatchedSubmissions();
csr->flushBatchedSubmissions();
EXPECT_TRUE(cmdBuffers.peekIsEmpty());
EXPECT_EQ(1u, wddm->submitResult.called);
auto csrCommandStream = mockCsr->commandStream.getGraphicsAllocation();
auto csrCommandStream = csr->commandStream.getGraphicsAllocation();
EXPECT_EQ(reinterpret_cast<uint64_t>(csrCommandStream->getUnderlyingBuffer()), wddm->submitResult.commandBufferSubmitted);
EXPECT_TRUE(((COMMAND_BUFFER_HEADER *)wddm->submitResult.commandHeaderSubmitted)->RequiresCoherency);
EXPECT_EQ(6u + csrSurfaceCount, wddm->makeResidentResult.handleCount);
@ -779,9 +775,13 @@ HWTEST_F(WddmCommandStreamMockGdiTest, givenRecordedCommandBufferWhenItIsSubmitt
}
}
HWTEST_F(WddmDefaultTest, givenDefaultWddmCsrWhenItIsCreatedThenBatchingIsTurnedOn) {
using WddmSimpleTest = ::testing::Test;
HWTEST_F(WddmSimpleTest, givenDefaultWddmCsrWhenItIsCreatedThenBatchingIsTurnedOn) {
DebugManager.flags.CsrDispatchMode.set(0);
std::unique_ptr<MockWddmCsr<FamilyType>> mockCsr(new MockWddmCsr<FamilyType>(*platformDevices[0], this->wddm, *device->executionEnvironment));
ExecutionEnvironment executionEnvironment;
auto wddm = Wddm::createWddm(WddmInterfaceVersion::Wddm20);
std::unique_ptr<MockWddmCsr<FamilyType>> mockCsr(new MockWddmCsr<FamilyType>(*platformDevices[0], wddm, executionEnvironment));
EXPECT_EQ(DispatchMode::BatchedDispatch, mockCsr->dispatchMode);
}
@ -796,7 +796,6 @@ HWTEST_F(WddmDefaultTest, givenFtrWddmHwQueuesFlagWhenCreatingCsrThenPickWddmVer
WddmCommandStreamReceiver<FamilyType> wddmCsr20(myHwInfo, nullptr, *device->executionEnvironment);
auto wddm20 = wddmCsr20.peekWddm();
EXPECT_EQ(typeid(*wddm20), typeid(WddmMock20));
delete wddm20;
}
myFtrTable.ftrWddmHwQueues = true;
@ -805,11 +804,10 @@ HWTEST_F(WddmDefaultTest, givenFtrWddmHwQueuesFlagWhenCreatingCsrThenPickWddmVer
WddmCommandStreamReceiver<FamilyType> wddmCsr23(myHwInfo, nullptr, *device->executionEnvironment);
auto wddm23 = wddmCsr23.peekWddm();
EXPECT_EQ(typeid(*wddm23), typeid(WddmMock23));
delete wddm23;
}
}
struct WddmCsrCompressionTests : WddmCommandStreamMockGdiTest {
struct WddmCsrCompressionTests : ::testing::Test {
void setCompressionEnabled(bool enableForBuffer, bool enableForImages) {
RuntimeCapabilityTable capabilityTable = platformDevices[0]->capabilityTable;
capabilityTable.ftrRenderCompressedBuffers = enableForBuffer;
@ -819,25 +817,25 @@ struct WddmCsrCompressionTests : WddmCommandStreamMockGdiTest {
}
void SetUp() override {
WddmCommandStreamMockGdiTest::SetUp();
setCompressionEnabled(true, true);
}
void createMockWddm() {
myMockWddm.reset(static_cast<WddmMock *>(Wddm::createWddm(WddmInterfaceVersion::Wddm20)));
myMockWddm = static_cast<WddmMock *>(Wddm::createWddm(WddmInterfaceVersion::Wddm20));
}
HardwareInfo hwInfo = {};
std::unique_ptr<WddmMock> myMockWddm;
WddmMock *myMockWddm;
};
HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenInitializedThenCreatePagetableMngr) {
bool compressionEnabled[2][2] = {{true, false}, {false, true}};
for (size_t i = 0; i < 2; i++) {
ExecutionEnvironment executionEnvironment;
setCompressionEnabled(compressionEnabled[i][0], compressionEnabled[i][1]);
createMockWddm();
EXPECT_EQ(nullptr, myMockWddm->getPageTableManager());
MockWddmCsr<FamilyType> mockWddmCsr(hwInfo, myMockWddm.get(), *device->executionEnvironment);
MockWddmCsr<FamilyType> mockWddmCsr(hwInfo, myMockWddm, executionEnvironment);
ASSERT_NE(nullptr, myMockWddm->getPageTableManager());
auto mockMngr = reinterpret_cast<MockGmmPageTableMngr *>(myMockWddm->getPageTableManager());
@ -877,26 +875,30 @@ HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenInitializedThenCrea
}
HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenInitializedThenDontCreatePagetableMngr) {
ExecutionEnvironment executionEnvironment;
setCompressionEnabled(false, false);
createMockWddm();
MockWddmCsr<FamilyType> mockWddmCsr(hwInfo, myMockWddm.get(), *device->executionEnvironment);
MockWddmCsr<FamilyType> mockWddmCsr(hwInfo, myMockWddm, executionEnvironment);
EXPECT_EQ(nullptr, myMockWddm->getPageTableManager());
}
HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenFlushingThenInitTranslationTableOnce) {
bool compressionEnabled[2][2] = {{true, false}, {false, true}};
for (size_t i = 0; i < 2; i++) {
ExecutionEnvironment *executionEnvironment = new ExecutionEnvironment;
setCompressionEnabled(compressionEnabled[i][0], compressionEnabled[i][1]);
createMockWddm();
auto mockWddmCsr = new MockWddmCsr<FamilyType>(hwInfo, myMockWddm.get(), *device->executionEnvironment);
auto mockWddmCsr = new MockWddmCsr<FamilyType>(hwInfo, myMockWddm, *executionEnvironment);
mockWddmCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch);
executionEnvironment->commandStreamReceiver.reset(mockWddmCsr);
auto mockMngr = reinterpret_cast<MockGmmPageTableMngr *>(myMockWddm->getPageTableManager());
mockWddmCsr->setMemoryManager(memManager);
std::unique_ptr<MockDevice> device(Device::create<MockDevice>(platformDevices[0], executionEnvironment));
this->device->resetCommandStreamReceiver(mockWddmCsr);
auto memManager = executionEnvironment->memoryManager.get();
mockWddmCsr->setPreemptionCsrAllocation(preemptionAllocation);
auto &csrCS = mockWddmCsr->getCS();
auto graphicsAllocation = memManager->allocateGraphicsMemory(1024);
@ -925,18 +927,19 @@ HWTEST_F(WddmCsrCompressionTests, givenEnabledCompressionWhenFlushingThenInitTra
}
HWTEST_F(WddmCsrCompressionTests, givenDisabledCompressionWhenFlushingThenDontInitTranslationTable) {
ExecutionEnvironment *executionEnvironment = new ExecutionEnvironment;
setCompressionEnabled(false, false);
createMockWddm();
auto mockWddmCsr = new MockWddmCsr<FamilyType>(hwInfo, myMockWddm.get(), *device->executionEnvironment);
auto mockWddmCsr = new MockWddmCsr<FamilyType>(hwInfo, myMockWddm, *executionEnvironment);
executionEnvironment->commandStreamReceiver.reset(mockWddmCsr);
mockWddmCsr->overrideDispatchPolicy(DispatchMode::BatchedDispatch);
std::unique_ptr<MockDevice> device(Device::create<MockDevice>(platformDevices[0], executionEnvironment));
auto memManager = executionEnvironment->memoryManager.get();
EXPECT_EQ(nullptr, myMockWddm->getPageTableManager());
mockWddmCsr->setMemoryManager(memManager);
mockWddmCsr->setPreemptionCsrAllocation(preemptionAllocation);
this->device->resetCommandStreamReceiver(mockWddmCsr);
auto graphicsAllocation = memManager->allocateGraphicsMemory(1024);
IndirectHeap cs(graphicsAllocation);

View File

@ -39,9 +39,7 @@ CommandStreamReceiver *createMockCommandStreamReceiver(const HardwareInfo &hwInf
class DriverInfoDeviceTest : public ::testing::Test {
public:
static Wddm *wddmMock;
void SetUp() {
wddmMock = nullptr;
hwInfo = platformDevices[0];
commandStreamReceiverCreateFunc = commandStreamReceiverFactory[hwInfo->pPlatform->eRenderCoreFamily];
commandStreamReceiverFactory[hwInfo->pPlatform->eRenderCoreFamily] = createMockCommandStreamReceiver;
@ -49,7 +47,6 @@ class DriverInfoDeviceTest : public ::testing::Test {
void TearDown() {
commandStreamReceiverFactory[hwInfo->pPlatform->eRenderCoreFamily] = commandStreamReceiverCreateFunc;
delete wddmMock;
}
CommandStreamReceiverCreateFunc commandStreamReceiverCreateFunc;
@ -59,14 +56,12 @@ class DriverInfoDeviceTest : public ::testing::Test {
CommandStreamReceiver *createMockCommandStreamReceiver(const HardwareInfo &hwInfoIn, bool withAubDump, ExecutionEnvironment &executionEnvironment) {
auto csr = new MockCommandStreamReceiver();
OSInterface *osInterface = new OSInterface();
DriverInfoDeviceTest::wddmMock = new WddmMock();
osInterface->get()->setWddm(DriverInfoDeviceTest::wddmMock);
executionEnvironment.osInterface.reset(osInterface);
osInterface->get()->setWddm(new WddmMock());
csr->setOSInterface(osInterface);
return csr;
}
Wddm *DriverInfoDeviceTest::wddmMock = nullptr;
TEST_F(DriverInfoDeviceTest, GivenDeviceCreatedWhenCorrectOSInterfaceThenCreateDriverInfo) {
overrideCommandStreamReceiverCreation = true;
auto device = MockDevice::createWithNewExecutionEnvironment<MockDevice>(hwInfo);

View File

@ -43,8 +43,9 @@ void HwInfoConfigTestWindows::SetUp() {
HwInfoConfigTest::SetUp();
osInterface.reset(new OSInterface());
Wddm::enumAdapters(outHwInfo);
std::unique_ptr<Wddm> wddm(Wddm::createWddm(Wddm::pickWddmInterfaceVersion(outHwInfo)));
wddm->enumAdapters(outHwInfo);
testHwInfo = outHwInfo;
}

View File

@ -63,6 +63,5 @@ void PerformanceCountersFixture::fillOsInterface() {
osInterfaceBase->get()->setWddm(new WddmMock());
}
void PerformanceCountersFixture::releaseOsInterface() {
delete osInterfaceBase->get()->getWddm();
}
} // namespace OCLRT

View File

@ -102,7 +102,9 @@ TEST(Wddm20EnumAdaptersTest, expectTrue) {
const HardwareInfo hwInfo = *platformDevices[0];
OsLibrary *mockGdiDll = setAdapterInfo(hwInfo.pPlatform, hwInfo.pSysInfo);
bool success = Wddm::enumAdapters(outHwInfo);
std::unique_ptr<Wddm> wddm(Wddm::createWddm(Wddm::pickWddmInterfaceVersion(outHwInfo)));
bool success = wddm->enumAdapters(outHwInfo);
EXPECT_TRUE(success);
const HardwareInfo *hwinfo = *platformDevices;
@ -123,7 +125,8 @@ TEST(Wddm20EnumAdaptersTest, givenEmptyHardwareInfoWhenEnumAdapterIsCalledThenCa
auto hwInfo = *platformDevices[0];
std::unique_ptr<OsLibrary> mockGdiDll(setAdapterInfo(hwInfo.pPlatform, hwInfo.pSysInfo));
bool success = Wddm::enumAdapters(outHwInfo);
std::unique_ptr<Wddm> wddm(Wddm::createWddm(Wddm::pickWddmInterfaceVersion(outHwInfo)));
bool success = wddm->enumAdapters(outHwInfo);
EXPECT_TRUE(success);
const HardwareInfo *hwinfo = *platformDevices;
@ -164,7 +167,8 @@ TEST(Wddm20EnumAdaptersTest, givenUnknownPlatformWhenEnumAdapterIsCalledThenFals
fSetAdpaterInfo(&platform, hwInfo.pSysInfo);
delete ptr;
});
bool ret = Wddm::enumAdapters(outHwInfo);
std::unique_ptr<Wddm> wddm(Wddm::createWddm(Wddm::pickWddmInterfaceVersion(outHwInfo)));
auto ret = wddm->enumAdapters(outHwInfo);
EXPECT_FALSE(ret);
EXPECT_EQ(nullptr, outHwInfo.pPlatform);
EXPECT_EQ(nullptr, outHwInfo.pSkuTable);
@ -453,7 +457,7 @@ TEST_F(Wddm20Tests, GetCpuGpuTime) {
TimeStampData CPUGPUTime01 = {0};
TimeStampData CPUGPUTime02 = {0};
std::unique_ptr<OSInterface> osInterface(new OSInterface());
osInterface->get()->setWddm(wddm.get());
osInterface->get()->setWddm(wddm.release());
std::unique_ptr<OSTime> osTime(OSTime::create(osInterface.get()).release());
auto success = osTime->getCpuGpuTime(&CPUGPUTime01);
EXPECT_TRUE(success);
@ -474,7 +478,7 @@ HWTEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocatio
EXPECT_EQ(0u, status);
wddm->init<FamilyType>();
WddmMemoryManager mm(false, wddm.release());
WddmMemoryManager mm(false, wddm.get());
auto graphicsAllocation = mm.createGraphicsAllocationFromSharedHandle(ALLOCATION_HANDLE, false, false);
auto wddmAllocation = (WddmAllocation *)graphicsAllocation;
@ -511,7 +515,7 @@ HWTEST_F(Wddm20WithMockGdiDllTests, givenSharedHandleWhenCreateGraphicsAllocatio
auto status = setSizesFcn(gmm->gmmResourceInfo.get(), 1u, 1024u, 1u);
EXPECT_EQ(0u, status);
auto mockWddm = wddm.release();
auto mockWddm = wddm.get();
mockWddm->init<FamilyType>();
WddmMemoryManager mm(false, mockWddm);

View File

@ -27,7 +27,7 @@ using namespace OCLRT;
using namespace ::testing;
TEST_F(WddmMemoryManagerSimpleTest, givenUseSystemMemorySetToTrueWhenAllocateInDevicePoolIsCalledThenNullptrIsReturned) {
memoryManager.reset(new MockWddmMemoryManager(false, wddm));
memoryManager.reset(new MockWddmMemoryManager(false, wddm.get()));
MemoryManager::AllocationStatus status = MemoryManager::AllocationStatus::Success;
AllocationData allocData;
allocData.allFlags = 0;

View File

@ -38,7 +38,7 @@ using namespace ::testing;
void WddmMemoryManagerFixture::SetUp() {
GmmEnvironmentFixture::SetUp();
GdiDllFixture::SetUp();
wddm = static_cast<WddmMock *>(Wddm::createWddm(WddmInterfaceVersion::Wddm20));
wddm.reset(static_cast<WddmMock *>(Wddm::createWddm(WddmInterfaceVersion::Wddm20)));
ASSERT_NE(nullptr, wddm);
if (platformDevices[0]->capabilityTable.ftrRenderCompressedBuffers || platformDevices[0]->capabilityTable.ftrRenderCompressedImages) {
GMM_DEVICE_CALLBACKS_INT dummyDeviceCallbacks = {};
@ -58,12 +58,12 @@ TEST(WddmMemoryManager, NonAssignable) {
}
TEST(WddmMemoryManagerAllocator32BitTest, allocator32BitIsCreatedWithCorrectBase) {
WddmMock *wddm = static_cast<WddmMock *>(Wddm::createWddm(WddmInterfaceVersion::Wddm20));
std::unique_ptr<WddmMock> wddm(static_cast<WddmMock *>(Wddm::createWddm(WddmInterfaceVersion::Wddm20)));
uint64_t base = 0x56000;
uint64_t size = 0x9000;
wddm->setHeap32(base, size);
std::unique_ptr<WddmMemoryManager> memoryManager = std::unique_ptr<WddmMemoryManager>(new WddmMemoryManager(false, wddm));
std::unique_ptr<WddmMemoryManager> memoryManager = std::unique_ptr<WddmMemoryManager>(new WddmMemoryManager(false, wddm.get()));
ASSERT_NE(nullptr, memoryManager->allocator32Bit.get());
@ -71,10 +71,10 @@ TEST(WddmMemoryManagerAllocator32BitTest, allocator32BitIsCreatedWithCorrectBase
}
TEST(WddmMemoryManagerWithDeferredDeleterTest, givenWMMWhenAsyncDeleterIsEnabledAndWaitForDeletionsIsCalledThenDeleterInWddmIsSetToNullptr) {
WddmMock *wddm = new WddmMock();
auto wddm = std::make_unique<WddmMock>();
bool actualDeleterFlag = DebugManager.flags.EnableDeferredDeleter.get();
DebugManager.flags.EnableDeferredDeleter.set(true);
MockWddmMemoryManager memoryManager(wddm);
MockWddmMemoryManager memoryManager(wddm.get());
EXPECT_NE(nullptr, memoryManager.getDeferredDeleter());
memoryManager.waitForDeletions();
EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter());
@ -82,7 +82,7 @@ TEST(WddmMemoryManagerWithDeferredDeleterTest, givenWMMWhenAsyncDeleterIsEnabled
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemoryIsCalledThenMemoryPoolIsSystem4KBPages) {
memoryManager.reset(new MockWddmMemoryManager(false, wddm));
memoryManager.reset(new MockWddmMemoryManager(false, wddm.get()));
auto size = 4096u;
auto allocation = memoryManager->allocateGraphicsMemory(size);
@ -99,7 +99,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemory
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemory64kbIsCalledThenMemoryPoolIsSystem64KBPages) {
memoryManager.reset(new MockWddmMemoryManager(false, wddm));
memoryManager.reset(new MockWddmMemoryManager(false, wddm.get()));
auto size = 4096u;
auto allocation = memoryManager->allocateGraphicsMemory64kb(size, MemoryConstants::preferredAlignment, false, false);
EXPECT_NE(nullptr, allocation);
@ -109,7 +109,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAl
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPages) {
memoryManager.reset(new MockWddmMemoryManager(false, wddm));
memoryManager.reset(new MockWddmMemoryManager(false, wddm.get()));
void *ptr = reinterpret_cast<void *>(0x1001);
auto size = 4096u;
auto allocation = memoryManager->allocateGraphicsMemory(size, ptr, false);
@ -122,7 +122,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocateGraphicsMemory
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocate32BitGraphicsMemoryWithPtrIsCalledThenMemoryPoolIsSystem4KBPagesWith32BitGpuAddressing) {
memoryManager.reset(new MockWddmMemoryManager(false, wddm));
memoryManager.reset(new MockWddmMemoryManager(false, wddm.get()));
void *ptr = reinterpret_cast<void *>(0x1001);
auto size = MemoryConstants::pageSize;
@ -136,7 +136,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenAllocate32BitGraphicsM
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesDisabledWhenAllocateGraphicsMemoryForSVMIsCalledThen4KBGraphicsAllocationIsReturned) {
memoryManager.reset(new MockWddmMemoryManager(false, wddm));
memoryManager.reset(new MockWddmMemoryManager(false, wddm.get()));
auto size = MemoryConstants::pageSize;
auto svmAllocation = memoryManager->allocateGraphicsMemoryForSVM(size, false);
@ -147,7 +147,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesDisabledWhenA
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAllocateGraphicsMemoryForSVMIsCalledThenMemoryPoolIsSystem64KBPages) {
memoryManager.reset(new MockWddmMemoryManager(true, wddm));
memoryManager.reset(new MockWddmMemoryManager(true, wddm.get()));
auto size = MemoryConstants::pageSize;
auto svmAllocation = memoryManager->allocateGraphicsMemoryForSVM(size, false);
@ -157,7 +157,7 @@ TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWith64KBPagesEnabledWhenAl
}
TEST_F(WddmMemoryManagerSimpleTest, givenMemoryManagerWhenCreateAllocationFromHandleIsCalledThenMemoryPoolIsSystemCpuInaccessible) {
memoryManager.reset(new MockWddmMemoryManager(false, wddm));
memoryManager.reset(new MockWddmMemoryManager(false, wddm.get()));
auto osHandle = 1u;
gdi->getQueryResourceInfoArgOut().NumAllocations = 1;
std::unique_ptr<Gmm> gmm(new Gmm(nullptr, 0, false));
@ -188,7 +188,7 @@ HWTEST_F(WddmMemoryManagerTest, givenDefaultWddmMemoryManagerWhenAskedForVirtual
}
TEST_F(WddmMemoryManagerTest, GivenGraphicsAllocationWhenAddAndRemoveAllocationToHostPtrManagerThenfragmentHasCorrectValues) {
memoryManager.reset(new (std::nothrow) MockWddmMemoryManager(wddm));
memoryManager.reset(new (std::nothrow) MockWddmMemoryManager(wddm.get()));
void *cpuPtr = (void *)0x30000;
size_t size = 0x1000;
@ -1904,10 +1904,10 @@ HWTEST_F(WddmMemoryManagerTest2, givenMemoryManagerWhenMakeResidentFailsThenMemo
}
TEST(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsEnabledThenCanDeferDeletions) {
WddmMock *wddm = new WddmMock;
auto wddm = std::make_unique<WddmMock>();
wddm->callBaseDestroyAllocations = false;
MockDeferredDeleter *deleter = new MockDeferredDeleter;
MockWddmMemoryManager memoryManager(wddm);
MockWddmMemoryManager memoryManager(wddm.get());
memoryManager.setDeferredDeleter(deleter);
EXPECT_EQ(0, deleter->deferDeletionCalled);
memoryManager.tryDeferDeletions(nullptr, 0, 0, 0);
@ -1916,19 +1916,19 @@ TEST(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsEnabledTh
}
TEST(WddmMemoryManagerWithAsyncDeleterTest, givenWddmWhenAsyncDeleterIsDisabledThenCannotDeferDeletions) {
WddmMock *wddm = new WddmMock;
auto wddm = std::make_unique<WddmMock>();
wddm->callBaseDestroyAllocations = false;
MockWddmMemoryManager memoryManager(wddm);
MockWddmMemoryManager memoryManager(wddm.get());
memoryManager.setDeferredDeleter(nullptr);
memoryManager.tryDeferDeletions(nullptr, 0, 0, 0);
EXPECT_EQ(1u, wddm->destroyAllocationResult.called);
}
TEST(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleterWhenCannotAllocateMemoryForTiledImageThenDrainIsCalledAndCreateAllocationIsCalledTwice) {
WddmMock *wddm = new WddmMock;
auto wddm = std::make_unique<WddmMock>();
wddm->callBaseDestroyAllocations = false;
MockDeferredDeleter *deleter = new MockDeferredDeleter;
MockWddmMemoryManager memoryManager(wddm);
MockWddmMemoryManager memoryManager(wddm.get());
memoryManager.setDeferredDeleter(deleter);
cl_image_desc imgDesc;
@ -1945,10 +1945,10 @@ TEST(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleterWh
}
TEST(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleterWhenCanAllocateMemoryForTiledImageThenDrainIsNotCalledAndCreateAllocationIsCalledOnce) {
WddmMock *wddm = new WddmMock;
auto wddm = std::make_unique<WddmMock>();
wddm->callBaseDestroyAllocations = false;
MockDeferredDeleter *deleter = new MockDeferredDeleter;
MockWddmMemoryManager memoryManager(wddm);
MockWddmMemoryManager memoryManager(wddm.get());
memoryManager.setDeferredDeleter(deleter);
cl_image_desc imgDesc;
@ -1969,9 +1969,9 @@ TEST(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithAsyncDeleterWh
}
TEST(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithoutAsyncDeleterWhenCannotAllocateMemoryForTiledImageThenCreateAllocationIsCalledOnce) {
WddmMock *wddm = new WddmMock;
auto wddm = std::make_unique<WddmMock>();
wddm->callBaseDestroyAllocations = false;
MockWddmMemoryManager memoryManager(wddm);
MockWddmMemoryManager memoryManager(wddm.get());
memoryManager.setDeferredDeleter(nullptr);
cl_image_desc imgDesc;
@ -1985,17 +1985,17 @@ TEST(WddmMemoryManagerWithAsyncDeleterTest, givenMemoryManagerWithoutAsyncDelete
}
TEST(WddmMemoryManagerDefaults, givenDefaultWddmMemoryManagerWhenItIsQueriedForInternalHeapBaseThenHeap1BaseIsReturned) {
WddmMock *wddm = new WddmMock;
auto wddm = std::make_unique<WddmMock>();
wddm->callBaseDestroyAllocations = false;
MockWddmMemoryManager memoryManager(wddm);
MockWddmMemoryManager memoryManager(wddm.get());
auto heapBase = wddm->getGfxPartition().Heap32[1].Base;
EXPECT_EQ(heapBase, memoryManager.getInternalHeapBaseAddress());
}
HWTEST_F(MockWddmMemoryManagerTest, givenValidateAllocationFunctionWhenItIsCalledWithTripleAllocationThenSuccessIsReturned) {
WddmMock *wddm = new WddmMock;
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init<FamilyType>());
MockWddmMemoryManager memoryManager(wddm);
MockWddmMemoryManager memoryManager(wddm.get());
auto wddmAlloc = (WddmAllocation *)memoryManager.allocateGraphicsMemory(4096u, reinterpret_cast<void *>(0x1000));
@ -2006,10 +2006,10 @@ HWTEST_F(MockWddmMemoryManagerTest, givenValidateAllocationFunctionWhenItIsCalle
HWTEST_F(MockWddmMemoryManagerTest, givenEnabled64kbpagesWhenCreatingGraphicsMemoryForBufferWithoutHostPtrThen64kbAdressIsAllocated) {
DebugManagerStateRestore dbgRestore;
WddmMock *wddm = new WddmMock;
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init<FamilyType>());
DebugManager.flags.Enable64kbpages.set(true);
WddmMemoryManager memoryManager64k(true, wddm);
WddmMemoryManager memoryManager64k(true, wddm.get());
EXPECT_EQ(0, wddm->createAllocationResult.called);
GraphicsAllocation *galloc = memoryManager64k.allocateGraphicsMemoryInPreferredPool(true, nullptr, static_cast<size_t>(MemoryConstants::pageSize64k), GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY);
@ -2024,10 +2024,10 @@ HWTEST_F(MockWddmMemoryManagerTest, givenEnabled64kbpagesWhenCreatingGraphicsMem
HWTEST_F(OsAgnosticMemoryManagerUsingWddmTest, givenEnabled64kbPagesWhenAllocationIsCreatedWithSizeSmallerThan64kbThenGraphicsAllocationsHas64kbAlignedUnderlyingSize) {
DebugManagerStateRestore dbgRestore;
WddmMock *wddm = new WddmMock;
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init<FamilyType>());
DebugManager.flags.Enable64kbpages.set(true);
WddmMemoryManager memoryManager(true, wddm);
WddmMemoryManager memoryManager(true, wddm.get());
auto graphicsAllocation = memoryManager.allocateGraphicsMemory64kb(1, MemoryConstants::pageSize64k, false, false);
EXPECT_NE(nullptr, graphicsAllocation);
@ -2044,9 +2044,9 @@ HWTEST_F(OsAgnosticMemoryManagerUsingWddmTest, givenEnabled64kbPagesWhenAllocati
HWTEST_F(MockWddmMemoryManagerTest, givenWddmWhenallocateGraphicsMemory64kbThenLockResultAndmapGpuVirtualAddressIsCalled) {
DebugManagerStateRestore dbgRestore;
DebugManager.flags.Enable64kbpages.set(true);
WddmMock *wddm = new WddmMock;
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init<FamilyType>());
MockWddmMemoryManager memoryManager64k(wddm);
MockWddmMemoryManager memoryManager64k(wddm.get());
uint32_t lockCount = wddm->lockResult.called;
uint32_t mapGpuVirtualAddressResult = wddm->mapGpuVirtualAddressResult.called;
GraphicsAllocation *galloc = memoryManager64k.allocateGraphicsMemory64kb(65536, 65536, true, false);
@ -2057,23 +2057,23 @@ HWTEST_F(MockWddmMemoryManagerTest, givenWddmWhenallocateGraphicsMemory64kbThenL
}
TEST_F(MockWddmMemoryManagerTest, givenDefaultMemoryManagerWhenItIsCreatedThenAsyncDeleterEnabledIsTrue) {
WddmMock *wddm = new WddmMock;
WddmMemoryManager memoryManager(false, wddm);
auto wddm = std::make_unique<WddmMock>();
WddmMemoryManager memoryManager(false, wddm.get());
EXPECT_TRUE(memoryManager.isAsyncDeleterEnabled());
EXPECT_NE(nullptr, memoryManager.getDeferredDeleter());
}
TEST_F(MockWddmMemoryManagerTest, givenDefaultWddmMemoryManagerWhenItIsCreatedThenMemoryBudgetIsNotExhausted) {
WddmMock *wddm = new WddmMock;
WddmMemoryManager memoryManager(false, wddm);
auto wddm = std::make_unique<WddmMock>();
WddmMemoryManager memoryManager(false, wddm.get());
EXPECT_FALSE(memoryManager.isMemoryBudgetExhausted());
}
TEST_F(MockWddmMemoryManagerTest, givenEnabledAsyncDeleterFlagWhenMemoryManagerIsCreatedThenAsyncDeleterEnabledIsTrueAndDeleterIsNotNullptr) {
bool defaultEnableDeferredDeleterFlag = DebugManager.flags.EnableDeferredDeleter.get();
DebugManager.flags.EnableDeferredDeleter.set(true);
WddmMock *wddm = new WddmMock;
WddmMemoryManager memoryManager(false, wddm);
auto wddm = std::make_unique<WddmMock>();
WddmMemoryManager memoryManager(false, wddm.get());
EXPECT_TRUE(memoryManager.isAsyncDeleterEnabled());
EXPECT_NE(nullptr, memoryManager.getDeferredDeleter());
DebugManager.flags.EnableDeferredDeleter.set(defaultEnableDeferredDeleterFlag);
@ -2082,17 +2082,17 @@ TEST_F(MockWddmMemoryManagerTest, givenEnabledAsyncDeleterFlagWhenMemoryManagerI
TEST_F(MockWddmMemoryManagerTest, givenDisabledAsyncDeleterFlagWhenMemoryManagerIsCreatedThenAsyncDeleterEnabledIsFalseAndDeleterIsNullptr) {
bool defaultEnableDeferredDeleterFlag = DebugManager.flags.EnableDeferredDeleter.get();
DebugManager.flags.EnableDeferredDeleter.set(false);
WddmMock *wddm = new WddmMock;
WddmMemoryManager memoryManager(false, wddm);
auto wddm = std::make_unique<WddmMock>();
WddmMemoryManager memoryManager(false, wddm.get());
EXPECT_FALSE(memoryManager.isAsyncDeleterEnabled());
EXPECT_EQ(nullptr, memoryManager.getDeferredDeleter());
DebugManager.flags.EnableDeferredDeleter.set(defaultEnableDeferredDeleterFlag);
}
HWTEST_F(MockWddmMemoryManagerTest, givenPageTableManagerWhenMapAuxGpuVaCalledThenUseWddmToMap) {
auto myWddm = new WddmMock();
auto myWddm = std::make_unique<WddmMock>();
EXPECT_TRUE(myWddm->init<FamilyType>());
WddmMemoryManager memoryManager(false, myWddm);
WddmMemoryManager memoryManager(false, myWddm.get());
auto mockMngr = new NiceMock<MockGmmPageTableMngr>();
myWddm->resetPageTableManager(mockMngr);
@ -2141,9 +2141,9 @@ HWTEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenMappedGpu
}
HWTEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenReleaseingThenUnmapAuxVa) {
WddmMock *wddm = new WddmMock();
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init<FamilyType>());
WddmMemoryManager memoryManager(false, wddm);
WddmMemoryManager memoryManager(false, wddm.get());
D3DGPU_VIRTUAL_ADDRESS gpuVa = 123;
auto mockMngr = new NiceMock<MockGmmPageTableMngr>();
@ -2167,9 +2167,9 @@ HWTEST_F(MockWddmMemoryManagerTest, givenRenderCompressedAllocationWhenReleasein
}
HWTEST_F(MockWddmMemoryManagerTest, givenNonRenderCompressedAllocationWhenReleaseingThenDontUnmapAuxVa) {
WddmMock *wddm = new WddmMock();
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init<FamilyType>());
WddmMemoryManager memoryManager(false, wddm);
WddmMemoryManager memoryManager(false, wddm.get());
auto mockMngr = new NiceMock<MockGmmPageTableMngr>();
wddm->resetPageTableManager(mockMngr);
@ -2211,9 +2211,9 @@ HWTEST_F(MockWddmMemoryManagerTest, givenFailingAllocationWhenMappedGpuVaThenRet
HWTEST_F(MockWddmMemoryManagerTest, givenRenderCompressedFlagSetWhenInternalIsUnsetThenDontUpdateAuxTable) {
D3DGPU_VIRTUAL_ADDRESS gpuVa = 0;
WddmMock *wddm = new WddmMock();
auto wddm = std::make_unique<WddmMock>();
EXPECT_TRUE(wddm->init<FamilyType>());
WddmMemoryManager memoryManager(false, wddm);
WddmMemoryManager memoryManager(false, wddm.get());
auto mockMngr = new NiceMock<MockGmmPageTableMngr>();
wddm->resetPageTableManager(mockMngr);

View File

@ -55,13 +55,13 @@ class WddmMemoryManagerFixture : public GmmEnvironmentFixture, public GdiDllFixt
heap32Base = 0x1000;
}
wddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1);
memoryManager.reset(new (std::nothrow) MockWddmMemoryManager(wddm));
memoryManager.reset(new (std::nothrow) MockWddmMemoryManager(wddm.get()));
//assert we have memory manager
ASSERT_NE(nullptr, memoryManager);
}
std::unique_ptr<MockWddmMemoryManager> memoryManager;
WddmMock *wddm = nullptr;
std::unique_ptr<WddmMock> wddm;
};
typedef ::Test<WddmMemoryManagerFixture> WddmMemoryManagerTest;
@ -70,7 +70,7 @@ class MockWddmMemoryManagerFixture : public GmmEnvironmentFixture {
public:
void SetUp() {
GmmEnvironmentFixture::SetUp();
wddm = static_cast<WddmMock *>(Wddm::createWddm(WddmInterfaceVersion::Wddm20));
wddm.reset(static_cast<WddmMock *>(Wddm::createWddm(WddmInterfaceVersion::Wddm20)));
gdi = new MockGdi();
wddm->gdi.reset(gdi);
}
@ -83,7 +83,7 @@ class MockWddmMemoryManagerFixture : public GmmEnvironmentFixture {
heap32Base = 0x1000;
}
wddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1);
memoryManager.reset(new (std::nothrow) MockWddmMemoryManager(wddm));
memoryManager.reset(new (std::nothrow) MockWddmMemoryManager(wddm.get()));
//assert we have memory manager
ASSERT_NE(nullptr, memoryManager);
}
@ -92,7 +92,7 @@ class MockWddmMemoryManagerFixture : public GmmEnvironmentFixture {
GmmEnvironmentFixture::TearDown();
}
std::unique_ptr<MockWddmMemoryManager> memoryManager;
WddmMock *wddm = nullptr;
std::unique_ptr<WddmMock> wddm;
MockGdi *gdi = nullptr;
};
@ -134,18 +134,18 @@ class WddmMemoryManagerFixtureWithGmockWddm : public GmmEnvironmentFixture {
void SetUp() {
GmmEnvironmentFixture::SetUp();
// wddm is deleted by memory manager
wddm = new NiceMock<GmockWddm>;
wddm.reset(new NiceMock<GmockWddm>);
ASSERT_NE(nullptr, wddm);
}
template <typename FamiltyType>
void SetUpMm() {
wddm->init<FamiltyType>();
memoryManager = new (std::nothrow) MockWddmMemoryManager(wddm);
memoryManager = new (std::nothrow) MockWddmMemoryManager(wddm.get());
//assert we have memory manager
ASSERT_NE(nullptr, memoryManager);
ON_CALL(*wddm, createAllocationsAndMapGpuVa(::testing::_)).WillByDefault(::testing::Invoke(wddm, &GmockWddm::baseCreateAllocationAndMapGpuVa));
ON_CALL(*wddm, createAllocationsAndMapGpuVa(::testing::_)).WillByDefault(::testing::Invoke(wddm.get(), &GmockWddm::baseCreateAllocationAndMapGpuVa));
}
void TearDown() {
delete memoryManager;
@ -153,7 +153,7 @@ class WddmMemoryManagerFixtureWithGmockWddm : public GmmEnvironmentFixture {
GmmEnvironmentFixture::TearDown();
}
NiceMock<GmockWddm> *wddm;
std::unique_ptr<NiceMock<GmockWddm>> wddm;
};
typedef ::Test<WddmMemoryManagerFixtureWithGmockWddm> WddmMemoryManagerTest2;
@ -175,7 +175,7 @@ class BufferWithWddmMemory : public ::testing::Test,
heap32Base = 0x1000;
}
wddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1);
memoryManager.reset(new (std::nothrow) MockWddmMemoryManager(wddm));
memoryManager.reset(new (std::nothrow) MockWddmMemoryManager(wddm.get()));
//assert we have memory manager
ASSERT_NE(nullptr, memoryManager);
context.setMemoryManager(memoryManager.get());