From 765e2639799e586ac8459dad866c6607a85576ba Mon Sep 17 00:00:00 2001 From: Kevin Trogant Date: Fri, 9 Feb 2024 10:09:39 +0100 Subject: [PATCH] Add render_command_buffer handle type Also unify handle types via macro --- src/renderer/vk/pipelines.c | 2 +- src/renderer/vk/render_targets.c | 2 +- src/runtime/main_loop.c | 1 + src/runtime/main_loop.h | 2 ++ src/runtime/renderer_api.h | 20 +++++++++++--------- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/renderer/vk/pipelines.c b/src/renderer/vk/pipelines.c index bea16df..be91aa1 100644 --- a/src/renderer/vk/pipelines.c +++ b/src/renderer/vk/pipelines.c @@ -126,7 +126,7 @@ rt_pipeline_handle RT_RENDERER_API_FN(CompilePipeline)(const rt_pipeline_info *i } rt_pipeline_slot *slot = _first_free; _first_free = slot->next_free; - slot->version = (slot->version + 1) & RT_GFX_HANDLE_MAX_VERSION; + slot->version = (slot->version + 1) & RT_RENDER_BACKEND_HANDLE_MAX_VERSION; /* No other thread that calls compile gets the same slot. * Another thread accessing the slot via GetPipeline would get a version mismatch. diff --git a/src/renderer/vk/render_targets.c b/src/renderer/vk/render_targets.c index b111cdd..63b1c5a 100644 --- a/src/renderer/vk/render_targets.c +++ b/src/renderer/vk/render_targets.c @@ -147,7 +147,7 @@ rt_render_target_handle RT_RENDERER_API_FN(CreateRenderTarget)(const rt_render_t } rt_render_target_slot *slot = _first_free; _first_free = slot->next_free; - slot->version = (slot->version + 1) & RT_GFX_HANDLE_MAX_VERSION; + slot->version = (slot->version + 1) & RT_RENDER_BACKEND_HANDLE_MAX_VERSION; /* No other thread that calls compile gets the same slot. * Another thread accessing the slot via GetPipeline would get a version mismatch. diff --git a/src/runtime/main_loop.c b/src/runtime/main_loop.c index 2d859db..f6c46bb 100644 --- a/src/runtime/main_loop.c +++ b/src/runtime/main_loop.c @@ -1,3 +1,4 @@ +#define RT_DONT_DEFINE_MAIN_LOOP_GLOBAL #include "main_loop.h" #include "runtime.h" #include "config.h" diff --git a/src/runtime/main_loop.h b/src/runtime/main_loop.h index 41eb279..8960344 100644 --- a/src/runtime/main_loop.h +++ b/src/runtime/main_loop.h @@ -23,8 +23,10 @@ typedef struct { volatile int shutdown; } rt_main_loop; +#ifndef RT_DONT_DEFINE_MAIN_LOOP_GLOBAL /* The applications main-loop */ extern RT_DLLIMPORT rt_main_loop g_main_loop; +#endif RT_DLLEXPORT rt_result rtInitMainLoop(rt_main_loop_update_fn *update_cb, rt_main_loop_render_fn *render_cb); diff --git a/src/runtime/renderer_api.h b/src/runtime/renderer_api.h index 539c25c..77fd587 100644 --- a/src/runtime/renderer_api.h +++ b/src/runtime/renderer_api.h @@ -88,17 +88,19 @@ typedef struct { /* Handles for backend objects */ -#define RT_GFX_HANDLE_MAX_VERSION 255 +#define RT_RENDER_BACKEND_HANDLE_MAX_VERSION 255 -typedef struct { - uint32_t version : 8; - uint32_t index : 24; -} rt_pipeline_handle; +#define RT_RENDER_BACKEND_HANDLE(name) \ + typedef struct { \ + uint32_t version : 8; \ + uint32_t index : 24; \ + } name -typedef struct { - uint32_t version : 8; - uint32_t index : 24; -} rt_render_target_handle; +RT_RENDER_BACKEND_HANDLE(rt_pipeline_handle); +RT_RENDER_BACKEND_HANDLE(rt_render_target_handle); +RT_RENDER_BACKEND_HANDLE(rt_render_command_buffer_handle); + +#undef RT_RENDER_BACKEND_HANDLE typedef void rt_register_renderer_cvars_fn(void); typedef rt_result rt_init_renderer_fn(const rt_renderer_init_info *info);