diff --git a/.gitignore b/.gitignore index 059af08..093612e 100644 --- a/.gitignore +++ b/.gitignore @@ -9,10 +9,12 @@ *.user *.userosscache *.sln.docstates +.vscode/ # User-specific files (MonoDevelop/Xamarin Studio) *.userprefs + # Mono auto generated files mono_crash.* @@ -34,6 +36,9 @@ bld/ [Ll]ogs/ [Ll]ib/ +# Cmake directory +[Bb]uild/ + # Visual Studio 2015/2017 cache/options directory .vs/ # Uncomment if you have tasks that create the project's static files in wwwroot @@ -361,4 +366,4 @@ MigrationBackup/ .ionide/ # Fody - auto-generated XML schema -FodyWeavers.xsd \ No newline at end of file +FodyWeavers.xsd diff --git a/CMakeLists.txt b/CMakeLists.txt index 0a8108d..1f08b18 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,9 +3,14 @@ set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_FLAGS "-DDEBUG") +set(CMAKE_CXX_FLAGS "-fsanitize=address -g -DDEBUG -D_DEBUG") + project(Pleascach) -list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") +if(WIN32) + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") +endif() file(GLOB SOURCES pléascach.cpp @@ -21,6 +26,7 @@ if(UNIX) set(GLFW3_LIBRARY glfw) endif() + include_directories(${CMAKE_CURRENT_LIST_DIR} include ${GLFW3_INCLUDE_DIR}) target_link_libraries(Pleascach ${GLFW3_LIBRARY} Vulkan::Vulkan) diff --git a/input/input.cpp b/Input/Input.cpp similarity index 98% rename from input/input.cpp rename to Input/Input.cpp index 83f9a8d..086efec 100644 --- a/input/input.cpp +++ b/Input/Input.cpp @@ -1,7 +1,7 @@ #include #define INPUT_PTR GLFWwindow* -#include +#include #include @@ -62,4 +62,4 @@ Input::Input(INPUT_PTR in) : in(in) { } }); }); -} \ No newline at end of file +} diff --git a/input/input.hpp b/Input/Input.hpp similarity index 99% rename from input/input.hpp rename to Input/Input.hpp index f05ba91..35a84fd 100644 --- a/input/input.hpp +++ b/Input/Input.hpp @@ -32,6 +32,7 @@ constexpr u32 operator ~ (InputModifierBit a) { struct InputEvent { enum Tag { + EXIT, RESIZE, CURSOR, KEY, diff --git a/memory/memory.cpp b/Memory/Memory.cpp similarity index 95% rename from memory/memory.cpp rename to Memory/Memory.cpp index e85acfb..87b3a9b 100644 --- a/memory/memory.cpp +++ b/Memory/Memory.cpp @@ -1,4 +1,4 @@ -#include +#include namespace mem { u32 choose_heap(vk::PhysicalDevice& phys_dev, const vk::MemoryRequirements& requirements, vk::MemoryPropertyFlags req_flags, vk::MemoryPropertyFlags pref_flags) { @@ -22,5 +22,7 @@ namespace mem { } } } + + return -1; } } \ No newline at end of file diff --git a/memory/memory.hpp b/Memory/Memory.hpp similarity index 100% rename from memory/memory.hpp rename to Memory/Memory.hpp diff --git a/README.md b/README.md index b8515f8..a41a395 100644 --- a/README.md +++ b/README.md @@ -2,4 +2,5 @@ ## Long Term Improvements +- Properly query surface to find supported - Add pipeline caching diff --git a/renderer/command_buffer.cpp b/Renderer/CommandBuffer.cpp similarity index 73% rename from renderer/command_buffer.cpp rename to Renderer/CommandBuffer.cpp index d337b4e..a359e95 100644 --- a/renderer/command_buffer.cpp +++ b/Renderer/CommandBuffer.cpp @@ -1,4 +1,6 @@ -#include +#include +#include + CommandBuffer::CommandBuffer(vk::Device dev, u32 queue_family) { /* (For now) allow command buffers to be individually recycled */ @@ -17,7 +19,8 @@ CommandBuffer::CommandBuffer(vk::Device dev, u32 queue_family) { .commandBufferCount = 1, }; - dev.allocateCommandBuffers(alloc_info); + + command_buffer = dev.allocateCommandBuffers(alloc_info)[0]; } void CommandBuffer::begin() { @@ -33,6 +36,14 @@ void CommandBuffer::copy(vk::Buffer in, vk::Buffer out, vk::ArrayProxy +struct GraphicsPipeline; +struct ComputePipeline; + struct CommandBuffer { CommandBuffer(vk::Device dev, u32 queue_family); @@ -16,6 +19,9 @@ struct CommandBuffer { /* copy between buffer */ void copy(vk::Buffer in, vk::Buffer out, vk::ArrayProxy regions); + void bind(const GraphicsPipeline& pipeline); + void bind(const ComputePipeline& pipeline); + /* stop recording commands */ void end(); @@ -23,4 +29,4 @@ struct CommandBuffer { vk::CommandBuffer command_buffer; vk::CommandPool command_pool; -}; \ No newline at end of file +}; diff --git a/Renderer/Pipeline.cpp b/Renderer/Pipeline.cpp new file mode 100644 index 0000000..7f3bcd6 --- /dev/null +++ b/Renderer/Pipeline.cpp @@ -0,0 +1,19 @@ +#include + +#include + +ComputePipeline::ComputePipeline(vk::Device dev, const Shader& shader) { + auto shader_info = vk::PipelineShaderStageCreateInfo { + .stage = vk::ShaderStageFlagBits::eCompute, + .module = shader, + .pName = "main", + }; + + auto layout = vk::PipelineLayoutCreateInfo { + + }; + + auto create_info = vk::ComputePipelineCreateInfo { + .stage = shader_info, + }; +} \ No newline at end of file diff --git a/Renderer/Pipeline.hpp b/Renderer/Pipeline.hpp new file mode 100644 index 0000000..a5bd78c --- /dev/null +++ b/Renderer/Pipeline.hpp @@ -0,0 +1,27 @@ +#pragma once + +#define VULKAN_HPP_NO_STRUCT_CONSTRUCTORS +#include + +struct Shader; + +struct ComputePipeline { + ComputePipeline(vk::Device dev, const Shader& shader); + + vk::Pipeline pipeline; + inline operator vk::Pipeline&() { + return pipeline; + } +}; + + +struct GraphicsPipeline { + GraphicsPipeline(vk::Device dev); + vk::Pipeline pipeline; + + inline operator vk::Pipeline&() { + return pipeline; + } +}; + + diff --git a/Renderer/Renderer.cpp b/Renderer/Renderer.cpp index becfa42..e87fd15 100644 --- a/Renderer/Renderer.cpp +++ b/Renderer/Renderer.cpp @@ -1,5 +1,5 @@ -#include -#include +#include +#include #include @@ -8,11 +8,11 @@ using namespace std::string_literals; Renderer::Renderer(Window& win) : win(win) { /* Create Instance object */ auto app_info = vk::ApplicationInfo { - .pApplicationName = "Pléascach Demo", + .pApplicationName = "Pl�ascach Demo", .applicationVersion = VK_MAKE_API_VERSION(0, 0, 1, 0), - .pEngineName = "Pléascach", + .pEngineName = "Pl�ascach", .engineVersion = VK_MAKE_API_VERSION(0, 0, 1, 0), - .apiVersion = VK_API_VERSION_1_0, + .apiVersion = VK_API_VERSION_1_1, }; const auto req_extensions = win.requiredExtensions(); @@ -29,7 +29,7 @@ Renderer::Renderer(Window& win) : win(win) { } /* query and enable available layers if in DEBUG mode */ -#ifdef _DEBUG +#ifdef DEBUG auto layers = vk::enumerateInstanceLayerProperties(); Log::info("%zu available instance layers\n", layers.size()); @@ -46,8 +46,8 @@ Renderer::Renderer(Window& win) : win(win) { .pApplicationInfo = &app_info, .enabledLayerCount = std::size(my_layers), .ppEnabledLayerNames = my_layers, - .enabledExtensionCount = static_cast(extensions.size()), - .ppEnabledExtensionNames = extension_names.data(), + .enabledExtensionCount = static_cast(req_extensions.size()), + .ppEnabledExtensionNames = req_extensions.data(), }; #else @@ -55,8 +55,8 @@ Renderer::Renderer(Window& win) : win(win) { .pApplicationInfo = &app_info, .enabledLayerCount = 0, .ppEnabledLayerNames = nullptr, - .enabledExtensionCount = static_cast(extensions.size()), - .ppEnabledExtensionNames = extensions.data(), + .enabledExtensionCount = static_cast(req_extensions.size()), + .ppEnabledExtensionNames = req_extensions.data(), }; #endif @@ -108,11 +108,11 @@ Renderer::Renderer(Window& win) : win(win) { /* enumerate available device features */ std::vector required_extensions; + required_extensions.push_back("VK_KHR_swapchain"); auto dev_extentions = phys_dev.enumerateDeviceExtensionProperties(); Log::info("%zu available device extensions\n", dev_extentions.size()); for (const auto& ext : dev_extentions) { Log::info("\t\"%s\"\n", ext.extensionName.data()); - required_extensions.push_back(ext.extensionName); } auto dev_layers = phys_dev.enumerateDeviceLayerProperties(); @@ -161,6 +161,8 @@ void Renderer::draw() { command_buffer->recycle(); command_buffer->begin(); + + command_buffer->end(); } @@ -185,7 +187,6 @@ void Renderer::present() { } Renderer::~Renderer() { - command_buffer->cleanup(dev); swapchain.reset(); dev.waitIdle(); dev.destroy(); diff --git a/Renderer/Renderer.hpp b/Renderer/Renderer.hpp index 7fd6af6..6e30e9b 100644 --- a/Renderer/Renderer.hpp +++ b/Renderer/Renderer.hpp @@ -5,8 +5,8 @@ #define VULKAN_HPP_NO_STRUCT_CONSTRUCTORS #include -#include -#include +#include +#include struct Window; @@ -27,4 +27,4 @@ struct Renderer { vk::Queue queue; std::unique_ptr command_buffer; uint32_t current_image_idx; -}; \ No newline at end of file +}; diff --git a/Renderer/Shader.cpp b/Renderer/Shader.cpp index 98ecc4a..ffe3072 100644 --- a/Renderer/Shader.cpp +++ b/Renderer/Shader.cpp @@ -1,4 +1,4 @@ -#include +#include #include diff --git a/Renderer/Shader.hpp b/Renderer/Shader.hpp index 2500cd6..f4bcc0c 100644 --- a/Renderer/Shader.hpp +++ b/Renderer/Shader.hpp @@ -9,7 +9,9 @@ struct Shader { Shader(vk::Device dev, const std::string& fname); void cleanup(vk::Device dev); - + inline operator vk::ShaderModule() const { + return module; + } inline operator vk::ShaderModule& () { return module; @@ -17,4 +19,4 @@ struct Shader { std::string fname; -}; \ No newline at end of file +}; diff --git a/Renderer/Swapchain.cpp b/Renderer/Swapchain.cpp index 433e639..264c996 100644 --- a/Renderer/Swapchain.cpp +++ b/Renderer/Swapchain.cpp @@ -1,4 +1,4 @@ -#include +#include Swapchain::Swapchain(vk::Device& dev, const vk::SurfaceKHR& surface, const vk::Extent2D& extent) : dev(dev), surface(surface) { create(extent); @@ -10,7 +10,7 @@ void Swapchain::create(const vk::Extent2D& extent, vk::SwapchainKHR old_swapchai .surface = surface, /* at least double-buffered */ .minImageCount = 3, - .imageFormat = vk::Format::eR8G8B8A8Unorm, + .imageFormat = vk::Format::eB8G8R8A8Unorm, .imageColorSpace = vk::ColorSpaceKHR::eSrgbNonlinear, .imageExtent = extent, .imageArrayLayers = 1, @@ -45,4 +45,4 @@ void Swapchain::cleanup() { Swapchain::~Swapchain() { cleanup(); -} \ No newline at end of file +} diff --git a/Window/Window.cpp b/Window/Window.cpp index 05c7b55..c3ba769 100644 --- a/Window/Window.cpp +++ b/Window/Window.cpp @@ -4,8 +4,8 @@ #define WINDOW_PTR GLFWwindow* #define INPUT_PTR GLFWwindow* -#include -#include +#include +#include #include @@ -84,4 +84,4 @@ Window::~Window() { glfwTerminate(); Log::info("Terminated GLFW\n"); -} \ No newline at end of file +} diff --git a/Window/Window.hpp b/Window/Window.hpp index d57ef28..ba2aba1 100644 --- a/Window/Window.hpp +++ b/Window/Window.hpp @@ -5,7 +5,9 @@ #include #include -#include +#include + +#include #ifndef WINDOW_PTR #define WINDOW_PTR void* diff --git a/pléascach.cpp b/pléascach.cpp index 8aef9a7..f46c938 100644 --- a/pléascach.cpp +++ b/pléascach.cpp @@ -1,6 +1,6 @@ -#include -#include -#include +#include +#include +#include #include @@ -30,6 +30,8 @@ int main() { break; case InputEvent::Tag::KEY: Log::info("Event Processed: Button 0x%x %d\n", event.key.key, event.key.state); + break; + case InputEvent::Tag::EXIT: win.close(); break; } @@ -38,5 +40,5 @@ int main() { } catch (const std::string& e) { std::cerr << "Exception: " << e << std::endl; - } + } } diff --git a/renderer/compute_pipeline.hpp b/renderer/compute_pipeline.hpp deleted file mode 100644 index 9413f8c..0000000 --- a/renderer/compute_pipeline.hpp +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once - -#define VULKAN_HPP_NO_STRUCT_CONSTRUCTORS -#include - -struct ComputePipeline { - ComputePipeline(vk::Device dev) { - } - - vk::Pipeline pipeline; - inline operator vk::Pipeline&() { - return pipeline; - } -}; -