Skip to content

Commit

Permalink
adding Vulkan prototypes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kbz-8 committed Sep 17, 2024
1 parent e20674b commit f54ba62
Show file tree
Hide file tree
Showing 12 changed files with 293 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/linux-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- { mode: debug, config: --asan=y, archive: false, cache_key: -asan }
- { mode: debug, config: --lsan=y, archive: false }
- { mode: debug, config: --tsan=y, archive: false }
- { mode: releasedbg, archive: yes }
- { mode: release, archive: yes }

runs-on: ${{ matrix.os }}
if: ${{ !contains(github.event.head_commit.message, 'ci skip') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- { mode: debug, config: --asan=y, archive: false, cache_key: -asan }
- { mode: debug, config: --lsan=y, archive: false }
- { mode: debug, config: --tsan=y, archive: false }
- { mode: releasedbg, archive: yes }
- { mode: release, archive: yes }

runs-on: ${{ matrix.os }}
if: ${{ !contains(github.event.head_commit.message, 'ci skip') }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/msys2-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
msystem: [mingw64]
os: [windows-latest]
arch: [x86_64]
mode: [debug, releasedbg]
mode: [debug, release]
kind: [shared, static]

runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
matrix:
os: [windows-latest]
arch: [x64]
mode: [debug, releasedbg]
mode: [debug, release]
kind: [shared, static]

runs-on: ${{ matrix.os }}
Expand Down
41 changes: 38 additions & 3 deletions Akel/Runtime/Includes/Drivers/Vulkan/PreCompiled.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,45 @@
#include <Core/CompilationProfile.h>
#include <Drivers/Vulkan/Vulkan.h>

#include <volk.h>
#include <vulkan/vulkan_core.h>

#define KVF_IMPL_VK_NO_PROTOTYPES
#include <kvf.h>
#ifdef VK_USE_PLATFORM_ANDROID_KHR
#include <vulkan/vulkan_android.h>
#endif

#ifdef VK_USE_PLATFORM_WAYLAND_KHR
#include <vulkan/vulkan_wayland.h>
#endif

#ifdef VK_USE_PLATFORM_WIN32_KHR
typedef struct HINSTANCE__* HINSTANCE;
typedef struct HWND__* HWND;
typedef struct HMONITOR__* HMONITOR;
typedef void* HANDLE;
typedef /*_Null_terminated_*/ const wchar_t* LPCWSTR;
typedef unsigned long DWORD;
typedef struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES;
#include <vulkan/vulkan_win32.h>
#endif

#ifdef VK_USE_PLATFORM_XCB_KHR
struct xcb_connection_t;
typedef uint32_t xcb_window_t;
typedef uint32_t xcb_visualid_t;
#include <vulkan/vulkan_xcb.h>
#endif

#ifdef VK_USE_PLATFORM_METAL_EXT
#include <vulkan/vulkan_metal.h>
#endif

#ifdef VK_USE_PLATFORM_XLIB_KHR
typedef struct _XDisplay Display;
typedef unsigned long XID;
typedef XID Window;
typedef unsigned long VisualID;
#include <vulkan/vulkan_xlib.h>
#endif

#include <vector>

Expand Down
4 changes: 4 additions & 0 deletions Akel/Runtime/Includes/Drivers/Vulkan/VulkanDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ namespace Ak

void WaitForIdle() override;

#define AK_VULKAN_DEVICE_FUNCTION(fn) PFN_##fn fn;
#include <Drivers/Vulkan/VulkanDevicePrototypes.h>
#undef AK_VULKAN_DEVICE_FUNCTION

~VulkanDevice() override;

private:
Expand Down
134 changes: 134 additions & 0 deletions Akel/Runtime/Includes/Drivers/Vulkan/VulkanDevicePrototypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// Copyright (C) 2024 kbz_8 ( [email protected] )
// This file is a part of Akel
// For conditions of distribution and use, see copyright notice in LICENSE

// No header guards

#ifndef AK_VULKAN_DEVICE_FUNCTION
#error "AK_VULKAN_DEVICE_FUNCTION not defined"
#endif

#ifdef VK_VERSION_1_0
AK_VULKAN_DEVICE_FUNCTION(vkAllocateCommandBuffers)
AK_VULKAN_DEVICE_FUNCTION(vkAllocateDescriptorSets)
AK_VULKAN_DEVICE_FUNCTION(vkAllocateMemory)
AK_VULKAN_DEVICE_FUNCTION(vkBeginCommandBuffer)
AK_VULKAN_DEVICE_FUNCTION(vkBindBufferMemory)
AK_VULKAN_DEVICE_FUNCTION(vkBindImageMemory)
AK_VULKAN_DEVICE_FUNCTION(vkCmdBeginQuery)
AK_VULKAN_DEVICE_FUNCTION(vkCmdBeginRenderPass)
AK_VULKAN_DEVICE_FUNCTION(vkCmdBindDescriptorSets)
AK_VULKAN_DEVICE_FUNCTION(vkCmdBindIndexBuffer)
AK_VULKAN_DEVICE_FUNCTION(vkCmdBindPipeline)
AK_VULKAN_DEVICE_FUNCTION(vkCmdBindVertexBuffers)
AK_VULKAN_DEVICE_FUNCTION(vkCmdBlitImage)
AK_VULKAN_DEVICE_FUNCTION(vkCmdClearAttachments)
AK_VULKAN_DEVICE_FUNCTION(vkCmdClearColorImage)
AK_VULKAN_DEVICE_FUNCTION(vkCmdClearDepthStencilImage)
AK_VULKAN_DEVICE_FUNCTION(vkCmdCopyBuffer)
AK_VULKAN_DEVICE_FUNCTION(vkCmdCopyBufferToImage)
AK_VULKAN_DEVICE_FUNCTION(vkCmdCopyImage)
AK_VULKAN_DEVICE_FUNCTION(vkCmdCopyImageToBuffer)
AK_VULKAN_DEVICE_FUNCTION(vkCmdCopyQueryPoolResults)
AK_VULKAN_DEVICE_FUNCTION(vkCmdDispatch)
AK_VULKAN_DEVICE_FUNCTION(vkCmdDispatchIndirect)
AK_VULKAN_DEVICE_FUNCTION(vkCmdDraw)
AK_VULKAN_DEVICE_FUNCTION(vkCmdDrawIndexed)
AK_VULKAN_DEVICE_FUNCTION(vkCmdDrawIndexedIndirect)
AK_VULKAN_DEVICE_FUNCTION(vkCmdDrawIndirect)
AK_VULKAN_DEVICE_FUNCTION(vkCmdEndQuery)
AK_VULKAN_DEVICE_FUNCTION(vkCmdEndRenderPass)
AK_VULKAN_DEVICE_FUNCTION(vkCmdExecuteCommands)
AK_VULKAN_DEVICE_FUNCTION(vkCmdFillBuffer)
AK_VULKAN_DEVICE_FUNCTION(vkCmdNextSubpass)
AK_VULKAN_DEVICE_FUNCTION(vkCmdPipelineBarrier)
AK_VULKAN_DEVICE_FUNCTION(vkCmdPushConstants)
AK_VULKAN_DEVICE_FUNCTION(vkCmdResetEvent)
AK_VULKAN_DEVICE_FUNCTION(vkCmdResetQueryPool)
AK_VULKAN_DEVICE_FUNCTION(vkCmdResolveImage)
AK_VULKAN_DEVICE_FUNCTION(vkCmdSetBlendConstants)
AK_VULKAN_DEVICE_FUNCTION(vkCmdSetDepthBias)
AK_VULKAN_DEVICE_FUNCTION(vkCmdSetDepthBounds)
AK_VULKAN_DEVICE_FUNCTION(vkCmdSetEvent)
AK_VULKAN_DEVICE_FUNCTION(vkCmdSetLineWidth)
AK_VULKAN_DEVICE_FUNCTION(vkCmdSetScissor)
AK_VULKAN_DEVICE_FUNCTION(vkCmdSetStencilCompareMask)
AK_VULKAN_DEVICE_FUNCTION(vkCmdSetStencilReference)
AK_VULKAN_DEVICE_FUNCTION(vkCmdSetStencilWriteMask)
AK_VULKAN_DEVICE_FUNCTION(vkCmdSetViewport)
AK_VULKAN_DEVICE_FUNCTION(vkCmdUpdateBuffer)
AK_VULKAN_DEVICE_FUNCTION(vkCmdWaitEvents)
AK_VULKAN_DEVICE_FUNCTION(vkCmdWriteTimestamp)
AK_VULKAN_DEVICE_FUNCTION(vkCreateBuffer)
AK_VULKAN_DEVICE_FUNCTION(vkCreateBufferView)
AK_VULKAN_DEVICE_FUNCTION(vkCreateCommandPool)
AK_VULKAN_DEVICE_FUNCTION(vkCreateComputePipelines)
AK_VULKAN_DEVICE_FUNCTION(vkCreateDescriptorPool)
AK_VULKAN_DEVICE_FUNCTION(vkCreateDescriptorSetLayout)
AK_VULKAN_DEVICE_FUNCTION(vkCreateEvent)
AK_VULKAN_DEVICE_FUNCTION(vkCreateFence)
AK_VULKAN_DEVICE_FUNCTION(vkCreateFramebuffer)
AK_VULKAN_DEVICE_FUNCTION(vkCreateGraphicsPipelines)
AK_VULKAN_DEVICE_FUNCTION(vkCreateImage)
AK_VULKAN_DEVICE_FUNCTION(vkCreateImageView)
AK_VULKAN_DEVICE_FUNCTION(vkCreatePipelineCache)
AK_VULKAN_DEVICE_FUNCTION(vkCreatePipelineLayout)
AK_VULKAN_DEVICE_FUNCTION(vkCreateRenderPass)
AK_VULKAN_DEVICE_FUNCTION(vkCreateSampler)
AK_VULKAN_DEVICE_FUNCTION(vkCreateSemaphore)
AK_VULKAN_DEVICE_FUNCTION(vkCreateShaderModule)
AK_VULKAN_DEVICE_FUNCTION(vkDestroyBuffer)
AK_VULKAN_DEVICE_FUNCTION(vkDestroyBufferView)
AK_VULKAN_DEVICE_FUNCTION(vkDestroyCommandPool)
AK_VULKAN_DEVICE_FUNCTION(vkDestroyDescriptorPool)
AK_VULKAN_DEVICE_FUNCTION(vkDestroyDescriptorSetLayout)
AK_VULKAN_DEVICE_FUNCTION(vkDestroyDevice)
AK_VULKAN_DEVICE_FUNCTION(vkDestroyEvent)
AK_VULKAN_DEVICE_FUNCTION(vkDestroyFence)
AK_VULKAN_DEVICE_FUNCTION(vkDestroyFramebuffer)
AK_VULKAN_DEVICE_FUNCTION(vkDestroyImage)
AK_VULKAN_DEVICE_FUNCTION(vkDestroyImageView)
AK_VULKAN_DEVICE_FUNCTION(vkDestroyPipeline)
AK_VULKAN_DEVICE_FUNCTION(vkDestroyPipelineCache)
AK_VULKAN_DEVICE_FUNCTION(vkDestroyPipelineLayout)
AK_VULKAN_DEVICE_FUNCTION(vkDestroyRenderPass)
AK_VULKAN_DEVICE_FUNCTION(vkDestroySampler)
AK_VULKAN_DEVICE_FUNCTION(vkDestroySemaphore)
AK_VULKAN_DEVICE_FUNCTION(vkDestroyShaderModule)
AK_VULKAN_DEVICE_FUNCTION(vkDeviceWaitIdle)
AK_VULKAN_DEVICE_FUNCTION(vkEndCommandBuffer)
AK_VULKAN_DEVICE_FUNCTION(vkFlushMappedMemoryRanges)
AK_VULKAN_DEVICE_FUNCTION(vkFreeCommandBuffers)
AK_VULKAN_DEVICE_FUNCTION(vkFreeDescriptorSets)
AK_VULKAN_DEVICE_FUNCTION(vkFreeMemory)
AK_VULKAN_DEVICE_FUNCTION(vkGetBufferMemoryRequirements)
AK_VULKAN_DEVICE_FUNCTION(vkGetDeviceMemoryCommitment)
AK_VULKAN_DEVICE_FUNCTION(vkGetDeviceQueue)
AK_VULKAN_DEVICE_FUNCTION(vkGetEventStatus)
AK_VULKAN_DEVICE_FUNCTION(vkGetFenceStatus)
AK_VULKAN_DEVICE_FUNCTION(vkGetImageMemoryRequirements)
AK_VULKAN_DEVICE_FUNCTION(vkGetImageSparseMemoryRequirements)
AK_VULKAN_DEVICE_FUNCTION(vkGetImageSubresourceLayout)
AK_VULKAN_DEVICE_FUNCTION(vkGetRenderAreaGranularity)
AK_VULKAN_DEVICE_FUNCTION(vkInvalidateMappedMemoryRanges)
AK_VULKAN_DEVICE_FUNCTION(vkMapMemory)
AK_VULKAN_DEVICE_FUNCTION(vkMergePipelineCaches)
AK_VULKAN_DEVICE_FUNCTION(vkQueueSubmit)
AK_VULKAN_DEVICE_FUNCTION(vkQueueWaitIdle)
AK_VULKAN_DEVICE_FUNCTION(vkResetCommandBuffer)
AK_VULKAN_DEVICE_FUNCTION(vkResetCommandPool)
AK_VULKAN_DEVICE_FUNCTION(vkResetDescriptorPool)
AK_VULKAN_DEVICE_FUNCTION(vkResetEvent)
AK_VULKAN_DEVICE_FUNCTION(vkResetFences)
AK_VULKAN_DEVICE_FUNCTION(vkSetEvent)
AK_VULKAN_DEVICE_FUNCTION(vkUnmapMemory)
AK_VULKAN_DEVICE_FUNCTION(vkUpdateDescriptorSets)
AK_VULKAN_DEVICE_FUNCTION(vkWaitForFences)
#endif
#ifdef VK_KHR_swapchain
AK_VULKAN_DEVICE_FUNCTION(vkAcquireNextImageKHR)
AK_VULKAN_DEVICE_FUNCTION(vkCreateSwapchainKHR)
AK_VULKAN_DEVICE_FUNCTION(vkDestroySwapchainKHR)
AK_VULKAN_DEVICE_FUNCTION(vkGetSwapchainImagesKHR)
AK_VULKAN_DEVICE_FUNCTION(vkQueuePresentKHR)
#endif
87 changes: 87 additions & 0 deletions Akel/Runtime/Includes/Drivers/Vulkan/VulkanGlobalPrototypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// Copyright (C) 2024 kbz_8 ( [email protected] )
// This file is a part of Akel
// For conditions of distribution and use, see copyright notice in LICENSE

// No header guards

#ifndef AK_VULKAN_GLOBAL_FUNCTION
#error "AK_VULKAN_GLOBAL_FUNCTION not defined"
#endif

#ifdef VK_VERSION_1_0
AK_VULKAN_GLOBAL_FUNCTION(vkCreateDevice)
AK_VULKAN_GLOBAL_FUNCTION(vkDestroyInstance)
AK_VULKAN_GLOBAL_FUNCTION(vkEnumerateDeviceExtensionProperties)
AK_VULKAN_GLOBAL_FUNCTION(vkEnumeratePhysicalDevices)
AK_VULKAN_GLOBAL_FUNCTION(vkGetDeviceProcAddr)
AK_VULKAN_GLOBAL_FUNCTION(vkGetPhysicalDeviceFeatures)
AK_VULKAN_GLOBAL_FUNCTION(vkGetPhysicalDeviceFormatProperties)
AK_VULKAN_GLOBAL_FUNCTION(vkGetPhysicalDeviceImageFormatProperties)
AK_VULKAN_GLOBAL_FUNCTION(vkGetPhysicalDeviceMemoryProperties)
AK_VULKAN_GLOBAL_FUNCTION(vkGetPhysicalDeviceProperties)
AK_VULKAN_GLOBAL_FUNCTION(vkGetPhysicalDeviceQueueFamilyProperties)
#endif

#ifdef VK_KHR_surface
AK_VULKAN_GLOBAL_FUNCTION(vkDestroySurfaceKHR)
AK_VULKAN_GLOBAL_FUNCTION(vkGetPhysicalDeviceSurfaceCapabilitiesKHR)
AK_VULKAN_GLOBAL_FUNCTION(vkGetPhysicalDeviceSurfaceFormatsKHR)
AK_VULKAN_GLOBAL_FUNCTION(vkGetPhysicalDeviceSurfacePresentModesKHR)
AK_VULKAN_GLOBAL_FUNCTION(vkGetPhysicalDeviceSurfaceSupportKHR)
#endif

#ifdef AK_VULKAN_DEBUG
#ifdef VK_EXT_debug_report
AK_VULKAN_GLOBAL_FUNCTION(vkCreateDebugReportCallbackEXT)
AK_VULKAN_GLOBAL_FUNCTION(vkDestroyDebugReportCallbackEXT)
AK_VULKAN_GLOBAL_FUNCTION(vkDebugReportMessageEXT)
#endif

#ifdef VK_EXT_debug_utils
AK_VULKAN_GLOBAL_FUNCTION(vkCreateDebugUtilsMessengerEXT)
AK_VULKAN_GLOBAL_FUNCTION(vkDestroyDebugUtilsMessengerEXT)
AK_VULKAN_GLOBAL_FUNCTION(vkSetDebugUtilsObjectNameEXT)
AK_VULKAN_GLOBAL_FUNCTION(vkSetDebugUtilsObjectTagEXT)
AK_VULKAN_GLOBAL_FUNCTION(vkSubmitDebugUtilsMessageEXT)
#endif
#endif

#ifdef VK_USE_PLATFORM_ANDROID_KHR
#ifdef VK_KHR_android_surface
AK_VULKAN_GLOBAL_FUNCTION(vkCreateAndroidSurfaceKHR)
#endif
#endif

#ifdef VK_USE_PLATFORM_XCB_KHR
#ifdef VK_KHR_xcb_surface
AK_VULKAN_GLOBAL_FUNCTION(vkCreateXcbSurfaceKHR)
AK_VULKAN_GLOBAL_FUNCTION(vkGetPhysicalDeviceXcbPresentationSupportKHR)
#endif
#endif

#ifdef VK_USE_PLATFORM_XLIB_KHR
#ifdef VK_KHR_xlib_surface
AK_VULKAN_GLOBAL_FUNCTION(vkCreateXlibSurfaceKHR)
AK_VULKAN_GLOBAL_FUNCTION(vkGetPhysicalDeviceXlibPresentationSupportKHR)
#endif
#endif

#ifdef VK_USE_PLATFORM_WAYLAND_KHR
#ifdef VK_KHR_wayland_surface
AK_VULKAN_GLOBAL_FUNCTION(vkCreateWaylandSurfaceKHR)
AK_VULKAN_GLOBAL_FUNCTION(vkGetPhysicalDeviceWaylandPresentationSupportKHR)
#endif
#endif

#ifdef VK_USE_PLATFORM_WIN32_KHR
#ifdef VK_KHR_win32_surface
AK_VULKAN_GLOBAL_FUNCTION(vkCreateWin32SurfaceKHR)
AK_VULKAN_GLOBAL_FUNCTION(vkGetPhysicalDeviceWin32PresentationSupportKHR)
#endif
#endif

#ifdef VK_USE_PLATFORM_METAL_EXT
#ifdef VK_EXT_metal_surface
AK_VULKAN_GLOBAL_FUNCTION(vkCreateMetalSurfaceEXT)
#endif
#endif
13 changes: 11 additions & 2 deletions Akel/Runtime/Includes/Drivers/Vulkan/VulkanRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@

namespace Ak
{
#define AK_VULKAN_GLOBAL_FUNCTION(fn) PFN_##fn fn;
#include <Drivers/Vulkan/VulkanGlobalPrototypes.h>
#undef AK_VULKAN_GLOBAL_FUNCTION

[[nodiscard]]
const char* VerbaliseVkResult(VkResult result) noexcept;

Expand All @@ -22,12 +26,17 @@ namespace Ak
VulkanRenderer();

inline VulkanDevice& GetDevice() override;
//inline static VulkanInstance& GetInstance();
inline VulkanInstance& GetInstance();

inline static bool IsInit() noexcept;
inline static VulkanRenderer& Get() noexcept;

~VulkanRenderer() override;

private:
//static UniquePtr<VulkanInstance> p_instance;
static VulkanRenderer* s_instance;

UniquePtr<VulkanInstance> p_instance;
UniquePtr<VulkanDevice> p_device;
};

Expand Down
26 changes: 13 additions & 13 deletions Akel/Runtime/Includes/Drivers/Vulkan/VulkanRenderer.inl
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,26 @@ namespace Ak
{
return *p_device;
}
/*

VulkanInstance& VulkanRenderer::GetInstance()
{
Verify((bool)p_instance, "Vulkan Renderer : cannot get Vulkan instance as the renderer is not init");
return *p_instance;
}
*/
bool IsVulkanSupported() noexcept

bool VulkanRenderer::IsInit() noexcept
{
if(volkInitialize() != VK_SUCCESS)
return false;
return s_instance != nullptr;
}

CallOnExit uninit_volk(volkFinalize);
VulkanRenderer& VulkanRenderer::Get() noexcept
{
Assert(IsInit(), "VulkanRenderer is not initialized");
return *s_instance;
}

VkInstance instance;
VkInstanceCreateInfo create_info{};
create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO;
VkResult res;
if(vkCreateInstance(&create_info, nullptr, &instance) != VK_SUCCESS)
return false;
bool IsVulkanSupported() noexcept
{
// TODO
return true;
}
}
2 changes: 1 addition & 1 deletion Akel/Runtime/Sources/Graphics/GraphicsModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ namespace Ak
{ "none", RendererDrivers::None },
};

static std::optional<std::string> driver_option = CommandLineInterface::Get().GetOption("rdr-driver");
static std::optional<std::string> driver_option = CommandLineInterface::Get().GetOption("renderer-backend");
if(driver_option.has_value())
{
if(!cli_options.Has(*driver_option))
Expand Down
Loading

0 comments on commit f54ba62

Please sign in to comment.