Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
GFXDevice.inl
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#ifndef DVD_HARDWARE_VIDEO_GFX_DEVICE_INL_
33#define DVD_HARDWARE_VIDEO_GFX_DEVICE_INL_
34
35namespace Divide {
36
37void DestroyIMP(IMPrimitive*& primitive);
38
39template <typename Descriptor, size_t N>
41{
42 for ( auto& primitive : _debugPrimitives )
43 {
44 primitive = nullptr;
45 }
46}
47
48template <typename Descriptor, size_t N>
50{
51 reset();
52}
53
54template <typename Descriptor, size_t N>
56{
57 return _debugPrimitives.size();
58}
59
60template <typename Descriptor, size_t N>
62{
63 LockGuard<Mutex> w_lock(_dataLock);
64
65 for (IMPrimitive*& primitive : _debugPrimitives)
66 {
67 DestroyIMP(primitive);
68 }
69
70 for (auto& data : _debugData)
71 {
72 data = {};
73 }
74}
75
76template <typename Descriptor, size_t N>
77void DebugPrimitiveHandler<Descriptor, N>::add( const I64 ID, const Descriptor& data ) noexcept
78{
79 LockGuard<Mutex> w_lock( _dataLock );
80 addLocked( ID, data );
81}
82
83template <typename Descriptor, size_t N>
84void DebugPrimitiveHandler<Descriptor, N>::addLocked( const I64 ID, const Descriptor& data ) noexcept
85{
86 const size_t count = _debugData.size();
87
88 for ( U32 i = 0u; i < count; ++i )
89 {
90 DataEntry& entry = _debugData[i];
91 if ( entry._id == ID )
92 {
93 entry._descriptor = data;
94 entry._frameLifeTime = g_maxFrameLifetime;
95 return;
96 }
97 }
98
99 for ( U32 i = 0u; i < count; ++i )
100 {
101 DataEntry& entry = _debugData[i];
102 if ( entry._frameLifeTime == 0u )
103 {
104 entry._id = ID;
105 entry._descriptor = data;
106 entry._frameLifeTime = g_maxFrameLifetime;
107 return;
108 }
109 }
110
111 //We need a new entry. Create one and try again
112 _debugPrimitives.emplace_back( nullptr );
113 _debugData.emplace_back();
114 addLocked( ID, data );
115}
116
118{
119 assert(_renderer != nullptr);
120 return *_renderer;
121}
122
123inline const RenderStateBlock& GFXDevice::get2DStateBlock() const noexcept
124{
125 return _state2DRendering;
126}
127
129{
131}
132
134{
135 return *_rtPool;
136}
137
138inline const GFXRTPool& GFXDevice::renderTargetPool() const noexcept
139{
140 return *_rtPool;
141}
142
143inline Handle<ShaderProgram> GFXDevice::getRTPreviewShader(const bool depthOnly) const noexcept
144{
145 return depthOnly ? _previewRenderTargetDepth : _previewRenderTargetColour;
146}
147
148inline void GFXDevice::registerDrawCall() noexcept
149{
151}
152
153inline void GFXDevice::registerDrawCalls(const U32 count) noexcept
154{
155 frameDrawCalls(frameDrawCalls() + count);
156}
157
159{
160 return s_deviceInformation;
161}
162
165 s_deviceInformation = info;
167
168inline bool GFXDevice::IsSubmitCommand(const GFX::CommandType type) noexcept
169{
173
175{
177}
178
180{
182}
183
184inline bool GFXDevice::setViewport(const I32 x, const I32 y, const I32 width, const I32 height)
185{
186 return setViewport({ x, y, width, height });
187}
188
189inline bool GFXDevice::setScissor(const I32 x, const I32 y, const I32 width, const I32 height)
190{
191 return setScissor({ x, y, width, height });
192}
193
195{
196 return _performanceMetrics;
197}
198
200{
201 return _performanceMetrics;
202}
203
205{
206 return _descriptorSets[to_base(usage)];
207}
208
210{
211 return _descriptorSets[to_base(usage)];
212}
213
214inline ShaderBuffer_uptr GFXDevice::newSB( const ShaderBufferDescriptor& descriptor )
215{
216 return _api->newSB( descriptor );
217}
218
219inline GenericVertexData_ptr GFXDevice::newGVD( const U32 ringBufferLength, const std::string_view name )
220{
221 return _api->newGVD( ringBufferLength, name );
222}
223
225{
227}
228
230{
231 return _perFrameBuffers[_perFrameBufferIndex];
232}
233
234inline void GFXDevice::GFXBuffers::reset( const bool camBuffer, const bool cullBuffer ) noexcept
235{
236 for ( U8 i = 0u; i < PER_FRAME_BUFFER_COUNT; ++i )
237 {
238 if ( camBuffer )
239 {
240 _perFrameBuffers[i]._camDataBuffer.reset();
241 }
242
243 if ( cullBuffer )
244 {
245 _perFrameBuffers[i]._cullCounter.reset();
246 }
247 }
248 crtBuffers()._camWritesThisFrame = 0u;
249 crtBuffers()._renderWritesThisFrame = 0u;
250}
251
253{
254 _perFrameBufferIndex = (_perFrameBufferIndex + 1u) % PER_FRAME_BUFFER_COUNT;
255 crtBuffers()._camWritesThisFrame = 0u;
256 crtBuffers()._renderWritesThisFrame = 0u;
257}
258}; // namespace Divide
259
260#endif //DVD_HARDWARE_VIDEO_GFX_DEVICE_INL_
bool setViewport(const Rect< I32 > &viewport)
Returns true if the viewport was changed.
Definition: GFXDevice.cpp:2051
ShaderBuffer_uptr newSB(const ShaderBufferDescriptor &descriptor)
Definition: GFXDevice.inl:214
RenderStateBlock _defaultStateNoDepthTest
The default render state but with depth testing disabled.
Definition: GFXDevice.h:488
static DeviceInformation s_deviceInformation
Definition: GFXDevice.h:580
static bool IsSubmitCommand(GFX::CommandType type) noexcept
Definition: GFXDevice.inl:168
static const DeviceInformation & GetDeviceInformation() noexcept
Definition: GFXDevice.inl:158
F32 renderingAspectRatio() const noexcept
Definition: GFXDevice.inl:179
RenderAPIWrapper_uptr _api
Definition: GFXDevice.h:468
vec2< U16 > renderingResolution() const noexcept
Definition: GFXDevice.inl:174
RenderStateBlock _state2DRendering
Special render state for 2D rendering.
Definition: GFXDevice.h:490
GFXRTPool & renderTargetPool() noexcept
Definition: GFXDevice.inl:133
Renderer_uptr _renderer
Definition: GFXDevice.h:469
Renderer & getRenderer() const
Definition: GFXDevice.inl:117
Handle< ShaderProgram > getRTPreviewShader(bool depthOnly) const noexcept
Definition: GFXDevice.inl:143
void registerDrawCalls(U32 count) noexcept
Definition: GFXDevice.inl:153
const RenderStateBlock & getNoDepthTestBlock() const noexcept
returns the standard state block
Definition: GFXDevice.inl:128
void registerDrawCall() noexcept
Definition: GFXDevice.inl:148
static void OverrideDeviceInformation(const DeviceInformation &info) noexcept
Definition: GFXDevice.inl:163
GenericVertexData_ptr newGVD(U32 ringBufferLength, std::string_view name)
Definition: GFXDevice.inl:219
const RenderStateBlock & get2DStateBlock() const noexcept
Definition: GFXDevice.inl:123
GFXDescriptorSet & descriptorSet(DescriptorSetUsage usage) noexcept
Definition: GFXDevice.inl:204
PerformanceMetrics _performanceMetrics
Definition: GFXDevice.h:572
std::unique_ptr< GFXRTPool > _rtPool
Definition: GFXDevice.h:482
PerformanceMetrics & getPerformanceMetrics() noexcept
Definition: GFXDevice.inl:194
bool setScissor(const Rect< I32 > &scissor)
Definition: GFXDevice.cpp:2057
vec2< U16 > _renderingResolution
Definition: GFXDevice.h:528
IMPrimitive replaces immediate mode calls to VB based rendering.
Definition: IMPrimitive.h:58
TiledForwardShading.
Definition: Renderer.h:50
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
std::lock_guard< mutex > LockGuard
Definition: SharedMutex.h:55
int32_t I32
uint8_t U8
constexpr F32 to_F32(const T value)
void DestroyIMP(IMPrimitive *&primitive)
Definition: GFXDevice.cpp:3092
DescriptorSetUsage
int64_t I64
uint32_t U32
Project const SceneEntry & entry
Definition: DefaultScene.h:41
constexpr auto to_base(const Type value) -> Type
Definition: GFXDevice.h:158
void addLocked(const I64 ID, const Descriptor &data) noexcept
Definition: GFXDevice.inl:84
void add(const I64 ID, const Descriptor &data) noexcept
Definition: GFXDevice.inl:77
size_t size() const noexcept
Definition: GFXDevice.inl:55
void reset(const bool camBuffer, const bool cullBuffer) noexcept
Definition: GFXDevice.inl:234
PerFrameBuffers & crtBuffers() noexcept
Definition: GFXDevice.inl:224
struct Divide::GFXDevice::GFXBuffers::PerFrameBuffers _perFrameBuffers[PER_FRAME_BUFFER_COUNT]
Queries are expensive, so this result MAY BE SEVERAL frames out of date!