Browse Source

SVGF seems to be working but pretty baddly

Panagiotis Christopoulos Charitos 4 years ago
parent
commit
b5fdfa0c4f

+ 1 - 1
AnKi/Gr/RenderGraph.cpp

@@ -675,7 +675,7 @@ RenderGraph::BakeContext* RenderGraph::newContext(const RenderGraphDescription&
 			// Create a new TextureInitInfo with the derived usage
 			// Create a new TextureInitInfo with the derived usage
 			TextureInitInfo initInf = inRt.m_initInfo;
 			TextureInitInfo initInf = inRt.m_initInfo;
 			initInf.m_usage = inRt.m_usageDerivedByDeps;
 			initInf.m_usage = inRt.m_usageDerivedByDeps;
-			ANKI_ASSERT(initInf.m_usage != TextureUsageBit::NONE);
+			ANKI_ASSERT(initInf.m_usage != TextureUsageBit::NONE && "Probably not referenced by any pass");
 
 
 			// Create the new hash
 			// Create the new hash
 			const U64 hash = appendHash(&initInf.m_usage, sizeof(initInf.m_usage), inRt.m_hash);
 			const U64 hash = appendHash(&initInf.m_usage, sizeof(initInf.m_usage), inRt.m_hash);

+ 17 - 0
AnKi/Gr/RenderGraph.h

@@ -185,6 +185,23 @@ public:
 		m_commandBuffer->bindImage(set, binding, view, arrayIdx);
 		m_commandBuffer->bindImage(set, binding, view, arrayIdx);
 	}
 	}
 
 
+	/// Convenience method to bind the whole image.
+	void bindImage(U32 set, U32 binding, RenderTargetHandle handle, U32 arrayIdx = 0)
+	{
+		TexturePtr tex;
+#if ANKI_ENABLE_ASSERTS
+		tex = getTexture(handle);
+		ANKI_ASSERT(tex->getLayerCount() == 1 && tex->getMipmapCount() == 1
+					&& tex->getDepthStencilAspect() == DepthStencilAspectBit::NONE);
+#endif
+		const TextureSubresourceInfo subresource;
+		TextureUsageBit usage;
+		getRenderTargetState(handle, subresource, tex, usage);
+		TextureViewInitInfo viewInit(tex, subresource, "TmpRenderGraph");
+		TextureViewPtr view = m_commandBuffer->getManager().newTextureView(viewInit);
+		m_commandBuffer->bindImage(set, binding, view, arrayIdx);
+	}
+
 	/// Convenience method.
 	/// Convenience method.
 	void bindStorageBuffer(U32 set, U32 binding, BufferHandle handle)
 	void bindStorageBuffer(U32 set, U32 binding, BufferHandle handle)
 	{
 	{

+ 3 - 0
AnKi/Renderer/ConfigDefs.h

@@ -49,3 +49,6 @@ ANKI_CONFIG_OPTION(r_bloomThreshold, 2.5, 0.0, 256.0)
 ANKI_CONFIG_OPTION(r_bloomScale, 2.5, 0.0, 256.0)
 ANKI_CONFIG_OPTION(r_bloomScale, 2.5, 0.0, 256.0)
 
 
 ANKI_CONFIG_OPTION(r_smResolveFactor, 0.5, 0.25, 1.0)
 ANKI_CONFIG_OPTION(r_smResolveFactor, 0.5, 0.25, 1.0)
+
+ANKI_CONFIG_OPTION(r_rtShadowsSvgf, 0, 1, 0)
+ANKI_CONFIG_OPTION(r_rtShadowsSvgfAtrousPassCount, 1, 5, 1)

+ 1 - 0
AnKi/Renderer/Renderer.cpp

@@ -281,6 +281,7 @@ Error Renderer::populateRenderGraph(RenderingContext& ctx)
 	ctx.m_matrices.m_jitter = m_jitteredMats8x[m_frameCount & (m_jitteredMats8x.getSize() - 1)];
 	ctx.m_matrices.m_jitter = m_jitteredMats8x[m_frameCount & (m_jitteredMats8x.getSize() - 1)];
 	ctx.m_matrices.m_projectionJitter = ctx.m_matrices.m_jitter * ctx.m_matrices.m_projection;
 	ctx.m_matrices.m_projectionJitter = ctx.m_matrices.m_jitter * ctx.m_matrices.m_projection;
 	ctx.m_matrices.m_viewProjectionJitter = ctx.m_matrices.m_projectionJitter * ctx.m_matrices.m_view;
 	ctx.m_matrices.m_viewProjectionJitter = ctx.m_matrices.m_projectionJitter * ctx.m_matrices.m_view;
+	ctx.m_matrices.m_invertedViewProjectionJitter = ctx.m_matrices.m_viewProjectionJitter.getInverse();
 
 
 	ctx.m_prevMatrices = m_prevMatrices;
 	ctx.m_prevMatrices = m_prevMatrices;
 
 

+ 1 - 0
AnKi/Renderer/Renderer.h

@@ -38,6 +38,7 @@ public:
 	Mat4 m_jitter = Mat4::getIdentity();
 	Mat4 m_jitter = Mat4::getIdentity();
 	Mat4 m_projectionJitter = Mat4::getIdentity();
 	Mat4 m_projectionJitter = Mat4::getIdentity();
 	Mat4 m_viewProjectionJitter = Mat4::getIdentity();
 	Mat4 m_viewProjectionJitter = Mat4::getIdentity();
+	Mat4 m_invertedViewProjectionJitter = Mat4::getIdentity();
 };
 };
 
 
 /// Rendering context.
 /// Rendering context.

+ 26 - 16
AnKi/Renderer/RtShadows.cpp

@@ -12,6 +12,7 @@
 #include <AnKi/Renderer/RenderQueue.h>
 #include <AnKi/Renderer/RenderQueue.h>
 #include <AnKi/Resource/ShaderProgramResourceSystem.h>
 #include <AnKi/Resource/ShaderProgramResourceSystem.h>
 #include <AnKi/Util/Tracer.h>
 #include <AnKi/Util/Tracer.h>
+#include <AnKi/Core/ConfigSet.h>
 
 
 namespace anki
 namespace anki
 {
 {
@@ -33,6 +34,9 @@ Error RtShadows::init(const ConfigSet& cfg)
 
 
 Error RtShadows::initInternal(const ConfigSet& cfg)
 Error RtShadows::initInternal(const ConfigSet& cfg)
 {
 {
+	m_useSvgf = cfg.getNumberU8("r_rtShadowsSvgf") != 0;
+	m_atrousPassCount = cfg.getNumberU8("r_rtShadowsSvgfAtrousPassCount");
+
 	// Ray gen program
 	// Ray gen program
 	ANKI_CHECK(getResourceManager().loadResource("Shaders/RtShadowsRayGen.ankiprog", m_rayGenProg));
 	ANKI_CHECK(getResourceManager().loadResource("Shaders/RtShadowsRayGen.ankiprog", m_rayGenProg));
 	ShaderProgramResourceVariantInitInfo variantInitInfo(m_rayGenProg);
 	ShaderProgramResourceVariantInitInfo variantInitInfo(m_rayGenProg);
@@ -200,7 +204,10 @@ void RtShadows::populateRenderGraph(RenderingContext& ctx)
 			m_runCtx.m_currentHistoryLengthRt =
 			m_runCtx.m_currentHistoryLengthRt =
 				rgraph.importRenderTarget(m_historyLengthRts[!prevRtIdx], TextureUsageBit::NONE);
 				rgraph.importRenderTarget(m_historyLengthRts[!prevRtIdx], TextureUsageBit::NONE);
 
 
-			m_runCtx.m_varianceRts[0] = rgraph.newRenderTarget(m_varianceRtDescr);
+			if(m_atrousPassCount > 1)
+			{
+				m_runCtx.m_varianceRts[0] = rgraph.newRenderTarget(m_varianceRtDescr);
+			}
 			m_runCtx.m_varianceRts[1] = rgraph.newRenderTarget(m_varianceRtDescr);
 			m_runCtx.m_varianceRts[1] = rgraph.newRenderTarget(m_varianceRtDescr);
 		}
 		}
 	}
 	}
@@ -285,7 +292,7 @@ void RtShadows::populateRenderGraph(RenderingContext& ctx)
 
 
 		for(U32 i = 0; i < m_atrousPassCount; ++i)
 		for(U32 i = 0; i < m_atrousPassCount; ++i)
 		{
 		{
-			const Bool lastPass = i == m_atrousPassCount - 1;
+			const Bool lastPass = i == U32(m_atrousPassCount - 1);
 			const U32 readRtIdx = (i + 1) & 1;
 			const U32 readRtIdx = (i + 1) & 1;
 
 
 			ComputeRenderPassDescription& rpass = rgraph.newComputeRenderPass("RtShadows SVGF Atrous");
 			ComputeRenderPassDescription& rpass = rgraph.newComputeRenderPass("RtShadows SVGF Atrous");
@@ -405,7 +412,7 @@ void RtShadows::run(RenderPassWorkContext& rgraphCtx)
 
 
 	cmdb->bindSampler(0, 6, m_r->getSamplers().m_trilinearRepeat);
 	cmdb->bindSampler(0, 6, m_r->getSamplers().m_trilinearRepeat);
 
 
-	rgraphCtx.bindImage(0, 7, m_runCtx.m_intermediateShadowsRts[0], TextureSubresourceInfo());
+	rgraphCtx.bindImage(0, 7, m_runCtx.m_intermediateShadowsRts[0]);
 
 
 	rgraphCtx.bindColorTexture(0, 8, m_runCtx.m_historyAndFinalRt);
 	rgraphCtx.bindColorTexture(0, 8, m_runCtx.m_historyAndFinalRt);
 	cmdb->bindSampler(0, 9, m_r->getSamplers().m_trilinearClamp);
 	cmdb->bindSampler(0, 9, m_r->getSamplers().m_trilinearClamp);
@@ -420,16 +427,16 @@ void RtShadows::run(RenderPassWorkContext& rgraphCtx)
 	{
 	{
 		// Bind something random
 		// Bind something random
 		rgraphCtx.bindColorTexture(0, 16, m_r->getMotionVectors().getMotionVectorsRt());
 		rgraphCtx.bindColorTexture(0, 16, m_r->getMotionVectors().getMotionVectorsRt());
-		rgraphCtx.bindImage(0, 17, m_runCtx.m_intermediateShadowsRts[0], TextureSubresourceInfo());
+		rgraphCtx.bindImage(0, 17, m_runCtx.m_intermediateShadowsRts[0]);
 		rgraphCtx.bindColorTexture(0, 18, m_r->getMotionVectors().getMotionVectorsRt());
 		rgraphCtx.bindColorTexture(0, 18, m_r->getMotionVectors().getMotionVectorsRt());
-		rgraphCtx.bindImage(0, 19, m_runCtx.m_intermediateShadowsRts[0], TextureSubresourceInfo());
+		rgraphCtx.bindImage(0, 19, m_runCtx.m_intermediateShadowsRts[0]);
 	}
 	}
 	else
 	else
 	{
 	{
 		rgraphCtx.bindColorTexture(0, 16, m_runCtx.m_prevMomentsRt);
 		rgraphCtx.bindColorTexture(0, 16, m_runCtx.m_prevMomentsRt);
-		rgraphCtx.bindImage(0, 17, m_runCtx.m_currentMomentsRt, TextureSubresourceInfo());
+		rgraphCtx.bindImage(0, 17, m_runCtx.m_currentMomentsRt);
 		rgraphCtx.bindColorTexture(0, 18, m_runCtx.m_prevHistoryLengthRt);
 		rgraphCtx.bindColorTexture(0, 18, m_runCtx.m_prevHistoryLengthRt);
-		rgraphCtx.bindImage(0, 19, m_runCtx.m_currentHistoryLengthRt, TextureSubresourceInfo());
+		rgraphCtx.bindImage(0, 19, m_runCtx.m_currentHistoryLengthRt);
 	}
 	}
 
 
 	cmdb->bindAllBindless(1);
 	cmdb->bindAllBindless(1);
@@ -456,10 +463,10 @@ void RtShadows::runDenoise(RenderPassWorkContext& rgraphCtx)
 	rgraphCtx.bindTexture(0, 2, m_r->getGBuffer().getDepthRt(), TextureSubresourceInfo(DepthStencilAspectBit::DEPTH));
 	rgraphCtx.bindTexture(0, 2, m_r->getGBuffer().getDepthRt(), TextureSubresourceInfo(DepthStencilAspectBit::DEPTH));
 	rgraphCtx.bindColorTexture(0, 3, m_r->getGBuffer().getColorRt(2));
 	rgraphCtx.bindColorTexture(0, 3, m_r->getGBuffer().getColorRt(2));
 
 
-	rgraphCtx.bindImage(0, 4, m_runCtx.m_historyAndFinalRt, TextureSubresourceInfo());
+	rgraphCtx.bindImage(0, 4, m_runCtx.m_historyAndFinalRt);
 
 
 	RtShadowsDenoiseUniforms unis;
 	RtShadowsDenoiseUniforms unis;
-	unis.invViewProjMat = m_runCtx.m_ctx->m_matrices.m_viewProjectionJitter.getInverse();
+	unis.invViewProjMat = m_runCtx.m_ctx->m_matrices.m_invertedViewProjectionJitter;
 	unis.time = F32(m_r->getGlobalTimestamp());
 	unis.time = F32(m_r->getGlobalTimestamp());
 	cmdb->setPushConstants(&unis, sizeof(unis));
 	cmdb->setPushConstants(&unis, sizeof(unis));
 
 
@@ -476,15 +483,15 @@ void RtShadows::runSvgfVariance(RenderPassWorkContext& rgraphCtx)
 	cmdb->bindSampler(0, 1, m_r->getSamplers().m_trilinearClamp);
 	cmdb->bindSampler(0, 1, m_r->getSamplers().m_trilinearClamp);
 
 
 	rgraphCtx.bindColorTexture(0, 2, m_runCtx.m_intermediateShadowsRts[0]);
 	rgraphCtx.bindColorTexture(0, 2, m_runCtx.m_intermediateShadowsRts[0]);
-	rgraphCtx.bindColorTexture(0, 3, m_runCtx.m_prevMomentsRt);
+	rgraphCtx.bindColorTexture(0, 3, m_runCtx.m_currentMomentsRt);
 	rgraphCtx.bindColorTexture(0, 4, m_runCtx.m_currentHistoryLengthRt);
 	rgraphCtx.bindColorTexture(0, 4, m_runCtx.m_currentHistoryLengthRt);
 	rgraphCtx.bindTexture(0, 5, m_r->getGBuffer().getDepthRt(), TextureSubresourceInfo(DepthStencilAspectBit::DEPTH));
 	rgraphCtx.bindTexture(0, 5, m_r->getGBuffer().getDepthRt(), TextureSubresourceInfo(DepthStencilAspectBit::DEPTH));
 	rgraphCtx.bindColorTexture(0, 6, m_r->getGBuffer().getColorRt(2));
 	rgraphCtx.bindColorTexture(0, 6, m_r->getGBuffer().getColorRt(2));
 
 
-	rgraphCtx.bindImage(0, 7, m_runCtx.m_intermediateShadowsRts[1], TextureSubresourceInfo());
-	rgraphCtx.bindImage(0, 8, m_runCtx.m_varianceRts[1], TextureSubresourceInfo());
+	rgraphCtx.bindImage(0, 7, m_runCtx.m_intermediateShadowsRts[1]);
+	rgraphCtx.bindImage(0, 8, m_runCtx.m_varianceRts[1]);
 
 
-	const Mat4 invViewProjMat = m_runCtx.m_ctx->m_matrices.m_viewProjectionJitter.getInverse();
+	const Mat4& invViewProjMat = m_runCtx.m_ctx->m_matrices.m_invertedViewProjectionJitter;
 	cmdb->setPushConstants(&invViewProjMat, sizeof(invViewProjMat));
 	cmdb->setPushConstants(&invViewProjMat, sizeof(invViewProjMat));
 
 
 	dispatchPPCompute(cmdb, 8, 8, m_r->getWidth() / 2, m_r->getHeight() / 2);
 	dispatchPPCompute(cmdb, 8, 8, m_r->getWidth() / 2, m_r->getHeight() / 2);
@@ -516,17 +523,20 @@ void RtShadows::runSvgfAtrous(RenderPassWorkContext& rgraphCtx)
 
 
 	if(lastPass)
 	if(lastPass)
 	{
 	{
-		rgraphCtx.bindImage(0, 6, m_runCtx.m_historyAndFinalRt, TextureSubresourceInfo());
+		rgraphCtx.bindImage(0, 6, m_runCtx.m_historyAndFinalRt);
 	}
 	}
 	else
 	else
 	{
 	{
-		rgraphCtx.bindImage(0, 6, m_runCtx.m_intermediateShadowsRts[!readRtIdx], TextureSubresourceInfo());
-		rgraphCtx.bindImage(0, 7, m_runCtx.m_varianceRts[!readRtIdx], TextureSubresourceInfo());
+		rgraphCtx.bindImage(0, 6, m_runCtx.m_intermediateShadowsRts[!readRtIdx]);
+		rgraphCtx.bindImage(0, 7, m_runCtx.m_varianceRts[!readRtIdx]);
 	}
 	}
 
 
 	const U32 width = (lastPass) ? m_r->getWidth() : m_r->getWidth() / 2;
 	const U32 width = (lastPass) ? m_r->getWidth() : m_r->getWidth() / 2;
 	const U32 height = (lastPass) ? m_r->getHeight() : m_r->getHeight() / 2;
 	const U32 height = (lastPass) ? m_r->getHeight() : m_r->getHeight() / 2;
 
 
+	const Mat4& invViewProjMat = m_runCtx.m_ctx->m_matrices.m_invertedViewProjectionJitter;
+	cmdb->setPushConstants(&invViewProjMat, sizeof(invViewProjMat));
+
 	dispatchPPCompute(cmdb, 8, 8, width, height);
 	dispatchPPCompute(cmdb, 8, 8, width, height);
 
 
 	++m_runCtx.m_atrousPassIdx;
 	++m_runCtx.m_atrousPassIdx;

+ 1 - 1
AnKi/Renderer/RtShadows.h

@@ -90,7 +90,7 @@ public:
 
 
 	Bool m_rtsImportedOnce = false;
 	Bool m_rtsImportedOnce = false;
 	Bool m_useSvgf = false;
 	Bool m_useSvgf = false;
-	U8 m_atrousPassCount = 1;
+	U8 m_atrousPassCount = 5;
 
 
 	class
 	class
 	{
 	{

+ 2 - 0
AnKi/Resource/ShaderProgramResourceSystem.cpp

@@ -320,10 +320,12 @@ Error ShaderProgramResourceSystem::createRayTracingPrograms(CString cacheDir, co
 		{
 		{
 			const U64 groupHash =
 			const U64 groupHash =
 				ShaderProgramRaytracingLibrary::generateShaderGroupGroupHash(filename, mutationHash, m_alloc);
 				ShaderProgramRaytracingLibrary::generateShaderGroupGroupHash(filename, mutationHash, m_alloc);
+#if ANKI_ENABLE_ASSERTS
 			for(const ShaderGroup& group : m_shaderGroups)
 			for(const ShaderGroup& group : m_shaderGroups)
 			{
 			{
 				ANKI_ASSERT(group.m_hitGroupHash != groupHash && "Shouldn't find group with the same hash");
 				ANKI_ASSERT(group.m_hitGroupHash != groupHash && "Shouldn't find group with the same hash");
 			}
 			}
+#endif
 
 
 			ShaderGroup group;
 			ShaderGroup group;
 			group.m_rayGen = rayGen;
 			group.m_rayGen = rayGen;

+ 2 - 2
AnKi/Shaders/RtShadowsSvgfAtrous.ankiprog

@@ -101,10 +101,10 @@ void main()
 			// Read shadows
 			// Read shadows
 			F32 shadowLayers[MAX_RT_SHADOW_LAYERS];
 			F32 shadowLayers[MAX_RT_SHADOW_LAYERS];
 			unpackRtShadows(textureLod(u_shadowsTex, u_nearestAnyClampSampler, sampleUv, 0.0), shadowLayers);
 			unpackRtShadows(textureLod(u_shadowsTex, u_nearestAnyClampSampler, sampleUv, 0.0), shadowLayers);
-			const F32 luma = computeShadowsLuma(shadowLayers);
 
 
 			// Compute luma weight
 			// Compute luma weight
-			const F32 variance = textureLod(u_varianceTex, u_nearestAnyClampSampler, sampleUv, 0.0).x;
+			const F32 luma = computeShadowsLuma(shadowLayers);
+			const F32 variance = textureLod(u_varianceTex, u_linearAnyClampSampler, sampleUv, 0.0).x;
 			const F32 sigmaL = 4.0;
 			const F32 sigmaL = 4.0;
 			const F32 wl = min(1.0, exp(-abs(luma - refLuma) / (sigmaL * sqrt(variance + 0.001) + EPSILON)));
 			const F32 wl = min(1.0, exp(-abs(luma - refLuma) / (sigmaL * sqrt(variance + 0.001) + EPSILON)));