diff --git a/indra/newview/app_settings/settings.xml b/indra/newview/app_settings/settings.xml
index 6d7e93b36457e0ac9f27b5ab7437bc3975aab2ef..5ade88e32bb5c0ea0c89d13e3535a55503b9f6f6 100644
--- a/indra/newview/app_settings/settings.xml
+++ b/indra/newview/app_settings/settings.xml
@@ -14261,6 +14261,17 @@
       <key>Value</key>
       <integer>1</integer>
     </map>
+  <key>RenderOcclusionTimeout</key>
+  <map>
+    <key>Comment</key>
+    <string>Maximum number of frames to wait on an occlusion query before forcibly reading it back</string>
+    <key>Persist</key>
+    <integer>1</integer>
+    <key>Type</key>
+    <string>S32</string>
+    <key>Value</key>
+    <integer>8</integer>
+  </map>
   <key>UseObjectCacheOcclusion</key>
   <map>
     <key>Comment</key>
diff --git a/indra/newview/llvieweroctree.cpp b/indra/newview/llvieweroctree.cpp
index d1d23cfb8e4210e0c60c15b87ee87c68af204db8..a2d8d30fb2c3b2c7e166400817c8531ad04b248a 100644
--- a/indra/newview/llvieweroctree.cpp
+++ b/indra/newview/llvieweroctree.cpp
@@ -1131,7 +1131,9 @@ void LLOcclusionCullingGroup::checkOcclusion()
                 mOcclusionCheckCount[LLViewerCamera::sCurCameraID]++;
             }
 
-            if (available || mOcclusionCheckCount[LLViewerCamera::sCurCameraID] > 4)
+            static LLCachedControl<S32> occlusion_timeout(gSavedSettings, "RenderOcclusionTimeout", 4);
+
+            if (available || mOcclusionCheckCount[LLViewerCamera::sCurCameraID] > occlusion_timeout)
             {   
                 mOcclusionCheckCount[LLViewerCamera::sCurCameraID] = 0;
                 GLuint query_result;    // Will be # samples drawn, or a boolean depending on mHasOcclusionQuery2 (both are type GLuint)
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index 18b01923461a2c996718611db4cabdea0f4ffdff..f059c87c91f4ba292415d64d39f255247c993a17 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -9419,7 +9419,7 @@ void LLPipeline::generateSunShadow(LLCamera& camera)
 	}
 	else
 	{
-        for (S32 j = 0; j < 4; j++)
+        for (S32 j = 0; j < (gCubeSnapshot ? 3 : 4); j++)
 		{
 			if (!hasRenderDebugMask(RENDER_DEBUG_SHADOW_FRUSTA) && !gCubeSnapshot)
 			{