From fcdb09a1426750c63fa7d7afe52a860ef3918d56 Mon Sep 17 00:00:00 2001 From: homeburger Date: Sat, 9 May 2026 20:22:51 -0500 Subject: [PATCH] hello vulkan --- CMakeLists.txt | 6 ++++++ README.md | 25 ++++++++++++++++++++++++- src/App.cpp | 2 +- src/App.hpp | 2 ++ src/Engine.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/Engine.hpp | 24 ++++++++++++++++++++++++ src/main.cpp | 4 ---- 7 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 src/Engine.cpp create mode 100644 src/Engine.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 6f2a14c..e692c27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,9 +25,12 @@ FetchContent_Declare( ) FetchContent_MakeAvailable(sdl3) +find_package(Vulkan REQUIRED) + # add_subdirectory() to nest CMakeLists add_executable(maiden + src/Engine.cpp src/App.cpp src/Window.cpp src/main.cpp @@ -37,6 +40,7 @@ add_executable(maiden add_executable(maiden_test src/App.cpp src/Window.cpp + src/Engine.cpp test/TestApp.cpp ) # i think the strat is to build all of the core app components into a single library @@ -49,6 +53,7 @@ target_include_directories(maiden PRIVATE target_link_libraries(maiden PRIVATE SDL3::SDL3 + Vulkan::Vulkan ) target_include_directories(maiden_test PRIVATE @@ -64,6 +69,7 @@ target_link_libraries(maiden_test PRIVATE GTest::gmock GTest::gmock_main SDL3::SDL3 + Vulkan::Vulkan ) include(CTest) diff --git a/README.md b/README.md index 27d798c..943b9c0 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,30 @@ $ git clone --recurse-submodules https://git.vxbard.net/homeburger/maiden.git # If you have already cloned the repository and you need its submodules: $ git submodule update --init --recursive ``` -### Build + +### Installation Prequisites +LunarG's Vulkan SDK is used for almost every Vulkan project, including this one. +Installation instructions here are for Ubuntu 24, further instructions can be found here: https://vulkan.lunarg.com/doc/sdk/1.4.341.1/linux/getting_started.html +```bash +$ cd ~/Downloads +$ wget "https://sdk.lunarg.com/sdk/download/1.4.341.1/linux/vulkansdk-linux-x86_64-1.4.341.1.tar.xz" # or the latest version on https://vulkan.lunarg.com/sdk/home +$ mkdir /opt/vulkan-sdk +$ cd /opt/vulkan-sdk +$ tar -xvf ~/Downloads/vulkansdk-linux-x86_64-1.4.341.1.tar.xz +$ sudo apt install libxcb-xinput0 libxcb-xinerama0 libxcb-cursor-dev # vulkan prerequeisites +``` +Then to setup your current session: +```bash +$ source /opt/vulkan-sdk/1.4.341.1/setup-env.sh # or whichever version you have +``` +Note: sourcing only affects your current shell session. Add to your .bashrc script if you wish for it to persist. + +Verify your installation by using the the command: +```bash +$ vulkaninfo +``` + +### Build This app uses CMake and C++20, so a compatible compiler (gcc8, clang9, msvc16) are necessary. Most library prerequisites are handled within CMake. Any others that need to be manually installed will be described below as the project grows. diff --git a/src/App.cpp b/src/App.cpp index d6845cc..1302106 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -5,7 +5,7 @@ #include #include -App::App(): window_(new Window()) { +App::App(): window_(new Window()), engine_(new Engine(window_)) { // smart pointers might be a good idea // since app will be the top level owner we can use unique ptrs for almost everything } diff --git a/src/App.hpp b/src/App.hpp index c94bb56..3c3ab18 100644 --- a/src/App.hpp +++ b/src/App.hpp @@ -5,6 +5,7 @@ #include #include "Window.hpp" +#include "Engine.hpp" class App { @@ -17,6 +18,7 @@ public: private: Window* window_; + Engine* engine_; bool rendering_ = true; diff --git a/src/Engine.cpp b/src/Engine.cpp new file mode 100644 index 0000000..003fe2e --- /dev/null +++ b/src/Engine.cpp @@ -0,0 +1,51 @@ + +#include "Engine.hpp" + +#include "vulkan/vulkan.h" +#include + +Engine::Engine(Window* window): window_(window) { + + // cleans up this constructor + init(); + +} + +void Engine::init() { + + VkApplicationInfo appInfo { + .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, + .pApplicationName = "maiden", + .apiVersion = VK_API_VERSION_1_4 + }; + + uint32_t instanceExtensionsCount = 0; + char const* const* instanceExtensions{ SDL_Vulkan_GetInstanceExtensions(&instanceExtensionsCount) }; + + VkInstanceCreateInfo instanceCI { + .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, + .pApplicationInfo = &appInfo, + .enabledExtensionCount = instanceExtensionsCount, + .ppEnabledExtensionNames = instanceExtensions, + }; + + VkInstance instance; + if(vkCreateInstance(&instanceCI, nullptr, &instance) == VK_SUCCESS) { + // TODO: need some kind of logger service + std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] Vulkan instance successfully created." << std::endl; + } else { + std::cout << "[" << __FUNCTION__ << ": " << __LINE__ << "] Error creating Vulkan instance." << std::endl; + } + + // next steps: + // device selection and setup + // queue creation + // vulkan memory allocator + // create vulkan surface + // attach surface to window + +} + +void Engine::draw() { + +} diff --git a/src/Engine.hpp b/src/Engine.hpp new file mode 100644 index 0000000..cb017e1 --- /dev/null +++ b/src/Engine.hpp @@ -0,0 +1,24 @@ + +#pragma once + +#include "Window.hpp" + +class Engine { + +public: + + Engine(Window* window); + ~Engine() = default; + + void init(); + + // draw is called every render iteration in that while loop + void draw(); + +private: + + // might get rid of this + + Window* window_; + +}; diff --git a/src/main.cpp b/src/main.cpp index ff0f4f3..e5aba48 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,12 +1,8 @@ -#include - #include "App.hpp" int main(int argc, char** argv) { - std::cout << "hi mom !" << std::endl; - // create app and run App app; app.run();