Commit 02a2bb80 by Alexis Hetu Committed by Alexis Hétu

Enable glsl integer code

This cl enables true integer support in glsl shaders. It still uses floating point registers to store all registers, regardless of the type, so integer and unsigned integer variables are simply reinterpreted as integers or unsigned integers and used as such by the appropriate instructions. Change-Id: If62213c917b4b0c907e58db9cd36944dd198beaa Reviewed-on: https://swiftshader-review.googlesource.com/3910Tested-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com>
parent 8d78cf77
......@@ -7,7 +7,7 @@
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
#include "windows.h"
#include "../Common/Version.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
......
......@@ -93,15 +93,16 @@ public:
float getFConst() const { return fConst; }
bool getBConst() const { return bConst; }
float getAsFloat()
float getAsFloat() const
{
const int FFFFFFFFh = 0xFFFFFFFF;
switch(type)
{
case EbtInt: return (float)iConst;
case EbtInt: return reinterpret_cast<const float&>(iConst);
case EbtUInt: return reinterpret_cast<const float&>(uConst);
case EbtFloat: return fConst;
case EbtBool: return (bConst == true) ? (float&)FFFFFFFFh : 0;
case EbtBool: return (bConst == true) ? reinterpret_cast<const float&>(FFFFFFFFh) : 0;
default: return 0;
}
}
......
......@@ -175,6 +175,7 @@ namespace glsl
virtual bool visitLoop(Visit visit, TIntermLoop*);
virtual bool visitBranch(Visit visit, TIntermBranch*);
sw::Shader::Opcode getOpcode(sw::Shader::Opcode op, TIntermTyped *in) const;
Instruction *emit(sw::Shader::Opcode op, TIntermTyped *dst = 0, TIntermNode *src0 = 0, TIntermNode *src1 = 0, TIntermNode *src2 = 0, int index = 0);
Instruction *emitCast(TIntermTyped *dst, TIntermTyped *src);
void emitBinary(sw::Shader::Opcode op, TIntermTyped *dst = 0, TIntermNode *src0 = 0, TIntermNode *src1 = 0, TIntermNode *src2 = 0);
......
......@@ -2994,9 +2994,9 @@ void APIENTRY glGetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype
case GL_LOW_INT:
case GL_MEDIUM_INT:
case GL_HIGH_INT:
// Single-precision floating-point numbers can accurately represent integers up to +/-16777216
range[0] = 24;
range[1] = 24;
// Full integer precision is supported
range[0] = 31;
range[1] = 30;
*precision = 0;
break;
default:
......
......@@ -169,7 +169,12 @@ public:
return mStride ? mStride : typeSize();
}
inline float getCurrentValue(int i) const
inline float getCurrentValueBitsAsFloat(int i) const
{
return mCurrentValue[i].f;
}
inline float getCurrentValueF(int i) const
{
switch(mCurrentValueType)
{
......
......@@ -2192,11 +2192,11 @@ namespace es2
bool Program::applyUniform1iv(GLint location, GLsizei count, const GLint *v)
{
float vector[MAX_UNIFORM_VECTORS][4];
GLint vector[MAX_UNIFORM_VECTORS][4];
for(int i = 0; i < count; i++)
{
vector[i][0] = (float)v[i];
vector[i][0] = v[i];
vector[i][1] = 0;
vector[i][2] = 0;
vector[i][3] = 0;
......@@ -2251,12 +2251,12 @@ namespace es2
bool Program::applyUniform2iv(GLint location, GLsizei count, const GLint *v)
{
float vector[MAX_UNIFORM_VECTORS][4];
GLint 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][0] = v[0];
vector[i][1] = v[1];
vector[i][2] = 0;
vector[i][3] = 0;
......@@ -2280,13 +2280,13 @@ namespace es2
bool Program::applyUniform3iv(GLint location, GLsizei count, const GLint *v)
{
float vector[MAX_UNIFORM_VECTORS][4];
GLint 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][0] = v[0];
vector[i][1] = v[1];
vector[i][2] = v[2];
vector[i][3] = 0;
v += 3;
......@@ -2309,14 +2309,14 @@ namespace es2
bool Program::applyUniform4iv(GLint location, GLsizei count, const GLint *v)
{
float vector[MAX_UNIFORM_VECTORS][4];
GLint 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];
vector[i][0] = v[0];
vector[i][1] = v[1];
vector[i][2] = v[2];
vector[i][3] = v[3];
v += 4;
}
......@@ -2338,11 +2338,11 @@ namespace es2
bool Program::applyUniform1uiv(GLint location, GLsizei count, const GLuint *v)
{
float vector[MAX_UNIFORM_VECTORS][4];
GLuint vector[MAX_UNIFORM_VECTORS][4];
for(int i = 0; i < count; i++)
{
vector[i][0] = (float)v[i];
vector[i][0] = v[i];
vector[i][1] = 0;
vector[i][2] = 0;
vector[i][3] = 0;
......@@ -2397,12 +2397,12 @@ namespace es2
bool Program::applyUniform2uiv(GLint location, GLsizei count, const GLuint *v)
{
float vector[MAX_UNIFORM_VECTORS][4];
GLuint 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][0] = v[0];
vector[i][1] = v[1];
vector[i][2] = 0;
vector[i][3] = 0;
......@@ -2426,13 +2426,13 @@ namespace es2
bool Program::applyUniform3uiv(GLint location, GLsizei count, const GLuint *v)
{
float vector[MAX_UNIFORM_VECTORS][4];
GLuint 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][0] = v[0];
vector[i][1] = v[1];
vector[i][2] = v[2];
vector[i][3] = 0;
v += 3;
......@@ -2455,14 +2455,14 @@ namespace es2
bool Program::applyUniform4uiv(GLint location, GLsizei count, const GLuint *v)
{
float vector[MAX_UNIFORM_VECTORS][4];
GLuint 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];
vector[i][0] = v[0];
vector[i][1] = v[1];
vector[i][2] = v[2];
vector[i][3] = v[3];
v += 4;
}
......
......@@ -200,7 +200,7 @@ GLenum VertexDataManager::prepareVertexData(GLint start, GLsizei count, Translat
if(mDirtyCurrentValue[i])
{
delete mCurrentValueBuffer[i];
mCurrentValueBuffer[i] = new ConstantVertexBuffer(attrib.getCurrentValue(0), attrib.getCurrentValue(1), attrib.getCurrentValue(2), attrib.getCurrentValue(3));
mCurrentValueBuffer[i] = new ConstantVertexBuffer(attrib.getCurrentValueBitsAsFloat(0), attrib.getCurrentValueBitsAsFloat(1), attrib.getCurrentValueBitsAsFloat(2), attrib.getCurrentValueBitsAsFloat(3));
mDirtyCurrentValue[i] = false;
}
......
......@@ -3582,9 +3582,9 @@ void GetShaderPrecisionFormat(GLenum shadertype, GLenum precisiontype, GLint* ra
case GL_LOW_INT:
case GL_MEDIUM_INT:
case GL_HIGH_INT:
// Single-precision floating-point numbers can accurately represent integers up to +/-16777216
range[0] = 24;
range[1] = 24;
// Full integer precision is supported
range[0] = 31;
range[1] = 30;
*precision = 0;
break;
default:
......@@ -4155,7 +4155,7 @@ void GetVertexAttribfv(GLuint index, GLenum pname, GLfloat* params)
const VertexAttribute& attrib = context->getCurrentVertexAttributes()[index];
for(int i = 0; i < 4; ++i)
{
params[i] = attrib.getCurrentValue(i);
params[i] = attrib.getCurrentValueF(i);
}
}
break;
......@@ -4228,7 +4228,7 @@ void GetVertexAttribiv(GLuint index, GLenum pname, GLint* params)
const VertexAttribute& attrib = context->getCurrentVertexAttributes()[index];
for(int i = 0; i < 4; ++i)
{
float currentValue = attrib.getCurrentValue(i);
float currentValue = attrib.getCurrentValueF(i);
params[i] = (GLint)(currentValue > 0.0f ? floor(currentValue + 0.5f) : ceil(currentValue - 0.5f));
}
}
......
......@@ -760,7 +760,7 @@ namespace sw
}
else if(src.rel.type == Shader::PARAMETER_TEMP)
{
reg.x = As<Float4>(Int4(i) + RoundInt(r.rf[src.rel.index].x));
reg.x = As<Float4>(Int4(i) + As<Int4>(r.rf[src.rel.index].x));
}
return reg;
case Shader::PARAMETER_PREDICATE: return reg; // Dummy
......@@ -898,21 +898,21 @@ namespace sw
if(var.rel.type == Shader::PARAMETER_TEMP)
{
return RoundInt(Extract(r.rf[var.rel.index].x, 0)) * var.rel.scale;
return As<Int>(Extract(r.rf[var.rel.index].x, 0)) * var.rel.scale;
}
else if(var.rel.type == Shader::PARAMETER_INPUT)
{
return RoundInt(Extract(r.vf[var.rel.index].x, 0)) * var.rel.scale;
return As<Int>(Extract(r.vf[var.rel.index].x, 0)) * var.rel.scale;
}
else if(var.rel.type == Shader::PARAMETER_OUTPUT)
{
return RoundInt(Extract(r.oC[var.rel.index].x, 0)) * var.rel.scale;
return As<Int>(Extract(r.oC[var.rel.index].x, 0)) * var.rel.scale;
}
else if(var.rel.type == Shader::PARAMETER_CONST)
{
RValue<Float4> c = *Pointer<Float4>(r.data + OFFSET(DrawData, ps.c[var.rel.index]));
RValue<Int4> c = *Pointer<Int4>(r.data + OFFSET(DrawData, ps.c[var.rel.index]));
return RoundInt(Extract(c, 0)) * var.rel.scale;
return Extract(c, 0) * var.rel.scale;
}
else ASSERT(false);
......
......@@ -583,11 +583,14 @@ namespace sw
}
}
void ShaderCore::mov(Vector4f &dst, const Vector4f &src, bool floorToInteger)
void ShaderCore::mov(Vector4f &dst, const Vector4f &src, bool integerDestination)
{
if(floorToInteger)
if(integerDestination)
{
dst.x = Floor(src.x);
dst.x = As<Float4>(RoundInt(src.x));
dst.y = As<Float4>(RoundInt(src.y));
dst.z = As<Float4>(RoundInt(src.z));
dst.w = As<Float4>(RoundInt(src.w));
}
else
{
......
......@@ -238,7 +238,7 @@ namespace sw
typedef Shader::Control Control;
public:
void mov(Vector4f &dst, const Vector4f &src, bool floorToInteger = false);
void mov(Vector4f &dst, const Vector4f &src, bool integerDestination = false);
void neg(Vector4f &dst, const Vector4f &src);
void ineg(Vector4f &dst, const Vector4f &src);
void f2b(Vector4f &dst, const Vector4f &src);
......
......@@ -188,7 +188,7 @@ namespace sw
case Shader::OPCODE_IMIN: imin(d, s0, s1); break;
case Shader::OPCODE_UMIN: umin(d, s0, s1); break;
case Shader::OPCODE_MOV: mov(d, s0, integer); break;
case Shader::OPCODE_MOVA: mov(d, s0); break;
case Shader::OPCODE_MOVA: mov(d, s0, true); break;
case Shader::OPCODE_NEG: neg(d, s0); break;
case Shader::OPCODE_INEG: ineg(d, s0); break;
case Shader::OPCODE_F2B: f2b(d, s0); break;
......@@ -680,7 +680,7 @@ namespace sw
}
else if(src.rel.type == Shader::PARAMETER_TEMP)
{
reg.x = As<Float4>(Int4(i) + RoundInt(r.r[src.rel.index].x));
reg.x = As<Float4>(Int4(i) + As<Int4>(r.r[src.rel.index].x));
}
return reg;
case Shader::PARAMETER_OUTPUT:
......@@ -694,7 +694,7 @@ namespace sw
}
break;
case Shader::PARAMETER_MISCTYPE:
reg.x = Float(r.instanceID);
reg.x = As<Float>(Int(r.instanceID));
return reg;
default:
ASSERT(false);
......@@ -821,7 +821,7 @@ namespace sw
default: ASSERT(false);
}
Int4 index = Int4(i) + RoundInt(a) * Int4(src.rel.scale);
Int4 index = Int4(i) + As<Int4>(a) * Int4(src.rel.scale);
index = Min(As<UInt4>(index), UInt4(256)); // Clamp to constant register range, c[256] = {0, 0, 0, 0}
......@@ -848,21 +848,21 @@ namespace sw
if(var.rel.type == Shader::PARAMETER_TEMP)
{
return RoundInt(Extract(r.r[var.rel.index].x, 0)) * var.rel.scale;
return As<Int>(Extract(r.r[var.rel.index].x, 0)) * var.rel.scale;
}
else if(var.rel.type == Shader::PARAMETER_INPUT)
{
return RoundInt(Extract(r.v[var.rel.index].x, 0)) * var.rel.scale;
return As<Int>(Extract(r.v[var.rel.index].x, 0)) * var.rel.scale;
}
else if(var.rel.type == Shader::PARAMETER_OUTPUT)
{
return RoundInt(Extract(r.o[var.rel.index].x, 0)) * var.rel.scale;
return As<Int>(Extract(r.o[var.rel.index].x, 0)) * var.rel.scale;
}
else if(var.rel.type == Shader::PARAMETER_CONST)
{
RValue<Float4> c = *Pointer<Float4>(r.data + OFFSET(DrawData,vs.c[var.rel.index]));
RValue<Int4> c = *Pointer<Int4>(r.data + OFFSET(DrawData, vs.c[var.rel.index]));
return RoundInt(Extract(c, 0)) * var.rel.scale;
return Extract(c, 0) * var.rel.scale;
}
else ASSERT(false);
......
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