Do not wait on CPU for fence.

- If allocation is passed for destruction it means that it is ready to
be destroyed, there is no need to wait for tag.

Change-Id: I6b85ed62250aca8ee6293956b6178ce19bdb1f30
This commit is contained in:
Mrozek, Michal
2018-09-06 17:58:32 +02:00
committed by sys_ocldev
parent cb2b45625a
commit df41112b6a
11 changed files with 23 additions and 76 deletions

View File

@@ -29,11 +29,9 @@ template <typename... Args>
DeferrableDeletion *DeferrableDeletion::create(Args... args) {
return new DeferrableDeletionImpl(std::forward<Args>(args)...);
}
template DeferrableDeletion *DeferrableDeletion::create(Wddm *wddm, D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue,
D3DKMT_HANDLE resourceHandle, OsContextWin *osContext);
template DeferrableDeletion *DeferrableDeletion::create(Wddm *wddm, D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle);
DeferrableDeletionImpl::DeferrableDeletionImpl(Wddm *wddm, D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue,
D3DKMT_HANDLE resourceHandle, OsContextWin *osContext) : osContext(osContext) {
DeferrableDeletionImpl::DeferrableDeletionImpl(Wddm *wddm, D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle) {
this->wddm = wddm;
if (handles) {
this->handles = new D3DKMT_HANDLE[allocationCount];
@@ -42,11 +40,10 @@ DeferrableDeletionImpl::DeferrableDeletionImpl(Wddm *wddm, D3DKMT_HANDLE *handle
}
}
this->allocationCount = allocationCount;
this->lastFenceValue = lastFenceValue;
this->resourceHandle = resourceHandle;
}
void DeferrableDeletionImpl::apply() {
bool destroyStatus = wddm->destroyAllocations(handles, allocationCount, lastFenceValue, resourceHandle, osContext);
bool destroyStatus = wddm->destroyAllocations(handles, allocationCount, resourceHandle);
DEBUG_BREAK_IF(!destroyStatus);
}
DeferrableDeletionImpl::~DeferrableDeletionImpl() {

View File

@@ -34,8 +34,7 @@ using OsContextWin = OsContext::OsContextImpl;
class DeferrableDeletionImpl : public DeferrableDeletion {
public:
DeferrableDeletionImpl(Wddm *wddm, D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue,
D3DKMT_HANDLE resourceHandle, OsContextWin *osContext);
DeferrableDeletionImpl(Wddm *wddm, D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle);
void apply() override;
~DeferrableDeletionImpl();
@@ -46,8 +45,6 @@ class DeferrableDeletionImpl : public DeferrableDeletion {
Wddm *wddm;
D3DKMT_HANDLE *handles = nullptr;
uint32_t allocationCount;
uint64_t lastFenceValue;
D3DKMT_HANDLE resourceHandle;
OsContextWin *osContext = nullptr;
};
} // namespace OCLRT

View File

@@ -549,13 +549,10 @@ NTSTATUS Wddm::createAllocationsAndMapGpuVa(OsHandleStorage &osHandles) {
return status;
}
bool Wddm::destroyAllocations(D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, D3DKMT_HANDLE resourceHandle, OsContextWin *osContext) {
bool Wddm::destroyAllocations(D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle) {
NTSTATUS status = STATUS_SUCCESS;
D3DKMT_DESTROYALLOCATION2 DestroyAllocation = {0};
DEBUG_BREAK_IF(!(allocationCount <= 1 || resourceHandle == 0));
if (lastFenceValue > 0) {
waitFromCpu(lastFenceValue, *osContext);
}
DestroyAllocation.hDevice = device;
DestroyAllocation.hResource = resourceHandle;

View File

@@ -78,7 +78,7 @@ class Wddm {
MOCKABLE_VIRTUAL NTSTATUS createAllocation(WddmAllocation *alloc);
MOCKABLE_VIRTUAL bool createAllocation64k(WddmAllocation *alloc);
MOCKABLE_VIRTUAL NTSTATUS createAllocationsAndMapGpuVa(OsHandleStorage &osHandles);
MOCKABLE_VIRTUAL bool destroyAllocations(D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, D3DKMT_HANDLE resourceHandle, OsContextWin *osContext);
MOCKABLE_VIRTUAL bool destroyAllocations(D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle);
MOCKABLE_VIRTUAL bool openSharedHandle(D3DKMT_HANDLE handle, WddmAllocation *alloc);
bool openNTHandle(HANDLE handle, WddmAllocation *alloc);
MOCKABLE_VIRTUAL void *lockResource(WddmAllocation *wddmAllocation);

View File

@@ -350,7 +350,7 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation
if (input->getResidencyData().osContext) {
osContextWin = input->getResidencyData().osContext->get();
}
auto status = tryDeferDeletions(allocationHandles, allocationCount, input->getResidencyData().lastFence, resourceHandle, osContextWin);
auto status = tryDeferDeletions(allocationHandles, allocationCount, resourceHandle);
DEBUG_BREAK_IF(!status);
alignedFreeWrapper(cpuPtr);
}
@@ -358,12 +358,12 @@ void WddmMemoryManager::freeGraphicsMemoryImpl(GraphicsAllocation *gfxAllocation
delete gfxAllocation;
}
bool WddmMemoryManager::tryDeferDeletions(D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, D3DKMT_HANDLE resourceHandle, OsContextWin *osContext) {
bool WddmMemoryManager::tryDeferDeletions(D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle) {
bool status = true;
if (deferredDeleter) {
deferredDeleter->deferDeletion(DeferrableDeletion::create(wddm, handles, allocationCount, lastFenceValue, resourceHandle, osContext));
deferredDeleter->deferDeletion(DeferrableDeletion::create(wddm, handles, allocationCount, resourceHandle));
} else {
status = wddm->destroyAllocations(handles, allocationCount, lastFenceValue, resourceHandle, osContext);
status = wddm->destroyAllocations(handles, allocationCount, resourceHandle);
}
return status;
}
@@ -427,7 +427,7 @@ void WddmMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage) {
if (osContext) {
osContextWin = osContext->get();
}
bool success = tryDeferDeletions(handles, allocationCount, lastFenceValue, 0, osContextWin);
bool success = tryDeferDeletions(handles, allocationCount, 0);
for (unsigned int i = 0; i < max_fragments_count; i++) {
if (handleStorage.fragmentStorageData[i].freeTheFragment) {
@@ -862,7 +862,7 @@ bool WddmMemoryManager::createWddmAllocation(WddmAllocation *allocation, Allocat
mapSuccess = wddm->mapGpuVirtualAddress(allocation, allocation->getAlignedCpuPtr(), allocation->is32BitAllocation, false, useHeap1);
}
if (!mapSuccess) {
wddm->destroyAllocations(&allocation->handle, 1, 0, allocation->resourceHandle, nullptr);
wddm->destroyAllocations(&allocation->handle, 1, allocation->resourceHandle);
wddmSuccess = STATUS_UNSUCCESSFUL;
}
allocation->setGpuAddress(allocation->gpuPtr);

View File

@@ -93,7 +93,7 @@ class WddmMemoryManager : public MemoryManager {
residencyLock = false;
}
bool tryDeferDeletions(D3DKMT_HANDLE *handles, uint32_t allocationCount, uint64_t lastFenceValue, D3DKMT_HANDLE resourceHandle, OsContextWin *osContext);
bool tryDeferDeletions(D3DKMT_HANDLE *handles, uint32_t allocationCount, D3DKMT_HANDLE resourceHandle);
bool isMemoryBudgetExhausted() const override { return memoryBudgetExhausted; }