2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2019-01-10 11:10:58 +01:00
|
|
|
* Copyright (C) 2017-2019 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"
|
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>
|
|
|
|
|
|
|
|
|
|
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:
|
2019-02-20 11:18:24 +01:00
|
|
|
~WddmMemoryManager() override;
|
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-12-17 11:49:17 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemory(const AllocationProperties &properties, const void *ptr) override;
|
2018-08-24 15:23:45 +02:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(size_t size, void *cpuPtr) 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;
|
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
|
|
|
|
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;
|
|
|
|
|
|
2019-01-10 11:10:58 +01:00
|
|
|
void obtainGpuAddressFromFragments(WddmAllocation *allocation, OsHandleStorage &handleStorage);
|
2018-06-21 11:42:03 +02:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
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:
|
2019-02-25 14:11:34 +01:00
|
|
|
GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) override;
|
2018-11-30 11:01:33 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override;
|
2018-12-06 15:03:06 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemory64kb(AllocationData allocationData) override;
|
2019-01-22 12:40:17 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryForImageImpl(const AllocationData &allocationData, std::unique_ptr<Gmm> gmm) override;
|
2018-11-30 11:01:33 +01:00
|
|
|
|
2019-01-24 11:51:33 +01:00
|
|
|
void *lockResourceImpl(GraphicsAllocation &graphicsAllocation) override;
|
|
|
|
|
void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) override;
|
2018-12-21 10:16:27 +01:00
|
|
|
GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) override;
|
|
|
|
|
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override;
|
2019-01-24 11:51:33 +01:00
|
|
|
|
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);
|
2019-02-13 10:44:19 +01:00
|
|
|
bool createWddmAllocation(WddmAllocation *allocation);
|
2018-01-22 16:43:26 +01:00
|
|
|
AlignedMallocRestrictions mallocRestrictions;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Wddm *wddm;
|
|
|
|
|
};
|
|
|
|
|
} // namespace OCLRT
|