2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2024-03-26 20:22:28 +08:00
|
|
|
* Copyright (C) 2018-2024 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/memory_manager/graphics_allocation.h"
|
2023-01-04 21:32:37 +08:00
|
|
|
#include "shared/source/memory_manager/memory_allocation.h"
|
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
2020-07-10 17:21:53 +08:00
|
|
|
#include "shared/source/memory_manager/multi_graphics_allocation.h"
|
2023-10-11 01:05:39 +08:00
|
|
|
#include "shared/test/common/test_macros/mock_method_macros.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2020-06-03 18:31:33 +08:00
|
|
|
|
2022-12-08 22:23:49 +08:00
|
|
|
inline constexpr uint32_t mockRootDeviceIndex = 0u;
|
|
|
|
inline constexpr DeviceBitfield mockDeviceBitfield(0b1);
|
2020-06-03 18:31:33 +08:00
|
|
|
|
2019-04-18 21:30:47 +08:00
|
|
|
class MockGraphicsAllocation : public MemoryAllocation {
|
2018-11-07 16:33:55 +08:00
|
|
|
public:
|
2024-03-26 20:22:28 +08:00
|
|
|
using BaseClass = MemoryAllocation;
|
2021-06-29 00:45:06 +08:00
|
|
|
using MemoryAllocation::allocationOffset;
|
2022-02-17 01:36:27 +08:00
|
|
|
using MemoryAllocation::allocationType;
|
2019-08-07 00:01:26 +08:00
|
|
|
using MemoryAllocation::aubInfo;
|
2022-09-23 21:05:43 +08:00
|
|
|
using MemoryAllocation::cpuPtr;
|
2021-06-29 00:45:06 +08:00
|
|
|
using MemoryAllocation::gpuAddress;
|
2019-04-18 21:30:47 +08:00
|
|
|
using MemoryAllocation::MemoryAllocation;
|
2021-02-11 22:30:05 +08:00
|
|
|
using MemoryAllocation::memoryPool;
|
2019-04-18 21:30:47 +08:00
|
|
|
using MemoryAllocation::objectNotResident;
|
|
|
|
using MemoryAllocation::objectNotUsed;
|
2023-11-21 18:19:31 +08:00
|
|
|
using MemoryAllocation::residency;
|
2021-06-29 00:45:06 +08:00
|
|
|
using MemoryAllocation::size;
|
2019-04-18 21:30:47 +08:00
|
|
|
using MemoryAllocation::usageInfos;
|
2018-05-14 17:25:18 +08:00
|
|
|
|
2019-02-26 18:37:51 +08:00
|
|
|
MockGraphicsAllocation()
|
2023-12-12 17:11:27 +08:00
|
|
|
: MemoryAllocation(0, AllocationType::unknown, nullptr, 0u, 0, MemoryPool::memoryNull, MemoryManager::maxOsContextCount, 0llu) {}
|
2019-02-26 18:37:51 +08:00
|
|
|
|
|
|
|
MockGraphicsAllocation(void *buffer, size_t sizeIn)
|
2023-12-12 17:11:27 +08:00
|
|
|
: MemoryAllocation(0, AllocationType::unknown, buffer, castToUint64(buffer), 0llu, sizeIn, MemoryPool::memoryNull, MemoryManager::maxOsContextCount) {}
|
2019-02-26 18:37:51 +08:00
|
|
|
|
|
|
|
MockGraphicsAllocation(void *buffer, uint64_t gpuAddr, size_t sizeIn)
|
2023-12-12 17:11:27 +08:00
|
|
|
: MemoryAllocation(0, AllocationType::unknown, buffer, gpuAddr, 0llu, sizeIn, MemoryPool::memoryNull, MemoryManager::maxOsContextCount) {}
|
2018-12-04 22:11:29 +08:00
|
|
|
|
2020-07-14 03:59:16 +08:00
|
|
|
MockGraphicsAllocation(uint32_t rootDeviceIndex, void *buffer, size_t sizeIn)
|
2023-12-12 17:11:27 +08:00
|
|
|
: MemoryAllocation(rootDeviceIndex, AllocationType::unknown, buffer, castToUint64(buffer), 0llu, sizeIn, MemoryPool::memoryNull, MemoryManager::maxOsContextCount) {}
|
2020-07-14 03:59:16 +08:00
|
|
|
|
2018-12-04 22:11:29 +08:00
|
|
|
void resetInspectionIds() {
|
|
|
|
for (auto &usageInfo : usageInfos) {
|
|
|
|
usageInfo.inspectionId = 0u;
|
|
|
|
}
|
2018-05-14 17:25:18 +08:00
|
|
|
}
|
2018-12-04 22:11:29 +08:00
|
|
|
|
2022-06-02 05:13:52 +08:00
|
|
|
void overrideMemoryPool(MemoryPool pool) {
|
2018-07-23 17:03:05 +08:00
|
|
|
this->memoryPool = pool;
|
|
|
|
}
|
2023-10-11 01:05:39 +08:00
|
|
|
|
|
|
|
int peekInternalHandle(MemoryManager *memoryManager, uint64_t &handle) override {
|
|
|
|
handle = internalHandle;
|
|
|
|
return peekInternalHandleResult;
|
|
|
|
}
|
2023-11-17 21:14:41 +08:00
|
|
|
void updateCompletionDataForAllocationAndFragments(uint64_t newFenceValue, uint32_t contextId) override {
|
|
|
|
updateCompletionDataForAllocationAndFragmentsCalledtimes++;
|
2023-11-21 18:19:31 +08:00
|
|
|
MemoryAllocation::updateCompletionDataForAllocationAndFragments(newFenceValue, contextId);
|
2023-11-17 21:14:41 +08:00
|
|
|
}
|
2024-03-26 20:22:28 +08:00
|
|
|
ADDMETHOD(hasAllocationReadOnlyType, bool, false, false, (), ());
|
|
|
|
ADDMETHOD_VOIDRETURN(setAsReadOnly, false, (), ());
|
2023-11-17 21:14:41 +08:00
|
|
|
|
|
|
|
uint64_t updateCompletionDataForAllocationAndFragmentsCalledtimes = 0;
|
2023-10-11 01:05:39 +08:00
|
|
|
int peekInternalHandleResult = 0;
|
|
|
|
uint64_t internalHandle = 0;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2020-07-10 17:21:53 +08:00
|
|
|
|
2022-05-05 20:01:59 +08:00
|
|
|
class MockGraphicsAllocationTaskCount : public MockGraphicsAllocation {
|
|
|
|
public:
|
2022-11-22 21:53:59 +08:00
|
|
|
TaskCountType getTaskCount(uint32_t contextId) const override {
|
2022-05-05 20:01:59 +08:00
|
|
|
getTaskCountCalleedTimes++;
|
|
|
|
return MockGraphicsAllocation::getTaskCount(contextId);
|
|
|
|
}
|
2022-11-22 21:53:59 +08:00
|
|
|
void updateTaskCount(TaskCountType newTaskCount, uint32_t contextId) override {
|
2022-05-05 20:01:59 +08:00
|
|
|
updateTaskCountCalleedTimes++;
|
|
|
|
MockGraphicsAllocation::updateTaskCount(newTaskCount, contextId);
|
|
|
|
}
|
|
|
|
static uint32_t getTaskCountCalleedTimes;
|
|
|
|
uint32_t updateTaskCountCalleedTimes = 0;
|
|
|
|
};
|
|
|
|
|
2020-07-10 17:21:53 +08:00
|
|
|
namespace GraphicsAllocationHelper {
|
|
|
|
|
|
|
|
static inline MultiGraphicsAllocation toMultiGraphicsAllocation(GraphicsAllocation *graphicsAllocation) {
|
|
|
|
MultiGraphicsAllocation multiGraphicsAllocation(graphicsAllocation->getRootDeviceIndex());
|
|
|
|
multiGraphicsAllocation.addAllocation(graphicsAllocation);
|
|
|
|
return multiGraphicsAllocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace GraphicsAllocationHelper
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|