aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorladevieq <ladevie.quentin@gmail.com>2022-08-04 23:35:13 +0200
committerladevieq <ladevie.quentin@gmail.com>2022-08-04 23:35:13 +0200
commit8279a357f6f35d58a4c81d84c3c44a7da687b170 (patch)
tree20e4dae3824bb485e34a43e44f6e468ed0afffd0 /src
parent969dd101a08997dc318207b6994201d5161d0bd3 (diff)
Fix most warnings
Diffstat (limited to 'src')
-rw-r--r--src/compute-renderpass.cpp4
-rw-r--r--src/main.cpp4
-rw-r--r--src/primitive-renderpass.cpp10
-rw-r--r--src/scene.cpp18
-rw-r--r--src/vec3.cpp2
-rw-r--r--src/vk-api.cpp68
-rw-r--r--src/vk-context.cpp49
-rw-r--r--src/vk-renderer.cpp4
8 files changed, 102 insertions, 57 deletions
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;