aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2023-02-07 23:53:55 +0100
committerladevieq <ladevie.quentin@gmail.com>2023-02-07 23:53:55 +0100
commit74a223d1a9d23369c6c20457424b34cf17da95ab (patch)
tree18ccf56b8ddc6274410150e7ad4b986e6cb7dbc5 /include
parent9286a3db4f529f435ea4270ffc2ca7a7a1da922d (diff)
Remove presentation stuff from device class
Device instance is no more a pointer Remove desc member in device structs
Diffstat (limited to 'include')
-rw-r--r--include/api-test/command-buffer.hpp2
-rw-r--r--include/api-test/freelist.hpp12
-rw-r--r--include/api-test/handle.hpp6
-rw-r--r--include/api-test/vk-device-types.hpp85
-rw-r--r--include/api-test/vk-device.hpp123
5 files changed, 127 insertions, 101 deletions
diff --git a/include/api-test/command-buffer.hpp b/include/api-test/command-buffer.hpp
index 31b1254..f7a18b0 100644
--- a/include/api-test/command-buffer.hpp
+++ b/include/api-test/command-buffer.hpp
@@ -40,8 +40,6 @@ private:
public:
rect render_area;
std::span<handle<device_texture>> color_attachments;
- // rect viewport;
- // rect scissor;
};
struct draw_params {
handle<device_pipeline> pipeline;
diff --git a/include/api-test/freelist.hpp b/include/api-test/freelist.hpp
index b231d9a..cfe8903 100644
--- a/include/api-test/freelist.hpp
+++ b/include/api-test/freelist.hpp
@@ -1,6 +1,7 @@
+#pragma once
#include <numeric>
#include <vector>
-
+#include <cassert>
static constexpr uint32_t default_element_count = 1024U;
@@ -27,6 +28,11 @@ class freelist {
}
T& operator[](uint32_t index) {
+ assert(index >= 0);
+ return items[index];
+ }
+
+ const T& operator[](uint32_t index) const {
return items[index];
}
@@ -41,11 +47,11 @@ class freelist {
return invalid_id;
}
- auto begin() {
+ auto begin() const {
return items.begin();
}
- auto end() {
+ auto end() const {
return items.end();
}
diff --git a/include/api-test/handle.hpp b/include/api-test/handle.hpp
index 956739d..a81480a 100644
--- a/include/api-test/handle.hpp
+++ b/include/api-test/handle.hpp
@@ -4,9 +4,9 @@
template<typename T>
struct handle {
- uint32_t id = handle::invalid_handle;
+ uint32_t id = handle::invalid_id;
- [[nodiscard]] inline bool is_valid() const { return id != handle::invalid_handle; }
+ [[nodiscard]] inline bool is_valid() const { return id != handle::invalid_id; }
- static constexpr uint32_t invalid_handle = -1;
+ static constexpr uint32_t invalid_id = -1U;
};
diff --git a/include/api-test/vk-device-types.hpp b/include/api-test/vk-device-types.hpp
index b069883..bd2274a 100644
--- a/include/api-test/vk-device-types.hpp
+++ b/include/api-test/vk-device-types.hpp
@@ -4,18 +4,16 @@
#include <span>
-#include "vk-bindless.hpp"
-
using VmaAllocation = struct VmaAllocation_T*;
struct texture_desc {
- uint32_t width = 1U;
- uint32_t height = 1U;
- uint32_t depth = 1U;
- uint32_t mips = 1U;
- VkImageUsageFlags usages;
- VkFormat format;
- VkImageType type;
+ uint32_t width = 1U;
+ uint32_t height = 1U;
+ uint32_t depth = 1U;
+ uint32_t mips = 1U;
+ VkImageUsageFlags usages;
+ VkFormat format;
+ VkImageType type;
static constexpr auto max_mips = 16U;
};
@@ -25,24 +23,27 @@ struct device_texture {
VkImageView whole_view;
VkImageView mips_views[texture_desc::max_mips] = { VK_NULL_HANDLE };
VkImageLayout layout;
- VkPipelineStageFlags2 stage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
- VkAccessFlags2 access = VK_ACCESS_2_NONE;
+ VkPipelineStageFlags2 stage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
+ VkAccessFlags2 access = VK_ACCESS_2_NONE;
+ VkFormat format;
+ VkImageAspectFlags aspects;
+
+ uint32_t width = 1U;
+ uint32_t height = 1U;
+ uint32_t depth = 1U;
+ uint32_t mips = 1U;
uint32_t storage_index = -1;
uint32_t sampled_index = -1;
- uint32_t sampler_index = -1;
VmaAllocation alloc;
-
- texture_desc desc;
};
-
struct buffer_desc {
- size_t size;
- VkBufferUsageFlags usages;
- VkMemoryPropertyFlags memory_properties;
- uint32_t memory_usage;
+ size_t size;
+ VkBufferUsageFlags usages;
+ VkMemoryPropertyFlags memory_properties;
+ uint32_t memory_usage;
};
struct device_buffer {
@@ -50,37 +51,57 @@ struct device_buffer {
VmaAllocation alloc;
VkDeviceAddress device_address = 0U;
void* mapped_ptr;
-
- buffer_desc desc;
+ size_t size;
};
struct pipeline_desc {
- std::span<uint8_t> vs_code;
- std::span<uint8_t> fs_code;
- std::span<uint8_t> cs_code;
+ std::span<uint8_t> cs_code;
+ std::span<uint8_t> vs_code;
+ std::span<uint8_t> fs_code;
std::span<VkFormat> color_attachments_format;
- VkFormat depth_attachment_format;
- VkFormat stencil_attachment_format;
+ VkFormat depth_attachment_format;
+ VkFormat stencil_attachment_format;
};
struct device_pipeline {
VkPipeline vk_pipeline;
VkPipelineBindPoint bind_point;
- pipeline_desc desc;
+};
- // bindless_model* bindless = nullptr;
+
+struct semaphore_desc {
+ VkSemaphoreType type;
+ uint64_t initial_value = 0U;
+};
+
+struct device_semaphore {
+ VkSemaphore vk_semaphore = nullptr;
+ uint64_t value;
};
+typedef struct HWND__* HWND;
+
struct surface_desc {
+ HWND window_handle;
+ VkSurfaceFormatKHR surface_format;
+ VkPresentModeKHR present_mode;
+ VkImageUsageFlags usages;
+ uint32_t image_count = surface_desc::default_image_count;
+ static constexpr uint32_t max_image_count = 3U;
+ static constexpr uint32_t default_image_count = 3U;
};
struct device_surface {
- VkSurfaceKHR vk_surface;
- VkSwapchainKHR vk_swapchain;
+ VkSurfaceKHR vk_surface;
+ VkSwapchainKHR vk_swapchain;
+
+ // handle<device_texture> swapchain_images;
+ uint32_t image_index;
+ uint32_t image_count;
- handle<device_texture> swapchain_images;
- uint32_t image_index;
+ void acquire_image_index(handle<device_semaphore> signal_handle);
+ handle<device_texture> get_backbuffer_image();
};
diff --git a/include/api-test/vk-device.hpp b/include/api-test/vk-device.hpp
index 5b71529..fd69d60 100644
--- a/include/api-test/vk-device.hpp
+++ b/include/api-test/vk-device.hpp
@@ -15,11 +15,6 @@ using VmaAllocator = struct VmaAllocator_T*;
class window;
-struct vksemaphore {
- VkSemaphore vk_semaphore = nullptr;
- uint64_t value = 0U;
-};
-
class vkdevice {
struct queue {
VkQueue vk_queue;
@@ -29,49 +24,63 @@ class vkdevice {
};
public:
- static vkdevice* init_device(const window& window);
+ void init();
- static void free_device();
-
- static inline vkdevice* get_render_device() {
+ static inline vkdevice& get_render_device() {
return render_device;
}
- handle<device_texture> create_texture(const texture_desc& desc);
+ handle<device_texture> create_texture(const texture_desc& desc);
+
+ handle<device_buffer> create_buffer(const buffer_desc& desc);
- handle<device_buffer> create_buffer(const buffer_desc& desc);
+ handle<device_pipeline> create_pipeline(const pipeline_desc& desc);
- handle<device_pipeline> create_pipeline(const pipeline_desc& desc);
+ handle<device_surface> create_surface(const surface_desc& desc);
- vksemaphore create_semaphore();
+ handle<device_semaphore> create_semaphore(const semaphore_desc& desc);
- void destroy_texture(const device_texture& texture);
- void destroy_texture(handle<device_texture> handle);
+ void destroy_texture(const device_texture& texture);
+ void destroy_texture(handle<device_texture> handle);
- void destroy_buffer(const device_buffer& buffer);
- void destroy_buffer(handle<device_buffer> handle);
+ void destroy_buffer(const device_buffer& buffer);
+ void destroy_buffer(handle<device_buffer> handle);
- void destroy_pipeline(const device_pipeline& pipeline);
- void destroy_pipeline(handle<device_pipeline> handle);
+ void destroy_pipeline(const device_pipeline& pipeline);
+ void destroy_pipeline(handle<device_pipeline> handle);
+
+ void destroy_semaphore(const device_semaphore& semaphore);
+ void destroy_semaphore(handle<device_semaphore> handle);
+
+ void destroy_surface(const device_surface& surface);
+ void destroy_surface(handle<device_surface> handle);
template<typename cmd_buf_type>
void allocate_command_buffers(cmd_buf_type* buffers, size_t count, QueueType queue_type) {
allocate_command_buffers(static_cast<command_buffer*>(buffers), count, queue_type);
}
- inline device_texture& get_texture(handle<device_texture> handle) {
+ [[nodiscard]] inline device_texture& get_texture(handle<device_texture> handle) {
return textures[handle.id];
}
- inline const device_buffer& get_buffer(handle<device_buffer> handle) {
+ [[nodiscard]] inline const device_buffer& get_buffer(handle<device_buffer> handle) const {
return buffers[handle.id];
}
- inline const device_pipeline& get_pipeline(handle<device_pipeline> handle) {
+ [[nodiscard]] inline const device_pipeline& get_pipeline(handle<device_pipeline> handle) const {
return pipelines[handle.id];
}
- inline const bindless_model& get_bindingmodel() {
+ [[nodiscard]] inline const device_surface& get_surface(handle<device_surface> handle) const {
+ return surfaces[handle.id];
+ }
+
+ [[nodiscard]] inline device_semaphore& get_semaphore(handle<device_semaphore> handle) {
+ return semaphores[handle.id];
+ }
+
+ [[nodiscard]] inline const bindless_model& get_bindingmodel() const {
return bindless;
}
@@ -79,70 +88,62 @@ class vkdevice {
return device;
}
- void wait(vksemaphore& semaphore);
+ void wait(handle<device_semaphore> semaphore_handle);
- void submit(std::span<command_buffer> buffers, vksemaphore* wait, vksemaphore* signal);
+ void submit(std::span<command_buffer> buffers, handle<device_semaphore> wait_handle, handle<device_semaphore> signal_handle);
- void present(device_surface& surface, const vksemaphore& semaphore);
+ void present(handle<device_surface> surface_handle, handle<device_semaphore> semaphore_handle);
private:
- vkdevice(const window& window);
+ vkdevice() = default;
~vkdevice();
void allocate_command_buffers(command_buffer* buffers, size_t count, QueueType type);
- void create_views(device_texture& texture);
+ VkShaderModule create_shader_module(const std::span<uint8_t>& shader_code);
- // Presentation stuff
- void create_surface(const window& window);
+ void create_views(const texture_desc& desc, device_texture& texture);
- void create_swapchain();
-
- void create_virtual_frames();
-
- VkSurfaceKHR surface = nullptr;
- VkSwapchainKHR swapchain = nullptr;
+ void create_swapchain(const surface_desc& desc, device_surface& surface);
// TODO: Wrap in a struct called adapter ?
- void create_instance();
-
- void create_device();
+ void create_instance();
- void create_memory_allocator();
+ void create_device();
- void create_command_pools();
+ void create_memory_allocator();
- void pick_physical_device();
+ void create_command_pools();
- static bool device_support_features(VkPhysicalDevice physical_dev);
+ void pick_physical_device();
- void create_debug_layer_callback();
+ static bool device_support_features(VkPhysicalDevice physical_dev);
- // Virtual frames resources
- static constexpr uint32_t virtual_frames_count = 3U;
- VkSemaphore semaphores[virtual_frames_count];
+ void create_debug_layer_callback();
- queue queues[static_cast<uint32_t>(QueueType::MAX)];
+ queue queues[static_cast<uint32_t>(QueueType::MAX)];
- VkInstance instance;
- VkPhysicalDevice physical_device;
- VkDevice device;
+ VkInstance instance;
+ VkPhysicalDevice physical_device;
+ VkDevice device;
- VmaAllocator gpu_allocator;
+ VmaAllocator gpu_allocator;
- bindless_model bindless;
+ bindless_model bindless;
- static constexpr size_t max_allocable_command_buffers = 16;
- static constexpr size_t max_submitable_command_buffers = 16;
+ static constexpr size_t max_allocable_command_buffers = 16;
+ static constexpr size_t max_submitable_command_buffers = 16;
- freelist<device_texture*> storage_indices;
- freelist<device_texture*> sampled_indices;
+ freelist<device_texture*> storage_indices;
+ freelist<device_texture*> sampled_indices;
- freelist<device_texture> textures;
- freelist<device_buffer> buffers;
- freelist<device_pipeline> pipelines;
+ freelist<device_texture> textures;
+ freelist<device_buffer> buffers;
+ freelist<device_pipeline> pipelines;
+ freelist<device_surface> surfaces;
+ freelist<device_semaphore> semaphores;
- static vkdevice* render_device;
+ static vkdevice render_device;
#ifdef _DEBUG
VkDebugUtilsMessengerEXT debug_messenger;