8
8
// Possible solution: Make compilation with debugPrintf shaders synchronous?
9
9
10
10
#define DIRTY_CHECK (x ) \
11
- if (!x ) { \
11
+ if (!(x) ) { \
12
12
return *this ; \
13
13
}
14
14
static VkPipelineStageFlags get_pipeline_stage (PassType pass_type, VkAccessFlags access_flags) {
@@ -292,14 +292,22 @@ RenderPass& RenderGraph::add_rt(const std::string& name, const RTPassSettings& s
292
292
auto & storage = pipeline_cache[name];
293
293
if (!recording && storage.pass_idxs .size ()) {
294
294
auto idx = storage.pass_idxs [storage.offset_idx ];
295
- ++storage.offset_idx ;
296
295
passes[idx].active = true ;
296
+ if (reload_shaders) {
297
+ if (storage.offset_idx == 0 ) {
298
+ pipeline_cache[name].pipeline ->cleanup ();
299
+ pipeline_cache[name].pipeline = std::make_unique<Pipeline>(ctx, name);
300
+ }
301
+ passes[idx].pipeline = pipeline_cache[name].pipeline .get ();
302
+ }
303
+ ++storage.offset_idx ;
297
304
return passes[idx];
298
305
}
306
+
299
307
pipeline = pipeline_cache[name].pipeline .get ();
300
308
cached = true ;
301
309
} else {
302
- pipeline_cache[name] = {std::make_unique<Pipeline>(ctx, pass_idx, name)};
310
+ pipeline_cache[name] = {std::make_unique<Pipeline>(ctx, name)};
303
311
pipeline = pipeline_cache[name].pipeline .get ();
304
312
}
305
313
passes.emplace_back (PassType::RT, pipeline, name, this , pass_idx, settings, cached);
@@ -315,17 +323,24 @@ RenderPass& RenderGraph::add_gfx(const std::string& name, const GraphicsPassSett
315
323
auto & storage = pipeline_cache[name];
316
324
if (!recording && storage.pass_idxs .size ()) {
317
325
auto idx = storage.pass_idxs [storage.offset_idx ];
318
- ++storage.offset_idx ;
319
326
auto & curr_pass = passes[idx];
320
327
curr_pass.gfx_settings ->color_outputs = settings.color_outputs ;
321
328
curr_pass.gfx_settings ->depth_output = settings.depth_output ;
322
329
curr_pass.active = true ;
330
+ if (reload_shaders) {
331
+ if (storage.offset_idx == 0 ) {
332
+ pipeline_cache[name].pipeline ->cleanup ();
333
+ pipeline_cache[name].pipeline = std::make_unique<Pipeline>(ctx, name);
334
+ }
335
+ passes[idx].pipeline = pipeline_cache[name].pipeline .get ();
336
+ }
337
+ ++storage.offset_idx ;
323
338
return curr_pass;
324
339
}
325
340
pipeline = pipeline_cache[name].pipeline .get ();
326
341
cached = true ;
327
342
} else {
328
- pipeline_cache[name] = {std::make_unique<Pipeline>(ctx, pass_idx, name)};
343
+ pipeline_cache[name] = {std::make_unique<Pipeline>(ctx, name)};
329
344
pipeline = pipeline_cache[name].pipeline .get ();
330
345
}
331
346
passes.emplace_back (PassType::Graphics, pipeline, name, this , pass_idx, settings, cached);
@@ -342,13 +357,20 @@ RenderPass& RenderGraph::add_compute(const std::string& name, const ComputePassS
342
357
if (!recording && storage.pass_idxs .size ()) {
343
358
auto idx = storage.pass_idxs [storage.offset_idx ];
344
359
passes[idx].active = true ;
360
+ if (reload_shaders) {
361
+ if (storage.offset_idx == 0 ) {
362
+ pipeline_cache[name].pipeline ->cleanup ();
363
+ pipeline_cache[name].pipeline = std::make_unique<Pipeline>(ctx, name);
364
+ }
365
+ passes[idx].pipeline = pipeline_cache[name].pipeline .get ();
366
+ }
345
367
++storage.offset_idx ;
346
368
return passes[idx];
347
369
}
348
370
pipeline = pipeline_cache[name].pipeline .get ();
349
371
cached = true ;
350
372
} else {
351
- pipeline_cache[name] = {std::make_unique<Pipeline>(ctx, pass_idx, name)};
373
+ pipeline_cache[name] = {std::make_unique<Pipeline>(ctx, name)};
352
374
pipeline = pipeline_cache[name].pipeline .get ();
353
375
}
354
376
passes.emplace_back (PassType::Compute, pipeline, name, this , pass_idx, settings, cached);
@@ -405,7 +427,7 @@ RenderPass& RenderPass::bind_buffer_array(std::vector<Buffer>& buffers) {
405
427
}
406
428
407
429
RenderPass& RenderPass::bind_tlas (const AccelKHR& tlas) {
408
- DIRTY_CHECK (rg->recording );
430
+ DIRTY_CHECK (rg->recording || rg-> reload_shaders );
409
431
pipeline->tlas_info = {VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET_ACCELERATION_STRUCTURE_KHR};
410
432
pipeline->tlas_info .accelerationStructureCount = 1 ;
411
433
pipeline->tlas_info .pAccelerationStructures = &tlas.accel ;
@@ -526,7 +548,7 @@ RenderPass& RenderPass::copy(const Resource& src, const Resource& dst) {
526
548
}
527
549
528
550
void RenderPass::finalize () {
529
- if (!rg->recording ) {
551
+ if (!rg->recording && !rg-> reload_shaders ) {
530
552
// Handle resource transitions
531
553
transition_resources ();
532
554
return ;
@@ -882,15 +904,15 @@ void RenderGraph::run(VkCommandBuffer cmd) {
882
904
img_sync_resources.resize (passes.size ());
883
905
884
906
// Compile shaders and process resources
885
- if (recording) {
907
+ if (recording || reload_shaders ) {
886
908
auto cmp = [](const std::pair<Shader*, RenderPass*>& a, const std::pair<Shader*, RenderPass*>& b) {
887
909
return a.first ->filename < b.first ->filename ;
888
910
};
889
911
std::set<std::pair<Shader*, RenderPass*>, decltype (cmp)> unique_shaders_set;
890
912
std::unordered_map<RenderPass*, std::vector<Shader*>> unique_shaders;
891
913
std::unordered_map<RenderPass*, std::vector<Shader*>> existing_shaders;
892
914
893
- // Recording -> The pass is active by default
915
+ // Recording or reload -> The pass is active by default
894
916
for (auto i = beginning_pass_idx; i < ending_pass_idx; i++) {
895
917
if (passes[i].gfx_settings ) {
896
918
for (auto & shader : passes[i].gfx_settings ->shaders ) {
@@ -1013,6 +1035,7 @@ void RenderGraph::reset(VkCommandBuffer cmd) {
1013
1035
buffer_sync_resources.clear ();
1014
1036
img_sync_resources.clear ();
1015
1037
beginning_pass_idx = ending_pass_idx = 0 ;
1038
+ reload_shaders = false ;
1016
1039
}
1017
1040
1018
1041
void RenderGraph::submit (CommandBuffer& cmd) {
0 commit comments