fix: Use Gmm to map virtual gpu addresses

Related-To: NEO-5842, NEO-7946

Signed-off-by: Maciej Plewka <maciej.plewka@intel.com>
This commit is contained in:
Maciej Plewka
2023-05-18 16:27:44 +00:00
committed by Compute-Runtime-Automation
parent ab1b4681cc
commit 4b6194cf0c
17 changed files with 209 additions and 8 deletions

View File

@@ -13,6 +13,7 @@
#include "shared/source/execution_environment/root_device_environment.h"
#include "shared/source/gmm_helper/client_context/gmm_client_context.h"
#include "shared/source/gmm_helper/client_context/gmm_handle_allocator.h"
#include "shared/source/gmm_helper/client_context/map_gpu_va_gmm.h"
#include "shared/source/gmm_helper/gmm.h"
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/gmm_helper/page_table_mngr.h"
@@ -536,8 +537,9 @@ bool Wddm::mapGpuVirtualAddress(Gmm *gmm, D3DKMT_HANDLE handle, D3DGPU_VIRTUAL_A
mapGPUVA.MaximumAddress = maximumAddress;
applyAdditionalMapGPUVAFields(mapGPUVA, gmm);
NTSTATUS status = getGdi()->mapGpuVirtualAddress(&mapGPUVA);
auto resourceInfo = gmm->gmmResourceInfo->peekGmmResourceInfo();
MapGpuVirtualAddressGmm gmmMapGpuVa = {&mapGPUVA, &resourceInfo, &gpuPtr, getGdi()};
auto status = gmm->getGmmHelper()->getClientContext()->mapGpuVirtualAddress(&gmmMapGpuVa);
auto gmmHelper = gmm->getGmmHelper();
gpuPtr = gmmHelper->canonize(mapGPUVA.VirtualAddress);
@@ -588,6 +590,14 @@ NTSTATUS Wddm::reserveGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS baseAddress,
return status;
}
uint64_t Wddm::freeGmmGpuVirtualAddress(Gmm *gmm, D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size) {
uint64_t status = STATUS_SUCCESS;
auto resourceInfo = gmm->gmmResourceInfo->peekGmmResourceInfo();
FreeGpuVirtualAddressGmm freeGpuva = {getAdapter(), rootDeviceEnvironment.getGmmHelper()->decanonize(gpuPtr), size, &resourceInfo, getGdi()};
status = gmm->getGmmHelper()->getClientContext()->freeGpuVirtualAddress(&freeGpuva);
return status;
}
bool Wddm::freeGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size) {
NTSTATUS status = STATUS_SUCCESS;
D3DKMT_FREEGPUVIRTUALADDRESS freeGpuva = {};

View File

@@ -70,6 +70,7 @@ class Wddm : public DriverModel {
MOCKABLE_VIRTUAL bool createContext(OsContextWin &osContext);
MOCKABLE_VIRTUAL void applyAdditionalContextFlags(CREATECONTEXT_PVTDATA &privateData, OsContextWin &osContext);
MOCKABLE_VIRTUAL void applyAdditionalMapGPUVAFields(D3DDDI_MAPGPUVIRTUALADDRESS &mapGPUVA, Gmm *gmm);
MOCKABLE_VIRTUAL uint64_t freeGmmGpuVirtualAddress(Gmm *gmm, D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size);
MOCKABLE_VIRTUAL bool freeGpuVirtualAddress(D3DGPU_VIRTUAL_ADDRESS &gpuPtr, uint64_t size);
MOCKABLE_VIRTUAL NTSTATUS createAllocation(const void *alignedCpuPtr, const Gmm *gmm, D3DKMT_HANDLE &outHandle, D3DKMT_HANDLE &outResourceHandle, uint64_t *outSharedHandle);
MOCKABLE_VIRTUAL bool createAllocation(const Gmm *gmm, D3DKMT_HANDLE &outHandle);

View File

@@ -639,7 +639,12 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation
}
}
for (auto handleId = 0u; handleId < gfxAllocation->getNumGmms(); handleId++) {
delete gfxAllocation->getGmm(handleId);
auto gmm = gfxAllocation->getGmm(handleId);
if (gmm) {
auto gpuAddress = input->getGpuAddress();
getWddm(gfxAllocation->getRootDeviceIndex()).freeGmmGpuVirtualAddress(gfxAllocation->getGmm(handleId), gpuAddress, input->getAlignedSize());
}
delete gmm;
}
uint64_t handle = 0;
int ret = input->peekInternalHandle(nullptr, handle);