2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-01-07 16:29:49 +08:00
|
|
|
* Copyright (C) 2017-2019 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"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#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
|
2019-02-26 18:37:51 +08:00
|
|
|
|
2019-02-11 17:02:27 +08:00
|
|
|
WddmAllocation(void *cpuPtrIn, size_t sizeIn, void *reservedAddr, MemoryPool::Type pool, bool multiOsContextCapable)
|
2019-02-26 18:37:51 +08:00
|
|
|
: GraphicsAllocation(AllocationType::UNKNOWN, cpuPtrIn, castToUint64(cpuPtrIn), 0llu, sizeIn, pool, multiOsContextCapable),
|
2017-12-21 07:45:38 +08:00
|
|
|
handle(0),
|
|
|
|
gpuPtr(0),
|
2018-11-19 18:24:16 +08:00
|
|
|
trimCandidateListPositions(maxOsContextCount, trimListUnusedPosition) {
|
2018-01-30 22:07:58 +08:00
|
|
|
reservedAddressSpace = reservedAddr;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2019-02-11 17:02:27 +08:00
|
|
|
WddmAllocation(void *cpuPtrIn, size_t sizeIn, osHandle sharedHandle, MemoryPool::Type pool, bool multiOsContextCapable)
|
2019-02-26 18:37:51 +08:00
|
|
|
: GraphicsAllocation(AllocationType::UNKNOWN, cpuPtrIn, sizeIn, sharedHandle, pool, multiOsContextCapable),
|
2018-10-12 23:37:27 +08:00
|
|
|
handle(0),
|
|
|
|
gpuPtr(0),
|
2019-02-11 17:02:27 +08:00
|
|
|
trimCandidateListPositions(maxOsContextCount, trimListUnusedPosition) {
|
2018-01-30 22:07:58 +08:00
|
|
|
reservedAddressSpace = nullptr;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void *getAlignedCpuPtr() const {
|
2018-10-31 17:05:34 +08:00
|
|
|
return alignDown(this->cpuPtr, MemoryConstants::pageSize);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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; }
|
2019-01-31 17:59:40 +08:00
|
|
|
void setCpuAddress(void *cpuPtr) { this->cpuPtr = cpuPtr; }
|
2019-01-16 22:09:33 +08:00
|
|
|
bool needsMakeResidentBeforeLock = false;
|
2018-01-30 22:07:58 +08:00
|
|
|
|
2019-02-14 18:38:04 +08:00
|
|
|
std::string getAllocationInfoString() const override {
|
2018-12-21 00:38:38 +08:00
|
|
|
std::stringstream ss;
|
|
|
|
ss << " Handle: " << handle;
|
|
|
|
return ss.str();
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
protected:
|
|
|
|
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
|