2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2019-01-10 18:10:58 +08:00
|
|
|
* Copyright (C) 2017-2019 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
|
|
|
|
#include "runtime/helpers/aligned_memory.h"
|
|
|
|
#include "runtime/memory_manager/memory_manager.h"
|
2018-08-27 21:48:29 +08:00
|
|
|
#include "runtime/os_interface/os_context.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "runtime/os_interface/windows/wddm_allocation.h"
|
|
|
|
#include "runtime/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;
|
2017-12-21 07:45:38 +08:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) 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
|
|
|
|
2018-02-28 19:09:48 +08:00
|
|
|
AllocationStatus populateOsHandles(OsHandleStorage &handleStorage) override;
|
2017-12-21 07:45:38 +08:00
|
|
|
void cleanOsHandles(OsHandleStorage &handleStorage) override;
|
|
|
|
|
2019-01-10 18:10:58 +08:00
|
|
|
void obtainGpuAddressFromFragments(WddmAllocation *allocation, OsHandleStorage &handleStorage);
|
2018-06-21 17:42:03 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
uint64_t getSystemSharedMemory() override;
|
|
|
|
uint64_t getMaxApplicationAddress() override;
|
2019-04-12 21:21:42 +08:00
|
|
|
uint64_t getInternalHeapBaseAddress() override;
|
2019-04-16 17:47:47 +08:00
|
|
|
uint64_t getExternalHeapBaseAddress() override;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-05 21:21:57 +08:00
|
|
|
bool tryDeferDeletions(const D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle);
|
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-25 22:10:07 +08:00
|
|
|
bool mapAuxGpuVA(GraphicsAllocation *graphicsAllocation) override;
|
|
|
|
|
2018-01-22 23:43:26 +08:00
|
|
|
AlignedMallocRestrictions *getAlignedMallocRestrictions() override;
|
|
|
|
|
2019-03-01 21:25:33 +08:00
|
|
|
bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, uint32_t sizeToCopy) const override;
|
2019-03-13 22:31:46 +08:00
|
|
|
void *reserveCpuAddressRange(size_t size) override;
|
|
|
|
void releaseReservedCpuAddressRange(void *reserved, size_t size) override;
|
2019-03-01 21:25:33 +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;
|
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-01-22 19:40:17 +08:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryForImageImpl(const AllocationData &allocationData, std::unique_ptr<Gmm> gmm) override;
|
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;
|
2018-12-21 17:16:27 +08:00
|
|
|
GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) override;
|
|
|
|
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override;
|
2019-01-24 18:51:33 +08:00
|
|
|
|
2019-04-05 17:54:56 +08:00
|
|
|
GraphicsAllocation *createAllocationFromHandle(osHandle handle, bool requireSpecificBitness, bool ntHandle, GraphicsAllocation::AllocationType allocationType);
|
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-03-14 15:32:56 +08:00
|
|
|
bool mapGpuVirtualAddressWithRetry(WddmAllocation *graphicsAllocation, const void *preferredGpuVirtualAddress);
|
|
|
|
uint32_t mapGpuVirtualAddress(WddmAllocation *graphicsAllocation, const void *preferredGpuVirtualAddress, uint32_t startingIndex);
|
2019-03-07 22:14:11 +08:00
|
|
|
bool createGpuAllocationsWithRetry(WddmAllocation *graphicsAllocation);
|
|
|
|
void obtainGpuAddressIfNeeded(WddmAllocation *graphicsAllocation);
|
2018-01-22 23:43:26 +08:00
|
|
|
AlignedMallocRestrictions mallocRestrictions;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
Wddm *wddm;
|
|
|
|
};
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|