Skip to content

Commit

Permalink
added CI, added Vulkan devices management
Browse files Browse the repository at this point in the history
  • Loading branch information
Kbz-8 committed Sep 16, 2024
1 parent 2ee6644 commit 24a515c
Show file tree
Hide file tree
Showing 24 changed files with 798 additions and 55 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/linux-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Linux build

on:
pull_request:
push:
paths-ignore:
- '.github/workflows/macos-build.yml'
- '.github/workflows/windows-build.yml'
- '.gitignore'
- 'LICENSE'
- 'README.md'

jobs:
build:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
arch: [x86_64]
kind: [shared, static]
confs:
- { mode: debug }
- { mode: debug, config: --asan=y }
- { mode: debug, config: --lsan=y }
- { mode: debug, config: --tsan=y }
- { mode: release }

runs-on: ${{ matrix.os }}
if: ${{ !contains(github.event.head_commit.message, 'ci skip') }}

steps:
- name: Get current date as package key
id: cache_key
run: echo "key=$(date +'%W')" >> $GITHUB_OUTPUT

# Install system dependencies
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get -y install mesa-common-dev
- name: Checkout repository
uses: actions/checkout@v4

# Force xmake to a specific folder (for cache)
- name: Set xmake env
run: echo "XMAKE_GLOBALDIR=${{ runner.workspace }}/xmake-global" >> $GITHUB_ENV

# Install xmake
- name: Setup xmake
uses: xmake-io/github-action-setup-xmake@v1
with:
actions-cache-folder: .xmake-cache-W${{ steps.cache_key.outputs.key }}

# Update xmake repository (in order to have the file that will be cached)
- name: Update xmake repository
run: xmake repo --update

# Fetch xmake dephash
- name: Retrieve dependencies hash
id: dephash
run: echo "hash=$(xmake l utils.ci.packageskey)" >> $GITHUB_OUTPUT
shell: bash

# Cache xmake dependencies
- name: Retrieve cached xmake dependencies
id: restore-depcache
uses: actions/cache/restore@v4
with:
path: ${{ env.XMAKE_GLOBALDIR }}/.xmake/packages
key: Linux-${{ matrix.arch }}-${{ matrix.confs.mode }}-${{ steps.dephash.outputs.hash }}-W${{ steps.cache_key.outputs.key }}

# Setup compilation mode and install project dependencies
- name: Configure xmake and install dependencies
run: xmake config --arch=${{ matrix.arch }} --mode=${{ matrix.confs.mode }} --kind=${{ matrix.kind }} --ccache=n --yes

# Save dependencies
- name: Save cached xmake dependencies
if: ${{ !steps.restore-depcache.outputs.cache-hit }}
uses: actions/cache/save@v4
with:
path: ${{ env.XMAKE_GLOBALDIR }}/.xmake/packages
key: ${{ steps.restore-depcache.outputs.cache-primary-key }}

# Build kanel CLI
- name: Build kanel CLI
run: xmake --yes
75 changes: 75 additions & 0 deletions .github/workflows/macos-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: macOS build

on:
pull_request:
push:
paths-ignore:
- '.github/workflows/linux-build.yml'
- '.github/workflows/windows-build.yml'
- '.gitignore'
- 'LICENSE'
- 'README.md'

jobs:
build:
strategy:
fail-fast: false
matrix:
os: [macOS-latest]
mode: [debug, releasedbg]
kind: [static, shared]
arch: [x86_64, arm64]

runs-on: ${{ matrix.os }}
if: ${{ !contains(github.event.head_commit.message, 'ci skip') }}

steps:
- name: Get current date as package key
id: cache_key
run: echo "key=$(date +'%W')" >> $GITHUB_OUTPUT

- name: Checkout repository
uses: actions/checkout@v4

# Force xmake to a specific folder (for cache)
- name: Set xmake env
run: echo "XMAKE_GLOBALDIR=${{ runner.workspace }}/xmake-global" >> $GITHUB_ENV

# Install xmake
- name: Setup xmake
uses: xmake-io/github-action-setup-xmake@v1
with:
actions-cache-folder: .xmake-cache-W${{ steps.cache_key.outputs.key }}

# Update xmake repository (in order to have the file that will be cached)
- name: Update xmake repository
run: xmake repo --update

# Fetch xmake dephash
- name: Retrieve dependencies hash
id: dephash
run: echo "hash=$(xmake l utils.ci.packageskey)" >> $GITHUB_OUTPUT

# Cache xmake dependencies
- name: Retrieve cached xmake dependencies
id: restore-depcache
uses: actions/cache/restore@v4
with:
path: ${{ env.XMAKE_GLOBALDIR }}/.xmake/packages
key: macOS-${{ matrix.arch }}-${{ matrix.mode }}-${{ steps.dephash.outputs.hash }}-W${{ steps.cache_key.outputs.key }}

# Setup compilation mode and install project dependencies
- name: Configure xmake and install dependencies
run: xmake config --arch=${{ matrix.arch }} --mode=${{ matrix.mode }} --kind=${{ matrix.kind }} --ccache=n --yes

# Save dependencies
- name: Save cached xmake dependencies
if: ${{ !steps.restore-depcache.outputs.cache-hit }}
uses: actions/cache/save@v4
with:
path: ${{ env.XMAKE_GLOBALDIR }}/.xmake/packages
key: ${{ steps.restore-depcache.outputs.cache-primary-key }}

# Build kanel CLI
- name: Build kanel CLI
run: xmake --yes
82 changes: 82 additions & 0 deletions .github/workflows/windows-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: Windows build

on:
pull_request:
push:
paths-ignore:
- '.github/workflows/linux-build.yml'
- '.github/workflows/macos-build.yml'
- '.gitignore'
- 'LICENSE'
- 'README.md'

jobs:
build:
strategy:
matrix:
os: [windows-latest]
arch: [x86, x64]
config:
- { kind: "static", mode: "debug", runtime: "MDd" }
- { kind: "static", mode: "debug", runtime: "MTd" }
- { kind: "static", mode: "release", runtime: "MD" }
- { kind: "static", mode: "release", runtime: "MT" }
- { kind: "shared", mode: "debug", runtime: "MDd" }
- { kind: "shared", mode: "release", runtime: "MD" }

runs-on: ${{ matrix.os }}
if: ${{ !contains(github.event.head_commit.message, 'ci skip') }}

steps:
- name: Get current date as package key
id: cache_key
run: echo "key=$(date +'%W')" >> $GITHUB_OUTPUT
shell: bash

- name: Avoid line ending issues on Windows
run: git config --global core.autocrlf false

- name: Checkout repository
uses: actions/checkout@v4

# Force xmake to a specific folder (for cache)
- name: Set xmake env
run: echo "XMAKE_GLOBALDIR=${{ runner.workspace }}/xmake-global" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append

# Install xmake
- name: Setup xmake
uses: xmake-io/github-action-setup-xmake@v1

# Update xmake repository (in order to have the file that will be cached)
- name: Update xmake repository
run: xmake repo --update

# Fetch xmake dephash
- name: Retrieve dependencies hash
id: dephash
run: echo "hash=$(xmake l utils.ci.packageskey)" >> $GITHUB_OUTPUT
shell: bash

# Cache xmake dependencies
- name: Retrieve cached xmake dependencies
id: restore-depcache
uses: actions/cache/restore@v4
with:
path: ${{ env.XMAKE_GLOBALDIR }}\.xmake\packages
key: MSVC-${{ matrix.arch }}-${{ matrix.config.mode }}-${{ matrix.config.runtime }}-${{ steps.dephash.outputs.hash }}-W${{ steps.cache_key.outputs.key }}

# Setup compilation mode and install project dependencies
- name: Configure xmake and install dependencies
run: xmake config --arch=${{ matrix.arch }} --kind=${{ matrix.config.kind }} --mode=${{ matrix.config.mode }} --vs_runtime=${{ matrix.config.runtime }} --ccache=n --yes

# Save dependencies
- name: Save cached xmake dependencies
if: ${{ !steps.restore-depcache.outputs.cache-hit }}
uses: actions/cache/save@v4
with:
path: ${{ env.XMAKE_GLOBALDIR }}/.xmake/packages
key: ${{ steps.restore-depcache.outputs.cache-primary-key }}

# Build kanel CLI
- name: Build kanel CLI
run: xmake --yes
5 changes: 4 additions & 1 deletion Kanel/Runtime/Includes/Modules/GPU/RHI/RHICore.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ static inline const char* kbhVerbaliseRHIResult(KbhRHIResult result)
switch(result)
{
case KBH_RHI_SUCCESS: return "Success";
case KBH_RHI_INCOMPLETE: return "Incomplete data";
case KBH_RHI_ERROR_INITIALIZATION_FAILED: return "Initialization of an object could not be completed for implementation-specific reasons";

default: return "Unknown RHI error";
Expand All @@ -35,8 +36,10 @@ static inline const char* kbhVerbaliseRHIResult(KbhRHIResult result)

static inline void kbhCheckRHIBackend(KbhRHIResult result, const char* file, const char* function, int line)
{
if(result != KBH_RHI_SUCCESS)
if(result < KBH_RHI_SUCCESS)
kbhFatalErrorBackend("RHI check failed due to: %s", file, function, line, kbhVerbaliseRHIResult(result));
else if(result > KBH_RHI_SUCCESS)
kbhErrorBackend("RHI check failed due to: %s", file, function, line, kbhVerbaliseRHIResult(result));
}

#undef kbhCheckRHI
Expand Down
1 change: 1 addition & 0 deletions Kanel/Runtime/Includes/Modules/GPU/RHI/RHIEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef enum KbhRHIType
typedef enum KbhRHIResult
{
KBH_RHI_SUCCESS = 0,
KBH_RHI_INCOMPLETE = 1,
KBH_RHI_ERROR_UNKOWN = -1,
KBH_RHI_ERROR_INITIALIZATION_FAILED = -2,
KBH_RHI_ERROR_INVALID_HANDLE = -3,
Expand Down
17 changes: 10 additions & 7 deletions Kanel/Runtime/Includes/Modules/GPU/Vulkan/VulkanCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,20 @@

#include <Core/Logs.h>

typedef struct VulkanDevice VulkanDevice;
KANEL_CLI_VULKAN_DEFINE_NULLABLE_HANDLE(KbhVulkanContext);
KANEL_CLI_VULKAN_DEFINE_NULLABLE_HANDLE(KbhVulkanDevice);

typedef struct KbhVulkanContext
typedef struct KbhVulkanContextHandler
{
VkInstance instance;
VulkanDevice* devices;
KbhVulkanDevice* devices;
size_t devices_count;
} KbhVulkanContext;
} KbhVulkanContextHandler;

KANEL_CLI_NONNULL(1) KbhRHIResult kbhVulkanInit(KbhVulkanContext** context);
void kbhVulkanUninit(KbhVulkanContext* context);

KANEL_CLI_NONNULL(1) KbhRHIResult kbhVulkanInit(KbhVulkanContext* context);
KbhRHIResult kbhVulkanLoadNewDevice(KbhVulkanContext context);
void kbhVulkanUninit(KbhVulkanContext context);

KANEL_CLI_VULKAN_API KbhRHILoaderPFNs kbhRHIVulkanBackendAcquirePFNs();

Expand Down Expand Up @@ -73,7 +76,7 @@ static inline const char* kbhVerbaliseVkResult(VkResult result)

static inline void kbhCheckVkBackend(VkResult result, const char* file, const char* function, int line)
{
if(result != KBH_RHI_SUCCESS)
if(result != VK_SUCCESS)
kbhFatalErrorBackend("Vulkan check failed due to: %s", file, function, line, kbhVerbaliseVkResult(result));
}

Expand Down
4 changes: 4 additions & 0 deletions Kanel/Runtime/Includes/Modules/GPU/Vulkan/VulkanDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,8 @@
#define KANEL_CLI_VULKAN_API
#endif

#define KANEL_CLI_VULKAN_DEFINE_NULLABLE_HANDLE(object) typedef struct object##Handler* object

#define KANEL_CLI_VULKAN_NULL_HANDLE KANEL_CLI_NULLPTR

#endif
4 changes: 4 additions & 0 deletions Kanel/Runtime/Sources/Modules/GPU/Vulkan/VulkanBuffer.c
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
// Copyright (C) 2024 kanel
// This file is part of "kanel-CLI"
// For conditions of distribution and use, see copyright notice in LICENSE

#include <Modules/GPU/Vulkan/VulkanBuffer.h>
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
// Copyright (C) 2024 kanel
// This file is part of "kanel-CLI"
// For conditions of distribution and use, see copyright notice in LICENSE

#include <Modules/GPU/Vulkan/VulkanCommandBuffer.h>

4 changes: 4 additions & 0 deletions Kanel/Runtime/Sources/Modules/GPU/Vulkan/VulkanCommandPool.c
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
// Copyright (C) 2024 kanel
// This file is part of "kanel-CLI"
// For conditions of distribution and use, see copyright notice in LICENSE

#include <Modules/GPU/Vulkan/VulkanCommandPool.h>

28 changes: 24 additions & 4 deletions Kanel/Runtime/Sources/Modules/GPU/Vulkan/VulkanCore.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
#include <Modules/GPU/Vulkan/VulkanCore.h>
#include <Modules/GPU/Vulkan/VulkanLoader.h>
#include <Modules/GPU/Vulkan/VulkanInstance.h>
#include <Modules/GPU/Vulkan/VulkanDevice.h>

#include <Modules/GPU/RHI/RHICore.h>

#include <Config.h>

#include <Core/Logs.h>

#include <stdlib.h>

KbhRHIResult kbhVulkanInit(KbhVulkanContext** context)
KbhRHIResult kbhVulkanInit(KbhVulkanContext* context)
{
*context = (KbhVulkanContext*)malloc(sizeof(KbhVulkanContext));
*context = (KbhVulkanContext)malloc(sizeof(KbhVulkanContextHandler));
if(!*context)
return KBH_RHI_ERROR_INITIALIZATION_FAILED;

Expand All @@ -25,14 +28,31 @@ KbhRHIResult kbhVulkanInit(KbhVulkanContext** context)
(*context)->instance = kbhVulkanCreateInstance(instance_extensions, sizeof(instance_extensions) / sizeof(const char*));
kbhLoadInstance((*context)->instance);

kbhCheckRHI(kbhVulkanLoadNewDevice(*context));

return KBH_RHI_SUCCESS;
}

KbhRHIResult kbhVulkanLoadNewDevice(KbhVulkanContext context)
{
if(context == KANEL_CLI_VULKAN_NULL_HANDLE)
return KBH_RHI_ERROR_INITIALIZATION_FAILED;
context->devices = (KbhVulkanDevice*)realloc(context->devices, sizeof(KbhVulkanDeviceHandler) * (context->devices_count + 1));
kbhVerify(context->devices != KANEL_CLI_NULLPTR); // Verify and not return error because if alloc fails, older devices are lost
kbhCheckRHI(kbhCreateVulkanDevice(context, &context->devices[context->devices_count]));
context->devices_count++;
return KBH_RHI_SUCCESS;
}

void kbhVulkanUninit(KbhVulkanContext* context)
void kbhVulkanUninit(KbhVulkanContext context)
{
if(context == KANEL_CLI_VULKAN_NULL_HANDLE)
return;
#pragma omp parallel for
for(size_t i = 0; i < context->devices_count; i++)
kbhDestroyVulkanDevice(context->devices[i]);
kbhVulkanDestroyInstance(context->instance);
kbhVulkanLoaderUninit();

free(context);
}

Expand Down
Loading

0 comments on commit 24a515c

Please sign in to comment.