aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/api-test/handle.hpp24
-rw-r--r--include/api-test/resource-manager.hpp22
-rw-r--r--include/api-test/texture.hpp17
-rw-r--r--include/api-test/vk-bindless.hpp93
-rw-r--r--include/buffer.hpp (renamed from include/api-test/buffer.hpp)0
-rw-r--r--include/bvh-node.hpp320
-rw-r--r--include/compute-renderpass.hpp41
-rw-r--r--include/dx12-command-buffer.hpp (renamed from include/api-test/dx12-command-buffer.hpp)0
-rw-r--r--include/dx12-device-types.hpp (renamed from include/api-test/dx12-device-types.hpp)0
-rw-r--r--include/dx12-device.hpp (renamed from include/api-test/dx12-device.hpp)0
-rw-r--r--include/freelist.hpp (renamed from include/api-test/freelist.hpp)39
-rw-r--r--include/handle.hpp13
-rw-r--r--include/primitive-renderpass.hpp93
-rw-r--r--include/renderpass.hpp22
-rw-r--r--include/texture.hpp86
-rw-r--r--include/vk-api.hpp219
-rw-r--r--include/vk-bindless.hpp49
-rw-r--r--include/vk-command-buffer.hpp (renamed from include/api-test/vk-command-buffer.hpp)30
-rw-r--r--include/vk-context.hpp49
-rw-r--r--include/vk-device-types.hpp (renamed from include/api-test/vk-device-types.hpp)57
-rw-r--r--include/vk-device.hpp (renamed from include/api-test/vk-device.hpp)30
-rw-r--r--include/vk-renderer.hpp164
-rw-r--r--include/vk-utils.hpp (renamed from include/api-test/vk-utils.hpp)6
23 files changed, 144 insertions, 1230 deletions
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/buffer.hpp b/include/buffer.hpp
index 64c4881..64c4881 100644
--- a/include/api-test/buffer.hpp
+++ b/include/buffer.hpp
diff --git a/include/bvh-node.hpp b/include/bvh-node.hpp
deleted file mode 100644
index 525e1c8..0000000
--- a/include/bvh-node.hpp
+++ /dev/null
@@ -1,320 +0,0 @@
-#ifndef __BVH_NODE_HPP_
-#define __BVH_NODE_HPP_
-
-#include <vector>
-#include <algorithm>
-#include <iostream>
-
-#include "aabb.hpp"
-// #include "sphere.hpp"
-#include "triangle.hpp"
-
-struct bvh_node {
- aabb bounding_box;
-
- int32_t next_id = -1;
- int32_t primitive_id = -1;
- uint32_t padding[2];
-};
-
-struct packed_bvh_node {
- float min[3];
- int32_t next_id = -1;
- float max[3];
- int32_t primitive_id = -1;
-};
-
-struct temp_node : public bvh_node {
- int32_t left_id;
- int32_t df_id;
-};
-
-class bvh {
-public:
- // bvh(std::vector<sphere>& spheres, std::vector<packed_bvh_node>& packed_nodes)
- // :spheres(spheres) {
- // packed_nodes.resize(2 * spheres.size() - 1);
- // temp_nodes = std::vector<temp_node>(2 * spheres.size() - 1);
- // leafs = std::vector<temp_node>(spheres.size());
-
- // for (uint32_t id = 0; id < spheres.size(); id++) {
- // leafs[id].bounding_box = aabb(spheres[id].center, spheres[id].radius);
- // leafs[id].primitive_id = id;
- // }
-
- // temp_nodes[0] = temp_node();
-
- // temp_nodes[0].bounding_box = compute_bounds(0, spheres.size());
- // subdivide(0, 0, spheres.size());
-
- // set_depth_first_order();
-
- // for (uint32_t id = 0; id < temp_nodes.size(); id++) {
- // auto old_node = temp_nodes[id];
- // auto &node = packed_nodes[old_node.df_id];
-
- // node.primitive_id = old_node.primitive_id;
-
- // node.min[0] = old_node.bounding_box.minimum.v[0];
- // node.min[1] = old_node.bounding_box.minimum.v[1];
- // node.min[2] = old_node.bounding_box.minimum.v[2];
-
- // node.max[0] = old_node.bounding_box.maximum.v[0];
- // node.max[1] = old_node.bounding_box.maximum.v[1];
- // node.max[2] = old_node.bounding_box.maximum.v[2];
-
- // if (old_node.next_id != -1) {
- // node.next_id = temp_nodes[old_node.next_id].df_id;
- // }
- // }
-
- // // exporter();
- // }
-
- bvh(std::vector<triangle>& triangles, std::vector<packed_bvh_node>& packed_nodes)
- :triangles(triangles) {
- packed_nodes.resize(2 * triangles.size() - 1);
- temp_nodes = std::vector<temp_node>(2 * triangles.size() - 1);
- leafs = std::vector<temp_node>(triangles.size());
-
- for (uint32_t id = 0; id < triangles.size(); id++) {
- leafs[id].bounding_box = aabb(triangles[id]);
- leafs[id].primitive_id = id;
- }
-
- temp_nodes[0] = temp_node();
-
- temp_nodes[0].bounding_box = compute_bounds(0, triangles.size());
- subdivide(0, 0, triangles.size());
-
- set_depth_first_order();
-
- for (uint32_t id = 0; id < temp_nodes.size(); id++) {
- auto old_node = temp_nodes[id];
- auto &node = packed_nodes[old_node.df_id];
-
- node.primitive_id = old_node.primitive_id;
-
- node.min[0] = old_node.bounding_box.minimum.v[0];
- node.min[1] = old_node.bounding_box.minimum.v[1];
- node.min[2] = old_node.bounding_box.minimum.v[2];
-
- node.max[0] = old_node.bounding_box.maximum.v[0];
- node.max[1] = old_node.bounding_box.maximum.v[1];
- node.max[2] = old_node.bounding_box.maximum.v[2];
-
- if (old_node.next_id != -1) {
- node.next_id = temp_nodes[old_node.next_id].df_id;
- }
- }
-
- // exporter();
- }
-
- //-------------------------
- // BVH exporter for graphviz
- //-------------------------
- void exporter() {
- std::cout << "digraph bvh {" << std::endl;
-
- traverse_depth_first(temp_nodes, 0);
-
- // traverse_depth_first_ordered(-1, 0);
-
- std::cout << "}" << std::endl;
- }
-
- bool traverse_depth_first(std::vector<temp_node>& nodes, int32_t id) {
- if (id <= 0) {
- std::cout << ";" << std::endl;
- return false;
- }
-
- std::cout << " -> " << id;
- if (traverse_depth_first(nodes, nodes[id].left_id)) {
- std::cout << "\t " << id;
- traverse_depth_first(nodes, nodes[id].left_id + 1);
- }
-
- return true;
- }
-
- int32_t traverse_depth_first_ordered(std::vector<bvh_node>& nodes, int32_t parent_id, int32_t id) {
- if (id == -1) {
- return -1;
- }
-
- if (nodes[id].primitive_id == -1) {
- int32_t left = id + 1;
- int32_t next_id;
-
- std::cout << "\t " << parent_id << " -> " << id << ";\n";
- next_id = traverse_depth_first_ordered(nodes, id, left);
-
- if (next_id != -1) {
- return traverse_depth_first_ordered(nodes, id, next_id);
- }
- } else if (nodes[id].primitive_id != -1 && nodes[id].next_id != -1) {
- std::cout << "\t " << parent_id << " -> " << id << ";\n";
- return nodes[id].next_id;
- } else {
- std::cout << "\t " << parent_id << " -> " << id << ";\n";
- }
-
- return -1;
- }
-
- std::vector<temp_node> temp_nodes;
- std::vector<temp_node> leafs;
-
- // std::vector<sphere>& spheres;
- std::vector<triangle>& triangles;
-
- uint32_t next_node_id = 0;
-
-private:
-
- static constexpr uint32_t buckets_count = 12;
-
- aabb compute_bounds(uint32_t begin, uint32_t end) {
- aabb global_box = aabb();
-
- for (uint32_t id = begin; id < end; id++) {
- global_box.union_with(leafs[id].bounding_box);
- }
-
- return global_box;
- }
-
- void subdivide(uint32_t parent_id, uint32_t begin, uint32_t end) {
- size_t count = end - begin;
- if (count == 1) {
- temp_nodes[parent_id] = leafs[begin];
- return;
- }
-
- auto left_id = ++next_node_id;
- auto right_id = ++next_node_id;
-
- temp_nodes[parent_id].left_id = left_id;
-
- if (count == 2) {
- temp_nodes[left_id] = leafs[begin];
- temp_nodes[right_id] = leafs[begin + 1];
- } else {
- auto parent_bb = temp_nodes[parent_id].bounding_box;
- int32_t split_axis = parent_bb.maximum_axis();
-
- if (count <= 4) {
- // Subdivide the node by splitting the set in two equal parts
- std::sort(leafs.begin() + begin, leafs.begin() + end,
- // [&](const bvh_node& a, const bvh_node& b) {
- // return spheres[a.primitive_id].center[split_axis] < spheres[b.primitive_id].center[split_axis];
- // }
- [&](const bvh_node& a, const bvh_node& b) {
- return triangles[a.primitive_id].center()[split_axis] < triangles[b.primitive_id].center()[split_axis];
- }
- );
-
- temp_nodes[left_id].bounding_box = compute_bounds(begin, begin + (count / 2));
- temp_nodes[right_id].bounding_box = compute_bounds(begin + (count / 2), end);
-
- subdivide(left_id, begin, begin + (count / 2));
- subdivide(right_id, begin + (count / 2), end);
- } else {
- // Subdivide based on SAH
- struct Bucket {
- uint32_t count = 0;
- aabb bb;
- };
- Bucket buckets[buckets_count];
-
- // Split the set in N spatial buckets
- // Simplify the optimal split axis search to just an axis between each bucket
- aabb centroid_bounds;
-
- for (size_t i = begin; i < end; i++) {
- auto primitive = triangles[leafs[i].primitive_id];
- centroid_bounds.union_with(primitive.center());
- // auto primitive = spheres[leafs[i].primitive_id];
- // centroid_bounds.union_with(primitive.center);
- }
-
- float split_axis_size = centroid_bounds.maximum[split_axis] - centroid_bounds.minimum[split_axis];
- for (size_t i = begin; i < end; i++) {
- auto primitive = triangles[leafs[i].primitive_id];
- auto normalized_offset = (primitive.center()[split_axis] - centroid_bounds.minimum[split_axis]) / split_axis_size;
- // auto primitive = spheres[leafs[i].primitive_id];
- // auto normalized_offset = (primitive.center[split_axis] - centroid_bounds.minimum[split_axis]) / split_axis_size;
- uint32_t bucket_index = normalized_offset * buckets_count;
- if (bucket_index == buckets_count) {
- bucket_index -= 1;
- }
-
- buckets[bucket_index].count++;
- buckets[bucket_index].bb.union_with(leafs[i].bounding_box);
- }
-
- // Compute each potential split axis cost
- float buckets_cost[buckets_count - 1] = { 0.f };
- for (size_t bucket_index = 0; bucket_index < buckets_count - 1; bucket_index++) {
- aabb right_side_bb, left_side_bb;
- float right_side_count = 0, left_side_count = 0;
-
- for (size_t i = 0; i <= bucket_index; i++) {
- left_side_bb.union_with(buckets[i].bb);
- left_side_count += buckets[i].count;
- }
-
- for (size_t i = bucket_index + 1; i < buckets_count; i++) {
- right_side_bb.union_with(buckets[i].bb);
- right_side_count += buckets[i].count;
- }
-
- float left = left_side_count * left_side_bb.surface_area();
- float right = right_side_count * right_side_bb.surface_area();
- buckets_cost[bucket_index] = 0.125f + (left + right) / parent_bb.surface_area();
- }
-
- float min_cost = buckets_cost[0];
- uint32_t min_cost_bucket = 0;
- for (size_t bucket_index = 1; bucket_index < buckets_count - 1; bucket_index++) {
- if (buckets_cost[bucket_index] < min_cost) {
- min_cost = buckets_cost[bucket_index];
- min_cost_bucket = bucket_index;
- }
- }
-
- uint32_t middle_primitive_index = buckets[0].count;
- for (size_t bucket_index = 1; bucket_index <= min_cost_bucket; bucket_index++) {
- middle_primitive_index += buckets[bucket_index].count;
- }
-
- temp_nodes[left_id].bounding_box = compute_bounds(begin, begin + middle_primitive_index);
- temp_nodes[right_id].bounding_box = compute_bounds(begin + middle_primitive_index, end);
-
- subdivide(left_id, begin, begin + middle_primitive_index);
- subdivide(right_id, begin + middle_primitive_index, end);
- }
- }
- }
-
- void set_depth_first_order() {
- int32_t df_index = 0;
- depth_first_order(0, -1, df_index);
- }
-
-
- void depth_first_order(int32_t id, int32_t next_id, int32_t &new_id) {
- auto &node = temp_nodes[id];
- node.next_id = next_id;
- node.df_id = new_id++;
-
- if (node.left_id > 0) {
- depth_first_order(node.left_id, node.left_id + 1, new_id);
- depth_first_order(node.left_id + 1, next_id, new_id);
- }
- }
-};
-
-#endif // !__BVH_NODE_HPP_
diff --git a/include/compute-renderpass.hpp b/include/compute-renderpass.hpp
deleted file mode 100644
index 6799171..0000000
--- a/include/compute-renderpass.hpp
+++ /dev/null
@@ -1,41 +0,0 @@
-#pragma once
-
-#include "renderpass.hpp"
-#include "vk-api.hpp"
-
-class Texture;
-class Buffer;
-
-class ComputeRenderpass : public Renderpass {
- public:
-
- ComputeRenderpass(vkapi& api);
- ~ComputeRenderpass() override;
-
- void set_pipeline(const char* shader_name);
-
- void set_dispatch_size(size_t count_x, size_t count_y, size_t count_z);
-
- void set_ouput_texture(Texture* out_texture);
-
- void set_constant(off_t offset, uint64_t* constant);
- void set_constant(off_t offset, Texture* texture);
- void set_constant(off_t offset, Buffer* buffer);
-
- // TODO: Do not use vulkan api type
- void execute(vkrenderer& renderer, VkCommandBuffer command_buffer) final;
-
- Texture* output_texture;
-
- private:
-
- std::vector<Texture*> input_textures;
-
- uint8_t constants[64];
-
- size_t group_count_x;
- size_t group_count_y;
- size_t group_count_z;
-
- pipeline pipeline;
-};
diff --git a/include/api-test/dx12-command-buffer.hpp b/include/dx12-command-buffer.hpp
index e9de39a..e9de39a 100644
--- a/include/api-test/dx12-command-buffer.hpp
+++ b/include/dx12-command-buffer.hpp
diff --git a/include/api-test/dx12-device-types.hpp b/include/dx12-device-types.hpp
index 4b2fc42..4b2fc42 100644
--- a/include/api-test/dx12-device-types.hpp
+++ b/include/dx12-device-types.hpp
diff --git a/include/api-test/dx12-device.hpp b/include/dx12-device.hpp
index baa5b60..baa5b60 100644
--- a/include/api-test/dx12-device.hpp
+++ b/include/dx12-device.hpp
diff --git a/include/api-test/freelist.hpp b/include/freelist.hpp
index cbcd56d..2df1ca5 100644
--- a/include/api-test/freelist.hpp
+++ b/include/freelist.hpp
@@ -1,10 +1,9 @@
#pragma once
-#include <vector>
-#include <cassert>
+#include "utils.hpp"
#include "handle.hpp"
-static constexpr uint32_t default_element_count = 1024U;
+static constexpr u32 default_element_count = 1024U;
template<typename T, const size_t initial_size = default_element_count>
class freelist {
@@ -31,6 +30,8 @@ class freelist {
// elements[0U].next_free = element.next_free;
element.item = std::move(item);
+ assert(element.generation + 1 != UINT32_MAX);
+
return { id, ++element.generation };
}
@@ -54,9 +55,21 @@ class freelist {
static constexpr uint32_t invalid_id = UINT32_MAX;
+ struct element {
+ union {
+ T item;
+ uint32_t next_free = freelist<T>::invalid_id;
+ };
+ uint32_t generation = 0U;
+ };
+
+ const std::vector<freelist::element>& get_list() const {
+ return elements;
+ }
+
private:
void grow(size_t grow_size) {
- auto size = elements.size();
+ size_t size = elements.size();
uint32_t next_free = static_cast<uint32_t>(size);
next_free_id = next_free;
@@ -70,17 +83,11 @@ private:
);
}
+ // this makes it impossible to know
+ elements.back().next_free = freelist<T>::invalid_id;
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;
};
@@ -97,7 +104,7 @@ class idlist {
// auto id = elements[0U].next_free;
auto id = next_free_id;
- if (id == idlist<T>::invalid_id) {
+ if (id == idlist::invalid_id) {
grow(elements.size());
// id = elements[0U].next_free;
@@ -107,7 +114,7 @@ class idlist {
auto& element = elements[id];
next_free_id = element.next_free;
elements[0U].next_free = element.next_free;
- element.next_free = idlist<T>::invalid_id;
+ element.next_free = idlist::invalid_id;
return { id, ++element.generation };
}
@@ -138,11 +145,11 @@ private:
);
}
- elements.back().next_free = idlist<T>::invalid_id;
+ elements.back().next_free = idlist::invalid_id;
}
struct element {
- uint32_t next_free = idlist<T>::invalid_id;
+ uint32_t next_free = idlist::invalid_id;
uint32_t generation = 0U;
};
diff --git a/include/handle.hpp b/include/handle.hpp
new file mode 100644
index 0000000..484b217
--- /dev/null
+++ b/include/handle.hpp
@@ -0,0 +1,13 @@
+#pragma once
+
+#include <cstdint>
+
+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;
+};
diff --git a/include/primitive-renderpass.hpp b/include/primitive-renderpass.hpp
deleted file mode 100644
index 95562fe..0000000
--- a/include/primitive-renderpass.hpp
+++ /dev/null
@@ -1,93 +0,0 @@
-#pragma once
-
-#include <vector>
-
-#include "renderpass.hpp"
-#include "vk-renderer.hpp"
-
-class Buffer;
-class Texture;
-class Sampler;
-class Primitive;
-
-class PrimitiveRenderpass : public Renderpass {
- public:
-
- PrimitiveRenderpass(vkapi& api);
-
- void add_primitive(Primitive* new_primitive);
-
- void add_color_attachment(VkFormat format);
-
- void set_depth_stencil(Texture* depth_stencil);
-
- void set_viewport(float x, float y, float width, float height);
-
- void set_color_attachment(uint32_t index, Texture* attachment);
-
- void finalize_render_pass();
-
- void execute(vkrenderer& renderer, VkCommandBuffer command_buffer) final;
-
- VkRenderPass render_pass = VK_NULL_HANDLE;
-
- private:
-
- void create_framebuffers();
-
- void recreate_framebuffers();
-
- VkViewport viewport = { .minDepth = 0.f, .maxDepth = 1.f };
-
- std::vector<Texture*> color_attachments;
- std::vector<VkImageView> color_attachments_view;
- std::vector<VkFormat> color_attachments_format;
-
- framebuffer framebuffers[vkrenderer::virtual_frames_count];
-
- std::vector<Primitive*> primitives;
-};
-
-
-class Primitive {
- public:
-
- Primitive(PrimitiveRenderpass& render_pass);
-
- void set_pipeline(const char* shader_name);
-
- void set_constant_offset(off_t offset);
- void set_constant(off_t offset, uint64_t* constant);
- void set_constant(off_t offset, Texture* texture);
- void set_constant(off_t offset, Buffer* buffer);
- void set_constant(off_t offset, Sampler* sampler);
-
- void set_index_buffer(Buffer* buffer);
-
- void set_scissor(int32_t x, int32_t y, uint32_t width, uint32_t height);
-
- void set_draw_info(size_t vertex_count, off_t indices_off, off_t vertex_off);
-
- void render(VkCommandBuffer command_buffer);
-
-
-private:
-
- vkapi& api;
-
- PrimitiveRenderpass& primitive_render_pass;
-
- pipeline pipeline;
-
- Buffer* index_buffer;
-
- size_t element_count;
- off_t indices_offset;
- off_t vertex_offset;
-
- off_t constant_offset;
-
- VkRect2D scissor = {};
-
- uint8_t constants[64];
-};
diff --git a/include/renderpass.hpp b/include/renderpass.hpp
deleted file mode 100644
index da116dd..0000000
--- a/include/renderpass.hpp
+++ /dev/null
@@ -1,22 +0,0 @@
-#pragma once
-
-using VkCommandBuffer = struct VkCommandBuffer_T*;
-
-class vkrenderer;
-class vkapi;
-
-class Renderpass {
- public:
-
- Renderpass(vkapi& api)
- :api(api)
- {};
-
- virtual ~Renderpass() = default;
-
- // TODO: Do not use vulkan api type
- virtual void execute(vkrenderer& renderer, VkCommandBuffer command_buffer) = 0;
-
- protected:
- vkapi &api;
-};
diff --git a/include/texture.hpp b/include/texture.hpp
index aac7b69..59bfec1 100644
--- a/include/texture.hpp
+++ b/include/texture.hpp
@@ -1,83 +1,17 @@
-#include <cstdint>
-
-using VkImage = struct VkImage_T*;
-
-struct TextureDesc {
- VkImageType type;
- VkFormat format;
- VkExtent size;
- VkImageUsageFlags usages;
-};
-
-class Texture {
- public:
- Texture(const TextureDesc desc)
- : description(desc) {
- create_device_image();
- }
-
- // Texture(handle image_handle) {
- // const auto& image = vkrenderer::api.get_image(image_handle);
- // width = image.size.width;
- // height = image.size.height;
- // depth = image.size.depth;
-
- // device_image = image_handle;
- // }
-
- // Texture(size_t width, size_t height, size_t depth, VkFormat format = VK_FORMAT_R8G8B8A8_UNORM, Sampler* texture_sampler = nullptr)
- // : width(width), height(height), depth(depth) {
- // sampler = texture_sampler;
- // device_image = vkrenderer::api.create_image(
- // { .width = (uint32_t)width, .height = (uint32_t)height, .depth = 1 },
- // format,
- // VK_IMAGE_USAGE_STORAGE_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_SAMPLED_BIT);
- // }
+#pragma once
- void update(void* new_data) {
- if (data == nullptr) {
- free(data);
- }
- data = new_data;
-
- vkrenderer::queue_image_update(this);
- }
-
- ~Texture() {
- vkrenderer::api.destroy_image(device_image);
-
- if (data == nullptr) {
- free(data);
- }
- }
-
- [[nodiscard]] size_t size() const {
- const auto& image = vkrenderer::api.get_image(device_image);
- return width * height * depth * pixel_size(image.format);
- }
-
- static size_t pixel_size(VkFormat format) {
- switch (format) {
- case VK_FORMAT_R8G8B8A8_UNORM:
- return 4;
- default:
- return 0;
- }
- }
-
- // Sampler* sampler = nullptr;
+#include <cstdint>
- private:
- void create_device_image();
+#include <vulkan/vulkan_core.h>
- void* data = nullptr;
+#include "handle.hpp"
- size_t width = 0;
- size_t height = 0;
- size_t depth = 0;
+struct device_texture;
- TextureDesc description;
+class texture {
+public:
+ texture(handle<device_texture> handle);
- VmaAllocationInfo alloc_info;
- VkImage device_image;
+private:
+ handle<device_texture> handle;
};
diff --git a/include/vk-api.hpp b/include/vk-api.hpp
deleted file mode 100644
index a3442f1..0000000
--- a/include/vk-api.hpp
+++ /dev/null
@@ -1,219 +0,0 @@
-#ifndef __VK_API_HPP_
-#define __VK_API_HPP_
-
-#include <cassert>
-#include <vector>
-
-#include <vulkan/vulkan_core.h>
-
-using VmaAllocation = struct VmaAllocation_T*;
-
-struct buffer {
- VmaAllocation alloc;
- void* device_ptr;
- VkBuffer handle;
- size_t size;
- VkDeviceAddress device_address;
-};
-
-struct pipeline {
- std::vector<VkShaderModule> shader_modules;
- VkPipeline handle = VK_NULL_HANDLE;
- VkPipelineBindPoint bind_point;
-};
-
-using bindless_index = uint32_t;
-using handle = uint32_t;
-
-struct image {
- VkImage handle;
- VkImageView view;
- VmaAllocation alloc;
- VkImageSubresourceRange subresource_range;
- VkFormat format;
- VkExtent3D size;
- VkImageUsageFlags usages;
- bindless_index bindless_storage_index = 0;
- bindless_index bindless_sampled_index = 0;
-
- VkImageLayout previous_layout = VK_IMAGE_LAYOUT_UNDEFINED;
- VkPipelineStageFlags previous_stage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
- VkAccessFlags previous_access = 0;
-};
-
-struct swapchain {
- uint32_t image_count;
- std::vector<handle> images;
- VkSwapchainKHR handle;
- VkSurfaceFormatKHR surface_format;
- VkExtent2D extent;
-};
-
-struct framebuffer {
- VkFramebuffer handle;
- VkExtent2D size;
-};
-
-struct sampler {
- VkSampler handle;
- bindless_index bindless_index;
-};
-
-struct global_descriptor {
- VkDescriptorSetLayout set_layout;
- VkPipelineLayout pipeline_layout;
- VkDescriptorSet set;
-
- std::vector<uint32_t> index_pool[3];
-
- static constexpr uint32_t pool_size = 1024U;
-
- global_descriptor() {
- for (int32_t index = pool_size; index > 0; index--) {
- index_pool[0].push_back((uint32_t)index);
- index_pool[1].push_back((uint32_t)index);
- index_pool[2].push_back((uint32_t)index);
- }
- }
-
- uint32_t allocate(VkDescriptorType type) {
- auto& pool = index_pool[descriptor_type_binding(type)];
- auto index = pool.back();
- pool.pop_back();
-
- return index;
- }
-
- void free(uint32_t index, VkDescriptorType type) {
- assert(index != 0);
- index_pool[descriptor_type_binding(type)].push_back(index);
- }
-
- static int32_t descriptor_type_binding(VkDescriptorType type) {
- switch (type) {
- case VK_DESCRIPTOR_TYPE_SAMPLER:
- return 0;
- case VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE:
- return 1;
- case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
- return 2;
- default:
- assert(true && "descriptor type not supported");
- return -1;
- }
- }
-};
-
-class window;
-class vkcontext;
-
-class vkapi {
- public:
- vkapi(vkcontext& context);
- ~vkapi();
-
- handle create_buffer(size_t data_size, VkBufferUsageFlags buffer_usage, uint32_t mem_usage);
- void copy_buffer(VkCommandBuffer cmd_buf, handle src, handle dst, size_t size);
- void copy_buffer(VkCommandBuffer cmd_buf, handle src, handle dst, size_t size, size_t buffer_offset = 0);
- void destroy_buffer(handle buffer);
-
-
- handle create_image(VkExtent3D size, VkFormat format, VkImageUsageFlags usages);
- void destroy_image(handle image);
- std::vector<handle> create_images(VkExtent3D size, VkFormat format, VkImageUsageFlags usages, size_t image_count);
- void destroy_images(std::vector<handle>& imgs);
-
-
- [[nodiscard]] VkFence create_fence() const;
- void destroy_fence(VkFence fence) const;
- [[nodiscard]] std::vector<VkFence> create_fences(size_t fences_count) const;
- void destroy_fences(VkFence fences[], size_t fences_count) const;
-
-
- [[nodiscard]] VkSemaphore create_semaphore() const;
- void destroy_semaphore(VkSemaphore semaphore) const;
- [[nodiscard]] std::vector<VkSemaphore> create_semaphores(size_t semaphores_count) const;
- void destroy_semaphores(VkSemaphore semaphores[], size_t semaphores_count) const;
-
- handle create_sampler(VkFilter filter, VkSamplerAddressMode address_mode);
- void destroy_sampler(handle sampler);
-
-
- [[nodiscard]] VkCommandPool create_command_pool() const;
-
- void allocate_command_buffers(VkCommandPool command_pool, VkCommandBuffer* command_buffers, size_t count) const;
-
-
- VkRenderPass create_render_pass(std::vector<VkFormat>& color_attachments_format, VkImageLayout initial_layout, VkImageLayout final_layout);
- VkRenderPass create_render_pass(std::vector<VkFormat>& color_attachments_format, VkFormat depth_attachement_format);
- void destroy_render_pass(VkRenderPass render_pass);
-
-
- framebuffer create_framebuffer(VkRenderPass render_pass, std::vector<VkFormat>& formats, VkExtent2D size);
- std::vector<framebuffer> create_framebuffers(VkRenderPass render_pass, std::vector<VkFormat>& formats, VkExtent2D size, uint32_t framebuffer_count);
- void destroy_framebuffer(framebuffer framebuffer) const;
- void destroy_framebuffers(std::vector<framebuffer>& framebuffers) const;
-
-
- pipeline create_compute_pipeline(const char* shader_name) const;
- pipeline create_graphics_pipeline(const char* shader_name, VkShaderStageFlagBits shader_stages, VkRenderPass render_pass, std::vector<VkDynamicState>& dynamic_states) const;
- void destroy_pipeline(pipeline& pipeline) const;
-
-
- VkSurfaceKHR create_surface(window& wnd) const;
- void destroy_surface(VkSurfaceKHR surface);
-
-
- swapchain create_swapchain(VkSurfaceKHR surface, size_t min_image_count, VkImageUsageFlags usages, VkSwapchainKHR old_swapchain);
- void destroy_swapchain(swapchain& swapchain);
-
- void update_descriptor_image(handle img, VkDescriptorType type);
- void update_descriptor_images(std::vector<handle>& images, VkDescriptorType type);
- void update_descriptor_sampler(handle sampler);
- void update_descriptor_samplers(std::vector<handle>& samplers);
-
-
- void update_constants(VkCommandBuffer command_buffer, VkShaderStageFlagBits shader_stage, off_t offset, size_t size, void* data);
-
- void start_record(VkCommandBuffer command_buffer);
-
- void image_barrier(VkCommandBuffer command_buffer, VkImageLayout dst_layout, VkPipelineStageFlagBits dst_stage, VkAccessFlags dst_access, handle image);
-
- void begin_render_pass(VkCommandBuffer command_buffer, VkRenderPass render_pass, std::vector<VkImageView>& attachments, framebuffer framebuffer, VkExtent2D size);
- void end_render_pass(VkCommandBuffer command_buffer);
-
- void run_compute_pipeline(VkCommandBuffer command_buffer, pipeline& pipeline, size_t group_count_x, size_t group_count_y, size_t group_count_z);
-
- void draw(VkCommandBuffer command_buffer, pipeline& pipeline, uint32_t vertex_count, uint32_t vertex_offset);
- void draw(VkCommandBuffer command_buffer, pipeline& pipeline, handle index_buffer, uint32_t primitive_count, uint32_t indices_offset, uint32_t vertices_offset);
-
- void blit_full(VkCommandBuffer command_buffer, handle src_image, handle dst_image);
-
- void end_record(VkCommandBuffer command_buffer);
-
- VkResult submit(VkCommandBuffer command_buffers[], size_t command_buffers_count, VkSemaphore wait_semaphore, VkSemaphore signal_semaphore, VkFence submission_fence) const;
-
- VkResult present(swapchain& swapchain, uint32_t image_index, VkSemaphore wait_semaphore) const;
-
- const buffer& get_buffer(handle buffer_handle) { return *buffers[buffer_handle]; };
-
- const image& get_image(handle image_handle) { return *images[image_handle]; };
-
- const sampler& get_sampler(handle sampler_handle) { return *samplers[sampler_handle]; };
-
- vkcontext& context;
-
- private:
- global_descriptor bindless_descriptor;
-
- static const char* shader_stage_extension(VkShaderStageFlags shader_stage);
-
- // TODO: Use freelists instead
- std::vector<buffer*> buffers;
- std::vector<image*> images;
- std::vector<sampler*> samplers;
-
- VkDescriptorPool descriptor_pool;
-};
-
-#endif // !__VK_API_HPP_
diff --git a/include/vk-bindless.hpp b/include/vk-bindless.hpp
new file mode 100644
index 0000000..008e420
--- /dev/null
+++ b/include/vk-bindless.hpp
@@ -0,0 +1,49 @@
+#pragma once
+
+#include <vulkan/vulkan_core.h>
+
+#include "handle.hpp"
+
+enum UniformTypes : uint32_t {
+ GLOBAL,
+ PASS,
+ DRAW,
+ MAX,
+};
+
+enum SamplerType : uint32_t {
+ NEAREST,
+ LINEAR,
+ MAX_SAMPLER,
+};
+
+struct device_buffer;
+
+struct bindless_model {
+ [[nodiscard]] device_buffer& get_uniform_buffer(enum UniformTypes type) const;
+
+ void init();
+
+ void deinit();
+
+ VkPipelineLayout global_layout;
+ VkDescriptorSet global_set;
+
+public:
+ static constexpr size_t push_constant_slot_size = sizeof(uintptr_t);
+ static constexpr size_t push_constant_slots = 3U;
+
+private:
+ VkDescriptorSetLayout global_set_layout;
+ VkDescriptorPool descriptor_pool;
+ handle<device_buffer> uniform_buffers[UniformTypes::MAX];
+
+ static constexpr size_t descriptor_pool_allocable_sets_count = 64U;
+ static constexpr uint32_t set_descriptors_count = 1024U;
+
+ VkSampler samplers[SamplerType::MAX_SAMPLER];
+
+ static constexpr size_t globals_uniform_buffer_size = 64 * KB;
+ static constexpr size_t passes_uniform_buffer_size = 64 * KB;
+ static constexpr size_t draws_uniform_buffer_size = 64 * KB;
+};
diff --git a/include/api-test/vk-command-buffer.hpp b/include/vk-command-buffer.hpp
index 08652fd..82d5439 100644
--- a/include/api-test/vk-command-buffer.hpp
+++ b/include/vk-command-buffer.hpp
@@ -1,37 +1,17 @@
#pragma once
-#include <cstdint>
-#include <span>
-
-#include <vulkan/vulkan_core.h>
-
#include "handle.hpp"
-
-#include "vec3.hpp"
-
#include "vk-device-types.hpp"
+#include "vec3.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 {
@@ -54,10 +34,6 @@ struct draw_params {
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 {
@@ -67,10 +43,6 @@ struct draw_indexed_params {
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 {
diff --git a/include/vk-context.hpp b/include/vk-context.hpp
deleted file mode 100644
index 0dfd256..0000000
--- a/include/vk-context.hpp
+++ /dev/null
@@ -1,49 +0,0 @@
-#pragma once
-
-#include <vulkan/vulkan_core.h>
-
-using VmaAllocator = struct VmaAllocator_T*;
-
-struct queue {
- VkQueue handle;
- uint32_t index;
- VkQueueFlags usages;
-};
-
-class vkcontext {
- public:
- vkcontext();
-
- ~vkcontext();
-
- VkInstance instance;
-
- VkPhysicalDevice physical_device;
- VkDevice device;
-
- VmaAllocator allocator;
-
- queue graphics_queue;
-
- private:
- void create_instance();
-
- void create_debugger();
-
- void create_device();
-
- void create_memory_allocator();
-
- void select_physical_device();
-
- [[nodiscard]] uint32_t select_queue(VkQueueFlags queue_usage) const;
-
- static void check_available_instance_layers(const char* needed_layers[], size_t needed_layers_count);
-
- static void check_available_instance_extensions(const char* needed_extensions[], size_t needed_extensions_count);
-
- static bool support_required_features(VkPhysicalDevice physical_device);
-
-
- VkDebugUtilsMessengerEXT debugMessenger;
-};
diff --git a/include/api-test/vk-device-types.hpp b/include/vk-device-types.hpp
index eddf40c..94f9560 100644
--- a/include/api-test/vk-device-types.hpp
+++ b/include/vk-device-types.hpp
@@ -1,8 +1,6 @@
#pragma once
-#include <vulkan/vulkan_core.h>
-
-#include <span>
+#include <cstdint>
#include "freelist.hpp"
@@ -60,6 +58,8 @@ struct device_texture {
uint32_t depth = 1U;
uint32_t mips = 1U;
+ const char* name = nullptr;
+
private:
handle<void> storage_index;
handle<void> sampled_index;
@@ -110,52 +110,56 @@ struct buffer_desc {
VkBufferUsageFlags usages;
VkMemoryPropertyFlags memory_properties;
uint32_t memory_usage;
+ const char* name;
};
-#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) {
+ u32 alloc_size = sizeof(T);
+ if (allocated_size + alloc_size > size) {
reset();
}
- auto* addr = (T*)(static_cast<uint8_t*>(mapped_ptr) + offset);
- offset += alloc_size;
+ offset = allocated_size;
+ T* addr = (T*)(static_cast<uint8_t*>(mapped_ptr) + offset);
+ allocated_size += 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) {
+ void* allocate(u32 alloc_size) {
+ if (allocated_size + alloc_size > size) {
reset();
}
- auto* addr = (void*)(static_cast<uint8_t*>(mapped_ptr) + offset);
- offset += alloc_size;
+ offset = allocated_size;
+ void* addr = (void*)(static_cast<uint8_t*>(mapped_ptr) + offset);
+ allocated_size += alloc_size;
return addr;
}
void reset() {
+ allocated_size = 0U;
offset = 0U;
}
- uint64_t offset = 0U;
- VkBuffer vk_buffer;
- VmaAllocation alloc;
- VkDeviceAddress device_address = 0U;
- void* mapped_ptr;
- size_t size;
+ u32 offset = 0U;
+ u32 allocated_size = 0U;
+ VkBuffer vk_buffer;
+ VmaAllocation alloc;
+ VkDeviceAddress device_address = 0U;
+ void* mapped_ptr;
+ size_t size;
+ VkBufferUsageFlagBits2 usages;
+
+ const char* name;
};
struct graphics_pipeline_desc {
- std::span<uint8_t> vs_code;
- std::span<uint8_t> fs_code;
+ uint8_t* vs_code;
+ size_t vs_code_size;
+ uint8_t* fs_code;
+ size_t fs_code_size;
std::span<VkFormat> color_attachments_format;
VkFormat depth_attachment_format;
VkFormat stencil_attachment_format;
@@ -163,7 +167,8 @@ struct graphics_pipeline_desc {
};
struct compute_pipeline_desc {
- std::span<uint8_t> cs_code;
+ uint8_t* cs_code;
+ size_t cs_code_size;
const char* name;
};
diff --git a/include/api-test/vk-device.hpp b/include/vk-device.hpp
index 1b04bb3..e2e8c99 100644
--- a/include/api-test/vk-device.hpp
+++ b/include/vk-device.hpp
@@ -1,13 +1,8 @@
#pragma once
-#include <cstdint>
-#include <span>
-
-#include <vulkan/vulkan_core.h>
-
#include "freelist.hpp"
-#include "vk-device-types.hpp"
#include "vk-bindless.hpp"
+#include "vk-command-buffer.hpp"
using VmaAllocator = struct VmaAllocator_T*;
@@ -16,17 +11,17 @@ class window;
class vkdevice {
struct queue {
- VkQueue vk_queue;
- uint32_t index;
+ VkQueue vk_queue = VK_NULL_HANDLE;
+ uint32_t index = UINT32_MAX;
VkQueueFlags usages;
- VkCommandPool command_pool;
+ VkCommandPool command_pool = VK_NULL_HANDLE;
};
public:
void init();
void deinit();
- static inline vkdevice& get_render_device() {
+ static inline vkdevice& get() {
return render_device;
}
@@ -89,7 +84,11 @@ class vkdevice {
return bindless;
}
- inline VkDevice get_device() {
+ const freelist<device_texture>& get_textures() const {
+ return textures;
+ }
+
+ inline VkDevice get_device() const {
return device;
}
@@ -97,6 +96,10 @@ class vkdevice {
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);
@@ -112,8 +115,6 @@ class vkdevice {
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 ?
@@ -127,7 +128,7 @@ class vkdevice {
void pick_physical_device();
- static bool device_support_features(VkPhysicalDevice physical_dev);
+ bool device_support_features(VkPhysicalDevice physical_dev);
void create_debug_layer_callback();
@@ -135,6 +136,7 @@ class vkdevice {
VkInstance instance;
VkPhysicalDevice physical_device;
+ VkPhysicalDeviceProperties2 physical_device_props;
VkDevice device;
VmaAllocator gpu_allocator;
diff --git a/include/vk-renderer.hpp b/include/vk-renderer.hpp
deleted file mode 100644
index 1317912..0000000
--- a/include/vk-renderer.hpp
+++ /dev/null
@@ -1,164 +0,0 @@
-#ifndef __VK_RENDERER_HPP_
-#define __VK_RENDERER_HPP_
-
-#include <cstdint>
-#include <format>
-#include <vector>
-
-#include "vk-context.hpp"
-#include "vk-api.hpp"
-
-
-class Renderpass;
-class ComputeRenderpass;
-class PrimitiveRenderpass;
-class Primitive;
-class window;
-
-class Texture;
-class Sampler;
-class RingBuffer;
-
-
-class Buffer {
- public:
-
- Buffer(size_t size, VkBufferUsageFlagBits usage);
- ~Buffer();
-
- void write(void* data, off_t alloc_offset, size_t data_size) const;
-
- void resize(size_t new_size);
-
- handle device_buffer;
-
- size_t buffer_size;
-
- VkBufferUsageFlagBits usage;
-};
-
-
-class vkrenderer {
- public:
- vkrenderer(window& wnd);
-
- ~vkrenderer();
-
- void recreate_swapchain();
-
-
- void update_images();
-
- void begin_frame();
-
- void finish_frame();
-
- static void queue_image_update(Texture* texture);
-
- static Buffer* create_buffer(size_t size);
-
- static Buffer* create_index_buffer(size_t size);
-
- static Buffer* create_staging_buffer(size_t size);
-
- static Sampler* create_sampler(VkFilter filter, VkSamplerAddressMode address_mode);
-
-
- ComputeRenderpass* create_compute_renderpass();
-
- PrimitiveRenderpass* create_primitive_renderpass();
-
- Primitive* create_primitive(PrimitiveRenderpass& primitive_render_pass);
-
- void render();
-
- [[nodiscard]]uint32_t frame_index() const { return this->virtual_frame_index; }
-
- [[nodiscard]]Texture* back_buffer() const { return swapchain_textures[swapchain_image_index]; }
-
- [[nodiscard]]VkFormat back_buffer_format() const { return swapchain.surface_format.format; }
-
- static constexpr uint32_t virtual_frames_count = 2;
-
- static vkcontext context;
-
- static vkapi api;
-
- private:
-
-
- void handle_swapchain_result(VkResult function_result);
-
- std::vector<Renderpass*> renderpasses;
-
- uint32_t virtual_frame_index = 0;
- uint32_t swapchain_image_index = 0;
-
- VkCommandBuffer graphics_command_buffers[virtual_frames_count];
- VkCommandBuffer copy_command_buffers[virtual_frames_count];
-
- RingBuffer* staging_buffers[virtual_frames_count];
-
-
- pipeline tonemapping_pipeline;
-
- VkFence submission_fences[virtual_frames_count];
- VkSemaphore execution_semaphores[virtual_frames_count];
- VkSemaphore acquire_semaphores[virtual_frames_count];
-
- VkCommandPool graphics_command_pool;
- VkCommandPool copy_command_pools[virtual_frames_count];
-
- VkSurfaceKHR platform_surface;
- swapchain swapchain;
- std::vector<Texture*> swapchain_textures;
- std::vector<VkCommandBuffer> recorded_command_buffers;
-
- const uint32_t min_swapchain_image_count = 3;
-
- static std::vector<Texture*> upload_queue;
-};
-
-class RingBuffer {
- public:
-
- static const size_t invalid_alloc = -1;
-
- RingBuffer(size_t size);
-
- [[nodiscard]]size_t alloc(size_t alloc_size) {
- assert(alloc_size > 0 && alloc_size <= buffer_size);
-
- auto alloc_offset = ptr;
-
- if (alloc_offset <= buffer_size - alloc_size) {
- ptr += alloc_size;
- return alloc_offset;
- }
-
- return invalid_alloc;
- }
-
- void write(void* data, size_t alloc_offset, size_t data_size) const {
- auto api_buffer = vkrenderer::api.get_buffer(device_buffer);
-
- std::memcpy((uint8_t*)api_buffer.device_ptr + alloc_offset, data, data_size);
- }
-
- void reset() {
- ptr = 0;
- }
-
- handle device_buffer;
-
- size_t buffer_size;
- size_t ptr = 0;
-};
-
-class Sampler {
- public:
-
- handle device_sampler;
-};
-
-#endif // !__VK_RENDERER_HPP_
diff --git a/include/api-test/vk-utils.hpp b/include/vk-utils.hpp
index 205e103..f26d2a3 100644
--- a/include/api-test/vk-utils.hpp
+++ b/include/vk-utils.hpp
@@ -1,13 +1,9 @@
#pragma once
-#include <cassert>
-
-#include <vulkan/vulkan_core.h>
-
#ifdef _DEBUG
#define VKCHECK(result) assert((result) == VK_SUCCESS)
#else
-#define VKCHECK(result) result
+#define VKCHECK(result) (void)result
#endif
VKAPI_ATTR VkBool32 VKAPI_CALL debug_callback(VkDebugUtilsMessageSeverityFlagBitsEXT severity,