-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrenderer.cpp
681 lines (542 loc) · 21 KB
/
renderer.cpp
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
// ----------------------------------------------------------------------------------------------------
#include <string>
#define SOKOL_IMPL
#define SOKOL_GFX_IMPL
#include "sokol_gfx.h"
#undef SOKOL_GFX_IMPL
#include "renderer.h"
// ----------------------------------------------------------------------------------------------------
constexpr int32_t INITIAL_NUMBER_OF_COMMANDS = 512;
constexpr int32_t INITIAL_NUMBER_OF_CLEANUPS = 128;
// ----------------------------------------------------------------------------------------------------
RENDERER::RENDERER(const sg_desc& desc)
{
// setup sokol graphics
sg_setup(desc);
// loop through commands
for (int32_t i = 0; i < 2; i ++)
{
// reserve commands
m_commands[i].reserve(INITIAL_NUMBER_OF_COMMANDS);
}
// reserve cleamups
m_cleanups.reserve(INITIAL_NUMBER_OF_CLEANUPS);
// release render semaphore
m_render_semaphore.release();
}
// ----------------------------------------------------------------------------------------------------
RENDERER::~RENDERER()
{
// process cleanups
process_cleanups(-1);
// shutdown sokol graphics
sg_shutdown();
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::execute_commands(bool resource_only)
{
// not flushing?
if (!m_flushing)
{
// acquire update semaphore
m_update_semaphore.acquire();
}
{
// lock execute mutex
std::scoped_lock<std::mutex> lock(m_execute_mutex);
// loop through commands
for (const auto& command : m_commands[m_commit_commands_index])
{
// ignore command?
if (resource_only && !(command.type >= RENDER_COMMAND::TYPE::MAKE_BUFFER && command.type <= RENDER_COMMAND::TYPE::DESTROY_PASS))
{
continue;
}
// execute command
switch (command.type)
{
case RENDER_COMMAND::TYPE::PUSH_DEBUG_GROUP:
sg_push_debug_group(command.push_debug_group.name);
break;
case RENDER_COMMAND::TYPE::POP_DEBUG_GROUP:
sg_pop_debug_group();
break;
case RENDER_COMMAND::TYPE::MAKE_BUFFER:
sg_init_buffer(command.make_buffer.buffer, command.make_buffer.desc);
break;
case RENDER_COMMAND::TYPE::MAKE_IMAGE:
sg_init_image(command.make_image.image, command.make_image.desc);
break;
case RENDER_COMMAND::TYPE::MAKE_SHADER:
sg_init_shader(command.make_shader.shader, command.make_shader.desc);
break;
case RENDER_COMMAND::TYPE::MAKE_PIPELINE:
sg_init_pipeline(command.make_pipeline.pipeline, command.make_pipeline.desc);
break;
case RENDER_COMMAND::TYPE::MAKE_PASS:
sg_init_pass(command.make_pass.pass, command.make_pass.desc);
break;
case RENDER_COMMAND::TYPE::DESTROY_BUFFER:
sg_uninit_buffer(command.destroy_buffer.buffer);
break;
case RENDER_COMMAND::TYPE::DESTROY_IMAGE:
sg_uninit_image(command.destroy_image.image);
break;
case RENDER_COMMAND::TYPE::DESTROY_SHADER:
sg_uninit_shader(command.destroy_shader.shader);
break;
case RENDER_COMMAND::TYPE::DESTROY_PIPELINE:
sg_uninit_pipeline(command.destroy_pipeline.pipeline);
break;
case RENDER_COMMAND::TYPE::DESTROY_PASS:
sg_uninit_pass(command.destroy_pass.pass);
break;
case RENDER_COMMAND::TYPE::UPDATE_BUFFER:
sg_update_buffer(command.update_buffer.buffer, command.update_buffer.data);
break;
case RENDER_COMMAND::TYPE::APPEND_BUFFER:
sg_append_buffer(command.append_buffer.buffer, command.append_buffer.data);
break;
case RENDER_COMMAND::TYPE::UPDATE_IMAGE:
sg_update_image(command.update_image.image, command.update_image.data);
break;
case RENDER_COMMAND::TYPE::BEGIN_DEFAULT_PASS:
sg_begin_default_pass(command.begin_default_pass.pass_action, m_default_pass_width, m_default_pass_height);
break;
case RENDER_COMMAND::TYPE::BEGIN_PASS:
sg_begin_pass(command.begin_pass.pass, command.begin_pass.pass_action);
break;
case RENDER_COMMAND::TYPE::APPLY_VIEWPORT:
sg_apply_viewport(command.apply_viewport.x, command.apply_viewport.y, command.apply_viewport.width, command.apply_viewport.height, command.apply_viewport.origin_top_left);
break;
case RENDER_COMMAND::TYPE::APPLY_SCISSOR_RECT:
sg_apply_scissor_rect(command.apply_scissor_rect.x, command.apply_scissor_rect.y, command.apply_scissor_rect.width, command.apply_scissor_rect.height, command.apply_scissor_rect.origin_top_left);
break;
case RENDER_COMMAND::TYPE::APPLY_PIPELINE:
sg_apply_pipeline(command.apply_pipeline.pipeline);
break;
case RENDER_COMMAND::TYPE::APPLY_BINDINGS:
sg_apply_bindings(command.apply_bindings.bindings);
break;
case RENDER_COMMAND::TYPE::APPLY_UNIFORMS:
sg_apply_uniforms(command.apply_uniforms.stage, command.apply_uniforms.ub_index, { command.apply_uniforms.buf, command.apply_uniforms.data_size });
break;
case RENDER_COMMAND::TYPE::DRAW:
sg_draw(command.draw.base_element, command.draw.number_of_elements, command.draw.number_of_instances);
break;
case RENDER_COMMAND::TYPE::END_PASS:
sg_end_pass();
break;
case RENDER_COMMAND::TYPE::COMMIT:
sg_commit();
break;
case RENDER_COMMAND::TYPE::CUSTOM:
command.custom.custom_cb(command.custom.custom_data);
break;
case RENDER_COMMAND::TYPE::NOT_SET:
break;
}
}
}
// release render semaphore
m_render_semaphore.release();
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::wait_for_flush()
{
// initialise finished flushing
bool finished_flushing = false;
// wait for flush
while (!finished_flushing)
{
// not flushing?
if (!m_flushing)
{
// acquire update semaphore
m_update_semaphore.acquire();
}
{
// lock execute mutex
std::scoped_lock<std::mutex> lock(m_execute_mutex);
// loop through commands
for (const auto& command : m_commands[m_commit_commands_index])
{
// execute command
switch (command.type)
{
case RENDER_COMMAND::TYPE::MAKE_BUFFER:
sg_init_buffer(command.make_buffer.buffer, command.make_buffer.desc);
break;
case RENDER_COMMAND::TYPE::MAKE_IMAGE:
sg_init_image(command.make_image.image, command.make_image.desc);
break;
case RENDER_COMMAND::TYPE::MAKE_SHADER:
sg_init_shader(command.make_shader.shader, command.make_shader.desc);
break;
case RENDER_COMMAND::TYPE::MAKE_PIPELINE:
sg_init_pipeline(command.make_pipeline.pipeline, command.make_pipeline.desc);
break;
case RENDER_COMMAND::TYPE::MAKE_PASS:
sg_init_pass(command.make_pass.pass, command.make_pass.desc);
break;
case RENDER_COMMAND::TYPE::DESTROY_BUFFER:
sg_uninit_buffer(command.destroy_buffer.buffer);
break;
case RENDER_COMMAND::TYPE::DESTROY_IMAGE:
sg_uninit_image(command.destroy_image.image);
break;
case RENDER_COMMAND::TYPE::DESTROY_SHADER:
sg_uninit_shader(command.destroy_shader.shader);
break;
case RENDER_COMMAND::TYPE::DESTROY_PIPELINE:
sg_uninit_pipeline(command.destroy_pipeline.pipeline);
break;
case RENDER_COMMAND::TYPE::DESTROY_PASS:
sg_uninit_pass(command.destroy_pass.pass);
break;
default:
break;
}
}
}
// udpate finished flushing
finished_flushing = m_flushing;
// release render semaphore
m_render_semaphore.release();
}
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::add_command_push_debug_group(const char* name)
{
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::PUSH_DEBUG_GROUP);
// copy args
command.push_debug_group.name = name;
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::add_command_pop_debug_group()
{
// add command
/*RENDER_COMMAND& command = */m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::POP_DEBUG_GROUP);
}
// ----------------------------------------------------------------------------------------------------
sg_buffer RENDERER::add_command_make_buffer(const sg_buffer_desc& desc)
{
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::MAKE_BUFFER);
// copy args
command.make_buffer.desc = desc;
// alloc buffer
command.make_buffer.buffer = sg_alloc_buffer();
// return buffer
return command.make_buffer.buffer;
}
// ----------------------------------------------------------------------------------------------------
sg_image RENDERER::add_command_make_image(const sg_image_desc& desc)
{
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::MAKE_IMAGE);
// copy args
command.make_image.desc = desc;
// alloc image
command.make_image.image = sg_alloc_image();
// return image
return command.make_image.image;
}
// ----------------------------------------------------------------------------------------------------
sg_shader RENDERER::add_command_make_shader(const sg_shader_desc& desc)
{
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::MAKE_SHADER);
// copy args
command.make_shader.desc = desc;
// alloc shader
command.make_shader.shader = sg_alloc_shader();
// return shader
return command.make_shader.shader;
}
// ----------------------------------------------------------------------------------------------------
sg_pipeline RENDERER::add_command_make_pipeline(const sg_pipeline_desc& desc)
{
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::MAKE_PIPELINE);
// copy args
command.make_pipeline.desc = desc;
// alloc pipeline
command.make_pipeline.pipeline = sg_alloc_pipeline();
// return pipeline
return command.make_pipeline.pipeline;
}
// ----------------------------------------------------------------------------------------------------
sg_pass RENDERER::add_command_make_pass(const sg_pass_desc& desc)
{
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::MAKE_PASS);
// copy args
command.make_pass.desc = desc;
// alloc pass
command.make_pass.pass = sg_alloc_pass();
// return pass
return command.make_pass.pass;
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::add_command_destroy_buffer(sg_buffer buffer)
{
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::DESTROY_BUFFER);
// copy args
command.destroy_buffer.buffer = buffer;
// schedule cleanup
schedule_cleanup(dealloc_buffer_cb, (void*)(uintptr_t)command.destroy_buffer.buffer.id);
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::add_command_destroy_image(sg_image image)
{
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::DESTROY_IMAGE);
// copy args
command.destroy_image.image = image;
// schedule cleanup
schedule_cleanup(dealloc_image_cb, (void*)(uintptr_t)command.destroy_image.image.id);
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::add_command_destroy_shader(sg_shader shader)
{
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::DESTROY_SHADER);
// copy args
command.destroy_shader.shader = shader;
// schedule cleanup
schedule_cleanup(dealloc_shader_cb, (void*)(uintptr_t)command.destroy_shader.shader.id);
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::add_command_destroy_pipeline(sg_pipeline pipeline)
{
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::DESTROY_PIPELINE);
// copy args
command.destroy_pipeline.pipeline = pipeline;
// schedule cleanup
schedule_cleanup(dealloc_pipeline_cb, (void*)(uintptr_t)command.destroy_pipeline.pipeline.id);
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::add_command_destroy_pass(sg_pass pass)
{
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::DESTROY_PASS);
// copy args
command.destroy_pass.pass = pass;
// schedule cleanup
schedule_cleanup(dealloc_pass_cb, (void*)(uintptr_t)command.destroy_pass.pass.id);
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::add_command_update_buffer(sg_buffer buffer, const sg_range& data)
{
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::UPDATE_BUFFER);
// copy args
command.update_buffer.buffer = buffer;
command.update_buffer.data = data;
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::add_command_append_buffer(sg_buffer buffer, const sg_range& data)
{
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::APPEND_BUFFER);
// copy args
command.append_buffer.buffer = buffer;
command.append_buffer.data = data;
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::add_command_update_image(sg_image image, const sg_image_data& data)
{
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::UPDATE_IMAGE);
// copy args
command.update_image.image = image;
command.update_image.data = data;
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::add_command_begin_default_pass(const sg_pass_action& pass_action)
{
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::BEGIN_DEFAULT_PASS);
// copy args
command.begin_default_pass.pass_action = pass_action;
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::add_command_begin_pass(sg_pass pass, const sg_pass_action& pass_action)
{
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::BEGIN_PASS);
// copy args
command.begin_pass.pass = pass;
command.begin_pass.pass_action = pass_action;
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::add_command_apply_viewport(int x, int y, int width, int height, bool origin_top_left)
{
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::APPLY_VIEWPORT);
// copy args
command.apply_viewport.x = x;
command.apply_viewport.y = y;
command.apply_viewport.width = width;
command.apply_viewport.height = height;
command.apply_viewport.origin_top_left = origin_top_left;
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::add_command_apply_scissor_rect(int x, int y, int width, int height, bool origin_top_left)
{
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::APPLY_SCISSOR_RECT);
// copy args
command.apply_scissor_rect.x = x;
command.apply_scissor_rect.y = y;
command.apply_scissor_rect.width = width;
command.apply_scissor_rect.height = height;
command.apply_scissor_rect.origin_top_left = origin_top_left;
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::add_command_apply_pipeline(sg_pipeline pipeline)
{
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::APPLY_PIPELINE);
// copy args
command.apply_pipeline.pipeline = pipeline;
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::add_command_apply_bindings(const sg_bindings& bindings)
{
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::APPLY_BINDINGS);
// copy args
command.apply_bindings.bindings = bindings;
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::add_command_apply_uniforms(sg_shader_stage stage, int ub_index, const sg_range& data)
{
// data size too big?
if ((size_t)data.size > sizeof(RENDER_COMMAND::apply_uniforms.buf))
{
return;
}
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::APPLY_UNIFORMS);
// copy args
command.apply_uniforms.stage = stage;
command.apply_uniforms.ub_index = ub_index;
memcpy(command.apply_uniforms.buf, data.ptr, data.size);
command.apply_uniforms.data_size = data.size;
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::add_command_draw(int base_element, int number_of_elements, int number_of_instances)
{
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::DRAW);
// copy args
command.draw.base_element = base_element;
command.draw.number_of_elements = number_of_elements;
command.draw.number_of_instances = number_of_instances;
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::add_command_end_pass()
{
// add command
/*RENDER_COMMAND& command = */m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::END_PASS);
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::add_command_commit()
{
// add command
/*RENDER_COMMAND& command = */m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::COMMIT);
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::add_command_custom(void (*custom_cb)(void* custom_data), void* custom_data)
{
// add command
RENDER_COMMAND& command = m_commands[m_pending_commands_index].emplace_back(RENDER_COMMAND::TYPE::CUSTOM);
// copy args
command.custom.custom_cb = custom_cb;
command.custom.custom_data = custom_data;
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::schedule_cleanup(void (*cleanup_cb)(void* cleanup_data), void* cleanup_data, int32_t number_of_frames_to_defer)
{
// add cleanup
RENDER_CLEANUP& cleanup = m_cleanups.emplace_back(cleanup_cb, cleanup_data);
// set frame index
cleanup.frame_index = m_frame_index + 1 + number_of_frames_to_defer;
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::commit_commands()
{
// acquire render semaphore
m_render_semaphore.acquire();
// clear commands
m_commands[m_commit_commands_index].resize(0);
// process cleanups
process_cleanups(m_frame_index);
// swap commands indexes
std::swap(m_pending_commands_index, m_commit_commands_index);
// increase frame index
m_frame_index ++;
// release update semaphore
m_update_semaphore.release();
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::flush_commands()
{
// acquire render semaphore
m_render_semaphore.acquire();
// clear commands
m_commands[m_commit_commands_index].resize(0);
// swap commands indexes
std::swap(m_pending_commands_index, m_commit_commands_index);
// set flushing
m_flushing = true;
// release update semaphore
m_update_semaphore.release();
}
// ----------------------------------------------------------------------------------------------------
const std::string RENDERER::get_name() const
{
// return name
switch (sg_query_backend())
{
case SG_BACKEND_GLCORE33:
return "OpenGL 3.3";
case SG_BACKEND_GLES2:
return "OpenGL ES 2.0";
case SG_BACKEND_GLES3:
return "OpenGL ES 3.0";
case SG_BACKEND_D3D11:
return "Direct3D 11";
case SG_BACKEND_METAL_IOS:
case SG_BACKEND_METAL_MACOS:
case SG_BACKEND_METAL_SIMULATOR:
return "Metal";
case SG_BACKEND_WGPU:
return "WebGPU";
default:
return "Unknown";
}
}
// ----------------------------------------------------------------------------------------------------
void RENDERER::process_cleanups(int32_t frame_index)
{
// loop through cleanups
for (auto& cleanup : m_cleanups)
{
// call cleanup cb?
if ((cleanup.frame_index <= frame_index || frame_index < 0) && cleanup.cleanup_cb)
{
// call cleanup cb
cleanup.cleanup_cb(cleanup.cleanup_data);
// reset cleanup cb
cleanup.cleanup_cb = nullptr;
}
}
// erase invalid cleanups
m_cleanups.erase(std::remove_if(m_cleanups.begin(), m_cleanups.end(), [](const auto& cleanup) { return !cleanup.cleanup_cb; }), m_cleanups.end());
}