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/Renderer/PixelProcessor.cpp b/src/Renderer/PixelProcessor.cpp
index d157f51..4162598 100644
--- a/src/Renderer/PixelProcessor.cpp
+++ b/src/Renderer/PixelProcessor.cpp
@@ -136,6 +136,32 @@
 		else ASSERT(false);
 	}
 
+	void PixelProcessor::setUniformBuffer(int index, sw::Resource* buffer, int offset)
+	{
+		uniformBuffer[index] = buffer;
+		uniformBufferOffset[index] = offset;
+	}
+
+	void PixelProcessor::lockUniformBuffers(byte** u)
+	{
+		for(int i = 0; i < MAX_UNIFORM_BUFFER_BINDINGS; ++i)
+		{
+			u[i] = uniformBuffer[i] ? static_cast<byte*>(uniformBuffer[i]->lock(PUBLIC, PRIVATE)) + uniformBufferOffset[i] : nullptr;
+		}
+	}
+
+	void PixelProcessor::unlockUniformBuffers()
+	{
+		for(int i = 0; i < MAX_UNIFORM_BUFFER_BINDINGS; ++i)
+		{
+			if(uniformBuffer[i])
+			{
+				uniformBuffer[i]->unlock();
+				uniformBuffer[i] = nullptr;
+			}
+		}
+	}
+
 	void PixelProcessor::setRenderTarget(int index, Surface *renderTarget)
 	{
 		context->renderTarget[index] = renderTarget;