diff options
| author | ladevieq <ladevie.quentin@gmail.com> | 2026-05-05 00:43:54 +0200 |
|---|---|---|
| committer | ladevieq <ladevie.quentin@gmail.com> | 2026-05-05 00:49:12 +0200 |
| commit | c3aac9026951e2a6e35e76b9c7d36e114a281453 (patch) | |
| tree | bdfc2ab5d5f1d196ba8c7a76371a29911f75913e /include/api-test | |
| parent | 754249d9c652ef941e6b082d2e86538d15ba9434 (diff) | |
Remove old api and move api-test content to src and include dirs
Diffstat (limited to 'include/api-test')
| -rw-r--r-- | include/api-test/buffer.hpp | 18 | ||||
| -rw-r--r-- | include/api-test/dx12-command-buffer.hpp | 28 | ||||
| -rw-r--r-- | include/api-test/dx12-device-types.hpp | 74 | ||||
| -rw-r--r-- | include/api-test/dx12-device.hpp | 97 | ||||
| -rw-r--r-- | include/api-test/freelist.hpp | 151 | ||||
| -rw-r--r-- | include/api-test/handle.hpp | 24 | ||||
| -rw-r--r-- | include/api-test/resource-manager.hpp | 22 | ||||
| -rw-r--r-- | include/api-test/texture.hpp | 17 | ||||
| -rw-r--r-- | include/api-test/vk-bindless.hpp | 93 | ||||
| -rw-r--r-- | include/api-test/vk-command-buffer.hpp | 103 | ||||
| -rw-r--r-- | include/api-test/vk-device-types.hpp | 213 | ||||
| -rw-r--r-- | include/api-test/vk-device.hpp | 161 | ||||
| -rw-r--r-- | include/api-test/vk-utils.hpp | 16 |
13 files changed, 0 insertions, 1017 deletions
diff --git a/include/api-test/buffer.hpp b/include/api-test/buffer.hpp deleted file mode 100644 index 64c4881..0000000 --- a/include/api-test/buffer.hpp +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include <cstdint> - -#include <vulkan/vulkan_core.h> - -#include "handle.hpp" - -struct device_buffer; - -class buffer { -public: - buffer(handle<device_buffer> handle); - -private: - handle<device_buffer> handle; - -}; diff --git a/include/api-test/dx12-command-buffer.hpp b/include/api-test/dx12-command-buffer.hpp deleted file mode 100644 index e9de39a..0000000 --- a/include/api-test/dx12-command-buffer.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#include <d3d12.h> - -#include "handle.hpp" -#include "dx12-device-types.hpp" - -namespace dx12 { - struct command_buffer { - void start() const; - void stop() const; - - // void barrier(handle<device_texture> texture_handle, VkPipelineStageFlags2 stage, VkAccessFlags2 access, VkImageLayout layout) const; - - void copy(handle<device_buffer> src_buffer, handle<device_texture> dst_texture, uint64_t offset = 0) const; - - ID3D12CommandAllocator* command_allocator; - ID3D12GraphicsCommandList* dx12_command_buffer; - dx12::QueueType queue_type; - }; - - struct graphics_command_buffer: public command_buffer { - // void dispatch(const dispatch_params& params) const; - - // void begin_renderpass(const renderpass_params& params) const; - // void draw(const draw_params& params) const; - // void draw_indexed(const draw_indexed_params& params) const; - // void end_renderpass() const; - }; -} diff --git a/include/api-test/dx12-device-types.hpp b/include/api-test/dx12-device-types.hpp deleted file mode 100644 index 4b2fc42..0000000 --- a/include/api-test/dx12-device-types.hpp +++ /dev/null @@ -1,74 +0,0 @@ -#pragma once -#include <d3d12.h> -#include <dxgi1_3.h> -#include <D3D12MemAlloc.h> - -#include <cstdint> - -namespace dx12 { - enum class QueueType : uint32_t { - GRAPHICS, - ASYNC_COMPUTE, - TRANSFER, - MAX, - }; - - struct buffer_desc { - uint32_t size; - bool map; - - D3D12_RESOURCE_STATES states; - D3D12_RESOURCE_FLAGS usages; - D3D12_HEAP_TYPE heap_type = D3D12_HEAP_TYPE_DEFAULT; - }; - - struct device_buffer { - ID3D12Resource* resource; - - D3D12MA::Allocation* alloc; - uint32_t size; - void* mapped_ptr = nullptr; - }; - - - struct texture_desc { - uint32_t width = 1U; - uint32_t height = 1U; - uint32_t depth = 1U; - uint32_t mips = 1U; - - D3D12_RESOURCE_STATES states; - D3D12_RESOURCE_FLAGS usages; - DXGI_FORMAT format; - D3D12_RESOURCE_DIMENSION type; - }; - - struct device_texture { - ID3D12Resource* resource; - D3D12MA::Allocation* alloc; - - uint32_t width = 1U; - uint32_t height = 1U; - uint32_t depth = 1U; - uint32_t mips = 1U; - uint64_t row_pitch = 1U; - - DXGI_FORMAT format; - - }; - - struct surface_desc { - HWND window_handle; - DXGI_FORMAT surface_format; - DXGI_SWAP_EFFECT present_mode; - DXGI_USAGE 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 { - IDXGISwapChain1* swapchain; - }; -} diff --git a/include/api-test/dx12-device.hpp b/include/api-test/dx12-device.hpp deleted file mode 100644 index baa5b60..0000000 --- a/include/api-test/dx12-device.hpp +++ /dev/null @@ -1,97 +0,0 @@ -#pragma once - -#include <d3d12.h> -#include <dxgi1_3.h> - -#include "freelist.hpp" -#include "dx12-device-types.hpp" - -#include "D3D12MemAlloc.h" - -namespace dx12 { - struct command_buffer; - - class device { - struct queue { - ID3D12CommandQueue* dx_queue; - D3D12_COMMAND_LIST_TYPE type; - }; - public: - void init(); - - static inline device& get_render_device() { - return render_device; - } - - handle<device_surface> create_surface(const surface_desc& desc); - - handle<device_buffer> create_buffer(const buffer_desc& desc); - - handle<device_texture> create_texture(const texture_desc& desc); - - void create_graphics_pipeline() {}; - - void create_compute_pipeline() {}; - - void allocate_command_buffers(command_buffer* buffers, size_t count, QueueType type); - - - [[nodiscard]] inline device_surface& get_surface(handle<device_surface> handle) { - return surfaces[handle]; - } - - [[nodiscard]] inline device_buffer& get_buffer(handle<device_buffer> handle) { - return buffers[handle]; - } - - [[nodiscard]] inline device_texture& get_texture(handle<device_texture> handle) { - return textures[handle]; - } - - [[nodiscard]] inline ID3D12Device* get_device() const { - return device; - } - - uint32_t submit(command_buffer* buffers, uint32_t count); - - void wait(); - - private: - IDXGIFactory3* factory; - IDXGIAdapter* adapter; - ID3D12Debug* debug_interface; - - D3D12MA::Allocator* allocator; - - ID3D12Device* device; - ID3D12Fence* fence; - uint64_t fence_value = 0U; - queue queues[static_cast<uint32_t>(QueueType::MAX)]; - - freelist<device_surface> surfaces; - freelist<device_buffer> buffers; - freelist<device_texture> textures; - - static constexpr size_t max_allocable_command_buffers = 16U; - static constexpr size_t max_submitable_command_buffers = 16U; - - static class device render_device; - - struct bindless_model { - void init(); - - [[nodiscard]] inline ID3D12DescriptorHeap* const* get_heaps() const { - return &resources_heap; - } - - ID3D12DescriptorHeap* resources_heap; - ID3D12DescriptorHeap* samplers_heap; - } model; - - public: - [[nodiscard]] static inline const device::bindless_model& get_bindless_model() { - return render_device.model; - } - }; - -} diff --git a/include/api-test/freelist.hpp b/include/api-test/freelist.hpp deleted file mode 100644 index cbcd56d..0000000 --- a/include/api-test/freelist.hpp +++ /dev/null @@ -1,151 +0,0 @@ -#pragma once -#include <vector> -#include <cassert> - -#include "handle.hpp" - -static constexpr uint32_t default_element_count = 1024U; - -template<typename T, const size_t initial_size = default_element_count> -class freelist { - public: - - freelist() { - grow(initial_size); - } - - handle<T> add(const T& item) { - // auto id = elements[0U].next_free; - auto id = next_free_id; - - if (id == freelist<T>::invalid_id) { - grow(elements.size()); - - // id = elements[0U].next_free; - id = next_free_id; - } - - auto& element = elements[id]; - - next_free_id = element.next_free; - // elements[0U].next_free = element.next_free; - element.item = std::move(item); - - return { id, ++element.generation }; - } - - void remove(handle<T> handle) { - assert(handle.generation == elements[handle.id].generation); - // elements[handle.id].next_free = elements[0U].next_free; - // elements[0U].next_free = handle.id; - elements[handle.id].next_free = next_free_id; - next_free_id = handle.id; - } - - T& operator[](handle<T> handle) { - assert(handle.generation == elements[handle.id].generation); - return elements[handle.id].item; - } - - const T& operator[](handle<T> handle) const { - assert(handle.generation == elements[handle.id].generation); - return elements[handle.id].item; - } - - static constexpr uint32_t invalid_id = UINT32_MAX; - -private: - void grow(size_t grow_size) { - auto size = elements.size(); - uint32_t next_free = static_cast<uint32_t>(size); - next_free_id = next_free; - - elements.reserve(size + grow_size); - - for (auto id { 0U }; id < initial_size; id++) { - elements.push_back( - { - .next_free = static_cast<uint32_t>(++next_free % initial_size), - } - ); - } - - elements.back().next_free = freelist<T>::invalid_id; - } - - struct element { - union { - T item; - uint32_t next_free = freelist<T>::invalid_id; - }; - uint32_t generation = 0U; - }; - - std::vector<element> elements; - uint32_t next_free_id; -}; - -template<const size_t initial_size = default_element_count> -class idlist { - public: - - idlist() { - grow(initial_size); - } - - handle<void> add() { - // auto id = elements[0U].next_free; - auto id = next_free_id; - - if (id == idlist<T>::invalid_id) { - grow(elements.size()); - - // id = elements[0U].next_free; - id = next_free_id; - } - - auto& element = elements[id]; - next_free_id = element.next_free; - elements[0U].next_free = element.next_free; - element.next_free = idlist<T>::invalid_id; - - return { id, ++element.generation }; - } - - void remove(handle<void> handle) { - assert(handle.generation == elements[handle.id].generation); - // elements[handle.id].next_free = elements[0U].next_free; - // elements[0U].next_free = handle.id; - elements[handle.id].next_free = next_free_id; - next_free_id = handle.id; - } - - static constexpr uint32_t invalid_id = UINT32_MAX; - -private: - void grow(size_t grow_size) { - auto size = elements.size(); - uint32_t next_free = static_cast<uint32_t>(size); - next_free_id = next_free; - - elements.reserve(size + grow_size); - - for (auto id { 0U }; id < initial_size; id++) { - elements.push_back( - { - .next_free = static_cast<uint32_t>(++next_free% initial_size), - } - ); - } - - elements.back().next_free = idlist<T>::invalid_id; - } - - struct element { - uint32_t next_free = idlist<T>::invalid_id; - uint32_t generation = 0U; - }; - - std::vector<element> elements; - uint32_t next_free_id; -}; diff --git a/include/api-test/handle.hpp b/include/api-test/handle.hpp deleted file mode 100644 index 2c52c01..0000000 --- a/include/api-test/handle.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include <cstdint> - -// template<typename T> -// struct handle { -// uint32_t id = handle::invalid_id; -// -// [[nodiscard]] inline bool is_valid() const { return id != handle::invalid_id; } -// -// static constexpr uint32_t invalid_id = -1U; -// }; - -template<typename U> -struct handle { - uint32_t id = invalid_id; - uint32_t generation = 0U; - - [[nodiscard]] inline bool is_valid() const { return id != handle::invalid_id; } - - static constexpr uint32_t invalid_id = UINT32_MAX; - - // static constexpr handle<U> invalid_handle {}; -}; diff --git a/include/api-test/resource-manager.hpp b/include/api-test/resource-manager.hpp deleted file mode 100644 index f414367..0000000 --- a/include/api-test/resource-manager.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include "handle.hpp" -#include "freelist.hpp" -#include "texture.hpp" -#include "buffer.hpp" - -class resourcemanager { -public: - - handle<texture> create_texture(const texture_desc& desc); - - handle<buffer> create_buffer(const buffer_desc& desc); - - const texture& get_texture(handle<texture> handle); - - const buffer& get_buffer(handle<buffer> handle); - -private: - freelist<texture> textures; - freelist<buffer> buffers; -}; diff --git a/include/api-test/texture.hpp b/include/api-test/texture.hpp deleted file mode 100644 index 59bfec1..0000000 --- a/include/api-test/texture.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include <cstdint> - -#include <vulkan/vulkan_core.h> - -#include "handle.hpp" - -struct device_texture; - -class texture { -public: - texture(handle<device_texture> handle); - -private: - handle<device_texture> handle; -}; diff --git a/include/api-test/vk-bindless.hpp b/include/api-test/vk-bindless.hpp deleted file mode 100644 index a5686ff..0000000 --- a/include/api-test/vk-bindless.hpp +++ /dev/null @@ -1,93 +0,0 @@ -#pragma once - -#include <cstdint> - -#include <vulkan/vulkan_core.h> - -#include "handle.hpp" - -enum BindlessSetType : uint32_t { - GLOBAL, - INSTANCES_UNIFORMS, - DRAWS_UNIFORMS, - MAX, -}; - -enum ConstantType : uint32_t { - GLOBALS, - INSTANCES, - DRAWS, - VERTEX_BUFFER -}; - -enum SamplerType : uint32_t { - NEAREST, - LINEAR, - MAX_SAMPLER, -}; - -struct device_buffer; - -struct bindless_model { -#ifndef USE_VK_DESCRIPTOR_BUFFER - [[nodiscard]] device_buffer& get_draws_uniform_buffer() const; - [[nodiscard]] device_buffer& get_globals_uniform_buffer() const; - - static bindless_model create_bindless_model(); - - static void destroy_bindless_model(bindless_model& bindless); - - VkPipelineLayout graphics_layout; - VkPipelineLayout compute_layout; - VkDescriptorSet sets[BindlessSetType::MAX]; - -private: - static constexpr size_t max_push_constants_size = 128ULL; - -public: - static constexpr size_t max_push_constants_slots_size = 8U; - static constexpr size_t max_push_constants_slots = max_push_constants_size / max_push_constants_slots_size; - -private: - VkDescriptorSetLayout sets_layout[BindlessSetType::MAX]; - VkDescriptorPool descriptor_pool; - handle<device_buffer> globals_uniform_buffer_handle; - handle<device_buffer> instances_uniform_buffer_handle; - handle<device_buffer> draws_uniform_buffer_handle; - - static constexpr size_t descriptor_pool_allocable_sets_count = 64U; - static constexpr uint32_t set_descriptors_count = 1024U; - - void create_layout(VkDevice device); - void create_descriptor_pool(VkDevice device); - void allocate_sets(VkDevice device); - - void destroy_descriptor_pool(VkDevice device); - - void create_immutable_samplers(VkDevice device); - - void destroy_immutable_samplers(VkDevice device); - - VkSampler samplers[SamplerType::MAX_SAMPLER]; - - static constexpr size_t globals_uniform_buffer_size = 64ULL * 1024ULL; - static constexpr size_t instances_uniform_buffer_size = 64ULL * 1024ULL; - static constexpr size_t draws_uniform_buffer_size = 64ULL * 1024ULL; -#else - VkPipelineLayout layout; - VkDescriptorSetLayout sets_layout[BindlessSetType::MAX]; - - static constexpr size_t descriptor_pool_allocable_sets_count = 64U; - static constexpr uint32_t set_descriptors_count[BindlessSetType::MAX]{ 1024U }; - - static bindless_model create_bindless_model(VkDevice device); - - static void destroy_bindless_model(VkDevice device, bindless_model& bindless); - - private: - void create_layout(VkDevice device); - - handle<device_buffer> storage_image_descriptors; - handle<device_buffer> sampled_image_descriptors; -#endif -}; diff --git a/include/api-test/vk-command-buffer.hpp b/include/api-test/vk-command-buffer.hpp deleted file mode 100644 index 08652fd..0000000 --- a/include/api-test/vk-command-buffer.hpp +++ /dev/null @@ -1,103 +0,0 @@ -#pragma once - -#include <cstdint> -#include <span> - -#include <vulkan/vulkan_core.h> - -#include "handle.hpp" - -#include "vec3.hpp" - -#include "vk-device-types.hpp" - -struct device_texture; -struct device_buffer; -struct device_pipeline; - -struct dispatch_params { - enum class PARAM_BINDING : uint32_t { - PARAM1, - PARAM2, - PARAM3, - PARAM4, - PARAM5, - PARAM6, - PARAM7, - PARAM8, - MAX - }; - - handle<device_pipeline> pipeline; - vec3u group_size; - vec3u local_group_size; - uint64_t params[static_cast<uint32_t>(PARAM_BINDING::MAX)]; -}; - -struct renderpass_params { -private: - struct rect { - int32_t x; - int32_t y; - uint32_t width; - uint32_t height; - }; - -public: - rect render_area; - std::span<handle<device_texture>> color_attachments; -}; - -struct draw_params { - handle<device_pipeline> pipeline; - handle<device_buffer> index_buffer; - uint32_t vertex_count; - uint32_t vertex_offset; - uint32_t instance_count; - uint64_t globals_address = 0U; // TODO: This is probably stupid and should be set elsewhere once ??? - uint64_t instances_address = 0U; - uint64_t uniforms_address = 0U; - uint64_t vertex_address = 0U; -}; - -struct draw_indexed_params { - handle<device_pipeline> pipeline; - handle<device_buffer> index_buffer; - uint32_t vertex_count; - uint32_t vertex_offset; - uint32_t index_offset; - uint32_t instance_count; - uint64_t globals_address = 0U; // TODO: This is probably stupid and should be set elsewhere once ??? - uint64_t instances_address = 0U; - uint64_t uniforms_address = 0U; - uint64_t vertex_address = 0U; -}; - -struct command_buffer { - void start() const; - void stop() const; - - void barrier(handle<device_texture> texture_handle, VkPipelineStageFlags2 stage, VkAccessFlags2 access, VkImageLayout layout) const; - - void copy(handle<device_buffer> buffer_handle, handle<device_texture> texture_handle, uint64_t offset = 0) const; - - VkCommandBuffer vk_command_buffer; - QueueType queue_type; -}; - -// General purpose queue -struct graphics_command_buffer: public command_buffer { - void dispatch(const dispatch_params& params) const; - - void begin_renderpass(const renderpass_params& params) const; - void draw(const draw_params& params) const; - void draw_indexed(const draw_indexed_params& params) const; - void end_renderpass() const; -}; - -struct compute_command_buffer: public command_buffer { - void dispatch(const dispatch_params& params); -}; - -struct transfer_command_buffer: public command_buffer { -}; diff --git a/include/api-test/vk-device-types.hpp b/include/api-test/vk-device-types.hpp deleted file mode 100644 index eddf40c..0000000 --- a/include/api-test/vk-device-types.hpp +++ /dev/null @@ -1,213 +0,0 @@ -#pragma once - -#include <vulkan/vulkan_core.h> - -#include <span> - -#include "freelist.hpp" - -using VmaAllocation = struct VmaAllocation_T*; - -enum class QueueType : uint32_t { - GRAPHICS, - ASYNC_COMPUTE, - TRANSFER, - MAX, -}; - -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; - VkImage vk_image = nullptr; - const char* name = nullptr; - - static constexpr auto max_mips = 16U; -}; - -struct device_texture { - void init(const texture_desc& desc); - - void release(); - - void create_views(); - - [[nodiscard]] uint32_t get_storage_index() const { - assert(storage_index.id != handle<void>::invalid_id); - return storage_index.id; - } - - [[nodiscard]] uint32_t get_sampled_index() const { - assert(sampled_index.id != handle<void>::invalid_id); - return sampled_index.id; - } - - VkImage vk_image = nullptr; - VkImageView whole_view = nullptr; - 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 = VK_FORMAT_UNDEFINED; - VkImageAspectFlags aspects = VK_IMAGE_ASPECT_NONE_KHR; - - uint32_t width = 1U; - uint32_t height = 1U; - uint32_t depth = 1U; - uint32_t mips = 1U; - - private: - handle<void> storage_index; - handle<void> sampled_index; - - VmaAllocation alloc = nullptr; - - static idlist<> storage_indices; - static idlist<> sampled_indices; -}; - - -struct sampler_desc { - VkFilter mag_filter = VK_FILTER_NEAREST; - VkFilter min_filter = VK_FILTER_NEAREST; - VkSamplerMipmapMode mipmap_mode = VK_SAMPLER_MIPMAP_MODE_NEAREST; - VkSamplerAddressMode address_mode_u = VK_SAMPLER_ADDRESS_MODE_REPEAT; - VkSamplerAddressMode address_mode_v = VK_SAMPLER_ADDRESS_MODE_REPEAT; - VkSamplerAddressMode address_mode_w = VK_SAMPLER_ADDRESS_MODE_REPEAT; - float mip_lod_bias = 0.f; - VkBool32 anisotropy = VK_FALSE; - float max_anisotropy = 0.f; - VkBool32 compare_enabled = VK_FALSE; - VkCompareOp compare_op = VK_COMPARE_OP_NEVER; - float min_lod = 0.f; - float max_lod = 0.f; - VkBorderColor border_color = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK; - VkBool32 unnomalized_coords = VK_FALSE; -}; - -struct device_sampler { - void init(const sampler_desc& desc); - - VkSampler vk_sampler = nullptr; - - [[nodiscard]] uint32_t get_sampler_index() const { - return sampler_index.id; - } - - private: - handle<void> sampler_index; - - static idlist<> sampler_indices; -}; - - -struct buffer_desc { - size_t size; - VkBufferUsageFlags usages; - VkMemoryPropertyFlags memory_properties; - uint32_t memory_usage; -}; - -#define ALIGN(value, alignment) \ - (((value) + ((alignment) - 1)) & ~((alignment) - 1)) - -struct device_buffer { - template<typename T> - T* allocate() { - // size_t alloc_size = (sizeof(T) + 0x100) & 0xffffff00; - size_t alloc_size = ALIGN(sizeof(T), 16); - if (offset + alloc_size > size) { - reset(); - } - - auto* addr = (T*)(static_cast<uint8_t*>(mapped_ptr) + offset); - offset += alloc_size; - return addr; - } - - void* allocate(uint64_t alloc_size) { - // size_t alloc_size = (sizeof(T) + 0x100) & 0xffffff00; - alloc_size = ALIGN(alloc_size, 16); - if (offset + alloc_size > size) { - reset(); - } - - auto* addr = (void*)(static_cast<uint8_t*>(mapped_ptr) + offset); - offset += alloc_size; - return addr; - } - - void reset() { - offset = 0U; - } - - uint64_t offset = 0U; - VkBuffer vk_buffer; - VmaAllocation alloc; - VkDeviceAddress device_address = 0U; - void* mapped_ptr; - size_t size; -}; - -struct graphics_pipeline_desc { - 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; - const char* name; -}; - -struct compute_pipeline_desc { - std::span<uint8_t> cs_code; - const char* name; -}; - -struct device_pipeline { - VkPipeline vk_pipeline; - VkPipelineBindPoint bind_point; -}; - -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; - VkSurfaceFormatKHR surface_format; - - handle<device_texture> swapchain_images[surface_desc::max_image_count]; - uint32_t image_index; - uint32_t image_count; - uint32_t frame_index = 0U; - - handle<device_semaphore> acquire_semaphores[surface_desc::max_image_count]; - handle<device_semaphore> submit_semaphores[surface_desc::max_image_count]; - - uint32_t acquire_image_index(); -}; diff --git a/include/api-test/vk-device.hpp b/include/api-test/vk-device.hpp deleted file mode 100644 index 1b04bb3..0000000 --- a/include/api-test/vk-device.hpp +++ /dev/null @@ -1,161 +0,0 @@ -#pragma once - -#include <cstdint> -#include <span> - -#include <vulkan/vulkan_core.h> - -#include "freelist.hpp" -#include "vk-device-types.hpp" -#include "vk-bindless.hpp" - -using VmaAllocator = struct VmaAllocator_T*; - -struct command_buffer; -class window; - -class vkdevice { - struct queue { - VkQueue vk_queue; - uint32_t index; - VkQueueFlags usages; - VkCommandPool command_pool; - }; - - public: - void init(); - void deinit(); - - static inline vkdevice& get_render_device() { - return render_device; - } - - handle<device_texture> create_texture(const texture_desc& desc); - - handle<device_sampler> create_sampler(const sampler_desc& desc); - - handle<device_buffer> create_buffer(const buffer_desc& desc); - - handle<device_pipeline> create_graphics_pipeline(const graphics_pipeline_desc& desc); - - handle<device_pipeline> create_compute_pipeline(const compute_pipeline_desc& desc); - - handle<device_surface> create_surface(const surface_desc& desc); - - handle<device_semaphore> create_semaphore(const semaphore_desc& desc, const char* name); - - void destroy_texture(handle<device_texture> handle); - - void destroy_sampler(handle<device_sampler> handle); - - void destroy_buffer(handle<device_buffer> handle); - - void destroy_pipeline(handle<device_pipeline> handle); - - void destroy_semaphore(handle<device_semaphore> handle); - - void destroy_surface(handle<device_surface> handle); - - template<typename buffer_type> - void allocate_command_buffers(buffer_type* buffers, size_t count, QueueType queue_type, const char* name) { - allocate_command_buffers(static_cast<command_buffer*>(buffers), count, queue_type, name); - } - - [[nodiscard]] inline device_texture& get_texture(handle<device_texture> handle) { - return textures[handle]; - } - - [[nodiscard]] inline device_sampler& get_sampler(handle<device_sampler> handle) { - return samplers[handle]; - } - - [[nodiscard]] inline device_buffer& get_buffer(handle<device_buffer> handle) { - return buffers[handle]; - } - - [[nodiscard]] inline const device_pipeline& get_pipeline(handle<device_pipeline> handle) const { - return pipelines[handle]; - } - - [[nodiscard]] inline device_surface& get_surface(handle<device_surface> handle) { - return surfaces[handle]; - } - - [[nodiscard]] inline device_semaphore& get_semaphore(handle<device_semaphore> handle) { - return semaphores[handle]; - } - - [[nodiscard]] inline const bindless_model& get_bindingmodel() const { - return bindless; - } - - inline VkDevice get_device() { - return device; - } - - inline VmaAllocator get_allocator() { - return gpu_allocator; - } - - // uint64_t submit(std::span<command_buffer> buffers, handle<device_semaphore> wait_handle, handle<device_semaphore> signal_handle, handle<device_semaphore> fence_handle); - uint32_t acquire_image_index(handle<device_surface> surface_handle); - uint64_t submit_before_present(handle<device_surface> surface_handle, command_buffer* buffers, uint32_t count); - uint64_t submit(command_buffer* buffers, uint32_t count); - - void present(handle<device_surface> surface_handle); - - void wait(); - - private: - vkdevice() = default; - ~vkdevice() = default; - - void allocate_command_buffers(command_buffer* buffers, size_t count, QueueType type, const char* name); - - VkShaderModule create_shader_module(const std::span<uint8_t>& shader_code); - - 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_memory_allocator(); - - void create_command_pools(); - - void pick_physical_device(); - - static bool device_support_features(VkPhysicalDevice physical_dev); - - void create_debug_layer_callback(); - - queue queues[static_cast<uint32_t>(QueueType::MAX)]; - - VkInstance instance; - VkPhysicalDevice physical_device; - VkDevice device; - - VmaAllocator gpu_allocator; - - bindless_model bindless; - - static constexpr size_t max_allocable_command_buffers = 16; - static constexpr size_t max_submitable_command_buffers = 16; - - freelist<device_texture> textures; - freelist<device_sampler> samplers; - freelist<device_buffer> buffers; - freelist<device_pipeline> pipelines; - freelist<device_surface> surfaces; - freelist<device_semaphore> semaphores; - - device_semaphore timeline_semaphore; - - static vkdevice render_device; - -#ifdef _DEBUG - VkDebugUtilsMessengerEXT debug_messenger; -#endif // _DEBUG -}; diff --git a/include/api-test/vk-utils.hpp b/include/api-test/vk-utils.hpp deleted file mode 100644 index 205e103..0000000 --- a/include/api-test/vk-utils.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#pragma once - -#include <cassert> - -#include <vulkan/vulkan_core.h> - -#ifdef _DEBUG -#define VKCHECK(result) assert((result) == VK_SUCCESS) -#else -#define VKCHECK(result) result -#endif - -VKAPI_ATTR VkBool32 VKAPI_CALL debug_callback(VkDebugUtilsMessageSeverityFlagBitsEXT severity, - VkDebugUtilsMessageTypeFlagsEXT type, - const VkDebugUtilsMessengerCallbackDataEXT* data, - void*); |
