Passing uniform buffers to the vertex/pixel programs
This cl contains the necessary changes to make uniform buffers
usable in shaders. A few things to note:
- Uniform buffers can be set, but nothing will attempt to access
them in this cl.
- While the 'index' of uniforms is expressed in terms of registers,
uniform buffer 'index' is expressed in bytes in both PixelProgram
and VertexProgram. This is necessary because of packing which can
potentially put some variables in the middle of registers.
Technically, std140 always packs variables in multiples of byte4,
but other future layouts may not, so using bytes as the unit is
more future proof.
- The above mentioned 'index' will have to be computed in OutputASM
and extra operations will need to be added (to fetch a row from a
row major matrix, for example).
Change-Id: I636cc4bdc6fe90d6f5697e735f4288f48d18a75b
Reviewed-on: https://swiftshader-review.googlesource.com/4151
Tested-by: Alexis Hétu <sugoi@google.com>
Reviewed-by: Nicolas Capens <capn@google.com>
diff --git a/src/Shader/PixelProgram.cpp b/src/Shader/PixelProgram.cpp
index 9fec0b3..8f56c06 100644
--- a/src/Shader/PixelProgram.cpp
+++ b/src/Shader/PixelProgram.cpp
@@ -743,7 +743,7 @@
}
else
{
- Int a = relativeAddress(src);
+ Int a = relativeAddress(src, src.bufferIndex);
reg = r[i + a];
}
@@ -756,7 +756,7 @@
}
else
{
- Int a = relativeAddress(src);
+ Int a = relativeAddress(src, src.bufferIndex);
reg = v[i + a];
}
@@ -800,7 +800,7 @@
}
else
{
- Int a = relativeAddress(src);
+ Int a = relativeAddress(src, src.bufferIndex);
reg = oC[i + a];
}
@@ -858,6 +858,23 @@
return mod;
}
+ RValue<Pointer<Byte>> PixelProgram::uniformAddress(int bufferIndex, unsigned int index)
+ {
+ if(bufferIndex == -1)
+ {
+ return data + OFFSET(DrawData, ps.c[index]);
+ }
+ else
+ {
+ return *Pointer<Pointer<Byte>>(data + OFFSET(DrawData, ps.u[bufferIndex])) + index;
+ }
+ }
+
+ RValue<Pointer<Byte>> PixelProgram::uniformAddress(int bufferIndex, unsigned int index, Int& offset)
+ {
+ return uniformAddress(bufferIndex, index) + offset * sizeof(float4);
+ }
+
Vector4f PixelProgram::readConstant(const Src &src, unsigned int offset)
{
Vector4f c;
@@ -865,7 +882,7 @@
if(src.rel.type == Shader::PARAMETER_VOID) // Not relative
{
- c.x = c.y = c.z = c.w = *Pointer<Float4>(data + OFFSET(DrawData, ps.c[i]));
+ c.x = c.y = c.z = c.w = *Pointer<Float4>(uniformAddress(src.bufferIndex, i));
c.x = c.x.xxxx;
c.y = c.y.yyyy;
@@ -897,7 +914,7 @@
{
Int loopCounter = aL[loopDepth];
- c.x = c.y = c.z = c.w = *Pointer<Float4>(data + OFFSET(DrawData, ps.c[i]) + loopCounter * 16);
+ c.x = c.y = c.z = c.w = *Pointer<Float4>(uniformAddress(src.bufferIndex, i, loopCounter));
c.x = c.x.xxxx;
c.y = c.y.yyyy;
@@ -906,9 +923,9 @@
}
else
{
- Int a = relativeAddress(src);
+ Int a = relativeAddress(src, src.bufferIndex);
- c.x = c.y = c.z = c.w = *Pointer<Float4>(data + OFFSET(DrawData, ps.c[i]) + a * 16);
+ c.x = c.y = c.z = c.w = *Pointer<Float4>(uniformAddress(src.bufferIndex, i, a));
c.x = c.x.xxxx;
c.y = c.y.yyyy;
@@ -919,7 +936,7 @@
return c;
}
- Int PixelProgram::relativeAddress(const Shader::Parameter &var)
+ Int PixelProgram::relativeAddress(const Shader::Parameter &var, int bufferIndex)
{
ASSERT(var.rel.deterministic);
@@ -937,7 +954,7 @@
}
else if(var.rel.type == Shader::PARAMETER_CONST)
{
- RValue<Int4> c = *Pointer<Int4>(data + OFFSET(DrawData, ps.c[var.rel.index]));
+ RValue<Int4> c = *Pointer<Int4>(uniformAddress(bufferIndex, var.rel.index));
return Extract(c, 0) * var.rel.scale;
}