2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2021-05-17 02:51:16 +08:00
|
|
|
* Copyright (C) 2018-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
|
|
|
|
#define UMDF_USING_NTSTATUS
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/aligned_memory.h"
|
|
|
|
#include "shared/source/memory_manager/graphics_allocation.h"
|
|
|
|
#include "shared/source/memory_manager/residency.h"
|
2021-06-08 03:47:12 +08:00
|
|
|
#include "shared/source/os_interface/windows/d3dkmthk_wrapper.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/os_interface/windows/windows_wrapper.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2021-04-03 01:01:51 +08:00
|
|
|
struct OsHandleWin : OsHandle {
|
|
|
|
D3DKMT_HANDLE handle = 0;
|
|
|
|
D3DGPU_VIRTUAL_ADDRESS gpuPtr = 0;
|
|
|
|
Gmm *gmm = nullptr;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
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:
|
2020-08-18 20:59:44 +08:00
|
|
|
WddmAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, void *reservedAddr, MemoryPool::Type pool, uint32_t shareable, size_t maxOsContextCount)
|
|
|
|
: WddmAllocation(rootDeviceIndex, 1, allocationType, cpuPtrIn, sizeIn, reservedAddr, pool, shareable, maxOsContextCount) {}
|
2020-04-21 19:16:45 +08:00
|
|
|
|
|
|
|
WddmAllocation(uint32_t rootDeviceIndex, size_t numGmms, AllocationType allocationType, void *cpuPtrIn, size_t sizeIn,
|
2020-08-18 20:59:44 +08:00
|
|
|
void *reservedAddr, MemoryPool::Type pool, uint32_t shareable, size_t maxOsContextCount)
|
2020-08-20 19:48:47 +08:00
|
|
|
: GraphicsAllocation(rootDeviceIndex, numGmms, allocationType, cpuPtrIn, castToUint64(cpuPtrIn), 0llu, sizeIn, pool, maxOsContextCount),
|
|
|
|
shareable(shareable), residency(maxOsContextCount), trimCandidateListPositions(maxOsContextCount, trimListUnusedPosition) {
|
2019-11-14 17:08:59 +08:00
|
|
|
reservedAddressRangeInfo.addressPtr = reservedAddr;
|
|
|
|
reservedAddressRangeInfo.rangeSize = sizeIn;
|
2020-04-21 19:16:45 +08:00
|
|
|
handles.resize(gmms.size());
|
2019-11-14 17:08:59 +08:00
|
|
|
}
|
|
|
|
|
2020-08-18 20:59:44 +08:00
|
|
|
WddmAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, osHandle sharedHandle, MemoryPool::Type pool, size_t maxOsContextCount)
|
|
|
|
: WddmAllocation(rootDeviceIndex, 1, allocationType, cpuPtrIn, sizeIn, sharedHandle, pool, maxOsContextCount) {}
|
2020-04-21 19:16:45 +08:00
|
|
|
|
|
|
|
WddmAllocation(uint32_t rootDeviceIndex, size_t numGmms, AllocationType allocationType, void *cpuPtrIn, size_t sizeIn,
|
2020-08-18 20:59:44 +08:00
|
|
|
osHandle sharedHandle, MemoryPool::Type pool, size_t maxOsContextCount)
|
2020-08-20 19:48:47 +08:00
|
|
|
: GraphicsAllocation(rootDeviceIndex, numGmms, allocationType, cpuPtrIn, sizeIn, sharedHandle, pool, maxOsContextCount),
|
|
|
|
residency(maxOsContextCount), trimCandidateListPositions(maxOsContextCount, trimListUnusedPosition) {
|
2020-04-21 19:16:45 +08:00
|
|
|
handles.resize(gmms.size());
|
|
|
|
}
|
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;
|
|
|
|
}
|
2020-04-21 19:16:45 +08:00
|
|
|
const StackVec<D3DKMT_HANDLE, EngineLimits::maxHandleCount> &getHandles() const { return handles; }
|
2019-03-05 16:25:18 +08:00
|
|
|
D3DKMT_HANDLE &getHandleToModify(uint32_t handleIndex) { return handles[handleIndex]; }
|
|
|
|
D3DKMT_HANDLE getDefaultHandle() const { return handles[0]; }
|
2020-04-21 19:16:45 +08:00
|
|
|
D3DKMT_HANDLE getHandle(uint32_t handleIndex) const { return handles[handleIndex]; }
|
2019-03-05 16:25:18 +08:00
|
|
|
void setDefaultHandle(D3DKMT_HANDLE handle) {
|
2020-04-21 19:16:45 +08:00
|
|
|
setHandle(handle, 0);
|
|
|
|
}
|
|
|
|
void setHandle(D3DKMT_HANDLE handle, uint32_t handleIndex) {
|
|
|
|
handles[handleIndex] = handle;
|
2019-03-05 16:25:18 +08:00
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-02-26 01:58:09 +08:00
|
|
|
D3DKMT_HANDLE *getSharedHandleToModify() {
|
|
|
|
if (shareable) {
|
|
|
|
return &sharingInfo.sharedHandle;
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
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-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; }
|
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
|
|
|
|
2019-03-05 16:25:18 +08:00
|
|
|
// OS assigned fields
|
|
|
|
D3DKMT_HANDLE resourceHandle = 0u; // used by shared resources
|
|
|
|
bool needsMakeResidentBeforeLock = false;
|
2019-05-27 17:50:29 +08:00
|
|
|
D3DGPU_VIRTUAL_ADDRESS reservedGpuVirtualAddress = 0u;
|
|
|
|
uint64_t reservedSizeForGpuVirtualAddress = 0u;
|
2019-11-14 17:08:59 +08:00
|
|
|
uint32_t shareable = 0u;
|
2020-09-14 21:14:11 +08:00
|
|
|
bool allocInFrontWindowPool = false;
|
2019-03-05 16:25:18 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
protected:
|
2019-03-05 16:25:18 +08:00
|
|
|
std::string getHandleInfoString() const {
|
|
|
|
std::stringstream ss;
|
|
|
|
for (auto &handle : handles) {
|
|
|
|
ss << " Handle: " << handle;
|
|
|
|
}
|
|
|
|
return ss.str();
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
ResidencyData residency;
|
2019-12-17 15:11:16 +08:00
|
|
|
std::vector<size_t> trimCandidateListPositions;
|
2020-04-21 19:16:45 +08:00
|
|
|
StackVec<D3DKMT_HANDLE, EngineLimits::maxHandleCount> handles;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|