2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2018-09-18 15:11:08 +08:00
|
|
|
* Copyright (C) 2017-2018 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"
|
|
|
|
#include <d3dkmthk.h>
|
|
|
|
#include <map>
|
|
|
|
#include <mutex>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
namespace OCLRT {
|
|
|
|
class Gmm;
|
|
|
|
class Wddm;
|
|
|
|
|
2018-08-27 21:48:29 +08:00
|
|
|
using OsContextWin = OsContext::OsContextImpl;
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
class WddmMemoryManager : public MemoryManager {
|
|
|
|
public:
|
|
|
|
using MemoryManager::allocateGraphicsMemory;
|
|
|
|
using MemoryManager::createGraphicsAllocationFromSharedHandle;
|
|
|
|
|
|
|
|
~WddmMemoryManager();
|
2018-10-01 22:10:54 +08:00
|
|
|
WddmMemoryManager(bool enable64kbPages, bool enableLocalMemory, Wddm *wddm, 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;
|
2018-07-23 01:27:33 +08:00
|
|
|
GraphicsAllocation *allocateGraphicsMemory64kb(size_t size, size_t alignment, bool forcePin, bool preferRenderCompressed) override;
|
2018-01-05 00:48:46 +08:00
|
|
|
GraphicsAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) override;
|
2017-12-21 07:45:38 +08:00
|
|
|
GraphicsAllocation *allocateGraphicsMemory(size_t size, const void *ptr) override;
|
2018-08-24 21:23:45 +08:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(size_t size, void *cpuPtr) override;
|
2018-07-09 20:12:32 +08:00
|
|
|
GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin) override;
|
2018-08-29 20:50:36 +08:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override;
|
2017-12-21 07:45:38 +08:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) override;
|
|
|
|
GraphicsAllocation *allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) override;
|
2018-07-18 15:48:21 +08:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override;
|
|
|
|
|
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
|
|
|
void *lockResource(GraphicsAllocation *graphicsAllocation) override;
|
|
|
|
void unlockResource(GraphicsAllocation *graphicsAllocation) override;
|
|
|
|
|
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;
|
|
|
|
|
2018-10-04 06:52:51 +08:00
|
|
|
OsContext *getRegisteredOsContext(uint32_t osContextId) { return registeredOsContexts[osContextId]; }
|
2018-09-26 19:19:20 +08:00
|
|
|
|
2018-06-21 17:42:03 +08:00
|
|
|
void obtainGpuAddresFromFragments(WddmAllocation *allocation, OsHandleStorage &handleStorage);
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) override;
|
|
|
|
|
|
|
|
static const D3DGPU_VIRTUAL_ADDRESS minimumAddress = static_cast<D3DGPU_VIRTUAL_ADDRESS>(0x0);
|
|
|
|
static const D3DGPU_VIRTUAL_ADDRESS maximumAddress = static_cast<D3DGPU_VIRTUAL_ADDRESS>((sizeof(size_t) == 8) ? 0x7ffffffffff : (D3DGPU_VIRTUAL_ADDRESS)0xffffffff);
|
|
|
|
|
|
|
|
uint64_t getSystemSharedMemory() override;
|
|
|
|
uint64_t getMaxApplicationAddress() override;
|
2018-03-12 22:24:46 +08:00
|
|
|
uint64_t getInternalHeapBaseAddress() override;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2018-09-06 23:58:32 +08:00
|
|
|
bool tryDeferDeletions(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;
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
protected:
|
2018-10-15 23:12:55 +08:00
|
|
|
GraphicsAllocation *createAllocationFromHandle(osHandle handle, bool requireSpecificBitness, bool ntHandle);
|
2017-12-21 07:45:38 +08:00
|
|
|
static bool validateAllocation(WddmAllocation *alloc);
|
2018-05-11 23:24:00 +08:00
|
|
|
bool createWddmAllocation(WddmAllocation *allocation, AllocationOrigin origin);
|
2018-01-22 23:43:26 +08:00
|
|
|
AlignedMallocRestrictions mallocRestrictions;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
Wddm *wddm;
|
|
|
|
};
|
|
|
|
} // namespace OCLRT
|