Analyze the shader for define instructions.
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>
diff --git a/src/OpenGL/libGL/Device.cpp b/src/OpenGL/libGL/Device.cpp
index 062c4fe..cd314d2 100644
--- a/src/OpenGL/libGL/Device.cpp
+++ b/src/OpenGL/libGL/Device.cpp
@@ -25,8 +25,6 @@
#include "Common/Timer.hpp"
#include "../common/debug.h"
-bool localShaderConstants = false;
-
namespace gl
{
using namespace sw;
diff --git a/src/OpenGL/libGLES_CM/Device.cpp b/src/OpenGL/libGLES_CM/Device.cpp
index 57667ab..de71203 100644
--- a/src/OpenGL/libGLES_CM/Device.cpp
+++ b/src/OpenGL/libGLES_CM/Device.cpp
@@ -25,8 +25,6 @@
#include "Common/Timer.hpp"
#include "../common/debug.h"
-bool localShaderConstants = false;
-
namespace es1
{
using namespace sw;
diff --git a/src/OpenGL/libGLESv2/Device.cpp b/src/OpenGL/libGLESv2/Device.cpp
index 57a0df7..5eabab1 100644
--- a/src/OpenGL/libGLESv2/Device.cpp
+++ b/src/OpenGL/libGLESv2/Device.cpp
@@ -25,8 +25,6 @@
#include "Common/Timer.hpp"
#include "../common/debug.h"
-bool localShaderConstants = false;
-
namespace es2
{
using namespace sw;
diff --git a/src/Radiance/libRAD/Device.cpp b/src/Radiance/libRAD/Device.cpp
index 1692f00..9e87461 100644
--- a/src/Radiance/libRAD/Device.cpp
+++ b/src/Radiance/libRAD/Device.cpp
@@ -25,8 +25,6 @@
#include "Common/Timer.hpp"
#include "../common/debug.h"
-bool localShaderConstants = false;
-
namespace es2
{
using namespace sw;
diff --git a/src/Shader/PixelRoutine.cpp b/src/Shader/PixelRoutine.cpp
index b9f3ab9..d9cab28 100644
--- a/src/Shader/PixelRoutine.cpp
+++ b/src/Shader/PixelRoutine.cpp
@@ -20,8 +20,6 @@
#include "Constants.hpp"
#include "Debug.hpp"
-extern bool localShaderConstants;
-
namespace sw
{
extern bool complementaryDepthBuffer;
@@ -5911,7 +5909,7 @@
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++)
{
diff --git a/src/Shader/Shader.cpp b/src/Shader/Shader.cpp
index f00a6a8..e2f6765 100644
--- a/src/Shader/Shader.cpp
+++ b/src/Shader/Shader.cpp
@@ -1337,6 +1337,11 @@
return containsLeave;
}
+ bool Shader::containsDefineInstruction() const
+ {
+ return containsDefine;
+ }
+
bool Shader::usesSampler(int index) const
{
return (usedSamplers & (1 << index)) != 0;
@@ -1545,6 +1550,7 @@
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 @@
{
containsContinue = true;
}
+ case OPCODE_DEF:
+ case OPCODE_DEFB:
+ case OPCODE_DEFI:
+ containsDefine = true;
}
}
diff --git a/src/Shader/Shader.hpp b/src/Shader/Shader.hpp
index 8c4fe3d..d4fd609 100644
--- a/src/Shader/Shader.hpp
+++ b/src/Shader/Shader.hpp
@@ -519,6 +519,7 @@
bool containsBreakInstruction() const;
bool containsContinueInstruction() const;
bool containsLeaveInstruction() const;
+ bool containsDefineInstruction() const;
bool usesSampler(int i) const;
struct Semantic
@@ -593,6 +594,7 @@
bool containsBreak;
bool containsContinue;
bool containsLeave;
+ bool containsDefine;
};
}
diff --git a/src/Shader/VertexProgram.cpp b/src/Shader/VertexProgram.cpp
index a2b4537..acbdbcf 100644
--- a/src/Shader/VertexProgram.cpp
+++ b/src/Shader/VertexProgram.cpp
@@ -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 @@
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++)
{