Browse Source

Fixed driver timeout crash related to invalid bounds checking in light grid creation shaders

BearishSun 8 years ago
parent
commit
4ec80fa09d

+ 2 - 6
Data/Raw/Engine/Shaders/LightGridLLCreation.bsl

@@ -90,10 +90,8 @@ Technique
 				uint3 groupThreadId : SV_GroupThreadID,
 				uint3 dispatchThreadId : SV_DispatchThreadID)
 			{
-				uint2 viewportMax = gViewportRectangle.xy + gViewportRectangle.zw;
-
 				// Ignore pixels out of valid range
-				if (all(dispatchThreadId.xy >= viewportMax))
+				if (any(dispatchThreadId.xy >= gGridSize.xy))
 					return;
 					
 				uint maxNumLinks = gNumCells * gMaxNumLightsPerCell;	
@@ -214,10 +212,8 @@ Technique
 
 			void main()
 			{
-				uvec2 viewportMax = gViewportRectangle.xy + gViewportRectangle.zw;
-
 				// Ignore pixels out of valid range
-				if (all(greaterThanEqual(gl_GlobalInvocationID.xy, viewportMax)))
+				if (any(greaterThanEqual(gl_GlobalInvocationID.xy, gGridSize.xy)))
 					return;
 					
 				uint maxNumLinks = gNumCells * gMaxNumLightsPerCell;	

+ 2 - 6
Data/Raw/Engine/Shaders/LightGridLLReduction.bsl

@@ -24,10 +24,8 @@ Technique
 				uint3 groupThreadId : SV_GroupThreadID,
 				uint3 dispatchThreadId : SV_DispatchThreadID)
 			{
-				uint2 viewportMax = gViewportRectangle.xy + gViewportRectangle.zw;
-
 				// Ignore pixels out of valid range
-				if (all(dispatchThreadId.xy >= viewportMax))
+				if (any(dispatchThreadId.xy >= gGridSize.xy))
 					return;
 					
 				uint maxNumLinks = gNumCells * gMaxNumLightsPerCell;	
@@ -93,10 +91,8 @@ Technique
 			
 			void main()
 			{
-				uvec2 viewportMax = gViewportRectangle.xy + gViewportRectangle.zw;
-
 				// Ignore pixels out of valid range
-				if (all(greaterThanEqual(gl_GlobalInvocationID.xy, viewportMax)))
+				if (any(greaterThanEqual(gl_GlobalInvocationID.xy, gGridSize.xy)))
 					return;
 					
 				uint maxNumLinks = gNumCells * gMaxNumLightsPerCell;	

+ 22 - 4
Source/RenderBeast/Source/BsRendererCamera.cpp

@@ -238,8 +238,17 @@ namespace bs { namespace ct
 		float c = projMatrix[3][2];
 
 		Vector2 output;
-		output.x = b / (depthRange * c);
-		output.y = minDepth / depthRange - a / (depthRange * c);
+
+		if (c != 0.0f)
+		{
+			output.x = b / (depthRange * c);
+			output.y = minDepth / depthRange - a / (depthRange * c);
+		}
+		else // Ortographic, assuming viewing towards negative Z
+		{
+			output.x = b / -depthRange;
+			output.y = minDepth / depthRange - a / -depthRange;
+		}
 
 		return output;
 	}
@@ -268,8 +277,17 @@ namespace bs { namespace ct
 		float c = projMatrix[3][2];
 
 		Vector2 output;
-		output.x = b / c;
-		output.y = - a / c;
+
+		if (c != 0.0f)
+		{
+			output.x = b / c;
+			output.y = -a / c;
+		}
+		else // Ortographic, assuming viewing towards negative Z
+		{
+			output.x = -b;
+			output.y = a;
+		}
 
 		return output;
 	}