diff options
| author | assiduous <assiduous@diligentgraphics.com> | 2020-12-03 04:08:06 +0000 |
|---|---|---|
| committer | assiduous <assiduous@diligentgraphics.com> | 2020-12-03 04:08:06 +0000 |
| commit | 57d21b1b34187df0ff1a3d31b85285fa2e21c9e5 (patch) | |
| tree | e48bb2aa8af6f9c01044f7d4a5cf6b479cb067cb /Graphics | |
| parent | Few minor updates to VariableSizeAllocationsManager (diff) | |
| download | DiligentCore-57d21b1b34187df0ff1a3d31b85285fa2e21c9e5.tar.gz DiligentCore-57d21b1b34187df0ff1a3d31b85285fa2e21c9e5.zip | |
Added IDeviceContext::GetFrameNumber() method (API )
Diffstat (limited to 'Graphics')
13 files changed, 35 insertions, 20 deletions
diff --git a/Graphics/GraphicsEngine/include/DeviceContextBase.hpp b/Graphics/GraphicsEngine/include/DeviceContextBase.hpp index ac56eac9..dcc186b5 100644 --- a/Graphics/GraphicsEngine/include/DeviceContextBase.hpp +++ b/Graphics/GraphicsEngine/include/DeviceContextBase.hpp @@ -185,6 +185,11 @@ public: ITexture* pDstTexture, const ResolveTextureSubresourceAttribs& ResolveAttribs) override = 0; + virtual Uint64 DILIGENT_CALL_TYPE GetFrameNumber() const override final + { + return m_FrameNumber; + } + /// Returns currently bound pipeline state and blend factors inline void GetPipelineState(IPipelineState** ppPSO, float* BlendFactors, Uint32& StencilRef); @@ -239,6 +244,11 @@ protected: bool EndQuery(IQuery* pQuery, int); + void EndFrame() + { + ++m_FrameNumber; + } + #ifdef DILIGENT_DEVELOPMENT // clang-format off bool DvpVerifyDrawArguments (const DrawAttribs& Attribs)const; @@ -343,6 +353,8 @@ protected: const bool m_bIsDeferred = false; + Uint64 m_FrameNumber = 0; + #ifdef DILIGENT_DEBUG // std::unordered_map is unbelievably slow. Keeping track of mapped buffers // in release builds is not feasible diff --git a/Graphics/GraphicsEngine/interface/APIInfo.h b/Graphics/GraphicsEngine/interface/APIInfo.h index 0ecbd92b..608c6fe3 100644 --- a/Graphics/GraphicsEngine/interface/APIInfo.h +++ b/Graphics/GraphicsEngine/interface/APIInfo.h @@ -30,7 +30,7 @@ /// \file /// Diligent API information -#define DILIGENT_API_VERSION 240078 +#define DILIGENT_API_VERSION 240079 #include "../../../Primitives/interface/BasicTypes.h" diff --git a/Graphics/GraphicsEngine/interface/DeviceContext.h b/Graphics/GraphicsEngine/interface/DeviceContext.h index 6320f947..122661f0 100644 --- a/Graphics/GraphicsEngine/interface/DeviceContext.h +++ b/Graphics/GraphicsEngine/interface/DeviceContext.h @@ -1448,6 +1448,12 @@ DILIGENT_BEGIN_INTERFACE(IDeviceContext, IObject) VIRTUAL void METHOD(FinishFrame)(THIS) PURE; + /// Returns the current frame number. + + /// \note The frame number is incremented every time FinishFrame() is called. + VIRTUAL Uint64 METHOD(GetFrameNumber)(THIS) CONST PURE; + + /// Transitions resource states. /// \param [in] BarrierCount - Number of barriers in pResourceBarriers array @@ -1537,6 +1543,7 @@ DILIGENT_END_INTERFACE # define IDeviceContext_UnmapTextureSubresource(This, ...) CALL_IFACE_METHOD(DeviceContext, UnmapTextureSubresource, This, __VA_ARGS__) # define IDeviceContext_GenerateMips(This, ...) CALL_IFACE_METHOD(DeviceContext, GenerateMips, This, __VA_ARGS__) # define IDeviceContext_FinishFrame(This) CALL_IFACE_METHOD(DeviceContext, FinishFrame, This) +# define IDeviceContext_GetFrameNumber(This) CALL_IFACE_METHOD(DeviceContext, GetFrameNumber, This) # define IDeviceContext_TransitionResourceStates(This, ...) CALL_IFACE_METHOD(DeviceContext, TransitionResourceStates, This, __VA_ARGS__) # define IDeviceContext_ResolveTextureSubresource(This, ...) CALL_IFACE_METHOD(DeviceContext, ResolveTextureSubresource, This, __VA_ARGS__) diff --git a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp index 7ee1ccec..d96e4204 100755 --- a/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp +++ b/Graphics/GraphicsEngineD3D11/src/DeviceContextD3D11Impl.cpp @@ -1187,6 +1187,8 @@ void DeviceContextD3D11Impl::FinishFrame() m_ActiveDisjointQuery->IsEnded = true; m_ActiveDisjointQuery.reset(); } + + TDeviceContextBase::EndFrame(); } void DeviceContextD3D11Impl::SetVertexBuffers(Uint32 StartSlot, diff --git a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.hpp b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.hpp index 91c1610a..4eb3585b 100644 --- a/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.hpp +++ b/Graphics/GraphicsEngineD3D12/include/DeviceContextD3D12Impl.hpp @@ -312,8 +312,6 @@ public: size_t GetNumCommandsInCtx() const { return m_State.NumCommands; } - Int64 GetCurrentFrameNumber() const { return m_ContextFrameNumber; } - private: void CommitD3D12IndexBuffer(GraphicsContext& GraphCtx, VALUE_TYPE IndexType); void CommitD3D12VertexBuffers(class GraphicsContext& GraphCtx); diff --git a/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp index d7cd54b6..0d0ac327 100644 --- a/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/BufferD3D12Impl.cpp @@ -404,9 +404,9 @@ ID3D12Resource* BufferD3D12Impl::GetD3D12Buffer(Uint64& DataStartByteOffset, IDe void BufferD3D12Impl::DvpVerifyDynamicAllocation(DeviceContextD3D12Impl* pCtx) const { auto ContextId = pCtx->GetContextId(); - auto CurrentFrame = pCtx->GetCurrentFrameNumber(); + auto CurrentFrame = pCtx->GetFrameNumber(); DEV_CHECK_ERR(m_DynamicData[ContextId].GPUAddress != 0, "Dynamic buffer '", m_Desc.Name, "' has not been mapped before its first use. Context Id: ", ContextId, ". Note: memory for dynamic buffers is allocated when a buffer is mapped."); - DEV_CHECK_ERR(m_DynamicData[ContextId].DvpCtxFrameNumber == static_cast<Uint64>(CurrentFrame), "Dynamic allocation of dynamic buffer '", m_Desc.Name, "' in frame ", CurrentFrame, " is out-of-date. Note: contents of all dynamic resources is discarded at the end of every frame. A buffer must be mapped before its first use in any frame."); + DEV_CHECK_ERR(m_DynamicData[ContextId].DvpCtxFrameNumber == CurrentFrame, "Dynamic allocation of dynamic buffer '", m_Desc.Name, "' in frame ", CurrentFrame, " is out-of-date. Note: contents of all dynamic resources is discarded at the end of every frame. A buffer must be mapped before its first use in any frame."); VERIFY(GetState() == RESOURCE_STATE_GENERIC_READ, "Dynamic buffers are expected to always be in RESOURCE_STATE_GENERIC_READ state"); } #endif diff --git a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp index 938c9468..45e6be49 100644 --- a/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp +++ b/Graphics/GraphicsEngineD3D12/src/DeviceContextD3D12Impl.cpp @@ -1313,7 +1313,7 @@ void DeviceContextD3D12Impl::EndRenderPass() D3D12DynamicAllocation DeviceContextD3D12Impl::AllocateDynamicSpace(size_t NumBytes, size_t Alignment) { - return m_DynamicHeap.Allocate(NumBytes, Alignment, m_ContextFrameNumber); + return m_DynamicHeap.Allocate(NumBytes, Alignment, GetFrameNumber()); } void DeviceContextD3D12Impl::UpdateBufferRegion(BufferD3D12Impl* pBuffD3D12, @@ -1346,7 +1346,7 @@ void DeviceContextD3D12Impl::UpdateBuffer(IBuffer* pBuffer auto* pBuffD3D12 = ValidatedCast<BufferD3D12Impl>(pBuffer); VERIFY(pBuffD3D12->GetDesc().Usage != USAGE_DYNAMIC, "Dynamic buffers must be updated via Map()"); constexpr size_t DefaultAlginment = 16; - auto TmpSpace = m_DynamicHeap.Allocate(Size, DefaultAlginment, m_ContextFrameNumber); + auto TmpSpace = m_DynamicHeap.Allocate(Size, DefaultAlginment, GetFrameNumber()); memcpy(TmpSpace.CPUAddress, pData, Size); UpdateBufferRegion(pBuffD3D12, TmpSpace, Offset, Size, StateTransitionMode); } diff --git a/Graphics/GraphicsEngineNextGenBase/include/DeviceContextNextGenBase.hpp b/Graphics/GraphicsEngineNextGenBase/include/DeviceContextNextGenBase.hpp index 84ad7a91..66751ac2 100644 --- a/Graphics/GraphicsEngineNextGenBase/include/DeviceContextNextGenBase.hpp +++ b/Graphics/GraphicsEngineNextGenBase/include/DeviceContextNextGenBase.hpp @@ -27,7 +27,6 @@ #pragma once -#include "Atomics.hpp" #include "BasicTypes.h" #include "ReferenceCounters.h" #include "RefCntAutoPtr.hpp" @@ -58,7 +57,6 @@ public: m_ContextId {ContextId }, m_CommandQueueId {CommandQueueId }, m_NumCommandsToFlush {NumCommandsToFlush}, - m_ContextFrameNumber {0}, m_SubmittedBuffersCmdQueueMask{bIsDeferred ? 0 : Uint64{1} << Uint64{CommandQueueId}} // clang-format on { @@ -106,13 +104,12 @@ protected: { this->m_pDevice->FlushStaleResources(m_CommandQueueId); } - Atomics::AtomicIncrement(m_ContextFrameNumber); + TBase::EndFrame(); } - const Uint32 m_ContextId; - const Uint32 m_CommandQueueId; - const Uint32 m_NumCommandsToFlush; - Atomics::AtomicInt64 m_ContextFrameNumber; + const Uint32 m_ContextId; + const Uint32 m_CommandQueueId; + const Uint32 m_NumCommandsToFlush; // This mask indicates which command queues command buffers from this context were submitted to. // For immediate context, this will always be 1 << m_CommandQueueId. diff --git a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp index d8af2feb..9e1760ac 100644 --- a/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp +++ b/Graphics/GraphicsEngineOpenGL/src/DeviceContextGLImpl.cpp @@ -1274,6 +1274,7 @@ void DeviceContextGLImpl::Flush() void DeviceContextGLImpl::FinishFrame() { + TDeviceContextBase::EndFrame(); } void DeviceContextGLImpl::FinishCommandList(class ICommandList** ppCommandList) diff --git a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp index 7f027c12..093ab8d9 100644 --- a/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp +++ b/Graphics/GraphicsEngineVulkan/include/DeviceContextVkImpl.hpp @@ -347,8 +347,6 @@ public: virtual void ResetRenderTargets() override final; - Int64 GetContextFrameNumber() const { return m_ContextFrameNumber; } - GenerateMipsVkHelper& GetGenerateMipsHelper() { return *m_GenerateMipsHelper; } QueryManagerVk* GetQueryManager() { return m_QueryMgr.get(); } diff --git a/Graphics/GraphicsEngineVulkan/include/VulkanDynamicHeap.hpp b/Graphics/GraphicsEngineVulkan/include/VulkanDynamicHeap.hpp index 6a03cd50..0aa286a4 100644 --- a/Graphics/GraphicsEngineVulkan/include/VulkanDynamicHeap.hpp +++ b/Graphics/GraphicsEngineVulkan/include/VulkanDynamicHeap.hpp @@ -97,7 +97,7 @@ struct VulkanDynamicAllocation size_t AlignedOffset = 0; // Offset from the start of the buffer size_t Size = 0; // Reserved size of this allocation #ifdef DILIGENT_DEVELOPMENT - Int64 dvpFrameNumber = 0; + Uint64 dvpFrameNumber = 0; #endif }; diff --git a/Graphics/GraphicsEngineVulkan/src/BufferVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/BufferVkImpl.cpp index 3e61a756..0d41ec33 100644 --- a/Graphics/GraphicsEngineVulkan/src/BufferVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/BufferVkImpl.cpp @@ -460,9 +460,9 @@ VkAccessFlags BufferVkImpl::GetAccessFlags() const #ifdef DILIGENT_DEVELOPMENT void BufferVkImpl::DvpVerifyDynamicAllocation(DeviceContextVkImpl* pCtx) const { - auto ContextId = pCtx->GetContextId(); + const auto ContextId = pCtx->GetContextId(); const auto& DynAlloc = m_DynamicAllocations[ContextId]; - auto CurrentFrame = pCtx->GetContextFrameNumber(); + const auto CurrentFrame = pCtx->GetFrameNumber(); DEV_CHECK_ERR(DynAlloc.pDynamicMemMgr != nullptr, "Dynamic buffer '", m_Desc.Name, "' has not been mapped before its first use. Context Id: ", ContextId, ". Note: memory for dynamic buffers is allocated when a buffer is mapped."); DEV_CHECK_ERR(DynAlloc.dvpFrameNumber == CurrentFrame, "Dynamic allocation of dynamic buffer '", m_Desc.Name, "' in frame ", CurrentFrame, " is out-of-date. Note: contents of all dynamic resources is discarded at the end of every frame. A buffer must be mapped before its first use in any frame."); } diff --git a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp index f2b70ff7..3520fa40 100644 --- a/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp +++ b/Graphics/GraphicsEngineVulkan/src/DeviceContextVkImpl.cpp @@ -2444,7 +2444,7 @@ VulkanDynamicAllocation DeviceContextVkImpl::AllocateDynamicSpace(Uint32 SizeInB { auto DynAlloc = m_DynamicHeap.Allocate(SizeInBytes, Alignment); #ifdef DILIGENT_DEVELOPMENT - DynAlloc.dvpFrameNumber = m_ContextFrameNumber; + DynAlloc.dvpFrameNumber = GetFrameNumber(); #endif return DynAlloc; } |
