OSDN Git Service

Analyze the shader for define instructions.
authorNicolas Capens <capn@google.com>
Fri, 15 May 2015 19:24:08 +0000 (15:24 -0400)
committerNicolas Capens <capn@google.com>
Fri, 15 May 2015 20:40:18 +0000 (20:40 +0000)
This eliminates the need to specify if shaders can contain defined
constant values in the front-end using a global variable.

Change-Id: If7802a2743c0afa650a2631cd7945c8b3d7cf645
Reviewed-on: https://swiftshader-review.googlesource.com/3152
Reviewed-by: Greg Hartman <ghartman@google.com>
Tested-by: Greg Hartman <ghartman@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
Tested-by: Nicolas Capens <capn@google.com>
src/OpenGL/libGL/Device.cpp
src/OpenGL/libGLES_CM/Device.cpp
src/OpenGL/libGLESv2/Device.cpp
src/Radiance/libRAD/Device.cpp
src/Shader/PixelRoutine.cpp
src/Shader/Shader.cpp
src/Shader/Shader.hpp
src/Shader/VertexProgram.cpp

index 062c4fe..cd314d2 100644 (file)
@@ -25,8 +25,6 @@
 #include "Common/Timer.hpp"\r
 #include "../common/debug.h"\r
 \r
-bool localShaderConstants = false;\r
-\r
 namespace gl\r
 {\r
        using namespace sw;\r
index 57667ab..de71203 100644 (file)
@@ -25,8 +25,6 @@
 #include "Common/Timer.hpp"\r
 #include "../common/debug.h"\r
 \r
-bool localShaderConstants = false;\r
-\r
 namespace es1\r
 {\r
        using namespace sw;\r
index 57a0df7..5eabab1 100644 (file)
@@ -25,8 +25,6 @@
 #include "Common/Timer.hpp"\r
 #include "../common/debug.h"\r
 \r
-bool localShaderConstants = false;\r
-\r
 namespace es2\r
 {\r
        using namespace sw;\r
index 1692f00..9e87461 100644 (file)
@@ -25,8 +25,6 @@
 #include "Common/Timer.hpp"\r
 #include "../common/debug.h"\r
 \r
-bool localShaderConstants = false;\r
-\r
 namespace es2\r
 {\r
        using namespace sw;\r
index b9f3ab9..d9cab28 100644 (file)
@@ -20,8 +20,6 @@
 #include "Constants.hpp"
 #include "Debug.hpp"
 
-extern bool localShaderConstants;
-
 namespace sw
 {
        extern bool complementaryDepthBuffer;
@@ -5911,7 +5909,7 @@ namespace sw
                        c.z = c.z.zzzz;
                        c.w = c.w.wwww;
 
-                       if(localShaderConstants)   // Constant may be known at compile time
+                       if(shader->containsDefineInstruction())   // Constant may be known at compile time
                        {
                                for(size_t j = 0; j < shader->getLength(); j++)
                                {
index f00a6a8..e2f6765 100644 (file)
@@ -1337,6 +1337,11 @@ namespace sw
                return containsLeave;
        }
 
+       bool Shader::containsDefineInstruction() const
+       {
+               return containsDefine;
+       }
+
        bool Shader::usesSampler(int index) const
        {
                return (usedSamplers & (1 << index)) != 0;
@@ -1545,6 +1550,7 @@ namespace sw
                containsLeave = false;
                containsBreak = false;
                containsContinue = false;
+               containsDefine = false;
 
                // Determine global presence of branching instructions
                for(unsigned int i = 0; i < instruction.size(); i++)
@@ -1579,6 +1585,10 @@ namespace sw
                                {
                                        containsContinue = true;
                                }
+                       case OPCODE_DEF:
+                       case OPCODE_DEFB:
+                       case OPCODE_DEFI:
+                               containsDefine = true;
                        }
                }
 
index 8c4fe3d..d4fd609 100644 (file)
@@ -519,6 +519,7 @@ namespace sw
                bool containsBreakInstruction() const;\r
                bool containsContinueInstruction() const;\r
                bool containsLeaveInstruction() const;\r
+               bool containsDefineInstruction() const;\r
                bool usesSampler(int i) const;\r
 \r
                struct Semantic\r
@@ -593,6 +594,7 @@ namespace sw
                bool containsBreak;\r
                bool containsContinue;\r
                bool containsLeave;\r
+               bool containsDefine;\r
        };\r
 }\r
 \r
index a2b4537..acbdbcf 100644 (file)
@@ -18,8 +18,6 @@
 #include "SamplerCore.hpp"
 #include "Debug.hpp"
 
-extern bool localShaderConstants;
-
 namespace sw
 {
        VertexProgram::VertexProgram(const VertexProcessor::State &state, const VertexShader *shader) : VertexRoutine(state, shader)
@@ -731,7 +729,7 @@ namespace sw
                        c.z = c.z.zzzz;
                        c.w = c.w.wwww;
 
-                       if(localShaderConstants)   // Constant may be known at compile time
+                       if(shader->containsDefineInstruction())   // Constant may be known at compile time
                        {
                                for(size_t j = 0; j < shader->getLength(); j++)
                                {