Plasma Engine  2.0
Loading...
Searching...
No Matches
Device_inl.h
1
3#define PL_GALDEVICE_LOCK_AND_CHECK() \
4 PL_LOCK(m_Mutex); \
5 VerifyMultithreadedAccess()
6
7PL_ALWAYS_INLINE const plGALDeviceCreationDescription* plGALDevice::GetDescription() const
8{
9 return &m_Description;
10}
11
12PL_ALWAYS_INLINE plUInt64 plGALDevice::GetCurrentFrame() const
13{
14 return GetCurrentFramePlatform();
15}
16
17PL_ALWAYS_INLINE plUInt64 plGALDevice::GetSafeFrame() const
18{
19 return GetSafeFramePlatform();
20}
21
23{
24 if (hTimestamp.IsInvalidated())
26
27 return GetTimestampResultPlatform(hTimestamp, out_result);
28}
29
31{
32 if (hOcclusion.IsInvalidated())
34
35 return GetOcclusionResultPlatform(hOcclusion, out_uiResult);
36}
37
38PL_ALWAYS_INLINE plEnum<plGALAsyncResult> plGALDevice::GetFenceResult(plGALFenceHandle hFence, plTime timeout)
39{
40 if (hFence == 0)
42
43 return GetFenceResultPlatform(hFence, timeout);
44}
45
46template <typename IdTableType, typename ReturnType>
47PL_ALWAYS_INLINE ReturnType* plGALDevice::Get(typename IdTableType::TypeOfId hHandle, const IdTableType& IdTable) const
48{
49 PL_GALDEVICE_LOCK_AND_CHECK();
50
51 ReturnType* pObject = nullptr;
52 IdTable.TryGetValue(hHandle, pObject);
53 return pObject;
54}
55
56inline const plGALSwapChain* plGALDevice::GetSwapChain(plGALSwapChainHandle hSwapChain) const
57{
58 return Get<SwapChainTable, plGALSwapChain>(hSwapChain, m_SwapChains);
59}
60
61inline const plGALShader* plGALDevice::GetShader(plGALShaderHandle hShader) const
62{
63 return Get<ShaderTable, plGALShader>(hShader, m_Shaders);
64}
65
66inline const plGALTexture* plGALDevice::GetTexture(plGALTextureHandle hTexture) const
67{
68 return Get<TextureTable, plGALTexture>(hTexture, m_Textures);
69}
70
71inline const plGALBuffer* plGALDevice::GetBuffer(plGALBufferHandle hBuffer) const
72{
73 return Get<BufferTable, plGALBuffer>(hBuffer, m_Buffers);
74}
75
76inline const plGALDepthStencilState* plGALDevice::GetDepthStencilState(plGALDepthStencilStateHandle hDepthStencilState) const
77{
78 return Get<DepthStencilStateTable, plGALDepthStencilState>(hDepthStencilState, m_DepthStencilStates);
79}
80
81inline const plGALBlendState* plGALDevice::GetBlendState(plGALBlendStateHandle hBlendState) const
82{
83 return Get<BlendStateTable, plGALBlendState>(hBlendState, m_BlendStates);
84}
85
86inline const plGALRasterizerState* plGALDevice::GetRasterizerState(plGALRasterizerStateHandle hRasterizerState) const
87{
88 return Get<RasterizerStateTable, plGALRasterizerState>(hRasterizerState, m_RasterizerStates);
89}
90
91inline const plGALVertexDeclaration* plGALDevice::GetVertexDeclaration(plGALVertexDeclarationHandle hVertexDeclaration) const
92{
93 return Get<VertexDeclarationTable, plGALVertexDeclaration>(hVertexDeclaration, m_VertexDeclarations);
94}
95
96inline const plGALSamplerState* plGALDevice::GetSamplerState(plGALSamplerStateHandle hSamplerState) const
97{
98 return Get<SamplerStateTable, plGALSamplerState>(hSamplerState, m_SamplerStates);
99}
100
101inline const plGALTextureResourceView* plGALDevice::GetResourceView(plGALTextureResourceViewHandle hResourceView) const
102{
103 return Get<TextureResourceViewTable, plGALTextureResourceView>(hResourceView, m_TextureResourceViews);
104}
105
106inline const plGALBufferResourceView* plGALDevice::GetResourceView(plGALBufferResourceViewHandle hResourceView) const
107{
108 return Get<BufferResourceViewTable, plGALBufferResourceView>(hResourceView, m_BufferResourceViews);
109}
110
111inline const plGALRenderTargetView* plGALDevice::GetRenderTargetView(plGALRenderTargetViewHandle hRenderTargetView) const
112{
113 return Get<RenderTargetViewTable, plGALRenderTargetView>(hRenderTargetView, m_RenderTargetViews);
114}
115
116inline const plGALTextureUnorderedAccessView* plGALDevice::GetUnorderedAccessView(plGALTextureUnorderedAccessViewHandle hUnorderedAccessView) const
117{
118 return Get<TextureUnorderedAccessViewTable, plGALTextureUnorderedAccessView>(hUnorderedAccessView, m_TextureUnorderedAccessViews);
119}
120
121inline const plGALBufferUnorderedAccessView* plGALDevice::GetUnorderedAccessView(plGALBufferUnorderedAccessViewHandle hUnorderedAccessView) const
122{
123 return Get<BufferUnorderedAccessViewTable, plGALBufferUnorderedAccessView>(hUnorderedAccessView, m_BufferUnorderedAccessViews);
124}
125
126// static
127PL_ALWAYS_INLINE void plGALDevice::SetDefaultDevice(plGALDevice* pDefaultDevice)
128{
129 s_pDefaultDevice = pDefaultDevice;
130}
131
132// static
133PL_ALWAYS_INLINE plGALDevice* plGALDevice::GetDefaultDevice()
134{
135 PL_ASSERT_DEBUG(s_pDefaultDevice != nullptr, "Default device not set.");
136 return s_pDefaultDevice;
137}
138
139// static
140PL_ALWAYS_INLINE bool plGALDevice::HasDefaultDevice()
141{
142 return s_pDefaultDevice != nullptr;
143}
144
145template <typename HandleType>
146PL_FORCE_INLINE void plGALDevice::AddDeadObject(plUInt32 uiType, HandleType handle)
147{
148 auto& deadObject = m_DeadObjects.ExpandAndGetRef();
149 deadObject.m_uiType = uiType;
150 deadObject.m_uiHandle = handle.GetInternalID().m_Data;
151}
152
153template <typename HandleType>
154void plGALDevice::ReviveDeadObject(plUInt32 uiType, HandleType handle)
155{
156 plUInt32 uiHandle = handle.GetInternalID().m_Data;
157
158 for (plUInt32 i = 0; i < m_DeadObjects.GetCount(); ++i)
159 {
160 const auto& deadObject = m_DeadObjects[i];
161
162 if (deadObject.m_uiType == uiType && deadObject.m_uiHandle == uiHandle)
163 {
164 m_DeadObjects.RemoveAtAndCopy(i);
165 return;
166 }
167 }
168}
169
170PL_ALWAYS_INLINE void plGALDevice::VerifyMultithreadedAccess() const
171{
172#if PL_ENABLED(PL_COMPILE_FOR_DEVELOPMENT)
173 PL_ASSERT_DEV(m_Capabilities.m_bMultithreadedResourceCreation || plThreadUtils::IsMainThread(),
174 "This device does not support multi-threaded resource creation, therefore this function can only be executed on the main thread.");
175#endif
176}
177
179{
180 return &m_Allocator;
181}
Base class for all memory allocators.
Definition Allocator.h:23
Definition RendererFoundationDLL.h:467
Definition State.h:7
Definition RendererFoundationDLL.h:418
Definition Buffer.h:8
Definition RendererFoundationDLL.h:432
Definition ResourceView.h:30
Definition RendererFoundationDLL.h:446
Definition UnorderedAccesView.h:28
Definition RendererFoundationDLL.h:460
Definition State.h:20
The plRenderDevice class is the primary interface for interactions with rendering APIs It contains a ...
Definition Device.h:19
void VerifyMultithreadedAccess() const
Asserts that either this device supports multi-threaded resource creation, or that this function is e...
Definition Device_inl.h:170
plAllocator * GetAllocator()
Internal: Returns the allocator used by the device.
Definition Device_inl.h:178
plUInt64 GetSafeFrame() const
The latest frame that has been fully executed on the GPU. Whenever you execute any work that requires...
Definition Device_inl.h:17
plEnum< plGALAsyncResult > GetFenceResult(plGALFenceHandle hFence, plTime timeout=plTime::MakeZero())
Definition Device_inl.h:38
plEnum< plGALAsyncResult > GetOcclusionQueryResult(plGALOcclusionHandle hOcclusion, plUInt64 &out_uiResult)
Definition Device_inl.h:30
plUInt64 GetCurrentFrame() const
The current rendering frame. This is a monotonically increasing number which changes +1 every time En...
Definition Device_inl.h:12
plEnum< plGALAsyncResult > GetTimestampResult(plGALTimestampHandle hTimestamp, plTime &out_result)
Queries the result of a timestamp. Should be called every frame until plGALAsyncResult::Ready is retu...
Definition Device_inl.h:22
Definition RendererFoundationDLL.h:474
Definition State.h:33
Definition RendererFoundationDLL.h:453
Definition RenderTargetView.h:8
Definition RendererFoundationDLL.h:481
Definition State.h:46
Definition RendererFoundationDLL.h:404
Definition Shader.h:7
Definition RendererFoundationDLL.h:397
Definition SwapChain.h:11
Definition RendererFoundationDLL.h:411
Definition Texture.h:8
Definition RendererFoundationDLL.h:425
Definition ResourceView.h:11
Definition RendererFoundationDLL.h:439
Definition UnorderedAccesView.h:11
Definition RendererFoundationDLL.h:488
Definition VertexDeclaration.h:8
static bool IsMainThread()
Helper function to check if the current thread is the main thread (e.g. the thread which initialized ...
Definition ThreadUtils_Posix.h:47
A custom enum implementation that allows to define the underlying storage type to control its memory ...
Definition Enum.h:37
@ Ready
The async operation has finished and the result is ready.
Definition RendererFoundationDLL.h:350
@ Expired
The async operation is too old and the result was thrown away. Pending results should be queried ever...
Definition RendererFoundationDLL.h:352
bool m_bMultithreadedResourceCreation
whether creating resources is allowed on other threads than the main thread
Definition DeviceCapabilities.h:51
Definition Descriptors.h:39
A generic id class that holds an id combined of an instance index and a generation counter.
Definition Id.h:52
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12