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
#include "stdafx.h"

#include "Headers/RenderPackage.h"

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

namespace Divide {

RenderPackage::RenderPackage(GFXDevice& context, bool useSecondaryBuffers)
    : _context(context),
      _isRenderable(false),
      _isOcclusionCullable(true),
      _secondaryCommandPool(useSecondaryBuffers),
      _commands(nullptr),
      _drawCommandDirty(true),
      _pipelineDirty(true),
      _clipPlanesDirty(true),
      _pushConstantsDirty(true),
      _descriptorSetsDirty(true)
{
}

RenderPackage::~RenderPackage()
{
    if (_commands != nullptr) {
        GFX::deallocateCommandBuffer(_commands, _secondaryCommandPool);
    }
}

void RenderPackage::clear() {
    _commands->clear();
    _drawCommands.clear();
    _pipelines.clear();
    _clipPlanes.clear();
    _pushConstants.clear();

    _drawCommandDirty = _pipelineDirty = _clipPlanesDirty = _pushConstantsDirty = _descriptorSetsDirty = true;
}

void RenderPackage::set(const RenderPackage& other) {
    *_commands = *other._commands;
}

size_t RenderPackage::getSortKeyHash() const {
    if (!_pipelines.empty()) {
        return _pipelines.front()._pipeline.getHash();
    }

    return 0;
}

I32 RenderPackage::drawCommandCount() const {
    return to_I32(_drawCommands.size());
}

const GFX::DrawCommand& RenderPackage::drawCommand(I32 index) const {
    DIVIDE_ASSERT(index < to_I32(_drawCommands.size()), "RenderPackage::drawCommand error: Invalid draw command index!");
    return _drawCommands[index];
}

GFX::DrawCommand& RenderPackage::drawCommand(I32 cmdIdx) {
    DIVIDE_ASSERT(cmdIdx < to_I32(_drawCommands.size()), "RenderPackage::drawCommand error: Invalid draw command index!");
    return _drawCommands[cmdIdx];
}

const GenericDrawCommand& RenderPackage::drawCommand(I32 index, I32 cmdIndex) const {
    DIVIDE_ASSERT(index < to_I32(_drawCommands.size()), "RenderPackage::drawCommand error: Invalid draw command index!");
    DIVIDE_ASSERT(cmdIndex < to_I32(_drawCommands[index]._drawCommands.size()), "RenderPackage::drawCommand error: Invalid draw command sub-index!");
    return _drawCommands[index]._drawCommands[cmdIndex];
}

void RenderPackage::drawCommand(I32 index, I32 cmdIndex, const GenericDrawCommand& cmd) {
    DIVIDE_ASSERT(index < to_I32(_drawCommands.size()), "RenderPackage::drawCommand error: Invalid draw command index!");
    DIVIDE_ASSERT(cmdIndex < to_I32(_drawCommands[index]._drawCommands.size()), "RenderPackage::drawCommand error: Invalid draw command sub-index!");
    _drawCommands[index]._drawCommands[cmdIndex] = cmd;
    _drawCommandDirty = true;
}

void RenderPackage::addDrawCommand(const GFX::DrawCommand& cmd) {
    CommandEntry entry;
    entry._type = GFX::CommandType::DRAW_COMMANDS;
    entry._index = _drawCommands.size();
    _commandOrdering.push_back(entry);

    _drawCommands.push_back(cmd);
}

const Pipeline& RenderPackage::pipeline(I32 index) const {
    DIVIDE_ASSERT(index < to_I32(_pipelines.size()), "RenderPackage::pipeline error: Invalid pipeline index!");
    return _pipelines[index]._pipeline;
}

void RenderPackage::pipeline(I32 index, const Pipeline& pipeline) {
    DIVIDE_ASSERT(index < to_I32(_pipelines.size()), "RenderPackage::pipeline error: Invalid pipeline index!");
    _pipelines[index]._pipeline.fromDescriptor(pipeline.toDescriptor());
    _pipelineDirty = true;
}

void RenderPackage::addPipelineCommand(const GFX::BindPipelineCommand& pipeline) {
    CommandEntry entry;
    entry._type = GFX::CommandType::BIND_PIPELINE;
    entry._index = _pipelines.size();
    _commandOrdering.push_back(entry);

    _pipelines.push_back(pipeline);
}

const ClipPlaneList& RenderPackage::clipPlanes(I32 index) const {
    DIVIDE_ASSERT(index < to_I32(_clipPlanes.size()), "RenderPackage::clipPlanes error: Invalid clip plane list index!");
    return _clipPlanes[index]._clippingPlanes;
}

void RenderPackage::clipPlanes(I32 index, const ClipPlaneList& clipPlanes) {
    DIVIDE_ASSERT(index < to_I32(_clipPlanes.size()), "RenderPackage::clipPlanes error: Invalid clip plane list index!");
    _clipPlanes[index]._clippingPlanes = clipPlanes;
    _clipPlanesDirty = true;
}

void RenderPackage::addClipPlanesCommand(const GFX::SetClipPlanesCommand& clipPlanes) {
    CommandEntry entry;
    entry._type = GFX::CommandType::SET_CLIP_PLANES;
    entry._index = _clipPlanes.size();
    _commandOrdering.push_back(entry);

    _clipPlanes.push_back(clipPlanes);
}

const PushConstants& RenderPackage::pushConstants(I32 index) const {
    DIVIDE_ASSERT(index < to_I32(_pushConstants.size()), "RenderPackage::pushConstants error: Invalid push constants index!");
    return _pushConstants[index]._constants;
}

void RenderPackage::pushConstants(I32 index, const PushConstants& constants) {
    DIVIDE_ASSERT(index < to_I32(_pushConstants.size()), "RenderPackage::pushConstants error: Invalid push constants index!");
    _pushConstants[index]._constants = constants;
    _pushConstantsDirty = true;
}

void RenderPackage::addPushConstantsCommand(const GFX::SendPushConstantsCommand& pushConstants) {
    CommandEntry entry;
    entry._type = GFX::CommandType::SEND_PUSH_CONSTANTS;
    entry._index = _pushConstants.size();
    _commandOrdering.push_back(entry);

    _pushConstants.push_back(pushConstants);
}

const DescriptorSet& RenderPackage::descriptorSet(I32 index) const {
    DIVIDE_ASSERT(index < to_I32(_descriptorSets.size()), "RenderPackage::descriptorSet error: Invalid descriptor set index!");
    return _descriptorSets[index]._set;
}

void RenderPackage::descriptorSet(I32 index, const DescriptorSet& descriptorSets) {
    DIVIDE_ASSERT(index < to_I32(_descriptorSets.size()), "RenderPackage::descriptorSet error: Invalid descriptor set index!");
    _descriptorSets[index]._set = descriptorSets;
    _descriptorSetsDirty = true;
}

void RenderPackage::addDescriptorSetsCommand(const GFX::BindDescriptorSetsCommand& descriptorSets) {
    CommandEntry entry;
    entry._type = GFX::CommandType::BIND_DESCRIPTOR_SETS;
    entry._index = _descriptorSets.size();
    _commandOrdering.push_back(entry);

    _descriptorSets.push_back(descriptorSets);
}

void RenderPackage::addCommandBuffer(const GFX::CommandBuffer& commandBuffer) {
    const vectorImpl<std::shared_ptr<GFX::Command>>& commands = commandBuffer();
    for (const std::shared_ptr<GFX::Command>& cmd : commands) {
        switch (cmd->_type) {
            case GFX::CommandType::DRAW_COMMANDS: {
                addDrawCommand(static_cast<GFX::DrawCommand&>(*cmd.get()));
            } break;
            case GFX::CommandType::BIND_PIPELINE: {
                addPipelineCommand(static_cast<GFX::BindPipelineCommand&>(*cmd.get()));
            } break;
            case GFX::CommandType::SET_CLIP_PLANES: {
                addClipPlanesCommand(static_cast<GFX::SetClipPlanesCommand&>(*cmd.get()));
            } break;
            case GFX::CommandType::SEND_PUSH_CONSTANTS: {
                addPushConstantsCommand(static_cast<GFX::SendPushConstantsCommand&>(*cmd.get()));
            } break;
            case GFX::CommandType::BIND_DESCRIPTOR_SETS: {
                addDescriptorSetsCommand(static_cast<GFX::BindDescriptorSetsCommand&>(*cmd.get()));
            } break;
            default:
            case GFX::CommandType::COUNT: {
                DIVIDE_ASSERT(false,
                              "RenderPackage::addCommandBuffer error: Specified command buffer "
                              "contains commands that are not supported for this stage");
            } break;
        };
    }
}

const GFX::CommandBuffer& RenderPackage::commands() const {
    return *_commands;
}

bool RenderPackage::buildCommandBuffer() {
    //ToDo: Try to rebuild only the affected bits and pieces. That's why we have multiple dirty flags -Ionut
    if (_commands == nullptr || _drawCommandDirty || _pipelineDirty || _clipPlanesDirty || _pushConstantsDirty || _descriptorSetsDirty) {
        if (_commands == nullptr) {
            _commands = GFX::allocateCommandBuffer(_secondaryCommandPool);
        }

        for (const CommandEntry& cmd : _commandOrdering) {
            switch (cmd._type) {
                case GFX::CommandType::DRAW_COMMANDS: {
                    addDrawCommand(_drawCommands[cmd._index]);
                } break;
                case GFX::CommandType::BIND_PIPELINE: {
                    addPipelineCommand(_pipelines[cmd._index]);
                } break;
                case GFX::CommandType::SET_CLIP_PLANES: {
                    addClipPlanesCommand(_clipPlanes[cmd._index]);
                } break;
                case GFX::CommandType::SEND_PUSH_CONSTANTS: {
                    addPushConstantsCommand(_pushConstants[cmd._index]);
                } break;
                case GFX::CommandType::BIND_DESCRIPTOR_SETS: {
                    addDescriptorSetsCommand(_descriptorSets[cmd._index]);
                } break;
                default:
                case GFX::CommandType::COUNT: {
                    DIVIDE_ASSERT(false,
                                  "RenderPackage::addCommandBuffer error: Specified command buffer "
                                  "contains commands that are not supported for this stage");
                } break;
            }
        }

        _drawCommandDirty = _pipelineDirty = _clipPlanesDirty = _pushConstantsDirty = _descriptorSetsDirty = false;
        return true;
    }
    return false;
}

}; //namespace Divide

Commits for Divide-Framework/trunk/Source Code/Platform/Video/RenderPackage.cpp

Diff revisions: vs.
Revision Author Commited Message
949 Diff Diff IonutCava picture IonutCava Thu 19 Oct, 2017 21:48:37 +0000

[Ionut]
- More command buffer refactoring

948 Diff Diff IonutCava picture IonutCava Tue 17 Oct, 2017 22:41:09 +0000

[Ionut]
- Move rendering data caching outside of CommandBuffer and into RenderPackage for better control.

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.

943 Diff Diff IonutCava picture IonutCava Tue 12 Sep, 2017 11:38:52 +0000

[IonutCava]
- Rework ThreadPool/Task system for clearer parent<->child relationship between tasks
— Disable Prio pool since it doesn’t work properly with the newest boost libraries
— Modify the C++11 threadpool to remove the boost dependency
- Reduce memory usage by allocating command buffers on use instead of on creation

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

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)

930 Diff Diff IonutCava picture IonutCava Sun 13 Aug, 2017 20:33:31 +0000

[Ionut]
- Fix a bug with Push Constant to Uniform conversion
- Add more push constant types
- Fix RENDER_INDIRECT param for draw commands
- Cleanup Sky, Terrain and Vegetation a bit

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

890 IonutCava picture IonutCava Sun 14 May, 2017 20:54:59 +0000

[Ionut]
- Add pre-compiled header support
- Initial code for per-stage tessellation computation