2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2018-09-18 15:11:08 +08:00
|
|
|
* Copyright (C) 2017-2018 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
|
|
|
|
#define UMDF_USING_NTSTATUS
|
2018-10-30 20:14:07 +08:00
|
|
|
#include "runtime/helpers/aligned_memory.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/memory_manager/graphics_allocation.h"
|
|
|
|
#include "runtime/os_interface/windows/windows_wrapper.h"
|
|
|
|
#include <d3dkmthk.h>
|
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
|
|
|
|
class Gmm;
|
|
|
|
|
|
|
|
struct OsHandle {
|
|
|
|
D3DKMT_HANDLE handle;
|
|
|
|
D3DGPU_VIRTUAL_ADDRESS gpuPtr;
|
|
|
|
Gmm *gmm;
|
|
|
|
};
|
|
|
|
|
|
|
|
const size_t trimListUnusedPosition = (size_t)-1;
|
|
|
|
|
|
|
|
class WddmAllocation : public GraphicsAllocation {
|
|
|
|
public:
|
|
|
|
// OS assigned fields
|
|
|
|
D3DKMT_HANDLE handle; // set by createAllocation
|
|
|
|
D3DKMT_HANDLE resourceHandle = 0u; // used by shared resources
|
|
|
|
|
|
|
|
D3DGPU_VIRTUAL_ADDRESS gpuPtr; // set by mapGpuVA
|
2018-10-30 20:14:07 +08:00
|
|
|
WddmAllocation(void *cpuPtrIn, size_t sizeIn, void *alignedCpuPtr, void *reservedAddr, MemoryPool::Type pool, size_t osContextsCount)
|
2018-10-30 22:24:15 +08:00
|
|
|
: GraphicsAllocation(cpuPtrIn, castToUint64(cpuPtrIn), 0llu, sizeIn),
|
2017-12-21 07:45:38 +08:00
|
|
|
handle(0),
|
|
|
|
gpuPtr(0),
|
|
|
|
alignedCpuPtr(alignedCpuPtr),
|
2018-10-09 23:03:07 +08:00
|
|
|
trimCandidateListPositions(osContextsCount, trimListUnusedPosition) {
|
2018-01-30 22:07:58 +08:00
|
|
|
reservedAddressSpace = reservedAddr;
|
2018-07-14 00:50:55 +08:00
|
|
|
this->memoryPool = pool;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-10-12 23:37:27 +08:00
|
|
|
WddmAllocation(void *cpuPtrIn, size_t sizeIn, osHandle sharedHandle, MemoryPool::Type pool, size_t osContextsCount)
|
|
|
|
: GraphicsAllocation(cpuPtrIn, sizeIn, sharedHandle),
|
|
|
|
handle(0),
|
|
|
|
gpuPtr(0),
|
|
|
|
alignedCpuPtr(nullptr),
|
2018-10-09 23:03:07 +08:00
|
|
|
trimCandidateListPositions(osContextsCount, trimListUnusedPosition) {
|
2018-01-30 22:07:58 +08:00
|
|
|
reservedAddressSpace = nullptr;
|
2018-07-14 00:50:55 +08:00
|
|
|
this->memoryPool = pool;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-10-12 23:37:27 +08:00
|
|
|
WddmAllocation(void *alignedCpuPtr, size_t sizeIn, void *reservedAddress, MemoryPool::Type pool, size_t osContextsCount)
|
2018-10-30 20:14:07 +08:00
|
|
|
: WddmAllocation(alignedCpuPtr, sizeIn, alignedCpuPtr, reservedAddress, pool, osContextsCount) {
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void *getAlignedCpuPtr() const {
|
|
|
|
return this->alignedCpuPtr;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t getAlignedSize() const {
|
2018-10-30 20:14:07 +08:00
|
|
|
return alignSizeWholePage(this->cpuPtr, this->size);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ResidencyData &getResidencyData() {
|
|
|
|
return residency;
|
|
|
|
}
|
|
|
|
|
2018-10-09 23:03:07 +08:00
|
|
|
void setTrimCandidateListPosition(uint32_t osContextId, size_t position) {
|
|
|
|
trimCandidateListPositions[osContextId] = position;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-10-09 23:03:07 +08:00
|
|
|
size_t getTrimCandidateListPosition(uint32_t osContextId) const {
|
|
|
|
if (osContextId < trimCandidateListPositions.size()) {
|
|
|
|
return trimCandidateListPositions[osContextId];
|
|
|
|
}
|
|
|
|
return trimListUnusedPosition;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2018-01-30 22:07:58 +08:00
|
|
|
void *getReservedAddress() const {
|
|
|
|
return this->reservedAddressSpace;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setReservedAddress(void *reserveMem) {
|
|
|
|
this->reservedAddressSpace = reserveMem;
|
|
|
|
}
|
2018-10-24 20:25:04 +08:00
|
|
|
void setGpuAddress(uint64_t graphicsAddress) { this->gpuAddress = graphicsAddress; }
|
2018-01-30 22:07:58 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
protected:
|
|
|
|
void *alignedCpuPtr;
|
|
|
|
ResidencyData residency;
|
2018-10-09 23:03:07 +08:00
|
|
|
std::vector<size_t> trimCandidateListPositions;
|
2018-01-30 22:07:58 +08:00
|
|
|
void *reservedAddressSpace;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
} // namespace OCLRT
|