Browse Source

Fix a bug when shadow tile allocations fail

Panagiotis Christopoulos Charitos 7 years ago
parent
commit
a2add5b79b

+ 14 - 0
src/anki/renderer/ShadowMapping.cpp

@@ -395,6 +395,13 @@ TileAllocatorResult ShadowMapping::allocateTilesAndScratchTiles(U64 lightUuid,
 		{
 		{
 			ANKI_R_LOGW("There is not enough space in the shadow atlas for more shadow maps. "
 			ANKI_R_LOGW("There is not enough space in the shadow atlas for more shadow maps. "
 						"Increase the r.shadowMapping.tileCountPerRowOrColumn or decrease the scene's shadow casters");
 						"Increase the r.shadowMapping.tileCountPerRowOrColumn or decrease the scene's shadow casters");
+
+			// Invalidate cache entries for what we already allocated
+			for(U j = 0; j < i; ++j)
+			{
+				m_esmTileAlloc.invalidateCache(lightUuid, faceIndices[j]);
+			}
+
 			return res;
 			return res;
 		}
 		}
 
 
@@ -429,6 +436,13 @@ TileAllocatorResult ShadowMapping::allocateTilesAndScratchTiles(U64 lightUuid,
 		{
 		{
 			ANKI_R_LOGW("Don't have enough space in the scratch shadow mapping buffer. "
 			ANKI_R_LOGW("Don't have enough space in the scratch shadow mapping buffer. "
 						"If you see this message too often increase r.shadowMapping.scratchTileCountX/Y");
 						"If you see this message too often increase r.shadowMapping.scratchTileCountX/Y");
+
+			// Invalidate ESM tiles
+			for(U j = 0; j < faceCount; ++j)
+			{
+				m_esmTileAlloc.invalidateCache(lightUuid, faceIndices[j]);
+			}
+
 			return res;
 			return res;
 		}
 		}
 
 

+ 16 - 0
src/anki/renderer/TileAllocator.cpp

@@ -270,4 +270,20 @@ TileAllocatorResult TileAllocator::allocate(Timestamp crntTimestamp,
 	return TileAllocatorResult::ALLOCATION_SUCCEDDED;
 	return TileAllocatorResult::ALLOCATION_SUCCEDDED;
 }
 }
 
 
+void TileAllocator::invalidateCache(U64 lightUuid, U32 lightFace)
+{
+	ANKI_ASSERT(m_cachingEnabled);
+	ANKI_ASSERT(lightUuid > 0);
+
+	HashMapKey key;
+	key.m_lightUuid = lightUuid;
+	key.m_face = lightFace;
+
+	auto it = m_lightInfoToTileIdx.find(key);
+	if(it != m_lightInfoToTileIdx.getEnd())
+	{
+		m_lightInfoToTileIdx.erase(m_alloc, it);
+	}
+}
+
 } // end namespace anki
 } // end namespace anki

+ 3 - 0
src/anki/renderer/TileAllocator.h

@@ -39,6 +39,9 @@ public:
 		U32 lod,
 		U32 lod,
 		Array<U32, 4>& tileViewport);
 		Array<U32, 4>& tileViewport);
 
 
+	/// Remove an light from the cache.
+	void invalidateCache(U64 lightUuid, U32 lightFace);
+
 private:
 private:
 	class Tile;
 	class Tile;