From adbf58d1821ea221e232659cefbbfbf49a26207a Mon Sep 17 00:00:00 2001 From: ravi688 Date: Thu, 24 Oct 2024 23:06:53 +0530 Subject: [PATCH] [SGE] Automatically build render graph on queue dispatch if the render queue has changed. --- .../sge/internal/vulkan/vulkan_render_queue.h | 2 ++ .../sge/internal/vulkan/vulkan_render_scene.h | 1 + source/sge/vulkan/vulkan_render_queue.c | 19 ++++++++++++++----- source/sge/vulkan/vulkan_render_scene.c | 7 +++++-- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/include/sge/internal/vulkan/vulkan_render_queue.h b/include/sge/internal/vulkan/vulkan_render_queue.h index 59cbb43a..62591b88 100644 --- a/include/sge/internal/vulkan/vulkan_render_queue.h +++ b/include/sge/internal/vulkan/vulkan_render_queue.h @@ -305,4 +305,6 @@ SGE_API void vulkan_render_queue_dispatch_single_material(vulkan_render_queue_t* /* sets the draw order policy, this is automatically called while creating the queue with type = VULKAN_RENDER_QUEUE_TYPE_TRANSPARENT queue */ SGE_API void vulkan_render_queue_set_draw_order_policy(vulkan_render_queue_t* queue, vulkan_transparent_queue_draw_order_policy_t policy); +static CAN_BE_UNUSED_FUNCTION INLINE_IF_RELEASE_MODE bool vulkan_render_queue_is_ready(const vulkan_render_queue_t* queue) { return queue->is_ready; } + END_CPP_COMPATIBLE diff --git a/include/sge/internal/vulkan/vulkan_render_scene.h b/include/sge/internal/vulkan/vulkan_render_scene.h index 3a669181..7fd9c5b8 100644 --- a/include/sge/internal/vulkan/vulkan_render_scene.h +++ b/include/sge/internal/vulkan/vulkan_render_scene.h @@ -38,6 +38,7 @@ typedef enum vulkan_render_scene_preset_type_t { + /* default preset creates background, geometry, alpha tested, geometry last, and overlay queues */ VULKAN_RENDER_SCENE_PRESET_TYPE_DEFAULT = 0, VULKAN_RENDER_SCENE_PRESET_TYPE_GEOMETRY_ONLY, VULKAN_RENDER_SCENE_PRESET_TYPE_ALPHA_TESTED_ONLY, diff --git a/source/sge/vulkan/vulkan_render_queue.c b/source/sge/vulkan/vulkan_render_queue.c index 56015247..e2f2f944 100644 --- a/source/sge/vulkan/vulkan_render_queue.c +++ b/source/sge/vulkan/vulkan_render_queue.c @@ -239,6 +239,9 @@ SGE_API void vulkan_render_queue_add(vulkan_render_queue_t* queue, vulkan_render buf_push(&lists[j], &obj->material->shader->handle); } } + + /* build & optimize the render graph again. */ + queue->is_ready = false; } // TODO @@ -260,8 +263,13 @@ SGE_API void vulkan_render_queue_removeH(vulkan_render_queue_t* queue, vulkan_re buf_ucount_t index = buf_find_index_of(list, &object, buf_ptr_comparer); if(index == BUF_INVALID_INDEX) LOG_WRN("remove failed, render object isn't found in the queue\n"); - buf_remove_at(list, index, NULL); - object->queue = NULL; + else + { + buf_remove_at(list, index, NULL); + object->queue = NULL; + /* build & optimize the render graph again. */ + queue->is_ready = false; + } } SGE_API void vulkan_render_queue_build(vulkan_render_queue_t* queue) @@ -660,9 +668,6 @@ static void order_objects_by_back_to_front(vulkan_render_queue_t* queue) SGE_API void vulkan_render_queue_dispatch(vulkan_render_queue_t* queue, vulkan_camera_t* camera, vulkan_render_scene_t* scene) { - debug_assert_wrn__(queue->is_ready, "Render Queue isn't ready but you are still trying to dispatch it"); - - /* if the camera is rendering only depth values then use the builtin depth shader and depth render pass */ if(vulkan_camera_is_depth_render_only(camera)) { @@ -679,6 +684,10 @@ SGE_API void vulkan_render_queue_dispatch(vulkan_render_queue_t* queue, vulkan_c return; } + /* build and optimize the render graph again if the queue is dirty. */ + if(!queue->is_ready) + vulkan_render_queue_build(queue); + // get the pointers to shader library and material library vulkan_shader_library_t* shader_library = queue->renderer->shader_library; vulkan_material_library_t* material_library = queue->renderer->material_library; diff --git a/source/sge/vulkan/vulkan_render_scene.c b/source/sge/vulkan/vulkan_render_scene.c index 54af2c0f..346a7ed5 100644 --- a/source/sge/vulkan/vulkan_render_scene.c +++ b/source/sge/vulkan/vulkan_render_scene.c @@ -475,8 +475,11 @@ SGE_API void vulkan_render_scene_build_queues(vulkan_render_scene_t* scene) for(u32 i = 0; i < count; i++) { AUTO queue = get_queue_at(scene, i); - debug_log_info("Queue type: %s", vulkan_render_queue_type_str(queue->type)); - vulkan_render_queue_build(queue); + if(vulkan_render_queue_is_ready(queue)) + { + debug_log_info("Queue type: %s", vulkan_render_queue_type_str(queue->type)); + vulkan_render_queue_build(queue); + } } }