Made modifications to allow executation in linux (at least on my thinkpad). I hate that capitalization doesn't matter on windows files, it fucked up my directories

This commit is contained in:
Conál 2024-01-19 00:22:23 -05:00
parent cc49f1b704
commit 36f515f53b
20 changed files with 122 additions and 53 deletions

7
.gitignore vendored
View File

@ -9,10 +9,12 @@
*.user *.user
*.userosscache *.userosscache
*.sln.docstates *.sln.docstates
.vscode/
# User-specific files (MonoDevelop/Xamarin Studio) # User-specific files (MonoDevelop/Xamarin Studio)
*.userprefs *.userprefs
# Mono auto generated files # Mono auto generated files
mono_crash.* mono_crash.*
@ -34,6 +36,9 @@ bld/
[Ll]ogs/ [Ll]ogs/
[Ll]ib/ [Ll]ib/
# Cmake directory
[Bb]uild/
# Visual Studio 2015/2017 cache/options directory # Visual Studio 2015/2017 cache/options directory
.vs/ .vs/
# Uncomment if you have tasks that create the project's static files in wwwroot # Uncomment if you have tasks that create the project's static files in wwwroot
@ -361,4 +366,4 @@ MigrationBackup/
.ionide/ .ionide/
# Fody - auto-generated XML schema # Fody - auto-generated XML schema
FodyWeavers.xsd FodyWeavers.xsd

View File

@ -3,9 +3,14 @@
set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "-DDEBUG")
set(CMAKE_CXX_FLAGS "-fsanitize=address -g -DDEBUG -D_DEBUG")
project(Pleascach) 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 file(GLOB SOURCES
pléascach.cpp pléascach.cpp
@ -21,6 +26,7 @@ if(UNIX)
set(GLFW3_LIBRARY glfw) set(GLFW3_LIBRARY glfw)
endif() endif()
include_directories(${CMAKE_CURRENT_LIST_DIR} include ${GLFW3_INCLUDE_DIR}) include_directories(${CMAKE_CURRENT_LIST_DIR} include ${GLFW3_INCLUDE_DIR})
target_link_libraries(Pleascach ${GLFW3_LIBRARY} Vulkan::Vulkan) target_link_libraries(Pleascach ${GLFW3_LIBRARY} Vulkan::Vulkan)

View File

@ -1,7 +1,7 @@
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#define INPUT_PTR GLFWwindow* #define INPUT_PTR GLFWwindow*
#include <input/input.hpp> #include <Input/Input.hpp>
#include <util/log.hpp> #include <util/log.hpp>
@ -62,4 +62,4 @@ Input::Input(INPUT_PTR in) : in(in) {
} }
}); });
}); });
} }

View File

@ -32,6 +32,7 @@ constexpr u32 operator ~ (InputModifierBit a) {
struct InputEvent { struct InputEvent {
enum Tag { enum Tag {
EXIT,
RESIZE, RESIZE,
CURSOR, CURSOR,
KEY, KEY,

View File

@ -1,4 +1,4 @@
#include <memory/memory.hpp> #include <Memory/Memory.hpp>
namespace mem { namespace mem {
u32 choose_heap(vk::PhysicalDevice& phys_dev, const vk::MemoryRequirements& requirements, vk::MemoryPropertyFlags req_flags, vk::MemoryPropertyFlags pref_flags) { 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;
} }
} }

View File

@ -2,4 +2,5 @@
## Long Term Improvements ## Long Term Improvements
- Properly query surface to find supported
- Add pipeline caching - Add pipeline caching

View File

@ -1,4 +1,6 @@
#include <renderer/command_buffer.hpp> #include <Renderer/CommandBuffer.hpp>
#include <Renderer/Pipeline.hpp>
CommandBuffer::CommandBuffer(vk::Device dev, u32 queue_family) { CommandBuffer::CommandBuffer(vk::Device dev, u32 queue_family) {
/* (For now) allow command buffers to be individually recycled */ /* (For now) allow command buffers to be individually recycled */
@ -17,7 +19,8 @@ CommandBuffer::CommandBuffer(vk::Device dev, u32 queue_family) {
.commandBufferCount = 1, .commandBufferCount = 1,
}; };
dev.allocateCommandBuffers(alloc_info);
command_buffer = dev.allocateCommandBuffers(alloc_info)[0];
} }
void CommandBuffer::begin() { void CommandBuffer::begin() {
@ -33,6 +36,14 @@ void CommandBuffer::copy(vk::Buffer in, vk::Buffer out, vk::ArrayProxy<const vk:
command_buffer.copyBuffer(in, out, regions); command_buffer.copyBuffer(in, out, regions);
} }
void CommandBuffer::bind(const GraphicsPipeline& pipeline) {
command_buffer.bindPipeline(vk::PipelineBindPoint::eGraphics, pipeline.pipeline);
}
void CommandBuffer::bind(const ComputePipeline& pipeline) {
command_buffer.bindPipeline(vk::PipelineBindPoint::eCompute, pipeline.pipeline);
}
void CommandBuffer::end() { void CommandBuffer::end() {
command_buffer.end(); command_buffer.end();
} }
@ -42,6 +53,5 @@ void CommandBuffer::recycle() {
} }
void CommandBuffer::cleanup(vk::Device dev) { void CommandBuffer::cleanup(vk::Device dev) {
dev.freeCommandBuffers(command_pool, command_buffer);
dev.destroyCommandPool(command_pool); dev.destroyCommandPool(command_pool);
} }

View File

@ -5,6 +5,9 @@
#include <util/int.hpp> #include <util/int.hpp>
struct GraphicsPipeline;
struct ComputePipeline;
struct CommandBuffer { struct CommandBuffer {
CommandBuffer(vk::Device dev, u32 queue_family); CommandBuffer(vk::Device dev, u32 queue_family);
@ -16,6 +19,9 @@ struct CommandBuffer {
/* copy between buffer */ /* copy between buffer */
void copy(vk::Buffer in, vk::Buffer out, vk::ArrayProxy<const vk::BufferCopy> regions); void copy(vk::Buffer in, vk::Buffer out, vk::ArrayProxy<const vk::BufferCopy> regions);
void bind(const GraphicsPipeline& pipeline);
void bind(const ComputePipeline& pipeline);
/* stop recording commands */ /* stop recording commands */
void end(); void end();
@ -23,4 +29,4 @@ struct CommandBuffer {
vk::CommandBuffer command_buffer; vk::CommandBuffer command_buffer;
vk::CommandPool command_pool; vk::CommandPool command_pool;
}; };

19
Renderer/Pipeline.cpp Normal file
View File

@ -0,0 +1,19 @@
#include <Renderer/Pipeline.hpp>
#include <Renderer/Shader.hpp>
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,
};
}

27
Renderer/Pipeline.hpp Normal file
View File

@ -0,0 +1,27 @@
#pragma once
#define VULKAN_HPP_NO_STRUCT_CONSTRUCTORS
#include <vulkan/vulkan.hpp>
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;
}
};

View File

@ -1,5 +1,5 @@
#include <renderer/renderer.hpp> #include <Renderer/Renderer.hpp>
#include <window/window.hpp> #include <Window/Window.hpp>
#include <util/log.hpp> #include <util/log.hpp>
@ -8,11 +8,11 @@ using namespace std::string_literals;
Renderer::Renderer(Window& win) : win(win) { Renderer::Renderer(Window& win) : win(win) {
/* Create Instance object */ /* Create Instance object */
auto app_info = vk::ApplicationInfo { auto app_info = vk::ApplicationInfo {
.pApplicationName = "Pléascach Demo", .pApplicationName = "Pl<EFBFBD>ascach Demo",
.applicationVersion = VK_MAKE_API_VERSION(0, 0, 1, 0), .applicationVersion = VK_MAKE_API_VERSION(0, 0, 1, 0),
.pEngineName = "Pléascach", .pEngineName = "Pl<EFBFBD>ascach",
.engineVersion = VK_MAKE_API_VERSION(0, 0, 1, 0), .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(); 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 */ /* query and enable available layers if in DEBUG mode */
#ifdef _DEBUG #ifdef DEBUG
auto layers = vk::enumerateInstanceLayerProperties(); auto layers = vk::enumerateInstanceLayerProperties();
Log::info("%zu available instance layers\n", layers.size()); Log::info("%zu available instance layers\n", layers.size());
@ -46,8 +46,8 @@ Renderer::Renderer(Window& win) : win(win) {
.pApplicationInfo = &app_info, .pApplicationInfo = &app_info,
.enabledLayerCount = std::size(my_layers), .enabledLayerCount = std::size(my_layers),
.ppEnabledLayerNames = my_layers, .ppEnabledLayerNames = my_layers,
.enabledExtensionCount = static_cast<u32>(extensions.size()), .enabledExtensionCount = static_cast<u32>(req_extensions.size()),
.ppEnabledExtensionNames = extension_names.data(), .ppEnabledExtensionNames = req_extensions.data(),
}; };
#else #else
@ -55,8 +55,8 @@ Renderer::Renderer(Window& win) : win(win) {
.pApplicationInfo = &app_info, .pApplicationInfo = &app_info,
.enabledLayerCount = 0, .enabledLayerCount = 0,
.ppEnabledLayerNames = nullptr, .ppEnabledLayerNames = nullptr,
.enabledExtensionCount = static_cast<u32>(extensions.size()), .enabledExtensionCount = static_cast<u32>(req_extensions.size()),
.ppEnabledExtensionNames = extensions.data(), .ppEnabledExtensionNames = req_extensions.data(),
}; };
#endif #endif
@ -108,11 +108,11 @@ Renderer::Renderer(Window& win) : win(win) {
/* enumerate available device features */ /* enumerate available device features */
std::vector<const char*> required_extensions; std::vector<const char*> required_extensions;
required_extensions.push_back("VK_KHR_swapchain");
auto dev_extentions = phys_dev.enumerateDeviceExtensionProperties(); auto dev_extentions = phys_dev.enumerateDeviceExtensionProperties();
Log::info("%zu available device extensions\n", dev_extentions.size()); Log::info("%zu available device extensions\n", dev_extentions.size());
for (const auto& ext : dev_extentions) { for (const auto& ext : dev_extentions) {
Log::info("\t\"%s\"\n", ext.extensionName.data()); Log::info("\t\"%s\"\n", ext.extensionName.data());
required_extensions.push_back(ext.extensionName);
} }
auto dev_layers = phys_dev.enumerateDeviceLayerProperties(); auto dev_layers = phys_dev.enumerateDeviceLayerProperties();
@ -161,6 +161,8 @@ void Renderer::draw() {
command_buffer->recycle(); command_buffer->recycle();
command_buffer->begin(); command_buffer->begin();
command_buffer->end(); command_buffer->end();
} }
@ -185,7 +187,6 @@ void Renderer::present() {
} }
Renderer::~Renderer() { Renderer::~Renderer() {
command_buffer->cleanup(dev);
swapchain.reset(); swapchain.reset();
dev.waitIdle(); dev.waitIdle();
dev.destroy(); dev.destroy();

View File

@ -5,8 +5,8 @@
#define VULKAN_HPP_NO_STRUCT_CONSTRUCTORS #define VULKAN_HPP_NO_STRUCT_CONSTRUCTORS
#include <vulkan/vulkan.hpp> #include <vulkan/vulkan.hpp>
#include <renderer/swapchain.hpp> #include <Renderer/Swapchain.hpp>
#include <renderer/command_buffer.hpp> #include <Renderer/CommandBuffer.hpp>
struct Window; struct Window;
@ -27,4 +27,4 @@ struct Renderer {
vk::Queue queue; vk::Queue queue;
std::unique_ptr<CommandBuffer> command_buffer; std::unique_ptr<CommandBuffer> command_buffer;
uint32_t current_image_idx; uint32_t current_image_idx;
}; };

View File

@ -1,4 +1,4 @@
#include <renderer/shader.hpp> #include <Renderer/Shader.hpp>
#include <util/log.hpp> #include <util/log.hpp>

View File

@ -9,7 +9,9 @@ struct Shader {
Shader(vk::Device dev, const std::string& fname); Shader(vk::Device dev, const std::string& fname);
void cleanup(vk::Device dev); void cleanup(vk::Device dev);
inline operator vk::ShaderModule() const {
return module;
}
inline operator vk::ShaderModule& () { inline operator vk::ShaderModule& () {
return module; return module;
@ -17,4 +19,4 @@ struct Shader {
std::string fname; std::string fname;
}; };

View File

@ -1,4 +1,4 @@
#include <renderer/swapchain.hpp> #include <Renderer/Swapchain.hpp>
Swapchain::Swapchain(vk::Device& dev, const vk::SurfaceKHR& surface, const vk::Extent2D& extent) : dev(dev), surface(surface) { Swapchain::Swapchain(vk::Device& dev, const vk::SurfaceKHR& surface, const vk::Extent2D& extent) : dev(dev), surface(surface) {
create(extent); create(extent);
@ -10,7 +10,7 @@ void Swapchain::create(const vk::Extent2D& extent, vk::SwapchainKHR old_swapchai
.surface = surface, .surface = surface,
/* at least double-buffered */ /* at least double-buffered */
.minImageCount = 3, .minImageCount = 3,
.imageFormat = vk::Format::eR8G8B8A8Unorm, .imageFormat = vk::Format::eB8G8R8A8Unorm,
.imageColorSpace = vk::ColorSpaceKHR::eSrgbNonlinear, .imageColorSpace = vk::ColorSpaceKHR::eSrgbNonlinear,
.imageExtent = extent, .imageExtent = extent,
.imageArrayLayers = 1, .imageArrayLayers = 1,
@ -45,4 +45,4 @@ void Swapchain::cleanup() {
Swapchain::~Swapchain() { Swapchain::~Swapchain() {
cleanup(); cleanup();
} }

View File

@ -4,8 +4,8 @@
#define WINDOW_PTR GLFWwindow* #define WINDOW_PTR GLFWwindow*
#define INPUT_PTR GLFWwindow* #define INPUT_PTR GLFWwindow*
#include <window/window.hpp> #include <Window/Window.hpp>
#include <input/input.hpp> #include <Input/Input.hpp>
#include <util/log.hpp> #include <util/log.hpp>
@ -84,4 +84,4 @@ Window::~Window() {
glfwTerminate(); glfwTerminate();
Log::info("Terminated GLFW\n"); Log::info("Terminated GLFW\n");
} }

View File

@ -5,7 +5,9 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <input/input.hpp> #include <memory>
#include <Input/Input.hpp>
#ifndef WINDOW_PTR #ifndef WINDOW_PTR
#define WINDOW_PTR void* #define WINDOW_PTR void*

View File

@ -1,6 +1,6 @@
#include <window/window.hpp> #include <Window/Window.hpp>
#include <input/input.hpp> #include <Input/Input.hpp>
#include <renderer/renderer.hpp> #include <Renderer/Renderer.hpp>
#include <util/log.hpp> #include <util/log.hpp>
@ -30,6 +30,8 @@ int main() {
break; break;
case InputEvent::Tag::KEY: case InputEvent::Tag::KEY:
Log::info("Event Processed: Button 0x%x %d\n", event.key.key, event.key.state); Log::info("Event Processed: Button 0x%x %d\n", event.key.key, event.key.state);
break;
case InputEvent::Tag::EXIT:
win.close(); win.close();
break; break;
} }
@ -38,5 +40,5 @@ int main() {
} catch (const std::string& e) { } catch (const std::string& e) {
std::cerr << "Exception: " << e << std::endl; std::cerr << "Exception: " << e << std::endl;
} }
} }

View File

@ -1,15 +0,0 @@
#pragma once
#define VULKAN_HPP_NO_STRUCT_CONSTRUCTORS
#include <vulkan/vulkan.hpp>
struct ComputePipeline {
ComputePipeline(vk::Device dev) {
}
vk::Pipeline pipeline;
inline operator vk::Pipeline&() {
return pipeline;
}
};