Browse Source

Fix shadows and Dbg

Panagiotis Christopoulos Charitos 1 year ago
parent
commit
2cc3f66335

+ 1 - 0
AnKi/Renderer/Dbg.cpp

@@ -252,6 +252,7 @@ void Dbg::populateRenderGraph(RenderingContext& ctx)
 	colorRti.m_loadOperation = RenderTargetLoadOperation::kClear;
 	GraphicsRenderPassTargetDesc depthRti(getRenderer().getGBuffer().getDepthRt());
 	depthRti.m_loadOperation = RenderTargetLoadOperation::kLoad;
+	depthRti.m_subresource.m_depthStencilAspect = DepthStencilAspectBit::kDepth;
 	pass.setRenderpassInfo({colorRti}, &depthRti);
 
 	pass.newTextureDependency(m_runCtx.m_rt, TextureUsageBit::kRtvDsvWrite);

+ 6 - 4
AnKi/Renderer/ShadowMapping.cpp

@@ -618,10 +618,11 @@ void ShadowMapping::createDrawShadowsPass(ConstWeakArray<ShadowSubpassInfo> subp
 	// Create the pass
 	GraphicsRenderPass& pass = rgraph.newGraphicsRenderPass(passName);
 
-	const Bool loadFb = !(subpasses.getSize() == 1 && subpasses[0].m_clearTileIndirectArgs.isValid());
+	const Bool maySkipDrawcalls = subpasses[0].m_clearTileIndirectArgs.isValid();
+	const Bool renderpassClear = subpasses.getSize() == 1 && !maySkipDrawcalls; // Rely on renderpass clear
 
 	GraphicsRenderPassTargetDesc smRti(m_runCtx.m_rt);
-	smRti.m_loadOperation = (loadFb) ? RenderTargetLoadOperation::kLoad : RenderTargetLoadOperation::kClear;
+	smRti.m_loadOperation = (renderpassClear) ? RenderTargetLoadOperation::kClear : RenderTargetLoadOperation::kLoad;
 	smRti.m_clearValue.m_depthStencil.m_depth = 1.0f;
 	smRti.m_subresource.m_depthStencilAspect = DepthStencilAspectBit::kDepth;
 	pass.setRenderpassInfo({}, &smRti, viewport[0], viewport[1], viewport[2], viewport[3]);
@@ -629,7 +630,7 @@ void ShadowMapping::createDrawShadowsPass(ConstWeakArray<ShadowSubpassInfo> subp
 	pass.newBufferDependency(visOut.m_dependency, BufferUsageBit::kIndirectDraw);
 	pass.newTextureDependency(m_runCtx.m_rt, TextureUsageBit::kRtvDsvWrite);
 
-	pass.setWork([this, visOut, subpasses, loadFb](RenderPassWorkContext& rgraphCtx) {
+	pass.setWork([this, visOut, subpasses, renderpassClear](RenderPassWorkContext& rgraphCtx) {
 		ANKI_TRACE_SCOPED_EVENT(ShadowMapping);
 
 		CommandBuffer& cmdb = *rgraphCtx.m_commandBuffer;
@@ -640,7 +641,8 @@ void ShadowMapping::createDrawShadowsPass(ConstWeakArray<ShadowSubpassInfo> subp
 
 			cmdb.setViewport(spass.m_viewport[0], spass.m_viewport[1], spass.m_viewport[2], spass.m_viewport[3]);
 
-			if(loadFb)
+			// Clear the tile
+			if(!renderpassClear)
 			{
 				cmdb.bindShaderProgram(m_clearDepthGrProg.get());
 				cmdb.setDepthCompareOperation(CompareOperation::kAlways);

+ 10 - 1
AnKi/Renderer/Utils/GpuVisibility.cpp

@@ -561,13 +561,22 @@ void GpuVisibility::populateRenderGraphInternal(Bool distanceBased, BaseGpuVisib
 		cmdb.fillBuffer(buff, 0); \
 		cmdb.popDebugMarker(); \
 	}
+
+#define ANKI_ZERO_PART(buff, alwaysZero, sizeToZero) \
+	if((alwaysZero || debugZeroing) && buff.isValid()) \
+	{ \
+		cmdb.pushDebugMarker(#buff, Vec3(1.0f, 1.0f, 1.0f)); \
+		cmdb.fillBuffer((debugZeroing) ? buff : BufferView(buff).setRange(sizeToZero), 0); \
+		cmdb.popDebugMarker(); \
+	}
+
 			ANKI_ZERO(stage1Mem.m_counters, true)
 			ANKI_ZERO(stage1Mem.m_visibleRenderables, false)
 			ANKI_ZERO(stage1Mem.m_visibleMeshlets, false)
 			ANKI_ZERO(stage1Mem.m_renderablePrefixSums, true)
 			ANKI_ZERO(stage1Mem.m_meshletPrefixSums, true)
 			ANKI_ZERO(stage1Mem.m_gpuVisIndirectDispatchArgs, false)
-			ANKI_ZERO(stage1Mem.m_visibleAabbIndices, false)
+			ANKI_ZERO_PART(stage1Mem.m_visibleAabbIndices, true, sizeof(U32))
 			ANKI_ZERO(stage1Mem.m_hash, true)
 
 			ANKI_ZERO(stage2Mem.m_legacy.m_instanceRateRenderables, false)

+ 5 - 0
Samples/Common/SampleApp.cpp

@@ -183,6 +183,11 @@ Error SampleApp::userMainLoop(Bool& quit, Second elapsedTime)
 			mover = &scene.getActiveCameraNode();
 		}
 
+		if(in.getKey(KeyCode::k2) == 1)
+		{
+			mover = &scene.findSceneNode("Spot");
+		}
+
 		if(in.getKey(KeyCode::kUp))
 		{
 			mover->rotateLocalX(ROTATE_ANGLE);

+ 17 - 11
Samples/Sponza/Assets/Scene.lua

@@ -1,4 +1,4 @@
--- Generated by: C:\src\anki\out\build\x64-Debug\Binaries\GltfImporter.exe sponza_crytek_7_pbr_3.0.gltf C:/src/anki/Samples/Sponza/Assets/ -rpath Assets -texrpath Assets -lod-count 2 -light-scale 0.0001839 -v
+-- Generated by: C:\src\anki\out\build\x64-Debug-VK\Binaries\GltfImporter.exe sponza_crytek_7_pbr_3.0.gltf C:/src/anki/Samples/Sponza/Assets/ -rpath Assets -texrpath Assets -lod-count 2 -light-scale 0.0001839 -v
 local scene = getSceneGraph()
 local events = getEventManager()
 
@@ -16,16 +16,6 @@ trf:setRotation(rot)
 trf:setScale(Vec4.new(1.000000, 1.000000, 1.000000, 0))
 node:setLocalTransform(trf)
 
-node = scene:newSceneNode("Sphere")
-node:newModelComponent():loadModelResource("Assets/Sphere_MTL_sphere_8df61cca01d9efcc.ankimdl")
-trf = Transform.new()
-trf:setOrigin(Vec4.new(0.718041, 1.838787, 0.000000, 0))
-rot = Mat3x4.new()
-rot:setAll(1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000, 0.000000, 0.000000, 0.000000, 1.000000, 0.000000)
-trf:setRotation(rot)
-trf:setScale(Vec4.new(1.000000, 1.000000, 1.000000, 0))
-node:setLocalTransform(trf)
-
 node = scene:newSceneNode("Cube.011")
 comp = node:newGlobalIlluminationProbeComponent()
 comp:setBoxVolumeSize(Vec3.new(48.094303, 25.484703, 21.568947))
@@ -2884,3 +2874,19 @@ rot:setAll(1.000000, 0.000000, 0.000000, 0.000000, 0.000000, -0.376587, 0.926381
 trf:setRotation(rot)
 trf:setScale(Vec4.new(1.000000, 1.000000, 1.000000, 0))
 node:setLocalTransform(trf)
+
+node = scene:newSceneNode("Spot")
+lcomp = node:newLightComponent()
+lcomp:setLightComponentType(LightComponentType.kSpot)
+lcomp:setDiffuseColor(Vec4.new(19.990450, 19.990450, 19.990450, 1))
+lcomp:setShadowEnabled(1)
+lcomp:setDistance(45.410000)
+lcomp:setOuterAngle(0.514791)
+lcomp:setInnerAngle(0.307609)
+trf = Transform.new()
+trf:setOrigin(Vec4.new(0.000000, 13.235932, -8.790560, 0))
+rot = Mat3x4.new()
+rot:setAll(0.383428, 0.288014, -0.877514, 0.000000, 0.922611, -0.076151, 0.378140, 0.000000, 0.042085, -0.954594, -0.294923, 0.000000)
+trf:setRotation(rot)
+trf:setScale(Vec4.new(1.000000, 1.000000, 1.000000, 0))
+node:setLocalTransform(trf)