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)
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;
}
......
......@@ -389,15 +389,15 @@ GLenum VertexShader::getType() const
return GL_VERTEX_SHADER;
}
int VertexShader::getSemanticIndex(const std::string &attributeName)
int VertexShader::getSemanticIndex(const std::string &attributeName) const
{
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:
~VertexShader();
virtual GLenum getType() const;
int getSemanticIndex(const std::string &attributeName);
int getSemanticIndex(const std::string &attributeName) const;
virtual sw::Shader *getShader() const;
virtual sw::VertexShader *getVertexShader() const;
......
......@@ -309,13 +309,12 @@ namespace sw
{
draw->queries = new std::list<Query*>();
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 || (q->type != Query::TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN))
if(includePrimitivesWrittenQueries || (query->type != Query::TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN))
{
++q->reference; // Atomic
draw->queries->push_back(q);
++query->reference; // Atomic
draw->queries->push_back(query);
}
}
}
......@@ -972,10 +971,8 @@ namespace sw
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)
{
case Query::FRAGMENTS_PASSED:
......
......@@ -167,11 +167,11 @@ namespace sw
{
zOverride = false;
for(unsigned int i = 0; i < instruction.size(); i++)
for(const auto &inst : instruction)
{
if(instruction[i]->opcode == Shader::OPCODE_TEXM3X2DEPTH ||
instruction[i]->opcode == Shader::OPCODE_TEXDEPTH ||
instruction[i]->dst.type == Shader::PARAMETER_DEPTHOUT)
if(inst->opcode == Shader::OPCODE_TEXM3X2DEPTH ||
inst->opcode == Shader::OPCODE_TEXDEPTH ||
inst->dst.type == Shader::PARAMETER_DEPTHOUT)
{
zOverride = true;
......@@ -184,10 +184,10 @@ namespace sw
{
kill = false;
for(unsigned int i = 0; i < instruction.size(); i++)
for(const auto &inst : instruction)
{
if(instruction[i]->opcode == Shader::OPCODE_TEXKILL ||
instruction[i]->opcode == Shader::OPCODE_DISCARD)
if(inst->opcode == Shader::OPCODE_TEXKILL ||
inst->opcode == Shader::OPCODE_DISCARD)
{
kill = true;
......@@ -226,25 +226,25 @@ namespace sw
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
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_TEXBEM:
......@@ -297,19 +297,19 @@ namespace sw
for(int argument = 0; argument < 4; argument++)
{
if(instruction[i]->src[argument].type == Shader::PARAMETER_INPUT ||
instruction[i]->src[argument].type == Shader::PARAMETER_TEXTURE)
if(inst->src[argument].type == Shader::PARAMETER_INPUT ||
inst->src[argument].type == Shader::PARAMETER_TEXTURE)
{
int index = instruction[i]->src[argument].index;
int swizzle = instruction[i]->src[argument].swizzle;
int mask = instruction[i]->dst.mask;
int index = inst->src[argument].index;
int swizzle = inst->src[argument].swizzle;
int mask = inst->dst.mask;
if(instruction[i]->src[argument].type == Shader::PARAMETER_TEXTURE)
if(inst->src[argument].type == Shader::PARAMETER_TEXTURE)
{
index += 2;
}
switch(instruction[i]->opcode)
switch(inst->opcode)
{
case Shader::OPCODE_TEX:
case Shader::OPCODE_TEXLDD:
......@@ -324,14 +324,14 @@ namespace sw
case Shader::OPCODE_TEXGRAD:
case Shader::OPCODE_TEXGRADOFFSET:
{
int sampler = instruction[i]->src[1].index;
int sampler = inst->src[1].index;
switch(samplerType[sampler])
{
case Shader::SAMPLER_UNKNOWN:
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][1] = true;
......@@ -370,24 +370,24 @@ namespace sw
ASSERT(false);
}
if(instruction[i]->bias)
if(inst->bias)
{
interpolant[index][3] = true;
}
if(instruction[i]->project)
if(inst->project)
{
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;
}
if(instruction[i]->src[0].modifier == Shader::MODIFIER_DW)
if(inst->src[0].modifier == Shader::MODIFIER_DW)
{
interpolant[index][3] = true;
}
......@@ -683,25 +683,25 @@ namespace sw
}
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 index = instruction[i]->usageIndex;
unsigned char mask = instruction[i]->dst.mask;
unsigned char reg = instruction[i]->dst.index;
unsigned char usage = inst->usage;
unsigned char index = inst->usageIndex;
unsigned char mask = inst->dst.mask;
unsigned char reg = inst->dst.index;
if(mask & 0x01) input[reg][0] = Semantic(usage, index);
if(mask & 0x02) input[reg][1] = Semantic(usage, index);
if(mask & 0x04) input[reg][2] = 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)
{
......@@ -719,14 +719,14 @@ namespace sw
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;
unsigned char reg = instruction[i]->dst.index;
bool centroid = inst->dst.centroid;
unsigned char reg = inst->dst.index;
switch(instruction[i]->dst.type)
switch(inst->dst.type)
{
case Shader::PARAMETER_INPUT:
input[reg][0].centroid = centroid;
......
......@@ -1136,10 +1136,10 @@ namespace sw
Shader::~Shader()
{
for(unsigned int i = 0; i < instruction.size(); i++)
for(auto &inst : instruction)
{
delete instruction[i];
instruction[i] = 0;
delete inst;
inst = 0;
}
}
......@@ -1454,9 +1454,9 @@ namespace sw
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
calledFunctions.clear();
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
dirtyConstantsI = 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:
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;
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;
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;
default:
......@@ -1631,9 +1631,9 @@ namespace sw
containsDefine = false;
// 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_IF:
......@@ -1644,22 +1644,22 @@ namespace sw
case OPCODE_BREAKP:
case OPCODE_LEAVE:
case OPCODE_CONTINUE:
if(instruction[i]->src[0].type != PARAMETER_CONSTBOOL)
if(inst->src[0].type != PARAMETER_CONSTBOOL)
{
dynamicBranching = true;
}
if(instruction[i]->opcode == OPCODE_LEAVE)
if(inst->opcode == OPCODE_LEAVE)
{
containsLeave = true;
}
if(instruction[i]->isBreak())
if(inst->isBreak())
{
containsBreak = true;
}
if(instruction[i]->opcode == OPCODE_CONTINUE)
if(inst->opcode == OPCODE_CONTINUE)
{
containsContinue = true;
}
......@@ -1794,36 +1794,36 @@ namespace sw
void Shader::markFunctionAnalysis(unsigned int functionLabel, Analysis flag)
{
bool marker = false;
for(unsigned int i = 0; i < instruction.size(); i++)
for(auto &inst : instruction)
{
if(!marker)
{
if(instruction[i]->opcode == OPCODE_LABEL && instruction[i]->dst.label == functionLabel)
if(inst->opcode == OPCODE_LABEL && inst->dst.label == functionLabel)
{
marker = true;
}
}
else
{
if(instruction[i]->opcode == OPCODE_RET)
if(inst->opcode == OPCODE_RET)
{
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()
{
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_TEXBEM:
......@@ -1848,8 +1848,8 @@ namespace sw
case OPCODE_TEXGRAD:
case OPCODE_TEXGRADOFFSET:
{
Parameter &dst = instruction[i]->dst;
Parameter &src1 = instruction[i]->src[1];
Parameter &dst = inst->dst;
Parameter &src1 = inst->src[1];
if(majorVersion >= 2)
{
......@@ -1873,13 +1873,13 @@ namespace sw
{
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
dynamicallyIndexedInput = 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 ||
instruction[i]->dst.rel.type == PARAMETER_LOOP ||
instruction[i]->dst.rel.type == PARAMETER_TEMP ||
instruction[i]->dst.rel.type == PARAMETER_CONST)
if(inst->dst.rel.type == PARAMETER_ADDR ||
inst->dst.rel.type == PARAMETER_LOOP ||
inst->dst.rel.type == PARAMETER_TEMP ||
inst->dst.rel.type == PARAMETER_CONST)
{
switch(instruction[i]->dst.type)
switch(inst->dst.type)
{
case PARAMETER_TEMP: dynamicallyIndexedTemporaries = true; break;
case PARAMETER_INPUT: dynamicallyIndexedInput = true; break;
......@@ -1908,12 +1908,12 @@ namespace sw
for(int j = 0; j < 3; j++)
{
if(instruction[i]->src[j].rel.type == PARAMETER_ADDR ||
instruction[i]->src[j].rel.type == PARAMETER_LOOP ||
instruction[i]->src[j].rel.type == PARAMETER_TEMP ||
instruction[i]->src[j].rel.type == PARAMETER_CONST)
if(inst->src[j].rel.type == PARAMETER_ADDR ||
inst->src[j].rel.type == PARAMETER_LOOP ||
inst->src[j].rel.type == PARAMETER_TEMP ||
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_INPUT: dynamicallyIndexedInput = true; break;
......
......@@ -233,9 +233,9 @@ namespace sw
output[Pos][2] = 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)
{
......@@ -285,15 +285,15 @@ namespace sw
}
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 &&
instruction[i]->dst.type == Shader::PARAMETER_OUTPUT)
if(inst->opcode == Shader::OPCODE_DCL &&
inst->dst.type == Shader::PARAMETER_OUTPUT)
{
unsigned char usage = instruction[i]->usage;
unsigned char usageIndex = instruction[i]->usageIndex;
unsigned char usage = inst->usage;
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.y) output[dst.index][1] = Semantic(usage, usageIndex);
......@@ -318,11 +318,12 @@ namespace sw
{
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;
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