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
|
2019-08-03 04:25:45 +08:00
|
|
|
#include "core/helpers/aligned_memory.h"
|
2019-08-29 18:15:33 +08:00
|
|
|
#include "core/os_interface/windows/windows_wrapper.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/memory_manager/graphics_allocation.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include <d3dkmthk.h>
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
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:
|
2019-09-12 20:38:46 +08:00
|
|
|
WddmAllocation(AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, void *reservedAddr, MemoryPool::Type pool)
|
|
|
|
: GraphicsAllocation(allocationType, cpuPtrIn, castToUint64(cpuPtrIn), 0llu, sizeIn, pool) {
|
2019-03-05 21:21:57 +08:00
|
|
|
trimCandidateListPositions.fill(trimListUnusedPosition);
|
2019-03-13 22:31:46 +08:00
|
|
|
reservedAddressRangeInfo.addressPtr = reservedAddr;
|
|
|
|
reservedAddressRangeInfo.rangeSize = sizeIn;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
2019-09-12 20:38:46 +08:00
|
|
|
WddmAllocation(AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, osHandle sharedHandle, MemoryPool::Type pool)
|
|
|
|
: GraphicsAllocation(allocationType, cpuPtrIn, sizeIn, sharedHandle, pool) {
|
2019-03-05 21:21:57 +08:00
|
|
|
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;
|
|
|
|
}
|
2019-03-05 16:25:18 +08:00
|
|
|
const std::array<D3DKMT_HANDLE, maxHandleCount> &getHandles() const { return handles; }
|
|
|
|
D3DKMT_HANDLE &getHandleToModify(uint32_t handleIndex) { return handles[handleIndex]; }
|
|
|
|
D3DKMT_HANDLE getDefaultHandle() const { return handles[0]; }
|
|
|
|
void setDefaultHandle(D3DKMT_HANDLE handle) {
|
|
|
|
handles[0] = handle;
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
|
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-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();
|
|
|
|
}
|
|
|
|
std::array<D3DKMT_HANDLE, maxHandleCount> handles{};
|
2017-12-21 07:45:38 +08:00
|
|
|
ResidencyData residency;
|
2019-03-05 21:21:57 +08:00
|
|
|
std::array<size_t, maxOsContextCount> trimCandidateListPositions;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|