Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
#include "stdafx.h"

#include "config.h"

#include "Headers/RenderPass.h"

#include "Graphs/Headers/SceneGraph.h"
#include "Managers/Headers/SceneManager.h"
#include "Managers/Headers/RenderPassManager.h"

#include "Platform/Video/Headers/GFXDevice.h"

#include "Scenes/Headers/Scene.h"
#include "Geometry/Material/Headers/Material.h"

#include "Rendering/Headers/Renderer.h"
#include "Rendering/Lighting/Headers/LightPool.h"
#include "Rendering/RenderPass/Headers/RenderQueue.h"
#include "Platform/Video/Buffers/ShaderBuffer/Headers/ShaderBuffer.h"

namespace Divide {

namespace {
    // We need a proper, time-based system, to check reflection budget
    namespace ReflectionUtil {
        U32 g_reflectionBudget = 0;

        inline bool isInBudget() {
            return g_reflectionBudget < 
                Config::MAX_REFLECTIVE_NODES_IN_VIEW;
        }

        inline void resetBudget() {
            g_reflectionBudget = 0;
        }

        inline void updateBudget() {
            ++g_reflectionBudget;
        }
        inline U32 currentEntry() {
            return g_reflectionBudget;
        }
    };
    namespace RefractionUtil {
        U32 g_refractionBudget = 0;

        inline bool isInBudget() {
            return g_refractionBudget <
                Config::MAX_REFRACTIVE_NODES_IN_VIEW;
        }

        inline void resetBudget() {
            g_refractionBudget = 0;
        }

        inline void updateBudget() {
            ++g_refractionBudget;
        }
        inline U32 currentEntry() {
            return g_refractionBudget;
        }
    };
    
};

RenderPass::BufferData::BufferData(GFXDevice& context)
  : _lastCommandCount(0),
    _lasNodeCount(0)
{
    ShaderBufferDescriptor bufferDescriptor;
    bufferDescriptor._primitiveCount = Config::MAX_VISIBLE_NODES;
    bufferDescriptor._primitiveSizeInBytes = sizeof(GFXDevice::NodeData);
    bufferDescriptor._ringBufferLength = 1;
    bufferDescriptor._unbound = true;
    bufferDescriptor._updateFrequency = BufferUpdateFrequency::OCASSIONAL;

    // This do not need to be persistently mapped as, hopefully, they will only be update once per frame
    // Each pass should have its own set of buffers (shadows, reflection, etc)
    _renderData = context.newSB(bufferDescriptor);

    bufferDescriptor._primitiveSizeInBytes = sizeof(IndirectDrawCommand);
    _cmdBuffer = context.newSB(bufferDescriptor);
    _cmdBuffer->addAtomicCounter(3);
}

RenderPass::BufferData::~BufferData()
{
}

RenderPass::BufferDataPool::BufferDataPool(GFXDevice& context, U32 maxBuffers)
    : _context(context)
{
    // Every visible node will first update this buffer with required data (WorldMatrix, NormalMatrix, Material properties, Bone count, etc)
    // Due to it's potentially huge size, it translates to (as seen by OpenGL) a Shader Storage Buffer that's persistently and coherently mapped
    // We make sure the buffer is large enough to hold data for all of our rendering stages to minimize the number of writes per frame
    // Create a shader buffer to hold all of our indirect draw commands
    // Useful if we need access to the buffer in GLSL/Compute programs
    _buffers.resize(maxBuffers, nullptr);
}

RenderPass::BufferDataPool::~BufferDataPool()
{
    _buffers.clear();
}

RenderPass::BufferData& RenderPass::BufferDataPool::getBufferData(I32 bufferIndex) {
    assert(IS_IN_RANGE_INCLUSIVE(bufferIndex, 0, to_I32(_buffers.size())));

    std::shared_ptr<BufferData>& buffer = _buffers[bufferIndex];
    // More likely case
    if (buffer) {
        return *buffer;
    }

    buffer = std::make_shared<BufferData>(_context);
    return *buffer;
}

RenderPass::RenderPass(RenderPassManager& parent, GFXDevice& context, stringImpl name, U8 sortKey, RenderStage passStageFlag)
    : _parent(parent),
      _context(context),
      _sortKey(sortKey),
      _name(name),
      _stageFlag(passStageFlag)
{
    _lastTotalBinSize = 0;

    U32 count = getBufferCountForStage(_stageFlag);
    _passBuffers = MemoryManager_NEW BufferDataPool(_context, count);
}

RenderPass::~RenderPass() 
{
    MemoryManager::DELETE(_passBuffers);
}

RenderPass::BufferData&  RenderPass::getBufferData(I32 bufferIndex) {
    return _passBuffers->getBufferData(bufferIndex);
}

void RenderPass::generateDrawCommands() {
}

void RenderPass::render(SceneRenderState& renderState) {
    GFX::ScopedCommandBuffer sBuffer = GFX::allocateScopedCommandBuffer();
    GFX::CommandBuffer& commandBuffer = sBuffer();

    if (_stageFlag != RenderStage::SHADOW) {
        LightPool::bindShadowMaps(_context, commandBuffer);
    }

    switch(_stageFlag) {
        case RenderStage::DISPLAY: {
            GFX::BeginDebugScopeCommand beginDebugScopeCmd;
            beginDebugScopeCmd._scopeID = 10;
            beginDebugScopeCmd._scopeName = "Display Render Stage";
            GFX::BeginDebugScope(commandBuffer, beginDebugScopeCmd);

            const RenderTarget& screenRT = _context.renderTargetPool().renderTarget(RenderTargetID(RenderTargetUsage::SCREEN));
            RenderPassManager::PassParams params;
            params.occlusionCull = Config::USE_HIZ_CULLING;
            params.camera = Attorney::SceneManagerCameraAccessor::playerCamera(_parent.parent().sceneManager());

            params.stage = _stageFlag;
            params.target = RenderTargetID(RenderTargetUsage::SCREEN);
            params.pass = 0;
            params.doPrePass = Config::USE_Z_PRE_PASS && screenRT.getAttachment(RTAttachmentType::Depth, 0).used();
            params.occlusionCull = true;
            _parent.doCustomPass(params, commandBuffer);

            GFX::EndDebugScopeCommand endDebugScopeCmd;
            GFX::EndDebugScope(commandBuffer, endDebugScopeCmd);

            _lastTotalBinSize = _parent.getQueue().getRenderQueueStackSize();

        } break;
        case RenderStage::SHADOW: {
            GFX::BeginDebugScopeCommand beginDebugScopeCmd;
            beginDebugScopeCmd._scopeID = 20;
            beginDebugScopeCmd._scopeName = "Shadow Render Stage";
            GFX::BeginDebugScope(commandBuffer, beginDebugScopeCmd);

            Attorney::SceneManagerRenderPass::generateShadowMaps(_parent.parent().sceneManager(), commandBuffer);
            GFX::EndDebugScopeCommand endDebugScopeCmd;
            GFX::EndDebugScope(commandBuffer, endDebugScopeCmd);

        } break;
        case RenderStage::REFLECTION: {
            SceneManager& mgr = _parent.parent().sceneManager();
            RenderPassManager::PassParams params;
            params.pass = Config::MAX_REFLECTIVE_NODES_IN_VIEW;
            params.camera = Attorney::SceneManagerCameraAccessor::playerCamera(_parent.parent().sceneManager());
            
            {
                GFX::BeginDebugScopeCommand beginDebugScopeCmd;
                beginDebugScopeCmd._scopeID = 30;
                beginDebugScopeCmd._scopeName = "Cube Reflection Render Stage";
                GFX::BeginDebugScope(commandBuffer, beginDebugScopeCmd);

                //Part 1 - update envirnoment maps:
                /*SceneEnvironmentProbePool* envProbPool =  Attorney::SceneRenderPass::getEnvProbes(renderState.parentScene());
                const EnvironmentProbeList& probes = envProbPool->getNearestSorted(params.camera->getEye());
                for (EnvironmentProbe_ptr& probe : probes) {
                    probe->refresh(commandBuffer);
                }
                RenderPassCuller::VisibleNodeList& mainNodeCache = mgr.getVisibleNodesCache(RenderStage::DISPLAY);
                for (const RenderPassCuller::VisibleNode& node : mainNodeCache) {
                    SceneGraphNode* nodePtr = node.second;
                    RenderingComponent* const rComp = nodePtr->get<RenderingComponent>();
                    Attorney::RenderingCompRenderPass::updateEnvProbeList(*rComp, probes);
                }*/

                GFX::EndDebugScopeCommand endDebugScopeCmd;
                GFX::EndDebugScope(commandBuffer, endDebugScopeCmd);
            }
            {
                GFX::BeginDebugScopeCommand beginDebugScopeCmd;
                beginDebugScopeCmd._scopeID = 40;
                beginDebugScopeCmd._scopeName = "Planar Reflection Render Stage";
                GFX::BeginDebugScope(commandBuffer, beginDebugScopeCmd);

                //Part 2 - update classic reflectors (e.g. mirrors, water, etc)
                //Get list of reflective nodes from the scene manager
                const RenderPassCuller::VisibleNodeList& nodeCache = mgr.getSortedReflectiveNodes();

                // While in budget, update reflections
                ReflectionUtil::resetBudget();
                for (const RenderPassCuller::VisibleNode& node : nodeCache) {
                    const SceneGraphNode* nodePtr = node.second;
                    RenderingComponent* const rComp = nodePtr->get<RenderingComponent>();
                    if (ReflectionUtil::isInBudget()) {
                        // Excluse node from rendering itself into the pass
                        bool isVisile = rComp->renderOptionEnabled(RenderingComponent::RenderOptions::IS_VISIBLE);
                        rComp->toggleRenderOption(RenderingComponent::RenderOptions::IS_VISIBLE, false);
                        if (Attorney::RenderingCompRenderPass::updateReflection(*rComp,
                                                                                 ReflectionUtil::currentEntry(),
                                                                                 params.camera,
                                                                                 renderState,
                                                                                 commandBuffer)) {

                            ReflectionUtil::updateBudget();
                        }
                        rComp->toggleRenderOption(RenderingComponent::RenderOptions::IS_VISIBLE, isVisile);
                    } else {
                        Attorney::RenderingCompRenderPass::clearReflection(*rComp);
                    }
                }
                GFX::EndDebugScopeCommand endDebugScopeCmd;
                GFX::EndDebugScope(commandBuffer, endDebugScopeCmd);
            }
        } break;
        case RenderStage::REFRACTION: {
            // Get list of refractive nodes from the scene manager
            SceneManager& mgr = _parent.parent().sceneManager();
            RenderPassManager::PassParams params;
            params.pass = Config::MAX_REFLECTIVE_NODES_IN_VIEW;
            params.camera = Attorney::SceneManagerCameraAccessor::playerCamera(_parent.parent().sceneManager());

            {
                GFX::BeginDebugScopeCommand beginDebugScopeCmd;
                beginDebugScopeCmd._scopeID = 50;
                beginDebugScopeCmd._scopeName = "Cube Refraction Render Stage";
                GFX::BeginDebugScope(commandBuffer, beginDebugScopeCmd);

                GFX::EndDebugScopeCommand endDebugScopeCmd;
                GFX::EndDebugScope(commandBuffer, endDebugScopeCmd);
            }
            {
                GFX::BeginDebugScopeCommand beginDebugScopeCmd;
                beginDebugScopeCmd._scopeID = 60;
                beginDebugScopeCmd._scopeName = "Planar Refraction Render Stage";
                GFX::BeginDebugScope(commandBuffer, beginDebugScopeCmd);

                const RenderPassCuller::VisibleNodeList& nodeCache = mgr.getSortedRefractiveNodes();
                // While in budget, update refractions
                RefractionUtil::resetBudget();
                for (const RenderPassCuller::VisibleNode& node : nodeCache) {
                    const SceneGraphNode* nodePtr = node.second;
                    RenderingComponent* const rComp = nodePtr->get<RenderingComponent>();
                    if (RefractionUtil::isInBudget()) {
                        bool isVisile = rComp->renderOptionEnabled(RenderingComponent::RenderOptions::IS_VISIBLE);
                        rComp->toggleRenderOption(RenderingComponent::RenderOptions::IS_VISIBLE, false);
                        if (Attorney::RenderingCompRenderPass::updateRefraction(*rComp,
                                                                                RefractionUtil::currentEntry(),
                                                                                params.camera,
                                                                                renderState,
                                                                                commandBuffer))
                        {
                            RefractionUtil::updateBudget();
                        }
                        rComp->toggleRenderOption(RenderingComponent::RenderOptions::IS_VISIBLE, isVisile);
                    }  else {
                        Attorney::RenderingCompRenderPass::clearRefraction(*rComp);
                    }
                }

                GFX::EndDebugScopeCommand endDebugScopeCmd;
                GFX::EndDebugScope(commandBuffer, endDebugScopeCmd);
            }
        } break;
    };

    _context.flushCommandBuffer(commandBuffer);
}

// This is very hackish but should hold up fine
U32 RenderPass::getBufferCountForStage(RenderStage stage) const {
    U32 maxPasses = 0;
    U32 maxStages = 0;

    //We only care about the first parameter as it will determine the properties for the rest of the stages
    switch (stage) {
        case RenderStage::REFLECTION: { //Both planar and cube
            // max reflective nodes and an extra buffer for environment maps
            maxPasses = Config::MAX_REFLECTIVE_NODES_IN_VIEW * 2+ 1;
            maxStages = 6u; // number of cube faces
        }; break;
        case RenderStage::REFRACTION: { //Both planar and cube
            // max reflective nodes and an extra buffer for environment maps
            maxPasses = Config::MAX_REFRACTIVE_NODES_IN_VIEW * 2 + 1;
            maxStages = 1u;
        } break;
        case RenderStage::SHADOW: {
            maxPasses = Config::Lighting::MAX_SHADOW_CASTING_LIGHTS;
            // Either CSM or cube map will have the highest stage count.
            maxStages = std::max(Config::Lighting::MAX_SPLITS_PER_LIGHT, 6u);// number of cube faces
        }; break;
        case RenderStage::DISPLAY: {
            maxPasses = 1;
            maxStages = 1;
        }; break;
    };


    return maxPasses * maxStages;
}

};

Commits for Divide-Framework/trunk/Source Code/Rendering/RenderPass/RenderPass.cpp

Diff revisions: vs.
Revision Author Commited Message
950 Diff Diff IonutCava picture IonutCava Sun 22 Oct, 2017 22:25:05 +0000

[Ionut]
- Revamp camera management
- More work on improving the command buffer system:
— Performance tweaks
— Validation
— Debug features
- Some code cleanup for Object3D stuff (preRender/onRender changes)

Still haven’t fixed random flashing issue

947 Diff Diff IonutCava picture IonutCava Sun 08 Oct, 2017 22:36:54 +0000

[Ionut]
- Refactor command buffer pooling
- Remove all static commands in an attempt to fix rendering issues. Profile and rework later.

942 Diff Diff IonutCava picture IonutCava Wed 06 Sep, 2017 20:45:37 +0000

[Ionut]
- Add more DLLs required by CEGUI
- Move CommandBuffer allocation from GFXDevice to GFX namespace

940 Diff Diff IonutCava picture IonutCava Fri 18 Aug, 2017 16:18:44 +0000

[Ionut]
- Generate GFX::CommandBuffers only from GFX::CommandBufferPools.
— We shouldn’t be allocating any new GFX::CommandBuffers at runtime now.
— ToDo: Add a similar system for Pipelines
- Add 2 command buffer pools to GFXDevice: a primary one used for rendering and a large, secondary one used for command generation

935 Diff Diff IonutCava picture IonutCava Tue 15 Aug, 2017 21:10:25 +0000

[IonutCava]
- Added debug scope (GL’s debug group) commands
- More bug fixes and optimizations

933 Diff Diff IonutCava picture IonutCava Tue 15 Aug, 2017 00:02:05 +0000

[Ionut]
- CommandBuffer Part 2/3: code compiles and splash screen renders and application doesn’t crash (still has drawing issues)

929 Diff Diff IonutCava picture IonutCava Sat 12 Aug, 2017 17:34:44 +0000

[Ionut]
- More work on finishing up new PushConstant / Command buffer rendering system:
— Everything compiles and runs but with graphical and performance issues

924 Diff Diff IonutCava picture IonutCava Wed 02 Aug, 2017 20:29:19 +0000

[Ionut]
- Rework RenderTarget binding. Now access is only available via the GFXRTPool
- Split RenderPassManager::doCustomPass into multiple steps for easier debugging and cleaner code
- Other small code cleanups

912 Diff Diff IonutCava picture IonutCava Sun 02 Jul, 2017 23:42:39 +0000

[Ionut]
- Add experimental Weighted Blended Order Independed Transparency (ref: http://casual-effects.blogspot.co.uk/2015/03/implemented-weighted-blended-order.html)
— Add per drawbuffer blend
— All translucent renderbin items go via the new OIT 2-step rendering: accumulation and composition
- Make sure we have proper blend enabled for text rendering
- Add a primitive form of PushConstants (unused yet. Emulated via Uniform calls)
- Fix bug with XMLParser not using case insensitive key lookups

893 IonutCava picture IonutCava Sun 18 Jun, 2017 17:33:07 +0000

[Ionut]
- Initial implementation of a PipelineStateObject (holds shader program, rasterizer state, etc)
- Rework PCH implementation a bit because VS2017 no longer has a /ZM option