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 {
|
|
|
|
|
|
|
|
struct OsHandle {
|
|
|
|
D3DKMT_HANDLE handle;
|
|
|
|
D3DGPU_VIRTUAL_ADDRESS gpuPtr;
|
|
|
|
Gmm *gmm;
|
|
|
|
};
|
|
|
|
|
2019-03-05 21:21:57 +08:00
|
|
|
constexpr size_t trimListUnusedPosition = std::numeric_limits<size_t>::max();
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
class WddmAllocation : public GraphicsAllocation {
|
|
|
|
public:
|
|
|
|
// OS assigned fields
|
2019-03-05 21:21:57 +08:00
|
|
|
D3DKMT_HANDLE handle = 0u; // set by createAllocation
|
2017-12-21 07:45:38 +08:00
|
|
|
D3DKMT_HANDLE resourceHandle = 0u; // used by shared resources
|
|
|
|
|
2019-02-28 16:51:36 +08:00
|
|
|
WddmAllocation(AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, void *reservedAddr, MemoryPool::Type pool, bool multiOsContextCapable)
|
2019-03-05 21:21:57 +08:00
|
|
|
: GraphicsAllocation(allocationType, cpuPtrIn, castToUint64(cpuPtrIn), 0llu, sizeIn, pool, multiOsContextCapable), reservedAddressSpace(reservedAddr) {
|
|
|
|
trimCandidateListPositions.fill(trimListUnusedPosition);
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2019-02-28 16:51:36 +08:00
|
|
|
WddmAllocation(AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, osHandle sharedHandle, MemoryPool::Type pool, bool multiOsContextCapable)
|
2019-03-05 21:21:57 +08:00
|
|
|
: GraphicsAllocation(allocationType, cpuPtrIn, sizeIn, sharedHandle, pool, multiOsContextCapable) {
|
|
|
|
trimCandidateListPositions.fill(trimListUnusedPosition);
|
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-27 18:22:10 +08:00
|
|
|
std::string getAllocationInfoString() const override;
|
2019-03-05 21:21:57 +08:00
|
|
|
uint64_t &getGpuAddressToModify() { return gpuAddress; }
|
2018-12-21 00:38:38 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
protected:
|
|
|
|
ResidencyData residency;
|
2019-03-05 21:21:57 +08:00
|
|
|
std::array<size_t, maxOsContextCount> trimCandidateListPositions;
|
|
|
|
void *reservedAddressSpace = nullptr;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
} // namespace OCLRT
|