2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2021-05-16 20:51:16 +02:00
|
|
|
* Copyright (C) 2018-2021 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
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/helpers/aligned_memory.h"
|
|
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
|
|
|
|
#include "shared/source/os_interface/os_context.h"
|
|
|
|
|
#include "shared/source/os_interface/windows/wddm_allocation.h"
|
|
|
|
|
#include "shared/source/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-02-27 11:39:32 +01:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
#include <map>
|
|
|
|
|
#include <mutex>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
namespace NEO {
|
2017-12-21 00:45:38 +01:00
|
|
|
class Gmm;
|
2019-02-27 11:17:17 +01:00
|
|
|
class OsContextWin;
|
2017-12-21 00:45:38 +01:00
|
|
|
class Wddm;
|
|
|
|
|
|
|
|
|
|
class WddmMemoryManager : public MemoryManager {
|
|
|
|
|
public:
|
2019-03-12 12:00:41 +01:00
|
|
|
using MemoryManager::allocateGraphicsMemoryWithProperties;
|
|
|
|
|
|
2019-02-20 11:18:24 +01:00
|
|
|
~WddmMemoryManager() override;
|
2019-03-21 17:45:00 +01:00
|
|
|
WddmMemoryManager(ExecutionEnvironment &executionEnvironment);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2018-06-04 16:11:04 +02:00
|
|
|
WddmMemoryManager(const WddmMemoryManager &) = delete;
|
|
|
|
|
WddmMemoryManager &operator=(const WddmMemoryManager &) = delete;
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation) override;
|
2019-03-04 14:50:26 +01:00
|
|
|
void handleFenceCompletion(GraphicsAllocation *allocation) override;
|
|
|
|
|
|
2021-05-24 06:14:30 +00:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation) override;
|
2021-07-06 12:35:28 +00:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, GraphicsAllocation::AllocationType allocType) override;
|
2018-07-18 09:48:21 +02:00
|
|
|
|
2018-05-08 10:00:23 +02:00
|
|
|
void addAllocationToHostPtrManager(GraphicsAllocation *memory) override;
|
|
|
|
|
void removeAllocationFromHostPtrManager(GraphicsAllocation *memory) override;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-01-07 07:42:40 +01:00
|
|
|
AllocationStatus populateOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override;
|
2019-11-15 09:59:48 +01:00
|
|
|
void cleanOsHandles(OsHandleStorage &handleStorage, uint32_t rootDeviceIndex) override;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2019-01-10 11:10:58 +01:00
|
|
|
void obtainGpuAddressFromFragments(WddmAllocation *allocation, OsHandleStorage &handleStorage);
|
2018-06-21 11:42:03 +02:00
|
|
|
|
2020-01-07 07:42:40 +01:00
|
|
|
uint64_t getSystemSharedMemory(uint32_t rootDeviceIndex) override;
|
2020-10-30 10:27:48 +01:00
|
|
|
uint64_t getLocalMemorySize(uint32_t rootDeviceIndex, uint32_t deviceBitfield) override;
|
2019-04-15 15:20:51 +02:00
|
|
|
|
2020-01-07 07:42:40 +01:00
|
|
|
bool tryDeferDeletions(const D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle, uint32_t rootDeviceIndex);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2018-11-05 15:15:31 +01:00
|
|
|
bool isMemoryBudgetExhausted() const override;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2018-01-22 16:43:26 +01:00
|
|
|
AlignedMallocRestrictions *getAlignedMallocRestrictions() override;
|
|
|
|
|
|
2020-10-07 15:32:03 +02:00
|
|
|
bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy) override;
|
2020-01-07 07:42:40 +01:00
|
|
|
void *reserveCpuAddressRange(size_t size, uint32_t rootDeviceIndex) override;
|
|
|
|
|
void releaseReservedCpuAddressRange(void *reserved, size_t size, uint32_t rootDeviceIndex) override;
|
2020-03-11 11:35:26 +01:00
|
|
|
bool isCpuCopyRequired(const void *ptr) override;
|
2019-03-01 14:25:33 +01:00
|
|
|
|
2020-07-07 10:50:04 +02:00
|
|
|
AddressRange reserveGpuAddress(size_t size, uint32_t rootDeviceIndex) override { return AddressRange{0, 0}; };
|
|
|
|
|
void freeGpuAddress(AddressRange addressRange, uint32_t rootDeviceIndex) override{};
|
2020-07-31 16:52:41 +02:00
|
|
|
bool verifyHandle(osHandle handle, uint32_t rootDeviceIndex, bool ntHandle) override;
|
2020-07-07 10:50:04 +02:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
protected:
|
2019-02-25 14:11:34 +01:00
|
|
|
GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) override;
|
2019-03-12 12:00:41 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &allocationData) override;
|
2018-11-30 11:01:33 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override;
|
2020-09-03 00:57:05 -07:00
|
|
|
GraphicsAllocation *allocateUSMHostGraphicsMemory(const AllocationData &allocationData) override;
|
2019-04-03 09:08:10 +02:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryWithHostPtr(const AllocationData &allocationData) override;
|
2019-02-28 14:12:13 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemory64kb(const AllocationData &allocationData) override;
|
2019-11-14 04:08:59 -05:00
|
|
|
GraphicsAllocation *allocateShareableMemory(const AllocationData &allocationData) override;
|
2019-01-22 12:40:17 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryForImageImpl(const AllocationData &allocationData, std::unique_ptr<Gmm> gmm) override;
|
2020-07-07 10:50:04 +02:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryWithGpuVa(const AllocationData &allocationData) override { return nullptr; }
|
2018-11-30 11:01:33 +01:00
|
|
|
|
2019-01-24 11:51:33 +01:00
|
|
|
void *lockResourceImpl(GraphicsAllocation &graphicsAllocation) override;
|
|
|
|
|
void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) override;
|
2019-03-11 10:19:02 +01:00
|
|
|
void freeAssociatedResourceImpl(GraphicsAllocation &graphicsAllocation) override;
|
2020-07-01 14:03:46 +02:00
|
|
|
GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData, bool useLocalMemory) override;
|
2018-12-21 10:16:27 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override;
|
2019-01-24 11:51:33 +01:00
|
|
|
|
2021-06-22 16:38:37 +02:00
|
|
|
MOCKABLE_VIRTUAL size_t getHugeGfxMemoryChunkSize() const;
|
|
|
|
|
GraphicsAllocation *allocateHugeGraphicsMemory(const AllocationData &allocationData, bool sharedVirtualAddress);
|
2020-04-21 13:16:45 +02:00
|
|
|
|
2019-10-22 10:26:23 +02:00
|
|
|
GraphicsAllocation *createAllocationFromHandle(osHandle handle, bool requireSpecificBitness, bool ntHandle, GraphicsAllocation::AllocationType allocationType, uint32_t rootDeviceIndex);
|
2017-12-21 00:45:38 +01:00
|
|
|
static bool validateAllocation(WddmAllocation *alloc);
|
2019-03-14 15:23:09 +01:00
|
|
|
bool createWddmAllocation(WddmAllocation *allocation, void *requiredGpuPtr);
|
2019-06-04 10:33:40 +02:00
|
|
|
bool mapGpuVirtualAddress(WddmAllocation *graphicsAllocation, const void *requiredGpuPtr);
|
|
|
|
|
bool mapGpuVaForOneHandleAllocation(WddmAllocation *graphicsAllocation, const void *requiredGpuPtr);
|
2020-06-29 10:59:34 +02:00
|
|
|
bool mapMultiHandleAllocationWithRetry(WddmAllocation *allocation, const void *requiredGpuPtr);
|
2019-03-07 15:14:11 +01:00
|
|
|
bool createGpuAllocationsWithRetry(WddmAllocation *graphicsAllocation);
|
2018-01-22 16:43:26 +01:00
|
|
|
AlignedMallocRestrictions mallocRestrictions;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-01-07 07:42:40 +01:00
|
|
|
Wddm &getWddm(uint32_t rootDeviceIndex) const;
|
2017-12-21 00:45:38 +01:00
|
|
|
};
|
2019-03-26 11:59:46 +01:00
|
|
|
} // namespace NEO
|