Commit eafdb22c by Nicolas Capens

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/3152Reviewed-by: 's avatarGreg Hartman <ghartman@google.com> Tested-by: 's avatarGreg Hartman <ghartman@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 84c9cf00
...@@ -25,8 +25,6 @@ ...@@ -25,8 +25,6 @@
#include "Common/Timer.hpp" #include "Common/Timer.hpp"
#include "../common/debug.h" #include "../common/debug.h"
bool localShaderConstants = false;
namespace gl namespace gl
{ {
using namespace sw; using namespace sw;
......
...@@ -25,8 +25,6 @@ ...@@ -25,8 +25,6 @@
#include "Common/Timer.hpp" #include "Common/Timer.hpp"
#include "../common/debug.h" #include "../common/debug.h"
bool localShaderConstants = false;
namespace es1 namespace es1
{ {
using namespace sw; using namespace sw;
......
...@@ -25,8 +25,6 @@ ...@@ -25,8 +25,6 @@
#include "Common/Timer.hpp" #include "Common/Timer.hpp"
#include "../common/debug.h" #include "../common/debug.h"
bool localShaderConstants = false;
namespace es2 namespace es2
{ {
using namespace sw; using namespace sw;
......
...@@ -25,8 +25,6 @@ ...@@ -25,8 +25,6 @@
#include "Common/Timer.hpp" #include "Common/Timer.hpp"
#include "../common/debug.h" #include "../common/debug.h"
bool localShaderConstants = false;
namespace es2 namespace es2
{ {
using namespace sw; using namespace sw;
......
...@@ -20,8 +20,6 @@ ...@@ -20,8 +20,6 @@
#include "Constants.hpp" #include "Constants.hpp"
#include "Debug.hpp" #include "Debug.hpp"
extern bool localShaderConstants;
namespace sw namespace sw
{ {
extern bool complementaryDepthBuffer; extern bool complementaryDepthBuffer;
...@@ -5911,7 +5909,7 @@ namespace sw ...@@ -5911,7 +5909,7 @@ namespace sw
c.z = c.z.zzzz; c.z = c.z.zzzz;
c.w = c.w.wwww; 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++) for(size_t j = 0; j < shader->getLength(); j++)
{ {
......
...@@ -1337,6 +1337,11 @@ namespace sw ...@@ -1337,6 +1337,11 @@ namespace sw
return containsLeave; return containsLeave;
} }
bool Shader::containsDefineInstruction() const
{
return containsDefine;
}
bool Shader::usesSampler(int index) const bool Shader::usesSampler(int index) const
{ {
return (usedSamplers & (1 << index)) != 0; return (usedSamplers & (1 << index)) != 0;
...@@ -1545,6 +1550,7 @@ namespace sw ...@@ -1545,6 +1550,7 @@ namespace sw
containsLeave = false; containsLeave = false;
containsBreak = false; containsBreak = false;
containsContinue = false; containsContinue = false;
containsDefine = false;
// Determine global presence of branching instructions // Determine global presence of branching instructions
for(unsigned int i = 0; i < instruction.size(); i++) for(unsigned int i = 0; i < instruction.size(); i++)
...@@ -1579,6 +1585,10 @@ namespace sw ...@@ -1579,6 +1585,10 @@ namespace sw
{ {
containsContinue = true; containsContinue = true;
} }
case OPCODE_DEF:
case OPCODE_DEFB:
case OPCODE_DEFI:
containsDefine = true;
} }
} }
......
...@@ -519,6 +519,7 @@ namespace sw ...@@ -519,6 +519,7 @@ namespace sw
bool containsBreakInstruction() const; bool containsBreakInstruction() const;
bool containsContinueInstruction() const; bool containsContinueInstruction() const;
bool containsLeaveInstruction() const; bool containsLeaveInstruction() const;
bool containsDefineInstruction() const;
bool usesSampler(int i) const; bool usesSampler(int i) const;
struct Semantic struct Semantic
...@@ -593,6 +594,7 @@ namespace sw ...@@ -593,6 +594,7 @@ namespace sw
bool containsBreak; bool containsBreak;
bool containsContinue; bool containsContinue;
bool containsLeave; bool containsLeave;
bool containsDefine;
}; };
} }
......
...@@ -18,8 +18,6 @@ ...@@ -18,8 +18,6 @@
#include "SamplerCore.hpp" #include "SamplerCore.hpp"
#include "Debug.hpp" #include "Debug.hpp"
extern bool localShaderConstants;
namespace sw namespace sw
{ {
VertexProgram::VertexProgram(const VertexProcessor::State &state, const VertexShader *shader) : VertexRoutine(state, shader) VertexProgram::VertexProgram(const VertexProcessor::State &state, const VertexShader *shader) : VertexRoutine(state, shader)
...@@ -731,7 +729,7 @@ namespace sw ...@@ -731,7 +729,7 @@ namespace sw
c.z = c.z.zzzz; c.z = c.z.zzzz;
c.w = c.w.wwww; 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++) for(size_t j = 0; j < shader->getLength(); j++)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment