Skip to content

Commit

Permalink
Merge pull request #41 from microsoft/perf
Browse files Browse the repository at this point in the history
Update for residency re-work
  • Loading branch information
jenatali authored Dec 12, 2022
2 parents 2336d4e + 94f2509 commit d5d2132
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ endif()
FetchContent_Declare(
d3d12translationlayer
GIT_REPOSITORY https://github.com/microsoft/D3D12TranslationLayer.git
GIT_TAG 4e12116d7f6e81e76c20e5afb66417bcd69c16c5
GIT_TAG 5277e2b2994bb475a709033a77bcc7a239def943
)
FetchContent_MakeAvailable(d3d12translationlayer)

Expand Down
15 changes: 7 additions & 8 deletions src/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1134,24 +1134,23 @@ namespace D3D11On12
STDMETHODIMP Device::AddResourceWaitsToQueue(_In_ ID3D11On12DDIResource* p11on12DDIResource, _In_ ID3D12CommandQueue* pCommmandQueue) noexcept
{
auto* pResource = static_cast<Resource*>(p11on12DDIResource)->ImmediateResource();
D3DX12Residency::ManagedObject* pResidencyHandle = pResource->GetResidencyHandle();
D3D12TranslationLayer::ManagedObject* pResidencyHandle = pResource->GetResidencyHandle();

D3D12TranslationLayer::ImmediateContext& ImmCtx = FlushBatchAndGetImmediateContext();

if (ImmCtx.IsResidencyManagementEnabled() && pResidencyHandle)
if (pResidencyHandle)
{
// Pin the resource while it is checked out to the caller.
pResidencyHandle->Pin();

// Ensure that the resource is resident after the waits on the callers queue are satisfied.
std::unique_ptr<D3DX12Residency::ResidencySet> pResidencySet = std::unique_ptr<D3DX12Residency::ResidencySet>(
ImmCtx.GetResidencyManager().CreateResidencySet());
auto pResidencySet = std::make_unique<D3D12TranslationLayer::ResidencySet>();

pResidencySet->Open();
pResidencySet->Open((UINT)D3D12TranslationLayer::COMMAND_LIST_TYPE::MAX_VALID);
pResidencySet->Insert(pResidencyHandle);
pResidencySet->Close();

ImmCtx.GetResidencyManager().SubmitCommandQueueCommand(pCommmandQueue, []() {}, pResidencySet.get());
ImmCtx.GetResidencyManager().SubmitCommandQueueCommand(pCommmandQueue, UINT_MAX, pResidencySet.get(), []() {});

// Add a deferred wait for the residency operation. This operation is signaled on the callers queue.
// This handles the case where caller decides to return the resource without scheduling dependent work
Expand Down Expand Up @@ -1184,7 +1183,7 @@ namespace D3D11On12
try
{
auto* pResource = static_cast<Resource*>(p11on12DDIResource)->ImmediateResource();
D3DX12Residency::ManagedObject* pResidencyHandle = pResource->GetResidencyHandle();
D3D12TranslationLayer::ManagedObject* pResidencyHandle = pResource->GetResidencyHandle();

std::vector<D3D12TranslationLayer::DeferredWait> DeferredWaits;
DeferredWaits.reserve(NumSync); // throw( bad_alloc )
Expand All @@ -1203,7 +1202,7 @@ namespace D3D11On12

pResource->AddDeferredWaits(DeferredWaits);

if (ImmCtx.IsResidencyManagementEnabled() && pResidencyHandle)
if (pResidencyHandle)
{
// Transition from an explicit pin to a pin until these waits are satisfied.
pResidencyHandle->AddPinWaits(NumSync, pSignalValues, ppFences);
Expand Down
5 changes: 1 addition & 4 deletions src/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,7 @@ namespace D3D11On12
createArgs.m_heapDesc.Flags |= D3D12_HEAP_FLAG_ALLOW_DISPLAY;
}

if (pDevice->GetImmediateContextNoFlush().IsResidencyManagementEnabled())
{
createArgs.m_heapDesc.Flags |= D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT;
}
createArgs.m_heapDesc.Flags |= D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT;

switch (pCreateResource->ResourceDimension)
{
Expand Down

0 comments on commit d5d2132

Please sign in to comment.