2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2019-01-07 09:29:49 +01:00
|
|
|
* Copyright (C) 2017-2019 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
#define UMDF_USING_NTSTATUS
|
2018-10-30 13:14:07 +01:00
|
|
|
#include "runtime/helpers/aligned_memory.h"
|
2017-12-21 00:45:38 +01:00
|
|
|
#include "runtime/memory_manager/graphics_allocation.h"
|
|
|
|
|
#include "runtime/os_interface/windows/windows_wrapper.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
#include <d3dkmthk.h>
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
struct OsHandle {
|
|
|
|
|
D3DKMT_HANDLE handle;
|
|
|
|
|
D3DGPU_VIRTUAL_ADDRESS gpuPtr;
|
|
|
|
|
Gmm *gmm;
|
|
|
|
|
};
|
|
|
|
|
|
2019-03-05 14:21:57 +01:00
|
|
|
constexpr size_t trimListUnusedPosition = std::numeric_limits<size_t>::max();
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
class WddmAllocation : public GraphicsAllocation {
|
|
|
|
|
public:
|
2019-02-28 09:51:36 +01:00
|
|
|
WddmAllocation(AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, void *reservedAddr, MemoryPool::Type pool, bool multiOsContextCapable)
|
2019-03-13 15:31:46 +01:00
|
|
|
: GraphicsAllocation(allocationType, cpuPtrIn, castToUint64(cpuPtrIn), 0llu, sizeIn, pool, multiOsContextCapable) {
|
2019-03-05 14:21:57 +01:00
|
|
|
trimCandidateListPositions.fill(trimListUnusedPosition);
|
2019-03-13 15:31:46 +01:00
|
|
|
reservedAddressRangeInfo.addressPtr = reservedAddr;
|
|
|
|
|
reservedAddressRangeInfo.rangeSize = sizeIn;
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2019-02-28 09:51:36 +01:00
|
|
|
WddmAllocation(AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, osHandle sharedHandle, MemoryPool::Type pool, bool multiOsContextCapable)
|
2019-03-05 14:21:57 +01:00
|
|
|
: GraphicsAllocation(allocationType, cpuPtrIn, sizeIn, sharedHandle, pool, multiOsContextCapable) {
|
|
|
|
|
trimCandidateListPositions.fill(trimListUnusedPosition);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void *getAlignedCpuPtr() const {
|
2018-10-31 10:05:34 +01:00
|
|
|
return alignDown(this->cpuPtr, MemoryConstants::pageSize);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t getAlignedSize() const {
|
2018-10-30 13:14:07 +01:00
|
|
|
return alignSizeWholePage(this->cpuPtr, this->size);
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ResidencyData &getResidencyData() {
|
|
|
|
|
return residency;
|
|
|
|
|
}
|
2019-03-05 09:25:18 +01: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 00:45:38 +01:00
|
|
|
|
2018-10-09 17:03:07 +02:00
|
|
|
void setTrimCandidateListPosition(uint32_t osContextId, size_t position) {
|
|
|
|
|
trimCandidateListPositions[osContextId] = position;
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2018-10-09 17:03:07 +02:00
|
|
|
size_t getTrimCandidateListPosition(uint32_t osContextId) const {
|
|
|
|
|
if (osContextId < trimCandidateListPositions.size()) {
|
|
|
|
|
return trimCandidateListPositions[osContextId];
|
|
|
|
|
}
|
|
|
|
|
return trimListUnusedPosition;
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2018-10-24 14:25:04 +02:00
|
|
|
void setGpuAddress(uint64_t graphicsAddress) { this->gpuAddress = graphicsAddress; }
|
2019-01-31 10:59:40 +01:00
|
|
|
void setCpuAddress(void *cpuPtr) { this->cpuPtr = cpuPtr; }
|
2018-01-30 15:07:58 +01:00
|
|
|
|
2019-02-27 11:22:10 +01:00
|
|
|
std::string getAllocationInfoString() const override;
|
2019-03-05 14:21:57 +01:00
|
|
|
uint64_t &getGpuAddressToModify() { return gpuAddress; }
|
2018-12-20 17:38:38 +01:00
|
|
|
|
2019-03-05 09:25:18 +01:00
|
|
|
// OS assigned fields
|
|
|
|
|
D3DKMT_HANDLE resourceHandle = 0u; // used by shared resources
|
|
|
|
|
bool needsMakeResidentBeforeLock = false;
|
2019-03-07 15:14:11 +01:00
|
|
|
D3DGPU_VIRTUAL_ADDRESS preferredGpuAddress = 0u;
|
2019-03-05 09:25:18 +01:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
protected:
|
2019-03-05 09:25:18 +01: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 00:45:38 +01:00
|
|
|
ResidencyData residency;
|
2019-03-05 14:21:57 +01:00
|
|
|
std::array<size_t, maxOsContextCount> trimCandidateListPositions;
|
2017-12-21 00:45:38 +01:00
|
|
|
};
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|