diff --git a/include/boo/graphicsdev/IGraphicsCommandQueue.hpp b/include/boo/graphicsdev/IGraphicsCommandQueue.hpp index 26bff5c..858a4df 100644 --- a/include/boo/graphicsdev/IGraphicsCommandQueue.hpp +++ b/include/boo/graphicsdev/IGraphicsCommandQueue.hpp @@ -33,7 +33,7 @@ struct IGraphicsCommandQueue virtual void drawInstancesIndexed(size_t start, size_t count, size_t instCount)=0; virtual void resolveBindTexture(const ObjToken& texture, const SWindowRect& rect, - bool tlOrigin, int bindIdx, bool color, bool depth)=0; + bool tlOrigin, int bindIdx, bool color, bool depth, bool clearDepth=false)=0; virtual void resolveDisplay(const ObjToken& source)=0; virtual void execute()=0; diff --git a/lib/graphicsdev/D3D11.cpp b/lib/graphicsdev/D3D11.cpp index 768b535..918b263 100644 --- a/lib/graphicsdev/D3D11.cpp +++ b/lib/graphicsdev/D3D11.cpp @@ -1112,7 +1112,7 @@ struct D3D11CommandQueue : IGraphicsCommandQueue } void resolveBindTexture(const boo::ObjToken& texture, const SWindowRect& rect, - bool tlOrigin, int bindIdx, bool color, bool depth) + bool tlOrigin, int bindIdx, bool color, bool depth, bool clearDepth) { const D3D11TextureR* tex = texture.cast(); if (color && tex->m_colorBindCount) @@ -1135,6 +1135,9 @@ struct D3D11CommandQueue : IGraphicsCommandQueue { m_deferredCtx->CopyResource(tex->m_depthBindTex[bindIdx].Get(), tex->m_depthTex.Get()); } + + if (clearDepth) + m_deferredCtx->ClearDepthStencilView(tex->m_dsv.Get(), D3D11_CLEAR_DEPTH, 0.0f, 0); } boo::ObjToken m_doPresent; diff --git a/lib/graphicsdev/D3D12.cpp b/lib/graphicsdev/D3D12.cpp index 728dfeb..75dff65 100644 --- a/lib/graphicsdev/D3D12.cpp +++ b/lib/graphicsdev/D3D12.cpp @@ -1404,7 +1404,7 @@ struct D3D12CommandQueue : IGraphicsCommandQueue void resolveBindTexture(const boo::ObjToken& texture, const SWindowRect& rect, bool tlOrigin, - int bindIdx, bool color, bool depth) + int bindIdx, bool color, bool depth, bool clearDepth) { D3D12TextureR* tex = texture.cast(); @@ -1468,6 +1468,12 @@ struct D3D12CommandQueue : IGraphicsCommandQueue }; m_cmdList->ResourceBarrier(2, copyTeardown); } + + if (clearDepth) + { + CD3DX12_CPU_DESCRIPTOR_HANDLE handle(tex->m_dsvHeap->GetCPUDescriptorHandleForHeapStart()); + m_cmdList->ClearDepthStencilView(handle, D3D12_CLEAR_FLAG_DEPTH, 0.0f, 0, 0, nullptr); + } } bool m_doPresent = false; diff --git a/lib/graphicsdev/GL.cpp b/lib/graphicsdev/GL.cpp index 9047921..2ab580a 100644 --- a/lib/graphicsdev/GL.cpp +++ b/lib/graphicsdev/GL.cpp @@ -1076,6 +1076,7 @@ struct GLCommandQueue : IGraphicsCommandQueue int bindIdx; bool resolveColor : 1; bool resolveDepth : 1; + bool clearDepth : 1; Command(Op op) : m_op(op) {} Command(const Command&) = delete; Command& operator=(const Command&) = delete; @@ -1308,6 +1309,12 @@ struct GLCommandQueue : IGraphicsCommandQueue cmd.viewport.rect.location[0], cmd.viewport.rect.location[1], cmd.viewport.rect.size[0], cmd.viewport.rect.size[1]); } + if (cmd.clearDepth) + { + glBindFramebuffer(GL_DRAW_FRAMEBUFFER, tex->m_fbo); + glDepthMask(GL_TRUE); + glClear(GL_DEPTH_BUFFER_BIT); + } break; } case Command::Op::Present: @@ -1456,7 +1463,7 @@ struct GLCommandQueue : IGraphicsCommandQueue } void resolveBindTexture(const ObjToken& texture, const SWindowRect& rect, bool tlOrigin, - int bindIdx, bool color, bool depth) + int bindIdx, bool color, bool depth, bool clearDepth) { GLTextureR* tex = texture.cast(); std::vector& cmds = m_cmdBufs[m_fillBuf]; @@ -1465,6 +1472,7 @@ struct GLCommandQueue : IGraphicsCommandQueue cmds.back().bindIdx = bindIdx; cmds.back().resolveColor = color; cmds.back().resolveDepth = depth; + cmds.back().clearDepth = clearDepth; SWindowRect intersectRect = rect.intersect(SWindowRect(0, 0, tex->m_width, tex->m_height)); SWindowRect& targetRect = cmds.back().viewport.rect; targetRect.location[0] = intersectRect.location[0]; diff --git a/lib/graphicsdev/Metal.mm b/lib/graphicsdev/Metal.mm index d3bc94d..9e6610c 100644 --- a/lib/graphicsdev/Metal.mm +++ b/lib/graphicsdev/Metal.mm @@ -1169,7 +1169,7 @@ struct MetalCommandQueue : IGraphicsCommandQueue } void resolveBindTexture(const ObjToken& texture, const SWindowRect& rect, bool tlOrigin, - int bindIdx, bool color, bool depth) + int bindIdx, bool color, bool depth, bool clearDepth) { MetalTextureR* tex = texture.cast(); @autoreleasepool @@ -1208,7 +1208,7 @@ struct MetalCommandQueue : IGraphicsCommandQueue } [blitEnc endEncoding]; - m_enc = [m_cmdBuf renderCommandEncoderWithDescriptor:tex->m_passDesc]; + m_enc = [m_cmdBuf renderCommandEncoderWithDescriptor:clearDepth ? tex->m_clearDepthPassDesc : tex->m_passDesc]; [m_enc setFrontFacingWinding:MTLWindingCounterClockwise]; if (m_boundVp.width || m_boundVp.height) diff --git a/lib/graphicsdev/Vulkan.cpp b/lib/graphicsdev/Vulkan.cpp index 97f01fd..2c5f13a 100644 --- a/lib/graphicsdev/Vulkan.cpp +++ b/lib/graphicsdev/Vulkan.cpp @@ -2791,7 +2791,7 @@ struct VulkanCommandQueue : IGraphicsCommandQueue void resolveBindTexture(const boo::ObjToken& texture, const SWindowRect& rect, bool tlOrigin, - int bindIdx, bool color, bool depth) + int bindIdx, bool color, bool depth, bool clearDepth) { VkCommandBuffer cmdBuf = m_cmdBufs[m_fillBuf]; VulkanTextureR* ctexture = texture.cast(); @@ -2867,6 +2867,19 @@ struct VulkanCommandQueue : IGraphicsCommandQueue } vk::CmdBeginRenderPass(cmdBuf, &m_boundTarget.cast()->m_passBeginInfo, VK_SUBPASS_CONTENTS_INLINE); + + if (clearDepth) + { + VkClearAttachment clr = {}; + VkClearRect rect = {}; + rect.layerCount = 1; + rect.rect.extent.width = ctexture->m_width; + rect.rect.extent.height = ctexture->m_height; + + clr.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT; + clr.clearValue.depthStencil.depth = 1.f; + vk::CmdClearAttachments(cmdBuf, 1, &clr, 1, &rect); + } } void execute();