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
#include "Headers/RenderQueue.h"

#include "Core/Headers/Console.h"
#include "Core/Headers/TaskPool.h"
#include "Utility/Headers/Localization.h"
#include "Graphs/Headers/SceneGraphNode.h"
#include "Geometry/Shapes/Headers/Object3D.h"
#include "Geometry/Material/Headers/Material.h"

namespace Divide {

RenderQueue::RenderQueue()
{
    _renderBins.fill(nullptr);
}

RenderQueue::~RenderQueue()
{
    for (RenderBin* bin : _renderBins) {
        MemoryManager::DELETE(bin);
    }
    _renderBins.fill(nullptr);
    _activeBins.clear();
}

U16 RenderQueue::getRenderQueueStackSize() const {
    U16 temp = 0;
    for (RenderBin* bin : _activeBins) {
        temp += bin->getBinSize();
    }
    return temp;
}

RenderBin* RenderQueue::getOrCreateBin(RenderBinType rbType) {
    RenderBin* temp = getBin(rbType);
    if (temp != nullptr) {
        return temp;
    }

    RenderingOrder::List sortOrder = RenderingOrder::List::COUNT;
    switch (rbType) {
        case RenderBinType::RBT_OPAQUE: {
            // By state varies based on the current rendering stage
            sortOrder = RenderingOrder::List::BY_STATE;
        } break;
        case RenderBinType::RBT_SKY: {
            sortOrder = RenderingOrder::List::NONE;
        } break;
        case RenderBinType::RBT_IMPOSTOR:
        case RenderBinType::RBT_TERRAIN:
        case RenderBinType::RBT_DECALS: {
            sortOrder = RenderingOrder::List::FRONT_TO_BACK;
        } break;
        case RenderBinType::RBT_WATER:
        case RenderBinType::RBT_VEGETATION_GRASS:
        case RenderBinType::RBT_PARTICLES:
        case RenderBinType::RBT_TRANSLUCENT: {
            sortOrder = RenderingOrder::List::BACK_TO_FRONT;
        } break;

        default: {
            Console::errorfn(Locale::get(_ID("ERROR_INVALID_RENDER_BIN_CREATION")));
            return nullptr;
        } break;
    };

    temp = MemoryManager_NEW RenderBin(rbType, sortOrder);
    // Bins are sorted by their type
    _renderBins[rbType._to_integral()] = temp;
    
    _activeBins.resize(0);
    for (RenderBin* bin : _renderBins) {
        if (bin != nullptr) {
            _activeBins.push_back(bin);
        }
    }

    return temp;
}

RenderBin* RenderQueue::getBinForNode(const std::shared_ptr<SceneNode>& node,
                                      const Material_ptr& matInstance) {
    assert(node != nullptr);
    switch (node->getType()) {
        case SceneNodeType::TYPE_LIGHT: {
            return getOrCreateBin(RenderBinType::RBT_IMPOSTOR);
        }
        case SceneNodeType::TYPE_WATER: {
            return getOrCreateBin(RenderBinType::RBT_WATER);
        }
        case SceneNodeType::TYPE_PARTICLE_EMITTER: {
            return getOrCreateBin(RenderBinType::RBT_PARTICLES);
        }
        case SceneNodeType::TYPE_VEGETATION_GRASS: {
            return getOrCreateBin(RenderBinType::RBT_VEGETATION_GRASS);
        }
        case SceneNodeType::TYPE_SKY: {
            return getOrCreateBin(RenderBinType::RBT_SKY);
        }
        case SceneNodeType::TYPE_VEGETATION_TREES:
        case SceneNodeType::TYPE_OBJECT3D: {
            if (static_cast<Object3D*>(node.get())->getObjectType() ==
                Object3D::ObjectType::TERRAIN) {
                return getOrCreateBin(RenderBinType::RBT_TERRAIN);
            }
            // Check if the object has a material with translucency
            if (matInstance && matInstance->isTranslucent()) {
                // Add it to the appropriate bin if so ...
                return getOrCreateBin(RenderBinType::RBT_TRANSLUCENT);
            }
            //... else add it to the general geometry bin
            return getOrCreateBin(RenderBinType::RBT_OPAQUE);
        }
    }
    return nullptr;
}

void RenderQueue::addNodeToQueue(const SceneGraphNode& sgn, RenderStage stage, const vec3<F32>& eyePos) {
    static Material_ptr defaultMat;

    RenderingComponent* const renderingCmp = sgn.get<RenderingComponent>();
    RenderBin* rb = getBinForNode(sgn.getNode(),
                                  renderingCmp
                                    ? renderingCmp->getMaterialInstance()
                                    : defaultMat);
    if (rb) {
        rb->addNodeToBin(sgn, stage, eyePos);
    }
}

void RenderQueue::populateRenderQueues(RenderStage renderStage) {
    TaskHandle populateTask = CreateTask(DELEGATE_CBK_PARAM<bool>());
    for (RenderBin* renderBin : _activeBins) {
        if (!renderBin->empty()) {
            populateTask.addChildTask(CreateTask(DELEGATE_BIND(&RenderBin::populateRenderQueue,
                                                               renderBin,
                                                               std::placeholders::_1,
                                                               renderStage))._task)->startTask(Task::TaskPriority::HIGH);      
        }
    }
    populateTask.startTask(Task::TaskPriority::MAX);
    populateTask.wait();
}

void RenderQueue::postRender(const SceneRenderState& renderState, RenderStage renderStage, RenderSubPassCmds& subPassesInOut) {
    for (RenderBin* renderBin : _activeBins) {
        renderBin->postRender(renderState, renderStage, subPassesInOut);
    }
}

void RenderQueue::sort(RenderStage renderStage) {
    U32 index = 0;
    for (RenderBin* renderBin : _activeBins) {
        renderBin->binIndex(index);
        index += renderBin->getBinSize();
    }

    TaskHandle sortTask = CreateTask(DELEGATE_CBK_PARAM<bool>());
    for (RenderBin* renderBin : _activeBins) {
        if (!renderBin->empty()) {
            sortTask.addChildTask(CreateTask(DELEGATE_BIND(&RenderBin::sort,
                                                        renderBin,
                                                        std::placeholders::_1,
                                                        renderStage))._task)->startTask(Task::TaskPriority::HIGH);
        }
    }
    sortTask.startTask(Task::TaskPriority::MAX);
    sortTask.wait();
}

void RenderQueue::refresh() {
    for (RenderBin* renderBin : _activeBins) {
        renderBin->refresh();
    }
}

};

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

Diff revisions: vs.
Revision Author Commited Message
781 Diff Diff IonutCava picture IonutCava Wed 12 Oct, 2016 16:03:46 +0000

[IonutCava]
- ShaderComputeQueue <-> Material shader request bug fix (element stuck in QUEUED state)
- More Camera class cleanups
- Add a method of removing EnvironmentProbes from their Pool

777 Diff Diff IonutCava picture IonutCava Fri 07 Oct, 2016 16:14:48 +0000

[IonutCava]
- Continue to implement CommandBuffer / RenderPass / RenderSubPass system.
— Rendering artefacts are still present.

760 Diff Diff IonutCava picture IonutCava Tue 09 Aug, 2016 16:30:12 +0000

[IonutCava]
- Complete rewrite of RenderPass system:
— Allow every rendering pass (reflection, environment, etc) to use the same rendering system: occlusion culling, light culling, etc
— Define render passes by a param based token similar to modern API systems (DX12/Vulkan)
— W.I.P.: Depth rendering slightly wrong; Environment Mapping ,reflection and refraction rendering currently disabled
- Add compile time variables for DEBUG/PROFILE/RELEASE builds to validate all code for every build

744 Diff Diff IonutCava picture IonutCava Tue 28 Jun, 2016 21:43:58 +0000

[IonutCava]
- More performance tweaks

712 Diff Diff IonutCava picture IonutCava Tue 24 May, 2016 16:18:37 +0000

[IonutCava]
- Added the concept of “buffer” to be used by GenericVertexData and ShaderBuffer without caring if it’s persistent or not.
— Persistent buffers handle their own locking instead of relying on the parent class
- HiZ occlusion culling fixes and optimizations

710 Diff Diff IonutCava picture IonutCava Fri 20 May, 2016 16:24:40 +0000

[IonutCava]
- Code cleanup
- Initial work on Scene loading and unloading with and without unloading assets:
— Need to change AIManager from a Singleton to a per-scene component

709 Diff Diff IonutCava picture IonutCava Thu 19 May, 2016 16:21:46 +0000

[IonutCava]
- Massive rewrite of the resource system:
— ResourceCache now uses a map of weak pointers and passes shared pointers to the call point of CreateResource
— RemoveResource is no longer needed, but resource based smart pointers use a custom deleter that calls unload()
— Keep a shared_ptr of the resource in the entity that needs it and pass shared_ptr references from getter methods
-— All of this removed the need for calls to RemoveResource, REGISTER_TRACKED_DEPENDENCY and UNREGISTER_TRACKED_DEPENDENCY reducing the number of mutex locks and atomic exchanges
- Singleton cleanup:
— Removed ShaderManager singleton and merged it’s data and responsibilities in static methods in both ShaderProgram and Shader classes.
Explanation: Due to the complex interdependency chains in the system, copying, updating, tracking the cache in a thread safe way became a lot more slower than a straight forward smart pointer based implementation. (e.g. scene graph nodes have 3d objects and material instances, 3d objects have materials, materials have textures and shaders, etc)

669 Diff Diff IonutCava picture IonutCava Mon 04 Apr, 2016 16:15:35 +0000

[IonutCava]
- Move Task creation calls to TaskPool.h
- Allow tasks to use any pool, but default behaviour is to use the Kernel’s main task pool
- Change image transparency check to use the task pool instead of OpenMP
— Perfect place for future parallel_for implementation
- Warning fixes
- Some method renaming for improved readability

664 Diff Diff IonutCava picture IonutCava Wed 30 Mar, 2016 16:23:51 +0000

[IonutCava]
- Split some render bin loops into multiple tasks
- Cleaned up the Task class
- Attempt to improve Console multithreaded performance (does not compile yet)

663 IonutCava picture IonutCava Tue 29 Mar, 2016 16:07:31 +0000

[IonutCava]
- Reworked task parent<->children system to allow child tasks to be started immediately after creation (to get adding and running to run in parallel)
- Added locked variable support to the debugging system