diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-01-03 06:55:54 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-01-03 06:55:54 +0000 |
| commit | f55a5ff022cffd85c497e29a32bb4603b4897e01 (patch) | |
| tree | 1b0d25c17c133c07b31a84ff6a9143dee9f68095 /Graphics/GraphicsEngineD3D12 | |
| parent | Fixed few MacOS build issues (diff) | |
| download | DiligentCore-f55a5ff022cffd85c497e29a32bb4603b4897e01.tar.gz DiligentCore-f55a5ff022cffd85c497e29a32bb4603b4897e01.zip | |
A bunch of minor updated to D3D12 queries
Diffstat (limited to 'Graphics/GraphicsEngineD3D12')
| -rw-r--r-- | Graphics/GraphicsEngineD3D12/include/QueryManager.h | 3 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineD3D12/src/QueryD3D12Impl.cpp | 5 | ||||
| -rw-r--r-- | Graphics/GraphicsEngineD3D12/src/QueryManager.cpp | 7 |
3 files changed, 14 insertions, 1 deletions
diff --git a/Graphics/GraphicsEngineD3D12/include/QueryManager.h b/Graphics/GraphicsEngineD3D12/include/QueryManager.h index a3e37645..fc8044f9 100644 --- a/Graphics/GraphicsEngineD3D12/include/QueryManager.h +++ b/Graphics/GraphicsEngineD3D12/include/QueryManager.h @@ -39,6 +39,8 @@ namespace Diligent class CommandContext; +// https://microsoft.github.io/DirectX-Specs/d3d/CountersAndQueries.html#queries + class QueryManager { public: @@ -79,6 +81,7 @@ private: std::mutex m_HeapMutex; std::array<QueryHeapInfo, QUERY_TYPE_NUM_TYPES> m_Heaps; + // Readback buffer that will contain the query data. CComPtr<ID3D12Resource> m_pd3d12ResolveBuffer; }; diff --git a/Graphics/GraphicsEngineD3D12/src/QueryD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/QueryD3D12Impl.cpp index 073f839a..1e102bd5 100644 --- a/Graphics/GraphicsEngineD3D12/src/QueryD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/QueryD3D12Impl.cpp @@ -90,7 +90,9 @@ bool QueryD3D12Impl::GetData(void* pData, Uint32 DataSize) { UINT64 AnySamplePassed; QueryMgr.ReadQueryData(m_Desc.Type, m_QueryHeapIndex, &AnySamplePassed, sizeof(AnySamplePassed)); - auto& QueryData = *reinterpret_cast<QueryDataBinaryOcclusion*>(pData); + auto& QueryData = *reinterpret_cast<QueryDataBinaryOcclusion*>(pData); + // Binary occlusion queries write 64-bits per query. The least significant bit is either 0 or 1. The rest of the bits are 0. + // https://microsoft.github.io/DirectX-Specs/d3d/CountersAndQueries.html#resolvequerydata QueryData.AnySamplePassed = AnySamplePassed != 0; } break; @@ -105,6 +107,7 @@ bool QueryD3D12Impl::GetData(void* pData, Uint32 DataSize) const auto& CmdQueue = m_pDevice->GetCommandQueue(CmdQueueId); auto* pd3d12Queue = const_cast<ICommandQueueD3D12&>(CmdQueue).GetD3D12CommandQueue(); + // https://microsoft.github.io/DirectX-Specs/d3d/CountersAndQueries.html#timestamp-frequency UINT64 TimestampFrequency = 0; pd3d12Queue->GetTimestampFrequency(&TimestampFrequency); QueryData.Frequency = TimestampFrequency; diff --git a/Graphics/GraphicsEngineD3D12/src/QueryManager.cpp b/Graphics/GraphicsEngineD3D12/src/QueryManager.cpp index 00a37076..6474383c 100644 --- a/Graphics/GraphicsEngineD3D12/src/QueryManager.cpp +++ b/Graphics/GraphicsEngineD3D12/src/QueryManager.cpp @@ -80,6 +80,8 @@ QueryManager::QueryManager(ID3D12Device* pd3d12Device, auto hr = pd3d12Device->CreateQueryHeap(&d3d12HeapDesc, __uuidof(HeapInfo.pd3d12QueryHeap), reinterpret_cast<void**>(&HeapInfo.pd3d12QueryHeap)); CHECK_D3D_RESULT_THROW(hr, "Failed to create D3D12 query heap of type"); + // AlignedDestinationBufferOffset must be a multiple of 8 bytes. + // https://microsoft.github.io/DirectX-Specs/d3d/CountersAndQueries.html#resolvequerydata Uint32 AlignedQueryDataSize = Align(GetQueryDataSize(static_cast<QUERY_TYPE>(QueryType)), Uint32{8}); HeapInfo.AvailableQueries.resize(HeapInfo.HeapSize); HeapInfo.ResolveBufferOffsets.resize(HeapInfo.HeapSize); @@ -113,6 +115,9 @@ QueryManager::QueryManager(ID3D12Device* pd3d12Device, HeapProps.CreationNodeMask = 1; HeapProps.VisibleNodeMask = 1; + // The destination buffer of a query resolve operation must be in the D3D12_RESOURCE_USAGE_COPY_DEST state. + // ResolveQueryData works with all heap types (default, upload, readback). + // https://microsoft.github.io/DirectX-Specs/d3d/CountersAndQueries.html#resolvequerydata auto hr = pd3d12Device->CreateCommittedResource(&HeapProps, D3D12_HEAP_FLAG_NONE, &D3D12BuffDesc, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, __uuidof(m_pd3d12ResolveBuffer), @@ -185,6 +190,8 @@ void QueryManager::EndQuery(CommandContext& Ctx, QUERY_TYPE Type, Uint32 Index) auto d3d12QueryType = QueryTypeToD3D12QueryType(Type); auto& HeapInfo = m_Heaps[Type]; Ctx.EndQuery(HeapInfo.pd3d12QueryHeap, d3d12QueryType, Index); + + // https://microsoft.github.io/DirectX-Specs/d3d/CountersAndQueries.html#resolvequerydata Ctx.ResolveQueryData(HeapInfo.pd3d12QueryHeap, d3d12QueryType, Index, 1, m_pd3d12ResolveBuffer, HeapInfo.ResolveBufferOffsets[Index]); } |
