Skip to content

Commit

Permalink
Merge pull request #1 from ft-grmhd/master
Browse files Browse the repository at this point in the history
I forgor about indev branch
  • Loading branch information
Kbz-8 authored Sep 25, 2024
2 parents 9b7fbf0 + 41602b4 commit 68bb088
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 48 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
!README.md
!LICENSE
!xmake.lua
!compile_commands.json
!/Kanel/
!/Xmake/
!/.github/
Expand Down
19 changes: 19 additions & 0 deletions Kanel/Runtime/Includes/Core/Application.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2024 kanel
// This file is part of "kanel-CLI"
// For conditions of distribution and use, see copyright notice in LICENSE

#ifndef KANEL_CLI_CORE_APPLICATION
#define KANEL_CLI_CORE_APPLICATION

#include <Core/CoreDefs.h>

typedef struct KbhCoreApplication
{

} KbhCoreApplication;

KbhCoreApplication* kbhCreateCoreApplication(int argc, char** argv);
KANEL_CLI_NONNULL(1) void kbhLaunchCoreApplication(const KbhCoreApplication* application);
KANEL_CLI_NONNULL(1) void kbhDestroyCoreApplication(const KbhCoreApplication* application);

#endif
1 change: 0 additions & 1 deletion Kanel/Runtime/Includes/Modules/GPU/Vulkan/VulkanCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ typedef struct KbhVulkanContextHandler
size_t devices_count;
} KbhVulkanContextHandler;


KANEL_CLI_NONNULL(1) KbhRHIResult kbhVulkanInit(KbhVulkanContext* context);
KbhRHIResult kbhVulkanLoadNewDevice(KbhVulkanContext context);
void kbhVulkanUninit(KbhVulkanContext context);
Expand Down
42 changes: 42 additions & 0 deletions Kanel/Runtime/Sources/Core/Application.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (C) 2024 kanel
// This file is part of "kanel-CLI"
// For conditions of distribution and use, see copyright notice in LICENSE

#include <Core/Application.h>
#include <Core/RuntimeOptions.h>
#include <Core/ModuleLoader.h>
#include <GPU/GPUSupport.h>

#include <stdlib.h>

KbhCoreApplication* kbhCreateCoreApplication(int argc, char** argv)
{
KbhCoreApplication* application = (KbhCoreApplication*)malloc(sizeof(KbhCoreApplication));
if(!application)
return KANEL_CLI_NULLPTR;
if(!kbhRuntimeOptionsParseCmd(argc, argv))
{
kbhRuntimeOptionsClear();
return 0;
}
kbhCoreLoadAllModulesFromCmdLine();
return application;
}

void kbhLaunchCoreApplication(const KbhCoreApplication* application)
{
// tests
char dummy[1024];
if(kbhRuntimeOptionsGetString("gpu", dummy, 1024))
{
kbhInitGPUSupport();
kbhUninitGPUSupport();
}
}

void kbhDestroyCoreApplication(const KbhCoreApplication* application)
{
kbhCoreUnloadAllModules();
kbhRuntimeOptionsClear();
free((void*)application);
}
14 changes: 7 additions & 7 deletions Kanel/Runtime/Sources/Core/ModuleLoader.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,27 @@ typedef struct KbhCoreModuleDescriptor
KbhCoreModule type;
} KbhCoreModuleDescriptor;

static KbhCoreModuleDescriptor* head = KANEL_CLI_NULLPTR;
static KbhCoreModuleDescriptor* module_descriptors_head = KANEL_CLI_NULLPTR;

static void kbhAddLibModule(KbhLibModule module, KbhCoreModule type)
{
KbhCoreModuleDescriptor* descriptor = (KbhCoreModuleDescriptor*)malloc(sizeof(KbhCoreModuleDescriptor));
if(!descriptor)
kbhFatalError("allocation failed");
descriptor->next = head;
descriptor->next = module_descriptors_head;
descriptor->module = module;
descriptor->type = type;
head = descriptor;
module_descriptors_head = descriptor;
}

static void kbhRemoveLibModule(KbhCoreModule type)
{
KbhCoreModuleDescriptor* ptr = head;
KbhCoreModuleDescriptor* ptr = module_descriptors_head;
if(ptr == KANEL_CLI_NULLPTR)
return;
if(ptr->type == type)
{
head = ptr->next;
module_descriptors_head = ptr->next;
free((void*)ptr);
return;
}
Expand Down Expand Up @@ -93,8 +93,8 @@ KbhLibModule kbhCoreLoadModule(KbhCoreModule type)

void kbhCoreUnloadAllModules()
{
while(head != KANEL_CLI_NULLPTR)
kbhCoreUnloadModule(head->type);
while(module_descriptors_head != KANEL_CLI_NULLPTR)
kbhCoreUnloadModule(module_descriptors_head->type);
}

void kbhCoreUnloadModule(KbhCoreModule type)
Expand Down
34 changes: 17 additions & 17 deletions Kanel/Runtime/Sources/Core/RuntimeOptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,78 +35,78 @@ typedef struct KbhRuntimeOption
KbhRuntimeOptionType type;
} KbhRuntimeOption;

static KbhRuntimeOption* head = KANEL_CLI_NULLPTR;
static KbhRuntimeOption* runtime_options_head = KANEL_CLI_NULLPTR;

static void kbhAddRuntimeOptionStringToList(const char* name, const char* string)
{
KbhRuntimeOption* option = (KbhRuntimeOption*)malloc(sizeof(KbhRuntimeOption));
if(!option)
kbhFatalError("allocation failed");
option->next = head;
option->next = runtime_options_head;
option->name = strdup(name);
if(!option->name)
kbhFatalError("allocation failed");
option->string = strdup(string);
if(!option->string)
kbhFatalError("allocation failed");
option->type = KBH_RUNTIME_OPTION_STRING;
head = option;
runtime_options_head = option;
}

static void kbhAddRuntimeOptionFloat32ToList(const char* name, float f32)
{
KbhRuntimeOption* option = (KbhRuntimeOption*)malloc(sizeof(KbhRuntimeOption));
if(!option)
kbhFatalError("allocation failed");
option->next = head;
option->next = runtime_options_head;
option->name = strdup(name);
if(!option->name)
kbhFatalError("allocation failed");
option->f32 = f32;
option->type = KBH_RUNTIME_OPTION_FLOAT32;
head = option;
runtime_options_head = option;
}

static void kbhAddRuntimeOptionFloat64ToList(const char* name, double f64)
{
KbhRuntimeOption* option = (KbhRuntimeOption*)malloc(sizeof(KbhRuntimeOption));
if(!option)
kbhFatalError("allocation failed");
option->next = head;
option->next = runtime_options_head;
option->name = strdup(name);
if(!option->name)
kbhFatalError("allocation failed");
option->f64 = f64;
option->type = KBH_RUNTIME_OPTION_INT;
head = option;
runtime_options_head = option;
}

static void kbhAddRuntimeOptionIntegerToList(const char* name, int32_t integer)
{
KbhRuntimeOption* option = (KbhRuntimeOption*)malloc(sizeof(KbhRuntimeOption));
if(!option)
kbhFatalError("allocation failed");
option->next = head;
option->next = runtime_options_head;
option->name = strdup(name);
if(!option->name)
kbhFatalError("allocation failed");
option->integer = integer;
option->type = KBH_RUNTIME_OPTION_INT;
head = option;
runtime_options_head = option;
}

static void kbhAddRuntimeOptionBooleanToList(const char* name, bool boolean)
{
KbhRuntimeOption* option = (KbhRuntimeOption*)malloc(sizeof(KbhRuntimeOption));
if(!option)
kbhFatalError("allocation failed");
option->next = head;
option->next = runtime_options_head;
option->name = strdup(name);
if(!option->name)
kbhFatalError("allocation failed");
option->boolean = boolean;
option->type = KBH_RUNTIME_OPTION_BOOL;
head = option;
runtime_options_head = option;
}

bool kbhRuntimeOptionsParseCmd(int argc, char** argv)
Expand Down Expand Up @@ -140,7 +140,7 @@ bool kbhRuntimeOptionsParseCmd(int argc, char** argv)

bool kbhRuntimeOptionsGetString(const char* opt_name, char* dst, size_t dst_len)
{
KbhRuntimeOption* ptr = head;
KbhRuntimeOption* ptr = runtime_options_head;
while(ptr != KANEL_CLI_NULLPTR)
{
if(strcmp(ptr->name, opt_name) == 0)
Expand All @@ -163,7 +163,7 @@ bool kbhRuntimeOptionsGetString(const char* opt_name, char* dst, size_t dst_len)

bool kbhRuntimeOptionsGetFloat64(const char* opt_name, double* dst)
{
KbhRuntimeOption* ptr = head;
KbhRuntimeOption* ptr = runtime_options_head;
while(ptr != KANEL_CLI_NULLPTR)
{
if(strcmp(ptr->name, opt_name) == 0)
Expand All @@ -181,7 +181,7 @@ bool kbhRuntimeOptionsGetFloat64(const char* opt_name, double* dst)

bool kbhRuntimeOptionsGetFloat32(const char* opt_name, float* dst)
{
KbhRuntimeOption* ptr = head;
KbhRuntimeOption* ptr = runtime_options_head;
while(ptr != KANEL_CLI_NULLPTR)
{
if(strcmp(ptr->name, opt_name) == 0)
Expand All @@ -199,7 +199,7 @@ bool kbhRuntimeOptionsGetFloat32(const char* opt_name, float* dst)

bool kbhRuntimeOptionsGetInt(const char* opt_name, int32_t* dst)
{
KbhRuntimeOption* ptr = head;
KbhRuntimeOption* ptr = runtime_options_head;
while(ptr != KANEL_CLI_NULLPTR)
{
if(strcmp(ptr->name, opt_name) == 0)
Expand All @@ -217,7 +217,7 @@ bool kbhRuntimeOptionsGetInt(const char* opt_name, int32_t* dst)

bool kbhRuntimeOptionsGetBool(const char* opt_name, bool* dst)
{
KbhRuntimeOption* ptr = head;
KbhRuntimeOption* ptr = runtime_options_head;
while(ptr != KANEL_CLI_NULLPTR)
{
if(strcmp(ptr->name, opt_name) == 0)
Expand All @@ -235,7 +235,7 @@ bool kbhRuntimeOptionsGetBool(const char* opt_name, bool* dst)

void kbhRuntimeOptionsClear()
{
KbhRuntimeOption* ptr = head;
KbhRuntimeOption* ptr = runtime_options_head;
while(ptr != KANEL_CLI_NULLPTR)
{
KbhRuntimeOption* tmp = ptr->next;
Expand Down
27 changes: 6 additions & 21 deletions Kanel/Runtime/Sources/Core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,14 @@
// This file is part of "kanel-CLI"
// For conditions of distribution and use, see copyright notice in LICENSE

#include <Core/RuntimeOptions.h>
#include <Core/ModuleLoader.h>

#include <GPU/GPUSupport.h>
#include <Core/Application.h>

int main(int argc, char *argv[])
{
if(!kbhRuntimeOptionsParseCmd(argc, argv))
{
kbhRuntimeOptionsClear();
return 0;
}
kbhCoreLoadAllModulesFromCmdLine();

// tests
char dummy[1024];
if(kbhRuntimeOptionsGetString("gpu", dummy, 1024))
{
kbhInitGPUSupport();
kbhUninitGPUSupport();
}

kbhCoreUnloadAllModules();
kbhRuntimeOptionsClear();
KbhCoreApplication* application = kbhCreateCoreApplication(argc, argv);
if(!application)
return 1;
kbhLaunchCoreApplication(application);
kbhDestroyCoreApplication(application);
return 0;
}
13 changes: 12 additions & 1 deletion xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ add_rules("build.gpu_plugins")
option("compile_shaders", { description = "Compile nzsl shaders into an includable binary version", default = true })
option("static", { description = "Build the engine statically (implies embed_gpu_backends)", default = is_plat("wasm") or false })
option("embed_gpu_backends", { description = "Embed GPU backend code into libkanelcli_gpu instead of loading them dynamically", default = is_plat("wasm") or false })
option("unitybuild", { description = "Build the engine using unity build", default = false })

add_requires("vrg")

Expand Down Expand Up @@ -241,9 +242,15 @@ for name, module in pairs(modules) do
add_cflags("-fPIC")
end

add_ldflags("-Wl,--export-dynamic")

add_includedirs("Kanel/Runtime/Sources")
add_rpathdirs("$ORIGIN")

if has_config("unitybuild") then
add_rules("c.unity_build", { batchsize = 12 })
end

on_clean(function(target)
if target:objectfiles() then
for _, file in ipairs(target:objectfiles()) do
Expand Down Expand Up @@ -280,9 +287,13 @@ target("kanel_cli")

add_packages("vrg")

if has_config("unitybuild") then
add_rules("c.unity_build", { batchsize = 0 })
end

for _, dir in ipairs(os.dirs("Kanel/Runtime/Sources/*")) do
if dir ~= "Kanel/Runtime/Sources/Modules" then
add_files(dir .. "/**.c")
add_files(dir .. "/**.c", { unity_group = dir })
add_files(dir .. "/**.cpp")
end
end
Expand Down

0 comments on commit 68bb088

Please sign in to comment.