diff --git a/include/gfx.hpp b/include/gfx.hpp index cee3b3e..b5f2f83 100644 --- a/include/gfx.hpp +++ b/include/gfx.hpp @@ -10,23 +10,11 @@ namespace engine { FRAGMENT, }; - struct Shader { - ShaderType type; - uint32_t handle; - }; - - typedef uint32_t Program; - enum class BufferType { VERTEX, INDEX, }; - struct Buffer { - BufferType type; - uint32_t handle; - }; - enum class Primitive { POINTS, LINES, diff --git a/include/gfx_device.hpp b/include/gfx_device.hpp index 9f1c021..f43c550 100644 --- a/include/gfx_device.hpp +++ b/include/gfx_device.hpp @@ -49,7 +49,8 @@ namespace engine { void createPipeline(const char* vertShaderPath, const char* fragShaderPath); // creates a vertex array for holding mesh data - bool createBuffer(const gfx::BufferDesc& desc, const void* data, gfx::BufferHandle* out); + gfx::BufferHandle* createVertexBuffer(const gfx::BufferDesc& desc, const void* vertices, const void* indices); + void destroyBuffer(const gfx::BufferHandle* buffer); // wait until all the active GPU queues have finished working void waitIdle(); diff --git a/src/engine.cpp b/src/engine.cpp index c1d9c0f..5d69831 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -3,6 +3,7 @@ #include "window.hpp" #include "gfx_device.hpp" #include "resource_manager.hpp" +#include "log.hpp" namespace engine { @@ -14,11 +15,17 @@ namespace engine { engine::ResourceManager resMan{}; m_gfx->createPipeline(resMan.getFilePath("shader.vert.spv").string().c_str(), resMan.getFilePath("shader.frag.spv").string().c_str()); + + gfx::BufferDesc bufferDesc { + .size = 65536, + }; + gfx::BufferHandle* buffer = m_gfx->createBuffer(bufferDesc, nullptr); + + m_gfx->destroyBuffer(buffer); } Application::~Application() { - } void Application::gameLoop() diff --git a/src/gfx_device_vulkan.cpp b/src/gfx_device_vulkan.cpp index dccc244..0379543 100644 --- a/src/gfx_device_vulkan.cpp +++ b/src/gfx_device_vulkan.cpp @@ -56,6 +56,8 @@ namespace engine { std::vector imageViews{}; std::vector framebuffers{}; + VkQueue activeQueue{}; + VkRenderPass renderpass; VkSemaphore acquireSemaphore = VK_NULL_HANDLE; // waits until the image is available @@ -67,17 +69,19 @@ namespace engine { VkPipeline handle = VK_NULL_HANDLE; }; - struct AllocatedBuffer { - VkBuffer buffer = VK_NULL_HANDLE; - VmaAllocation allocation = nullptr; - }; - enum class QueueFlags : uint32_t { GRAPHICS = (1 << 0), TRANSFER = (1 << 1), COMPUTE = (1 << 2), }; + // handles + + struct gfx::BufferHandle { + VkBuffer buffer = VK_NULL_HANDLE; + VmaAllocation allocation = nullptr; + }; + // functions @@ -516,6 +520,7 @@ namespace engine { std::vector queues{}; Queue gfxQueue; + Queue presentQueue; VkCommandPool commandPool = VK_NULL_HANDLE; VkCommandBuffer commandBuffer = VK_NULL_HANDLE; @@ -825,6 +830,8 @@ namespace engine { vkGetDeviceQueue(pimpl->device, q.familyIndex, q.queueIndex, &q.handle); } + pimpl->presentQueue = getQueueSupporting(pimpl->queues, QueueFlags::TRANSFER); + pimpl->gfxQueue = getQueueSupporting(pimpl->queues, QueueFlags::GRAPHICS); VkCommandPoolCreateInfo gfxCmdPoolInfo{ @@ -1036,7 +1043,7 @@ namespace engine { presentInfo.pImageIndices = &imageIndex; presentInfo.pResults = nullptr; - res = vkQueuePresentKHR(pimpl->gfxQueue.handle, &presentInfo); + res = vkQueuePresentKHR(pimpl->presentQueue.handle, &presentInfo); if (res == VK_SUBOPTIMAL_KHR || res == VK_ERROR_OUT_OF_DATE_KHR) { // recreate swapchain waitIdle(); @@ -1198,9 +1205,27 @@ namespace engine { } - bool GFXDevice::createBuffer(const gfx::BufferDesc& desc, const void* data, gfx::BufferHandle* out) + gfx::BufferHandle* GFXDevice::createBuffer(const gfx::BufferDesc& desc, const void* data) { - return false; + auto out = new gfx::BufferHandle{}; + + VkBufferCreateInfo createInfo{ VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO }; + createInfo.size = desc.size; + createInfo.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT; + + VmaAllocationCreateInfo allocInfo{}; + allocInfo.usage = VMA_MEMORY_USAGE_AUTO; + + VkResult res = vmaCreateBuffer(pimpl->allocator, &createInfo, &allocInfo, &out->buffer, &out->allocation, nullptr); + assert(res == VK_SUCCESS); + + return out; + } + + void GFXDevice::destroyBuffer(const gfx::BufferHandle* buffer) + { + vmaDestroyBuffer(pimpl->allocator, buffer->buffer, buffer->allocation); + delete buffer; } void GFXDevice::waitIdle()