Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor passing VK objects #25

Merged
merged 6 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/nova_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
pushd cov_build && make test && popd
- name: Generate unit tests coverage
run: |
./bin/generate_ut_cov.sh
./bin/generate-ut-cov.sh
- name: Send raport to Codecov
uses: codecov/codecov-action@v1
with:
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@
[submodule "3rdparty/ImGuizmo"]
path = 3rdparty/ImGuizmo
url = https://github.com/CedricGuillemet/ImGuizmo.git
[submodule "3rdparty/backward-cpp"]
path = 3rdparty/backward-cpp
url = https://github.com/bombela/backward-cpp.git
1 change: 1 addition & 0 deletions 3rdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
add_subdirectory(libkc)
add_subdirectory(expected)
add_subdirectory(backward-cpp)

# imgui

Expand Down
1 change: 1 addition & 0 deletions 3rdparty/backward-cpp
Submodule backward-cpp added at 51f070
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ cmake_minimum_required(VERSION 3.10)
project(starlight)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_BUILD_TYPE Debug)
# set(CMAKE_BUILD_TYPE RelWithDebInfo)
set(SL_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/engine/src)

set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")
set (CMAKE_LINKER_FLAGS_DEBUG "${CMAKE_LINKER_FLAGS_DEBUG} -fno-omit-frame-pointer -fsanitize=address")

add_definitions(-DDEV_MODE=1)
add_definitions(-DUSE_GLFW=1)
add_definitions(-DUSE_VK=1)
Expand Down
7 changes: 7 additions & 0 deletions assets/shaders/Builtin.Shader.UIGrid.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#version 450

layout(location = 0) out vec4 outColor;

void main() {
outColor = vec4(1.0, 0.0, 0.0, 1.0);
}
17 changes: 17 additions & 0 deletions assets/shaders/Builtin.Shader.UIGrid.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"version": 1.0,
"name": "Builtin.Shader.UIGrid",
"cullMode": "back",
"stages": [
{ "stage": "vertex", "file": "Builtin.Shader.UIGrid.vert.spv" },
{ "stage": "fragment", "file": "Builtin.Shader.UIGrid.frag.spv" }
],
"use-instances": false,
"use-local": false,
"attributes": [],
"uniforms": [
{ "type": "mat4", "scope": "global", "name": "view" },
{ "type": "mat4", "scope": "global", "name": "projection" },
{ "type": "vec3", "scope": "global", "name": "pos" }
]
}
19 changes: 19 additions & 0 deletions assets/shaders/Builtin.Shader.UIGrid.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#version 450

// Shared set between most vertex shaders
layout(set = 0, binding = 0) uniform ViewUniforms {
mat4 view;
mat4 proj;
vec3 pos;
}
view;

// Grid position are in xy clipped space
vec3 gridPlane[6] = vec3[](
vec3(1, 1, 0), vec3(-1, -1, 0), vec3(-1, 1, 0), vec3(-1, -1, 0), vec3(1, 1, 0),
vec3(1, -1, 0)
);
// normal vertice projection
void main() {
gl_Position = view.proj * view.view * vec4(gridPlane[gl_VertexIndex].xyz, 1.0);
}
2 changes: 1 addition & 1 deletion bin/deps.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ fi;
sudo apt-get install -y gcc-10 g++-10
sudo apt-get install -y libxrandr-dev libxinerama-dev libx11-dev libxcursor-dev libxi-dev libgl-dev \
uuid-dev libassimp-dev libglfw3-dev libjsoncpp-dev libglm-dev libgtest-dev libgmock-dev libfmt-dev libassimp-dev \
libfreetype-dev
libfreetype-dev cppcheck

wget -qO - http://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo apt-key add -
sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-focal.list http://packages.lunarg.com/vulkan/lunarg-vulkan-focal.list
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions bin/run-static-analysis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

SRC=$(dirname "$0")/../

cppcheck --enable=warning,style,performance $SRC/engine/*
2 changes: 1 addition & 1 deletion editor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
file(GLOB_RECURSE EDITOR_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
set(EDITOR_TARGET starlight-editor)
set(EDITOR_LIBS starlight-core starlight-renderer starlight-resource starlight-scene starlight-ui)
set(EDITOR_LIBS backward asan starlight-core starlight-renderer starlight-resource starlight-scene starlight-ui)

add_executable(${EDITOR_TARGET} ${EDITOR_SRC})
set_property(TARGET ${EDITOR_TARGET} PROPERTY CXX_STANDARD 20)
Expand Down
2 changes: 2 additions & 0 deletions editor/ui/ResourcesPanel.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "ResourcesPanel.h"

#include <thread>

#include "starlight/resource/All.h"

template <typename Resource, typename Manager>
Expand Down
4 changes: 4 additions & 0 deletions editor/ui/ResourcesPanel.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "Core.h"
#include "Console.h"

#include "kc/async/TaskScheduler.hpp"

class ResourcesPanel {
public:
explicit ResourcesPanel(UIState* state, Logger* logger);
Expand All @@ -15,6 +17,8 @@ class ResourcesPanel {
UIState* m_state;
Logger* m_logger;

kc::async::TaskScheduler ts;

sl::ui::TabMenu m_resourcesTab;
sl::ui::Popup m_loadPopup;
};
2 changes: 1 addition & 1 deletion engine/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_compile_definitions(NV_VK_DEBUG)
add_compile_definitions(STARLIGHT_VK_DEBUG)

add_subdirectory(src/starlight)

Expand Down
2 changes: 0 additions & 2 deletions engine/src/starlight/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
set(CMAKE_BUILD_TYPE Debug)

add_subdirectory(core)
add_subdirectory(renderer)
add_subdirectory(resource)
Expand Down
2 changes: 1 addition & 1 deletion engine/src/starlight/core/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
find_package(Vulkan REQUIRED)

set(SL_LIBS spdlog stb assimp dl kc fmt glfw expected ${Vulkan_LIBRARIES})
set(SL_LIBS spdlog stb assimp dl kc fmt glfw expected backward ${Vulkan_LIBRARIES})
set(SL_TARGET starlight-core)
file(GLOB_RECURSE SL_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)

Expand Down
37 changes: 37 additions & 0 deletions engine/src/starlight/core/Enum.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <concepts>

namespace sl {

template <typename T>
requires(std::is_enum_v<T>&& requires(T e) { enableBitOperations(e); }
) constexpr auto
operator|(const T lhs, const T rhs) {
using underlying = std::underlying_type_t<T>;

return static_cast<T>(
static_cast<underlying>(lhs) | static_cast<underlying>(rhs)
);
}

template <typename T>
requires(std::is_enum_v<T>&& requires(T e) { enableBitOperations(e); }
) constexpr auto
operator&(const T lhs, const T rhs) {
using underlying = std::underlying_type_t<T>;

return static_cast<T>(
static_cast<underlying>(lhs) & static_cast<underlying>(rhs)
);
}

template <typename T>
requires(std::is_enum_v<T>&& requires(T e) { enableBitOperations(e); }
) constexpr bool isFlagEnabled(const T lhs, const T rhs) {
using underlying = std::underlying_type_t<T>;

return static_cast<underlying>(lhs & rhs) > 0;
}

} // namespace sl
25 changes: 25 additions & 0 deletions engine/src/starlight/core/utils/RAIIWrapper.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#pragma once

#include <functional>

namespace sl {

template <typename T> class RAIIWrapper {
using Destructor = std::function<void(T&)>;

public:
template <typename Constructor>
explicit RAIIWrapper(Constructor&& constructor, Destructor&& destructor) :
m_resource(constructor()), m_destructor(std::move(destructor)) {}

~RAIIWrapper() { m_destructor(m_resource); }

T& get() const { return m_resource; }
T* getPointer() const { return &m_resource; }

private:
mutable T m_resource; // todo: no mutable!
Destructor m_destructor;
};

} // namespace sl
17 changes: 12 additions & 5 deletions engine/src/starlight/core/window/glfw/Vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,29 @@

namespace sl::glfw {

void createVulkanSurface(
VkInstance instance, void* windowHandle, VkAllocationCallbacks* allocator, VkSurfaceKHR* surface
VkSurfaceKHR createVulkanSurface(
VkInstance instance, void* windowHandle, VkAllocationCallbacks* allocator
) {
VkSurfaceKHR surface;

LOG_TRACE("Creating Vulkan surface");
ASSERT(windowHandle != nullptr, "windowHandle==nullptr");

VK_ASSERT(glfwCreateWindowSurface(
instance, static_cast<GLFWwindow*>(windowHandle), allocator, surface
instance, static_cast<GLFWwindow*>(windowHandle), allocator, &surface
));

return surface;
}

std::vector<const char*> getRequiredExtensions() {
uint32_t glfwExtensionCount = 0;
const auto glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
const auto glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount
);

return std::vector<const char*>{glfwExtensions, glfwExtensions + glfwExtensionCount};
return std::vector<const char*>{
glfwExtensions, glfwExtensions + glfwExtensionCount
};
}

} // namespace sl::glfw
Expand Down
4 changes: 2 additions & 2 deletions engine/src/starlight/core/window/glfw/Vulkan.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

namespace sl::glfw {

void createVulkanSurface(
VkInstance instance, void* windowHandle, VkAllocationCallbacks* allocator, VkSurfaceKHR* surface
VkSurfaceKHR createVulkanSurface(
VkInstance instance, void* windowHandle, VkAllocationCallbacks* allocator
);

std::vector<const char*> getRequiredExtensions();
Expand Down
2 changes: 1 addition & 1 deletion engine/src/starlight/renderer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
find_package(Vulkan REQUIRED)

set(SL_LIBS spdlog stb assimp dl kc fmt glfw imgui ${Vulkan_LIBRARIES} starlight-core)
set(SL_LIBS spdlog stb assimp dl kc fmt glfw imgui backward backward backward ${Vulkan_LIBRARIES} starlight-core)
set(SL_TARGET starlight-renderer)
file(GLOB_RECURSE SL_SRC ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)

Expand Down
8 changes: 2 additions & 6 deletions engine/src/starlight/renderer/RendererFrontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@ RendererFrontend::RendererFrontend(Window& window, const Config& config) :
m_viewportHeight = h;
}

RendererFrontend::~RendererFrontend() {}

void RendererFrontend::init(std::span<RenderView*> renderViews) {
m_renderViews.assign(renderViews.begin(), renderViews.end());

auto backendProxy = m_backend.getProxy();
auto resourcePools = m_backend.getResourcePools();

auto backendProxy = m_backend.getProxy();
auto resourcePools = m_backend.getResourcePools();
const auto viewCount = m_renderViews.size();

RenderView::InitProperties initProperties{
Expand All @@ -33,7 +30,6 @@ void RendererFrontend::init(std::span<RenderView*> renderViews) {
for (u32 i = 0; i < viewCount; ++i) {
initProperties.hasPreviousView = (i != 0);
initProperties.hasNextView = (i != viewCount - 1);

m_renderViews[i]->init(*backendProxy, *resourcePools, initProperties);
}
}
Expand Down
8 changes: 4 additions & 4 deletions engine/src/starlight/renderer/RendererFrontend.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <vector>
#include <functional>
#include <span>

Expand All @@ -18,7 +19,6 @@ namespace sl {
class RendererFrontend {
public:
explicit RendererFrontend(Window& window, const Config& config);
virtual ~RendererFrontend();

void init(std::span<RenderView*> renderViews);

Expand All @@ -33,16 +33,16 @@ class RendererFrontend {
void onViewportResize(u32 w, u32 h);

private:
FrameStatistics m_frameStatistics;
RendererBackendVendor m_backend;
vk::VKRendererBackend m_backend;

std::vector<RenderView*> m_renderViews;

RenderMode m_renderMode;

u16 m_framesSinceResize;
bool m_resizing;

FrameStatistics m_frameStatistics;

u32 m_viewportWidth;
u32 m_viewportHeight;
};
Expand Down
11 changes: 11 additions & 0 deletions engine/src/starlight/renderer/gpu/CommandBufferPool.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once

#include "CommandBuffer.h"

namespace sl {

struct CommandBufferPool {
virtual CommandBuffer* getFrameCommandBuffer() = 0;
};

} // namespace sl
5 changes: 4 additions & 1 deletion engine/src/starlight/renderer/gpu/ResourcePools.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
namespace sl {

struct ResourcePools {
virtual ~ResourcePools() = default;

virtual Mesh* createMesh(
const Mesh::Properties& props, std::span<const Vertex3> vertices,
std::span<const uint32_t> indices, const Extent3& extent
) = 0;
virtual Mesh* createMesh(
const Mesh::Properties& props, std::span<const Vertex2> vertices,
std::span<const uint32_t> indices, const Extent2& extent
) = 0;
) = 0;

virtual void destroyMesh(Mesh& mesh) = 0;

virtual Texture* createTexture(
Expand Down
15 changes: 15 additions & 0 deletions engine/src/starlight/renderer/gpu/vulkan/VKBackendAccessor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#pragma once

#include "VKContext.h"
#include "VKLogicalDevice.h"
#include "VKPhysicalDevice.h"

namespace sl::vk {

struct VKBackendAccessor {
virtual VKContext* getContext() = 0;
virtual VKPhysicalDevice* getPhysicalDevice() = 0;
virtual VKLogicalDevice* getLogicalDevice() = 0;
};

} // namespace sl::vk
Loading
Loading