2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2018-09-18 09:11:08 +02:00
|
|
|
* Copyright (C) 2017-2018 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
|
|
|
|
|
#include "runtime/helpers/aligned_memory.h"
|
|
|
|
|
#include "runtime/memory_manager/memory_manager.h"
|
2018-08-27 15:48:29 +02:00
|
|
|
#include "runtime/os_interface/os_context.h"
|
2017-12-21 00:45:38 +01: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 15:48:29 +02:00
|
|
|
using OsContextWin = OsContext::OsContextImpl;
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
class WddmMemoryManager : public MemoryManager {
|
|
|
|
|
public:
|
|
|
|
|
using MemoryManager::allocateGraphicsMemory;
|
|
|
|
|
using MemoryManager::createGraphicsAllocationFromSharedHandle;
|
|
|
|
|
|
|
|
|
|
~WddmMemoryManager();
|
2018-10-01 16:10:54 +02:00
|
|
|
WddmMemoryManager(bool enable64kbPages, bool enableLocalMemory, Wddm *wddm, 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;
|
2018-07-22 19:27:33 +02:00
|
|
|
GraphicsAllocation *allocateGraphicsMemory64kb(size_t size, size_t alignment, bool forcePin, bool preferRenderCompressed) override;
|
2018-01-04 17:48:46 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemory(size_t size, size_t alignment, bool forcePin, bool uncacheable) override;
|
2017-12-21 00:45:38 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemory(size_t size, const void *ptr) override;
|
2018-08-24 15:23:45 +02:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(size_t size, void *cpuPtr) override;
|
2018-07-09 14:12:32 +02:00
|
|
|
GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, AllocationOrigin allocationOrigin) override;
|
2018-08-29 14:50:36 +02:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromSharedHandle(osHandle handle, bool requireSpecificBitness) override;
|
2017-12-21 00:45:38 +01:00
|
|
|
GraphicsAllocation *createGraphicsAllocationFromNTHandle(void *handle) override;
|
|
|
|
|
GraphicsAllocation *allocateGraphicsMemoryForImage(ImageInfo &imgInfo, Gmm *gmm) override;
|
2018-07-18 09:48:21 +02:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override;
|
|
|
|
|
|
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
|
|
|
void *lockResource(GraphicsAllocation *graphicsAllocation) override;
|
|
|
|
|
void unlockResource(GraphicsAllocation *graphicsAllocation) override;
|
|
|
|
|
|
2018-02-28 12:09:48 +01:00
|
|
|
AllocationStatus populateOsHandles(OsHandleStorage &handleStorage) override;
|
2017-12-21 00:45:38 +01:00
|
|
|
void cleanOsHandles(OsHandleStorage &handleStorage) override;
|
|
|
|
|
|
2018-10-04 00:52:51 +02:00
|
|
|
OsContext *getRegisteredOsContext(uint32_t osContextId) { return registeredOsContexts[osContextId]; }
|
2018-09-26 13:19:20 +02:00
|
|
|
|
2018-06-21 11:42:03 +02:00
|
|
|
void obtainGpuAddresFromFragments(WddmAllocation *allocation, OsHandleStorage &handleStorage);
|
|
|
|
|
|
2017-12-21 00:45:38 +01: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 15:24:46 +01:00
|
|
|
uint64_t getInternalHeapBaseAddress() override;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2018-09-06 17:58:32 +02:00
|
|
|
bool tryDeferDeletions(D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle);
|
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-25 15:10:07 +01:00
|
|
|
bool mapAuxGpuVA(GraphicsAllocation *graphicsAllocation) override;
|
|
|
|
|
|
2018-01-22 16:43:26 +01:00
|
|
|
AlignedMallocRestrictions *getAlignedMallocRestrictions() override;
|
|
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
protected:
|
2018-10-15 17:12:55 +02:00
|
|
|
GraphicsAllocation *createAllocationFromHandle(osHandle handle, bool requireSpecificBitness, bool ntHandle);
|
2017-12-21 00:45:38 +01:00
|
|
|
static bool validateAllocation(WddmAllocation *alloc);
|
2018-05-11 17:24:00 +02:00
|
|
|
bool createWddmAllocation(WddmAllocation *allocation, AllocationOrigin origin);
|
2018-01-22 16:43:26 +01:00
|
|
|
AlignedMallocRestrictions mallocRestrictions;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Wddm *wddm;
|
|
|
|
|
};
|
|
|
|
|
} // namespace OCLRT
|