@@ -22,8 +22,12 @@ namespace Siege::Vulkan
22
22
Material::Material (Shader vertShader, Shader fragShader)
23
23
: vertexShader{std::move (vertShader)}, fragmentShader{std::move (fragShader)}
24
24
{
25
- bufferSize += (Buffer::PadUniformBufferSize (vertexShader.GetTotalUniformSize ()) +
26
- Buffer::PadUniformBufferSize (fragmentShader.GetTotalUniformSize ()));
25
+ // Separate uniforms into unique properties
26
+
27
+ uint64_t offset {0 };
28
+
29
+ AddShader (vertexShader, OUT offset);
30
+ AddShader (fragmentShader, OUT offset);
27
31
28
32
// TODO: Make a standalone buffer class
29
33
// Allocate buffer which can store all the data we need
@@ -33,13 +37,6 @@ Material::Material(Shader vertShader, Shader fragShader)
33
37
OUT buffer.buffer ,
34
38
OUT buffer.bufferMemory );
35
39
36
- // Separate uniforms into unique properties
37
-
38
- uint64_t offset {0 };
39
-
40
- AddShader (vertexShader, OUT offset);
41
- AddShader (fragmentShader, OUT offset);
42
-
43
40
// Create Descriptor Set Layout for Sets
44
41
45
42
for (size_t i = 0 ; i < propertiesSlots.Count (); i++)
@@ -113,13 +110,15 @@ Material& Material::operator=(Material&& other)
113
110
void Material::SetUniformData (Hash::StringId id, uint64_t dataSize, const void * data)
114
111
{
115
112
// TODO: Clean this up.
116
- for (auto & slot : propertiesSlots)
113
+ for (auto it = propertiesSlots. CreateIterator (); it; ++it )
117
114
{
118
- for (auto & property : slot.properties )
115
+ auto slot = *it;
116
+ for (auto slotIt = slot.properties .CreateIterator (); slotIt; ++slotIt)
119
117
{
120
- if (property.id == id)
118
+ auto prop = *slotIt;
119
+ if (prop.id == id)
121
120
{
122
- Buffer::CopyData (buffer, dataSize, data, property .offset );
121
+ Buffer::CopyData (buffer, dataSize, data, prop .offset );
123
122
return ;
124
123
}
125
124
}
@@ -164,6 +163,8 @@ void Material::AddShader(const Shader& shader, uint64_t& offset)
164
163
property.shaderStage = (Utils::ShaderType)(property.shaderStage | shader.GetShaderType ());
165
164
property.offset = offset;
166
165
166
+ bufferSize += uniform.totalSize ;
167
+
167
168
offset += uniform.totalSize ;
168
169
}
169
170
}
@@ -173,8 +174,8 @@ void Material::Bind(const CommandBuffer& commandBuffer)
173
174
graphicsPipeline.Bind (commandBuffer);
174
175
175
176
// TODO: Cache this on the material itself?
176
- StackArray <VkDescriptorSet, 10 > setsToBind;
177
- for (auto property : propertiesSlots) setsToBind.Append (property .set );
177
+ ::Siege::Utils::MSArray <VkDescriptorSet, 10 > setsToBind;
178
+ for (auto it = propertiesSlots. CreateIterator (); it; ++it) setsToBind.Append ((*it) .set );
178
179
179
180
graphicsPipeline.BindSets (commandBuffer, setsToBind);
180
181
}
@@ -185,8 +186,8 @@ void Material::Bind(VkCommandBuffer commandBuffer)
185
186
graphicsPipeline.Bind (commandBuffer);
186
187
187
188
// TODO: Cache this on the material itself?
188
- StackArray <VkDescriptorSet, 10 > setsToBind;
189
- for (auto property : propertiesSlots) setsToBind.Append (property .set );
189
+ ::Siege::Utils::MSArray <VkDescriptorSet, 10 > setsToBind;
190
+ for (auto it = propertiesSlots. CreateIterator (); it; ++it) setsToBind.Append ((*it) .set );
190
191
191
192
graphicsPipeline.BindSets (commandBuffer, setsToBind);
192
193
}
@@ -199,19 +200,20 @@ void Material::UpdateMaterial()
199
200
void Material::WriteSet (PropertiesSlot& slot)
200
201
{
201
202
VkWriteDescriptorSet writes[slot.properties .Count ()];
203
+ VkDescriptorBufferInfo bufferInfos[slot.properties .Count ()];
202
204
203
205
for (size_t j = 0 ; j < slot.properties .Count (); j++)
204
206
{
205
207
auto & property = slot.properties [j];
206
208
207
- VkDescriptorBufferInfo bufferInfo = Descriptor::CreateBufferInfo (buffer.buffer , property.offset , property.size );
209
+ bufferInfos[j] = Descriptor::CreateBufferInfo (buffer.buffer , property.offset , property.size );
208
210
209
211
writes[j] = Descriptor::CreateWriteSet (
210
212
j,
211
213
slot.set ,
212
214
1 ,
213
215
Utils::ToVkDescriptorType (property.type ),
214
- &bufferInfo );
216
+ &bufferInfos[j] );
215
217
}
216
218
217
219
Descriptor::WriteSets (Vulkan::Context::GetVkLogicalDevice (),
0 commit comments