aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/api-test/command-buffer.hpp35
-rw-r--r--include/api-test/handle.hpp2
-rw-r--r--include/api-test/vk-bindless.hpp24
-rw-r--r--include/api-test/vk-device-types.hpp92
-rw-r--r--include/api-test/vk-device.hpp72
5 files changed, 181 insertions, 44 deletions
diff --git a/include/api-test/command-buffer.hpp b/include/api-test/command-buffer.hpp
index f7a18b0..d26fa13 100644
--- a/include/api-test/command-buffer.hpp
+++ b/include/api-test/command-buffer.hpp
@@ -22,10 +22,22 @@ 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;
- uint32_t uniforms_offset;
+ uint64_t params[static_cast<uint32_t>(PARAM_BINDING::MAX)];
};
struct renderpass_params {
@@ -41,14 +53,30 @@ 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;
- uint32_t uniforms_offset;
+ 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 {
@@ -68,7 +96,8 @@ struct graphics_command_buffer: public command_buffer {
void dispatch(const dispatch_params& params) const;
void begin_renderpass(const renderpass_params& params) const;
- void render(const draw_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/handle.hpp b/include/api-test/handle.hpp
index 72c46a2..f07776b 100644
--- a/include/api-test/handle.hpp
+++ b/include/api-test/handle.hpp
@@ -19,4 +19,6 @@ struct handle {
[[nodiscard]] inline bool is_valid() const { return id != handle::invalid_id; }
static constexpr uint32_t invalid_id = -1U;
+
+ // static constexpr handle<U> invalid_handle {};
};
diff --git a/include/api-test/vk-bindless.hpp b/include/api-test/vk-bindless.hpp
index 7b8eccc..a5686ff 100644
--- a/include/api-test/vk-bindless.hpp
+++ b/include/api-test/vk-bindless.hpp
@@ -13,6 +13,13 @@ enum BindlessSetType : uint32_t {
MAX,
};
+enum ConstantType : uint32_t {
+ GLOBALS,
+ INSTANCES,
+ DRAWS,
+ VERTEX_BUFFER
+};
+
enum SamplerType : uint32_t {
NEAREST,
LINEAR,
@@ -22,19 +29,29 @@ enum SamplerType : uint32_t {
struct device_buffer;
struct bindless_model {
-#ifndef USE_VK_DESCRIPTOR_BUFFERS
- [[nodiscard]] const device_buffer& get_uniform_buffer() const;
+#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 layout;
+ 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;
@@ -53,6 +70,7 @@ private:
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
diff --git a/include/api-test/vk-device-types.hpp b/include/api-test/vk-device-types.hpp
index 3085e29..994f0c4 100644
--- a/include/api-test/vk-device-types.hpp
+++ b/include/api-test/vk-device-types.hpp
@@ -29,10 +29,12 @@ struct device_texture {
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;
}
@@ -60,6 +62,41 @@ struct device_texture {
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;
@@ -68,6 +105,35 @@ struct buffer_desc {
};
struct device_buffer {
+ template<typename T>
+ T* allocate() {
+ // size_t alloc_size = (sizeof(T) + 0x100) & 0xffffff00;
+ size_t alloc_size = sizeof(T);
+ 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;
+ 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;
+ }
+
+ uint32_t offset = 0U;
VkBuffer vk_buffer;
VmaAllocation alloc;
VkDeviceAddress device_address = 0U;
@@ -75,8 +141,7 @@ struct device_buffer {
size_t size;
};
-struct pipeline_desc {
- std::span<uint8_t> cs_code;
+struct graphics_pipeline_desc {
std::span<uint8_t> vs_code;
std::span<uint8_t> fs_code;
std::span<VkFormat> color_attachments_format;
@@ -84,6 +149,10 @@ struct pipeline_desc {
VkFormat stencil_attachment_format;
};
+struct compute_pipeline_desc {
+ std::span<uint8_t> cs_code;
+};
+
struct device_pipeline {
VkPipeline vk_pipeline;
VkPipelineBindPoint bind_point;
@@ -114,14 +183,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;
+ handle<device_semaphore> acquire_semaphores[surface_desc::max_image_count];
+ handle<device_semaphore> submit_semaphores[surface_desc::max_image_count];
- void acquire_image_index(handle<device_semaphore> signal_handle);
- handle<device_texture> get_backbuffer_image() const;
+ uint32_t acquire_image_index();
};
diff --git a/include/api-test/vk-device.hpp b/include/api-test/vk-device.hpp
index 1ece366..7f86cbb 100644
--- a/include/api-test/vk-device.hpp
+++ b/include/api-test/vk-device.hpp
@@ -31,9 +31,13 @@ class vkdevice {
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_pipeline(const pipeline_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);
@@ -41,6 +45,8 @@ class vkdevice {
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);
@@ -49,16 +55,20 @@ class vkdevice {
void destroy_surface(handle<device_surface> handle);
- template<typename array_type>
- void allocate_command_buffers(array_type& buffers, QueueType queue_type) {
- allocate_command_buffers(static_cast<command_buffer*>(buffers.data()), buffers.size(), queue_type);
+ template<typename buffer_type>
+ void allocate_command_buffers(buffer_type* buffers, size_t count, QueueType queue_type) {
+ allocate_command_buffers(static_cast<command_buffer*>(buffers), count, queue_type);
}
[[nodiscard]] inline device_texture& get_texture(handle<device_texture> handle) {
return textures[handle];
}
- [[nodiscard]] inline const device_buffer& get_buffer(handle<device_buffer> handle) const {
+ [[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];
}
@@ -86,11 +96,14 @@ class vkdevice {
return gpu_allocator;
}
- void wait(handle<device_semaphore> semaphore_handle);
+ // 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);
+ uint32_t submit_before_present(handle<device_surface> surface_handle, command_buffer* buffers, uint32_t count);
+ uint32_t submit(command_buffer* buffers, uint32_t count);
- void submit(std::span<command_buffer> buffers, handle<device_semaphore> wait_handle, handle<device_semaphore> signal_handle);
+ void present(handle<device_surface> surface_handle);
- void present(handle<device_surface> surface_handle, handle<device_semaphore> semaphore_handle);
+ void wait();
private:
vkdevice() = default;
@@ -103,38 +116,41 @@ class vkdevice {
void create_swapchain(const surface_desc& desc, device_surface& surface);
// TODO: Wrap in a struct called adapter ?
- void create_instance();
+ void create_instance();
+
+ void create_device();
- void create_device();
+ void create_memory_allocator();
- void create_memory_allocator();
+ void create_command_pools();
- void create_command_pools();
+ void pick_physical_device();
- void pick_physical_device();
+ static bool device_support_features(VkPhysicalDevice physical_dev);
- static bool device_support_features(VkPhysicalDevice physical_dev);
+ void create_debug_layer_callback();
- 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> textures;
+ freelist<device_sampler> samplers;
+ freelist<device_buffer> buffers;
+ freelist<device_pipeline> pipelines;
+ freelist<device_surface> surfaces;
+ freelist<device_semaphore> semaphores;
- freelist<device_texture> textures;
- freelist<device_buffer> buffers;
- freelist<device_pipeline> pipelines;
- freelist<device_surface> surfaces;
- freelist<device_semaphore> semaphores;
+ device_semaphore timeline_semaphore;
static vkdevice render_device;