aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2022-02-14 12:45:52 +0100
committerladevieq <ladevie.quentin@gmail.com>2022-02-14 12:45:52 +0100
commitf582eb80d73a1d0b735503c8894636782406228c (patch)
treec4eb2da956a5b8977c8796b5fe25725ff518a23f /include
parentbbb45f80298dc4a41d31805416bad19363c8eff8 (diff)
High level buffer class
Diffstat (limited to 'include')
-rw-r--r--include/compute-renderpass.hpp29
-rw-r--r--include/renderpass.hpp27
-rw-r--r--include/scene.hpp18
-rw-r--r--include/vk-api.hpp1
-rw-r--r--include/vk-renderer.hpp69
5 files changed, 99 insertions, 45 deletions
diff --git a/include/compute-renderpass.hpp b/include/compute-renderpass.hpp
index 39cbf79..a581930 100644
--- a/include/compute-renderpass.hpp
+++ b/include/compute-renderpass.hpp
@@ -1,32 +1,11 @@
#pragma once
+#include "renderpass.hpp"
#include "vk-api.hpp"
#include <array>
class Texture;
-class Renderpass {
- public:
-
- Renderpass(vkapi& api)
- :api(api)
- {};
-
- virtual ~Renderpass() {
- api.destroy_pipeline(pipeline);
- }
-
- void set_pipeline(pipeline pipeline) {
- this->pipeline = pipeline;
- }
-
- // TODO: Do not use vulkan api type
- virtual void execute(VkCommandBuffer command_buffer) = 0;
-
- protected:
- vkapi &api;
-
- pipeline pipeline;
-};
+class Buffer;
class ComputeRenderpass : public Renderpass {
public:
@@ -35,12 +14,16 @@ class ComputeRenderpass : public Renderpass {
: Renderpass(api)
{}
+
+ void set_pipeline(std::string& shader_name) override final;
+
void set_dispatch_size(size_t count_x, size_t count_y, size_t count_z);
void set_ouput_texture(Texture* ouput_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(VkCommandBuffer command_buffer) override final;
diff --git a/include/renderpass.hpp b/include/renderpass.hpp
new file mode 100644
index 0000000..64947b6
--- /dev/null
+++ b/include/renderpass.hpp
@@ -0,0 +1,27 @@
+#pragma once
+
+#include <string>
+
+#include "vk-api.hpp"
+
+class Renderpass {
+ public:
+
+ Renderpass(vkapi& api)
+ :api(api)
+ {};
+
+ virtual ~Renderpass() {
+ api.destroy_pipeline(pipeline);
+ }
+
+ virtual void set_pipeline(std::string& shader_name) = 0;
+
+ // TODO: Do not use vulkan api type
+ virtual void execute(VkCommandBuffer command_buffer) = 0;
+
+ protected:
+ vkapi &api;
+
+ pipeline pipeline;
+};
diff --git a/include/scene.hpp b/include/scene.hpp
index e24e65f..4bce1a7 100644
--- a/include/scene.hpp
+++ b/include/scene.hpp
@@ -34,10 +34,6 @@ class scene {
public:
scene(camera cam, uint32_t width, uint32_t height, vkrenderer &renderer);
- void* scene_buffer_ptr() {
- return scene_buffer.alloc_info.pMappedData;
- }
-
metadata meta;
// Geometry & BVH
@@ -47,13 +43,13 @@ public:
std::vector<float> uvs;
std::vector<material> materials;
- buffer scene_buffer;
- buffer indices_buffer;
- buffer positions_buffer;
- buffer normals_buffer;
- buffer uvs_buffer;
- buffer bvh_buffer;
- buffer materials_buffer;
+ Buffer* scene_buffer;
+ Buffer* indices_buffer;
+ Buffer* positions_buffer;
+ Buffer* normals_buffer;
+ Buffer* uvs_buffer;
+ Buffer* bvh_buffer;
+ Buffer* materials_buffer;
std::vector<packed_bvh_node> packed_nodes;
};
diff --git a/include/vk-api.hpp b/include/vk-api.hpp
index 174d050..cc0188d 100644
--- a/include/vk-api.hpp
+++ b/include/vk-api.hpp
@@ -159,6 +159,7 @@ class vkapi {
void update_descriptor_image(image &img, VkDescriptorType type);
void update_descriptor_images(std::vector<image> &images, VkDescriptorType type);
+ void update_descriptor_sampler(sampler &sampler);
void update_descriptor_samplers(std::vector<sampler> &samplers);
diff --git a/include/vk-renderer.hpp b/include/vk-renderer.hpp
index ba9b5a0..76dfffc 100644
--- a/include/vk-renderer.hpp
+++ b/include/vk-renderer.hpp
@@ -1,21 +1,20 @@
#ifndef __VK_RENDERER_HPP_
#define __VK_RENDERER_HPP_
+#include <stdint.h>
#include <vector>
#include "vk-api.hpp"
-#include "vulkan-loader.hpp"
+#include "vulkan/vulkan_core.h"
-#include "compute-renderpass.hpp"
-class scene;
+class Renderpass;
+class ComputeRenderpass;
class window;
-class Texture {
- public:
-
- image device_image;
-};
+class Texture;
+class Buffer;
+class Sampler;
class vkrenderer {
public:
@@ -33,19 +32,26 @@ class vkrenderer {
void recreate_swapchain();
- void update_image(image img, void* data, size_t size);
+ void update_image(Texture* texture, void* data, size_t size);
- Texture* create_2d_texture(size_t width, size_t height);
+ Buffer* create_buffer(size_t size, bool isStatic);
+
+ Texture* create_2d_texture(size_t width, size_t height, VkFormat format);
+
+ Sampler* create_sampler(VkFilter filter, VkSamplerAddressMode address_mode);
ComputeRenderpass* create_compute_renderpass();
void render();
+ uint32_t frame_index() { return this->virtual_frame_index; }
+
+ private:
+
vkapi api;
std::vector<Renderpass*> renderpasses;
- private:
void handle_swapchain_result(VkResult function_result);
@@ -81,4 +87,45 @@ class vkrenderer {
static constexpr uint32_t virtual_frames_count = 2;
};
+// TODO: Move those to there own files
+class Texture {
+ public:
+
+ sampler sampler;
+
+ image device_image;
+};
+
+class Sampler {
+ public:
+ sampler device_sampler;
+};
+
+class Buffer {
+ public:
+
+ Buffer(vkrenderer* renderer, size_t size, bool isStatic)
+ : renderer(renderer), size(size), isStatic(isStatic) {}
+
+ void* ptr() {
+ size_t offset = isStatic ? 0 : size * renderer->frame_index();
+ return (uint8_t*)device_buffer.alloc_info.pMappedData + offset;
+ }
+
+ unsigned long long device_address() {
+ size_t offset = isStatic ? 0 : size * renderer->frame_index();
+ return device_buffer.device_address + offset;
+ }
+
+ buffer device_buffer;
+
+ private:
+
+ bool isStatic;
+
+ size_t size;
+
+ vkrenderer* renderer;
+};
+
#endif // !__VK_RENDERER_HPP_