Added LoadOP to render pass

This commit is contained in:
antopilo
2025-03-23 01:03:42 -04:00
parent 58c2193356
commit e8fda9c544
8 changed files with 44 additions and 15 deletions

View File

@@ -617,7 +617,6 @@ void GizmoDrawer::DrawGizmos(Ref<Scene> scene, bool occluded)
renderList.Flush(gizmoShader, true);
}
// Sound emitter
auto audioView = scene->m_Registry.view<TransformComponent, AudioEmitterComponent>();
for (auto e : audioView)

View File

@@ -213,7 +213,6 @@ void ViewportWidget::OnSceneChanged(Ref<Nuake::Scene> scene)
sceneViewport->GetOnDebugDraw().AddRaw(this, &ViewportWidget::OnDebugDraw);
}
float GetGizmoScale(const Vector3& camPosition, const Nuake::Vector3& position)
{
float distance = Distance(camPosition, position);
@@ -228,7 +227,6 @@ float GetGizmoScale(const Vector3& camPosition, const Nuake::Vector3& position)
return 1.0f;
}
template<typename T>
void DrawIconGizmo(DebugCmd& debugCmd, const std::string& icon)
{

View File

@@ -52,6 +52,22 @@ void Cmd::ClearColorImage(Ref<VulkanImage> img, Color color) const
vkCmdClearColorImage(CmdBuffer, img->GetImage(), VK_IMAGE_LAYOUT_GENERAL, &clearValue, 1, &clearRange);
}
void Cmd::ClearDepthImage(Ref<VulkanImage> img) const
{
VkClearDepthStencilValue clearValue = {};
clearValue.depth = 0.0f;
clearValue.stencil = 0;
VkImageSubresourceRange clearRange = {};
clearRange.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
clearRange.baseMipLevel = 0;
clearRange.levelCount = VK_REMAINING_MIP_LEVELS;
clearRange.baseArrayLayer = 0;
clearRange.layerCount = VK_REMAINING_ARRAY_LAYERS;
vkCmdClearDepthStencilImage(CmdBuffer, img->GetImage(), VK_IMAGE_LAYOUT_GENERAL, &clearValue, 1, &clearRange);
}
void Cmd::BindDescriptorSet(VkPipelineLayout pipeline, VkDescriptorSet descriptor, uint32_t set) const
{
vkCmdBindDescriptorSets(

View File

@@ -26,6 +26,7 @@ namespace Nuake
void SetViewport(const Vector2& size) const;
void SetScissor(const Vector2& size) const;
void ClearColorImage(Ref<VulkanImage> img, Color color = Color(0, 0, 0, 1)) const;
void ClearDepthImage(Ref<VulkanImage> img) const;
void BindDescriptorSet(VkPipelineLayout pipeline, VkDescriptorSet descriptor, uint32_t set) const;
void BindIndexBuffer(VkBuffer buffer) const;
void DrawIndexed(uint32_t count) const;

View File

@@ -9,9 +9,10 @@
using namespace Nuake;
TextureAttachment::TextureAttachment(const std::string& name, ImageFormat format, ImageUsage usage) :
TextureAttachment::TextureAttachment(const std::string& name, ImageFormat format, ImageUsage usage, bool clearOnLoad) :
Name(name),
Format(format)
Format(format),
ClearOnLoad(clearOnLoad)
{
Image = std::make_shared<VulkanImage>(format, Vector2(1280, 720), usage);
@@ -37,11 +38,21 @@ void RenderPass::Execute(PassRenderContext& ctx, PassAttachments& inputs)
void RenderPass::ClearAttachments(PassRenderContext& ctx, PassAttachments& inputs)
{
// Clear all color attachments
for (auto& attachment : inputs)
for (int i = 0; i < std::size(Attachments); i++)
{
if (attachment->GetUsage() != ImageUsage::Depth)
auto& texture = inputs[i];
auto& spec = Attachments[i];
if (spec.ClearOnLoad)
{
ctx.commandBuffer.ClearColorImage(attachment, this->ClearColor);
if (texture->GetUsage() != ImageUsage::Depth)
{
ctx.commandBuffer.ClearColorImage(texture, this->ClearColor);
}
else
{
ctx.commandBuffer.ClearDepthImage(texture);
}
}
}
}
@@ -120,9 +131,9 @@ void RenderPass::Render(PassRenderContext& ctx, PassAttachments& inputs)
}
}
TextureAttachment& RenderPass::AddAttachment(const std::string& name, ImageFormat format, ImageUsage usage)
TextureAttachment& RenderPass::AddAttachment(const std::string& name, ImageFormat format, ImageUsage usage, bool clearOnLoad)
{
auto newAttachment = TextureAttachment(name, format, usage);
auto newAttachment = TextureAttachment(name, format, usage, clearOnLoad);
if (usage == ImageUsage::Depth)
{
DepthAttachment = newAttachment;

View File

@@ -32,9 +32,10 @@ namespace Nuake
std::string Name;
ImageFormat Format;
Ref<VulkanImage> Image;
bool ClearOnLoad = true;
public:
TextureAttachment(const std::string& name, ImageFormat format, ImageUsage usage = ImageUsage::Default);
TextureAttachment(const std::string& name, ImageFormat format, ImageUsage usage = ImageUsage::Default, bool clearOnLoad = true);
TextureAttachment() = default;
~TextureAttachment() = default;
};
@@ -88,7 +89,7 @@ namespace Nuake
public:
void SetDepthTest(bool enabled) { HasDepthTest = enabled; }
std::string GetName() const { return Name; }
TextureAttachment& AddAttachment(const std::string& name, ImageFormat format, ImageUsage usage = ImageUsage::Default);
TextureAttachment& AddAttachment(const std::string& name, ImageFormat format, ImageUsage usage = ImageUsage::Default, bool clearOnLoad = true);
TextureAttachment& GetAttachment(const std::string& name);
std::vector<TextureAttachment> GetAttachments();

View File

@@ -157,6 +157,7 @@ SceneRenderPipeline::SceneRenderPipeline()
});
gBufferPass.SetRender([&](PassRenderContext& ctx) {
Cmd& cmd = ctx.commandBuffer;
Ref<Scene> scene = ctx.scene;
auto& res = GPUResources::Get();
@@ -283,8 +284,10 @@ SceneRenderPipeline::SceneRenderPipeline()
auto& gizmoPass = GBufferPipeline.AddPass("Gizmo");
gizmoPass.SetShaders(shaderMgr.GetShader("gizmo_vert"), shaderMgr.GetShader("gizmo_frag"));
gizmoPass.SetPushConstant(debugConstant);
gizmoPass.AddAttachment("GizmoOutput", GizmoOutput->GetFormat());
gizmoPass.AddInput("Depth");
gizmoPass.AddAttachment("GizmoOutput", GizmoOutput->GetFormat());
gizmoPass.AddAttachment("GizmoDepth", GBufferDepth->GetFormat(), ImageUsage::Depth, false);
gizmoPass.SetDepthTest(true);
gizmoPass.SetPreRender([&](PassRenderContext& ctx) {
Cmd& cmd = ctx.commandBuffer;
auto& layout = ctx.renderPass->PipelineLayout;
@@ -411,7 +414,7 @@ void SceneRenderPipeline::Render(PassRenderContext& ctx)
{ GBufferAlbedo, GBufferDepth, GBufferNormal, GBufferMaterial, GBufferEntityID }, // GBuffer
{ ShadingOutput }, // Shading
{ TonemappedOutput }, // Tonemap
{ GizmoOutput },
{ GizmoOutput, GBufferDepth }, // Reusing depth from gBuffer
{ GizmoCombineOutput },
{ OutlineOutput }
};

View File

@@ -177,7 +177,7 @@ VkRenderingAttachmentInfo VulkanInit::DepthAttachmentInfo(VkImageView view, VkIm
depthAttachment.imageView = view;
depthAttachment.imageLayout = layout;
depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_CLEAR;
depthAttachment.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
depthAttachment.storeOp = VK_ATTACHMENT_STORE_OP_STORE;
depthAttachment.clearValue.depthStencil.depth = 0.f;