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;
|
2019-02-27 11:17:17 +01:00
|
|
|
class OsContextWin;
|
2017-12-21 00:45:38 +01:00
|
|
|
class Wddm;
|
|
|
|
|
|
|
|
|
|
class WddmMemoryManager : public MemoryManager {
|
|
|
|
|
public:
|
2019-03-12 12:00:41 +01:00
|
|
|
using MemoryManager::allocateGraphicsMemoryWithProperties;
|
|
|
|
|
|
2019-02-20 11:18:24 +01:00
|
|
|
~WddmMemoryManager() override;
|
2019-03-21 17:45:00 +01:00
|
|
|
WddmMemoryManager(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;
|
2019-03-04 14:50:26 +01:00
|
|
|
void handleFenceCompletion(GraphicsAllocation *allocation) override;
|
|
|
|
|
|
2019-03-12 12:00:41 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryWithProperties(const AllocationProperties &properties, const void *ptr) 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
|
|
|
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
|
|
|
|
2019-03-05 14:21:57 +01:00
|
|
|
bool tryDeferDeletions(const 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;
|
|
|
|
|
|
2019-03-01 14:25:33 +01:00
|
|
|
bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, uint32_t sizeToCopy) const override;
|
2019-03-13 15:31:46 +01:00
|
|
|
void *reserveCpuAddressRange(size_t size) override;
|
|
|
|
|
void releaseReservedCpuAddressRange(void *reserved, size_t size) override;
|
2019-03-01 14:25:33 +01:00
|
|
|
|
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;
|
2019-03-12 12:00:41 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &allocationData) override;
|
2018-11-30 11:01:33 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override;
|
2019-02-28 14:12:13 +01:00
|
|
|
GraphicsAllocation *allocateGraphicsMemory64kb(const 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;
|
2019-03-11 10:19:02 +01:00
|
|
|
void freeAssociatedResourceImpl(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-03-14 15:23:09 +01:00
|
|
|
bool createWddmAllocation(WddmAllocation *allocation, void *requiredGpuPtr);
|
2019-03-14 08:32:56 +01:00
|
|
|
bool mapGpuVirtualAddressWithRetry(WddmAllocation *graphicsAllocation, const void *preferredGpuVirtualAddress);
|
|
|
|
|
uint32_t mapGpuVirtualAddress(WddmAllocation *graphicsAllocation, const void *preferredGpuVirtualAddress, uint32_t startingIndex);
|
2019-03-07 15:14:11 +01:00
|
|
|
bool createGpuAllocationsWithRetry(WddmAllocation *graphicsAllocation);
|
|
|
|
|
void obtainGpuAddressIfNeeded(WddmAllocation *graphicsAllocation);
|
2018-01-22 16:43:26 +01:00
|
|
|
AlignedMallocRestrictions mallocRestrictions;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Wddm *wddm;
|
|
|
|
|
};
|
|
|
|
|
} // namespace OCLRT
|