Browse Source

Trying to find the bug

Panagiotis Christopoulos Charitos 12 years ago
parent
commit
dcb3a71fbe

+ 3 - 0
include/anki/util/System.h

@@ -13,6 +13,9 @@ namespace anki {
 /// Get the number of CPU cores
 extern U32 getCpuCoresCount();
 
+/// Print the backtrace
+extern void printBacktrace();
+
 /// @}
 /// @}
 

+ 6 - 1
shaders/IsLp.glsl

@@ -345,13 +345,18 @@ void main()
 #endif
 
 #if 1
+	fColor = fColor * 0.0001 
+		+ vec3(float(tiles[vInstanceId].lightsCount[1]));
+#endif
+
+#if 0
 	if(tiles[vInstanceId].lightsCount[0] > 0)
 	{
 		fColor += vec3(0.0, 0.1, 0.0);
 	}
 #endif
 
-#if 1
+#if 0
 	vec3 tmpc = vec3((vInstanceId % 4) / 3.0, (vInstanceId % 3) / 2.0, 
 		(vInstanceId % 2));
 	fColor += tmpc / 40.0;

+ 18 - 11
shaders/IsRejectLights.glsl

@@ -16,7 +16,7 @@ uniform highp sampler2D depthMap;
 
 layout(std140, binding = TILES_BLOCK_BINDING) buffer tilesBlock
 {
-	Tile tiles[TILES_Y_COUNT][TILES_X_COUNT];
+	Tile tiles[TILES_Y_COUNT * TILES_X_COUNT];
 };
 
 layout(std140) uniform pointLightsBlock
@@ -37,10 +37,12 @@ layout(std140) uniform commonBlock
 
 void main()
 {
+	uint tileIndex = tileY * TILES_X_COUNT + tileX;
+
 	//
-	// First calculate the z of the near plane
+	// First calculate the z of the far plane
 	//
-	float minDepth = 10000.0; // min depth of tile
+	float maxDepth = -10000.0; // min depth of tile
 
 	const ivec2 COORD = ivec2(ivec2(tileX, tileY) * ivec2(TILE_W, TILE_H));
 
@@ -50,12 +52,12 @@ void main()
 		{
 			float depth = texelFetch(depthMap, COORD + ivec2(x, y), 0).r;
 
-			minDepth = min(depth, minDepth);
+			maxDepth = max(depth, maxDepth);
 		}
 	}
 
 	// Convert to view space
-	float nearZ = -planes.y / (planes.x + minDepth);
+	float z = -planes.y / (planes.x + maxDepth);
 
 	//
 	// Reject point lights
@@ -63,17 +65,22 @@ void main()
 	uint newPointLightIndices[MAX_POINT_LIGHTS_PER_TILE];
 	uint newPointLightsCount = 0;
 
-	uint pointLightsCount = tiles[tileY][tileX].lightsCount[0];
+	tiles[tileIndex].lightsCount[1] = 0;
+
+	uint pointLightsCount = tiles[tileIndex].lightsCount[0];
 	for(uint i = 0U; i < pointLightsCount; ++i)
 	{
-		uint lightId = tiles[tileY][tileX].pointLightIndices[i / 4U][i % 4U];
+		uint lightId = tiles[tileIndex].pointLightIndices[i / 4U][i % 4U];
 
 		vec4 posRadius = pointLights[lightId].posRadius;
 		vec3 pos = posRadius.xyz;
-		float radius = posRadius.w;
+		float radius = -1.0 / posRadius.w;
+
+		if(pos.z < 0.0)
+		tiles[tileIndex].lightsCount[1] += 1;
 		
 		// Should reject?
-		if(pos.z - radius <= nearZ)
+		if((pos.z - 0.5) <= z)
 		{
 			// No
 
@@ -84,8 +91,8 @@ void main()
 	// Copy back
 	for(uint i = 0U; i < newPointLightsCount; i++)
 	{
-		tiles[tileY][tileX].pointLightIndices[i / 4U][i % 4U] = 
+		tiles[tileIndex].pointLightIndices[i / 4U][i % 4U] = 
 			newPointLightIndices[i];
 	}
-	tiles[tileY][tileX].lightsCount[0] = newPointLightsCount;
+	tiles[tileIndex].lightsCount[0] = newPointLightsCount;
 }

+ 7 - 3
src/renderer/Is.cpp

@@ -543,7 +543,7 @@ void Is::initInternal(const RendererInitializer& initializer)
 		throw ANKI_EXCEPTION("Problem with the commonBlock");
 	}
 
-#if ANKI_GL == ANKI_GL_DESKTOP
+#if ANKI_GL == ANKI_GL_DESKTOP && 0
 	if(rejectProg.isLoaded())
 	{
 		ublock = &rejectProg->findUniformBlock("commonBlock");
@@ -564,7 +564,7 @@ void Is::initInternal(const RendererInitializer& initializer)
 		throw ANKI_EXCEPTION("Problem with the pointLightsBlock");
 	}
 
-#if ANKI_GL == ANKI_GL_DESKTOP
+#if ANKI_GL == ANKI_GL_DESKTOP && 0
 	if(rejectProg.isLoaded())
 	{
 		ublock = &rejectProg->findUniformBlock("pointLightsBlock");
@@ -809,11 +809,15 @@ void Is::lightPass()
 		}*/
 		tilesBuffer.setTarget(GL_SHADER_STORAGE_BUFFER);
 		tilesBuffer.setBinding(TILES_BLOCK_BINDING);
-		tilesBuffer.setTarget(GL_UNIFORM_BUFFER);
 
 		commonUbo.setBinding(COMMON_UNIFORMS_BLOCK_BINDING);
 
+		rejectProg->findUniformVariable("depthMap").set(
+			r->getMs().getDepthFai());
+
 		glDispatchCompute(TILES_X_COUNT, TILES_Y_COUNT, 1);
+
+		tilesBuffer.setTarget(GL_UNIFORM_BUFFER);
 	}
 #endif	
 

+ 0 - 1
src/renderer/MainRenderer.cpp

@@ -56,7 +56,6 @@ void MainRenderer::initGl()
 	GlStateSingleton::get().setClearColor(Vec4(1.0, 0.0, 1.0, 1.0));
 	GlStateSingleton::get().setClearDepthValue(1.0);
 	GlStateSingleton::get().setClearStencilValue(0);
-	glDepthFunc(GL_LEQUAL);
 	// CullFace is always on
 	glCullFace(GL_BACK);
 	GlStateSingleton::get().enable(GL_CULL_FACE);

+ 2 - 0
src/util/Assert.cpp

@@ -1,4 +1,5 @@
 #include "anki/util/Assert.h"
+#include "anki/util/System.h"
 #include <cstdlib>
 #include <iostream>
 
@@ -19,6 +20,7 @@ void akassert(bool expr, const char* exprTxt, const char* file, int line,
 #if ANKI_CPU_ARCH == ANKI_CPU_ARCH_INTEL
 		asm("int $3");
 #endif
+		printBacktrace();
 		abort();
 	}
 }

+ 19 - 0
src/util/System.cpp

@@ -3,6 +3,8 @@
 
 #if ANKI_POSIX
 #	include <unistd.h>
+#	include <execinfo.h>
+#	include <signal.h>
 #else
 #	error "Unimplemented"
 #endif
@@ -19,4 +21,21 @@ U32 getCpuCoresCount()
 #endif
 }
 
+//==============================================================================
+void printBacktrace()
+{
+#if ANKI_POSIX
+	void *array[10];
+	size_t size;
+
+	// get void*'s for all entries on the stack
+	size = backtrace(array, 10);
+
+	// print out all the frames to stderr
+	backtrace_symbols_fd(array, size, 2);	
+#else
+#	error "Unimplemented"
+#endif
+}
+
 } // end namespace anki