Commit bf3fc254 by Alexis Hetu Committed by Alexis Hétu

Minor C++11 code cleanup

Used range-based for loop where it was trivial to do so. This change should be noop in terms of functionality. Change-Id: I3d692cc2706f35f5b710e7539fa084365cf28af1 Reviewed-on: https://swiftshader-review.googlesource.com/14628Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com>
parent 5a0e7273
...@@ -580,11 +580,11 @@ bool Display::isValidWindow(EGLNativeWindowType window) ...@@ -580,11 +580,11 @@ bool Display::isValidWindow(EGLNativeWindowType window)
bool Display::hasExistingWindowSurface(EGLNativeWindowType window) bool Display::hasExistingWindowSurface(EGLNativeWindowType window)
{ {
for(SurfaceSet::iterator surface = mSurfaceSet.begin(); surface != mSurfaceSet.end(); surface++) for(const auto &surface : mSurfaceSet)
{ {
if((*surface)->isWindowSurface()) if(surface->isWindowSurface())
{ {
if((*surface)->getWindowHandle() == window) if(surface->getWindowHandle() == window)
{ {
return true; return true;
} }
......
...@@ -389,15 +389,15 @@ GLenum VertexShader::getType() const ...@@ -389,15 +389,15 @@ GLenum VertexShader::getType() const
return GL_VERTEX_SHADER; return GL_VERTEX_SHADER;
} }
int VertexShader::getSemanticIndex(const std::string &attributeName) int VertexShader::getSemanticIndex(const std::string &attributeName) const
{ {
if(!attributeName.empty()) if(!attributeName.empty())
{ {
for(glsl::ActiveAttributes::iterator attribute = activeAttributes.begin(); attribute != activeAttributes.end(); attribute++) for(const auto &attribute : activeAttributes)
{ {
if(attribute->name == attributeName) if(attribute.name == attributeName)
{ {
return attribute->registerIndex; return attribute.registerIndex;
} }
} }
} }
......
...@@ -99,7 +99,7 @@ public: ...@@ -99,7 +99,7 @@ public:
~VertexShader(); ~VertexShader();
virtual GLenum getType() const; virtual GLenum getType() const;
int getSemanticIndex(const std::string &attributeName); int getSemanticIndex(const std::string &attributeName) const;
virtual sw::Shader *getShader() const; virtual sw::Shader *getShader() const;
virtual sw::VertexShader *getVertexShader() const; virtual sw::VertexShader *getVertexShader() const;
......
...@@ -309,13 +309,12 @@ namespace sw ...@@ -309,13 +309,12 @@ namespace sw
{ {
draw->queries = new std::list<Query*>(); draw->queries = new std::list<Query*>();
bool includePrimitivesWrittenQueries = vertexState.transformFeedbackQueryEnabled && vertexState.transformFeedbackEnabled; bool includePrimitivesWrittenQueries = vertexState.transformFeedbackQueryEnabled && vertexState.transformFeedbackEnabled;
for(std::list<Query*>::iterator query = queries.begin(); query != queries.end(); query++) for(auto &query : queries)
{ {
Query* q = *query; if(includePrimitivesWrittenQueries || (query->type != Query::TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN))
if(includePrimitivesWrittenQueries || (q->type != Query::TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN))
{ {
++q->reference; // Atomic ++query->reference; // Atomic
draw->queries->push_back(q); draw->queries->push_back(query);
} }
} }
} }
...@@ -972,10 +971,8 @@ namespace sw ...@@ -972,10 +971,8 @@ namespace sw
if(draw.queries) if(draw.queries)
{ {
for(std::list<Query*>::iterator q = draw.queries->begin(); q != draw.queries->end(); q++) for(auto &query : *(draw.queries))
{ {
Query *query = *q;
switch(query->type) switch(query->type)
{ {
case Query::FRAGMENTS_PASSED: case Query::FRAGMENTS_PASSED:
......
...@@ -167,11 +167,11 @@ namespace sw ...@@ -167,11 +167,11 @@ namespace sw
{ {
zOverride = false; zOverride = false;
for(unsigned int i = 0; i < instruction.size(); i++) for(const auto &inst : instruction)
{ {
if(instruction[i]->opcode == Shader::OPCODE_TEXM3X2DEPTH || if(inst->opcode == Shader::OPCODE_TEXM3X2DEPTH ||
instruction[i]->opcode == Shader::OPCODE_TEXDEPTH || inst->opcode == Shader::OPCODE_TEXDEPTH ||
instruction[i]->dst.type == Shader::PARAMETER_DEPTHOUT) inst->dst.type == Shader::PARAMETER_DEPTHOUT)
{ {
zOverride = true; zOverride = true;
...@@ -184,10 +184,10 @@ namespace sw ...@@ -184,10 +184,10 @@ namespace sw
{ {
kill = false; kill = false;
for(unsigned int i = 0; i < instruction.size(); i++) for(const auto &inst : instruction)
{ {
if(instruction[i]->opcode == Shader::OPCODE_TEXKILL || if(inst->opcode == Shader::OPCODE_TEXKILL ||
instruction[i]->opcode == Shader::OPCODE_DISCARD) inst->opcode == Shader::OPCODE_DISCARD)
{ {
kill = true; kill = true;
...@@ -226,25 +226,25 @@ namespace sw ...@@ -226,25 +226,25 @@ namespace sw
samplerType[i] = Shader::SAMPLER_UNKNOWN; samplerType[i] = Shader::SAMPLER_UNKNOWN;
} }
for(unsigned int i = 0; i < instruction.size(); i++) for(const auto &inst : instruction)
{ {
if(instruction[i]->dst.type == Shader::PARAMETER_SAMPLER) if(inst->dst.type == Shader::PARAMETER_SAMPLER)
{ {
int sampler = instruction[i]->dst.index; int sampler = inst->dst.index;
samplerType[sampler] = instruction[i]->samplerType; samplerType[sampler] = inst->samplerType;
} }
} }
bool interpolant[MAX_FRAGMENT_INPUTS][4] = {{false}}; // Interpolants in use bool interpolant[MAX_FRAGMENT_INPUTS][4] = {{false}}; // Interpolants in use
for(unsigned int i = 0; i < instruction.size(); i++) for(const auto &inst : instruction)
{ {
if(instruction[i]->dst.type == Shader::PARAMETER_TEXTURE) if(inst->dst.type == Shader::PARAMETER_TEXTURE)
{ {
int index = instruction[i]->dst.index + 2; int index = inst->dst.index + 2;
switch(instruction[i]->opcode) switch(inst->opcode)
{ {
case Shader::OPCODE_TEX: case Shader::OPCODE_TEX:
case Shader::OPCODE_TEXBEM: case Shader::OPCODE_TEXBEM:
...@@ -297,19 +297,19 @@ namespace sw ...@@ -297,19 +297,19 @@ namespace sw
for(int argument = 0; argument < 4; argument++) for(int argument = 0; argument < 4; argument++)
{ {
if(instruction[i]->src[argument].type == Shader::PARAMETER_INPUT || if(inst->src[argument].type == Shader::PARAMETER_INPUT ||
instruction[i]->src[argument].type == Shader::PARAMETER_TEXTURE) inst->src[argument].type == Shader::PARAMETER_TEXTURE)
{ {
int index = instruction[i]->src[argument].index; int index = inst->src[argument].index;
int swizzle = instruction[i]->src[argument].swizzle; int swizzle = inst->src[argument].swizzle;
int mask = instruction[i]->dst.mask; int mask = inst->dst.mask;
if(instruction[i]->src[argument].type == Shader::PARAMETER_TEXTURE) if(inst->src[argument].type == Shader::PARAMETER_TEXTURE)
{ {
index += 2; index += 2;
} }
switch(instruction[i]->opcode) switch(inst->opcode)
{ {
case Shader::OPCODE_TEX: case Shader::OPCODE_TEX:
case Shader::OPCODE_TEXLDD: case Shader::OPCODE_TEXLDD:
...@@ -324,14 +324,14 @@ namespace sw ...@@ -324,14 +324,14 @@ namespace sw
case Shader::OPCODE_TEXGRAD: case Shader::OPCODE_TEXGRAD:
case Shader::OPCODE_TEXGRADOFFSET: case Shader::OPCODE_TEXGRADOFFSET:
{ {
int sampler = instruction[i]->src[1].index; int sampler = inst->src[1].index;
switch(samplerType[sampler]) switch(samplerType[sampler])
{ {
case Shader::SAMPLER_UNKNOWN: case Shader::SAMPLER_UNKNOWN:
if(version == 0x0104) if(version == 0x0104)
{ {
if((instruction[i]->src[0].swizzle & 0x30) == 0x20) // .xyz if((inst->src[0].swizzle & 0x30) == 0x20) // .xyz
{ {
interpolant[index][0] = true; interpolant[index][0] = true;
interpolant[index][1] = true; interpolant[index][1] = true;
...@@ -370,24 +370,24 @@ namespace sw ...@@ -370,24 +370,24 @@ namespace sw
ASSERT(false); ASSERT(false);
} }
if(instruction[i]->bias) if(inst->bias)
{ {
interpolant[index][3] = true; interpolant[index][3] = true;
} }
if(instruction[i]->project) if(inst->project)
{ {
interpolant[index][3] = true; interpolant[index][3] = true;
} }
if(version == 0x0104 && instruction[i]->opcode == Shader::OPCODE_TEX) if(version == 0x0104 && inst->opcode == Shader::OPCODE_TEX)
{ {
if(instruction[i]->src[0].modifier == Shader::MODIFIER_DZ) if(inst->src[0].modifier == Shader::MODIFIER_DZ)
{ {
interpolant[index][2] = true; interpolant[index][2] = true;
} }
if(instruction[i]->src[0].modifier == Shader::MODIFIER_DW) if(inst->src[0].modifier == Shader::MODIFIER_DW)
{ {
interpolant[index][3] = true; interpolant[index][3] = true;
} }
...@@ -683,25 +683,25 @@ namespace sw ...@@ -683,25 +683,25 @@ namespace sw
} }
else // Shader Model 3.0 input declaration; v# indexable else // Shader Model 3.0 input declaration; v# indexable
{ {
for(unsigned int i = 0; i < instruction.size(); i++) for(const auto &inst : instruction)
{ {
if(instruction[i]->opcode == Shader::OPCODE_DCL) if(inst->opcode == Shader::OPCODE_DCL)
{ {
if(instruction[i]->dst.type == Shader::PARAMETER_INPUT) if(inst->dst.type == Shader::PARAMETER_INPUT)
{ {
unsigned char usage = instruction[i]->usage; unsigned char usage = inst->usage;
unsigned char index = instruction[i]->usageIndex; unsigned char index = inst->usageIndex;
unsigned char mask = instruction[i]->dst.mask; unsigned char mask = inst->dst.mask;
unsigned char reg = instruction[i]->dst.index; unsigned char reg = inst->dst.index;
if(mask & 0x01) input[reg][0] = Semantic(usage, index); if(mask & 0x01) input[reg][0] = Semantic(usage, index);
if(mask & 0x02) input[reg][1] = Semantic(usage, index); if(mask & 0x02) input[reg][1] = Semantic(usage, index);
if(mask & 0x04) input[reg][2] = Semantic(usage, index); if(mask & 0x04) input[reg][2] = Semantic(usage, index);
if(mask & 0x08) input[reg][3] = Semantic(usage, index); if(mask & 0x08) input[reg][3] = Semantic(usage, index);
} }
else if(instruction[i]->dst.type == Shader::PARAMETER_MISCTYPE) else if(inst->dst.type == Shader::PARAMETER_MISCTYPE)
{ {
unsigned char index = instruction[i]->dst.index; unsigned char index = inst->dst.index;
if(index == Shader::VPosIndex) if(index == Shader::VPosIndex)
{ {
...@@ -719,14 +719,14 @@ namespace sw ...@@ -719,14 +719,14 @@ namespace sw
if(version >= 0x0200) if(version >= 0x0200)
{ {
for(unsigned int i = 0; i < instruction.size(); i++) for(const auto &inst : instruction)
{ {
if(instruction[i]->opcode == Shader::OPCODE_DCL) if(inst->opcode == Shader::OPCODE_DCL)
{ {
bool centroid = instruction[i]->dst.centroid; bool centroid = inst->dst.centroid;
unsigned char reg = instruction[i]->dst.index; unsigned char reg = inst->dst.index;
switch(instruction[i]->dst.type) switch(inst->dst.type)
{ {
case Shader::PARAMETER_INPUT: case Shader::PARAMETER_INPUT:
input[reg][0].centroid = centroid; input[reg][0].centroid = centroid;
......
...@@ -1136,10 +1136,10 @@ namespace sw ...@@ -1136,10 +1136,10 @@ namespace sw
Shader::~Shader() Shader::~Shader()
{ {
for(unsigned int i = 0; i < instruction.size(); i++) for(auto &inst : instruction)
{ {
delete instruction[i]; delete inst;
instruction[i] = 0; inst = 0;
} }
} }
...@@ -1454,9 +1454,9 @@ namespace sw ...@@ -1454,9 +1454,9 @@ namespace sw
std::ofstream file(fullName, std::ofstream::out); std::ofstream file(fullName, std::ofstream::out);
for(unsigned int i = 0; i < instruction.size(); i++) for(const auto &inst : instruction)
{ {
file << instruction[i]->string(shaderType, version) << std::endl; file << inst->string(shaderType, version) << std::endl;
} }
} }
...@@ -1517,11 +1517,11 @@ namespace sw ...@@ -1517,11 +1517,11 @@ namespace sw
calledFunctions.clear(); calledFunctions.clear();
rescan = false; rescan = false;
for(unsigned int i = 0; i < instruction.size(); i++) for(const auto &inst : instruction)
{ {
if(instruction[i]->isCall()) if(inst->isCall())
{ {
calledFunctions.insert(instruction[i]->dst.label); calledFunctions.insert(inst->dst.label);
} }
} }
...@@ -1594,26 +1594,26 @@ namespace sw ...@@ -1594,26 +1594,26 @@ namespace sw
dirtyConstantsI = 0; dirtyConstantsI = 0;
dirtyConstantsB = 0; dirtyConstantsB = 0;
for(unsigned int i = 0; i < instruction.size(); i++) for(const auto &inst : instruction)
{ {
switch(instruction[i]->opcode) switch(inst->opcode)
{ {
case OPCODE_DEF: case OPCODE_DEF:
if(instruction[i]->dst.index + 1 > dirtyConstantsF) if(inst->dst.index + 1 > dirtyConstantsF)
{ {
dirtyConstantsF = instruction[i]->dst.index + 1; dirtyConstantsF = inst->dst.index + 1;
} }
break; break;
case OPCODE_DEFI: case OPCODE_DEFI:
if(instruction[i]->dst.index + 1 > dirtyConstantsI) if(inst->dst.index + 1 > dirtyConstantsI)
{ {
dirtyConstantsI = instruction[i]->dst.index + 1; dirtyConstantsI = inst->dst.index + 1;
} }
break; break;
case OPCODE_DEFB: case OPCODE_DEFB:
if(instruction[i]->dst.index + 1 > dirtyConstantsB) if(inst->dst.index + 1 > dirtyConstantsB)
{ {
dirtyConstantsB = instruction[i]->dst.index + 1; dirtyConstantsB = inst->dst.index + 1;
} }
break; break;
default: default:
...@@ -1631,9 +1631,9 @@ namespace sw ...@@ -1631,9 +1631,9 @@ namespace sw
containsDefine = 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(const auto &inst : instruction)
{ {
switch(instruction[i]->opcode) switch(inst->opcode)
{ {
case OPCODE_CALLNZ: case OPCODE_CALLNZ:
case OPCODE_IF: case OPCODE_IF:
...@@ -1644,22 +1644,22 @@ namespace sw ...@@ -1644,22 +1644,22 @@ namespace sw
case OPCODE_BREAKP: case OPCODE_BREAKP:
case OPCODE_LEAVE: case OPCODE_LEAVE:
case OPCODE_CONTINUE: case OPCODE_CONTINUE:
if(instruction[i]->src[0].type != PARAMETER_CONSTBOOL) if(inst->src[0].type != PARAMETER_CONSTBOOL)
{ {
dynamicBranching = true; dynamicBranching = true;
} }
if(instruction[i]->opcode == OPCODE_LEAVE) if(inst->opcode == OPCODE_LEAVE)
{ {
containsLeave = true; containsLeave = true;
} }
if(instruction[i]->isBreak()) if(inst->isBreak())
{ {
containsBreak = true; containsBreak = true;
} }
if(instruction[i]->opcode == OPCODE_CONTINUE) if(inst->opcode == OPCODE_CONTINUE)
{ {
containsContinue = true; containsContinue = true;
} }
...@@ -1794,36 +1794,36 @@ namespace sw ...@@ -1794,36 +1794,36 @@ namespace sw
void Shader::markFunctionAnalysis(unsigned int functionLabel, Analysis flag) void Shader::markFunctionAnalysis(unsigned int functionLabel, Analysis flag)
{ {
bool marker = false; bool marker = false;
for(unsigned int i = 0; i < instruction.size(); i++) for(auto &inst : instruction)
{ {
if(!marker) if(!marker)
{ {
if(instruction[i]->opcode == OPCODE_LABEL && instruction[i]->dst.label == functionLabel) if(inst->opcode == OPCODE_LABEL && inst->dst.label == functionLabel)
{ {
marker = true; marker = true;
} }
} }
else else
{ {
if(instruction[i]->opcode == OPCODE_RET) if(inst->opcode == OPCODE_RET)
{ {
break; break;
} }
else if(instruction[i]->isCall()) else if(inst->isCall())
{ {
markFunctionAnalysis(instruction[i]->dst.label, flag); markFunctionAnalysis(inst->dst.label, flag);
} }
instruction[i]->analysis |= flag; inst->analysis |= flag;
} }
} }
} }
void Shader::analyzeSamplers() void Shader::analyzeSamplers()
{ {
for(unsigned int i = 0; i < instruction.size(); i++) for(const auto &inst : instruction)
{ {
switch(instruction[i]->opcode) switch(inst->opcode)
{ {
case OPCODE_TEX: case OPCODE_TEX:
case OPCODE_TEXBEM: case OPCODE_TEXBEM:
...@@ -1848,8 +1848,8 @@ namespace sw ...@@ -1848,8 +1848,8 @@ namespace sw
case OPCODE_TEXGRAD: case OPCODE_TEXGRAD:
case OPCODE_TEXGRADOFFSET: case OPCODE_TEXGRADOFFSET:
{ {
Parameter &dst = instruction[i]->dst; Parameter &dst = inst->dst;
Parameter &src1 = instruction[i]->src[1]; Parameter &src1 = inst->src[1];
if(majorVersion >= 2) if(majorVersion >= 2)
{ {
...@@ -1873,13 +1873,13 @@ namespace sw ...@@ -1873,13 +1873,13 @@ namespace sw
{ {
int callSiteIndex[2048] = {0}; int callSiteIndex[2048] = {0};
for(unsigned int i = 0; i < instruction.size(); i++) for(auto &inst : instruction)
{ {
if(instruction[i]->opcode == OPCODE_CALL || instruction[i]->opcode == OPCODE_CALLNZ) if(inst->opcode == OPCODE_CALL || inst->opcode == OPCODE_CALLNZ)
{ {
int label = instruction[i]->dst.label; int label = inst->dst.label;
instruction[i]->dst.callSite = callSiteIndex[label]++; inst->dst.callSite = callSiteIndex[label]++;
} }
} }
} }
...@@ -1890,14 +1890,14 @@ namespace sw ...@@ -1890,14 +1890,14 @@ namespace sw
dynamicallyIndexedInput = false; dynamicallyIndexedInput = false;
dynamicallyIndexedOutput = false; dynamicallyIndexedOutput = false;
for(unsigned int i = 0; i < instruction.size(); i++) for(const auto &inst : instruction)
{ {
if(instruction[i]->dst.rel.type == PARAMETER_ADDR || if(inst->dst.rel.type == PARAMETER_ADDR ||
instruction[i]->dst.rel.type == PARAMETER_LOOP || inst->dst.rel.type == PARAMETER_LOOP ||
instruction[i]->dst.rel.type == PARAMETER_TEMP || inst->dst.rel.type == PARAMETER_TEMP ||
instruction[i]->dst.rel.type == PARAMETER_CONST) inst->dst.rel.type == PARAMETER_CONST)
{ {
switch(instruction[i]->dst.type) switch(inst->dst.type)
{ {
case PARAMETER_TEMP: dynamicallyIndexedTemporaries = true; break; case PARAMETER_TEMP: dynamicallyIndexedTemporaries = true; break;
case PARAMETER_INPUT: dynamicallyIndexedInput = true; break; case PARAMETER_INPUT: dynamicallyIndexedInput = true; break;
...@@ -1908,12 +1908,12 @@ namespace sw ...@@ -1908,12 +1908,12 @@ namespace sw
for(int j = 0; j < 3; j++) for(int j = 0; j < 3; j++)
{ {
if(instruction[i]->src[j].rel.type == PARAMETER_ADDR || if(inst->src[j].rel.type == PARAMETER_ADDR ||
instruction[i]->src[j].rel.type == PARAMETER_LOOP || inst->src[j].rel.type == PARAMETER_LOOP ||
instruction[i]->src[j].rel.type == PARAMETER_TEMP || inst->src[j].rel.type == PARAMETER_TEMP ||
instruction[i]->src[j].rel.type == PARAMETER_CONST) inst->src[j].rel.type == PARAMETER_CONST)
{ {
switch(instruction[i]->src[j].type) switch(inst->src[j].type)
{ {
case PARAMETER_TEMP: dynamicallyIndexedTemporaries = true; break; case PARAMETER_TEMP: dynamicallyIndexedTemporaries = true; break;
case PARAMETER_INPUT: dynamicallyIndexedInput = true; break; case PARAMETER_INPUT: dynamicallyIndexedInput = true; break;
......
...@@ -233,9 +233,9 @@ namespace sw ...@@ -233,9 +233,9 @@ namespace sw
output[Pos][2] = Semantic(Shader::USAGE_POSITION, 0); output[Pos][2] = Semantic(Shader::USAGE_POSITION, 0);
output[Pos][3] = Semantic(Shader::USAGE_POSITION, 0); output[Pos][3] = Semantic(Shader::USAGE_POSITION, 0);
for(unsigned int i = 0; i < instruction.size(); i++) for(const auto &inst : instruction)
{ {
const DestinationParameter &dst = instruction[i]->dst; const DestinationParameter &dst = inst->dst;
switch(dst.type) switch(dst.type)
{ {
...@@ -285,15 +285,15 @@ namespace sw ...@@ -285,15 +285,15 @@ namespace sw
} }
else // Shader Model 3.0 input declaration else // Shader Model 3.0 input declaration
{ {
for(unsigned int i = 0; i < instruction.size(); i++) for(const auto &inst : instruction)
{ {
if(instruction[i]->opcode == Shader::OPCODE_DCL && if(inst->opcode == Shader::OPCODE_DCL &&
instruction[i]->dst.type == Shader::PARAMETER_OUTPUT) inst->dst.type == Shader::PARAMETER_OUTPUT)
{ {
unsigned char usage = instruction[i]->usage; unsigned char usage = inst->usage;
unsigned char usageIndex = instruction[i]->usageIndex; unsigned char usageIndex = inst->usageIndex;
const DestinationParameter &dst = instruction[i]->dst; const DestinationParameter &dst = inst->dst;
if(dst.x) output[dst.index][0] = Semantic(usage, usageIndex); if(dst.x) output[dst.index][0] = Semantic(usage, usageIndex);
if(dst.y) output[dst.index][1] = Semantic(usage, usageIndex); if(dst.y) output[dst.index][1] = Semantic(usage, usageIndex);
...@@ -318,11 +318,12 @@ namespace sw ...@@ -318,11 +318,12 @@ namespace sw
{ {
textureSampling = false; textureSampling = false;
for(unsigned int i = 0; i < instruction.size() && !textureSampling; i++) for(const auto &inst : instruction)
{ {
if(instruction[i]->src[1].type == PARAMETER_SAMPLER) if(inst->src[1].type == PARAMETER_SAMPLER)
{ {
textureSampling = true; textureSampling = true;
break;
} }
} }
} }
......
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