Diligent Engine  v.2.4.g
DeviceContextNextGenBase.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019-2021 Diligent Graphics LLC
3  * Copyright 2015-2019 Egor Yusov
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * In no event and under no legal theory, whether in tort (including negligence),
18  * contract, or otherwise, unless required by applicable law (such as deliberate
19  * and grossly negligent acts) or agreed to in writing, shall any Contributor be
20  * liable for any damages, including any direct, indirect, special, incidental,
21  * or consequential damages of any character arising as a result of this License or
22  * out of the use or inability to use the software (including but not limited to damages
23  * for loss of goodwill, work stoppage, computer failure or malfunction, or any and
24  * all other commercial damages or losses), even if such Contributor has been advised
25  * of the possibility of such damages.
26  */
27 
28 #pragma once
29 
30 #include <atomic>
31 
32 #include "BasicTypes.h"
33 #include "ReferenceCounters.h"
34 #include "RefCntAutoPtr.hpp"
35 #include "DeviceContextBase.hpp"
36 #include "RefCntAutoPtr.hpp"
37 
38 namespace Diligent
39 {
40 
42 
43 template <typename EngineImplTraits>
44 class DeviceContextNextGenBase : public DeviceContextBase<EngineImplTraits>
45 {
46 public:
48  using DeviceImplType = typename EngineImplTraits::RenderDeviceImplType;
49  using ICommandQueueType = typename EngineImplTraits::CommandQueueInterface;
50 
52  DeviceImplType* pRenderDevice,
53  Uint32 ContextId,
54  Uint32 CommandQueueId,
55  bool bIsDeferred) :
56  // clang-format off
57  TBase{pRefCounters, pRenderDevice, bIsDeferred},
58  m_ContextId {ContextId },
59  m_CommandQueueId {CommandQueueId },
60  m_SubmittedBuffersCmdQueueMask{bIsDeferred ? 0 : Uint64{1} << Uint64{CommandQueueId}}
61  // clang-format on
62  {
63  }
64 
66  {
67  }
68 
70  {
71  if (this->m_bIsDeferred)
72  {
73  LOG_WARNING_MESSAGE("Deferred contexts have no associated command queues");
74  return nullptr;
75  }
76  return this->m_pDevice->LockCommandQueue(m_CommandQueueId);
77  }
78 
79  virtual void DILIGENT_CALL_TYPE UnlockCommandQueue() override final
80  {
81  if (this->m_bIsDeferred)
82  {
83  LOG_WARNING_MESSAGE("Deferred contexts have no associated command queues");
84  return;
85  }
86  this->m_pDevice->UnlockCommandQueue(m_CommandQueueId);
87  }
88 
90  {
91  return m_CommandQueueId;
92  }
93 
94 protected:
95  // Should be called at the end of FinishFrame()
96  void EndFrame()
97  {
98  if (this->m_bIsDeferred)
99  {
100  // For deferred context, reset submitted cmd queue mask
102  }
103  else
104  {
105  this->m_pDevice->FlushStaleResources(m_CommandQueueId);
106  }
107  TBase::EndFrame();
108  }
109 
112 
113  // This mask indicates which command queues command buffers from this context were submitted to.
114  // For immediate context, this will always be 1 << m_CommandQueueId.
115  // For deferred contexts, this will accumulate bits of the queues to which command buffers
116  // were submitted to before FinishFrame() was called. This mask is used to release resources
117  // allocated by the context during the frame when FinishFrame() is called.
118  std::atomic_uint64_t m_SubmittedBuffersCmdQueueMask{0};
119 };
120 
121 } // namespace Diligent
Diligent::DeviceContextNextGenBase< EngineD3D12ImplTraits >::ICommandQueueType
typename EngineD3D12ImplTraits ::CommandQueueInterface ICommandQueueType
Definition: DeviceContextNextGenBase.hpp:49
Diligent::IReferenceCounters
Base interface for a reference counter object that stores the number of strong and weak references an...
Definition: ReferenceCounters.h:44
Diligent::DeviceContextNextGenBase::m_ContextId
const Uint32 m_ContextId
Definition: DeviceContextNextGenBase.hpp:110
Diligent::DeviceContextNextGenBase::UnlockCommandQueue
virtual void UnlockCommandQueue() override final
Definition: DeviceContextNextGenBase.hpp:79
Diligent::Uint64
uint64_t Uint64
64-bit unsigned integer
Definition: BasicTypes.h:50
Diligent::DeviceContextNextGenBase::LockCommandQueue
virtual ICommandQueueType * LockCommandQueue() override final
Definition: DeviceContextNextGenBase.hpp:69
Diligent::DeviceContextNextGenBase::DeviceContextNextGenBase
DeviceContextNextGenBase(IReferenceCounters *pRefCounters, DeviceImplType *pRenderDevice, Uint32 ContextId, Uint32 CommandQueueId, bool bIsDeferred)
Definition: DeviceContextNextGenBase.hpp:51
DeviceContextBase.hpp
Diligent::DeviceContextBase::EndFrame
void EndFrame()
Definition: DeviceContextBase.hpp:340
Diligent::DeviceContextBase< EngineD3D12ImplTraits >::DeviceImplType
typename EngineD3D12ImplTraits ::RenderDeviceImplType DeviceImplType
Definition: DeviceContextBase.hpp:112
ReferenceCounters.h
Diligent::DeviceContextNextGenBase::GetCommandQueueId
Uint32 GetCommandQueueId() const
Definition: DeviceContextNextGenBase.hpp:89
BasicTypes.h
DILIGENT_CALL_TYPE
#define DILIGENT_CALL_TYPE
Definition: CommonDefinitions.h:45
Diligent::Uint32
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
Diligent::DeviceContextNextGenBase::~DeviceContextNextGenBase
~DeviceContextNextGenBase()
Definition: DeviceContextNextGenBase.hpp:65
Diligent::DeviceContextBase
Base implementation of the device context.
Definition: DeviceContextBase.hpp:107
Diligent::DeviceContextNextGenBase::m_SubmittedBuffersCmdQueueMask
std::atomic_uint64_t m_SubmittedBuffersCmdQueueMask
Definition: DeviceContextNextGenBase.hpp:118
LOG_WARNING_MESSAGE
#define LOG_WARNING_MESSAGE(...)
Definition: Errors.hpp:123
RefCntAutoPtr.hpp
Diligent::DeviceContextNextGenBase::m_CommandQueueId
const Uint32 m_CommandQueueId
Definition: DeviceContextNextGenBase.hpp:111
Diligent::DeviceContextNextGenBase
Base implementation of the device context for next-generation backends.
Definition: DeviceContextNextGenBase.hpp:44
Diligent::DeviceContextBase::m_bIsDeferred
const bool m_bIsDeferred
Definition: DeviceContextBase.hpp:476
Diligent::DeviceContextNextGenBase::EndFrame
void EndFrame()
Definition: DeviceContextNextGenBase.hpp:96
Diligent::DeviceContextBase::m_pDevice
RefCntAutoPtr< DeviceImplType > m_pDevice
Strong reference to the device.
Definition: DeviceContextBase.hpp:409
Diligent
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37