aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/aabb.hpp5
-rw-r--r--include/bvh-node.hpp3
-rw-r--r--include/color.hpp2
-rw-r--r--include/compute-renderpass.hpp12
-rw-r--r--include/gltf.hpp8
-rw-r--r--include/primitive-renderpass.hpp12
-rw-r--r--include/renderpass.hpp7
-rw-r--r--include/scene.hpp9
-rw-r--r--include/utils.hpp7
-rw-r--r--include/vec3.hpp2
-rw-r--r--include/vk-api.hpp45
-rw-r--r--include/vk-renderer.hpp22
-rw-r--r--include/vulkan-loader.hpp7
-rw-r--r--include/window.hpp1
14 files changed, 70 insertions, 72 deletions
diff --git a/include/aabb.hpp b/include/aabb.hpp
index 85b3c21..dcab8c9 100644
--- a/include/aabb.hpp
+++ b/include/aabb.hpp
@@ -1,11 +1,12 @@
#ifndef __AABB_HPP_
#define __AABB_HPP_
-#include "vec3.hpp"
-#include "triangle.hpp"
#include <cmath>
#include <climits>
+#include "vec3.hpp"
+#include "triangle.hpp"
+
class aabb {
public:
aabb() = default;
diff --git a/include/bvh-node.hpp b/include/bvh-node.hpp
index 99b6d62..525e1c8 100644
--- a/include/bvh-node.hpp
+++ b/include/bvh-node.hpp
@@ -3,9 +3,10 @@
#include <vector>
#include <algorithm>
+#include <iostream>
#include "aabb.hpp"
-#include "sphere.hpp"
+// #include "sphere.hpp"
#include "triangle.hpp"
struct bvh_node {
diff --git a/include/color.hpp b/include/color.hpp
index f300e76..312f70c 100644
--- a/include/color.hpp
+++ b/include/color.hpp
@@ -3,7 +3,7 @@
#include <iostream>
-#include "vec3.hpp"
+using color = class vec3;
void write_color(std::ostream& out, const color& pixel_color);
diff --git a/include/compute-renderpass.hpp b/include/compute-renderpass.hpp
index 641d4b1..14c3147 100644
--- a/include/compute-renderpass.hpp
+++ b/include/compute-renderpass.hpp
@@ -2,7 +2,6 @@
#include "renderpass.hpp"
#include "vk-api.hpp"
-#include <array>
class Texture;
class Buffer;
@@ -14,12 +13,9 @@ class ComputeRenderpass : public Renderpass {
: Renderpass(api)
{}
- ~ComputeRenderpass() {
- api.destroy_pipeline(pipeline);
- }
+ ~ComputeRenderpass() override;
-
- void set_pipeline(std::string& shader_name);
+ void set_pipeline(const char* shader_name);
void set_dispatch_size(size_t count_x, size_t count_y, size_t count_z);
@@ -30,7 +26,7 @@ class ComputeRenderpass : public Renderpass {
void set_constant(off_t offset, Buffer* buffer);
// TODO: Do not use vulkan api type
- void execute(vkrenderer& renderer, VkCommandBuffer command_buffer) override final;
+ void execute(vkrenderer& renderer, VkCommandBuffer command_buffer) final;
Texture* output_texture;
@@ -38,7 +34,7 @@ class ComputeRenderpass : public Renderpass {
std::vector<Texture*> input_textures;
- std::array<uint8_t, 64> constants;
+ uint8_t constants[64];
size_t group_count_x;
size_t group_count_y;
diff --git a/include/gltf.hpp b/include/gltf.hpp
index 0364ca8..66fb6ec 100644
--- a/include/gltf.hpp
+++ b/include/gltf.hpp
@@ -1,7 +1,6 @@
#ifndef __GLTF_HPP_
#define __GLTF_HPP_
-#include <filesystem>
#include <vector>
#include <optional>
@@ -11,8 +10,6 @@ using json = nlohmann::json;
#include "material.hpp"
-#include "vk-renderer.hpp"
-
struct mesh_part {
std::vector<uint16_t> indices;
std::vector<float> positions;
@@ -34,6 +31,11 @@ struct node {
std::optional<mesh> mesh;
};
+namespace std::filesystem {
+ class path;
+}
+
+class vkrenderer;
class gltf {
public:
static node load(std::filesystem::path &path, std::string &filename, vkrenderer &renderer);
diff --git a/include/primitive-renderpass.hpp b/include/primitive-renderpass.hpp
index 45b43e9..2e0a77b 100644
--- a/include/primitive-renderpass.hpp
+++ b/include/primitive-renderpass.hpp
@@ -1,11 +1,9 @@
#pragma once
-#include <stdint.h>
#include <vector>
-#include <array>
-#include "vk-renderer.hpp"
#include "renderpass.hpp"
+#include "vk-renderer.hpp"
class Buffer;
class Texture;
@@ -29,7 +27,7 @@ class PrimitiveRenderpass : public Renderpass {
void finalize_render_pass();
- void execute(vkrenderer& renderer, VkCommandBuffer command_buffer) override final;
+ void execute(vkrenderer& renderer, VkCommandBuffer command_buffer) final;
VkRenderPass render_pass = VK_NULL_HANDLE;
@@ -45,7 +43,7 @@ class PrimitiveRenderpass : public Renderpass {
std::vector<VkImageView> color_attachments_view;
std::vector<VkFormat> color_attachments_format;
- std::array<framebuffer, vkrenderer::virtual_frames_count> framebuffers;
+ framebuffer framebuffers[vkrenderer::virtual_frames_count];
std::vector<Primitive*> primitives;
};
@@ -58,7 +56,7 @@ class Primitive {
: api(api), primitive_render_pass(render_pass)
{};
- void set_pipeline(std::string& shader_name);
+ void set_pipeline(const char* shader_name);
void set_constant_offset(off_t offset);
void set_constant(off_t offset, uint64_t* constant);
@@ -93,5 +91,5 @@ private:
VkRect2D scissor = {};
- std::array<uint8_t, 64> constants;
+ uint8_t constants[64];
};
diff --git a/include/renderpass.hpp b/include/renderpass.hpp
index a444c64..da116dd 100644
--- a/include/renderpass.hpp
+++ b/include/renderpass.hpp
@@ -1,8 +1,9 @@
#pragma once
-#include <string>
+using VkCommandBuffer = struct VkCommandBuffer_T*;
-#include "vk-renderer.hpp"
+class vkrenderer;
+class vkapi;
class Renderpass {
public:
@@ -11,7 +12,7 @@ class Renderpass {
:api(api)
{};
- virtual ~Renderpass() {};
+ virtual ~Renderpass() = default;
// TODO: Do not use vulkan api type
virtual void execute(vkrenderer& renderer, VkCommandBuffer command_buffer) = 0;
diff --git a/include/scene.hpp b/include/scene.hpp
index 8e47ab0..cabd10e 100644
--- a/include/scene.hpp
+++ b/include/scene.hpp
@@ -3,9 +3,10 @@
#include "camera.hpp"
#include "bvh-node.hpp"
+#include "material.hpp"
-#include "vk-renderer.hpp"
-
+class vkrenderer;
+class Buffer;
class scene {
struct metadata {
camera cam;
@@ -18,8 +19,8 @@ class scene {
uint32_t sample_index = 0;
- uint32_t enable_dof = false;
- uint32_t debug_bvh = false;
+ uint32_t enable_dof = (uint32_t)false;
+ uint32_t debug_bvh = (uint32_t)false;
int32_t downscale_factor = 1;
metadata(camera cam, uint32_t width, uint32_t height)
diff --git a/include/utils.hpp b/include/utils.hpp
index 201976f..6e39098 100644
--- a/include/utils.hpp
+++ b/include/utils.hpp
@@ -1,8 +1,7 @@
#ifndef __UTILS_HPP_
#define __UTILS_HPP_
-#include <string>
-#include <filesystem>
+#include <thread>
#include <vector>
std::vector<uint8_t> read_file(const char* path);
@@ -16,7 +15,7 @@ inline float deg_to_rad(float deg) {
}
inline float randd() {
- return rand() / (RAND_MAX + 1.f);
+ return (float)rand() / (RAND_MAX + 1.f);
}
inline float randd(float min, float max) {
@@ -24,7 +23,7 @@ inline float randd(float min, float max) {
}
inline int32_t randi(int32_t min, int32_t max) {
- return (int32_t)(randd(min, max + 1.f));
+ return (int32_t)(randd((float)min, (float)max + 1.f));
}
inline float clamp(float x, float min, float max) {
diff --git a/include/vec3.hpp b/include/vec3.hpp
index 0250345..673bd83 100644
--- a/include/vec3.hpp
+++ b/include/vec3.hpp
@@ -1,7 +1,7 @@
#ifndef __VEC3_HPP_
#define __VEC3_HPP_
-#include <iostream>
+#include <ostream>
#include <xmmintrin.h>
class vec3 {
diff --git a/include/vk-api.hpp b/include/vk-api.hpp
index 0f1431a..c2ed9bd 100644
--- a/include/vk-api.hpp
+++ b/include/vk-api.hpp
@@ -1,10 +1,8 @@
#ifndef __VK_API_HPP_
#define __VK_API_HPP_
-#include <stdint.h>
#include <vector>
-#include <map>
-#include <iostream>
+#include <cassert>
#include "vk-context.hpp"
@@ -18,7 +16,7 @@ struct buffer {
struct pipeline {
std::vector<VkShaderModule> shader_modules;
- VkPipeline handle;
+ VkPipeline handle = VK_NULL_HANDLE;
VkPipelineBindPoint bind_point;
};
@@ -34,8 +32,8 @@ struct image {
VkFormat format;
VkExtent3D size;
VkImageUsageFlags usages;
- bindless_index bindless_storage_index;
- bindless_index bindless_sampled_index;
+ 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;
@@ -68,7 +66,7 @@ struct global_descriptor {
std::vector<uint32_t> index_pool[3];
global_descriptor() {
- for (int32_t index = 1024; index >= 0; index--) {
+ for (int32_t index = 1024; 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);
@@ -84,10 +82,11 @@ struct global_descriptor {
}
void free(uint32_t index, VkDescriptorType type) {
+ assert(index != 0);
index_pool[descriptor_type_binding(type)].push_back(index);
}
- int32_t descriptor_type_binding(VkDescriptorType type) {
+ static int32_t descriptor_type_binding(VkDescriptorType type) {
switch(type) {
case VK_DESCRIPTOR_TYPE_SAMPLER:
return 0;
@@ -96,7 +95,7 @@ struct global_descriptor {
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
return 2;
default:
- std::cerr << "descriptor type not supported" << std::endl;
+ assert(true && "descriptor type not supported");
return -1;
}
}
@@ -106,7 +105,7 @@ class window;
class vkapi {
public:
- vkapi();
+ vkapi(vkcontext& context);
~vkapi();
handle create_buffer(size_t data_size, VkBufferUsageFlags buffer_usage, VmaMemoryUsage mem_usage);
@@ -121,16 +120,16 @@ class vkapi {
void destroy_images(std::vector<handle>& images);
- VkFence create_fence();
- void destroy_fence(VkFence fence);
- std::vector<VkFence> create_fences(size_t fences_count);
- void destroy_fences(std::vector<VkFence> &fences);
+ [[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;
- VkSemaphore create_semaphore();
- void destroy_semaphore(VkSemaphore semaphore);
- std::vector<VkSemaphore> create_semaphores(size_t semaphores_count);
- void destroy_semaphores(std::vector<VkSemaphore> &semaphores);
+ [[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);
@@ -152,7 +151,7 @@ class vkapi {
pipeline create_compute_pipeline(const char* shader_name);
- pipeline create_graphics_pipeline(const char* shader_name, VkShaderStageFlagBits shader_stages, VkRenderPass render_pass, std::vector<VkDynamicState> dynamic_states);
+ pipeline create_graphics_pipeline(const char* shader_name, VkShaderStageFlagBits shader_stages, VkRenderPass render_pass, std::vector<VkDynamicState>& dynamic_states);
void destroy_pipeline(pipeline &pipeline);
@@ -191,21 +190,21 @@ class vkapi {
void end_record(VkCommandBuffer command_buffer);
- VkResult submit(VkCommandBuffer command_buffer, VkSemaphore wait_semaphore, VkSemaphore signal_semaphore, VkFence submission_fence);
+ VkResult submit(VkCommandBuffer command_buffer, VkSemaphore wait_semaphore, VkSemaphore signal_semaphore, VkFence submission_fence) const;
- VkResult present(swapchain& swapchain, uint32_t image_index, VkSemaphore wait_semaphore);
+ 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;
+ vkcontext& context;
private:
global_descriptor bindless_descriptor;
- const char* shader_stage_extension(VkShaderStageFlags shader_stage);
+ static const char* shader_stage_extension(VkShaderStageFlags shader_stage);
// TODO: Use freelists instead
std::vector<buffer*> buffers;
diff --git a/include/vk-renderer.hpp b/include/vk-renderer.hpp
index 864bc48..a301a5b 100644
--- a/include/vk-renderer.hpp
+++ b/include/vk-renderer.hpp
@@ -1,8 +1,6 @@
#ifndef __VK_RENDERER_HPP_
#define __VK_RENDERER_HPP_
-#include <stdint.h>
-#include <sys/types.h>
#include <vector>
#include "vk-api.hpp"
@@ -26,8 +24,6 @@ class vkrenderer {
void begin_frame();
- void compute(uint32_t width, uint32_t height);
-
void finish_frame();
void recreate_swapchain();
@@ -52,19 +48,23 @@ class vkrenderer {
void render();
- uint32_t frame_index() { return this->virtual_frame_index; }
+ [[nodiscard]]uint32_t frame_index() const { return this->virtual_frame_index; }
- Texture* back_buffer() { return swapchain_textures[swapchain_image_index]; }
+ [[nodiscard]]Texture* back_buffer() const { return swapchain_textures[swapchain_image_index]; }
- VkFormat back_buffer_format() { return swapchain.surface_format.format; }
+ [[nodiscard]]VkFormat back_buffer_format() const { return swapchain.surface_format.format; }
static constexpr uint32_t virtual_frames_count = 2;
+ vkcontext context;
+
+ vkapi api;
+
private:
void handle_swapchain_result(VkResult function_result);
- vkapi api;
+ // vkapi api;
std::vector<Renderpass*> renderpasses;
@@ -78,9 +78,9 @@ class vkrenderer {
pipeline tonemapping_pipeline;
- std::vector<VkFence> submission_fences;
- std::vector<VkSemaphore> execution_semaphores;
- std::vector<VkSemaphore> acquire_semaphores;
+ VkFence submission_fences[virtual_frames_count];
+ VkSemaphore execution_semaphores[virtual_frames_count];
+ VkSemaphore acquire_semaphores[virtual_frames_count];
VkSurfaceKHR platform_surface;
swapchain swapchain;
diff --git a/include/vulkan-loader.hpp b/include/vulkan-loader.hpp
index 16df7a6..d8c1082 100644
--- a/include/vulkan-loader.hpp
+++ b/include/vulkan-loader.hpp
@@ -164,10 +164,11 @@
VULKAN_DEVICE_FUNCTIONS
#undef X
- void load_vulkan();
- void load_instance_functions(VkInstance instance);
+void load_vulkan();
- void load_device_functions(VkDevice device);
+void load_instance_functions(VkInstance instance);
+
+void load_device_functions(VkDevice device);
#endif // !__VULKAN_LOADER_HPP_
diff --git a/include/window.hpp b/include/window.hpp
index 07753df..cab215f 100644
--- a/include/window.hpp
+++ b/include/window.hpp
@@ -1,7 +1,6 @@
#ifndef __WINDOW_HPP_
#define __WINDOW_HPP_
-#include <cstdint>
#include <vector>
#include "defines.hpp"