Browse Source

Disabled shader branching from lighting calculations as on some GPUs it has a dramatic negative performance impact.
Added -noflush command line option to disable GPU command queue flushing before rendering.

Lasse Öörni 14 years ago
parent
commit
d0ab5fb7d6

+ 1 - 0
Docs/GettingStarted.dox

@@ -99,6 +99,7 @@ Urho3D.exe understands the following command line options:
 -deferred   Use deferred rendering
 -b<length>  Sound buffer length in milliseconds
 -r<freq>    Mixing frequency in Hz
+-noflush    Disable GPU command queue flushing
 -nolimit    Disable frame limiter
 -noshadows  Disable rendering of shadows
 -nosound    Disable sound output

+ 4 - 0
Engine/Engine/Engine.cpp

@@ -84,6 +84,7 @@ bool Engine::Initialize(const String& windowTitle, const String& logName, const
     bool sound = true;
     bool stereo = true;
     bool interpolate = true;
+    bool flush = true;
     
     for (unsigned i = 0; i < arguments.Size(); ++i)
     {
@@ -105,6 +106,8 @@ bool Engine::Initialize(const String& windowTitle, const String& logName, const
                 stereo = false;
             else if (argument == "noshadows")
                 shadows = false;
+            else if (argument == "noflush")
+                flush = false;
             else if (argument == "sm2")
                 forceSM2 = true;
             else
@@ -186,6 +189,7 @@ bool Engine::Initialize(const String& windowTitle, const String& logName, const
     if (!headless_)
     {
         Graphics* graphics = GetSubsystem<Graphics>();
+        graphics->SetFlushGPU(flush);
         graphics->SetForceSM2(forceSM2);
         graphics->SetWindowTitle(windowTitle);
         if (!graphics->SetMode(mode, width, height, fullscreen, vsync, multiSample))

+ 1 - 24
SourceAssets/HLSLShaders/Forward.hlsl

@@ -4,11 +4,6 @@
 #include "Lighting.hlsl"
 #include "Fog.hlsl"
 
-// Use branching if the pixel shader is expensive
-#if defined(SM3) && (defined(SPECULAR) || defined(SHADOW))
-    #define BRANCHING
-#endif
-
 void VS(float4 iPos : POSITION,
     float3 iNormal : NORMAL,
     #ifdef NORMALMAP
@@ -142,15 +137,10 @@ void PS(float2 iTexCoord : TEXCOORD0,
             diff = GetDiffusePointOrSpot(normal, iWorldPos.xyz, lightDir, lightVec);
         #endif
 
-        #ifdef BRANCHING
-        if (diff > 0.0)
-        {
-        #endif
-
         #ifdef SHADOW
             diff *= GetShadow(iShadowPos);
         #endif
-        
+
         #ifdef SPOTLIGHT
             lightColor = iSpotPos.w > 0.0 ? tex2Dproj(sLightSpotMap, iSpotPos).rgb * cLightColor.rgb : 0.0;
         #else
@@ -180,19 +170,6 @@ void PS(float2 iTexCoord : TEXCOORD0,
             oColor = float4(GetLitFog(finalColor, iWorldPos.w), diffColor.a);
         #endif
 
-        #ifdef BRANCHING
-        }
-        else
-        {
-        #ifdef AMBIENT
-            float3 finalColor = cAmbientColor * diffColor.rgb;
-            oColor = float4(GetFog(finalColor, iWorldPos.w), diffColor.a);
-        #else
-            oColor = float4(0.0, 0.0, 0.0, diffColor.a);
-        #endif
-        }
-        #endif
-
     #else
 
         #if defined(VOLUMETRIC) && (defined(DIRLIGHT) || defined(POINTLIGHT) || defined(SPOTLIGHT))

+ 0 - 16
SourceAssets/HLSLShaders/Light.hlsl

@@ -4,11 +4,6 @@
 #include "ScreenPos.hlsl"
 #include "Lighting.hlsl"
 
-// Use branching if the pixel shader is expensive
-#if defined(SM3) && (defined(SPECULAR) || defined(SHADOW))
-    #define BRANCHING
-#endif
-
 void VS(float4 iPos : POSITION,
     #ifdef DIRLIGHT
         out float2 oScreenPos : TEXCOORD0,
@@ -91,11 +86,6 @@ void PS(
         diff = GetDiffusePointOrSpot(normal, worldPos, lightDir, lightVec);
     #endif
 
-    #ifdef BRANCHING
-    if (diff > 0.0)
-    {
-    #endif
-
     #ifdef SHADOW
         float4 shadowPos = mul(float4(worldPos, 1.0), cShadowProjPS);
         diff *= GetShadow(shadowPos);
@@ -120,10 +110,4 @@ void PS(
         float3 finalColor = diff * diffInput.rgb * lightColor;
         oColor = float4(finalColor, 0.0);
     #endif
-
-    #ifdef BRANCHING
-    }
-    else
-        oColor = 0.0;
-    #endif
 }