Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions VkRenderer/Hdri.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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<VkRenderingAttachmentInfo, 2> colorAttachments = {
vkinit::attachment_info(engine->_drawImage.imageView, &clearVal, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL),
Expand Down
1 change: 0 additions & 1 deletion VkRenderer/Hdri.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once
#include <optional>
#include <string>
#include "vk_types.h"

Expand Down
2 changes: 1 addition & 1 deletion VkRenderer/VulkanGeometryKHR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(mesh.firstIndex * sizeof(std::uint32_t)),
.firstVertex = 0,
.transformOffset = 0,
};
Expand Down
4 changes: 1 addition & 3 deletions VkRenderer/VulkanResourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
#include <glm/gtc/packing.hpp>
#include "vk_engine.h"
#include "vk_images.h"
#include "vk_initializers.h"
#include "vk_utils.h"

void VulkanResourceManager::init(VulkanEngine *engine) {
_engine = engine;
createDefaultTextures();
createDefaultSamplers();
}

void VulkanResourceManager::cleanup() {
void VulkanResourceManager::cleanup() const {
if (!_engine)
return;

Expand Down
2 changes: 1 addition & 1 deletion VkRenderer/VulkanResourceManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
4 changes: 1 addition & 3 deletions VkRenderer/cube.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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(); });
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion VkRenderer/cube.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
8 changes: 4 additions & 4 deletions VkRenderer/gbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -126,7 +126,7 @@ void Gbuffer::draw_gbuffer(VulkanEngine *engine, VkCommandBuffer cmd) {

std::vector<uint32_t> 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<int>(engine->mainDrawContext.OpaqueSurfaces.size()); i++) {
/*if (is_visible(mainDrawContext.OpaqueSurfaces[i], sceneData.viewproj)) {*/
opaque_draws.push_back(i);

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion VkRenderer/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <vk_engine.h>

int main(int argc, char *argv[]) {
int main() {
VulkanEngine engine;

engine.init();
Expand Down
22 changes: 11 additions & 11 deletions VkRenderer/postprocess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 / engine->_windowExtent.width, 1.0f / engine->_windowExtent.height, 0.0f);
_fxaaData.R_inverseFilterTextureSize = glm::vec3(1.0f / static_cast<float>(engine->_windowExtent.width),
1.0f / static_cast<float>(engine->_windowExtent.height), 0.0f);
_fxaaData.R_fxaaSpanMax = 8.0f;
_fxaaData.R_fxaaReduceMin = 1.0f / 128.0f;
_fxaaData.R_fxaaReduceMul = 1.0f / 8.0f;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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<VkRenderingAttachmentInfo, 1> colorAttachments = {
vkinit::attachment_info(_fullscreenImage.imageView, &clearVal, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL),
Expand Down Expand Up @@ -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<VkRenderingAttachmentInfo, 1> colorAttachments = {
vkinit::attachment_info(_fxaaImage.imageView, &clearVal, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL),
Expand Down
26 changes: 13 additions & 13 deletions VkRenderer/raytracer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ 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<VkAccelerationStructureInstanceKHR> tlas;
const uint32_t totalSurfaces = static_cast<uint32_t>(engine->mainDrawContext.OpaqueSurfaces.size() +
engine->mainDrawContext.TransparentSurfaces.size());
const auto totalSurfaces = static_cast<uint32_t>(engine->mainDrawContext.OpaqueSurfaces.size() +
engine->mainDrawContext.TransparentSurfaces.size());
tlas.reserve(totalSurfaces);

// Add opaque surfaces first
Expand Down Expand Up @@ -98,7 +98,7 @@ void Raytracer::createTopLevelAS(const VulkanEngine *engine) const {
}

// Add transparent surfaces after opaque ones
const uint32_t opaqueCount = static_cast<uint32_t>(engine->mainDrawContext.OpaqueSurfaces.size());
const auto opaqueCount = static_cast<uint32_t>(engine->mainDrawContext.OpaqueSurfaces.size());
for (std::uint32_t i = 0; i < static_cast<uint32_t>(engine->mainDrawContext.TransparentSurfaces.size()); i++) {
VkTransformMatrixKHR vk_transform = {};
const glm::mat4 &t = engine->mainDrawContext.TransparentSurfaces[i].transform;
Expand Down Expand Up @@ -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); });
}

{
Expand Down Expand Up @@ -177,8 +177,8 @@ void Raytracer::createRtDescriptorSet(VulkanEngine *engine) {
}

std::vector<ObjDesc> objDescs;
const uint32_t totalSurfaces = static_cast<uint32_t>(engine->mainDrawContext.OpaqueSurfaces.size() +
engine->mainDrawContext.TransparentSurfaces.size());
const auto totalSurfaces = static_cast<uint32_t>(engine->mainDrawContext.OpaqueSurfaces.size() +
engine->mainDrawContext.TransparentSurfaces.size());
objDescs.reserve(totalSurfaces);

// Add opaque surfaces first
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});
Expand Down Expand Up @@ -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() {
Expand All @@ -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;
Expand All @@ -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);
Expand Down
9 changes: 1 addition & 8 deletions VkRenderer/raytracer.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
#pragma once

#include <RenderObject.h>
#include <functional>
#include <raytraceKHR_vk.h>
#include <vk_descriptors.h>
#include <vk_loader.h>
#include <vk_pipelines.h>
#include <vk_types.h>
#include <vk_utils.h>

#include "VkBootstrap.h"

class VulkanEngine;

Expand Down Expand Up @@ -44,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();

Expand Down
4 changes: 2 additions & 2 deletions VkRenderer/shadowmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -130,7 +130,7 @@ void shadowMap::draw_depthShadowMap(VulkanEngine *engine, VkCommandBuffer cmd) c
std::vector<uint32_t> 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<int>(engine->mainDrawContext.OpaqueSurfaces.size()); i++) {
/*if (is_visible(mainDrawContext.OpaqueSurfaces[i], sceneData.viewproj)) {*/
opaque_draws.push_back(i);
/*}*/
Expand Down
7 changes: 0 additions & 7 deletions VkRenderer/shadowmap.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,7 @@
#pragma once

#include <functional>
#include <glm/gtx/transform.hpp>
#include <vk_descriptors.h>
#include <vk_loader.h>
#include <vk_pipelines.h>
#include <vk_types.h>
#include <vk_utils.h>

#include "VkBootstrap.h"

class VulkanEngine;

Expand Down
Loading