Commit b72f8ee8 by Alexis Hetu Committed by Alexis Hétu

Adding unsigned int support for uniforms

Added unsigned int uniforms related functions and entries where appropriate to enable it. Change-Id: Ia3086817a25e6736cee9ba3d58d97bc8eaf520a3 Reviewed-on: https://swiftshader-review.googlesource.com/3101Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 3456d8fd
...@@ -517,6 +517,7 @@ namespace es2 ...@@ -517,6 +517,7 @@ namespace es2
bool Program::setUniformiv(GLint location, GLsizei count, const GLint *v, int numElements) bool Program::setUniformiv(GLint location, GLsizei count, const GLint *v, int numElements)
{ {
static GLenum intType[] = { GL_INT, GL_INT_VEC2, GL_INT_VEC3, GL_INT_VEC4 }; static GLenum intType[] = { GL_INT, GL_INT_VEC2, GL_INT_VEC3, GL_INT_VEC4 };
static GLenum uintType[] = { GL_UNSIGNED_INT, GL_UNSIGNED_INT_VEC2, GL_UNSIGNED_INT_VEC3, GL_UNSIGNED_INT_VEC4 };
static GLenum boolType[] = { GL_BOOL, GL_BOOL_VEC2, GL_BOOL_VEC3, GL_BOOL_VEC4 }; static GLenum boolType[] = { GL_BOOL, GL_BOOL_VEC2, GL_BOOL_VEC3, GL_BOOL_VEC4 };
if(location < 0 || location >= (int)uniformIndex.size()) if(location < 0 || location >= (int)uniformIndex.size())
...@@ -537,7 +538,7 @@ namespace es2 ...@@ -537,7 +538,7 @@ namespace es2
count = std::min(size - (int)uniformIndex[location].element, count); count = std::min(size - (int)uniformIndex[location].element, count);
int index = numElements - 1; int index = numElements - 1;
if(targetUniform->type == intType[index]) if(targetUniform->type == intType[index] || targetUniform->type == uintType[index])
{ {
memcpy(targetUniform->data + uniformIndex[location].element * sizeof(GLint)* numElements, memcpy(targetUniform->data + uniformIndex[location].element * sizeof(GLint)* numElements,
v, numElements * sizeof(GLint)* count); v, numElements * sizeof(GLint)* count);
...@@ -639,6 +640,7 @@ namespace es2 ...@@ -639,6 +640,7 @@ namespace es2
bool Program::setUniformuiv(GLint location, GLsizei count, const GLuint *v, int numElements) bool Program::setUniformuiv(GLint location, GLsizei count, const GLuint *v, int numElements)
{ {
static GLenum intType[] = { GL_INT, GL_INT_VEC2, GL_INT_VEC3, GL_INT_VEC4 }; static GLenum intType[] = { GL_INT, GL_INT_VEC2, GL_INT_VEC3, GL_INT_VEC4 };
static GLenum uintType[] = { GL_UNSIGNED_INT, GL_UNSIGNED_INT_VEC2, GL_UNSIGNED_INT_VEC3, GL_UNSIGNED_INT_VEC4 };
static GLenum boolType[] = { GL_BOOL, GL_BOOL_VEC2, GL_BOOL_VEC3, GL_BOOL_VEC4 }; static GLenum boolType[] = { GL_BOOL, GL_BOOL_VEC2, GL_BOOL_VEC3, GL_BOOL_VEC4 };
if(location < 0 || location >= (int)uniformIndex.size()) if(location < 0 || location >= (int)uniformIndex.size())
...@@ -659,7 +661,7 @@ namespace es2 ...@@ -659,7 +661,7 @@ namespace es2
count = std::min(size - (int)uniformIndex[location].element, count); count = std::min(size - (int)uniformIndex[location].element, count);
int index = numElements - 1; int index = numElements - 1;
if(targetUniform->type == intType[index]) if(targetUniform->type == uintType[index] || targetUniform->type == intType[index])
{ {
memcpy(targetUniform->data + uniformIndex[location].element * sizeof(GLuint)* numElements, memcpy(targetUniform->data + uniformIndex[location].element * sizeof(GLuint)* numElements,
v, numElements * sizeof(GLuint)* count); v, numElements * sizeof(GLuint)* count);
...@@ -743,6 +745,17 @@ namespace es2 ...@@ -743,6 +745,17 @@ namespace es2
} }
} }
break; break;
case GL_UNSIGNED_INT:
{
GLuint *uintParams = (GLuint*)targetUniform->data + uniformIndex[location].element * count;
for(unsigned int i = 0; i < count; i++)
{
params[i] = (float)uintParams[i];
}
}
break;
default: UNREACHABLE(); default: UNREACHABLE();
} }
...@@ -788,6 +801,7 @@ namespace es2 ...@@ -788,6 +801,7 @@ namespace es2
} }
break; break;
case GL_INT: case GL_INT:
case GL_UNSIGNED_INT:
memcpy(params, targetUniform->data + uniformIndex[location].element * count * sizeof(GLint), memcpy(params, targetUniform->data + uniformIndex[location].element * count * sizeof(GLint),
count * sizeof(GLint)); count * sizeof(GLint));
break; break;
...@@ -836,6 +850,7 @@ namespace es2 ...@@ -836,6 +850,7 @@ namespace es2
} }
break; break;
case GL_INT: case GL_INT:
case GL_UNSIGNED_INT:
memcpy(params, targetUniform->data + uniformIndex[location].element * count * sizeof(GLuint), memcpy(params, targetUniform->data + uniformIndex[location].element * count * sizeof(GLuint),
count * sizeof(GLuint)); count * sizeof(GLuint));
break; break;
...@@ -872,6 +887,7 @@ namespace es2 ...@@ -872,6 +887,7 @@ namespace es2
int size = targetUniform->size(); int size = targetUniform->size();
GLfloat *f = (GLfloat*)targetUniform->data; GLfloat *f = (GLfloat*)targetUniform->data;
GLint *i = (GLint*)targetUniform->data; GLint *i = (GLint*)targetUniform->data;
GLuint *ui = (GLuint*)targetUniform->data;
GLboolean *b = (GLboolean*)targetUniform->data; GLboolean *b = (GLboolean*)targetUniform->data;
switch(targetUniform->type) switch(targetUniform->type)
...@@ -901,6 +917,10 @@ namespace es2 ...@@ -901,6 +917,10 @@ namespace es2
case GL_INT_VEC2: applyUniform2iv(location, size, i); break; case GL_INT_VEC2: applyUniform2iv(location, size, i); break;
case GL_INT_VEC3: applyUniform3iv(location, size, i); break; case GL_INT_VEC3: applyUniform3iv(location, size, i); break;
case GL_INT_VEC4: applyUniform4iv(location, size, i); break; case GL_INT_VEC4: applyUniform4iv(location, size, i); break;
case GL_UNSIGNED_INT: applyUniform1uiv(location, size, ui); break;
case GL_UNSIGNED_INT_VEC2: applyUniform2uiv(location, size, ui); break;
case GL_UNSIGNED_INT_VEC3: applyUniform3uiv(location, size, ui); break;
case GL_UNSIGNED_INT_VEC4: applyUniform4uiv(location, size, ui); break;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
...@@ -1882,6 +1902,158 @@ namespace es2 ...@@ -1882,6 +1902,158 @@ namespace es2
return true; return true;
} }
bool Program::applyUniform1uiv(GLint location, GLsizei count, const GLuint *v)
{
float vector[MAX_UNIFORM_VECTORS][4];
for(int i = 0; i < count; i++)
{
vector[i][0] = (float)v[i];
vector[i][1] = 0;
vector[i][2] = 0;
vector[i][3] = 0;
}
Uniform *targetUniform = uniforms[uniformIndex[location].index];
if(targetUniform->psRegisterIndex != -1)
{
if(targetUniform->type == GL_SAMPLER_2D ||
targetUniform->type == GL_SAMPLER_CUBE ||
targetUniform->type == GL_SAMPLER_EXTERNAL_OES ||
targetUniform->type == GL_SAMPLER_3D_OES)
{
for(int i = 0; i < count; i++)
{
unsigned int samplerIndex = targetUniform->psRegisterIndex + i;
if(samplerIndex < MAX_TEXTURE_IMAGE_UNITS)
{
ASSERT(samplersPS[samplerIndex].active);
samplersPS[samplerIndex].logicalTextureUnit = v[i];
}
}
}
else
{
device->setPixelShaderConstantF(targetUniform->psRegisterIndex, (float*)vector, targetUniform->registerCount());
}
}
if(targetUniform->vsRegisterIndex != -1)
{
if(targetUniform->type == GL_SAMPLER_2D ||
targetUniform->type == GL_SAMPLER_CUBE ||
targetUniform->type == GL_SAMPLER_EXTERNAL_OES ||
targetUniform->type == GL_SAMPLER_3D_OES)
{
for(int i = 0; i < count; i++)
{
unsigned int samplerIndex = targetUniform->vsRegisterIndex + i;
if(samplerIndex < MAX_VERTEX_TEXTURE_IMAGE_UNITS)
{
ASSERT(samplersVS[samplerIndex].active);
samplersVS[samplerIndex].logicalTextureUnit = v[i];
}
}
}
else
{
device->setVertexShaderConstantF(targetUniform->vsRegisterIndex, (float*)vector, targetUniform->registerCount());
}
}
return true;
}
bool Program::applyUniform2uiv(GLint location, GLsizei count, const GLuint *v)
{
float vector[MAX_UNIFORM_VECTORS][4];
for(int i = 0; i < count; i++)
{
vector[i][0] = (float)v[0];
vector[i][1] = (float)v[1];
vector[i][2] = 0;
vector[i][3] = 0;
v += 2;
}
Uniform *targetUniform = uniforms[uniformIndex[location].index];
if(targetUniform->psRegisterIndex != -1)
{
device->setPixelShaderConstantF(targetUniform->psRegisterIndex, (float*)vector, targetUniform->registerCount());
}
if(targetUniform->vsRegisterIndex != -1)
{
device->setVertexShaderConstantF(targetUniform->vsRegisterIndex, (float*)vector, targetUniform->registerCount());
}
return true;
}
bool Program::applyUniform3uiv(GLint location, GLsizei count, const GLuint *v)
{
float vector[MAX_UNIFORM_VECTORS][4];
for(int i = 0; i < count; i++)
{
vector[i][0] = (float)v[0];
vector[i][1] = (float)v[1];
vector[i][2] = (float)v[2];
vector[i][3] = 0;
v += 3;
}
Uniform *targetUniform = uniforms[uniformIndex[location].index];
if(targetUniform->psRegisterIndex != -1)
{
device->setPixelShaderConstantF(targetUniform->psRegisterIndex, (float*)vector, targetUniform->registerCount());
}
if(targetUniform->vsRegisterIndex != -1)
{
device->setVertexShaderConstantF(targetUniform->vsRegisterIndex, (float*)vector, targetUniform->registerCount());
}
return true;
}
bool Program::applyUniform4uiv(GLint location, GLsizei count, const GLuint *v)
{
float vector[MAX_UNIFORM_VECTORS][4];
for(int i = 0; i < count; i++)
{
vector[i][0] = (float)v[0];
vector[i][1] = (float)v[1];
vector[i][2] = (float)v[2];
vector[i][3] = (float)v[3];
v += 4;
}
Uniform *targetUniform = uniforms[uniformIndex[location].index];
if(targetUniform->psRegisterIndex != -1)
{
device->setPixelShaderConstantF(targetUniform->psRegisterIndex, (float*)vector, targetUniform->registerCount());
}
if(targetUniform->vsRegisterIndex != -1)
{
device->setVertexShaderConstantF(targetUniform->vsRegisterIndex, (float*)vector, targetUniform->registerCount());
}
return true;
}
void Program::appendToInfoLog(const char *format, ...) void Program::appendToInfoLog(const char *format, ...)
{ {
if(!format) if(!format)
......
...@@ -172,6 +172,10 @@ namespace es2 ...@@ -172,6 +172,10 @@ namespace es2
bool applyUniform2iv(GLint location, GLsizei count, const GLint *v); bool applyUniform2iv(GLint location, GLsizei count, const GLint *v);
bool applyUniform3iv(GLint location, GLsizei count, const GLint *v); bool applyUniform3iv(GLint location, GLsizei count, const GLint *v);
bool applyUniform4iv(GLint location, GLsizei count, const GLint *v); bool applyUniform4iv(GLint location, GLsizei count, const GLint *v);
bool applyUniform1uiv(GLint location, GLsizei count, const GLuint *v);
bool applyUniform2uiv(GLint location, GLsizei count, const GLuint *v);
bool applyUniform3uiv(GLint location, GLsizei count, const GLuint *v);
bool applyUniform4uiv(GLint location, GLsizei count, const GLuint *v);
bool setUniformfv(GLint location, GLsizei count, const GLfloat *v, int numElements); bool setUniformfv(GLint location, GLsizei count, const GLfloat *v, int numElements);
bool setUniformMatrixfv(GLint location, GLsizei count, const GLfloat *value, GLenum type); bool setUniformMatrixfv(GLint location, GLsizei count, const GLfloat *value, GLenum type);
......
...@@ -29,6 +29,7 @@ namespace es2 ...@@ -29,6 +29,7 @@ namespace es2
case GL_BOOL: case GL_BOOL:
case GL_FLOAT: case GL_FLOAT:
case GL_INT: case GL_INT:
case GL_UNSIGNED_INT:
case GL_SAMPLER_2D: case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE: case GL_SAMPLER_CUBE:
case GL_SAMPLER_EXTERNAL_OES: case GL_SAMPLER_EXTERNAL_OES:
...@@ -37,14 +38,17 @@ namespace es2 ...@@ -37,14 +38,17 @@ namespace es2
case GL_BOOL_VEC2: case GL_BOOL_VEC2:
case GL_FLOAT_VEC2: case GL_FLOAT_VEC2:
case GL_INT_VEC2: case GL_INT_VEC2:
case GL_UNSIGNED_INT_VEC2:
return 2; return 2;
case GL_INT_VEC3: case GL_INT_VEC3:
case GL_UNSIGNED_INT_VEC3:
case GL_FLOAT_VEC3: case GL_FLOAT_VEC3:
case GL_BOOL_VEC3: case GL_BOOL_VEC3:
return 3; return 3;
case GL_BOOL_VEC4: case GL_BOOL_VEC4:
case GL_FLOAT_VEC4: case GL_FLOAT_VEC4:
case GL_INT_VEC4: case GL_INT_VEC4:
case GL_UNSIGNED_INT_VEC4:
case GL_FLOAT_MAT2: case GL_FLOAT_MAT2:
return 4; return 4;
case GL_FLOAT_MAT2x3: case GL_FLOAT_MAT2x3:
...@@ -99,6 +103,11 @@ namespace es2 ...@@ -99,6 +103,11 @@ namespace es2
case GL_INT_VEC3: case GL_INT_VEC3:
case GL_INT_VEC4: case GL_INT_VEC4:
return GL_INT; return GL_INT;
case GL_UNSIGNED_INT:
case GL_UNSIGNED_INT_VEC2:
case GL_UNSIGNED_INT_VEC3:
case GL_UNSIGNED_INT_VEC4:
return GL_UNSIGNED_INT;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
...@@ -113,6 +122,7 @@ namespace es2 ...@@ -113,6 +122,7 @@ namespace es2
case GL_BOOL: return sizeof(GLboolean); case GL_BOOL: return sizeof(GLboolean);
case GL_FLOAT: return sizeof(GLfloat); case GL_FLOAT: return sizeof(GLfloat);
case GL_INT: return sizeof(GLint); case GL_INT: return sizeof(GLint);
case GL_UNSIGNED_INT: return sizeof(GLuint);
} }
return UniformTypeSize(UniformComponentType(type)) * UniformComponentCount(type); return UniformTypeSize(UniformComponentType(type)) * UniformComponentCount(type);
...@@ -127,15 +137,19 @@ namespace es2 ...@@ -127,15 +137,19 @@ namespace es2
case GL_BOOL: case GL_BOOL:
case GL_FLOAT: case GL_FLOAT:
case GL_INT: case GL_INT:
case GL_UNSIGNED_INT:
case GL_BOOL_VEC2: case GL_BOOL_VEC2:
case GL_FLOAT_VEC2: case GL_FLOAT_VEC2:
case GL_INT_VEC2: case GL_INT_VEC2:
case GL_UNSIGNED_INT_VEC2:
case GL_INT_VEC3: case GL_INT_VEC3:
case GL_UNSIGNED_INT_VEC3:
case GL_FLOAT_VEC3: case GL_FLOAT_VEC3:
case GL_BOOL_VEC3: case GL_BOOL_VEC3:
case GL_BOOL_VEC4: case GL_BOOL_VEC4:
case GL_FLOAT_VEC4: case GL_FLOAT_VEC4:
case GL_INT_VEC4: case GL_INT_VEC4:
case GL_UNSIGNED_INT_VEC4:
case GL_SAMPLER_2D: case GL_SAMPLER_2D:
case GL_SAMPLER_CUBE: case GL_SAMPLER_CUBE:
case GL_SAMPLER_EXTERNAL_OES: case GL_SAMPLER_EXTERNAL_OES:
...@@ -169,15 +183,18 @@ namespace es2 ...@@ -169,15 +183,18 @@ namespace es2
case GL_BOOL: case GL_BOOL:
case GL_FLOAT: case GL_FLOAT:
case GL_INT: case GL_INT:
case GL_UNSIGNED_INT:
return 1; return 1;
case GL_BOOL_VEC2: case GL_BOOL_VEC2:
case GL_FLOAT_VEC2: case GL_FLOAT_VEC2:
case GL_INT_VEC2: case GL_INT_VEC2:
case GL_UNSIGNED_INT_VEC2:
case GL_FLOAT_MAT2: case GL_FLOAT_MAT2:
case GL_FLOAT_MAT2x3: case GL_FLOAT_MAT2x3:
case GL_FLOAT_MAT2x4: case GL_FLOAT_MAT2x4:
return 2; return 2;
case GL_INT_VEC3: case GL_INT_VEC3:
case GL_UNSIGNED_INT_VEC3:
case GL_FLOAT_VEC3: case GL_FLOAT_VEC3:
case GL_BOOL_VEC3: case GL_BOOL_VEC3:
case GL_FLOAT_MAT3: case GL_FLOAT_MAT3:
...@@ -187,6 +204,7 @@ namespace es2 ...@@ -187,6 +204,7 @@ namespace es2
case GL_BOOL_VEC4: case GL_BOOL_VEC4:
case GL_FLOAT_VEC4: case GL_FLOAT_VEC4:
case GL_INT_VEC4: case GL_INT_VEC4:
case GL_UNSIGNED_INT_VEC4:
case GL_FLOAT_MAT4: case GL_FLOAT_MAT4:
case GL_FLOAT_MAT4x2: case GL_FLOAT_MAT4x2:
case GL_FLOAT_MAT4x3: case GL_FLOAT_MAT4x3:
......
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