diff options
| -rw-r--r-- | include/compute-renderpass.hpp | 2 | ||||
| -rw-r--r-- | include/material.hpp | 2 | ||||
| -rw-r--r-- | include/primitive-renderpass.hpp | 4 | ||||
| -rw-r--r-- | include/scene.hpp | 19 | ||||
| -rw-r--r-- | include/utils.hpp | 10 | ||||
| -rw-r--r-- | include/vk-api.hpp | 19 | ||||
| -rw-r--r-- | include/vk-context.hpp | 2 | ||||
| -rw-r--r-- | include/vk-renderer.hpp | 3 | ||||
| -rw-r--r-- | src/compute-renderpass.cpp | 4 | ||||
| -rw-r--r-- | src/main.cpp | 4 | ||||
| -rw-r--r-- | src/primitive-renderpass.cpp | 10 | ||||
| -rw-r--r-- | src/scene.cpp | 18 | ||||
| -rw-r--r-- | src/vec3.cpp | 2 | ||||
| -rw-r--r-- | src/vk-api.cpp | 68 | ||||
| -rw-r--r-- | src/vk-context.cpp | 49 | ||||
| -rw-r--r-- | src/vk-renderer.cpp | 4 |
16 files changed, 130 insertions, 90 deletions
diff --git a/include/compute-renderpass.hpp b/include/compute-renderpass.hpp index 60a1e05..6799171 100644 --- a/include/compute-renderpass.hpp +++ b/include/compute-renderpass.hpp @@ -16,7 +16,7 @@ class ComputeRenderpass : public Renderpass { 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_ouput_texture(Texture* out_texture); void set_constant(off_t offset, uint64_t* constant); void set_constant(off_t offset, Texture* texture); diff --git a/include/material.hpp b/include/material.hpp index 780e68d..efa6141 100644 --- a/include/material.hpp +++ b/include/material.hpp @@ -1,6 +1,8 @@ #ifndef __MATERIAL_HPP_ #define __MATERIAL_HPP_ +#include <cstdint> + #include "vec3.hpp" struct texture { diff --git a/include/primitive-renderpass.hpp b/include/primitive-renderpass.hpp index 8dda772..4d90d3c 100644 --- a/include/primitive-renderpass.hpp +++ b/include/primitive-renderpass.hpp @@ -68,7 +68,7 @@ class Primitive { 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 first_vertex, off_t vertex_offset); + void set_draw_info(size_t vertex_count, off_t indices_off, off_t vertex_off); void render(VkCommandBuffer command_buffer); @@ -84,7 +84,7 @@ private: Buffer* index_buffer; size_t element_count; - off_t first_vertex; + off_t indices_offset; off_t vertex_offset; off_t constant_offset; diff --git a/include/scene.hpp b/include/scene.hpp index c0b0344..257b8c9 100644 --- a/include/scene.hpp +++ b/include/scene.hpp @@ -1,11 +1,10 @@ #ifndef __SCENE_HPP_
#define __SCENE_HPP_
+#include <cstdint>
+
#include "camera.hpp"
-#include "bvh.hpp"
-#include "material.hpp"
-class vkrenderer;
class Buffer;
class scene {
struct metadata {
@@ -23,24 +22,16 @@ class scene { uint32_t debug_bvh = (uint32_t)false;
int32_t downscale_factor = 1;
- metadata(camera cam, uint32_t width, uint32_t height)
- : cam(std::move(cam)), width(width), height(height) {}
+ metadata(const camera &cam, uint32_t width, uint32_t height);
};
// void random_scene();
public:
- scene(camera cam, uint32_t width, uint32_t height, vkrenderer &renderer);
+ scene(const camera& cam, uint32_t width, uint32_t height);
metadata meta;
- // Geometry & BVH
- std::vector<uint32_t> indices;
- std::vector<float> positions;
- std::vector<float> normals;
- std::vector<float> uvs;
- std::vector<material> materials;
-
Buffer* scene_buffer;
Buffer* indices_buffer;
Buffer* positions_buffer;
@@ -48,8 +39,6 @@ public: Buffer* uvs_buffer;
Buffer* bvh_buffer;
Buffer* materials_buffer;
-
- std::vector<packed_bvh_node> packed_nodes;
};
#endif // !__SCENE_HPP_
diff --git a/include/utils.hpp b/include/utils.hpp index cbc92b3..83a867f 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -31,16 +31,17 @@ inline int32_t randi(int32_t min, int32_t max) { } inline float clamp(float x, float min, float max) { - if (x < min) return min; - if (x > max) return max; + if (x < min) { return min; } + if (x > max) { return max; } return x; } -#include <windows.h> #if defined(WINDOWS) + +#include <windows.h> + void log_last_error(); -#endif class watcher { public: @@ -61,3 +62,4 @@ private: inline static std::unordered_map<std::string, std::function<void()>> callbacks; inline static std::unordered_map<std::string, watch_data> watched_dirs; }; +#endif diff --git a/include/vk-api.hpp b/include/vk-api.hpp index 2391b60..2b88e42 100644 --- a/include/vk-api.hpp +++ b/include/vk-api.hpp @@ -7,7 +7,6 @@ #include "vulkan-loader.hpp" using VmaAllocation = struct VmaAllocation_T*; -using VmaMemoryUsage = enum VmaMemoryUsage; struct buffer { VmaAllocation alloc; @@ -68,8 +67,10 @@ struct global_descriptor { std::vector<uint32_t> index_pool[3]; + static constexpr uint32_t pool_size = 1024U; + global_descriptor() { - for (int32_t index = 1024; index > 0; index--) { + 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); @@ -112,7 +113,7 @@ class vkapi { vkapi(vkcontext& context); ~vkapi(); - handle create_buffer(size_t data_size, VkBufferUsageFlags buffer_usage, VmaMemoryUsage mem_usage); + 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); void destroy_buffer(handle buffer); @@ -121,7 +122,7 @@ class vkapi { 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>& images); + void destroy_images(std::vector<handle>& imgs); [[nodiscard]] VkFence create_fence() const; @@ -150,13 +151,13 @@ class vkapi { 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); - void destroy_framebuffers(std::vector<framebuffer>& framebuffers); + void destroy_framebuffer(framebuffer framebuffer) const; + void destroy_framebuffers(std::vector<framebuffer>& framebuffers) const; - 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); - void destroy_pipeline(pipeline &pipeline); + 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; std::vector<VkDescriptorSet> create_descriptor_sets(VkDescriptorSetLayout descriptor_sets_layout, size_t descriptor_sets_count); diff --git a/include/vk-context.hpp b/include/vk-context.hpp index 078b3c0..8d0b91f 100644 --- a/include/vk-context.hpp +++ b/include/vk-context.hpp @@ -37,7 +37,7 @@ class vkcontext { static void check_available_instance_layers(std::vector<const char*>& needed_layers); - static void check_available_instance_extensions(std::vector<const char*>& available_layers, std::vector<const char*>& needed_extensions); + static void check_available_instance_extensions(std::vector<const char*>& needed_extensions); static bool support_required_features(VkPhysicalDevice physical_device); diff --git a/include/vk-renderer.hpp b/include/vk-renderer.hpp index 5efb7d6..57ebb31 100644 --- a/include/vk-renderer.hpp +++ b/include/vk-renderer.hpp @@ -31,7 +31,7 @@ class vkrenderer { void update_image(Texture* texture, void* data); - void update_buffer(Buffer* buffer, void* data, off_t offset, size_t size); + void update_buffer(Buffer* buffer, void* data, off_t offset, size_t size) const; Buffer* create_buffer(size_t size, bool isStatic); @@ -116,6 +116,7 @@ class Buffer { handle device_buffer; size_t size; + size_t element_size; bool isStatic; }; diff --git a/src/compute-renderpass.cpp b/src/compute-renderpass.cpp index b7af1ba..2728fec 100644 --- a/src/compute-renderpass.cpp +++ b/src/compute-renderpass.cpp @@ -16,8 +16,8 @@ void ComputeRenderpass::set_pipeline(const char* shader_name) { this->pipeline = api.create_compute_pipeline(shader_name); } -void ComputeRenderpass::set_ouput_texture(Texture* output_texture) { - this->output_texture = output_texture; +void ComputeRenderpass::set_ouput_texture(Texture* out_texture) { + this->output_texture = out_texture; auto image = api.get_image(output_texture->device_image); diff --git a/src/main.cpp b/src/main.cpp index 1e5e556..97aaa27 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -83,12 +83,12 @@ int main() { raytracing_pass->set_pipeline("compute"); watcher::watch_file(std::filesystem::path("../shaders/compute.comp"), [&]() { - LPSTR cmd_line = "glslc.exe --target-env=vulkan1.2 -std=460 ../shaders/compute.comp -o shaders/compute.comp.spv -I \"../shaders/include\"\0"; + LPCSTR app_name = "glslc.exe --target-env=vulkan1.2 -std=460 ../shaders/compute.comp -o shaders/compute.comp.spv -I \"../shaders/include\"\0"; STARTUPINFO start_info {}; PROCESS_INFORMATION proc_info {}; if (FAILED(CreateProcessA( + app_name, nullptr, - cmd_line, nullptr, nullptr, FALSE, diff --git a/src/primitive-renderpass.cpp b/src/primitive-renderpass.cpp index 72bcf19..acedcdf 100644 --- a/src/primitive-renderpass.cpp +++ b/src/primitive-renderpass.cpp @@ -47,10 +47,10 @@ void Primitive::set_scissor(int32_t x, int32_t y, uint32_t width, uint32_t heigh scissor.extent.height = height; } -void Primitive::set_draw_info(size_t vertex_count, off_t first_vertex, off_t vertex_offset) { +void Primitive::set_draw_info(size_t vertex_count, off_t indices_off, off_t vertex_off) { this->element_count = vertex_count; - this->first_vertex = first_vertex; - this->vertex_offset = vertex_offset; + this->indices_offset = indices_off; + this->vertex_offset = vertex_off; } void Primitive::render(VkCommandBuffer command_buffer) { @@ -63,7 +63,7 @@ void Primitive::render(VkCommandBuffer command_buffer) { pipeline, index_buffer->device_buffer, element_count, - first_vertex, + indices_offset, vertex_offset ); }; @@ -122,7 +122,7 @@ void PrimitiveRenderpass::execute(vkrenderer& renderer, VkCommandBuffer command_ vkCmdSetViewport(command_buffer, 0, 1, &viewport); - for (auto primitive : primitives) { + for (auto* primitive : primitives) { primitive->render(command_buffer); } diff --git a/src/scene.cpp b/src/scene.cpp index d32a696..d62e309 100644 --- a/src/scene.cpp +++ b/src/scene.cpp @@ -5,6 +5,8 @@ #include "vk-renderer.hpp"
#include "gltf.hpp"
+#include "bvh.hpp"
+#include "material.hpp"
// void scene::random_scene() {
// material ground_material = { { 0.5, 0.5, 0.5 } };
@@ -55,8 +57,20 @@ // spheres_count = spheres.size();
// }
-scene::scene(camera cam, uint32_t width, uint32_t height, vkrenderer &renderer)
- :meta(std::move(cam), width, height){
+
+scene::metadata::metadata(const camera &cam, uint32_t width, uint32_t height)
+ : cam(cam), width(width), height(height) {}
+
+scene::scene(const camera& cam, uint32_t width, uint32_t height)
+ :meta(cam, width, height){
+
+ // Geometry & BVH
+ std::vector<uint32_t> indices;
+ std::vector<float> positions;
+ std::vector<float> normals;
+ std::vector<float> uvs;
+ std::vector<material> materials;
+ std::vector<packed_bvh_node> packed_nodes;
// auto bistro_interior_path = std::filesystem::path("../models/BistroInterior");
// auto bistro_interior_filename = std::string("BistroInterior.gltf");
diff --git a/src/vec3.cpp b/src/vec3.cpp index 43431fc..1bd068f 100644 --- a/src/vec3.cpp +++ b/src/vec3.cpp @@ -44,7 +44,7 @@ vec3 &vec3::operator/=(float numerator) { return *this; } -float vec3::operator[](int axis) { +float vec3::operator[](const int axis) { if (axis > 2) { return std::numeric_limits<float>::infinity(); } return v[axis]; diff --git a/src/vk-api.cpp b/src/vk-api.cpp index 1c7f187..ebffd38 100644 --- a/src/vk-api.cpp +++ b/src/vk-api.cpp @@ -1,5 +1,6 @@ #include "vk-api.hpp" +#include <filesystem> #include <cassert> #include <vk_mem_alloc.h> @@ -30,19 +31,19 @@ vkapi::vkapi(vkcontext& context) std::vector<VkDescriptorPoolSize> descriptor_pools_sizes = { { .type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, - .descriptorCount = (uint32_t)1024, + .descriptorCount = (uint32_t)global_descriptor::pool_size, }, { .type = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, - .descriptorCount = (uint32_t)1024, + .descriptorCount = (uint32_t)global_descriptor::pool_size, }, { .type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, - .descriptorCount = (uint32_t)1024, + .descriptorCount = (uint32_t)global_descriptor::pool_size, }, { .type = VK_DESCRIPTOR_TYPE_SAMPLER, - .descriptorCount = (uint32_t)1024, + .descriptorCount = (uint32_t)global_descriptor::pool_size, } }; @@ -61,19 +62,19 @@ vkapi::vkapi(vkcontext& context) { .binding = 0, .descriptorType = VK_DESCRIPTOR_TYPE_SAMPLER, - .descriptorCount = 1024, + .descriptorCount = global_descriptor::pool_size, .stageFlags = VK_SHADER_STAGE_ALL, }, { .binding = 1, .descriptorType = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, - .descriptorCount = 1024, + .descriptorCount = global_descriptor::pool_size, .stageFlags = VK_SHADER_STAGE_ALL, }, { .binding = 2, .descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, - .descriptorCount = 1024, + .descriptorCount = global_descriptor::pool_size, .stageFlags = VK_SHADER_STAGE_ALL, }, }; @@ -145,7 +146,6 @@ vkapi::vkapi(vkcontext& context) } vkapi::~vkapi() { - // Free resources for (handle buffer_handle = 0; buffer_handle < buffers.size(); buffer_handle++) { destroy_buffer(buffer_handle); } @@ -168,8 +168,8 @@ vkapi::~vkapi() { } -handle vkapi::create_buffer(size_t data_size, VkBufferUsageFlags buffer_usage, VmaMemoryUsage mem_usage) { - struct buffer* buffer = new struct buffer(); +handle vkapi::create_buffer(size_t data_size, VkBufferUsageFlags buffer_usage, uint32_t mem_usage) { + auto* buffer = new struct buffer(); VkBufferCreateInfo buffer_info = {}; buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO; @@ -177,7 +177,7 @@ handle vkapi::create_buffer(size_t data_size, VkBufferUsageFlags buffer_usage, V buffer_info.usage = buffer_usage | VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT_KHR; VmaAllocationCreateInfo alloc_create_info = {}; - alloc_create_info.usage = mem_usage; + alloc_create_info.usage = (VmaMemoryUsage)mem_usage; alloc_create_info.flags = VMA_ALLOCATION_CREATE_MAPPED_BIT; VmaAllocationInfo alloc_info {}; @@ -237,7 +237,7 @@ void vkapi::destroy_buffer(handle buffer) { handle vkapi::create_image(VkExtent3D size, VkFormat format, VkImageUsageFlags usages) { - struct image* image = new struct image(); + auto* image = new struct image(); image->size = size; @@ -295,12 +295,12 @@ handle vkapi::create_image(VkExtent3D size, VkFormat format, VkImageUsageFlags u auto image_handle = images.size() - 1; - if (usages & VK_IMAGE_USAGE_STORAGE_BIT) { + if ((usages & VK_IMAGE_USAGE_STORAGE_BIT) != 0U) { image->bindless_storage_index = bindless_descriptor.allocate(VK_DESCRIPTOR_TYPE_STORAGE_IMAGE); update_descriptor_image(image_handle, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE); } - if (usages & VK_IMAGE_USAGE_SAMPLED_BIT) { + if ((usages & VK_IMAGE_USAGE_SAMPLED_BIT) != 0U) { image->bindless_sampled_index = bindless_descriptor.allocate(VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE); update_descriptor_image(image_handle, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE); } @@ -308,7 +308,7 @@ handle vkapi::create_image(VkExtent3D size, VkFormat format, VkImageUsageFlags u return image_handle; } void vkapi::destroy_image(handle image) { - auto current_image = images[image]; + auto* current_image = images[image]; bindless_descriptor.free(current_image->bindless_storage_index, VK_DESCRIPTOR_TYPE_STORAGE_IMAGE); bindless_descriptor.free(current_image->bindless_sampled_index, VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE); @@ -330,8 +330,8 @@ std::vector<handle> vkapi::create_images(VkExtent3D size, VkFormat format, VkIma return images_handles; } -void vkapi::destroy_images(std::vector<handle> &images) { - for (auto handle: images) { +void vkapi::destroy_images(std::vector<handle> &imgs) { + for (auto handle: imgs) { destroy_image(handle); } } @@ -599,13 +599,13 @@ std::vector<framebuffer> vkapi::create_framebuffers(VkRenderPass render_pass, st return framebuffers; } -void vkapi::destroy_framebuffer(framebuffer framebuffer) { +void vkapi::destroy_framebuffer(framebuffer framebuffer) const { VKRESULT(vkDeviceWaitIdle(context.device)) vkDestroyFramebuffer(context.device, framebuffer.handle, VK_NULL_HANDLE); } -void vkapi::destroy_framebuffers(std::vector<framebuffer>& framebuffers) { +void vkapi::destroy_framebuffers(std::vector<framebuffer>& framebuffers) const { VKRESULT(vkDeviceWaitIdle(context.device)) for (auto& framebuffer: framebuffers) { @@ -614,14 +614,14 @@ void vkapi::destroy_framebuffers(std::vector<framebuffer>& framebuffers) { } -pipeline vkapi::create_compute_pipeline(const char* shader_name) { +pipeline vkapi::create_compute_pipeline(const char* shader_name) const { pipeline pipeline { .bind_point = VK_PIPELINE_BIND_POINT_COMPUTE }; - char shader_path[256] = {}; - sprintf(shader_path, "%s%s%s", "./shaders/", shader_name, ".comp.spv"); - std::vector<uint8_t> shader_code = read_file(shader_path); + auto shader_filename = std::string(shader_name) + ".comp.spv"; + auto shader_path = std::filesystem::path{ "./shaders" } / shader_filename; + std::vector<uint8_t> shader_code = read_file(shader_path.string().c_str()); assert(!shader_code.empty()); pipeline.shader_modules.resize(1); @@ -631,9 +631,9 @@ pipeline vkapi::create_compute_pipeline(const char* shader_name) { shader_create_info.pNext = VK_NULL_HANDLE; shader_create_info.flags = 0; shader_create_info.codeSize = shader_code.size(); - shader_create_info.pCode = (uint32_t*)shader_code.data(); + shader_create_info.pCode = reinterpret_cast<uint32_t*>(shader_code.data()); - VKRESULT(vkCreateShaderModule(context.device, &shader_create_info, VK_NULL_HANDLE, &pipeline.shader_modules[0])) + VKRESULT(vkCreateShaderModule(context.device, &shader_create_info, VK_NULL_HANDLE, (pipeline.shader_modules).data())) VkPipelineShaderStageCreateInfo stage_create_info = {}; stage_create_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; @@ -664,7 +664,7 @@ pipeline vkapi::create_compute_pipeline(const char* shader_name) { return pipeline; } -pipeline vkapi::create_graphics_pipeline(const char* shader_name, VkShaderStageFlagBits shader_stages, VkRenderPass render_pass, std::vector<VkDynamicState>& dynamic_states) { +pipeline vkapi::create_graphics_pipeline(const char* shader_name, VkShaderStageFlagBits shader_stages, VkRenderPass render_pass, std::vector<VkDynamicState>& dynamic_states) const { pipeline pipeline { .bind_point = VK_PIPELINE_BIND_POINT_GRAPHICS }; @@ -672,22 +672,20 @@ pipeline vkapi::create_graphics_pipeline(const char* shader_name, VkShaderStageF std::vector<VkPipelineShaderStageCreateInfo> stages_create_info = {}; for (VkShaderStageFlags stage_flag = VK_SHADER_STAGE_VERTEX_BIT; stage_flag <= VK_SHADER_STAGE_ALL_GRAPHICS; stage_flag <<= 2) { - if (stage_flag & shader_stages) { + if ((stage_flag & shader_stages) != 0U) { VkShaderModule shader_module; - char shader_path[256] = {}; - sprintf(shader_path, "%s%s%s%s", "./shaders/", shader_name, shader_stage_extension(stage_flag), ".spv"); - std::vector<uint8_t> shader_code = read_file(shader_path); - if (shader_code.size() == 0) { - exit(1); - } + auto shader_filename = std::string(shader_name) + shader_stage_extension(stage_flag) + ".spv"; + auto shader_path = std::filesystem::path{ "./shaders" } / shader_filename; + std::vector<uint8_t> shader_code = read_file(shader_path.string().c_str()); + assert(!shader_code.empty()); VkShaderModuleCreateInfo shader_create_info = {}; shader_create_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO; shader_create_info.pNext = nullptr; shader_create_info.flags = 0; shader_create_info.codeSize = shader_code.size(); - shader_create_info.pCode = (uint32_t*)shader_code.data(); + shader_create_info.pCode = reinterpret_cast<uint32_t*>(shader_code.data()); VKRESULT(vkCreateShaderModule(context.device, &shader_create_info, nullptr, &shader_module)) @@ -792,7 +790,7 @@ pipeline vkapi::create_graphics_pipeline(const char* shader_name, VkShaderStageF return pipeline; } -void vkapi::destroy_pipeline(pipeline &pipeline) { +void vkapi::destroy_pipeline(pipeline &pipeline) const { for (auto& shader_module: pipeline.shader_modules) { vkDestroyShaderModule(context.device, shader_module, nullptr); } diff --git a/src/vk-context.cpp b/src/vk-context.cpp index 3f7f6e0..e659b86 100644 --- a/src/vk-context.cpp +++ b/src/vk-context.cpp @@ -19,7 +19,40 @@ VKAPI_ATTR VkBool32 VKAPI_CALL DebugCallback(VkDebugUtilsMessageSeverityFlagBits const VkDebugUtilsMessengerCallbackDataEXT *data, void *userData) { - std::cerr << data->pMessage << std::endl; + const char* severity_cstr = nullptr; + switch(severity) { + case VK_DEBUG_UTILS_MESSAGE_SEVERITY_VERBOSE_BIT_EXT: + severity_cstr = "VERBOSE"; + break; + case VK_DEBUG_UTILS_MESSAGE_SEVERITY_INFO_BIT_EXT: + severity_cstr = "INFO"; + break; + case VK_DEBUG_UTILS_MESSAGE_SEVERITY_WARNING_BIT_EXT: + severity_cstr = "WARNING"; + break; + case VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT: + severity_cstr = "ERROR"; + break; + default: + break; + } + + const char* type_cstr = nullptr; + switch(type) { + case VK_DEBUG_UTILS_MESSAGE_TYPE_GENERAL_BIT_EXT: + type_cstr = "GENERAL"; + break; + case VK_DEBUG_UTILS_MESSAGE_TYPE_VALIDATION_BIT_EXT: + type_cstr = "VALIDATION"; + break; + case VK_DEBUG_UTILS_MESSAGE_TYPE_PERFORMANCE_BIT_EXT: + type_cstr = "PERFORMANCE"; + break; + default: + break; + } + + std::cerr << "[" << severity_cstr << "_" << type_cstr << "]: " << data->pMessage << std::endl; return VK_FALSE; } @@ -70,7 +103,7 @@ void vkcontext::create_instance() { #endif }; - check_available_instance_extensions(needed_layers, needed_extensions); + check_available_instance_extensions(needed_extensions); VkInstanceCreateInfo instance_create_info = {}; instance_create_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; @@ -182,9 +215,9 @@ void vkcontext::select_physical_device() { vkEnumeratePhysicalDevices(instance, &physical_devices_count, physical_devices.data()); - for (auto& physical_device: physical_devices) { - if (support_required_features(physical_device)) { - this->physical_device = physical_device; + for (auto& physical_dev: physical_devices) { + if (support_required_features(physical_dev)) { + physical_device = physical_dev; } } @@ -199,7 +232,7 @@ void vkcontext::select_queue(VkQueueFlags queueUsage) { vkGetPhysicalDeviceQueueFamilyProperties(physical_device, &queue_properties_count, queue_properties.data()); for (uint32_t properties_index = 0; properties_index < queue_properties_count; properties_index++) { - if (queue_properties[properties_index].queueFlags & queueUsage) { + if ((queue_properties[properties_index].queueFlags & queueUsage) != 0U) { queue_index = properties_index; return; } @@ -229,7 +262,7 @@ void vkcontext::check_available_instance_layers(std::vector<const char*>& needed assert(available_needed_layers_count == needed_layers.size()); } -void vkcontext::check_available_instance_extensions(std::vector<const char*>& available_layers, std::vector<const char*>& needed_extensions) { +void vkcontext::check_available_instance_extensions(std::vector<const char*>& needed_extensions) { uint32_t vulkan_extensions_count = 0; vkEnumerateInstanceExtensionProperties(VK_NULL_HANDLE, &vulkan_extensions_count, VK_NULL_HANDLE); @@ -245,7 +278,7 @@ void vkcontext::check_available_instance_extensions(std::vector<const char*>& av } } - // assert(available_needed_extensions_count == needed_extensions.size()); + assert(available_needed_extensions_count == needed_extensions.size()); } bool vkcontext::support_required_features(VkPhysicalDevice physical_device) { diff --git a/src/vk-renderer.cpp b/src/vk-renderer.cpp index ed7129c..55039da 100644 --- a/src/vk-renderer.cpp +++ b/src/vk-renderer.cpp @@ -158,8 +158,8 @@ void vkrenderer::update_image(Texture* texture, void* data) { VKRESULT(vkWaitForFences(context.device, 1, &submission_fences[virtual_frame_index], VK_TRUE, UINT64_MAX)) } -void vkrenderer::update_buffer(Buffer* buffer, void* data, off_t offset, size_t size) { - auto device_buffer = api.get_buffer(buffer->device_buffer); +void vkrenderer::update_buffer(Buffer* buffer, void* data, off_t offset, size_t size) const { + auto device_buffer = vkrenderer::api.get_buffer(buffer->device_buffer); size_t dynamic_offset = buffer->isStatic ? 0 : buffer->size * virtual_frame_index; |
