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