diff --git a/src/vulkan_instance.hpp b/src/vulkan_instance.hpp index cafef8f..c5cbf8b 100644 --- a/src/vulkan_instance.hpp +++ b/src/vulkan_instance.hpp @@ -11,9 +11,10 @@ #define VULKAN_HPP_NO_CONSTRUCTORS #include -#include "vk_convert.hpp" +#define LOG_SUBLOGS #include "vertex.hpp" +#include "vk_convert.hpp" #include "vulkan_util.hpp" #include "vulkan_allocator.hpp" @@ -21,7 +22,7 @@ #include #include -#include +#include #include #include @@ -47,6 +48,16 @@ namespace gz::vlk { /** * @nosubgrouping + * @details + * @section vi_options + * - `VULKAN_INSTANCE_SWAP_CHAIN_AS_TRANSFER_DST` + * - `VULKAN_INSTANCE_SWAP_CHAIN_AS_RENDER_TARGET` + * + * @todo Push constancts for texture atlases + * @todo Multiple texture atlases test + * @todo Font + * @todo Runtime glsl -> spirv compilation -> pipeline recreation + * @todo Improve current allocation "strategy" */ class VulkanInstance { public: @@ -60,18 +71,18 @@ namespace gz::vlk { /** * @brief Initializes the vulkan instance * @details - * -# @ref createWindow "create a window through glfw" - * -# @ref createInstance "create the vulkan instance" - * -# @ref setupDebugMessenger "sets up the debug messenger" - * -# @ref createSurface "create a the window surface" - * -# @ref selectPhysicalDevice "select a GPU" - * -# @ref setValidSettings "set the possible settings for the SettingsManager" - * -# @ref createLogicalDevice "create a logical device" - * -# @ref createSwapChain "create the swap chain" - * -# @ref createCommandPools "create the command pools" + * -# @ref createWindow() "create a window through glfw" + * -# @ref createInstance() "create the vulkan instance" + * -# @ref setupDebugMessenger() "sets up the debug messenger" + * -# @ref createSurface() "create a the window surface" + * -# @ref selectPhysicalDevice() "select a GPU" + * -# @ref setValidSettings() "set the possible settings for the SettingsManager" + * -# @ref createLogicalDevice() "create a logical device" + * -# @ref createSwapChain() "create the swap chain" + * -# @ref createCommandPools() "create the command pools" * @todo move depth image, texture, texture samples, model stuff to renderers - * -# @ref createCommandBuffers "create command buffers for swap chain image layout transitions" - * -# @ref createSyncObjects "create synchronization objects" + * -# @ref createCommandBuffers() "create command buffers for swap chain image layout transitions" + * -# @ref createSyncObjects() "create synchronization objects" */ void init(); /** @@ -179,6 +190,12 @@ namespace gz::vlk { */ void copyBuffer(vk::Buffer srcBuffer, vk::Buffer dstBuffer, vk::DeviceSize size); + /** + * @brief Copy srcData to dstBuffer at offset via a staging buffer + * @todo Detect when staging buffer is not necessary and make a direct copy + */ + void copyToDeviceBuffer(const void* srcData, vk::DeviceSize srcSize, vk::Buffer& dstBuffer, MemoryInfo& dstMemory, uint32_t dstOffset); + /** * @brief Begin a command buffer that is going to be used once * @param commandPool: The command pool from which the buffer should be allocated @@ -192,8 +209,6 @@ namespace gz::vlk { * After command buffer is submitted on the specified queue, the function waits for the queue to idle */ void endSingleTimeCommands(vk::CommandBuffer cmdBuffer, InstanceCommandPool commandPool); - - void loadModel(const std::string& path, VerticesAndIndices& model); /// @} /** @@ -251,7 +266,7 @@ namespace gz::vlk { * */ template - void createGraphicsPipeline(vk::GraphicsPipelineCreateInfo&& pipelineCI, const std::vector* descriptorSetLayouts, bool useDepthStencil, Pipeline& pipeline); + void createGraphicsPipeline(vk::GraphicsPipelineCreateInfo&& pipelineCI, const std::vector& descriptorSetLayouts, const std::vector& pushConstantRanges, bool useDepthStencil, Pipeline& pipeline); vk::ShaderModule createShaderModule(const std::vector& code); /* void createShaderStageCreateInfos(const std::vector>& shaders, std::vector& shaderStages); */ @@ -341,7 +356,7 @@ namespace gz::vlk { /** * @brief Create a 2D imageView with format for image. */ - void createImageView(vk::Format format, vk::Image& image, vk::ImageView& imageView, vk::ImageAspectFlags aspectFlags); + void createImageView(vk::Format format, const vk::Image& image, vk::ImageView& imageView, vk::ImageAspectFlags aspectFlags); void destroyImageView(vk::ImageView& imageView); void copyBufferToImage(vk::Buffer buffer, vk::Image image, int32_t offsetX, int32_t offsetY, uint32_t width, uint32_t height); @@ -366,9 +381,12 @@ namespace gz::vlk { * Supported transitions: * - UNDEFINED -> DEPTH_STENCIL_ATTACHMENT_OPTIMAL (graphics q) * - UNDEFINED -> TRANSFER_DST_OPTIMAL (transfer q) + * - UNDEFINED -> COLOR_ATTACHMENT_OPTIMAL (graphics q) * - SHADER_READ_ONLY_OPTIMAL -> TRANSFER_DST_OPTIMAL (graphics q) * - TRANSFER_DST_OPTIMAL -> SHADER_READ_ONLY_OPTIMAL (graphics q) * - TRANSFER_DST_OPTIMAL -> PRESENT_SRC_KHR (graphics q) + * - COLOR_ATTACHMENT_OPTIMAL -> PRESENT_SRC_KHR (graphics q) + * - COLOR_ATTACHMENT_OPTIMAL -> TRANSFER_SRC_OPTIMAL (graphics q) * * If you do not provide a command buffer, a command buffer from the indicated queue will be created and submitted. * If you do provide a command buffer, the command is recorded but NOT submitted. @@ -403,6 +421,9 @@ namespace gz::vlk { VkDebugUtilsMessageTypeFlagsEXT messageType, const VkDebugUtilsMessengerCallbackDataEXT* pCallbackData, void* pUserData); + static Log createSublog(bool showLog, const std::string& prefix, Color prefixColor) { + return vLog.createSublog(showLog, prefix, prefixColor); + } /// @} private: @@ -623,6 +644,7 @@ namespace gz::vlk { vk::Extent2D selectSwapExtent(const vk::SurfaceCapabilities2KHR& capabilities); /** * @brief Create swap chain, image views + * @todo query if transfer dst is supported */ void createSwapChain(); /** @@ -692,7 +714,7 @@ namespace gz::vlk { void cleanupDebugMessenger(); VkDebugUtilsMessengerEXT debugMessenger; static gz::Log vLog; - /// @} /// @} + /// @} /** * @name Debugging: (handle ownership) @@ -708,7 +730,10 @@ namespace gz::vlk { * `Handle Ownerships: [ - , ...]` */ static void getHandleOwnerString(std::string_view message); + /// Temporary used in getHandleOwnerString static std::string handleOwnerString; + /// Temporary used in getHandleOwnerString to filter duplicates + static std::set foundHandles; /// Used for alternating the color of validation messages between grey and white static bool lastColorWhite; /// @}