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
#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)
{
    ShaderBufferParams params;
    params._primitiveCount = Config::MAX_VISIBLE_NODES;
    params._primitiveSizeInBytes = sizeof(GFXDevice::NodeData);
    params._ringBufferLength = 1;
    params._unbound = true;
    params._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(params);

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

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

RenderPass::BufferDataPool::BufferDataPool(GFXDevice& context, U32 maxBuffers)
{
    // 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
    for (U32 j = 0; j < maxBuffers; ++j) {
        BufferData* data = MemoryManager_NEW BufferData(context);
        _buffers.push_back(data);
    }
}

RenderPass::BufferDataPool::~BufferDataPool()
{
    for (BufferData* buffer : _buffers) {
        MemoryManager::DELETE(buffer);
    }
}

RenderPass::BufferData& RenderPass::BufferDataPool::getBufferData(I32 bufferIndex) {
    assert(bufferIndex >= 0);

    return *_buffers[bufferIndex];
}

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);

    _drawCommandsCache.reserve(Config::MAX_VISIBLE_NODES);
}

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

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

void RenderPass::generateDrawCommands() {
    _drawCommandsCache.resize(0);
}

void RenderPass::render(SceneRenderState& renderState) {
    if (_stageFlag != RenderStage::SHADOW) {
        LightPool::bindShadowMaps(_context);
    }

    switch(_stageFlag) {
        case RenderStage::DISPLAY: {
            GFX::ScopedDebugMessage msg(_context, "Display Render Stage", 0);

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

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

        } break;
        case RenderStage::SHADOW: {
            GFX::ScopedDebugMessage msg(_context, "Shadow Render Stage", 1);

            Attorney::SceneManagerRenderPass::generateShadowMaps(_parent.parent().sceneManager());
        } break;
        case RenderStage::REFLECTION: {
            SceneManager& mgr = _parent.parent().sceneManager();
            RenderPassManager::PassParams params;
            params.pass = Config::MAX_REFLECTIVE_NODES_IN_VIEW;
            params.camera = Attorney::SceneManagerRenderPass::getActiveCamera(_parent.parent().sceneManager());

            {
                GFX::ScopedDebugMessage msg(_context, "Cube Reflection Stage", 2);
                //Part 1 - update envirnoment maps:
                /*SceneEnvironmentProbePool* envProbPool =  Attorney::SceneRenderPass::getEnvProbes(renderState.parentScene());
                const EnvironmentProbeList& probes = envProbPool->getNearestSorted();
                for (EnvironmentProbe_ptr& probe : probes) {
                    probe->refresh();
                }
                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::ScopedDebugMessage msg(_context, "Planar Reflection Stage", 3);

                //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->isVisible();
                        rComp->setVisible(false);
                        if (Attorney::RenderingCompRenderPass::updateReflection(*rComp,
                                                                                 ReflectionUtil::currentEntry(),
                                                                                 params.camera,
                                                                                 renderState)) {

                            ReflectionUtil::updateBudget();
                        }
                        rComp->setVisible(isVisile);
                    }
                    else {
                        Attorney::RenderingCompRenderPass::clearReflection(*rComp);
                    }
                }
            }
        } 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::SceneManagerRenderPass::getActiveCamera(_parent.parent().sceneManager());

            {
                GFX::ScopedDebugMessage msg(_context, "Cube Refraction Stage", 4);
            }
            {
                GFX::ScopedDebugMessage msg(_context, "Planar Refraction Stage", 5);
                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->isVisible();
                        rComp->setVisible(false);
                        if (Attorney::RenderingCompRenderPass::updateRefraction(*rComp,
                                                                                RefractionUtil::currentEntry(),
                                                                                params.camera,
                                                                                renderState))
                        {
                            RefractionUtil::updateBudget();
                        }
                        rComp->setVisible(isVisile);
                    }
                    else {
                        Attorney::RenderingCompRenderPass::clearRefraction(*rComp);
                    }
                }
            }
        } break;
    };
}

// 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
853 Diff Diff IonutCava picture IonutCava Tue 07 Feb, 2017 21:43:58 +0000

[IonutCava]
- More work on water rendering.

852 Diff Diff IonutCava picture IonutCava Tue 07 Feb, 2017 17:17:27 +0000

[IonutCava]
- Separate Pass Type from Render Stage:
— Render Stage: Display, Shadow, Reflection, Refraction, etc
— Pass Type: Depth pass, Colour Pass, etc
- ToDo: Bug fixes for issues introduced with this change

850 Diff Diff IonutCava picture IonutCava Mon 06 Feb, 2017 17:04:39 +0000

[IonutCava]
- More code rot fixes
- Separate Planar reflectors/refractors from Cube R/R
- Now passing detail levels to shaders

849 Diff Diff IonutCava picture IonutCava Mon 06 Feb, 2017 13:04:17 +0000

[IonutCava]
- Add a debug message push/pop system to make frame analysis in external apps easier (e.g. in RenderDoc)

847 Diff Diff IonutCava picture IonutCava Sun 05 Feb, 2017 21:16:24 +0000

[IonutCava]
- Code rot fixes:
— Terrain loading (8 bit heightmap only for now)
— Terrain rendering
— Water Plane loading and rendering
— Reflection and Refraction rendering passes (hack for now: need environment cubemaps as separate from reflect/refract maps for planar rendering)
-— ToDo: Separate Reflection / Refraction render targets to Planar R/R and Cube R/R. Environment probes should use Cube Reflections, Water should use planar reflection targets.
- Added a way to register debug views: texture, shader and params. Viewports get automatically scaled and positioned
— ToDo: Add a hover-preview feature
— ToDo: Add a click-lock preview feature

827 Diff Diff IonutCava picture IonutCava Sun 22 Jan, 2017 21:59:36 +0000

[IonutCava]
- ShaderBuffers now decide heuristically if they get persistently mapped or not (depends on size. Current limit is 512Kb for subData calls.
- Separate visible node command generation into 2 steps: onRender and getDrawPackage. onRender allows the creation of parallel tasks that should finish by the time the second call, getDrawPackage reaches the same node
- Update ParticleEmitter to take into account multiple players and increase parallelism at the cost of memory consumption and complexity.
- Add a default bounding box for Players (add extents to SceneTransform nodes)
- All buffers (ShaderBuffer, d3dConstantBuffer, glUniformBuffer, glBufferImpl, glGenericBuffer, etc) use BufferParams for creation.
— Constructor and create calls have been merged together

824 Diff Diff IonutCava picture IonutCava Thu 19 Jan, 2017 17:18:03 +0000

[IonutCava]
- Prev Frame attachment system removed from RenderTargets
— Concept too high level for RT. Moved prev depth buffer to GFX class
- Other small optimizations.

815 Diff Diff IonutCava picture IonutCava Thu 12 Jan, 2017 23:33:01 +0000

[IonutCava]
- Fixed viewport alignment issue
- Added per-player RenderTargets (added index support to GFXRTPool)
- Initial implementation of per-player cameras
— Removed defaultCamera
— Scenes now use a baseCamera as a template for new player cameras

809 Diff Diff IonutCava picture IonutCava Tue 10 Jan, 2017 17:16:26 +0000

[IonutCava]
- Move velocity calc to the normal colour pass.
- Optimise glFramebuffer and cleanup RTAttachment class

807 IonutCava picture IonutCava Mon 09 Jan, 2017 17:06:26 +0000

[IonutCava]
- Split PlatformDefines.h into 2. Move data type defines to PlatformDataTypes.h
- Continue to improve velocity map calculation
- Remove “destroy()” calls from most classes. Attempt to move as many classes to the RAII system.