Commit ab752790 by Alexis Hetu Committed by Alexis Hétu

Making proper use of size_t

In a lot of cases, int was being used instead of size_to represent sizes. That led to some warnings about inconsistencies between int and size_t usage. While this cl doesn't solve all warnings, it tries to use size_t and int where it should be appropriate to use them. Change-Id: Id760df1360f65b2bba60f4075cdf4954fc6bbaf3 Reviewed-on: https://swiftshader-review.googlesource.com/5177Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarAlexis Hétu <sugoi@google.com>
parent 536f7913
......@@ -165,8 +165,8 @@ namespace glsl
}
else
{
const int numComponents = type.getElementSize();
baseAlignment = (numComponents == 3 ? 4u : static_cast<size_t>(numComponents));
const size_t numComponents = type.getElementSize();
baseAlignment = (numComponents == 3 ? 4u : numComponents);
}
mCurrentOffset = sw::align(mCurrentOffset, baseAlignment);
......@@ -1114,7 +1114,7 @@ namespace glsl
TIntermTyped *result = node;
const TType &resultType = node->getType();
TIntermSequence &arg = node->getSequence();
int argumentCount = arg.size();
size_t argumentCount = arg.size();
switch(node->getOp())
{
......@@ -1187,7 +1187,7 @@ namespace glsl
TIntermSequence &arguments = *function->arg;
for(int i = 0; i < argumentCount; i++)
for(size_t i = 0; i < argumentCount; i++)
{
TIntermTyped *in = arguments[i]->getAsTyped();
......@@ -1208,7 +1208,7 @@ namespace glsl
copy(result, function->ret);
}
for(int i = 0; i < argumentCount; i++)
for(size_t i = 0; i < argumentCount; i++)
{
TIntermTyped *argument = arguments[i]->getAsTyped();
TIntermTyped *out = arg[i]->getAsTyped();
......@@ -1328,7 +1328,7 @@ namespace glsl
{
int component = 0;
for(int i = 0; i < argumentCount; i++)
for(size_t i = 0; i < argumentCount; i++)
{
TIntermTyped *argi = arg[i]->getAsTyped();
int size = argi->getNominalSize();
......@@ -1409,7 +1409,7 @@ namespace glsl
int column = 0;
int row = 0;
for(int i = 0; i < argumentCount; i++)
for(size_t i = 0; i < argumentCount; i++)
{
TIntermTyped *argi = arg[i]->getAsTyped();
int size = argi->getNominalSize();
......@@ -1434,7 +1434,7 @@ namespace glsl
if(visit == PostVisit)
{
int offset = 0;
for(int i = 0; i < argumentCount; i++)
for(size_t i = 0; i < argumentCount; i++)
{
TIntermTyped *argi = arg[i]->getAsTyped();
int size = argi->totalRegisterCount();
......@@ -2030,8 +2030,8 @@ namespace glsl
if(type.isInterfaceBlock())
{
// Offset index to the beginning of the selected instance
size_t blockRegisters = type.elementRegisterCount();
size_t bufferOffset = argumentInfo.clampedIndex / blockRegisters;
int blockRegisters = type.elementRegisterCount();
int bufferOffset = argumentInfo.clampedIndex / blockRegisters;
argumentInfo.bufferIndex += bufferOffset;
argumentInfo.clampedIndex -= bufferOffset * blockRegisters;
}
......
......@@ -481,7 +481,7 @@ bool TParseContext::constructorErrorCheck(const TSourceLoc &line, TIntermNode* n
// again, there is an extra argument, so 'overfull' will become true.
//
int size = 0;
size_t size = 0;
bool full = false;
bool overFull = false;
bool matrixInMatrix = false;
......@@ -2221,7 +2221,7 @@ TIntermTyped* TParseContext::addConstArrayNode(int index, TIntermTyped* node, co
index = 0;
}
int arrayElementSize = arrayElementType.getObjectSize();
size_t arrayElementSize = arrayElementType.getObjectSize();
if (tempConstantNode) {
ConstantUnion* unionArray = tempConstantNode->getUnionArrayPointer();
......@@ -2246,11 +2246,10 @@ TIntermTyped* TParseContext::addConstStruct(const TString& identifier, TIntermTy
{
const TFieldList &fields = node->getType().getStruct()->fields();
TIntermTyped *typedNode;
int instanceSize = 0;
unsigned int index = 0;
size_t instanceSize = 0;
TIntermConstantUnion *tempConstantNode = node->getAsConstantUnion();
for ( index = 0; index < fields.size(); ++index) {
for(size_t index = 0; index < fields.size(); ++index) {
if (fields[index]->name() == identifier) {
break;
} else {
......
......@@ -87,7 +87,7 @@ void TType::buildMangledName(TString& mangledName)
}
}
int TType::getStructSize() const
size_t TType::getStructSize() const
{
if (!getStruct()) {
assert(false && "Not a struct");
......
......@@ -277,7 +277,7 @@ public:
int getNominalSize() const { return primarySize; }
void setNominalSize(int s) { primarySize = s; }
// Full size of single instance of type
int getObjectSize() const
size_t getObjectSize() const
{
if(isArray())
{
......@@ -289,7 +289,7 @@ public:
}
}
int getElementSize() const
size_t getElementSize() const
{
if(getBasicType() == EbtStruct)
{
......@@ -467,7 +467,7 @@ public:
protected:
void buildMangledName(TString&);
int getStructSize() const;
size_t getStructSize() const;
void computeDeepestStructNesting();
TBasicType type;
......
......@@ -349,9 +349,9 @@ void TOutputTraverser::visitConstantUnion(TIntermConstantUnion* node)
{
TInfoSinkBase& out = sink;
int size = node->getType().getObjectSize();
size_t size = node->getType().getObjectSize();
for (int i = 0; i < size; i++) {
for(size_t i = 0; i < size; i++) {
OutputTreeText(out, node, mDepth);
switch (node->getUnionArrayPointer()[i].getType()) {
case EbtBool:
......
......@@ -37,13 +37,13 @@ protected:
bool visitLoop(Visit visit, TIntermLoop*);
bool visitBranch(Visit visit, TIntermBranch*);
int index;
size_t index;
ConstantUnion *unionArray;
TType type;
TOperator constructorType;
bool singleConstantParam;
TInfoSink& infoSink;
int size; // size of the constructor ( 4 for vec4)
size_t size; // size of the constructor ( 4 for vec4)
bool isMatrix;
int matrixSize; // dimension of the matrix (nominal size and not the instance size)
};
......@@ -156,17 +156,17 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node)
}
ConstantUnion* leftUnionArray = unionArray;
int instanceSize = type.getObjectSize();
size_t instanceSize = type.getObjectSize();
TBasicType basicType = type.getBasicType();
if (index >= instanceSize)
return;
if (!singleConstantParam) {
int size = node->getType().getObjectSize();
size_t size = node->getType().getObjectSize();
ConstantUnion *rightUnionArray = node->getUnionArrayPointer();
for (int i=0; i < size; i++) {
for(size_t i = 0; i < size; i++) {
if (index >= instanceSize)
return;
leftUnionArray[index].cast(basicType, rightUnionArray[i]);
......@@ -174,11 +174,11 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node)
(index)++;
}
} else {
int totalSize = index + size;
size_t totalSize = index + size;
ConstantUnion *rightUnionArray = node->getUnionArrayPointer();
if (!isMatrix) {
int count = 0;
for (int i = index; i < totalSize; i++) {
for(size_t i = index; i < totalSize; i++) {
if (i >= instanceSize)
return;
......@@ -192,7 +192,7 @@ void TConstTraverser::visitConstantUnion(TIntermConstantUnion* node)
} else { // for matrix constructors
int count = 0;
int element = index;
for (int i = index; i < totalSize; i++) {
for(size_t i = index; i < totalSize; i++) {
if (i >= instanceSize)
return;
if (element - i == 0 || (i - element) % (matrixSize + 1) == 0 )
......
......@@ -4308,7 +4308,7 @@ const GLubyte* Context::getExtensions(GLuint index, GLuint* numExt) const
static GLubyte* extensionsCat = nullptr;
if(!extensionsCat && (numExtensions > 0))
{
int totalLength = numExtensions; // 1 space between each extension name + terminating null
size_t totalLength = numExtensions; // 1 space between each extension name + terminating null
for(unsigned int i = 0; i < numExtensions; i++)
{
totalLength += strlen(reinterpret_cast<const char*>(extensions[i]));
......
......@@ -64,7 +64,7 @@ namespace es2
{
if(blockInfo.index == -1)
{
int bytes = UniformTypeSize(type) * size();
size_t bytes = UniformTypeSize(type) * size();
data = new unsigned char[bytes];
memset(data, 0, bytes);
}
......@@ -347,8 +347,8 @@ namespace es2
size_t subscript = GL_INVALID_INDEX;
std::string baseName = es2::ParseUniformName(name, &subscript);
unsigned int numUniforms = uniformIndex.size();
for(unsigned int location = 0; location < numUniforms; location++)
size_t numUniforms = uniformIndex.size();
for(size_t location = 0; location < numUniforms; location++)
{
const int index = uniformIndex[location].index;
const bool isArray = uniforms[index]->isArray();
......@@ -357,7 +357,7 @@ namespace es2
((isArray && uniformIndex[location].element == subscript) ||
(subscript == GL_INVALID_INDEX)))
{
return location;
return (GLint)location;
}
}
......@@ -375,8 +375,8 @@ namespace es2
return GL_INVALID_INDEX;
}
unsigned int numUniforms = uniforms.size();
for(unsigned int index = 0; index < numUniforms; index++)
size_t numUniforms = uniforms.size();
for(GLuint index = 0; index < numUniforms; index++)
{
if(uniforms[index]->name == baseName)
{
......@@ -430,8 +430,8 @@ namespace es2
size_t subscript = GL_INVALID_INDEX;
std::string baseName = es2::ParseUniformName(name, &subscript);
unsigned int numUniformBlocks = getActiveUniformBlockCount();
for(unsigned int blockIndex = 0; blockIndex < numUniformBlocks; blockIndex++)
size_t numUniformBlocks = getActiveUniformBlockCount();
for(GLuint blockIndex = 0; blockIndex < numUniformBlocks; blockIndex++)
{
const UniformBlock &uniformBlock = *uniformBlocks[blockIndex];
if(uniformBlock.name == baseName)
......@@ -1053,8 +1053,8 @@ namespace es2
void Program::dirtyAllUniforms()
{
unsigned int numUniforms = uniforms.size();
for(unsigned int index = 0; index < numUniforms; index++)
size_t numUniforms = uniforms.size();
for(size_t index = 0; index < numUniforms; index++)
{
uniforms[index]->dirty = true;
}
......@@ -1063,8 +1063,8 @@ namespace es2
// Applies all the uniforms set for this program object to the device
void Program::applyUniforms()
{
unsigned int numUniforms = uniformIndex.size();
for(unsigned int location = 0; location < numUniforms; location++)
GLint numUniforms = uniformIndex.size();
for(GLint location = 0; location < numUniforms; location++)
{
if(uniformIndex[location].element != 0)
{
......@@ -1075,7 +1075,7 @@ namespace es2
if(targetUniform->dirty && (targetUniform->blockInfo.index == -1))
{
int size = targetUniform->size();
GLsizei size = targetUniform->size();
GLfloat *f = (GLfloat*)targetUniform->data;
GLint *i = (GLint*)targetUniform->data;
GLuint *ui = (GLuint*)targetUniform->data;
......@@ -1664,7 +1664,7 @@ namespace es2
if(location == -1) // Not previously defined
{
uniforms.push_back(uniform);
unsigned int index = uniforms.size() - 1;
size_t index = uniforms.size() - 1;
for(int i = 0; i < uniform->size(); i++)
{
......@@ -1708,8 +1708,8 @@ namespace es2
{
return false;
}
const unsigned int numBlockMembers = block1.fields.size();
for(unsigned int blockMemberIndex = 0; blockMemberIndex < numBlockMembers; blockMemberIndex++)
const size_t numBlockMembers = block1.fields.size();
for(size_t blockMemberIndex = 0; blockMemberIndex < numBlockMembers; blockMemberIndex++)
{
const glsl::Uniform& member1 = shader1->activeUniforms[block1.fields[blockMemberIndex]];
const glsl::Uniform& member2 = shader2->activeUniforms[block2.fields[blockMemberIndex]];
......@@ -2423,7 +2423,7 @@ namespace es2
return currentSerial++;
}
int Program::getInfoLogLength() const
size_t Program::getInfoLogLength() const
{
if(!infoLog)
{
......@@ -2578,8 +2578,8 @@ namespace es2
{
int maxLength = 0;
unsigned int numUniforms = uniforms.size();
for(unsigned int uniformIndex = 0; uniformIndex < numUniforms; uniformIndex++)
size_t numUniforms = uniforms.size();
for(size_t uniformIndex = 0; uniformIndex < numUniforms; uniformIndex++)
{
if(!uniforms[uniformIndex]->name.empty())
{
......@@ -2649,17 +2649,17 @@ namespace es2
GLint Program::getActiveUniformBlockMaxLength() const
{
int maxLength = 0;
size_t maxLength = 0;
if(isLinked())
{
unsigned int numUniformBlocks = getActiveUniformBlockCount();
for(unsigned int uniformBlockIndex = 0; uniformBlockIndex < numUniformBlocks; uniformBlockIndex++)
size_t numUniformBlocks = getActiveUniformBlockCount();
for(size_t uniformBlockIndex = 0; uniformBlockIndex < numUniformBlocks; uniformBlockIndex++)
{
const UniformBlock &uniformBlock = *uniformBlocks[uniformBlockIndex];
if(!uniformBlock.name.empty())
{
const int length = uniformBlock.name.length() + 1;
size_t length = uniformBlock.name.length() + 1;
// Counting in "[0]".
const int arrayLength = (uniformBlock.isArrayElement() ? 3 : 0);
......
......@@ -174,7 +174,7 @@ namespace es2
void link();
bool isLinked() const;
int getInfoLogLength() const;
size_t getInfoLogLength() const;
void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog);
void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders);
......
......@@ -84,7 +84,7 @@ void Shader::setSource(GLsizei count, const char *const *string, const GLint *le
mSource[totalLength] = '\0';
}
int Shader::getInfoLogLength() const
size_t Shader::getInfoLogLength() const
{
if(infoLog.empty())
{
......@@ -117,7 +117,7 @@ void Shader::getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLogOut)
}
}
int Shader::getSourceLength() const
size_t Shader::getSourceLength() const
{
if(!mSource)
{
......
......@@ -49,9 +49,9 @@ public:
void deleteSource();
void setSource(GLsizei count, const char *const *string, const GLint *length);
int getInfoLogLength() const;
size_t getInfoLogLength() const;
void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog);
int getSourceLength() const;
size_t getSourceLength() const;
void getSource(GLsizei bufSize, GLsizei *length, char *source);
void compile();
......
......@@ -78,9 +78,7 @@ unsigned int VertexDataManager::writeAttributeData(StreamingVertexBuffer *vertex
if(buffer)
{
int offset = attribute.mOffset;
input = static_cast<const char*>(buffer->data()) + offset;
input = static_cast<const char*>(buffer->data()) + attribute.mOffset;
}
else
{
......
......@@ -2591,7 +2591,7 @@ void GetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
*params = buffer->usage();
break;
case GL_BUFFER_SIZE:
*params = buffer->size();
*params = (GLint)buffer->size();
break;
case GL_BUFFER_ACCESS_FLAGS:
if(clientVersion >= 3)
......@@ -2610,14 +2610,14 @@ void GetBufferParameteriv(GLenum target, GLenum pname, GLint* params)
case GL_BUFFER_MAP_LENGTH:
if(clientVersion >= 3)
{
*params = buffer->length();
*params = (GLint)buffer->length();
break;
}
else return error(GL_INVALID_ENUM);
case GL_BUFFER_MAP_OFFSET:
if(clientVersion >= 3)
{
*params = buffer->offset();
*params = (GLint)buffer->offset();
break;
}
else return error(GL_INVALID_ENUM);
......@@ -3168,19 +3168,19 @@ void GetProgramiv(GLuint program, GLenum pname, GLint* params)
*params = programObject->isValidated();
return;
case GL_INFO_LOG_LENGTH:
*params = programObject->getInfoLogLength();
*params = (GLint)programObject->getInfoLogLength();
return;
case GL_ATTACHED_SHADERS:
*params = programObject->getAttachedShadersCount();
return;
case GL_ACTIVE_ATTRIBUTES:
*params = programObject->getActiveAttributeCount();
*params = (GLint)programObject->getActiveAttributeCount();
return;
case GL_ACTIVE_ATTRIBUTE_MAX_LENGTH:
*params = programObject->getActiveAttributeMaxLength();
return;
case GL_ACTIVE_UNIFORMS:
*params = programObject->getActiveUniformCount();
*params = (GLint)programObject->getActiveUniformCount();
return;
case GL_ACTIVE_UNIFORM_MAX_LENGTH:
*params = programObject->getActiveUniformMaxLength();
......@@ -3188,7 +3188,7 @@ void GetProgramiv(GLuint program, GLenum pname, GLint* params)
case GL_ACTIVE_UNIFORM_BLOCKS:
if(clientVersion >= 3)
{
*params = programObject->getActiveUniformBlockCount();
*params = (GLint)programObject->getActiveUniformBlockCount();
return;
}
else return error(GL_INVALID_ENUM);
......@@ -3407,10 +3407,10 @@ void GetShaderiv(GLuint shader, GLenum pname, GLint* params)
*params = shaderObject->isCompiled() ? GL_TRUE : GL_FALSE;
return;
case GL_INFO_LOG_LENGTH:
*params = shaderObject->getInfoLogLength();
*params = (GLint)shaderObject->getInfoLogLength();
return;
case GL_SHADER_SOURCE_LENGTH:
*params = shaderObject->getSourceLength();
*params = (GLint)shaderObject->getSourceLength();
return;
default:
return error(GL_INVALID_ENUM);
......
......@@ -1683,7 +1683,7 @@ GL_APICALL void *GL_APIENTRY glMapBufferRange(GLenum target, GLintptr offset, GL
return error(GL_INVALID_OPERATION, nullptr);
}
GLint bufferSize = buffer->size();
GLsizeiptr bufferSize = buffer->size();
if((offset < 0) || (length < 0) || ((offset + length) > bufferSize))
{
error(GL_INVALID_VALUE);
......@@ -1726,7 +1726,7 @@ GL_APICALL void GL_APIENTRY glFlushMappedBufferRange(GLenum target, GLintptr off
return error(GL_INVALID_OPERATION);
}
GLint bufferSize = buffer->size();
GLsizeiptr bufferSize = buffer->size();
if((offset < 0) || (length < 0) || ((offset + length) > bufferSize))
{
error(GL_INVALID_VALUE);
......
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