Fix not clearing texture in the raytrace render pass

This commit is contained in:
Magnus Norddahl 2023-09-05 23:50:50 +02:00
parent 280063ac6c
commit bbd246bdc9
2 changed files with 43 additions and 11 deletions

View file

@ -117,11 +117,13 @@ void GPURaytracer::RenderAtlasImage(size_t pageIndex)
{ {
LightmapImage& img = atlasImages[pageIndex]; LightmapImage& img = atlasImages[pageIndex];
const auto beginPass = [&]() { // Begin with clear
{
RenderPassBegin() RenderPassBegin()
.RenderPass(raytrace.renderPass.get()) .RenderPass(raytrace.renderPassBegin.get())
.RenderArea(0, 0, atlasImageSize, atlasImageSize) .RenderArea(0, 0, atlasImageSize, atlasImageSize)
.Framebuffer(img.raytrace.Framebuffer.get()) .Framebuffer(img.raytrace.Framebuffer.get())
.AddClearColor(0.0f, 0.0f, 0.0f, 0.0f)
.Execute(cmdbuffer.get()); .Execute(cmdbuffer.get());
VkDeviceSize offset = 0; VkDeviceSize offset = 0;
@ -129,8 +131,7 @@ void GPURaytracer::RenderAtlasImage(size_t pageIndex)
cmdbuffer->bindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, raytrace.pipeline.get()); cmdbuffer->bindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, raytrace.pipeline.get());
cmdbuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, raytrace.pipelineLayout.get(), 0, raytrace.descriptorSet0.get()); cmdbuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, raytrace.pipelineLayout.get(), 0, raytrace.descriptorSet0.get());
cmdbuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, raytrace.pipelineLayout.get(), 1, raytrace.descriptorSet1.get()); cmdbuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, raytrace.pipelineLayout.get(), 1, raytrace.descriptorSet1.get());
}; }
beginPass();
for (size_t i = 0; i < mesh->surfaces.size(); i++) for (size_t i = 0; i < mesh->surfaces.size(); i++)
{ {
@ -169,7 +170,19 @@ void GPURaytracer::RenderAtlasImage(size_t pageIndex)
firstLight = 0; firstLight = 0;
firstVertex = 0; firstVertex = 0;
BeginCommands(); BeginCommands();
beginPass();
// Begin without clear
RenderPassBegin()
.RenderPass(raytrace.renderPassBegin.get())
.RenderArea(0, 0, atlasImageSize, atlasImageSize)
.Framebuffer(img.raytrace.Framebuffer.get())
.Execute(cmdbuffer.get());
VkDeviceSize offset = 0;
cmdbuffer->bindVertexBuffers(0, 1, &sceneVertexBuffer->buffer, &offset);
cmdbuffer->bindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS, raytrace.pipeline.get());
cmdbuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, raytrace.pipelineLayout.get(), 0, raytrace.descriptorSet0.get());
cmdbuffer->bindDescriptorSet(VK_PIPELINE_BIND_POINT_GRAPHICS, raytrace.pipelineLayout.get(), 1, raytrace.descriptorSet1.get());
printf("."); printf(".");
@ -745,11 +758,11 @@ void GPURaytracer::CreateRaytracePipeline()
.DebugName("raytrace.pipelineLayout") .DebugName("raytrace.pipelineLayout")
.Create(device.get()); .Create(device.get());
raytrace.renderPass = RenderPassBuilder() raytrace.renderPassBegin = RenderPassBuilder()
.AddAttachment( .AddAttachment(
VK_FORMAT_R16G16B16A16_SFLOAT, VK_FORMAT_R16G16B16A16_SFLOAT,
VK_SAMPLE_COUNT_4_BIT, VK_SAMPLE_COUNT_4_BIT,
VK_ATTACHMENT_LOAD_OP_DONT_CARE, VK_ATTACHMENT_LOAD_OP_CLEAR,
VK_ATTACHMENT_STORE_OP_STORE, VK_ATTACHMENT_STORE_OP_STORE,
VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_UNDEFINED,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL) VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)
@ -760,12 +773,30 @@ void GPURaytracer::CreateRaytracePipeline()
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT, VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT, VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
VK_ACCESS_COLOR_ATTACHMENT_READ_BIT) VK_ACCESS_COLOR_ATTACHMENT_READ_BIT)
.DebugName("raytrace.renderpass") .DebugName("raytrace.renderpassBegin")
.Create(device.get());
raytrace.renderPassContinue = RenderPassBuilder()
.AddAttachment(
VK_FORMAT_R16G16B16A16_SFLOAT,
VK_SAMPLE_COUNT_4_BIT,
VK_ATTACHMENT_LOAD_OP_LOAD,
VK_ATTACHMENT_STORE_OP_STORE,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL,
VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)
.AddSubpass()
.AddSubpassColorAttachmentRef(0, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)
.AddExternalSubpassDependency(
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT,
VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT,
VK_ACCESS_COLOR_ATTACHMENT_READ_BIT)
.DebugName("raytrace.renderpassContinue")
.Create(device.get()); .Create(device.get());
raytrace.pipeline = GraphicsPipelineBuilder() raytrace.pipeline = GraphicsPipelineBuilder()
.Layout(raytrace.pipelineLayout.get()) .Layout(raytrace.pipelineLayout.get())
.RenderPass(raytrace.renderPass.get()) .RenderPass(raytrace.renderPassBegin.get())
.AddVertexShader(vertShader.get()) .AddVertexShader(vertShader.get())
.AddFragmentShader(fragShader.get()) .AddFragmentShader(fragShader.get())
.AddVertexBufferBinding(0, sizeof(SceneVertex)) .AddVertexBufferBinding(0, sizeof(SceneVertex))
@ -906,7 +937,7 @@ LightmapImage GPURaytracer::CreateImage(int width, int height)
.Create(device.get()); .Create(device.get());
img.raytrace.Framebuffer = FramebufferBuilder() img.raytrace.Framebuffer = FramebufferBuilder()
.RenderPass(raytrace.renderPass.get()) .RenderPass(raytrace.renderPassBegin.get())
.Size(width, height) .Size(width, height)
.AddAttachment(img.raytrace.View.get()) .AddAttachment(img.raytrace.View.get())
.DebugName("LightmapImage.raytrace.Framebuffer") .DebugName("LightmapImage.raytrace.Framebuffer")

View file

@ -197,7 +197,8 @@ private:
std::unique_ptr<VulkanDescriptorSetLayout> descriptorSetLayout1; std::unique_ptr<VulkanDescriptorSetLayout> descriptorSetLayout1;
std::unique_ptr<VulkanPipelineLayout> pipelineLayout; std::unique_ptr<VulkanPipelineLayout> pipelineLayout;
std::unique_ptr<VulkanPipeline> pipeline; std::unique_ptr<VulkanPipeline> pipeline;
std::unique_ptr<VulkanRenderPass> renderPass; std::unique_ptr<VulkanRenderPass> renderPassBegin;
std::unique_ptr<VulkanRenderPass> renderPassContinue;
std::unique_ptr<VulkanDescriptorPool> descriptorPool0; std::unique_ptr<VulkanDescriptorPool> descriptorPool0;
std::unique_ptr<VulkanDescriptorPool> descriptorPool1; std::unique_ptr<VulkanDescriptorPool> descriptorPool1;
std::unique_ptr<VulkanDescriptorSet> descriptorSet0; std::unique_ptr<VulkanDescriptorSet> descriptorSet0;