Track resources to flush in deferring dynamic descriptor updates

* During the frame we don't update our internal descriptor tracking, we
  just record the updates on the CPU timeline.
* However, it's possible that one of those copies or writes references a
  resource that is persistently mapped, so we need to know about that so
  we can flush it at the next execute.
This commit is contained in:
baldurk
2016-10-30 14:00:31 +01:00
parent 21b4f94379
commit 8852b5f739
4 changed files with 45 additions and 0 deletions
@@ -441,6 +441,32 @@ void STDMETHODCALLTYPE WrappedID3D12CommandQueue::ExecuteCommandLists(
if(capframe)
{
// any descriptor copies or writes could reference new resources not in the
// bound descs list yet. So we take all of those referenced descriptors and
// include them to see if we need to flush
std::vector<D3D12Descriptor> dynDescRefs;
m_pDevice->GetDynamicDescriptorReferences(dynDescRefs);
for(size_t i = 0; i < dynDescRefs.size(); i++)
{
ResourceId id, id2;
FrameRefType ref = eFrameRef_Read;
dynDescRefs[i].GetRefIDs(id, id2, ref);
if(id != ResourceId())
{
refdIDs.insert(id);
GetResourceManager()->MarkResourceFrameReferenced(id, ref);
}
if(id2 != ResourceId())
{
refdIDs.insert(id2);
GetResourceManager()->MarkResourceFrameReferenced(id2, ref);
}
}
// for each bound descriptor table, mark it referenced as well as all resources currently
// bound to it
for(auto it = record->bakedCommands->cmdInfo->boundDescs.begin();
+1
View File
@@ -1665,6 +1665,7 @@ void WrappedID3D12Device::FlushPendingDescriptorWrites()
SCOPED_LOCK(m_DynDescLock);
writes.swap(m_DynamicDescriptorWrites);
copies.swap(m_DynamicDescriptorCopies);
m_DynamicDescriptorRefs.clear();
}
for(size_t i = 0; i < writes.size(); i++)
+7
View File
@@ -301,6 +301,7 @@ private:
Threading::CriticalSection m_DynDescLock;
std::vector<DynamicDescriptorCopy> m_DynamicDescriptorCopies;
std::vector<DynamicDescriptorWrite> m_DynamicDescriptorWrites;
std::vector<D3D12Descriptor> m_DynamicDescriptorRefs;
GPUAddressRangeTracker m_GPUAddresses;
@@ -378,6 +379,12 @@ public:
ID3D12CommandAllocator *GetAlloc() { return m_Alloc; }
void ApplyBarriers(vector<D3D12_RESOURCE_BARRIER> &barriers);
void GetDynamicDescriptorReferences(std::vector<D3D12Descriptor> &refs)
{
SCOPED_LOCK(m_DynDescLock);
m_DynamicDescriptorRefs.swap(refs);
}
void GetResIDFromAddr(D3D12_GPU_VIRTUAL_ADDRESS addr, ResourceId &id, UINT64 &offs)
{
m_GPUAddresses.GetResIDFromAddr(addr, id, offs);
@@ -648,6 +648,7 @@ void WrappedID3D12Device::CreateConstantBufferView(const D3D12_CONSTANT_BUFFER_V
{
SCOPED_LOCK(m_DynDescLock);
m_DynamicDescriptorWrites.push_back(write);
m_DynamicDescriptorRefs.push_back(write.desc);
}
{
@@ -691,6 +692,8 @@ void WrappedID3D12Device::CreateShaderResourceView(ID3D12Resource *pResource,
{
SCOPED_LOCK(m_DynDescLock);
m_DynamicDescriptorWrites.push_back(write);
if(pResource && pResource->GetDesc().Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
m_DynamicDescriptorRefs.push_back(write.desc);
}
{
@@ -742,6 +745,8 @@ void WrappedID3D12Device::CreateUnorderedAccessView(ID3D12Resource *pResource,
{
SCOPED_LOCK(m_DynDescLock);
m_DynamicDescriptorWrites.push_back(write);
if(pResource && pResource->GetDesc().Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
m_DynamicDescriptorRefs.push_back(write.desc);
}
{
@@ -787,6 +792,8 @@ void WrappedID3D12Device::CreateRenderTargetView(ID3D12Resource *pResource,
{
SCOPED_LOCK(m_DynDescLock);
m_DynamicDescriptorWrites.push_back(write);
if(pResource && pResource->GetDesc().Dimension == D3D12_RESOURCE_DIMENSION_BUFFER)
m_DynamicDescriptorRefs.push_back(write.desc);
}
{
@@ -1606,6 +1613,8 @@ void WrappedID3D12Device::CopyDescriptors(
{
SCOPED_LOCK(m_DynDescLock);
m_DynamicDescriptorCopies.insert(m_DynamicDescriptorCopies.end(), copies.begin(), copies.end());
for(size_t i = 0; i < copies.size(); i++)
m_DynamicDescriptorRefs.push_back(*copies[i].src);
}
{
@@ -1673,6 +1682,8 @@ void WrappedID3D12Device::CopyDescriptorsSimple(UINT NumDescriptors,
{
SCOPED_LOCK(m_DynDescLock);
m_DynamicDescriptorCopies.insert(m_DynamicDescriptorCopies.end(), copies.begin(), copies.end());
for(size_t i = 0; i < copies.size(); i++)
m_DynamicDescriptorRefs.push_back(*copies[i].src);
}
{