Subversion Repository Public Repository

Divide-Framework

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

Diff Revisions 948 vs 949 for /trunk/Source Code/Platform/Video/RenderPackage.cpp

Diff revisions: vs.
  @@ -12,7 +12,7 @@
12 12 _isRenderable(false),
13 13 _isOcclusionCullable(true),
14 14 _secondaryCommandPool(useSecondaryBuffers),
15 - _commands(GFX::allocateCommandBuffer(useSecondaryBuffers)),
15 + _commands(nullptr),
16 16 _drawCommandDirty(true),
17 17 _pipelineDirty(true),
18 18 _clipPlanesDirty(true),
  @@ -23,7 +23,9 @@
23 23
24 24 RenderPackage::~RenderPackage()
25 25 {
26 - GFX::deallocateCommandBuffer(_commands, _secondaryCommandPool);
26 + if (_commands != nullptr) {
27 + GFX::deallocateCommandBuffer(_commands, _secondaryCommandPool);
28 + }
27 29 }
28 30
29 31 void RenderPackage::clear() {
  @@ -42,108 +44,198 @@
42 44
43 45 size_t RenderPackage::getSortKeyHash() const {
44 46 if (!_pipelines.empty()) {
45 - return _pipelines.front().getHash();
47 + return _pipelines.front()._pipeline.getHash();
46 48 }
47 49
48 50 return 0;
49 51 }
50 52
51 - size_t RenderPackage::drawCommandCount() const {
52 - return _drawCommands.size();
53 + I32 RenderPackage::drawCommandCount() const {
54 + return to_I32(_drawCommands.size());
53 55 }
54 56
55 - GenericDrawCommand& RenderPackage::drawCommand(I32 index) {
57 + const GFX::DrawCommand& RenderPackage::drawCommand(I32 index) const {
56 58 DIVIDE_ASSERT(index < to_I32(_drawCommands.size()), "RenderPackage::drawCommand error: Invalid draw command index!");
57 59 return _drawCommands[index];
58 60 }
59 61
60 - const GenericDrawCommand& RenderPackage::drawCommand(I32 index) const {
62 + GFX::DrawCommand& RenderPackage::drawCommand(I32 cmdIdx) {
63 + DIVIDE_ASSERT(cmdIdx < to_I32(_drawCommands.size()), "RenderPackage::drawCommand error: Invalid draw command index!");
64 + return _drawCommands[cmdIdx];
65 + }
66 +
67 + const GenericDrawCommand& RenderPackage::drawCommand(I32 index, I32 cmdIndex) const {
61 68 DIVIDE_ASSERT(index < to_I32(_drawCommands.size()), "RenderPackage::drawCommand error: Invalid draw command index!");
62 - return _drawCommands[index];
69 + DIVIDE_ASSERT(cmdIndex < to_I32(_drawCommands[index]._drawCommands.size()), "RenderPackage::drawCommand error: Invalid draw command sub-index!");
70 + return _drawCommands[index]._drawCommands[cmdIndex];
63 71 }
64 72
65 - void RenderPackage::drawCommand(I32 index, const GenericDrawCommand cmd) {
73 + void RenderPackage::drawCommand(I32 index, I32 cmdIndex, const GenericDrawCommand& cmd) {
66 74 DIVIDE_ASSERT(index < to_I32(_drawCommands.size()), "RenderPackage::drawCommand error: Invalid draw command index!");
67 - _drawCommands[index].set(cmd);
75 + DIVIDE_ASSERT(cmdIndex < to_I32(_drawCommands[index]._drawCommands.size()), "RenderPackage::drawCommand error: Invalid draw command sub-index!");
76 + _drawCommands[index]._drawCommands[cmdIndex] = cmd;
68 77 _drawCommandDirty = true;
69 78 }
70 79
71 80 void RenderPackage::addDrawCommand(const GFX::DrawCommand& cmd) {
72 - GFX::AddDrawCommands(*_commands, cmd);
73 - _drawCommands.insert(std::cend(_drawCommands),
74 - std::cbegin(cmd._drawCommands),
75 - std::cend(cmd._drawCommands));
81 + CommandEntry entry;
82 + entry._type = GFX::CommandType::DRAW_COMMANDS;
83 + entry._index = _drawCommands.size();
84 + _commandOrdering.push_back(entry);
85 +
86 + _drawCommands.push_back(cmd);
76 87 }
77 88
78 89 const Pipeline& RenderPackage::pipeline(I32 index) const {
79 90 DIVIDE_ASSERT(index < to_I32(_pipelines.size()), "RenderPackage::pipeline error: Invalid pipeline index!");
80 - return _pipelines[index];
91 + return _pipelines[index]._pipeline;
81 92 }
82 93
83 94 void RenderPackage::pipeline(I32 index, const Pipeline& pipeline) {
84 95 DIVIDE_ASSERT(index < to_I32(_pipelines.size()), "RenderPackage::pipeline error: Invalid pipeline index!");
85 - _pipelines[index].fromDescriptor(pipeline.toDescriptor());
96 + _pipelines[index]._pipeline.fromDescriptor(pipeline.toDescriptor());
86 97 _pipelineDirty = true;
87 98 }
88 99
89 100 void RenderPackage::addPipelineCommand(const GFX::BindPipelineCommand& pipeline) {
90 - GFX::BindPipeline(*_commands, pipeline);
91 - _pipelines.push_back(pipeline._pipeline);
101 + CommandEntry entry;
102 + entry._type = GFX::CommandType::BIND_PIPELINE;
103 + entry._index = _pipelines.size();
104 + _commandOrdering.push_back(entry);
105 +
106 + _pipelines.push_back(pipeline);
92 107 }
93 108
94 109 const ClipPlaneList& RenderPackage::clipPlanes(I32 index) const {
95 110 DIVIDE_ASSERT(index < to_I32(_clipPlanes.size()), "RenderPackage::clipPlanes error: Invalid clip plane list index!");
96 - return _clipPlanes[index];
111 + return _clipPlanes[index]._clippingPlanes;
97 112 }
98 113
99 114 void RenderPackage::clipPlanes(I32 index, const ClipPlaneList& clipPlanes) {
100 115 DIVIDE_ASSERT(index < to_I32(_clipPlanes.size()), "RenderPackage::clipPlanes error: Invalid clip plane list index!");
101 - _clipPlanes[index] = clipPlanes;
116 + _clipPlanes[index]._clippingPlanes = clipPlanes;
102 117 _clipPlanesDirty = true;
103 118 }
104 119
105 120 void RenderPackage::addClipPlanesCommand(const GFX::SetClipPlanesCommand& clipPlanes) {
106 - GFX::SetClipPlanes(*_commands, clipPlanes);
107 - _clipPlanes.push_back(clipPlanes._clippingPlanes);
121 + CommandEntry entry;
122 + entry._type = GFX::CommandType::SET_CLIP_PLANES;
123 + entry._index = _clipPlanes.size();
124 + _commandOrdering.push_back(entry);
125 +
126 + _clipPlanes.push_back(clipPlanes);
108 127 }
109 128
110 129 const PushConstants& RenderPackage::pushConstants(I32 index) const {
111 130 DIVIDE_ASSERT(index < to_I32(_pushConstants.size()), "RenderPackage::pushConstants error: Invalid push constants index!");
112 - return _pushConstants[index];
131 + return _pushConstants[index]._constants;
113 132 }
114 133
115 134 void RenderPackage::pushConstants(I32 index, const PushConstants& constants) {
116 135 DIVIDE_ASSERT(index < to_I32(_pushConstants.size()), "RenderPackage::pushConstants error: Invalid push constants index!");
117 - _pushConstants[index] = constants;
136 + _pushConstants[index]._constants = constants;
118 137 _pushConstantsDirty = true;
119 138 }
120 139
121 140 void RenderPackage::addPushConstantsCommand(const GFX::SendPushConstantsCommand& pushConstants) {
122 - GFX::SendPushConstants(*_commands, pushConstants);
123 - _pushConstants.push_back(pushConstants._constants);
141 + CommandEntry entry;
142 + entry._type = GFX::CommandType::SEND_PUSH_CONSTANTS;
143 + entry._index = _pushConstants.size();
144 + _commandOrdering.push_back(entry);
145 +
146 + _pushConstants.push_back(pushConstants);
124 147 }
125 148
126 149 const DescriptorSet& RenderPackage::descriptorSet(I32 index) const {
127 150 DIVIDE_ASSERT(index < to_I32(_descriptorSets.size()), "RenderPackage::descriptorSet error: Invalid descriptor set index!");
128 - return _descriptorSets[index];
151 + return _descriptorSets[index]._set;
129 152 }
130 153
131 154 void RenderPackage::descriptorSet(I32 index, const DescriptorSet& descriptorSets) {
132 155 DIVIDE_ASSERT(index < to_I32(_descriptorSets.size()), "RenderPackage::descriptorSet error: Invalid descriptor set index!");
133 - _descriptorSets[index] = descriptorSets;
156 + _descriptorSets[index]._set = descriptorSets;
134 157 _descriptorSetsDirty = true;
135 158 }
136 159
137 160 void RenderPackage::addDescriptorSetsCommand(const GFX::BindDescriptorSetsCommand& descriptorSets) {
138 - GFX::BindDescriptorSets(*_commands, descriptorSets);
139 - _descriptorSets.push_back(descriptorSets._set);
161 + CommandEntry entry;
162 + entry._type = GFX::CommandType::BIND_DESCRIPTOR_SETS;
163 + entry._index = _descriptorSets.size();
164 + _commandOrdering.push_back(entry);
165 +
166 + _descriptorSets.push_back(descriptorSets);
167 + }
168 +
169 + void RenderPackage::addCommandBuffer(const GFX::CommandBuffer& commandBuffer) {
170 + const vectorImpl<std::shared_ptr<GFX::Command>>& commands = commandBuffer();
171 + for (const std::shared_ptr<GFX::Command>& cmd : commands) {
172 + switch (cmd->_type) {
173 + case GFX::CommandType::DRAW_COMMANDS: {
174 + addDrawCommand(static_cast<GFX::DrawCommand&>(*cmd.get()));
175 + } break;
176 + case GFX::CommandType::BIND_PIPELINE: {
177 + addPipelineCommand(static_cast<GFX::BindPipelineCommand&>(*cmd.get()));
178 + } break;
179 + case GFX::CommandType::SET_CLIP_PLANES: {
180 + addClipPlanesCommand(static_cast<GFX::SetClipPlanesCommand&>(*cmd.get()));
181 + } break;
182 + case GFX::CommandType::SEND_PUSH_CONSTANTS: {
183 + addPushConstantsCommand(static_cast<GFX::SendPushConstantsCommand&>(*cmd.get()));
184 + } break;
185 + case GFX::CommandType::BIND_DESCRIPTOR_SETS: {
186 + addDescriptorSetsCommand(static_cast<GFX::BindDescriptorSetsCommand&>(*cmd.get()));
187 + } break;
188 + default:
189 + case GFX::CommandType::COUNT: {
190 + DIVIDE_ASSERT(false,
191 + "RenderPackage::addCommandBuffer error: Specified command buffer "
192 + "contains commands that are not supported for this stage");
193 + } break;
194 + };
195 + }
140 196 }
141 197
142 - GFX::CommandBuffer& RenderPackage::commands() {
198 + const GFX::CommandBuffer& RenderPackage::commands() const {
143 199 return *_commands;
144 200 }
145 201
146 - const GFX::CommandBuffer& RenderPackage::commands() const {
147 - return *_commands;
202 + bool RenderPackage::buildCommandBuffer() {
203 + //ToDo: Try to rebuild only the affected bits and pieces. That's why we have multiple dirty flags -Ionut
204 + if (_commands == nullptr || _drawCommandDirty || _pipelineDirty || _clipPlanesDirty || _pushConstantsDirty || _descriptorSetsDirty) {
205 + if (_commands == nullptr) {
206 + _commands = GFX::allocateCommandBuffer(_secondaryCommandPool);
207 + }
208 +
209 + for (const CommandEntry& cmd : _commandOrdering) {
210 + switch (cmd._type) {
211 + case GFX::CommandType::DRAW_COMMANDS: {
212 + addDrawCommand(_drawCommands[cmd._index]);
213 + } break;
214 + case GFX::CommandType::BIND_PIPELINE: {
215 + addPipelineCommand(_pipelines[cmd._index]);
216 + } break;
217 + case GFX::CommandType::SET_CLIP_PLANES: {
218 + addClipPlanesCommand(_clipPlanes[cmd._index]);
219 + } break;
220 + case GFX::CommandType::SEND_PUSH_CONSTANTS: {
221 + addPushConstantsCommand(_pushConstants[cmd._index]);
222 + } break;
223 + case GFX::CommandType::BIND_DESCRIPTOR_SETS: {
224 + addDescriptorSetsCommand(_descriptorSets[cmd._index]);
225 + } break;
226 + default:
227 + case GFX::CommandType::COUNT: {
228 + DIVIDE_ASSERT(false,
229 + "RenderPackage::addCommandBuffer error: Specified command buffer "
230 + "contains commands that are not supported for this stage");
231 + } break;
232 + }
233 + }
234 +
235 + _drawCommandDirty = _pipelineDirty = _clipPlanesDirty = _pushConstantsDirty = _descriptorSetsDirty = false;
236 + return true;
237 + }
238 + return false;
148 239 }
240 +
149 241 }; //namespace Divide