@@ -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,8 +105,10 @@ 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
114
void Material::Destroy ()
@@ -107,10 +117,12 @@ void Material::Destroy()
107
117
108
118
Buffer::DestroyBuffer (buffer);
109
119
110
- propertiesSlots.MForEach ([&](PropertiesSlot& prop) {
120
+ for (auto it = propertiesSlots.CreateFIterator (); it; ++it)
121
+ {
122
+ auto & prop = *it;
111
123
vkDestroyDescriptorSetLayout (device, prop.layout , nullptr );
112
124
prop.layout = nullptr ;
113
- });
125
+ }
114
126
115
127
vertexShader.Destroy ();
116
128
fragmentShader.Destroy ();
@@ -151,26 +163,34 @@ uint32_t Material::SetTexture(Hash::StringId id, Texture2D* texture)
151
163
texIndex = textureIds.Count ();
152
164
textureIds.Append (texture->GetId ());
153
165
154
- propertiesSlots.MForEachI ([&](PropertiesSlot& slot, size_t i) {
166
+ for (auto it = propertiesSlots.CreateIterator (); it; ++it)
167
+ {
168
+ auto & slot = *it;
155
169
auto & properties = slot.properties ;
170
+
156
171
auto propIdx = FindPropertyIndex (id, slot);
157
172
158
- if (propIdx == -1 ) return ;
173
+ if (propIdx == -1 ) continue ;
159
174
160
175
auto info = texture->GetInfo ();
161
176
162
177
texture2DInfos[texIndex] = {info.sampler ,
163
178
info.imageInfo .view ,
164
179
ToVkImageLayout (info.imageInfo .layout )};
165
180
166
- if (writeSets.Count () > 0 ) return ;
181
+ if (writeSets.Count () > 0 ) break ;
167
182
168
183
auto prop = properties[propIdx];
169
184
170
- writes.ForEachI (MSA_IT_I (VkWriteDescriptorSet, 10 , sets, j) {
171
- QueueImageUpdate (sets, perFrameDescriptorSets[j][i], prop.binding , prop.count , 0 );
172
- });
173
- });
185
+ for (auto write = writes.CreateFIterator (); write; ++write)
186
+ {
187
+ QueueImageUpdate (*write,
188
+ perFrameDescriptorSets[write.GetIndex ()][it.GetIndex ()],
189
+ prop.binding ,
190
+ prop.count ,
191
+ 0 );
192
+ }
193
+ }
174
194
175
195
return texIndex;
176
196
}
@@ -238,16 +258,19 @@ void Material::Bind(const CommandBuffer& commandBuffer)
238
258
graphicsPipeline.BindSets (commandBuffer, perFrameDescriptorSets[frameIndex]);
239
259
}
240
260
241
- void Material::BindPushConstant (const CommandBuffer& buffer , const void * values)
261
+ void Material::BindPushConstant (const CommandBuffer& commandBuffer , const void * values)
242
262
{
243
- graphicsPipeline.PushConstants (buffer , pushConstant.type , pushConstant.size , values);
263
+ graphicsPipeline.PushConstants (commandBuffer , pushConstant.type , pushConstant.size , values);
244
264
}
245
265
246
266
void Material::Recreate ()
247
267
{
248
268
MSArray<VkDescriptorSetLayout, 10 > layouts;
249
269
250
- propertiesSlots.MForEach ([&](PropertiesSlot& slot) { layouts.Append (slot.layout ); });
270
+ for (auto it = propertiesSlots.CreateIterator (); it; ++it)
271
+ {
272
+ layouts.Append ((*it).layout );
273
+ }
251
274
252
275
graphicsPipeline = Pipeline::Builder ()
253
276
.WithRenderPass (Context::GetSwapchain ().GetRenderPass ())
@@ -273,14 +296,15 @@ void Material::Update()
273
296
274
297
void Material::Update (Hash::StringId id)
275
298
{
276
- propertiesSlots.ForEachI ([&](PropertiesSlot& slot, size_t i) {
277
- auto propertyIndex = FindPropertyIndex (id, slot);
299
+ for (auto it = propertiesSlots.CreateFIterator (); it; ++it)
300
+ {
301
+ auto propertyIndex = FindPropertyIndex (id, *it);
278
302
279
303
if (propertyIndex == -1 ) return ;
280
304
281
305
auto & setsToWrite = writes[Renderer::GetCurrentFrameIndex ()];
282
306
Write (setsToWrite);
283
- });
307
+ }
284
308
}
285
309
286
310
void Material::WriteSet (uint32_t set, PropertiesSlot& slot)
@@ -290,13 +314,23 @@ void Material::WriteSet(uint32_t set, PropertiesSlot& slot)
290
314
291
315
auto & properties = slot.properties ;
292
316
293
- properties.MForEachI ([&](Property& prop, size_t i) {
317
+ for (auto propIt = properties.CreateIterator (); propIt; ++propIt)
318
+ {
319
+ auto prop = *propIt;
294
320
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
- });
321
+ for (auto setIt = perFrameDescriptorSets.CreateFIterator (); setIt; ++setIt)
322
+ {
323
+ auto sets = *setIt;
324
+ if (IsTexture2D (prop.type ))
325
+ QueueImageUpdate (writes[setIt.GetIndex ()], sets[set], propIt.GetIndex ());
326
+ else
327
+ QueuePropertyUpdate (writes[setIt.GetIndex ()],
328
+ sets[set],
329
+ prop.type ,
330
+ propIt.GetIndex (),
331
+ 1 );
332
+ }
333
+ }
300
334
}
301
335
302
336
void Material::Write (MSArray<VkWriteDescriptorSet, 10 >& sets)
@@ -337,26 +371,28 @@ void Material::QueuePropertyUpdate(MSArray<VkWriteDescriptorSet, 10>& writeQueue
337
371
int32_t Material::FindPropertyIndex (Hash::StringId id, PropertiesSlot& slot)
338
372
{
339
373
int32_t foundIdx {-1 };
340
- slot.properties .MForEachI ([&](Property& property, size_t i) {
341
- if (property.id == id)
374
+ for (auto it = slot.properties .CreateIterator (); it; ++it)
375
+ {
376
+ if ((*it).id == id)
342
377
{
343
- foundIdx = i ;
344
- return ;
378
+ foundIdx = it. GetIndex () ;
379
+ break ;
345
380
}
346
- });
381
+ }
347
382
return foundIdx;
348
383
}
349
384
350
385
int32_t Material::FindTextureIndex (Hash::StringId id)
351
386
{
352
387
int32_t texExists = -1 ;
353
- textureIds.MForEachI ([&](Hash::StringId& texId, size_t i) {
354
- if (id == texId)
388
+ for (auto it = textureIds.CreateIterator (); it; ++it)
389
+ {
390
+ if (id == *it)
355
391
{
356
- texExists = i ;
357
- return ;
392
+ texExists = it. GetIndex () ;
393
+ break ;
358
394
}
359
- });
395
+ }
360
396
return texExists;
361
397
}
362
398
0 commit comments