Commit 1970bb6e authored by Lukas Tietze's avatar Lukas Tietze

Cleanup-Bugs gefixt

parent d84e9f89
......@@ -218,7 +218,6 @@ namespace lib
vk::DescriptorPool descriptorPool;
vk::RenderPass renderPass;
ImGui_ImplVulkanH_Window window = {};
std::vector<vk::Framebuffer> frameBuffers;
bool show = false;
} imGui;
......
......@@ -14,12 +14,14 @@ namespace lib
vk::CommandPool commandPool;
vk::CommandBuffer commandBuffer;
vk::Fence inFlightFence;
vk::DescriptorSet descriptorSet;
vk::DescriptorSet raytracingDescriptorSet;
vk::DescriptorSet rasterizationDescriptorSet;
vk::Image swapChainImage;
vk::ImageView swapChainImageView;
vk::Framebuffer swapChainFramebufferForRasterizationRenderPass;
vk::Framebuffer swapChainFramebufferForImGui;
std::unique_ptr<lib::Texture> raytracingTexture;
vk::Framebuffer raytracingTextureFbo;
};
} // namespace lib
......@@ -10,8 +10,6 @@ namespace lib
vk::Pipeline pipeline;
vk::DescriptorSetLayout descriptorSetLayout;
vk::DescriptorPool descriptorPool;
std::vector<vk::DescriptorSet> descriptorSets;
vk::RenderPass renderPass;
std::vector<vk::Framebuffer> frameBuffers;
};
} // namespace lib
......@@ -44,7 +44,7 @@ namespace
vk::AttachmentReference attachmentReference;
attachmentReference.attachment = 0;
attachmentReference.layout = vk::ImageLayout::eGeneral;
attachmentReference.layout = vk::ImageLayout::eColorAttachmentOptimal;
vk::SubpassDescription subpass;
subpass.pipelineBindPoint = vk::PipelineBindPoint::eGraphics;
......@@ -60,30 +60,21 @@ namespace
return logicalDevice.createRenderPass(createInfo);
}
std::vector<vk::Framebuffer> genImGuiFrameBuffers(vk::Device logicalDevice,
const vk::RenderPass &renderpass,
const vk::Extent2D &extent,
const std::vector<lib::Frame> &frames)
vk::Framebuffer genImGuiFramebuffer(vk::Device logicalDevice,
const vk::RenderPass &renderpass,
const vk::Extent2D &extent,
const vk::ImageView &imageView)
{
const auto count = static_cast<uint32_t>(frames.size());
std::vector<vk::Framebuffer> res;
res.reserve(count);
for (uint32_t i = 0; i < count; i++)
{
vk::FramebufferCreateInfo createInfo;
createInfo.renderPass = renderpass;
createInfo.attachmentCount = 1;
createInfo.pAttachments = &frames[i].swapChainImageView;
createInfo.width = extent.width;
createInfo.height = extent.height;
createInfo.layers = 1;
res.push_back(logicalDevice.createFramebuffer(createInfo));
}
vk::FramebufferCreateInfo createInfo;
createInfo.renderPass = renderpass;
createInfo.attachmentCount = 1;
createInfo.pAttachments = &imageView;
createInfo.width = extent.width;
createInfo.height = extent.height;
createInfo.layers = 1;
return res;
return logicalDevice.createFramebuffer(createInfo);
}
void PrepareImGuiSettings()
......@@ -96,10 +87,14 @@ void lib::CgContext::CreateImGuiComponents()
this->imGui.descriptorPool = ::genImGuiDescriptorPool(this->logicalDevice,
static_cast<uint32_t>(this->frames.size()));
this->imGui.renderPass = ::genImGuiRenderPass(this->logicalDevice, this->swapChainImageFormat);
this->imGui.frameBuffers = ::genImGuiFrameBuffers(this->logicalDevice,
this->imGui.renderPass,
this->swapChainExtent,
this->frames);
for (auto &frame : this->frames)
{
frame.swapChainFramebufferForImGui = ::genImGuiFramebuffer(this->logicalDevice,
this->imGui.renderPass,
this->swapChainExtent,
frame.swapChainImageView);
}
ImGui_ImplVulkan_InitInfo info = {};
info.Instance = this->instance;
......@@ -145,9 +140,10 @@ void lib::CgContext::DestroyImGuiComponents()
this->logicalDevice.destroyRenderPass(this->imGui.renderPass);
this->logicalDevice.destroyDescriptorPool(this->imGui.descriptorPool);
for (const auto &frameBuffer : this->imGui.frameBuffers)
for (auto &frame : this->frames)
{
this->logicalDevice.destroyFramebuffer(frameBuffer);
this->logicalDevice.destroyFramebuffer(frame.swapChainFramebufferForImGui);
frame.swapChainFramebufferForImGui = nullptr;
}
}
......
......@@ -167,14 +167,20 @@ void lib::CgContext::CreateRasterizationDescriptorSets()
allocateInfo.descriptorSetCount = count;
allocateInfo.pSetLayouts = layouts.data();
this->rasterizationStep.descriptorSets = this->logicalDevice.allocateDescriptorSets(allocateInfo);
auto sets = this->logicalDevice.allocateDescriptorSets(allocateInfo);
auto setsIt = std::begin(sets);
for (uint32_t i = 0; i < count; i++)
for (auto &frame : this->frames)
{
frame.rasterizationDescriptorSet = *setsIt++;
vk::DescriptorImageInfo rtImageInfo;
rtImageInfo.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal;
rtImageInfo.imageView = this->frames[i].raytracingTexture->GetView();
rtImageInfo.sampler = this->frames[i].raytracingTexture->GetSampler();
// rtImageInfo.imageView = frame.raytracingTexture->GetView();
// rtImageInfo.sampler = frame.raytracingTexture->GetSampler();
rtImageInfo.imageView = this->dummyTexture->GetView();
rtImageInfo.sampler = this->dummyTexture->GetSampler();
vk::WriteDescriptorSet rtImageWrite;
rtImageWrite.descriptorCount = 1;
......@@ -182,7 +188,7 @@ void lib::CgContext::CreateRasterizationDescriptorSets()
rtImageWrite.dstArrayElement = 0;
rtImageWrite.dstBinding = 0;
rtImageWrite.pImageInfo = &rtImageInfo;
rtImageWrite.dstSet = this->rasterizationStep.descriptorSets[i];
rtImageWrite.dstSet = frame.rasterizationDescriptorSet;
this->logicalDevice.updateDescriptorSets(rtImageWrite, {});
}
......@@ -230,8 +236,8 @@ void lib::CgContext::CreateRasterizationDescriptorSetLayout()
void lib::CgContext::CreateRasterizationRenderPass()
{
vk::AttachmentDescription colorAttachment;
colorAttachment.initialLayout = vk::ImageLayout::eColorAttachmentOptimal;
colorAttachment.finalLayout = vk::ImageLayout::eColorAttachmentOptimal;
colorAttachment.initialLayout = vk::ImageLayout::eUndefined;
colorAttachment.finalLayout = vk::ImageLayout::ePresentSrcKHR;
colorAttachment.loadOp = vk::AttachmentLoadOp::eDontCare;
colorAttachment.storeOp = vk::AttachmentStoreOp::eStore;
colorAttachment.format = this->swapChainImageFormat;
......@@ -272,19 +278,38 @@ void lib::CgContext::CreateRasterizationFrameBuffers()
{
const auto count = static_cast<uint32_t>(frames.size());
this->rasterizationStep.frameBuffers.reserve(count);
this->rasterizationStep.frameBuffers.clear();
for (uint32_t i = 0; i < count; i++)
for (auto &frame : this->frames)
{
const lib::TextureCreateInfo textureCreateInfo{
{
this->physicalDeviceInfo.GetGraphicsQueueFamily(),
this->physicalDeviceInfo.GetBufferStagingQueueFamily(),
this->physicalDeviceInfo.GetComputeQueueFamily(),
this->physicalDeviceInfo.GetPresentationQueueFamily(),
},
this->swapChainImageFormat,
vk::ImageUsageFlagBits::eSampled |
vk::ImageUsageFlagBits::eStorage |
vk::ImageUsageFlagBits::eColorAttachment,
vk::ImageLayout::eGeneral};
auto newTexture = new lib::Texture{this,
this->swapChainExtent.width,
this->swapChainExtent.height,
textureCreateInfo};
frame.raytracingTexture.reset(newTexture);
vk::FramebufferCreateInfo createInfo;
createInfo.renderPass = this->rasterizationStep.renderPass;
createInfo.attachmentCount = 1;
createInfo.pAttachments = &frames[i].swapChainImageView;
createInfo.pAttachments = &frame.swapChainImageView;
createInfo.width = this->swapChainExtent.width;
createInfo.height = this->swapChainExtent.height;
createInfo.layers = 1;
this->rasterizationStep.frameBuffers.push_back(logicalDevice.createFramebuffer(createInfo));
frame.swapChainFramebufferForRasterizationRenderPass = logicalDevice.createFramebuffer(createInfo);
}
lib::log::Info("Successfully created rasterization framebuffers!");
}
\ No newline at end of file
......@@ -26,11 +26,6 @@
#include "imgui_impl_vulkan.h"
#include "imgui_impl_glfw.h"
using lib::log::Info;
using lib::log::Debug;
using lib::log::Error;
using lib::log::Warning;
void lib::CgContext::CreateAccelerationStructures()
{
auto commandBuffer = this->AllocateSingleUseComputeCommandBuffer();
......@@ -51,7 +46,7 @@ void lib::CgContext::CreateAccelerationStructures()
commandBuffer.Run();
Info("Successfully created acceleration structures!");
lib::log::Info("Successfully created acceleration structures!");
}
void lib::CgContext::CreateRaytracingDescriptorSetLayout()
......@@ -131,7 +126,7 @@ void lib::CgContext::CreateRaytracingDescriptorSetLayout()
this->raytracingStep.descriptorSetLayout = this->logicalDevice.createDescriptorSetLayout(createInfo);
Info("Successfully created descriptor set layout!");
lib::log::Info("Successfully created raytracing descriptor set layout!");
}
void lib::CgContext::CreateRaytracingDescriptorPool()
......@@ -162,6 +157,8 @@ void lib::CgContext::CreateRaytracingDescriptorPool()
createInfo.maxSets = static_cast<uint32_t>(count);
this->raytracingStep.descriptorPool = this->logicalDevice.createDescriptorPool(createInfo);
lib::log::Info("Successfully created raytracing descriptor pool!");
}
void lib::CgContext::CreateRaytracingDescriptorSets()
......@@ -179,10 +176,10 @@ void lib::CgContext::CreateRaytracingDescriptorSets()
for (size_t i = 0; i < count; i++)
{
auto &frame = this->frames[i];
frame.descriptorSet = descriptorSets[i];
frame.raytracingDescriptorSet = descriptorSets[i];
vk::StructureChain<vk::WriteDescriptorSet, vk::WriteDescriptorSetAccelerationStructureNV> accelerationStructureWrite;
accelerationStructureWrite.get<vk::WriteDescriptorSet>().dstSet = frame.descriptorSet;
accelerationStructureWrite.get<vk::WriteDescriptorSet>().dstSet = frame.raytracingDescriptorSet;
accelerationStructureWrite.get<vk::WriteDescriptorSet>().dstBinding = this->descriptorBindings.accelerationStructure;
accelerationStructureWrite.get<vk::WriteDescriptorSet>().dstArrayElement = 0;
accelerationStructureWrite.get<vk::WriteDescriptorSet>().descriptorType = vk::DescriptorType::eAccelerationStructureNV;
......@@ -195,7 +192,7 @@ void lib::CgContext::CreateRaytracingDescriptorSets()
outputImageInfo.imageView = frame.raytracingTexture->GetView();
vk::WriteDescriptorSet outputImageWrite;
outputImageWrite.dstSet = frame.descriptorSet;
outputImageWrite.dstSet = frame.raytracingDescriptorSet;
outputImageWrite.dstBinding = this->descriptorBindings.outputImage;
outputImageWrite.dstArrayElement = 0;
outputImageWrite.descriptorType = vk::DescriptorType::eStorageImage;
......@@ -207,7 +204,7 @@ void lib::CgContext::CreateRaytracingDescriptorSets()
camInfo.range = VK_WHOLE_SIZE;
vk::WriteDescriptorSet camWrite;
camWrite.dstSet = frame.descriptorSet;
camWrite.dstSet = frame.raytracingDescriptorSet;
camWrite.dstBinding = this->descriptorBindings.cameraAndLightUbo;
camWrite.dstArrayElement = 0;
camWrite.descriptorType = vk::DescriptorType::eUniformBuffer;
......@@ -225,7 +222,7 @@ void lib::CgContext::CreateRaytracingDescriptorSets()
}
vk::WriteDescriptorSet vertexBufferWrite;
vertexBufferWrite.dstSet = frame.descriptorSet;
vertexBufferWrite.dstSet = frame.raytracingDescriptorSet;
vertexBufferWrite.dstBinding = this->descriptorBindings.vertices;
vertexBufferWrite.dstArrayElement = 0;
vertexBufferWrite.descriptorType = vk::DescriptorType::eStorageBuffer;
......@@ -243,7 +240,7 @@ void lib::CgContext::CreateRaytracingDescriptorSets()
}
vk::WriteDescriptorSet indexBufferWrite;
indexBufferWrite.dstSet = frame.descriptorSet;
indexBufferWrite.dstSet = frame.raytracingDescriptorSet;
indexBufferWrite.dstBinding = this->descriptorBindings.indices;
indexBufferWrite.dstArrayElement = 0;
indexBufferWrite.descriptorType = vk::DescriptorType::eStorageBuffer;
......@@ -255,7 +252,7 @@ void lib::CgContext::CreateRaytracingDescriptorSets()
materialBufferInfo.range = VK_WHOLE_SIZE;
vk::WriteDescriptorSet materialBufferWrite;
materialBufferWrite.dstSet = frame.descriptorSet;
materialBufferWrite.dstSet = frame.raytracingDescriptorSet;
materialBufferWrite.dstBinding = this->descriptorBindings.materials;
materialBufferWrite.dstArrayElement = 0;
materialBufferWrite.descriptorType = vk::DescriptorType::eStorageBuffer;
......@@ -267,7 +264,7 @@ void lib::CgContext::CreateRaytracingDescriptorSets()
objectInstanceInfo.range = VK_WHOLE_SIZE;
vk::WriteDescriptorSet objectInstanceWrite;
objectInstanceWrite.dstSet = frame.descriptorSet;
objectInstanceWrite.dstSet = frame.raytracingDescriptorSet;
objectInstanceWrite.dstBinding = this->descriptorBindings.objectInstances;
objectInstanceWrite.dstArrayElement = 0;
objectInstanceWrite.descriptorType = vk::DescriptorType::eStorageBuffer;
......@@ -280,7 +277,7 @@ void lib::CgContext::CreateRaytracingDescriptorSets()
dummyTextureInfo.sampler = this->dummyTexture->GetSampler();
vk::WriteDescriptorSet dummyTextureWrite;
dummyTextureWrite.dstSet = frame.descriptorSet;
dummyTextureWrite.dstSet = frame.raytracingDescriptorSet;
dummyTextureWrite.dstBinding = this->descriptorBindings.dummyTexture;
dummyTextureWrite.dstArrayElement = 0;
dummyTextureWrite.descriptorType = vk::DescriptorType::eCombinedImageSampler;
......@@ -298,7 +295,7 @@ void lib::CgContext::CreateRaytracingDescriptorSets()
{});
}
Info("Successfully created raytracing descriptor set!");
lib::log::Info("Successfully created raytracing descriptor set!");
}
bool lib::CgContext::TryCreateRayTracingPipeline()
......@@ -414,13 +411,13 @@ bool lib::CgContext::TryCreateRayTracingPipeline()
const auto result = this->logicalDevice.createRayTracingPipelinesNV(vk::PipelineCache(), pipelineCreateInfo);
this->raytracingStep.pipeline = result.value[0];
Info("Successfully created raytracing pipeline!");
lib::log::Info("Successfully created raytracing pipeline!");
success = true;
}
else
{
Error("Failed to load shaders required for raytracing!");
lib::log::Error("Failed to load shaders required for raytracing!");
}
if (raygenModule)
......@@ -449,19 +446,38 @@ bool lib::CgContext::TryCreateRayTracingPipeline()
void lib::CgContext::CreateShaderBindingTable()
{
uint32_t sbtSize = static_cast<uint32_t>(this->shaderOffsets.count * this->physicalDeviceInfo.GetRaytracingProperties().shaderGroupHandleSize);
auto shadercount = static_cast<uint32_t>(this->appInfo.shaderTable.missShaders.size() + this->appInfo.shaderTable.closestHitShaders.size() + 1);
auto handleSize = this->physicalDeviceInfo.GetRaytracingProperties().shaderGroupHandleSize;
auto baseAlignment = this->physicalDeviceInfo.GetRaytracingProperties().shaderGroupBaseAlignment;
auto sbtBufferSize = shadercount * handleSize;
auto sbtSize = shadercount * baseAlignment;
std::vector<uint8_t> sbtBuf(sbtBufferSize);
this->logicalDevice.getRayTracingShaderGroupHandlesNV(this->raytracingStep.pipeline, 0, shadercount,
sbtBufferSize, sbtBuf.data());
std::vector<uint8_t> alignedSbtBuf(sbtSize);
uint32_t rPos = 0;
uint32_t wPos = 0;
std::vector<uint8_t> sbtBuf(sbtSize);
this->logicalDevice.getRayTracingShaderGroupHandlesNV(this->raytracingStep.pipeline, 0, this->shaderOffsets.count,
sbtSize, sbtBuf.data());
for (uint32_t i = 0; i < shadercount; i++)
{
for (uint32_t j = 0; j < handleSize; j++)
{
alignedSbtBuf[wPos++] = sbtBuf[rPos++];
}
wPos += baseAlignment - handleSize;
}
auto [stagingBuffer, finalBuffer] = this->CreateStagingBuffers(vk::BufferUsageFlagBits::eRayTracingNV);
stagingBuffer.BufferData(sbtBuf);
finalBuffer.AllocateFor(sbtBuf);
stagingBuffer.BufferData(alignedSbtBuf);
finalBuffer.AllocateFor(alignedSbtBuf);
this->CopyBuffer(stagingBuffer, finalBuffer);
this->shaderBindingTableBuffer.reset(new lib::Buffer(std::move(finalBuffer)));
Info("Successfully created shader binding table!");
lib::log::Info("Successfully created shader binding table!");
}
......@@ -98,10 +98,10 @@ lib::CgContext::CgContext(const AppCreateInfo &info, GLFWwindow *window) : windo
this->CreateQueues();
this->CreateSwapChain();
this->CreateImageViews();
this->CreateRasterizationRenderPass();
this->CreateRasterizationFrameBuffers();
this->CreateUniformBuffers();
this->CreateCommandPool();
this->CreateRasterizationRenderPass();
this->CreateRasterizationFrameBuffers();
this->LoadDummyTexture();
this->modelLoaded = this->TryLoadModel();
......@@ -221,16 +221,14 @@ lib::CgContext::~CgContext()
void lib::CgContext::CleanupSwapChain()
{
for (const auto &frame : this->frames)
for (auto &frame : this->frames)
{
this->logicalDevice.freeCommandBuffers(frame.commandPool, frame.commandBuffer);
}
for (auto rasterizationFrameBuffer : this->rasterizationStep.frameBuffers)
{
if (rasterizationFrameBuffer)
if (frame.swapChainFramebufferForRasterizationRenderPass)
{
this->logicalDevice.destroyFramebuffer(rasterizationFrameBuffer);
this->logicalDevice.destroyFramebuffer(frame.swapChainFramebufferForRasterizationRenderPass);
frame.swapChainFramebufferForRasterizationRenderPass = nullptr;
}
}
......@@ -264,6 +262,12 @@ void lib::CgContext::CleanupSwapChain()
this->rasterizationStep.pipelineLayout = nullptr;
}
if (this->rasterizationStep.renderPass)
{
this->logicalDevice.destroyRenderPass(this->rasterizationStep.renderPass);
this->rasterizationStep.renderPass = nullptr;
}
if (this->raytracingStep.descriptorPool)
{
this->logicalDevice.destroyDescriptorPool(this->raytracingStep.descriptorPool);
......@@ -276,12 +280,17 @@ void lib::CgContext::CleanupSwapChain()
this->rasterizationStep.descriptorPool = nullptr;
}
for (const auto &frame : this->frames)
for (auto &frame : this->frames)
{
if (frame.swapChainImageView)
{
this->logicalDevice.destroyImageView(frame.swapChainImageView);
}
if (frame.raytracingTexture)
{
frame.raytracingTexture.reset();
}
}
if (this->swapChain)
......@@ -731,64 +740,68 @@ void lib::CgContext::UpdateCommandBuffer(uint32_t imageIndex)
frame.commandBuffer.begin(beginInfo);
if (this->IsOk())
{
frame.commandBuffer.bindPipeline(vk::PipelineBindPoint::eRayTracingNV, this->raytracingStep.pipeline);
frame.commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eRayTracingNV, this->raytracingStep.pipelineLayout,
0, frame.descriptorSet, {});
}
// if (this->IsOk())
// {
// frame.commandBuffer.bindPipeline(vk::PipelineBindPoint::eRayTracingNV, this->raytracingStep.pipeline);
// frame.commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eRayTracingNV,
// this->raytracingStep.pipelineLayout,
// 0, frame.raytracingDescriptorSet,
// {});
// TransitionImageLayout(frame.commandBuffer,
// frame.raytracingTexture->GetHandle(), this->swapChainImageFormat,
// vk::ImageLayout::eUndefined, vk::ImageLayout::eGeneral,
// vk::PipelineStageFlagBits::eTopOfPipe,
// vk::PipelineStageFlagBits::eRayTracingShaderNV);
// frame.ubo->ScheduleTransfer(frame.commandBuffer);
// frame.commandBuffer.pushConstants(this->raytracingStep.pipelineLayout,
// vk::ShaderStageFlagBits::eRaygenNV | vk::ShaderStageFlagBits::eClosestHitNV,
// 0, sizeof(this->pushConstant),
// &this->pushConstant);
// auto sbtEntrySize = this->physicalDeviceInfo.GetRaytracingProperties().shaderGroupBaseAlignment;
// frame.commandBuffer.traceRaysNV(this->shaderBindingTableBuffer->GetBufferHandle(), this->shaderOffsets.rayGen * sbtEntrySize,
// this->shaderBindingTableBuffer->GetBufferHandle(), this->shaderOffsets.miss * sbtEntrySize, sbtEntrySize,
// this->shaderBindingTableBuffer->GetBufferHandle(), this->shaderOffsets.hitGroup * sbtEntrySize, sbtEntrySize,
// this->shaderBindingTableBuffer->GetBufferHandle(), 0, 0,
// this->swapChainExtent.width, this->swapChainExtent.height, 1);
// }
// TransitionImageLayout(frame.commandBuffer,
// frame.raytracingTexture->GetHandle(), this->swapChainImageFormat,
// vk::ImageLayout::eGeneral, vk::ImageLayout::eShaderReadOnlyOptimal,
// vk::PipelineStageFlagBits::eRayTracingShaderNV, vk::PipelineStageFlagBits::eAllGraphics);
TransitionImageLayout(frame.commandBuffer,
frame.raytracingTexture->GetHandle(), this->swapChainImageFormat,
vk::ImageLayout::eUndefined, vk::ImageLayout::eGeneral,
vk::PipelineStageFlagBits::eTopOfPipe,
vk::PipelineStageFlagBits::eRayTracingShaderNV);
frame.swapChainImage, this->swapChainImageFormat,
vk::ImageLayout::eUndefined, vk::ImageLayout::eColorAttachmentOptimal,
vk::PipelineStageFlagBits::eRayTracingShaderNV, vk::PipelineStageFlagBits::eAllGraphics);
if (this->IsOk())
{
frame.ubo->ScheduleTransfer(frame.commandBuffer);
frame.commandBuffer.pushConstants(this->raytracingStep.pipelineLayout,
vk::ShaderStageFlagBits::eRaygenNV | vk::ShaderStageFlagBits::eClosestHitNV,
0, sizeof(this->pushConstant),
&this->pushConstant);
auto sbtEntrySize = this->physicalDeviceInfo.GetRaytracingProperties().shaderGroupHandleSize;
// vk::RenderPassBeginInfo ppBeginInfo;
// ppBeginInfo.renderPass = this->rasterizationStep.renderPass;
// ppBeginInfo.framebuffer = frame.swapChainFramebufferForRasterizationRenderPass;
// ppBeginInfo.renderArea.offset = {0, 0};
// ppBeginInfo.renderArea.extent = this->swapChainExtent;
frame.commandBuffer.traceRaysNV(this->shaderBindingTableBuffer->GetBufferHandle(), this->shaderOffsets.rayGen * sbtEntrySize,
this->shaderBindingTableBuffer->GetBufferHandle(), this->shaderOffsets.miss * sbtEntrySize, sbtEntrySize,
this->shaderBindingTableBuffer->GetBufferHandle(), this->shaderOffsets.hitGroup * sbtEntrySize, sbtEntrySize,
this->shaderBindingTableBuffer->GetBufferHandle(), 0, 0,
this->swapChainExtent.width, this->swapChainExtent.height, 1);
}
if (this->doPostProcessing)
{
TransitionImageLayout(frame.commandBuffer,
frame.raytracingTexture->GetHandle(), this->swapChainImageFormat,
vk::ImageLayout::eGeneral, vk::ImageLayout::eColorAttachmentOptimal,
vk::PipelineStageFlagBits::eRayTracingShaderNV, vk::PipelineStageFlagBits::eFragmentShader);
vk::RenderPassBeginInfo ppBeginInfo;
ppBeginInfo.renderPass = this->rasterizationStep.renderPass;
ppBeginInfo.framebuffer = this->rasterizationStep.frameBuffers[imageIndex];
ppBeginInfo.renderArea.offset = {0, 0};
ppBeginInfo.renderArea.extent = this->swapChainExtent;
frame.commandBuffer.beginRenderPass(ppBeginInfo, vk::SubpassContents::eInline);
frame.commandBuffer.bindPipeline(vk::PipelineBindPoint::eGraphics, this->rasterizationStep.pipeline);
frame.commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics,
this->rasterizationStep.pipelineLayout,
0, this->rasterizationStep.descriptorSets, {});
frame.commandBuffer.draw(3, 1, 0, 0);
frame.commandBuffer.endRenderPass();
// frame.commandBuffer.beginRenderPass(ppBeginInfo, vk::SubpassContents::eInline);
// frame.commandBuffer.bindPipeline(vk::PipelineBindPoint::eGraphics, this->rasterizationStep.pipeline);
// frame.commandBuffer.bindDescriptorSets(vk::PipelineBindPoint::eGraphics,
// this->rasterizationStep.pipelineLayout,
// 0, frame.rasterizationDescriptorSet, {});
// frame.commandBuffer.draw(3, 1, 0, 0);
// frame.commandBuffer.endRenderPass();
}
if (this->imGui.show)
{
vk::RenderPassBeginInfo uiBeginInfo;
uiBeginInfo.renderPass = this->imGui.renderPass;
uiBeginInfo.framebuffer = this->imGui.frameBuffers[imageIndex];
uiBeginInfo.framebuffer = frame.swapChainFramebufferForImGui;
uiBeginInfo.renderArea.offset = {0, 0};
uiBeginInfo.renderArea.extent = this->swapChainExtent;
......@@ -802,8 +815,8 @@ void lib::CgContext::UpdateCommandBuffer(uint32_t imageIndex)
{
TransitionImageLayout(frame.commandBuffer,
frame.swapChainImage, this->swapChainImageFormat,
vk::ImageLayout::eGeneral, vk::ImageLayout::ePresentSrcKHR,
vk::PipelineStageFlagBits::eRayTracingShaderNV,
vk::ImageLayout::eColorAttachmentOptimal, vk::ImageLayout::ePresentSrcKHR,
vk::PipelineStageFlagBits::eColorAttachmentOutput,
vk::PipelineStageFlagBits::eBottomOfPipe);
}
......@@ -1075,37 +1088,6 @@ void lib::CgContext::LoadDummyTexture()
createInfo};
this->dummyTexture.reset(newTexture);
for (auto &frame : this->frames)
{
const lib::TextureCreateInfo textureCreateInfo{
{
this->physicalDeviceInfo.GetGraphicsQueueFamily(),
this->physicalDeviceInfo.GetBufferStagingQueueFamily(),
this->physicalDeviceInfo.GetComputeQueueFamily(),
this->physicalDeviceInfo.GetPresentationQueueFamily(),
},
this->swapChainImageFormat,
vk::ImageUsageFlagBits::eStorage | vk::ImageUsageFlagBits::eColorAttachment,
vk::ImageLayout::eGeneral};
auto newTexture = new lib::Texture{this,
this->swapChainExtent.width,
this->swapChainExtent.height,
textureCreateInfo};
frame.raytracingTexture.reset(newTexture);
vk::FramebufferCreateInfo createInfo;
createInfo.renderPass = this->rasterizationStep.renderPass;
createInfo.attachmentCount = 1;
createInfo.pAttachments = &frame.raytracingTexture->GetView();
createInfo.width = this->swapChainExtent.width;
createInfo.height = this->swapChainExtent.height;
createInfo.layers = 1;
frame.raytracingTextureFbo = this->logicalDevice.createFramebuffer(createInfo);
}
}
bool lib::CgContext::TryLoadModel()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment