From 290e4c3c33f9af401c0565b840de3514d199faf5 Mon Sep 17 00:00:00 2001 From: ladevieq Date: Thu, 9 Feb 2023 08:26:40 +0100 Subject: Presentation abstraction --- include/api-test/freelist.hpp | 2 +- include/api-test/vk-device-types.hpp | 21 +++++++++++++++++---- include/api-test/vk-device.hpp | 11 +++++------ 3 files changed, 23 insertions(+), 11 deletions(-) (limited to 'include') diff --git a/include/api-test/freelist.hpp b/include/api-test/freelist.hpp index cfe8903..3cdd55d 100644 --- a/include/api-test/freelist.hpp +++ b/include/api-test/freelist.hpp @@ -18,7 +18,7 @@ class freelist { const auto id = free.back(); free.pop_back(); - items[id] = item; + items[id] = std::move(item); return id; } diff --git a/include/api-test/vk-device-types.hpp b/include/api-test/vk-device-types.hpp index bd2274a..86eb22b 100644 --- a/include/api-test/vk-device-types.hpp +++ b/include/api-test/vk-device-types.hpp @@ -4,6 +4,8 @@ #include +#include "freelist.hpp" + using VmaAllocation = struct VmaAllocation_T*; struct texture_desc { @@ -14,15 +16,21 @@ struct texture_desc { VkImageUsageFlags usages; VkFormat format; VkImageType type; + VkImage vk_image = nullptr; static constexpr auto max_mips = 16U; }; struct device_texture { + device_texture() = default; + device_texture(const texture_desc& desc); + + void create_views(); + VkImage vk_image; VkImageView whole_view; - VkImageView mips_views[texture_desc::max_mips] = { VK_NULL_HANDLE }; - VkImageLayout layout; + VkImageView mips_views[texture_desc::max_mips] = { nullptr }; + VkImageLayout layout = VK_IMAGE_LAYOUT_UNDEFINED; VkPipelineStageFlags2 stage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT; VkAccessFlags2 access = VK_ACCESS_2_NONE; VkFormat format; @@ -37,6 +45,10 @@ struct device_texture { uint32_t sampled_index = -1; VmaAllocation alloc; + +private: + static freelist storage_indices; + static freelist sampled_indices; }; struct buffer_desc { @@ -97,11 +109,12 @@ struct surface_desc { struct device_surface { VkSurfaceKHR vk_surface; VkSwapchainKHR vk_swapchain; + VkSurfaceFormatKHR surface_format; - // handle swapchain_images; + handle swapchain_images[surface_desc::max_image_count]; uint32_t image_index; uint32_t image_count; void acquire_image_index(handle signal_handle); - handle get_backbuffer_image(); + handle get_backbuffer_image() const; }; diff --git a/include/api-test/vk-device.hpp b/include/api-test/vk-device.hpp index fd69d60..9e42b38 100644 --- a/include/api-test/vk-device.hpp +++ b/include/api-test/vk-device.hpp @@ -72,7 +72,7 @@ class vkdevice { return pipelines[handle.id]; } - [[nodiscard]] inline const device_surface& get_surface(handle handle) const { + [[nodiscard]] inline device_surface& get_surface(handle handle) { return surfaces[handle.id]; } @@ -88,6 +88,10 @@ class vkdevice { return device; } + inline VmaAllocator get_allocator() { + return gpu_allocator; + } + void wait(handle semaphore_handle); void submit(std::span buffers, handle wait_handle, handle signal_handle); @@ -102,8 +106,6 @@ class vkdevice { VkShaderModule create_shader_module(const std::span& shader_code); - void create_views(const texture_desc& desc, device_texture& texture); - void create_swapchain(const surface_desc& desc, device_surface& surface); // TODO: Wrap in a struct called adapter ? @@ -134,9 +136,6 @@ class vkdevice { static constexpr size_t max_allocable_command_buffers = 16; static constexpr size_t max_submitable_command_buffers = 16; - freelist storage_indices; - freelist sampled_indices; - freelist textures; freelist buffers; freelist pipelines; -- cgit v1.3