2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2021-12-14 21:57:01 +00:00
|
|
|
* Copyright (C) 2018-2022 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
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/helpers/aligned_memory.h"
|
|
|
|
#include "shared/source/memory_manager/graphics_allocation.h"
|
2021-06-07 21:47:12 +02:00
|
|
|
#include "shared/source/os_interface/windows/d3dkmthk_wrapper.h"
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/os_interface/windows/windows_wrapper.h"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2021-04-02 17:01:51 +00:00
|
|
|
struct OsHandleWin : OsHandle {
|
2022-07-07 21:11:29 +10:00
|
|
|
~OsHandleWin() override = default;
|
2021-04-02 17:01:51 +00:00
|
|
|
D3DKMT_HANDLE handle = 0;
|
|
|
|
D3DGPU_VIRTUAL_ADDRESS gpuPtr = 0;
|
|
|
|
Gmm *gmm = nullptr;
|
2017-12-21 00:45:38 +01:00
|
|
|
};
|
|
|
|
|
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:
|
2022-06-07 15:35:22 +00:00
|
|
|
struct RegistrationData {
|
|
|
|
uint64_t gpuVirtualAddress = 0;
|
|
|
|
uint64_t size = 0;
|
|
|
|
};
|
|
|
|
|
2022-06-01 21:13:52 +00:00
|
|
|
WddmAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, void *cpuPtrIn, uint64_t canonizedAddress, size_t sizeIn, void *reservedAddr, MemoryPool pool, uint32_t shareable, size_t maxOsContextCount)
|
2022-05-30 14:18:50 +00:00
|
|
|
: WddmAllocation(rootDeviceIndex, 1, allocationType, cpuPtrIn, canonizedAddress, sizeIn, reservedAddr, pool, shareable, maxOsContextCount) {}
|
2020-04-21 13:16:45 +02:00
|
|
|
|
2022-05-30 14:18:50 +00:00
|
|
|
WddmAllocation(uint32_t rootDeviceIndex, size_t numGmms, AllocationType allocationType, void *cpuPtrIn, uint64_t canonizedAddress, size_t sizeIn,
|
2022-06-01 21:13:52 +00:00
|
|
|
void *reservedAddr, MemoryPool pool, uint32_t shareable, size_t maxOsContextCount)
|
2022-05-30 14:18:50 +00:00
|
|
|
: GraphicsAllocation(rootDeviceIndex, numGmms, allocationType, cpuPtrIn, canonizedAddress, 0llu, sizeIn, pool, maxOsContextCount),
|
2022-05-10 10:46:08 +00:00
|
|
|
shareable(shareable), trimCandidateListPositions(maxOsContextCount, trimListUnusedPosition) {
|
2019-11-14 04:08:59 -05:00
|
|
|
reservedAddressRangeInfo.addressPtr = reservedAddr;
|
|
|
|
reservedAddressRangeInfo.rangeSize = sizeIn;
|
2020-04-21 13:16:45 +02:00
|
|
|
handles.resize(gmms.size());
|
2019-11-14 04:08:59 -05:00
|
|
|
}
|
|
|
|
|
2022-06-03 11:48:45 +00:00
|
|
|
WddmAllocation(uint32_t rootDeviceIndex, AllocationType allocationType, void *cpuPtrIn, size_t sizeIn, osHandle sharedHandle,
|
|
|
|
MemoryPool pool, size_t maxOsContextCount, uint64_t canonizedGpuAddress)
|
|
|
|
: WddmAllocation(rootDeviceIndex, 1, allocationType, cpuPtrIn, sizeIn, sharedHandle, pool, maxOsContextCount, canonizedGpuAddress) {}
|
2020-04-21 13:16:45 +02:00
|
|
|
|
|
|
|
WddmAllocation(uint32_t rootDeviceIndex, size_t numGmms, AllocationType allocationType, void *cpuPtrIn, size_t sizeIn,
|
2022-06-03 11:48:45 +00:00
|
|
|
osHandle sharedHandle, MemoryPool pool, size_t maxOsContextCount, uint64_t canonizedGpuAddress)
|
|
|
|
: GraphicsAllocation(rootDeviceIndex, numGmms, allocationType, cpuPtrIn, sizeIn, sharedHandle, pool, maxOsContextCount, canonizedGpuAddress),
|
2022-05-10 10:46:08 +00:00
|
|
|
trimCandidateListPositions(maxOsContextCount, trimListUnusedPosition) {
|
2020-04-21 13:16:45 +02:00
|
|
|
handles.resize(gmms.size());
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2020-04-21 13:16:45 +02:00
|
|
|
const StackVec<D3DKMT_HANDLE, EngineLimits::maxHandleCount> &getHandles() const { return handles; }
|
2019-03-05 09:25:18 +01:00
|
|
|
D3DKMT_HANDLE &getHandleToModify(uint32_t handleIndex) { return handles[handleIndex]; }
|
|
|
|
D3DKMT_HANDLE getDefaultHandle() const { return handles[0]; }
|
2020-04-21 13:16:45 +02:00
|
|
|
D3DKMT_HANDLE getHandle(uint32_t handleIndex) const { return handles[handleIndex]; }
|
2019-03-05 09:25:18 +01:00
|
|
|
void setDefaultHandle(D3DKMT_HANDLE handle) {
|
2020-04-21 13:16:45 +02:00
|
|
|
setHandle(handle, 0);
|
|
|
|
}
|
|
|
|
void setHandle(D3DKMT_HANDLE handle, uint32_t handleIndex) {
|
|
|
|
handles[handleIndex] = handle;
|
2019-03-05 09:25:18 +01:00
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2021-08-30 14:57:25 +00:00
|
|
|
uint64_t peekInternalHandle(MemoryManager *memoryManager) override {
|
|
|
|
return ntSecureHandle;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t *getSharedHandleToModify() {
|
2020-02-25 18:58:09 +01:00
|
|
|
if (shareable) {
|
2021-08-30 14:57:25 +00:00
|
|
|
return &ntSecureHandle;
|
2020-02-25 18:58:09 +01:00
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
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-05-27 11:50:29 +02:00
|
|
|
D3DGPU_VIRTUAL_ADDRESS reservedGpuVirtualAddress = 0u;
|
|
|
|
uint64_t reservedSizeForGpuVirtualAddress = 0u;
|
2019-11-14 04:08:59 -05:00
|
|
|
uint32_t shareable = 0u;
|
2020-09-14 15:14:11 +02:00
|
|
|
bool allocInFrontWindowPool = false;
|
2019-03-05 09:25:18 +01:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
protected:
|
2021-08-30 14:57:25 +00:00
|
|
|
uint64_t ntSecureHandle = 0u;
|
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();
|
|
|
|
}
|
2019-12-17 08:11:16 +01:00
|
|
|
std::vector<size_t> trimCandidateListPositions;
|
2020-04-21 13:16:45 +02:00
|
|
|
StackVec<D3DKMT_HANDLE, EngineLimits::maxHandleCount> handles;
|
2017-12-21 00:45:38 +01:00
|
|
|
};
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|