|
|
@@ -3,7 +3,7 @@
|
|
|
// Code licensed under the BSD License.
|
|
|
// http://www.anki3d.org/LICENSE
|
|
|
|
|
|
-#include <AnKi/Renderer/HiZ.h>
|
|
|
+#include <AnKi/Renderer/HZB.h>
|
|
|
#include <AnKi/Renderer/Renderer.h>
|
|
|
#include <AnKi/Renderer/GBuffer.h>
|
|
|
#include <AnKi/Core/ConfigSet.h>
|
|
|
@@ -27,33 +27,33 @@
|
|
|
|
|
|
namespace anki {
|
|
|
|
|
|
-Error HiZ::init()
|
|
|
+Error HZB::init()
|
|
|
{
|
|
|
- registerDebugRenderTarget("HiZ");
|
|
|
+ registerDebugRenderTarget("HZB");
|
|
|
|
|
|
- ANKI_CHECK(ResourceManager::getSingleton().loadResource("ShaderBinaries/HiZReprojection.ankiprogbin", m_reproj.m_prog));
|
|
|
+ ANKI_CHECK(ResourceManager::getSingleton().loadResource("ShaderBinaries/HZBReprojection.ankiprogbin", m_reproj.m_prog));
|
|
|
|
|
|
const ShaderProgramResourceVariant* variant;
|
|
|
m_reproj.m_prog->getOrCreateVariant(variant);
|
|
|
m_reproj.m_grProg.reset(&variant->getProgram());
|
|
|
|
|
|
- ANKI_CHECK(ResourceManager::getSingleton().loadResource("ShaderBinaries/ClearTextureCompute.ankiprogbin", m_clearHiZ.m_prog));
|
|
|
- ShaderProgramResourceVariantInitInfo variantInit(m_clearHiZ.m_prog);
|
|
|
+ ANKI_CHECK(ResourceManager::getSingleton().loadResource("ShaderBinaries/ClearTextureCompute.ankiprogbin", m_clearHZB.m_prog));
|
|
|
+ ShaderProgramResourceVariantInitInfo variantInit(m_clearHZB.m_prog);
|
|
|
variantInit.addMutation("TEXTURE_DIMENSIONS", 2);
|
|
|
variantInit.addMutation("COMPONENT_TYPE", 1);
|
|
|
- m_clearHiZ.m_prog->getOrCreateVariant(variantInit, variant);
|
|
|
- m_clearHiZ.m_grProg.reset(&variant->getProgram());
|
|
|
+ m_clearHZB.m_prog->getOrCreateVariant(variantInit, variant);
|
|
|
+ m_clearHZB.m_grProg.reset(&variant->getProgram());
|
|
|
|
|
|
- ANKI_CHECK(ResourceManager::getSingleton().loadResource("ShaderBinaries/HiZGenPyramid.ankiprogbin", m_mipmapping.m_prog));
|
|
|
+ ANKI_CHECK(ResourceManager::getSingleton().loadResource("ShaderBinaries/HZBGenPyramid.ankiprogbin", m_mipmapping.m_prog));
|
|
|
m_mipmapping.m_prog->getOrCreateVariant(variant);
|
|
|
m_mipmapping.m_grProg.reset(&variant->getProgram());
|
|
|
|
|
|
- m_hiZRtDescr = getRenderer().create2DRenderTargetDescription(ConfigSet::getSingleton().getRHiZWidth(), ConfigSet::getSingleton().getRHiZHeight(),
|
|
|
- Format::kR32_Uint, "HiZ U32");
|
|
|
- m_hiZRtDescr.m_mipmapCount = U8(computeMaxMipmapCount2d(m_hiZRtDescr.m_width, m_hiZRtDescr.m_height, 1));
|
|
|
- m_hiZRtDescr.bake();
|
|
|
+ m_HZBRtDescr = getRenderer().create2DRenderTargetDescription(ConfigSet::getSingleton().getRHZBWidth(), ConfigSet::getSingleton().getRHZBHeight(),
|
|
|
+ Format::kR32_Uint, "HZB U32");
|
|
|
+ m_HZBRtDescr.m_mipmapCount = U8(computeMaxMipmapCount2d(m_HZBRtDescr.m_width, m_HZBRtDescr.m_height, 1));
|
|
|
+ m_HZBRtDescr.bake();
|
|
|
|
|
|
- BufferInitInfo buffInit("HiZCounterBuffer");
|
|
|
+ BufferInitInfo buffInit("HZBCounterBuffer");
|
|
|
buffInit.m_size = sizeof(U32);
|
|
|
buffInit.m_usage = BufferUsageBit::kStorageComputeWrite | BufferUsageBit::kTransferDestination;
|
|
|
m_mipmapping.m_counterBuffer = GrManager::getSingleton().newBuffer(buffInit);
|
|
|
@@ -61,37 +61,37 @@ Error HiZ::init()
|
|
|
return Error::kNone;
|
|
|
}
|
|
|
|
|
|
-void HiZ::populateRenderGraph(RenderingContext& ctx)
|
|
|
+void HZB::populateRenderGraph(RenderingContext& ctx)
|
|
|
{
|
|
|
RenderGraphDescription& rgraph = ctx.m_renderGraphDescr;
|
|
|
|
|
|
- m_runCtx.m_hiZRt = rgraph.newRenderTarget(m_hiZRtDescr);
|
|
|
+ m_runCtx.m_HZBRt = rgraph.newRenderTarget(m_HZBRtDescr);
|
|
|
TextureSubresourceInfo firstMipSubresource;
|
|
|
|
|
|
// Clear RT
|
|
|
{
|
|
|
- ComputeRenderPassDescription& pass = rgraph.newComputeRenderPass("HiZ clear");
|
|
|
- pass.newTextureDependency(m_runCtx.m_hiZRt, TextureUsageBit::kImageComputeWrite, firstMipSubresource);
|
|
|
+ ComputeRenderPassDescription& pass = rgraph.newComputeRenderPass("HZB clear");
|
|
|
+ pass.newTextureDependency(m_runCtx.m_HZBRt, TextureUsageBit::kImageComputeWrite, firstMipSubresource);
|
|
|
|
|
|
pass.setWork([this](RenderPassWorkContext& rctx) {
|
|
|
CommandBuffer& cmdb = *rctx.m_commandBuffer;
|
|
|
|
|
|
- cmdb.bindShaderProgram(m_clearHiZ.m_grProg.get());
|
|
|
+ cmdb.bindShaderProgram(m_clearHZB.m_grProg.get());
|
|
|
|
|
|
TextureSubresourceInfo firstMipSubresource;
|
|
|
- rctx.bindImage(0, 0, m_runCtx.m_hiZRt, firstMipSubresource);
|
|
|
+ rctx.bindImage(0, 0, m_runCtx.m_HZBRt, firstMipSubresource);
|
|
|
|
|
|
UVec4 clearColor(0u);
|
|
|
cmdb.setPushConstants(&clearColor, sizeof(clearColor));
|
|
|
|
|
|
- dispatchPPCompute(cmdb, 8, 8, 1, m_hiZRtDescr.m_width, m_hiZRtDescr.m_height, 1);
|
|
|
+ dispatchPPCompute(cmdb, 8, 8, 1, m_HZBRtDescr.m_width, m_HZBRtDescr.m_height, 1);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
// Reproject
|
|
|
{
|
|
|
- ComputeRenderPassDescription& pass = rgraph.newComputeRenderPass("HiZ reprojection");
|
|
|
- pass.newTextureDependency(m_runCtx.m_hiZRt, TextureUsageBit::kImageComputeWrite, firstMipSubresource);
|
|
|
+ ComputeRenderPassDescription& pass = rgraph.newComputeRenderPass("HZB reprojection");
|
|
|
+ pass.newTextureDependency(m_runCtx.m_HZBRt, TextureUsageBit::kImageComputeWrite, firstMipSubresource);
|
|
|
pass.newTextureDependency(getRenderer().getGBuffer().getPreviousFrameDepthRt(), TextureUsageBit::kSampledCompute);
|
|
|
|
|
|
pass.setWork([this, &ctx](RenderPassWorkContext& rctx) {
|
|
|
@@ -101,7 +101,7 @@ void HiZ::populateRenderGraph(RenderingContext& ctx)
|
|
|
|
|
|
rctx.bindTexture(0, 0, getRenderer().getGBuffer().getPreviousFrameDepthRt(), TextureSubresourceInfo(DepthStencilAspectBit::kDepth));
|
|
|
TextureSubresourceInfo firstMipSubresource;
|
|
|
- rctx.bindImage(0, 1, m_runCtx.m_hiZRt, firstMipSubresource);
|
|
|
+ rctx.bindImage(0, 1, m_runCtx.m_HZBRt, firstMipSubresource);
|
|
|
|
|
|
cmdb.setPushConstants(&ctx.m_matrices.m_reprojection, sizeof(Mat4));
|
|
|
|
|
|
@@ -111,22 +111,22 @@ void HiZ::populateRenderGraph(RenderingContext& ctx)
|
|
|
|
|
|
// Mipmap
|
|
|
{
|
|
|
- ComputeRenderPassDescription& pass = rgraph.newComputeRenderPass("HiZ mip gen");
|
|
|
+ ComputeRenderPassDescription& pass = rgraph.newComputeRenderPass("HZB mip gen");
|
|
|
|
|
|
- pass.newTextureDependency(m_runCtx.m_hiZRt, TextureUsageBit::kSampledCompute, firstMipSubresource);
|
|
|
+ pass.newTextureDependency(m_runCtx.m_HZBRt, TextureUsageBit::kSampledCompute, firstMipSubresource);
|
|
|
|
|
|
- for(U32 mip = 1; mip < m_hiZRtDescr.m_mipmapCount; ++mip)
|
|
|
+ for(U32 mip = 1; mip < m_HZBRtDescr.m_mipmapCount; ++mip)
|
|
|
{
|
|
|
TextureSubresourceInfo subresource;
|
|
|
subresource.m_firstMipmap = mip;
|
|
|
- pass.newTextureDependency(m_runCtx.m_hiZRt, TextureUsageBit::kImageComputeWrite, subresource);
|
|
|
+ pass.newTextureDependency(m_runCtx.m_HZBRt, TextureUsageBit::kImageComputeWrite, subresource);
|
|
|
}
|
|
|
|
|
|
pass.setWork([this](RenderPassWorkContext& rgraphCtx) {
|
|
|
CommandBuffer& cmdb = *rgraphCtx.m_commandBuffer;
|
|
|
|
|
|
TextureSubresourceInfo firstMipSubresource;
|
|
|
- const U32 mipsToCompute = m_hiZRtDescr.m_mipmapCount - 1;
|
|
|
+ const U32 mipsToCompute = m_HZBRtDescr.m_mipmapCount - 1;
|
|
|
|
|
|
// Zero the counter buffer once before everything else
|
|
|
if(!m_mipmapping.m_counterBufferZeroed) [[unlikely]]
|
|
|
@@ -145,7 +145,7 @@ void HiZ::populateRenderGraph(RenderingContext& ctx)
|
|
|
varAU2(dispatchThreadGroupCountXY);
|
|
|
varAU2(workGroupOffset); // needed if Left and Top are not 0,0
|
|
|
varAU2(numWorkGroupsAndMips);
|
|
|
- varAU4(rectInfo) = initAU4(0, 0, m_hiZRtDescr.m_width, m_hiZRtDescr.m_height);
|
|
|
+ varAU4(rectInfo) = initAU4(0, 0, m_HZBRtDescr.m_width, m_HZBRtDescr.m_height);
|
|
|
SpdSetup(dispatchThreadGroupCountXY, workGroupOffset, numWorkGroupsAndMips, rectInfo, mipsToCompute);
|
|
|
|
|
|
struct Uniforms
|
|
|
@@ -174,11 +174,11 @@ void HiZ::populateRenderGraph(RenderingContext& ctx)
|
|
|
subresource.m_firstMipmap = 1;
|
|
|
}
|
|
|
|
|
|
- rgraphCtx.bindImage(0, 0, m_runCtx.m_hiZRt, subresource, mip);
|
|
|
+ rgraphCtx.bindImage(0, 0, m_runCtx.m_HZBRt, subresource, mip);
|
|
|
}
|
|
|
|
|
|
cmdb.bindStorageBuffer(0, 1, m_mipmapping.m_counterBuffer.get(), 0, kMaxPtrSize);
|
|
|
- rgraphCtx.bindTexture(0, 2, m_runCtx.m_hiZRt, firstMipSubresource);
|
|
|
+ rgraphCtx.bindTexture(0, 2, m_runCtx.m_HZBRt, firstMipSubresource);
|
|
|
|
|
|
cmdb.dispatchCompute(dispatchThreadGroupCountXY[0], dispatchThreadGroupCountXY[1], 1);
|
|
|
});
|