From bb16734a43c50dc6acd8a23712bf5df72f0959fe Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 9 Feb 2022 04:36:50 +0100 Subject: [PATCH] [d3d11] Implement sequence number tracking on deferred contexts --- src/d3d11/d3d11_cmdlist.cpp | 49 +++++++++++++++++++++++++++++++++ src/d3d11/d3d11_cmdlist.h | 14 ++++++++-- src/d3d11/d3d11_context_def.cpp | 8 ++++-- 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/src/d3d11/d3d11_cmdlist.cpp b/src/d3d11/d3d11_cmdlist.cpp index 1dadcbe2..b2e2fe78 100644 --- a/src/d3d11/d3d11_cmdlist.cpp +++ b/src/d3d11/d3d11_cmdlist.cpp @@ -1,5 +1,7 @@ #include "d3d11_cmdlist.h" #include "d3d11_device.h" +#include "d3d11_buffer.h" +#include "d3d11_texture.h" namespace dxvk { @@ -58,6 +60,9 @@ namespace dxvk { for (const auto& query : m_queries) cmdList->m_queries.push_back(query); + for (const auto& resource : m_resources) + cmdList->m_resources.push_back(resource); + MarkSubmitted(); } @@ -71,11 +76,55 @@ namespace dxvk { for (const auto& chunk : m_chunks) seq = CsThread->dispatchChunk(DxvkCsChunkRef(chunk)); + for (const auto& resource : m_resources) + TrackResourceSequenceNumber(resource, seq); + MarkSubmitted(); return seq; } + void D3D11CommandList::TrackResourceUsage( + ID3D11Resource* pResource, + D3D11_RESOURCE_DIMENSION ResourceType, + UINT Subresource) { + m_resources.emplace_back(pResource, ResourceType, Subresource); + } + + + void D3D11CommandList::TrackResourceSequenceNumber( + const D3D11ResourceRef& Resource, + uint64_t Seq) { + ID3D11Resource* iface = Resource.Get(); + UINT subresource = Resource.GetSubresource(); + + switch (Resource.GetType()) { + case D3D11_RESOURCE_DIMENSION_UNKNOWN: + break; + + case D3D11_RESOURCE_DIMENSION_BUFFER: { + auto impl = static_cast(iface); + impl->TrackSequenceNumber(Seq); + } break; + + case D3D11_RESOURCE_DIMENSION_TEXTURE1D: { + auto impl = static_cast(iface)->GetCommonTexture(); + impl->TrackSequenceNumber(subresource, Seq); + } break; + + case D3D11_RESOURCE_DIMENSION_TEXTURE2D: { + auto impl = static_cast(iface)->GetCommonTexture(); + impl->TrackSequenceNumber(subresource, Seq); + } break; + + case D3D11_RESOURCE_DIMENSION_TEXTURE3D: { + auto impl = static_cast(iface)->GetCommonTexture(); + impl->TrackSequenceNumber(subresource, Seq); + } break; + } + } + + void D3D11CommandList::MarkSubmitted() { if (m_submitted.exchange(true) && !m_warned.exchange(true) && m_parent->GetOptions()->dcSingleUseMode) { diff --git a/src/d3d11/d3d11_cmdlist.h b/src/d3d11/d3d11_cmdlist.h index 2b942a13..8be313ad 100644 --- a/src/d3d11/d3d11_cmdlist.h +++ b/src/d3d11/d3d11_cmdlist.h @@ -31,17 +31,27 @@ namespace dxvk { uint64_t EmitToCsThread( DxvkCsThread* CsThread); - + + void TrackResourceUsage( + ID3D11Resource* pResource, + D3D11_RESOURCE_DIMENSION ResourceType, + UINT Subresource); + private: - + UINT const m_contextFlags; std::vector m_chunks; std::vector> m_queries; + std::vector m_resources; std::atomic m_submitted = { false }; std::atomic m_warned = { false }; + void TrackResourceSequenceNumber( + const D3D11ResourceRef& Resource, + uint64_t Seq); + void MarkSubmitted(); }; diff --git a/src/d3d11/d3d11_context_def.cpp b/src/d3d11/d3d11_context_def.cpp index ff5c4ac5..01766066 100644 --- a/src/d3d11/d3d11_context_def.cpp +++ b/src/d3d11/d3d11_context_def.cpp @@ -423,13 +423,17 @@ namespace dxvk { void D3D11DeferredContext::TrackTextureSequenceNumber( D3D11CommonTexture* pResource, UINT Subresource) { - // TODO implement + m_commandList->TrackResourceUsage( + pResource->GetInterface(), + pResource->GetDimension(), + Subresource); } void D3D11DeferredContext::TrackBufferSequenceNumber( D3D11Buffer* pResource) { - // TODO implement + m_commandList->TrackResourceUsage( + pResource, D3D11_RESOURCE_DIMENSION_BUFFER, 0); }