2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2021-01-30 06:23:06 +08:00
|
|
|
* Copyright (C) 2017-2021 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"
|
2020-08-20 19:48:47 +08:00
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
class BufferObject;
|
2020-08-11 20:00:41 +08:00
|
|
|
class OsContext;
|
2020-09-14 19:28:47 +08:00
|
|
|
class Drm;
|
2021-01-30 06:23:06 +08:00
|
|
|
enum class CacheRegion : uint16_t;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
struct OsHandle {
|
|
|
|
BufferObject *bo = nullptr;
|
|
|
|
};
|
|
|
|
|
2019-12-17 15:11:16 +08:00
|
|
|
using BufferObjects = std::array<BufferObject *, EngineLimits::maxHandleCount>;
|
2019-09-02 03:36:15 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
class DrmAllocation : public GraphicsAllocation {
|
|
|
|
public:
|
2019-11-04 23:03:30 +08:00
|
|
|
DrmAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, BufferObject *bo, void *ptrIn, size_t sizeIn, osHandle sharedHandle, MemoryPool::Type pool)
|
2020-04-21 19:16:45 +08:00
|
|
|
: DrmAllocation(rootDeviceIndex, 1, allocationType, bo, ptrIn, sizeIn, sharedHandle, pool) {}
|
|
|
|
|
|
|
|
DrmAllocation(uint32_t rootDeviceIndex, size_t numGmms, AllocationType allocationType, BufferObject *bo, void *ptrIn, size_t sizeIn, osHandle sharedHandle, MemoryPool::Type pool)
|
2020-08-20 19:48:47 +08:00
|
|
|
: GraphicsAllocation(rootDeviceIndex, numGmms, allocationType, ptrIn, sizeIn, sharedHandle, pool, MemoryManager::maxOsContextCount),
|
2019-09-09 20:14:25 +08:00
|
|
|
bufferObjects({{bo}}) {
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2019-02-26 18:37:51 +08:00
|
|
|
|
2019-11-04 23:03:30 +08:00
|
|
|
DrmAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, BufferObject *bo, void *ptrIn, uint64_t gpuAddress, size_t sizeIn, MemoryPool::Type pool)
|
2020-04-21 19:16:45 +08:00
|
|
|
: DrmAllocation(rootDeviceIndex, 1, allocationType, bo, ptrIn, gpuAddress, sizeIn, pool) {}
|
|
|
|
|
|
|
|
DrmAllocation(uint32_t rootDeviceIndex, size_t numGmms, AllocationType allocationType, BufferObject *bo, void *ptrIn, uint64_t gpuAddress, size_t sizeIn, MemoryPool::Type pool)
|
2020-08-20 19:48:47 +08:00
|
|
|
: GraphicsAllocation(rootDeviceIndex, numGmms, allocationType, ptrIn, gpuAddress, 0, sizeIn, pool, MemoryManager::maxOsContextCount),
|
2019-09-09 20:14:25 +08:00
|
|
|
bufferObjects({{bo}}) {
|
2019-09-02 03:36:15 +08:00
|
|
|
}
|
|
|
|
|
2019-11-04 23:03:30 +08:00
|
|
|
DrmAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, BufferObjects &bos, void *ptrIn, uint64_t gpuAddress, size_t sizeIn, MemoryPool::Type pool)
|
2020-04-21 19:16:45 +08:00
|
|
|
: DrmAllocation(rootDeviceIndex, 1, allocationType, bos, ptrIn, gpuAddress, sizeIn, pool) {}
|
|
|
|
|
|
|
|
DrmAllocation(uint32_t rootDeviceIndex, size_t numGmms, AllocationType allocationType, BufferObjects &bos, void *ptrIn, uint64_t gpuAddress, size_t sizeIn, MemoryPool::Type pool)
|
2020-08-20 19:48:47 +08:00
|
|
|
: GraphicsAllocation(rootDeviceIndex, numGmms, allocationType, ptrIn, gpuAddress, 0, sizeIn, pool, MemoryManager::maxOsContextCount),
|
2019-09-02 03:36:15 +08:00
|
|
|
bufferObjects(bos) {
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2019-02-14 18:38:04 +08:00
|
|
|
std::string getAllocationInfoString() const override;
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
BufferObject *getBO() const {
|
|
|
|
if (fragmentsStorage.fragmentCount) {
|
|
|
|
return fragmentsStorage.fragmentStorageData[0].osHandleStorage->bo;
|
|
|
|
}
|
2019-09-02 03:36:15 +08:00
|
|
|
return this->bufferObjects[0];
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
2019-09-02 03:36:15 +08:00
|
|
|
const BufferObjects &getBOs() const {
|
|
|
|
return this->bufferObjects;
|
|
|
|
}
|
|
|
|
BufferObject *&getBufferObjectToModify(uint32_t handleIndex) {
|
|
|
|
return bufferObjects[handleIndex];
|
|
|
|
}
|
|
|
|
|
2019-06-06 22:26:47 +08:00
|
|
|
uint64_t peekInternalHandle(MemoryManager *memoryManager) override;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2021-01-30 06:23:06 +08:00
|
|
|
bool setCacheRegion(Drm *drm, size_t regionSize, CacheRegion regionIndex);
|
|
|
|
|
2020-10-05 15:57:50 +08:00
|
|
|
void *getMmapPtr() { return this->mmapPtr; }
|
|
|
|
void setMmapPtr(void *ptr) { this->mmapPtr = ptr; }
|
2020-10-12 21:11:40 +08:00
|
|
|
size_t getMmapSize() { return this->mmapSize; }
|
|
|
|
void setMmapSize(size_t size) { this->mmapSize = size; }
|
2020-10-05 15:57:50 +08:00
|
|
|
|
2020-08-11 20:00:41 +08:00
|
|
|
void makeBOsResident(OsContext *osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind);
|
|
|
|
void bindBO(BufferObject *bo, OsContext *osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind);
|
|
|
|
void bindBOs(OsContext *osContext, uint32_t vmHandleId, std::vector<BufferObject *> *bufferObjects, bool bind);
|
2020-11-19 22:11:37 +08:00
|
|
|
MOCKABLE_VIRTUAL void registerBOBindExtHandle(Drm *drm);
|
2020-09-17 19:27:32 +08:00
|
|
|
void freeRegisteredBOBindExtHandles(Drm *drm);
|
2020-10-17 06:52:18 +08:00
|
|
|
void linkWithRegisteredHandle(uint32_t handle);
|
2020-06-26 15:14:36 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
protected:
|
2019-09-02 03:36:15 +08:00
|
|
|
BufferObjects bufferObjects{};
|
2020-09-17 19:27:32 +08:00
|
|
|
StackVec<uint32_t, 1> registeredBoBindHandles;
|
2020-10-05 15:57:50 +08:00
|
|
|
|
|
|
|
void *mmapPtr = nullptr;
|
2020-10-12 21:11:40 +08:00
|
|
|
size_t mmapSize = 0u;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|