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
|
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;
|
|
|
|
|
|
2021-07-14 16:51:47 +02:00
|
|
|
enum class GfxMemoryAllocationMethod : uint32_t {
|
|
|
|
|
UseUmdSystemPtr,
|
|
|
|
|
AllocateByKmd
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
extern const GfxMemoryAllocationMethod preferredAllocationMethod;
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
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;
|
2022-03-02 03:43:59 +00:00
|
|
|
void freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation, bool isImportedAllocation) override;
|
2019-03-04 14:50:26 +01:00
|
|
|
void handleFenceCompletion(GraphicsAllocation *allocation) override;
|
|
|
|
|
|
2022-12-08 00:09:22 +00:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromMultipleSharedHandles(const std::vector<osHandle> &handles, AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override;
|
2022-11-30 15:42:33 +00:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties, bool requireSpecificBitness, bool isHostIpcAllocation, bool reuseSharedAllocation) override;
|
2022-02-04 13:59:01 +00:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle, uint32_t rootDeviceIndex, 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;
|
2021-07-27 14:24:20 +00:00
|
|
|
double getPercentOfGlobalMemoryAvailable(uint32_t rootDeviceIndex) 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;
|
2021-10-21 11:16:19 +00:00
|
|
|
bool copyMemoryToAllocationBanks(GraphicsAllocation *graphicsAllocation, size_t destinationOffset, const void *memoryToCopy, size_t sizeToCopy, DeviceBitfield handleMask) 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;
|
2022-06-13 14:13:34 +00:00
|
|
|
bool isWCMemory(const void *ptr) override;
|
2019-03-01 14:25:33 +01:00
|
|
|
|
2022-09-17 00:38:06 +00:00
|
|
|
AddressRange reserveGpuAddress(const void *requiredStartAddress, size_t size, RootDeviceIndicesContainer rootDeviceIndices, uint32_t *reservedOnRootDeviceIndex) override;
|
|
|
|
|
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;
|
2021-12-14 21:57:01 +00:00
|
|
|
bool isNTHandle(osHandle handle, uint32_t rootDeviceIndex) override;
|
2021-10-07 07:26:03 +00:00
|
|
|
void releaseDeviceSpecificMemResources(uint32_t rootDeviceIndex) override{};
|
|
|
|
|
void createDeviceSpecificMemResources(uint32_t rootDeviceIndex) override{};
|
2022-06-07 15:35:22 +00:00
|
|
|
void registerAllocationInOs(GraphicsAllocation *allocation) 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;
|
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;
|
2021-08-11 10:36:04 +00:00
|
|
|
GraphicsAllocation *allocateMemoryByKMD(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
|
|
|
|
2021-07-14 16:51:47 +02:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override;
|
2021-08-20 03:56:09 +02:00
|
|
|
MOCKABLE_VIRTUAL GraphicsAllocation *allocateSystemMemoryAndCreateGraphicsAllocationFromIt(const AllocationData &allocationData);
|
|
|
|
|
MOCKABLE_VIRTUAL GraphicsAllocation *allocateGraphicsMemoryUsingKmdAndMapItToCpuVA(const AllocationData &allocationData, bool allowLargePages);
|
2021-07-14 16:51:47 +02: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-07-14 16:51:47 +02:00
|
|
|
MOCKABLE_VIRTUAL size_t getHugeGfxMemoryChunkSize(GfxMemoryAllocationMethod allocationMethod) const;
|
2021-07-27 17:02:31 +00:00
|
|
|
MOCKABLE_VIRTUAL GraphicsAllocation *allocateHugeGraphicsMemory(const AllocationData &allocationData, bool sharedVirtualAddress);
|
2020-04-21 13:16:45 +02:00
|
|
|
|
2022-02-04 13:59:01 +00:00
|
|
|
GraphicsAllocation *createAllocationFromHandle(osHandle handle, bool requireSpecificBitness, bool ntHandle, AllocationType allocationType, uint32_t rootDeviceIndex);
|
2017-12-21 00:45:38 +01:00
|
|
|
static bool validateAllocation(WddmAllocation *alloc);
|
2021-08-11 10:36:04 +00:00
|
|
|
MOCKABLE_VIRTUAL bool createWddmAllocation(WddmAllocation *allocation, void *requiredGpuPtr);
|
2022-11-25 07:39:47 +01:00
|
|
|
bool mapGpuVirtualAddress(WddmAllocation *graphicsAllocation, const void *requiredGpuPtr);
|
2019-06-04 10:33:40 +02:00
|
|
|
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
|