|
|
@@ -6,7 +6,7 @@
|
|
|
#include <AnKi/Renderer/Ssr.h>
|
|
|
#include <AnKi/Renderer/Renderer.h>
|
|
|
#include <AnKi/Util/Tracer.h>
|
|
|
-#include <AnKi/Renderer/LightShading.h>
|
|
|
+#include <AnKi/Renderer/DownscaleBlur.h>
|
|
|
#include <AnKi/Renderer/GBuffer.h>
|
|
|
#include <AnKi/Renderer/DepthDownscale.h>
|
|
|
|
|
|
@@ -29,10 +29,9 @@
|
|
|
|
|
|
namespace anki {
|
|
|
|
|
|
-// TODO remove the _ in the names
|
|
|
static NumericCVar<U32> g_ssrStepIncrementCVar(CVarSubsystem::kRenderer, "SsrStepIncrement", 32, 1, 256, "The number of steps for each loop");
|
|
|
static NumericCVar<U32> g_ssrMaxIterationsCVar(CVarSubsystem::kRenderer, "SsrMaxIterations", 64, 1, 256, "Max SSR raymarching loop iterations");
|
|
|
-static NumericCVar<F32> g_ssrRoughnessCutoffCVar(CVarSubsystem::kRenderer, "SsrRoughnessCutoff_", (ANKI_PLATFORM_MOBILE) ? 0.7f : 1.0f, 0.0f, 1.0f,
|
|
|
+static NumericCVar<F32> g_ssrRoughnessCutoffCVar(CVarSubsystem::kRenderer, "SsrRoughnessCutoff", (ANKI_PLATFORM_MOBILE) ? 0.7f : 1.0f, 0.0f, 1.0f,
|
|
|
"Materials with roughness higher that this value will fallback to probe reflections");
|
|
|
static BoolCVar g_ssrQuarterResolution(CVarSubsystem::kRenderer, "SsrQuarterResolution", ANKI_PLATFORM_MOBILE);
|
|
|
|
|
|
@@ -62,27 +61,14 @@ Error Ssr::initInternal()
|
|
|
mipTexUsage |= TextureUsageBit::kFramebufferWrite;
|
|
|
}
|
|
|
|
|
|
- TextureInitInfo mipTexInit =
|
|
|
- getRenderer().create2DRenderTargetInitInfo(getRenderer().getInternalResolution().x() / 2, getRenderer().getInternalResolution().y() / 2,
|
|
|
- getRenderer().getHdrFormat(), mipTexUsage, "Downscaled light shading");
|
|
|
- mipTexInit.m_mipmapCount = U8(computeMaxMipmapCount2d(mipTexInit.m_width, mipTexInit.m_height, 16));
|
|
|
- m_mipmappedLightShdingTex = getRenderer().createAndClearRenderTarget(mipTexInit, TextureUsageBit::kAllSampled);
|
|
|
-
|
|
|
m_ssrRtDescr = getRenderer().create2DRenderTargetDescription(rez.x(), rez.y(), Format::kR16G16B16A16_Sfloat, "SSR");
|
|
|
m_ssrRtDescr.bake();
|
|
|
|
|
|
m_fbDescr.m_colorAttachmentCount = 1;
|
|
|
m_fbDescr.bake();
|
|
|
|
|
|
- ANKI_CHECK(loadShaderProgram("ShaderBinaries/Ssr.ankiprogbin", {}, m_prog, m_mipmapLightShadingGrProg, "MipGeneration"));
|
|
|
ANKI_CHECK(loadShaderProgram("ShaderBinaries/Ssr.ankiprogbin", {}, m_prog, m_ssrGrProg, "Ssr"));
|
|
|
|
|
|
- BufferInitInfo buffInit("SsrCounterBuffer");
|
|
|
- buffInit.m_size = sizeof(U32);
|
|
|
- buffInit.m_usage = BufferUsageBit::kUavComputeWrite | BufferUsageBit::kTransferDestination;
|
|
|
- m_counterBuffer = GrManager::getSingleton().newBuffer(buffInit);
|
|
|
- zeroBuffer(m_counterBuffer.get());
|
|
|
-
|
|
|
return Error::kNone;
|
|
|
}
|
|
|
|
|
|
@@ -93,16 +79,6 @@ void Ssr::populateRenderGraph(RenderingContext& ctx)
|
|
|
RenderGraphDescription& rgraph = ctx.m_renderGraphDescr;
|
|
|
const Bool preferCompute = g_preferComputeCVar.get();
|
|
|
|
|
|
- if(m_mipmappedLightShdingTexImportedOnce) [[likely]]
|
|
|
- {
|
|
|
- m_runCtx.m_mipmappedLightShadingRt = rgraph.importRenderTarget(m_mipmappedLightShdingTex.get());
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- m_runCtx.m_mipmappedLightShadingRt = rgraph.importRenderTarget(m_mipmappedLightShdingTex.get(), TextureUsageBit::kAllSampled);
|
|
|
- m_mipmappedLightShdingTexImportedOnce = true;
|
|
|
- }
|
|
|
-
|
|
|
m_runCtx.m_ssrRt = rgraph.newRenderTarget(m_ssrRtDescr);
|
|
|
|
|
|
TextureUsageBit readUsage;
|
|
|
@@ -120,13 +96,15 @@ void Ssr::populateRenderGraph(RenderingContext& ctx)
|
|
|
{
|
|
|
// TODO
|
|
|
GraphicsRenderPassDescription& pass = rgraph.newGraphicsRenderPass("SSR");
|
|
|
+ pass.setFramebufferInfo(m_fbDescr, {m_runCtx.m_ssrRt}, {});
|
|
|
+
|
|
|
ppass = &pass;
|
|
|
|
|
|
readUsage = TextureUsageBit::kSampledFragment;
|
|
|
writeUsage = TextureUsageBit::kFramebufferWrite;
|
|
|
}
|
|
|
|
|
|
- ppass->newTextureDependency(m_runCtx.m_mipmappedLightShadingRt, readUsage);
|
|
|
+ ppass->newTextureDependency(getRenderer().getDownscaleBlur().getRt(), readUsage);
|
|
|
ppass->newTextureDependency(getRenderer().getGBuffer().getColorRt(1), readUsage);
|
|
|
ppass->newTextureDependency(getRenderer().getGBuffer().getColorRt(2), readUsage);
|
|
|
ppass->newTextureDependency(getRenderer().getDepthDownscale().getRt(), readUsage);
|
|
|
@@ -156,7 +134,7 @@ void Ssr::populateRenderGraph(RenderingContext& ctx)
|
|
|
rgraphCtx.bindColorTexture(0, 2, getRenderer().getGBuffer().getColorRt(1));
|
|
|
rgraphCtx.bindColorTexture(0, 3, getRenderer().getGBuffer().getColorRt(2));
|
|
|
rgraphCtx.bindColorTexture(0, 4, getRenderer().getDepthDownscale().getRt());
|
|
|
- rgraphCtx.bindColorTexture(0, 5, m_runCtx.m_mipmappedLightShadingRt);
|
|
|
+ rgraphCtx.bindColorTexture(0, 5, getRenderer().getDownscaleBlur().getRt());
|
|
|
|
|
|
if(g_preferComputeCVar.get())
|
|
|
{
|
|
|
@@ -171,82 +149,4 @@ void Ssr::populateRenderGraph(RenderingContext& ctx)
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-void Ssr::populateRenderGraphPostLightShading(RenderingContext& ctx)
|
|
|
-{
|
|
|
- ANKI_TRACE_SCOPED_EVENT(SsrPost);
|
|
|
-
|
|
|
- RenderGraphDescription& rgraph = ctx.m_renderGraphDescr;
|
|
|
- const Bool preferCompute = g_preferComputeCVar.get();
|
|
|
-
|
|
|
- TextureUsageBit readUsage;
|
|
|
- TextureUsageBit writeUsage;
|
|
|
- RenderPassDescriptionBase* ppass;
|
|
|
- if(preferCompute)
|
|
|
- {
|
|
|
- ComputeRenderPassDescription& pass = rgraph.newComputeRenderPass("SSR: Light downscale");
|
|
|
- ppass = &pass;
|
|
|
-
|
|
|
- readUsage = TextureUsageBit::kSampledCompute;
|
|
|
- writeUsage = TextureUsageBit::kUavComputeWrite;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- // TODO
|
|
|
- ANKI_ASSERT(0);
|
|
|
- readUsage = TextureUsageBit::kSampledFragment;
|
|
|
- writeUsage = TextureUsageBit::kFramebufferWrite;
|
|
|
- }
|
|
|
-
|
|
|
- ppass->newTextureDependency(getRenderer().getLightShading().getRt(), readUsage);
|
|
|
- ppass->newTextureDependency(m_runCtx.m_mipmappedLightShadingRt, writeUsage);
|
|
|
-
|
|
|
- ppass->setWork([this](RenderPassWorkContext& rgraphCtx) {
|
|
|
- CommandBuffer& cmdb = *rgraphCtx.m_commandBuffer;
|
|
|
-
|
|
|
- cmdb.bindShaderProgram(m_mipmapLightShadingGrProg.get());
|
|
|
-
|
|
|
- const U32 mipsToCompute = m_mipmappedLightShdingTex->getMipmapCount();
|
|
|
-
|
|
|
- varAU2(dispatchThreadGroupCountXY);
|
|
|
- varAU2(workGroupOffset); // needed if Left and Top are not 0,0
|
|
|
- varAU2(numWorkGroupsAndMips);
|
|
|
- varAU4(rectInfo) = initAU4(0, 0, getRenderer().getInternalResolution().x(), getRenderer().getInternalResolution().y());
|
|
|
- SpdSetup(dispatchThreadGroupCountXY, workGroupOffset, numWorkGroupsAndMips, rectInfo, mipsToCompute);
|
|
|
-
|
|
|
- class Constants
|
|
|
- {
|
|
|
- public:
|
|
|
- Vec2 m_invSrcTexSize;
|
|
|
- U32 m_threadGroupCount;
|
|
|
- U32 m_mipmapCount;
|
|
|
- } consts;
|
|
|
- consts.m_invSrcTexSize = 1.0f / Vec2(getRenderer().getInternalResolution());
|
|
|
- consts.m_threadGroupCount = numWorkGroupsAndMips[0];
|
|
|
- consts.m_mipmapCount = numWorkGroupsAndMips[1];
|
|
|
-
|
|
|
- cmdb.setPushConstants(&consts, sizeof(consts));
|
|
|
-
|
|
|
- for(U32 mip = 0; mip < kMaxMipsSinglePassDownsamplerCanProduce; ++mip)
|
|
|
- {
|
|
|
- TextureSubresourceInfo subresource;
|
|
|
- if(mip < mipsToCompute)
|
|
|
- {
|
|
|
- subresource.m_firstMipmap = mip;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- subresource.m_firstMipmap = 0; // Put something random
|
|
|
- }
|
|
|
-
|
|
|
- rgraphCtx.bindUavTexture(0, 0, m_runCtx.m_mipmappedLightShadingRt, subresource, mip);
|
|
|
- }
|
|
|
-
|
|
|
- cmdb.bindUavBuffer(0, 1, m_counterBuffer.get(), 0, sizeof(U32));
|
|
|
- rgraphCtx.bindColorTexture(0, 2, getRenderer().getLightShading().getRt());
|
|
|
- cmdb.bindSampler(0, 3, getRenderer().getSamplers().m_trilinearClamp.get());
|
|
|
-
|
|
|
- cmdb.dispatchCompute(dispatchThreadGroupCountXY[0], dispatchThreadGroupCountXY[1], 1);
|
|
|
- });
|
|
|
-}
|
|
|
-
|
|
|
} // end namespace anki
|