@@ -54,32 +54,40 @@ Material::Material(Shader vertShader, Shader fragShader) :
54
54
writes = MHArray<MSArray<VkWriteDescriptorSet, 10 >>(framesCount);
55
55
56
56
// Create Descriptor Set Layout for Sets
57
- propertiesSlots.MForEachI ([&](PropertiesSlot& slot, size_t i) {
57
+ for (auto slotIt = propertiesSlots.CreateIterator (); slotIt; ++slotIt)
58
+ {
58
59
MSArray<VkDescriptorSetLayoutBinding, 10 > bindings;
59
60
61
+ auto & slot = *slotIt;
62
+
60
63
auto & properties = slot.properties ;
61
64
62
- properties.MForEachI ([&](Property& prop, size_t j) {
63
- bindings.Append (CreateLayoutBinding (j, prop.count , prop.type , prop.shaderStage ));
64
- prop.binding = j;
65
- });
65
+ for (auto propIt = properties.CreateIterator (); propIt; ++propIt)
66
+ {
67
+ auto & prop = *propIt;
68
+ bindings.Append (
69
+ CreateLayoutBinding (propIt.GetIndex (), prop.count , prop.type , prop.shaderStage ));
70
+ prop.binding = propIt.GetIndex ();
71
+ }
66
72
67
73
CC_ASSERT (CreateLayout (device, OUT slot.layout , bindings.Data (), properties.Count ()),
68
74
" Failed to create descriptor set!" )
69
75
70
- perFrameDescriptorSets.ForEach (MSA_IT (VkDescriptorSet, MAX_UNIFORM_SETS, sets) {
76
+ for (auto setIt = perFrameDescriptorSets.CreateFIterator (); setIt; ++setIt)
77
+ {
78
+ auto & sets = *setIt;
71
79
sets.Append (VK_NULL_HANDLE);
72
80
AllocateSets (device,
73
81
OUT & sets.Back (),
74
82
DescriptorPool::GetDescriptorPool (),
75
83
1 ,
76
84
&slot.layout );
77
- });
85
+ }
78
86
79
- WriteSet (i , slot);
80
- });
87
+ WriteSet (slotIt. GetIndex () , slot);
88
+ }
81
89
82
- writes.MForEach ( MSA_IT (VkWriteDescriptorSet, 10 , sets) { Write (sets); } );
90
+ for ( auto writeIt = writes.CreateIterator (); writeIt; ++writeIt) Write (*writeIt );
83
91
84
92
// Create Pipeline
85
93
Recreate ();
@@ -97,20 +105,23 @@ Material::~Material()
97
105
98
106
Buffer::DestroyBuffer (buffer);
99
107
100
- propertiesSlots.ForEach (
101
- [&](PropertiesSlot& prop) { vkDestroyDescriptorSetLayout (device, prop.layout , nullptr ); });
108
+ for (auto it = propertiesSlots.CreateFIterator (); it; ++it)
109
+ {
110
+ vkDestroyDescriptorSetLayout (device, it->layout , nullptr );
111
+ }
102
112
}
103
113
104
- void Material::Destroy ()
114
+ void Material::Free ()
105
115
{
106
116
auto device = Vulkan::Context::GetVkLogicalDevice ();
107
117
108
118
Buffer::DestroyBuffer (buffer);
109
119
110
- propertiesSlots.MForEach ([&](PropertiesSlot& prop) {
111
- vkDestroyDescriptorSetLayout (device, prop.layout , nullptr );
112
- prop.layout = nullptr ;
113
- });
120
+ for (auto it = propertiesSlots.CreateFIterator (); it; ++it)
121
+ {
122
+ vkDestroyDescriptorSetLayout (device, it->layout , nullptr );
123
+ it->layout = nullptr ;
124
+ }
114
125
115
126
vertexShader.Destroy ();
116
127
fragmentShader.Destroy ();
@@ -151,26 +162,34 @@ uint32_t Material::SetTexture(Hash::StringId id, Texture2D* texture)
151
162
texIndex = textureIds.Count ();
152
163
textureIds.Append (texture->GetId ());
153
164
154
- propertiesSlots.MForEachI ([&](PropertiesSlot& slot, size_t i) {
165
+ for (auto it = propertiesSlots.CreateIterator (); it; ++it)
166
+ {
167
+ auto & slot = *it;
155
168
auto & properties = slot.properties ;
169
+
156
170
auto propIdx = FindPropertyIndex (id, slot);
157
171
158
- if (propIdx == -1 ) return ;
172
+ if (propIdx == -1 ) continue ;
159
173
160
174
auto info = texture->GetInfo ();
161
175
162
176
texture2DInfos[texIndex] = {info.sampler ,
163
177
info.imageInfo .view ,
164
178
ToVkImageLayout (info.imageInfo .layout )};
165
179
166
- if (writeSets.Count () > 0 ) return ;
180
+ if (writeSets.Count () > 0 ) break ;
167
181
168
182
auto prop = properties[propIdx];
169
183
170
- writes.ForEachI (MSA_IT_I (VkWriteDescriptorSet, 10 , sets, j) {
171
- QueueImageUpdate (sets, perFrameDescriptorSets[j][i], prop.binding , prop.count , 0 );
172
- });
173
- });
184
+ for (auto write = writes.CreateFIterator (); write; ++write)
185
+ {
186
+ QueueImageUpdate (*write,
187
+ perFrameDescriptorSets[write.GetIndex ()][it.GetIndex ()],
188
+ prop.binding ,
189
+ prop.count ,
190
+ 0 );
191
+ }
192
+ }
174
193
175
194
return texIndex;
176
195
}
@@ -238,16 +257,19 @@ void Material::Bind(const CommandBuffer& commandBuffer)
238
257
graphicsPipeline.BindSets (commandBuffer, perFrameDescriptorSets[frameIndex]);
239
258
}
240
259
241
- void Material::BindPushConstant (const CommandBuffer& buffer , const void * values)
260
+ void Material::BindPushConstant (const CommandBuffer& commandBuffer , const void * values)
242
261
{
243
- graphicsPipeline.PushConstants (buffer , pushConstant.type , pushConstant.size , values);
262
+ graphicsPipeline.PushConstants (commandBuffer , pushConstant.type , pushConstant.size , values);
244
263
}
245
264
246
265
void Material::Recreate ()
247
266
{
248
267
MSArray<VkDescriptorSetLayout, 10 > layouts;
249
268
250
- propertiesSlots.MForEach ([&](PropertiesSlot& slot) { layouts.Append (slot.layout ); });
269
+ for (auto it = propertiesSlots.CreateIterator (); it; ++it)
270
+ {
271
+ layouts.Append ((*it).layout );
272
+ }
251
273
252
274
graphicsPipeline = Pipeline::Builder ()
253
275
.WithRenderPass (Context::GetSwapchain ().GetRenderPass ())
@@ -273,14 +295,15 @@ void Material::Update()
273
295
274
296
void Material::Update (Hash::StringId id)
275
297
{
276
- propertiesSlots.ForEachI ([&](PropertiesSlot& slot, size_t i) {
277
- auto propertyIndex = FindPropertyIndex (id, slot);
298
+ for (auto it = propertiesSlots.CreateFIterator (); it; ++it)
299
+ {
300
+ auto propertyIndex = FindPropertyIndex (id, *it);
278
301
279
302
if (propertyIndex == -1 ) return ;
280
303
281
304
auto & setsToWrite = writes[Renderer::GetCurrentFrameIndex ()];
282
305
Write (setsToWrite);
283
- });
306
+ }
284
307
}
285
308
286
309
void Material::WriteSet (uint32_t set, PropertiesSlot& slot)
@@ -290,13 +313,23 @@ void Material::WriteSet(uint32_t set, PropertiesSlot& slot)
290
313
291
314
auto & properties = slot.properties ;
292
315
293
- properties.MForEachI ([&](Property& prop, size_t i) {
316
+ for (auto propIt = properties.CreateIterator (); propIt; ++propIt)
317
+ {
318
+ auto prop = *propIt;
294
319
bufferInfos.Append (CreateBufferInfo (buffer.buffer , prop.offset , prop.size ));
295
- perFrameDescriptorSets.ForEachI (MSA_IT_I (VkDescriptorSet, MAX_UNIFORM_SETS, sets, j) {
296
- if (IsTexture2D (prop.type )) QueueImageUpdate (writes[j], sets[set], i);
297
- else QueuePropertyUpdate (writes[j], sets[set], prop.type , i, 1 );
298
- });
299
- });
320
+ for (auto setIt = perFrameDescriptorSets.CreateFIterator (); setIt; ++setIt)
321
+ {
322
+ auto sets = *setIt;
323
+ if (IsTexture2D (prop.type ))
324
+ QueueImageUpdate (writes[setIt.GetIndex ()], sets[set], propIt.GetIndex ());
325
+ else
326
+ QueuePropertyUpdate (writes[setIt.GetIndex ()],
327
+ sets[set],
328
+ prop.type ,
329
+ propIt.GetIndex (),
330
+ 1 );
331
+ }
332
+ }
300
333
}
301
334
302
335
void Material::Write (MSArray<VkWriteDescriptorSet, 10 >& sets)
@@ -337,26 +370,28 @@ void Material::QueuePropertyUpdate(MSArray<VkWriteDescriptorSet, 10>& writeQueue
337
370
int32_t Material::FindPropertyIndex (Hash::StringId id, PropertiesSlot& slot)
338
371
{
339
372
int32_t foundIdx {-1 };
340
- slot.properties .MForEachI ([&](Property& property, size_t i) {
341
- if (property.id == id)
373
+ for (auto it = slot.properties .CreateIterator (); it; ++it)
374
+ {
375
+ if (it->id == id)
342
376
{
343
- foundIdx = i ;
344
- return ;
377
+ foundIdx = it. GetIndex () ;
378
+ break ;
345
379
}
346
- });
380
+ }
347
381
return foundIdx;
348
382
}
349
383
350
384
int32_t Material::FindTextureIndex (Hash::StringId id)
351
385
{
352
386
int32_t texExists = -1 ;
353
- textureIds.MForEachI ([&](Hash::StringId& texId, size_t i) {
354
- if (id == texId)
387
+ for (auto it = textureIds.CreateIterator (); it; ++it)
388
+ {
389
+ if (id == *it)
355
390
{
356
- texExists = i ;
357
- return ;
391
+ texExists = it. GetIndex () ;
392
+ break ;
358
393
}
359
- });
394
+ }
360
395
return texExists;
361
396
}
362
397
0 commit comments