diff options
| author | ladevieq <ladevie.quentin@gmail.com> | 2026-08-17 02:20:13 +0200 |
|---|---|---|
| committer | ladevieq <ladevie.quentin@gmail.com> | 2026-08-17 02:20:13 +0200 |
| commit | 782741f0fea5b2a95aed9ad3673ecafb4b164885 (patch) | |
| tree | 7e381783dc52fc54eba8d4850b05ea759c5eab11 /include | |
| parent | 92e09dc06f8c8dd5b7a9323d586f4bf642078727 (diff) | |
Inital work on vulkan descriptor heap implementation
Diffstat (limited to 'include')
| -rw-r--r-- | include/vk-bindless.hpp | 2 | ||||
| -rw-r--r-- | include/vk-command-buffer.hpp | 11 | ||||
| -rw-r--r-- | include/vk-device-types.hpp | 21 | ||||
| -rw-r--r-- | include/vk-device.hpp | 67 | ||||
| -rw-r--r-- | include/vulkan-loader.hpp | 6 |
5 files changed, 49 insertions, 58 deletions
diff --git a/include/vk-bindless.hpp b/include/vk-bindless.hpp index 008e420..be076b8 100644 --- a/include/vk-bindless.hpp +++ b/include/vk-bindless.hpp @@ -20,7 +20,7 @@ enum SamplerType : uint32_t { struct device_buffer; struct bindless_model { - [[nodiscard]] device_buffer& get_uniform_buffer(enum UniformTypes type) const; + [[nodiscard]] device_buffer* get_uniform_buffer(enum UniformTypes type) const; void init(); diff --git a/include/vk-command-buffer.hpp b/include/vk-command-buffer.hpp index 82d5439..f82e52f 100644 --- a/include/vk-command-buffer.hpp +++ b/include/vk-command-buffer.hpp @@ -25,7 +25,8 @@ private: public: rect render_area; - std::span<handle<device_texture>> color_attachments; + handle<device_texture>* color_attachments; + size_t color_attachments_count; }; struct draw_params { @@ -55,15 +56,17 @@ struct command_buffer { VkCommandBuffer vk_command_buffer; QueueType queue_type; + + // TODO: Add relevant fields in order to bind heaps }; // General purpose queue struct graphics_command_buffer: public command_buffer { - void dispatch(const dispatch_params& params) const; + void dispatch(const dispatch_params& params, const void* data, size_t size) 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 draw(const draw_params& params, const void* data, size_t size) const; + void draw_indexed(const draw_indexed_params& params, const void* data, size_t size) const; void end_renderpass() const; }; diff --git a/include/vk-device-types.hpp b/include/vk-device-types.hpp index f77d2af..25f933f 100644 --- a/include/vk-device-types.hpp +++ b/include/vk-device-types.hpp @@ -160,7 +160,8 @@ struct graphics_pipeline_desc { size_t vs_code_size; uint8_t* fs_code; size_t fs_code_size; - std::span<VkFormat> color_attachments_format; + VkFormat* color_attachments_format; + size_t color_attachments_format_count; VkFormat depth_attachment_format; VkFormat stencil_attachment_format; const char* name; @@ -202,17 +203,17 @@ struct surface_desc { }; struct device_surface { - VkSurfaceKHR vk_surface; - VkSwapchainKHR vk_swapchain; - VkSurfaceFormatKHR surface_format; + 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_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]; + device_semaphore acquire_semaphores[surface_desc::max_image_count]; + device_semaphore submit_semaphores[surface_desc::max_image_count]; uint32_t acquire_image_index(); }; diff --git a/include/vk-device.hpp b/include/vk-device.hpp index e2e8c99..84a1a36 100644 --- a/include/vk-device.hpp +++ b/include/vk-device.hpp @@ -37,8 +37,6 @@ class vkdevice { 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); @@ -47,8 +45,6 @@ class vkdevice { 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> @@ -56,50 +52,34 @@ class vkdevice { 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 device_texture* get_texture(handle<device_texture> handle) { + return &textures[handle]; } - [[nodiscard]] inline const device_pipeline& get_pipeline(handle<device_pipeline> handle) const { - return pipelines[handle]; + [[nodiscard]] inline device_sampler* get_sampler(handle<device_sampler> handle) { + return &samplers[handle]; } - [[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_semaphore& get_semaphore(handle<device_semaphore> handle) { - return semaphores[handle]; + [[nodiscard]] inline const device_pipeline* get_pipeline(handle<device_pipeline> handle) const { + return &pipelines[handle]; } - [[nodiscard]] inline const bindless_model& get_bindingmodel() const { - return bindless; + [[nodiscard]] inline device_surface* get_surface(handle<device_surface> handle) { + return &surfaces[handle]; } - const freelist<device_texture>& get_textures() const { - return textures; + inline VmaAllocator get_allocator() const { + return gpu_allocator; } inline VkDevice get_device() const { return device; } - inline VmaAllocator get_allocator() { - return gpu_allocator; - } - - inline const VkPhysicalDeviceLimits& get_device_limits() const { - return physical_device_props.properties.limits; - } - // 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); @@ -109,6 +89,8 @@ class vkdevice { void wait(); + void wait_for_fence(u64 value); + private: vkdevice() = default; ~vkdevice() = default; @@ -122,16 +104,10 @@ class vkdevice { void create_device(); - void create_memory_allocator(); - - void create_command_pools(); - - void pick_physical_device(); + void create_heaps(VkPhysicalDeviceDescriptorHeapPropertiesEXT& descriptor_heap_props); bool device_support_features(VkPhysicalDevice physical_dev); - void create_debug_layer_callback(); - queue queues[static_cast<uint32_t>(QueueType::MAX)]; VkInstance instance; @@ -139,9 +115,15 @@ class vkdevice { VkPhysicalDeviceProperties2 physical_device_props; VkDevice device; - VmaAllocator gpu_allocator; + handle<device_buffer> image_heap; // TODO: Dont use handle for internally used resources + handle<device_buffer> sampler_heap; + + static constexpr size_t max_images_count = UINT16_MAX; + static constexpr size_t max_samplers_count = 16U; - bindless_model bindless; + static size_t + + VmaAllocator gpu_allocator; static constexpr size_t max_allocable_command_buffers = 16; static constexpr size_t max_submitable_command_buffers = 16; @@ -151,9 +133,8 @@ class vkdevice { freelist<device_buffer> buffers; freelist<device_pipeline> pipelines; freelist<device_surface> surfaces; - freelist<device_semaphore> semaphores; - device_semaphore timeline_semaphore; + device_semaphore fence; static vkdevice render_device; diff --git a/include/vulkan-loader.hpp b/include/vulkan-loader.hpp index 7a3a68e..3d9237b 100644 --- a/include/vulkan-loader.hpp +++ b/include/vulkan-loader.hpp @@ -5,6 +5,7 @@ #if _WIN32 #include <vulkan/vulkan_core.h> +#define VULKAN_H_ 1 // Fake vulkan.h include typedef unsigned long DWORD; typedef const wchar_t* LPCWSTR; typedef void* HANDLE; @@ -90,6 +91,7 @@ typedef struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES; X(vkCmdPipelineBarrier) \ X(vkCmdPipelineBarrier2) \ X(vkCmdPushConstants) \ + X(vkCmdPushDataEXT) \ X(vkCmdClearColorImage) \ X(vkCmdBeginRenderPass) \ X(vkCmdBeginRendering) \ @@ -97,6 +99,8 @@ typedef struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES; X(vkCmdBindVertexBuffers) \ X(vkCmdBindIndexBuffer) \ X(vkCmdBindDescriptorSets) \ + X(vkCmdBindResourceHeapEXT) \ + X(vkCmdBindSamplerHeapEXT) \ X(vkCmdSetViewport) \ X(vkCmdSetScissor) \ X(vkCmdCopyBuffer) \ @@ -125,6 +129,8 @@ typedef struct _SECURITY_ATTRIBUTES SECURITY_ATTRIBUTES; X(vkCreateDescriptorPool) \ X(vkAllocateDescriptorSets) \ X(vkUpdateDescriptorSets) \ + X(vkWriteResourceDescriptorsEXT) \ + X(vkWriteSamplerDescriptorsEXT) \ X(vkGetBufferDeviceAddress) \ X(vkGetBufferMemoryRequirements) \ X(vkGetImageMemoryRequirements) \ |
