From 1332110bf49d5c724f17e221b00a13b8194e9299 Mon Sep 17 00:00:00 2001 From: prathikkaranth Date: Mon, 25 Aug 2025 11:59:35 +0530 Subject: [PATCH 1/7] [Fix] Fix for validation warning in ssao - vkAllocateDescriptorSets(): pAllocateInfo->pSetLayouts[0] binding 1 was created with VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER but VkDescriptorPool was not created with any VkDescriptorPoolSize::type with VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER --- VkRenderer/vk_engine.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/VkRenderer/vk_engine.cpp b/VkRenderer/vk_engine.cpp index 7b366ed..682aaf2 100644 --- a/VkRenderer/vk_engine.cpp +++ b/VkRenderer/vk_engine.cpp @@ -1260,7 +1260,8 @@ void VulkanEngine::draw_geometry(VkCommandBuffer cmd) { void VulkanEngine::init_descriptors() { // create a descriptor pool that will hold 10 sets with 1 image each std::vector sizes = {{VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1}, - {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1}}; + {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1}, + {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1}}; globalDescriptorAllocator.init(_device, 10, sizes); From f8e7addd764f1754b077c90c26b5b72d9a89d3d2 Mon Sep 17 00:00:00 2001 From: prathikkaranth Date: Mon, 25 Aug 2025 12:27:18 +0530 Subject: [PATCH 2/7] [Fix] Make sure each swapchain image has its ow semaphore per frame preventing preventing the validation error where the same semaphore was being reused before the previous presentation completed. --- VkRenderer/vk_engine.cpp | 30 ++++++++++++++++++++++++++---- VkRenderer/vk_engine.h | 6 +++++- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/VkRenderer/vk_engine.cpp b/VkRenderer/vk_engine.cpp index 682aaf2..4628873 100644 --- a/VkRenderer/vk_engine.cpp +++ b/VkRenderer/vk_engine.cpp @@ -555,7 +555,7 @@ void VulkanEngine::draw() { VkSemaphoreSubmitInfo waitInfo = vkinit::semaphore_submit_info(VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT_KHR, get_current_frame()._swapchainSemaphore); VkSemaphoreSubmitInfo signalInfo = - vkinit::semaphore_submit_info(VK_PIPELINE_STAGE_2_ALL_GRAPHICS_BIT, get_current_frame()._renderSemaphore); + vkinit::semaphore_submit_info(VK_PIPELINE_STAGE_2_ALL_GRAPHICS_BIT, get_current_render_semaphore(swapchainImageIndex)); const VkSubmitInfo2 submit = vkinit::submit_info(&cmdinfo, &signalInfo, &waitInfo); @@ -573,7 +573,7 @@ void VulkanEngine::draw() { presentInfo.pSwapchains = &_swapchain; presentInfo.swapchainCount = 1; - presentInfo.pWaitSemaphores = &get_current_frame()._renderSemaphore; + presentInfo.pWaitSemaphores = &get_current_render_semaphore(swapchainImageIndex); presentInfo.waitSemaphoreCount = 1; presentInfo.pImageIndices = &swapchainImageIndex; @@ -971,12 +971,10 @@ void VulkanEngine::init_sync_structures() { VkSemaphoreCreateInfo semaphoreCreateInfo = vkinit::semaphore_create_info(); VK_CHECK(vkCreateSemaphore(_device, &semaphoreCreateInfo, nullptr, &_frame._swapchainSemaphore)); - VK_CHECK(vkCreateSemaphore(_device, &semaphoreCreateInfo, nullptr, &_frame._renderSemaphore)); _mainDeletionQueue.push_function([=] { vkDestroyFence(_device, _frame._renderFence, nullptr); vkDestroySemaphore(_device, _frame._swapchainSemaphore, nullptr); - vkDestroySemaphore(_device, _frame._renderSemaphore, nullptr); }); } } @@ -1001,6 +999,30 @@ void VulkanEngine::create_swapchain(uint32_t width, uint32_t height) { _swapchain = vkbSwapchain.swapchain; _swapchainImages = vkbSwapchain.get_images().value(); _swapchainImageViews = vkbSwapchain.get_image_views().value(); + + // Create render semaphores for each swapchain image in each frame + VkSemaphoreCreateInfo semaphoreCreateInfo = vkinit::semaphore_create_info(); + for (auto &frame : _frames) { + // Clear any existing semaphores + for (VkSemaphore sem : frame._renderSemaphores) { + vkDestroySemaphore(_device, sem, nullptr); + } + + // Create new semaphores for each swapchain image + frame._renderSemaphores.clear(); + frame._renderSemaphores.resize(_swapchainImages.size()); + for (size_t i = 0; i < _swapchainImages.size(); i++) { + VK_CHECK(vkCreateSemaphore(_device, &semaphoreCreateInfo, nullptr, &frame._renderSemaphores[i])); + } + } + + _mainDeletionQueue.push_function([=] { + for (auto &frame : _frames) { + for (VkSemaphore sem : frame._renderSemaphores) { + vkDestroySemaphore(_device, sem, nullptr); + } + } + }); } void VulkanEngine::init_swapchain() { diff --git a/VkRenderer/vk_engine.h b/VkRenderer/vk_engine.h index 32b1e47..42591a7 100644 --- a/VkRenderer/vk_engine.h +++ b/VkRenderer/vk_engine.h @@ -28,7 +28,8 @@ struct FrameData { VkCommandBuffer _mainCommandBuffer; VkCommandBuffer _rtCommandBuffer; - VkSemaphore _swapchainSemaphore, _renderSemaphore; + VkSemaphore _swapchainSemaphore; + std::vector _renderSemaphores; // One per swapchain image VkFence _renderFence; DeletionQueue _deletionQueue; @@ -150,6 +151,9 @@ class VulkanEngine { FrameData _frames[FRAME_OVERLAP]; FrameData &get_current_frame() { return _frames[_frameNumber % FRAME_OVERLAP]; } + VkSemaphore &get_current_render_semaphore(uint32_t swapchainImageIndex) { + return get_current_frame()._renderSemaphores[swapchainImageIndex]; + } VkQueue _graphicsQueue{}; uint32_t _graphicsQueueFamily; From 2ec26c75fda2f72f09905dcd9751b415ec16c339 Mon Sep 17 00:00:00 2001 From: prathikkaranth Date: Mon, 25 Aug 2025 12:43:52 +0530 Subject: [PATCH 3/7] [Fix] Add VK_DESCRIPTOR_TYPE_STORAGE_BUFFER and VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR to descriptor pool config to fix validation warnings --- VkRenderer/vk_engine.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/VkRenderer/vk_engine.cpp b/VkRenderer/vk_engine.cpp index 4628873..01d8c46 100644 --- a/VkRenderer/vk_engine.cpp +++ b/VkRenderer/vk_engine.cpp @@ -1283,7 +1283,9 @@ void VulkanEngine::init_descriptors() { // create a descriptor pool that will hold 10 sets with 1 image each std::vector sizes = {{VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1}, {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1}, - {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1}}; + {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1}, + {VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, 1}, + {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1}}; globalDescriptorAllocator.init(_device, 10, sizes); From e22b3ba385e510d125c0a52fc18e7375dc53e3e3 Mon Sep 17 00:00:00 2001 From: prathikkaranth Date: Mon, 25 Aug 2025 17:12:58 +0530 Subject: [PATCH 4/7] [Fix] Increase pool size for loader descriptor allocator to fix warning --- VkRenderer/vk_engine.cpp | 2 +- VkRenderer/vk_loader.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/VkRenderer/vk_engine.cpp b/VkRenderer/vk_engine.cpp index 01d8c46..a74052c 100644 --- a/VkRenderer/vk_engine.cpp +++ b/VkRenderer/vk_engine.cpp @@ -1283,7 +1283,7 @@ void VulkanEngine::init_descriptors() { // create a descriptor pool that will hold 10 sets with 1 image each std::vector sizes = {{VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1}, {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1}, - {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1}, + {VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 5}, {VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, 1}, {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1}}; diff --git a/VkRenderer/vk_loader.cpp b/VkRenderer/vk_loader.cpp index 60b85f5..b26964f 100644 --- a/VkRenderer/vk_loader.cpp +++ b/VkRenderer/vk_loader.cpp @@ -188,7 +188,7 @@ std::optional> loadGltf(VulkanEngine *engine, std::s } // we can stimate the descriptors we will need accurately - std::vector sizes = {{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 3}, + std::vector sizes = {{VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 5}, {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 3}, {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1}}; From 06d0386aa8969015093fea3025a0fe0275c265e8 Mon Sep 17 00:00:00 2001 From: prathikkaranth Date: Mon, 25 Aug 2025 18:25:35 +0530 Subject: [PATCH 5/7] [Fix] Cleanup compiler warnings --- VkRenderer/VulkanGeometryKHR.cpp | 2 +- VkRenderer/VulkanResourceManager.cpp | 4 +--- VkRenderer/VulkanResourceManager.h | 2 +- VkRenderer/raytracer.h | 7 ------ VkRenderer/ssao.cpp | 12 +++++----- VkRenderer/ssao.h | 4 ++-- VkRenderer/vk_descriptors.cpp | 12 +++++----- VkRenderer/vk_descriptors.h | 10 ++++---- VkRenderer/vk_engine.cpp | 36 +++++++++++++--------------- VkRenderer/vk_engine.h | 3 +-- VkRenderer/vk_loader.cpp | 4 ++-- 11 files changed, 42 insertions(+), 54 deletions(-) diff --git a/VkRenderer/VulkanGeometryKHR.cpp b/VkRenderer/VulkanGeometryKHR.cpp index f99e47a..bd856e5 100644 --- a/VkRenderer/VulkanGeometryKHR.cpp +++ b/VkRenderer/VulkanGeometryKHR.cpp @@ -43,7 +43,7 @@ namespace experirender::vk { // The entire array will be used to build the BLAS VkAccelerationStructureBuildRangeInfoKHR offset{ .primitiveCount = max_primitive_count, - .primitiveOffset = mesh.firstIndex * sizeof(std::uint32_t), + .primitiveOffset = static_cast(mesh.firstIndex * sizeof(std::uint32_t)), .firstVertex = 0, .transformOffset = 0, }; diff --git a/VkRenderer/VulkanResourceManager.cpp b/VkRenderer/VulkanResourceManager.cpp index c0206fd..3f8c356 100644 --- a/VkRenderer/VulkanResourceManager.cpp +++ b/VkRenderer/VulkanResourceManager.cpp @@ -2,8 +2,6 @@ #include #include "vk_engine.h" #include "vk_images.h" -#include "vk_initializers.h" -#include "vk_utils.h" void VulkanResourceManager::init(VulkanEngine *engine) { _engine = engine; @@ -11,7 +9,7 @@ void VulkanResourceManager::init(VulkanEngine *engine) { createDefaultSamplers(); } -void VulkanResourceManager::cleanup() { +void VulkanResourceManager::cleanup() const { if (!_engine) return; diff --git a/VkRenderer/VulkanResourceManager.h b/VkRenderer/VulkanResourceManager.h index 27f85c6..a1212ab 100644 --- a/VkRenderer/VulkanResourceManager.h +++ b/VkRenderer/VulkanResourceManager.h @@ -13,7 +13,7 @@ class VulkanResourceManager { // Initialize with engine reference void init(VulkanEngine *engine); - void cleanup(); + void cleanup() const; // Default texture resources AllocatedImage getWhiteImage() const { return _whiteImage; } diff --git a/VkRenderer/raytracer.h b/VkRenderer/raytracer.h index 956109c..5278565 100644 --- a/VkRenderer/raytracer.h +++ b/VkRenderer/raytracer.h @@ -1,15 +1,8 @@ #pragma once -#include -#include #include -#include #include -#include #include -#include - -#include "VkBootstrap.h" class VulkanEngine; diff --git a/VkRenderer/ssao.cpp b/VkRenderer/ssao.cpp index 46d3364..91f4151 100644 --- a/VkRenderer/ssao.cpp +++ b/VkRenderer/ssao.cpp @@ -34,7 +34,7 @@ void ssao::init_ssao(VulkanEngine *engine) { _ssaoInputDescriptors = engine->globalDescriptorAllocator.allocate(engine->_device, _ssaoInputDescriptorLayout); engine->_mainDeletionQueue.push_function( - [=] { vkDestroyDescriptorSetLayout(engine->_device, _ssaoInputDescriptorLayout, nullptr); }); + [=, this] { vkDestroyDescriptorSetLayout(engine->_device, _ssaoInputDescriptorLayout, nullptr); }); VkPipelineLayoutCreateInfo ssao_layout_info{}; ssao_layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; @@ -66,7 +66,7 @@ void ssao::init_ssao(VulkanEngine *engine) { VK_CHECK(vkCreateComputePipelines(engine->_device, VK_NULL_HANDLE, 1, &ssaoPipelineInfo, nullptr, &_ssaoPipeline)); vkDestroyShaderModule(engine->_device, ssaoDrawShader, nullptr); - engine->_mainDeletionQueue.push_function([=] { + engine->_mainDeletionQueue.push_function([=, this] { vkDestroyPipelineLayout(engine->_device, _ssaoPipelineLayout, nullptr); vkDestroyPipeline(engine->_device, _ssaoPipeline, nullptr); vkutil::destroy_image(engine, _ssaoImage); @@ -93,7 +93,7 @@ void ssao::init_ssao_blur(VulkanEngine *engine) { engine->globalDescriptorAllocator.allocate(engine->_device, _ssaoBlurInputDescriptorLayout); engine->_mainDeletionQueue.push_function( - [=] { vkDestroyDescriptorSetLayout(engine->_device, _ssaoBlurInputDescriptorLayout, nullptr); }); + [=, this] { vkDestroyDescriptorSetLayout(engine->_device, _ssaoBlurInputDescriptorLayout, nullptr); }); VkPipelineLayoutCreateInfo ssao_blur_layout_info{}; ssao_blur_layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; @@ -133,7 +133,7 @@ void ssao::init_ssao_blur(VulkanEngine *engine) { vkCreateSampler(engine->_device, &sampl, nullptr, &_ssaoSampler); vkDestroyShaderModule(engine->_device, ssaoBlurDrawShader, nullptr); - engine->_mainDeletionQueue.push_function([=] { + engine->_mainDeletionQueue.push_function([=, this] { vkDestroyPipelineLayout(engine->_device, _ssaoBlurPipelineLayout, nullptr); vkDestroyPipeline(engine->_device, _ssaoBlurPipeline, nullptr); vkDestroySampler(engine->_device, _ssaoSampler, nullptr); @@ -143,7 +143,7 @@ void ssao::init_ssao_blur(VulkanEngine *engine) { float ssao::ssaoLerp(float a, float b, float f) { return a + f * (b - a); } -std::vector ssao::generate_ssao_kernels() { +std::vector ssao::generate_ssao_kernels() const { // generate sample kernel // ---------------------- @@ -194,7 +194,7 @@ void ssao::init_ssao_data(VulkanEngine *engine) { ssaoData.samples[i] = glm::vec4(ssaoKernel[i], 1.0); } - engine->_mainDeletionQueue.push_function([=] { vkutil::destroy_image(engine, _ssaoNoiseImage); }); + engine->_mainDeletionQueue.push_function([=, this] { vkutil::destroy_image(engine, _ssaoNoiseImage); }); } diff --git a/VkRenderer/ssao.h b/VkRenderer/ssao.h index 64fffab..de6ff3a 100644 --- a/VkRenderer/ssao.h +++ b/VkRenderer/ssao.h @@ -40,8 +40,8 @@ class ssao { AllocatedImage _ssaoNoiseImage{}; // SSAO - std::vector generate_ssao_kernels(); - float ssaoLerp(float a, float b, float f); + std::vector generate_ssao_kernels() const; + static float ssaoLerp(float a, float b, float f); void init_ssao_data(VulkanEngine *engine); void init_ssao(VulkanEngine *engine); void init_ssao_blur(VulkanEngine *engine); diff --git a/VkRenderer/vk_descriptors.cpp b/VkRenderer/vk_descriptors.cpp index ed9cd96..c9a14be 100644 --- a/VkRenderer/vk_descriptors.cpp +++ b/VkRenderer/vk_descriptors.cpp @@ -55,7 +55,7 @@ void DescriptorAllocator::init_pool(VkDevice device, uint32_t maxSets, std::span std::vector poolSizes; for (PoolSizeRatio ratio: poolRatios) { poolSizes.push_back( - VkDescriptorPoolSize{.type = ratio.type, .descriptorCount = uint32_t(ratio.ratio * maxSets)}); + VkDescriptorPoolSize{.type = ratio.type, .descriptorCount = (static_cast(ratio.ratio) * maxSets)}); } VkDescriptorPoolCreateInfo pool_info = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO}; @@ -67,11 +67,11 @@ void DescriptorAllocator::init_pool(VkDevice device, uint32_t maxSets, std::span vkCreateDescriptorPool(device, &pool_info, nullptr, &pool); } -void DescriptorAllocator::clear_descriptors(VkDevice device) { vkResetDescriptorPool(device, pool, 0); } +void DescriptorAllocator::clear_descriptors(VkDevice device) const { vkResetDescriptorPool(device, pool, 0); } -void DescriptorAllocator::destroy_pool(VkDevice device) { vkDestroyDescriptorPool(device, pool, nullptr); } +void DescriptorAllocator::destroy_pool(VkDevice device) const { vkDestroyDescriptorPool(device, pool, nullptr); } -VkDescriptorSet DescriptorAllocator::allocate(VkDevice device, VkDescriptorSetLayout layout) { +VkDescriptorSet DescriptorAllocator::allocate(VkDevice device, VkDescriptorSetLayout layout) const { VkDescriptorSetAllocateInfo allocInfo = {}; allocInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO; allocInfo.pNext = nullptr; @@ -87,7 +87,7 @@ VkDescriptorSet DescriptorAllocator::allocate(VkDevice device, VkDescriptorSetLa VkDescriptorPool DescriptorAllocatorGrowable::get_pool(VkDevice device) { VkDescriptorPool newPool; - if (readyPools.size() != 0) { + if (!readyPools.empty()) { newPool = readyPools.back(); readyPools.pop_back(); } else { @@ -108,7 +108,7 @@ VkDescriptorPool DescriptorAllocatorGrowable::create_pool(VkDevice device, uint3 std::vector poolSizes; for (PoolSizeRatio ratio: poolRatios) { poolSizes.push_back( - VkDescriptorPoolSize{.type = ratio.type, .descriptorCount = uint32_t(ratio.ratio * setCount)}); + VkDescriptorPoolSize{.type = ratio.type, .descriptorCount = static_cast(ratio.ratio) * setCount}); } VkDescriptorPoolCreateInfo pool_info = {}; diff --git a/VkRenderer/vk_descriptors.h b/VkRenderer/vk_descriptors.h index a7f6481..f43ffc6 100644 --- a/VkRenderer/vk_descriptors.h +++ b/VkRenderer/vk_descriptors.h @@ -26,10 +26,10 @@ struct DescriptorAllocator { VkDescriptorPool pool; void init_pool(VkDevice device, uint32_t maxSets, std::span poolRatios); - void clear_descriptors(VkDevice device); - void destroy_pool(VkDevice device); + void clear_descriptors(VkDevice device) const; + void destroy_pool(VkDevice device) const; - VkDescriptorSet allocate(VkDevice device, VkDescriptorSetLayout layout); + VkDescriptorSet allocate(VkDevice device, VkDescriptorSetLayout layout) const; }; struct DescriptorAllocatorGrowable { @@ -47,12 +47,12 @@ struct DescriptorAllocatorGrowable { private: VkDescriptorPool get_pool(VkDevice device); - VkDescriptorPool create_pool(VkDevice device, uint32_t setCount, std::span poolRatios); + static VkDescriptorPool create_pool(VkDevice device, uint32_t setCount, std::span poolRatios); std::vector ratios; std::vector fullPools; std::vector readyPools; - uint32_t setsPerPool; + uint32_t setsPerPool = 0; }; struct DescriptorWriter { diff --git a/VkRenderer/vk_engine.cpp b/VkRenderer/vk_engine.cpp index a74052c..1894cb6 100644 --- a/VkRenderer/vk_engine.cpp +++ b/VkRenderer/vk_engine.cpp @@ -200,7 +200,7 @@ void VulkanEngine::init_default_data() { _resourceManager.init(this); // Add resource manager cleanup to deletion queue - _mainDeletionQueue.push_function([=] { _resourceManager.cleanup(); }); + _mainDeletionQueue.push_function([=, this] { _resourceManager.cleanup(); }); // Shadow light map _shadowMap.init_lightSpaceMatrix(this); @@ -527,7 +527,7 @@ void VulkanEngine::draw() { // Clear the swapchain before drawing UI VkClearValue clearValue = {}; - clearValue.color = {0.0f, 0.0f, 0.0f, 1.0f}; // Black background + clearValue.color = {{0.0f, 0.0f, 0.0f, 1.0f}}; // Black background VkRenderingAttachmentInfo colorAttachment = vkinit::attachment_info( _swapchainImageViews[swapchainImageIndex], &clearValue, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL); @@ -939,7 +939,7 @@ void VulkanEngine::init_commands() { VK_CHECK(vkAllocateCommandBuffers(_device, &cmdAllocInfo, &_frame._mainCommandBuffer)); - _mainDeletionQueue.push_function([=] { vkDestroyCommandPool(_device, _frame._commandPool, nullptr); }); + _mainDeletionQueue.push_function([=, this] { vkDestroyCommandPool(_device, _frame._commandPool, nullptr); }); } VK_CHECK(vkCreateCommandPool(_device, &commandPoolInfo, nullptr, &_immCommandPool)); @@ -949,7 +949,7 @@ void VulkanEngine::init_commands() { VK_CHECK(vkAllocateCommandBuffers(_device, &cmdAllocInfo, &_immCommandBuffer)); - _mainDeletionQueue.push_function([=] { vkDestroyCommandPool(_device, _immCommandPool, nullptr); }); + _mainDeletionQueue.push_function([=, this] { vkDestroyCommandPool(_device, _immCommandPool, nullptr); }); } void VulkanEngine::init_sync_structures() { @@ -962,7 +962,7 @@ void VulkanEngine::init_sync_structures() { const VkFenceCreateInfo fenceCreateInfo = vkinit::fence_create_info(VK_FENCE_CREATE_SIGNALED_BIT); VK_CHECK(vkCreateFence(_device, &fenceCreateInfo, nullptr, &_immFence)); - _mainDeletionQueue.push_function([=] { vkDestroyFence(_device, _immFence, nullptr); }); + _mainDeletionQueue.push_function([=, this] { vkDestroyFence(_device, _immFence, nullptr); }); for (auto &_frame: _frames) { @@ -972,7 +972,7 @@ void VulkanEngine::init_sync_structures() { VK_CHECK(vkCreateSemaphore(_device, &semaphoreCreateInfo, nullptr, &_frame._swapchainSemaphore)); - _mainDeletionQueue.push_function([=] { + _mainDeletionQueue.push_function([=, this] { vkDestroyFence(_device, _frame._renderFence, nullptr); vkDestroySemaphore(_device, _frame._swapchainSemaphore, nullptr); }); @@ -1016,7 +1016,7 @@ void VulkanEngine::create_swapchain(uint32_t width, uint32_t height) { } } - _mainDeletionQueue.push_function([=] { + _mainDeletionQueue.push_function([=, this] { for (auto &frame : _frames) { for (VkSemaphore sem : frame._renderSemaphores) { vkDestroySemaphore(_device, sem, nullptr); @@ -1075,7 +1075,7 @@ void VulkanEngine::init_swapchain() { VK_CHECK(vkCreateImageView(_device, &dview_info, nullptr, &_depthImage.imageView)); // add to deletion queues - _mainDeletionQueue.push_function([=] { + _mainDeletionQueue.push_function([=, this] { vkDestroyImageView(_device, _drawImage.imageView, nullptr); vmaDestroyImage(_allocator, _drawImage.image, _drawImage.allocation); @@ -1139,7 +1139,7 @@ void VulkanEngine::draw_geometry(VkCommandBuffer cmd) { std::vector opaque_draws; opaque_draws.reserve(mainDrawContext.OpaqueSurfaces.size()); - for (int i = 0; i < mainDrawContext.OpaqueSurfaces.size(); i++) { + for (int i = 0; i < static_cast(mainDrawContext.OpaqueSurfaces.size()); i++) { /*if (is_visible(mainDrawContext.OpaqueSurfaces[i], sceneData.viewproj)) {*/ opaque_draws.push_back(i); /*}*/ @@ -1545,7 +1545,7 @@ void GLTFMetallic_Roughness::build_pipelines(VulkanEngine *engine) { vkDestroyShaderModule(engine->_device, meshFragShader, nullptr); vkDestroyShaderModule(engine->_device, meshVertexShader, nullptr); - engine->_mainDeletionQueue.push_function([=] { + engine->_mainDeletionQueue.push_function([=, this] { vkDestroyDescriptorSetLayout(engine->_device, materialLayout, nullptr); vkDestroyPipelineLayout(engine->_device, newLayout, nullptr); vkDestroyPipeline(engine->_device, opaquePipeline.pipeline, nullptr); @@ -1606,8 +1606,6 @@ MaterialInstance GLTFMetallic_Roughness::write_material(VulkanEngine *engine, Vk return matData; } -void GLTFMetallic_Roughness::clear_resources(VkDevice device) {} - void MeshNode::Draw(const glm::mat4 &topMatrix, DrawContext &ctx) { const glm::mat4 nodeMatrix = topMatrix * worldTransform; @@ -1719,7 +1717,7 @@ void VulkanEngine::save_screenshot_full() { // Save as PNG (BGRA -> RGBA conversion needed for swapchain format) std::vector rgba_data(_swapchainExtent.width * _swapchainExtent.height * 4); - uint8_t *src = static_cast(data); + const auto *src = static_cast(data); for (uint32_t i = 0; i < _swapchainExtent.width * _swapchainExtent.height; i++) { rgba_data[i * 4 + 0] = src[i * 4 + 2]; // R = B @@ -1728,8 +1726,8 @@ void VulkanEngine::save_screenshot_full() { rgba_data[i * 4 + 3] = src[i * 4 + 3]; // A = A } - if (stbi_write_png(ss.str().c_str(), _swapchainExtent.width, _swapchainExtent.height, 4, rgba_data.data(), - _swapchainExtent.width * 4)) { + if (stbi_write_png(ss.str().c_str(), static_cast(_swapchainExtent.width), static_cast(_swapchainExtent.height), 4, rgba_data.data(), + static_cast(_swapchainExtent.width * 4))) { spdlog::info("Full screenshot saved: {}", ss.str()); } else { spdlog::error("Failed to save full screenshot: {}", ss.str()); @@ -1739,7 +1737,7 @@ void VulkanEngine::save_screenshot_full() { vkutil::destroy_buffer(this, stagingBuffer); } -void VulkanEngine::save_screenshot_render_only() { +void VulkanEngine::save_screenshot_render_only() const { // Wait for current frame to complete vkDeviceWaitIdle(_device); @@ -1791,7 +1789,7 @@ void VulkanEngine::save_screenshot_render_only() { << std::setw(3) << ms.count() << ".png"; // Convert HDR float data to LDR uint8 (raw conversion, no tone mapping) - float *src = static_cast(data); + const auto src = static_cast(data); std::vector ldr_data(finalImage.imageExtent.width * finalImage.imageExtent.height * 3); for (uint32_t i = 0; i < finalImage.imageExtent.width * finalImage.imageExtent.height; i++) { @@ -1805,8 +1803,8 @@ void VulkanEngine::save_screenshot_render_only() { ldr_data[i * 3 + 2] = static_cast(std::clamp(b * 255.0f, 0.0f, 255.0f)); } - if (stbi_write_png(ss.str().c_str(), finalImage.imageExtent.width, finalImage.imageExtent.height, 3, - ldr_data.data(), finalImage.imageExtent.width * 3)) { + if (stbi_write_png(ss.str().c_str(), static_cast(finalImage.imageExtent.width), static_cast(finalImage.imageExtent.height), 3, + ldr_data.data(), static_cast(finalImage.imageExtent.width * 3))) { spdlog::info("Render-only screenshot saved: {}", ss.str()); } else { spdlog::error("Failed to save render-only screenshot: {}", ss.str()); diff --git a/VkRenderer/vk_engine.h b/VkRenderer/vk_engine.h index 42591a7..b5ff7a3 100644 --- a/VkRenderer/vk_engine.h +++ b/VkRenderer/vk_engine.h @@ -141,7 +141,6 @@ class VulkanEngine { bool useRaytracer{false}; // Ray tracing - void traverseLoadedMeshNodesOnceForRT(); Raytracer raytracerPipeline; VkExtent2D _windowExtent{RenderConfig::getDefaultWindowExtent()}; @@ -264,7 +263,7 @@ class VulkanEngine { // Screenshot functions void save_screenshot_full(); - void save_screenshot_render_only(); + void save_screenshot_render_only() const; #ifdef NSIGHT_AFTERMATH_ENABLED // Helper functions for GPU crash markers diff --git a/VkRenderer/vk_loader.cpp b/VkRenderer/vk_loader.cpp index b26964f..244c5ba 100644 --- a/VkRenderer/vk_loader.cpp +++ b/VkRenderer/vk_loader.cpp @@ -499,7 +499,7 @@ std::optional> loadGltf(VulkanEngine *engine, std::s // loop the vertices of this surface, find min/max bounds glm::vec3 minpos = vertices[initial_vtx].position; glm::vec3 maxpos = vertices[initial_vtx].position; - for (int i = static_cast(initial_vtx); i < vertices.size(); i++) { + for (int i = static_cast(initial_vtx); i < static_cast(vertices.size()); i++) { minpos = glm::min(minpos, vertices[i].position); maxpos = glm::max(maxpos, vertices[i].position); } @@ -553,7 +553,7 @@ std::optional> loadGltf(VulkanEngine *engine, std::s } // run loop again to setup transform hierarchy - for (int i = 0; i < gltf.nodes.size(); i++) { + for (int i = 0; i < static_cast(gltf.nodes.size()); i++) { fastgltf::Node &node = gltf.nodes[i]; std::shared_ptr &sceneNode = nodes[i]; From 4f0f937114e800b4817ff6b9c91b93721956ca7b Mon Sep 17 00:00:00 2001 From: prathikkaranth Date: Mon, 25 Aug 2025 22:30:39 +0530 Subject: [PATCH 6/7] [Fix] Cleanup some compiler warnings --- VkRenderer/Hdri.cpp | 6 +++--- VkRenderer/Hdri.h | 1 - VkRenderer/cube.cpp | 4 +--- VkRenderer/cube.h | 2 +- VkRenderer/gbuffer.cpp | 8 ++++---- VkRenderer/main.cpp | 2 +- VkRenderer/postprocess.cpp | 20 ++++++++++---------- VkRenderer/raytracer.cpp | 22 +++++++++++----------- VkRenderer/raytracer.h | 2 +- VkRenderer/shadowmap.cpp | 4 ++-- VkRenderer/shadowmap.h | 7 ------- VkRenderer/ssao.h | 9 +-------- VkRenderer/vk_engine.cpp | 2 +- VkRenderer/vk_loader.cpp | 3 ++- VkRenderer/vk_loader.h | 6 ++---- 15 files changed, 40 insertions(+), 58 deletions(-) diff --git a/VkRenderer/Hdri.cpp b/VkRenderer/Hdri.cpp index 8d3a8ab..b12f505 100644 --- a/VkRenderer/Hdri.cpp +++ b/VkRenderer/Hdri.cpp @@ -147,7 +147,7 @@ void HDRI::load_hdri_to_buffer_fallback(VulkanEngine *engine) { stbi_set_flip_vertically_on_load(false); - engine->_mainDeletionQueue.push_function([=] { + engine->_mainDeletionQueue.push_function([=, this] { vkDestroySampler(engine->_device, _hdriMapSampler, nullptr); vkutil::destroy_image(engine, _hdriMap); }); @@ -233,12 +233,12 @@ void HDRI::init_hdriMap(VulkanEngine *engine) { vkDestroyShaderModule(engine->_device, skyboxVertShader, nullptr); vkDestroyShaderModule(engine->_device, skyboxFragShader, nullptr); - engine->_mainDeletionQueue.push_function([=] { cleanup(engine); }); + engine->_mainDeletionQueue.push_function([=, this] { cleanup(engine); }); } void HDRI::draw_hdriMap(VulkanEngine *engine, VkCommandBuffer cmd) { - VkClearValue clearVal = {.color = {0.0f, 0.0f, 0.0f, 1.0f}}; + VkClearValue clearVal = {.color = {{0.0f, 0.0f, 0.0f, 1.0f}}}; std::array colorAttachments = { vkinit::attachment_info(engine->_drawImage.imageView, &clearVal, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL), diff --git a/VkRenderer/Hdri.h b/VkRenderer/Hdri.h index 98bbed7..fd95cf8 100644 --- a/VkRenderer/Hdri.h +++ b/VkRenderer/Hdri.h @@ -1,5 +1,4 @@ #pragma once -#include #include #include "vk_types.h" diff --git a/VkRenderer/cube.cpp b/VkRenderer/cube.cpp index 94ff5a4..656389f 100644 --- a/VkRenderer/cube.cpp +++ b/VkRenderer/cube.cpp @@ -3,7 +3,6 @@ #include "vk_buffers.h" #include "vk_descriptors.h" #include "vk_engine.h" -#include "vk_initializers.h" #include "vk_pipelines.h" void CubePipeline::init(VulkanEngine *engine) { @@ -58,7 +57,6 @@ void CubePipeline::init(VulkanEngine *engine) { vkDestroyShaderModule(engine->_device, cubeFragShader, nullptr); hasPipeline = true; - spdlog::info("Cube pipeline created successfully"); // Add to deletion queue engine->_mainDeletionQueue.push_function([=, this]() { destroy(); }); @@ -81,7 +79,7 @@ void CubePipeline::destroy() { hasPipeline = false; } -void CubePipeline::draw(VulkanEngine *engine, VkCommandBuffer cmd) { +void CubePipeline::draw(VulkanEngine *engine, VkCommandBuffer cmd) const { if (!hasPipeline) return; diff --git a/VkRenderer/cube.h b/VkRenderer/cube.h index 648b943..d064b84 100644 --- a/VkRenderer/cube.h +++ b/VkRenderer/cube.h @@ -6,7 +6,7 @@ class VulkanEngine; class CubePipeline { public: void init(VulkanEngine *engine); - void draw(VulkanEngine *engine, VkCommandBuffer cmd); + void draw(VulkanEngine *engine, VkCommandBuffer cmd) const; void destroy(); bool isInitialized() const { return hasPipeline; } diff --git a/VkRenderer/gbuffer.cpp b/VkRenderer/gbuffer.cpp index 0d77684..9904695 100644 --- a/VkRenderer/gbuffer.cpp +++ b/VkRenderer/gbuffer.cpp @@ -80,7 +80,7 @@ void Gbuffer::init_gbuffer(VulkanEngine *engine) { vkDestroyShaderModule(engine->_device, gbufferFragShader, nullptr); vkDestroyShaderModule(engine->_device, gbufferVertexShader, nullptr); - engine->_mainDeletionQueue.push_function([=] { + engine->_mainDeletionQueue.push_function([=, this] { vkDestroyPipelineLayout(engine->_device, _gbufferPipelineLayout, nullptr); vkDestroyDescriptorSetLayout(engine->_device, _gbufferInputDescriptorLayout, nullptr); vkDestroyPipeline(engine->_device, _gbufferPipeline, nullptr); @@ -104,7 +104,7 @@ void Gbuffer::draw_gbuffer(VulkanEngine *engine, VkCommandBuffer cmd) { gbuffer_writer.update_set(engine->_device, _gbufferInputDescriptors); - VkClearValue clearVal = {.color = {0.0f, 0.0f, 0.0f, 1.0f}}; + VkClearValue clearVal = {.color = {{0.0f, 0.0f, 0.0f, 1.0f}}}; // begin a render pass connected to our draw image VkRenderingAttachmentInfo depthAttachment = vkinit::depth_attachment_info(engine->_depthImage.imageView, VK_IMAGE_LAYOUT_DEPTH_ATTACHMENT_OPTIMAL); @@ -126,7 +126,7 @@ void Gbuffer::draw_gbuffer(VulkanEngine *engine, VkCommandBuffer cmd) { std::vector opaque_draws; opaque_draws.reserve(engine->mainDrawContext.OpaqueSurfaces.size()); - for (int i = 0; i < engine->mainDrawContext.OpaqueSurfaces.size(); i++) { + for (int i = 0; i < static_cast(engine->mainDrawContext.OpaqueSurfaces.size()); i++) { /*if (is_visible(mainDrawContext.OpaqueSurfaces[i], sceneData.viewproj)) {*/ opaque_draws.push_back(i); @@ -151,7 +151,7 @@ void Gbuffer::draw_gbuffer(VulkanEngine *engine, VkCommandBuffer cmd) { // add it to the deletion queue of this frame so it gets deleted once its been used engine->get_current_frame()._deletionQueue.push_function( - [=, this]() { vkutil::destroy_buffer(engine, gpuSceneDataBuffer); }); + [=] { vkutil::destroy_buffer(engine, gpuSceneDataBuffer); }); // write the buffer vkutil::upload_to_buffer(engine, &engine->sceneData, sizeof(GPUSceneData), gpuSceneDataBuffer); diff --git a/VkRenderer/main.cpp b/VkRenderer/main.cpp index 2118d24..eef078c 100644 --- a/VkRenderer/main.cpp +++ b/VkRenderer/main.cpp @@ -1,6 +1,6 @@ #include -int main(int argc, char *argv[]) { +int main() { VulkanEngine engine; engine.init(); diff --git a/VkRenderer/postprocess.cpp b/VkRenderer/postprocess.cpp index 5def70a..0dffc37 100644 --- a/VkRenderer/postprocess.cpp +++ b/VkRenderer/postprocess.cpp @@ -15,7 +15,7 @@ void PostProcessor::init(VulkanEngine *engine) { // init FXAA data _fxaaData.R_inverseFilterTextureSize = - glm::vec3(1.0f / engine->_windowExtent.width, 1.0f / engine->_windowExtent.height, 0.0f); + glm::vec3(1.0f / static_cast(engine->_windowExtent.width), 1.0f / static_cast(engine->_windowExtent.height), 0.0f); _fxaaData.R_fxaaSpanMax = 8.0f; _fxaaData.R_fxaaReduceMin = 1.0f / 128.0f; _fxaaData.R_fxaaReduceMul = 1.0f / 8.0f; @@ -58,7 +58,7 @@ void PostProcessor::init(VulkanEngine *engine) { engine->globalDescriptorAllocator.allocate(engine->_device, _postProcessDescriptorSetLayout); engine->_mainDeletionQueue.push_function( - [=] { vkDestroyDescriptorSetLayout(engine->_device, _postProcessDescriptorSetLayout, nullptr); }); + [=, this] { vkDestroyDescriptorSetLayout(engine->_device, _postProcessDescriptorSetLayout, nullptr); }); VkPipelineLayoutCreateInfo post_process_layout_info{}; post_process_layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; @@ -69,7 +69,7 @@ void PostProcessor::init(VulkanEngine *engine) { VK_CHECK(vkCreatePipelineLayout(engine->_device, &post_process_layout_info, nullptr, &_postProcessPipelineLayout)); engine->_mainDeletionQueue.push_function( - [=] { vkDestroyPipelineLayout(engine->_device, _postProcessPipelineLayout, nullptr); }); + [=, this] { vkDestroyPipelineLayout(engine->_device, _postProcessPipelineLayout, nullptr); }); // layout code VkShaderModule fullscreenDrawVertShader; @@ -115,7 +115,7 @@ void PostProcessor::init(VulkanEngine *engine) { _fxaaDescriptorSet = engine->globalDescriptorAllocator.allocate(engine->_device, _fxaaDescriptorSetLayout); engine->_mainDeletionQueue.push_function( - [=] { vkDestroyDescriptorSetLayout(engine->_device, _fxaaDescriptorSetLayout, nullptr); }); + [=, this] { vkDestroyDescriptorSetLayout(engine->_device, _fxaaDescriptorSetLayout, nullptr); }); VkPipelineLayoutCreateInfo fxaa_layout_info{}; fxaa_layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; @@ -126,7 +126,7 @@ void PostProcessor::init(VulkanEngine *engine) { VK_CHECK(vkCreatePipelineLayout(engine->_device, &fxaa_layout_info, nullptr, &_fxaaPipelineLayout)); engine->_mainDeletionQueue.push_function( - [=] { vkDestroyPipelineLayout(engine->_device, _fxaaPipelineLayout, nullptr); }); + [=, this] { vkDestroyPipelineLayout(engine->_device, _fxaaPipelineLayout, nullptr); }); // FXAA shaders VkShaderModule fxaaVertShader; @@ -167,7 +167,7 @@ void PostProcessor::init(VulkanEngine *engine) { } engine->_mainDeletionQueue.push_function( - [=] { vkDestroyDescriptorSetLayout(engine->_device, _gridDescriptorSetLayout, nullptr); }); + [=, this] { vkDestroyDescriptorSetLayout(engine->_device, _gridDescriptorSetLayout, nullptr); }); VkPipelineLayoutCreateInfo grid_layout_info{}; grid_layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO; @@ -178,7 +178,7 @@ void PostProcessor::init(VulkanEngine *engine) { VK_CHECK(vkCreatePipelineLayout(engine->_device, &grid_layout_info, nullptr, &_gridPipelineLayout)); engine->_mainDeletionQueue.push_function( - [=] { vkDestroyPipelineLayout(engine->_device, _gridPipelineLayout, nullptr); }); + [=, this] { vkDestroyPipelineLayout(engine->_device, _gridPipelineLayout, nullptr); }); // Grid shaders VkShaderModule gridVertShader; @@ -209,7 +209,7 @@ void PostProcessor::init(VulkanEngine *engine) { vkDestroyShaderModule(engine->_device, gridFragShader, nullptr); vkDestroyShaderModule(engine->_device, gridVertShader, nullptr); - engine->_mainDeletionQueue.push_function([=] { + engine->_mainDeletionQueue.push_function([=, this] { vkDestroyPipeline(engine->_device, _postProcessPipeline, nullptr); vkDestroyPipeline(engine->_device, _fxaaPipeline, nullptr); vkDestroyPipeline(engine->_device, _gridPipeline, nullptr); @@ -220,7 +220,7 @@ void PostProcessor::init(VulkanEngine *engine) { } void PostProcessor::draw(VulkanEngine *engine, VkCommandBuffer cmd) { - VkClearValue clearVal = {.color = {0.0f, 0.0f, 0.0f, 1.0f}}; + VkClearValue clearVal = {.color = {{0.0f, 0.0f, 0.0f, 1.0f}}}; std::array colorAttachments = { vkinit::attachment_info(_fullscreenImage.imageView, &clearVal, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL), @@ -294,7 +294,7 @@ void PostProcessor::draw(VulkanEngine *engine, VkCommandBuffer cmd) { } void PostProcessor::draw_fxaa(VulkanEngine *engine, VkCommandBuffer cmd) { - VkClearValue clearVal = {.color = {0.0f, 0.0f, 0.0f, 1.0f}}; + VkClearValue clearVal = {.color = {{0.0f, 0.0f, 0.0f, 1.0f}}}; std::array colorAttachments = { vkinit::attachment_info(_fxaaImage.imageView, &clearVal, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL), diff --git a/VkRenderer/raytracer.cpp b/VkRenderer/raytracer.cpp index 78beaf4..c059cec 100644 --- a/VkRenderer/raytracer.cpp +++ b/VkRenderer/raytracer.cpp @@ -56,13 +56,13 @@ void Raytracer::createRtOutputImageOnly(VulkanEngine *engine) { "RT Output Image"); // Add to deletion queue - engine->_mainDeletionQueue.push_function([=] { vkutil::destroy_image(engine, _rtOutputImage); }); + engine->_mainDeletionQueue.push_function([=, this] { vkutil::destroy_image(engine, _rtOutputImage); }); } void Raytracer::createTopLevelAS(const VulkanEngine *engine) const { // TLAS - Storing each BLAS std::vector tlas; - const uint32_t totalSurfaces = static_cast(engine->mainDrawContext.OpaqueSurfaces.size() + + const auto totalSurfaces = static_cast(engine->mainDrawContext.OpaqueSurfaces.size() + engine->mainDrawContext.TransparentSurfaces.size()); tlas.reserve(totalSurfaces); @@ -98,7 +98,7 @@ void Raytracer::createTopLevelAS(const VulkanEngine *engine) const { } // Add transparent surfaces after opaque ones - const uint32_t opaqueCount = static_cast(engine->mainDrawContext.OpaqueSurfaces.size()); + const auto opaqueCount = static_cast(engine->mainDrawContext.OpaqueSurfaces.size()); for (std::uint32_t i = 0; i < static_cast(engine->mainDrawContext.TransparentSurfaces.size()); i++) { VkTransformMatrixKHR vk_transform = {}; const glm::mat4 &t = engine->mainDrawContext.TransparentSurfaces[i].transform; @@ -142,7 +142,7 @@ void Raytracer::createRtDescriptorSet(VulkanEngine *engine) { "RT Output Image"); // Add to deletion queue - engine->_mainDeletionQueue.push_function([=] { vkutil::destroy_image(engine, _rtOutputImage); }); + engine->_mainDeletionQueue.push_function([=, this] { vkutil::destroy_image(engine, _rtOutputImage); }); } { @@ -177,7 +177,7 @@ void Raytracer::createRtDescriptorSet(VulkanEngine *engine) { } std::vector objDescs; - const uint32_t totalSurfaces = static_cast(engine->mainDrawContext.OpaqueSurfaces.size() + + const auto totalSurfaces = static_cast(engine->mainDrawContext.OpaqueSurfaces.size() + engine->mainDrawContext.TransparentSurfaces.size()); objDescs.reserve(totalSurfaces); @@ -318,7 +318,7 @@ void Raytracer::createRtDescriptorSet(VulkanEngine *engine) { tex_writer.update_set(engine->_device, m_texDescSet); engine->_mainDeletionQueue.push_function( - [=] { vkDestroyDescriptorSetLayout(engine->_device, m_texSetLayout, nullptr); }); + [=, this] { vkDestroyDescriptorSetLayout(engine->_device, m_texSetLayout, nullptr); }); } // Mat descriptions @@ -377,7 +377,7 @@ void Raytracer::createRtDescriptorSet(VulkanEngine *engine) { mat_writer.update_set(engine->_device, m_matDescSet); - engine->_mainDeletionQueue.push_function([=] { + engine->_mainDeletionQueue.push_function([=, this] { vkDestroyDescriptorSetLayout(engine->_device, m_rtDescSetLayout, nullptr); vkDestroyDescriptorSetLayout(engine->_device, m_objDescSetLayout, nullptr); vkDestroyDescriptorSetLayout(engine->_device, m_matDescSetLayout, nullptr); @@ -513,7 +513,7 @@ void Raytracer::createRtPipeline(VulkanEngine *engine) { for (auto &s: stages) vkDestroyShaderModule(engine->_device, s.module, nullptr); - engine->_mainDeletionQueue.push_function([=] { + engine->_mainDeletionQueue.push_function([=, this] { vkDestroyPipelineLayout(engine->_device, m_rtPipelineLayout, nullptr); vkDestroyPipeline(engine->_device, m_rtPipeline, nullptr); }); @@ -587,7 +587,7 @@ void Raytracer::createRtShaderBindingTable(VulkanEngine *engine) { // Clean up vmaUnmapMemory(engine->_allocator, m_rtSBTBuffer.allocation); - engine->_mainDeletionQueue.push_function([=] { vkutil::destroy_buffer(engine, m_rtSBTBuffer); }); + engine->_mainDeletionQueue.push_function([=, this] { vkutil::destroy_buffer(engine, m_rtSBTBuffer); }); } void Raytracer::resetSamples() { @@ -598,7 +598,7 @@ void Raytracer::resetSamples() { //-------------------------------------------------------------------------------------------------- // Ray Tracing the scene // -void Raytracer::raytrace(VulkanEngine *engine, const VkCommandBuffer &cmdBuf, const glm::vec4 &clearColor) { +void Raytracer::raytrace(VulkanEngine *engine, const VkCommandBuffer &cmdBuf) { // Safety check: Don't raytrace if no geometry is loaded (acceleration structures not initialized) if (engine->mainDrawContext.OpaqueSurfaces.empty() && engine->mainDrawContext.TransparentSurfaces.empty()) { return; @@ -611,7 +611,7 @@ void Raytracer::raytrace(VulkanEngine *engine, const VkCommandBuffer &cmdBuf, co // add it to the deletion queue of this frame so it gets deleted once its been used engine->get_current_frame()._deletionQueue.push_function( - [=, this]() { vkutil::destroy_buffer(engine, gpuSceneDataBuffer); }); + [=] { vkutil::destroy_buffer(engine, gpuSceneDataBuffer); }); // write the buffer vkutil::upload_to_buffer(engine, &engine->sceneData, sizeof(GPUSceneData), gpuSceneDataBuffer); diff --git a/VkRenderer/raytracer.h b/VkRenderer/raytracer.h index 5278565..66c36de 100644 --- a/VkRenderer/raytracer.h +++ b/VkRenderer/raytracer.h @@ -37,7 +37,7 @@ class Raytracer { void createRtPipeline(VulkanEngine *engine); void createRtShaderBindingTable(VulkanEngine *engine); void resetSamples(); - void raytrace(VulkanEngine *engine, const VkCommandBuffer &cmdBuf, const glm::vec4 &clearColor); + void raytrace(VulkanEngine *engine, const VkCommandBuffer &cmdBuf); void rtSampleUpdates(const VulkanEngine *engine); void setRTDefaultData(); diff --git a/VkRenderer/shadowmap.cpp b/VkRenderer/shadowmap.cpp index 027e51e..b093507 100644 --- a/VkRenderer/shadowmap.cpp +++ b/VkRenderer/shadowmap.cpp @@ -102,7 +102,7 @@ void shadowMap::init_depthShadowMap(VulkanEngine *engine) { vkCreateSampler(engine->_device, &sampl2, nullptr, &_shadowDepthMapSampler); - engine->_mainDeletionQueue.push_function([=] { + engine->_mainDeletionQueue.push_function([=, this] { vkDestroyPipelineLayout(engine->_device, _depthShadowMapPipelineLayout, nullptr); vkDestroyPipeline(engine->_device, _depthShadowMapPipeline, nullptr); vkDestroySampler(engine->_device, _shadowDepthMapSampler, nullptr); @@ -130,7 +130,7 @@ void shadowMap::draw_depthShadowMap(VulkanEngine *engine, VkCommandBuffer cmd) c std::vector opaque_draws; opaque_draws.reserve(engine->mainDrawContext.OpaqueSurfaces.size()); - for (int i = 0; i < engine->mainDrawContext.OpaqueSurfaces.size(); i++) { + for (int i = 0; i < static_cast(engine->mainDrawContext.OpaqueSurfaces.size()); i++) { /*if (is_visible(mainDrawContext.OpaqueSurfaces[i], sceneData.viewproj)) {*/ opaque_draws.push_back(i); /*}*/ diff --git a/VkRenderer/shadowmap.h b/VkRenderer/shadowmap.h index 3aa085a..37f438b 100644 --- a/VkRenderer/shadowmap.h +++ b/VkRenderer/shadowmap.h @@ -1,14 +1,7 @@ #pragma once -#include #include -#include -#include -#include #include -#include - -#include "VkBootstrap.h" class VulkanEngine; diff --git a/VkRenderer/ssao.h b/VkRenderer/ssao.h index de6ff3a..2540930 100644 --- a/VkRenderer/ssao.h +++ b/VkRenderer/ssao.h @@ -1,13 +1,6 @@ #pragma once -#include -#include -#include -#include #include -#include - -#include "VkBootstrap.h" class VulkanEngine; @@ -40,7 +33,7 @@ class ssao { AllocatedImage _ssaoNoiseImage{}; // SSAO - std::vector generate_ssao_kernels() const; + [[nodiscard]] std::vector generate_ssao_kernels() const; static float ssaoLerp(float a, float b, float f); void init_ssao_data(VulkanEngine *engine); void init_ssao(VulkanEngine *engine); diff --git a/VkRenderer/vk_engine.cpp b/VkRenderer/vk_engine.cpp index 1894cb6..1ef682a 100644 --- a/VkRenderer/vk_engine.cpp +++ b/VkRenderer/vk_engine.cpp @@ -409,7 +409,7 @@ void VulkanEngine::draw() { if (useRaytracer) { // Raytracing path (grid not supported in raytracer mode yet) - raytracerPipeline.raytrace(this, cmd, glm::vec4(0.0f)); + raytracerPipeline.raytrace(this, cmd); vkutil::transition_image(cmd, raytracerPipeline._rtOutputImage.image, VK_IMAGE_LAYOUT_GENERAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, VK_IMAGE_ASPECT_COLOR_BIT); diff --git a/VkRenderer/vk_loader.cpp b/VkRenderer/vk_loader.cpp index 244c5ba..3e267fe 100644 --- a/VkRenderer/vk_loader.cpp +++ b/VkRenderer/vk_loader.cpp @@ -6,6 +6,7 @@ // header for std::visit #include +#include #include #include #include "stb_image.h" @@ -534,7 +535,7 @@ std::optional> loadGltf(VulkanEngine *engine, std::s file.nodes[node.name.c_str()]; std::visit(fastgltf::visitor{[&](fastgltf::math::fmat4x4 matrix) { - memcpy(&newNode->localTransform, matrix.data(), sizeof(matrix)); + newNode->localTransform = glm::make_mat4(matrix.data()); }, [&](fastgltf::TRS transform) { glm::vec3 tl(transform.translation[0], transform.translation[1], diff --git a/VkRenderer/vk_loader.h b/VkRenderer/vk_loader.h index 261ff4c..6414e46 100644 --- a/VkRenderer/vk_loader.h +++ b/VkRenderer/vk_loader.h @@ -58,11 +58,9 @@ struct LoadedGLTF : public IRenderable { VulkanEngine *creator; - ~LoadedGLTF() { clearAll(); }; + ~LoadedGLTF() override { clearAll(); }; - virtual void Draw(const glm::mat4 &topMatrix, DrawContext &ctx); - - void translateLoadedScene(glm::vec3 translation, DrawContext &ctx); + void Draw(const glm::mat4 &topMatrix, DrawContext &ctx) override; private: void clearAll(); From aa2198b8ba193a6d37e110e6429212b90ce0676e Mon Sep 17 00:00:00 2001 From: prathikkaranth Date: Mon, 25 Aug 2025 22:39:24 +0530 Subject: [PATCH 7/7] [Fix] Fix style check --- VkRenderer/postprocess.cpp | 4 ++-- VkRenderer/raytracer.cpp | 4 ++-- VkRenderer/vk_descriptors.cpp | 4 ++-- VkRenderer/vk_engine.cpp | 22 ++++++++++++---------- VkRenderer/vk_engine.h | 4 ++-- VkRenderer/vk_images.cpp | 4 ---- VkRenderer/vk_loader.cpp | 32 +++++++++++++++----------------- 7 files changed, 35 insertions(+), 39 deletions(-) diff --git a/VkRenderer/postprocess.cpp b/VkRenderer/postprocess.cpp index 0dffc37..d1d58a3 100644 --- a/VkRenderer/postprocess.cpp +++ b/VkRenderer/postprocess.cpp @@ -14,8 +14,8 @@ void PostProcessor::init(VulkanEngine *engine) { // validation error. Should debug this later. // init FXAA data - _fxaaData.R_inverseFilterTextureSize = - glm::vec3(1.0f / static_cast(engine->_windowExtent.width), 1.0f / static_cast(engine->_windowExtent.height), 0.0f); + _fxaaData.R_inverseFilterTextureSize = glm::vec3(1.0f / static_cast(engine->_windowExtent.width), + 1.0f / static_cast(engine->_windowExtent.height), 0.0f); _fxaaData.R_fxaaSpanMax = 8.0f; _fxaaData.R_fxaaReduceMin = 1.0f / 128.0f; _fxaaData.R_fxaaReduceMul = 1.0f / 8.0f; diff --git a/VkRenderer/raytracer.cpp b/VkRenderer/raytracer.cpp index c059cec..7cdb868 100644 --- a/VkRenderer/raytracer.cpp +++ b/VkRenderer/raytracer.cpp @@ -63,7 +63,7 @@ void Raytracer::createTopLevelAS(const VulkanEngine *engine) const { // TLAS - Storing each BLAS std::vector tlas; const auto totalSurfaces = static_cast(engine->mainDrawContext.OpaqueSurfaces.size() + - engine->mainDrawContext.TransparentSurfaces.size()); + engine->mainDrawContext.TransparentSurfaces.size()); tlas.reserve(totalSurfaces); // Add opaque surfaces first @@ -178,7 +178,7 @@ void Raytracer::createRtDescriptorSet(VulkanEngine *engine) { std::vector objDescs; const auto totalSurfaces = static_cast(engine->mainDrawContext.OpaqueSurfaces.size() + - engine->mainDrawContext.TransparentSurfaces.size()); + engine->mainDrawContext.TransparentSurfaces.size()); objDescs.reserve(totalSurfaces); // Add opaque surfaces first diff --git a/VkRenderer/vk_descriptors.cpp b/VkRenderer/vk_descriptors.cpp index c9a14be..98a373f 100644 --- a/VkRenderer/vk_descriptors.cpp +++ b/VkRenderer/vk_descriptors.cpp @@ -54,8 +54,8 @@ VkDescriptorSetLayout DescriptorLayoutBuilder::build(VkDevice device, VkShaderSt void DescriptorAllocator::init_pool(VkDevice device, uint32_t maxSets, std::span poolRatios) { std::vector poolSizes; for (PoolSizeRatio ratio: poolRatios) { - poolSizes.push_back( - VkDescriptorPoolSize{.type = ratio.type, .descriptorCount = (static_cast(ratio.ratio) * maxSets)}); + poolSizes.push_back(VkDescriptorPoolSize{.type = ratio.type, + .descriptorCount = (static_cast(ratio.ratio) * maxSets)}); } VkDescriptorPoolCreateInfo pool_info = {.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO}; diff --git a/VkRenderer/vk_engine.cpp b/VkRenderer/vk_engine.cpp index 1ef682a..0257ea3 100644 --- a/VkRenderer/vk_engine.cpp +++ b/VkRenderer/vk_engine.cpp @@ -554,8 +554,8 @@ void VulkanEngine::draw() { VkSemaphoreSubmitInfo waitInfo = vkinit::semaphore_submit_info(VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT_KHR, get_current_frame()._swapchainSemaphore); - VkSemaphoreSubmitInfo signalInfo = - vkinit::semaphore_submit_info(VK_PIPELINE_STAGE_2_ALL_GRAPHICS_BIT, get_current_render_semaphore(swapchainImageIndex)); + VkSemaphoreSubmitInfo signalInfo = vkinit::semaphore_submit_info(VK_PIPELINE_STAGE_2_ALL_GRAPHICS_BIT, + get_current_render_semaphore(swapchainImageIndex)); const VkSubmitInfo2 submit = vkinit::submit_info(&cmdinfo, &signalInfo, &waitInfo); @@ -1002,12 +1002,12 @@ void VulkanEngine::create_swapchain(uint32_t width, uint32_t height) { // Create render semaphores for each swapchain image in each frame VkSemaphoreCreateInfo semaphoreCreateInfo = vkinit::semaphore_create_info(); - for (auto &frame : _frames) { + for (auto &frame: _frames) { // Clear any existing semaphores - for (VkSemaphore sem : frame._renderSemaphores) { + for (VkSemaphore sem: frame._renderSemaphores) { vkDestroySemaphore(_device, sem, nullptr); } - + // Create new semaphores for each swapchain image frame._renderSemaphores.clear(); frame._renderSemaphores.resize(_swapchainImages.size()); @@ -1017,8 +1017,8 @@ void VulkanEngine::create_swapchain(uint32_t width, uint32_t height) { } _mainDeletionQueue.push_function([=, this] { - for (auto &frame : _frames) { - for (VkSemaphore sem : frame._renderSemaphores) { + for (auto &frame: _frames) { + for (VkSemaphore sem: frame._renderSemaphores) { vkDestroySemaphore(_device, sem, nullptr); } } @@ -1726,7 +1726,8 @@ void VulkanEngine::save_screenshot_full() { rgba_data[i * 4 + 3] = src[i * 4 + 3]; // A = A } - if (stbi_write_png(ss.str().c_str(), static_cast(_swapchainExtent.width), static_cast(_swapchainExtent.height), 4, rgba_data.data(), + if (stbi_write_png(ss.str().c_str(), static_cast(_swapchainExtent.width), + static_cast(_swapchainExtent.height), 4, rgba_data.data(), static_cast(_swapchainExtent.width * 4))) { spdlog::info("Full screenshot saved: {}", ss.str()); } else { @@ -1803,8 +1804,9 @@ void VulkanEngine::save_screenshot_render_only() const { ldr_data[i * 3 + 2] = static_cast(std::clamp(b * 255.0f, 0.0f, 255.0f)); } - if (stbi_write_png(ss.str().c_str(), static_cast(finalImage.imageExtent.width), static_cast(finalImage.imageExtent.height), 3, - ldr_data.data(), static_cast(finalImage.imageExtent.width * 3))) { + if (stbi_write_png(ss.str().c_str(), static_cast(finalImage.imageExtent.width), + static_cast(finalImage.imageExtent.height), 3, ldr_data.data(), + static_cast(finalImage.imageExtent.width * 3))) { spdlog::info("Render-only screenshot saved: {}", ss.str()); } else { spdlog::error("Failed to save render-only screenshot: {}", ss.str()); diff --git a/VkRenderer/vk_engine.h b/VkRenderer/vk_engine.h index b5ff7a3..80701b4 100644 --- a/VkRenderer/vk_engine.h +++ b/VkRenderer/vk_engine.h @@ -150,8 +150,8 @@ class VulkanEngine { FrameData _frames[FRAME_OVERLAP]; FrameData &get_current_frame() { return _frames[_frameNumber % FRAME_OVERLAP]; } - VkSemaphore &get_current_render_semaphore(uint32_t swapchainImageIndex) { - return get_current_frame()._renderSemaphores[swapchainImageIndex]; + VkSemaphore &get_current_render_semaphore(uint32_t swapchainImageIndex) { + return get_current_frame()._renderSemaphores[swapchainImageIndex]; } VkQueue _graphicsQueue{}; diff --git a/VkRenderer/vk_images.cpp b/VkRenderer/vk_images.cpp index c1e4e8b..9c9f018 100644 --- a/VkRenderer/vk_images.cpp +++ b/VkRenderer/vk_images.cpp @@ -94,10 +94,6 @@ AllocatedImage vkutil::create_hdri_image(const VulkanEngine *engine, float *data int nrComponents, const char *name) { VkFormat format = VK_FORMAT_R16G16B16A16_SFLOAT; - // Calculate source size based on nrComponents from stb_image - size_t srcBytesPerPixel = nrComponents * 2; // RGB - 16: So each channel is 2 bytes - size_t srcSize = width * height * srcBytesPerPixel; - // Calculate destination size for the R16G16B16A16_SFLOAT format size_t dstBytesPerPixel = 8; // 16-bit per channel × 4 channels / 8 bits per byte size_t dstSize = width * height * dstBytesPerPixel; diff --git a/VkRenderer/vk_loader.cpp b/VkRenderer/vk_loader.cpp index 3e267fe..a1b65b7 100644 --- a/VkRenderer/vk_loader.cpp +++ b/VkRenderer/vk_loader.cpp @@ -5,8 +5,8 @@ // header for std::visit -#include #include +#include #include #include #include "stb_image.h" @@ -534,22 +534,20 @@ std::optional> loadGltf(VulkanEngine *engine, std::s nodes.push_back(newNode); file.nodes[node.name.c_str()]; - std::visit(fastgltf::visitor{[&](fastgltf::math::fmat4x4 matrix) { - newNode->localTransform = glm::make_mat4(matrix.data()); - }, - [&](fastgltf::TRS transform) { - glm::vec3 tl(transform.translation[0], transform.translation[1], - transform.translation[2]); - glm::quat rot(transform.rotation[3], transform.rotation[0], - transform.rotation[1], transform.rotation[2]); - glm::vec3 sc(transform.scale[0], transform.scale[1], transform.scale[2]); - - glm::mat4 tm = glm::translate(glm::mat4(1.f), tl); - glm::mat4 rm = glm::toMat4(rot); - glm::mat4 sm = glm::scale(glm::mat4(1.f), sc); - - newNode->localTransform = tm * rm * sm; - }}, + std::visit(fastgltf::visitor{ + [&](fastgltf::math::fmat4x4 matrix) { newNode->localTransform = glm::make_mat4(matrix.data()); }, + [&](fastgltf::TRS transform) { + glm::vec3 tl(transform.translation[0], transform.translation[1], transform.translation[2]); + glm::quat rot(transform.rotation[3], transform.rotation[0], transform.rotation[1], + transform.rotation[2]); + glm::vec3 sc(transform.scale[0], transform.scale[1], transform.scale[2]); + + glm::mat4 tm = glm::translate(glm::mat4(1.f), tl); + glm::mat4 rm = glm::toMat4(rot); + glm::mat4 sm = glm::scale(glm::mat4(1.f), sc); + + newNode->localTransform = tm * rm * sm; + }}, node.transform); }