Skip to content

Commit

Permalink
[SGE] Automatically build render graph on queue dispatch if the rende…
Browse files Browse the repository at this point in the history
…r queue has changed.
  • Loading branch information
ravi688 committed Oct 24, 2024
1 parent 54dd390 commit adbf58d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
2 changes: 2 additions & 0 deletions include/sge/internal/vulkan/vulkan_render_queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions include/sge/internal/vulkan/vulkan_render_scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
19 changes: 14 additions & 5 deletions source/sge/vulkan/vulkan_render_queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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))
{
Expand All @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions source/sge/vulkan/vulkan_render_scene.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit adbf58d

Please sign in to comment.