Bug 1146034 - Cherry pick "Fix struct uniform packing." a=sledru
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Wed, 25 Mar 2015 10:13:31 -0400
changeset 258331 9adbbf9a8784
parent 258330 eb178aedaaad
child 258332 c2f29d6648e8
push id4647
push userryanvm@gmail.com
push date2015-04-07 21:15 +0000
treeherdermozilla-beta@6d1efbb2c76c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssledru
bugs1146034
milestone38.0
Bug 1146034 - Cherry pick "Fix struct uniform packing." a=sledru This comes from ANGLE commit 2857f489f32372310014888342c6f9c97fac5995
gfx/angle/src/common/blocklayout.cpp
gfx/angle/src/common/blocklayout.h
gfx/angle/src/libGLESv2/renderer/d3d/ProgramD3D.cpp
--- a/gfx/angle/src/common/blocklayout.cpp
+++ b/gfx/angle/src/common/blocklayout.cpp
@@ -28,16 +28,28 @@ BlockMemberInfo BlockLayoutEncoder::enco
 
     const BlockMemberInfo memberInfo(mCurrentOffset * BytesPerComponent, arrayStride * BytesPerComponent, matrixStride * BytesPerComponent, isRowMajorMatrix);
 
     advanceOffset(type, arraySize, isRowMajorMatrix, arrayStride, matrixStride);
 
     return memberInfo;
 }
 
+// static
+size_t BlockLayoutEncoder::getBlockRegister(const BlockMemberInfo &info)
+{
+    return (info.offset / BytesPerComponent) / ComponentsPerRegister;
+}
+
+// static
+size_t BlockLayoutEncoder::getBlockRegisterElement(const BlockMemberInfo &info)
+{
+    return (info.offset / BytesPerComponent) % ComponentsPerRegister;
+}
+
 void BlockLayoutEncoder::nextRegister()
 {
     mCurrentOffset = rx::roundUp<size_t>(mCurrentOffset, ComponentsPerRegister);
 }
 
 Std140BlockEncoder::Std140BlockEncoder()
 {
 }
--- a/gfx/angle/src/common/blocklayout.h
+++ b/gfx/angle/src/common/blocklayout.h
@@ -56,16 +56,19 @@ class BlockLayoutEncoder
     size_t getCurrentElement() const { return mCurrentOffset % ComponentsPerRegister; }
 
     virtual void enterAggregateType() = 0;
     virtual void exitAggregateType() = 0;
 
     static const size_t BytesPerComponent = 4u;
     static const unsigned int ComponentsPerRegister = 4u;
 
+    static size_t getBlockRegister(const BlockMemberInfo &info);
+    static size_t getBlockRegisterElement(const BlockMemberInfo &info);
+
   protected:
     size_t mCurrentOffset;
 
     void nextRegister();
 
     virtual void getBlockLayoutInfo(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int *arrayStrideOut, int *matrixStrideOut) = 0;
     virtual void advanceOffset(GLenum type, unsigned int arraySize, bool isRowMajorMatrix, int arrayStride, int matrixStride) = 0;
 };
--- a/gfx/angle/src/libGLESv2/renderer/d3d/ProgramD3D.cpp
+++ b/gfx/angle/src/libGLESv2/renderer/d3d/ProgramD3D.cpp
@@ -1389,40 +1389,38 @@ void ProgramD3D::defineUniform(GLenum sh
         // Arrays are treated as aggregate types
         if (uniform.isArray())
         {
             encoder->enterAggregateType();
         }
 
         gl::LinkedUniform *linkedUniform = getUniformByName(fullName);
 
+        // Advance the uniform offset, to track registers allocation for structs
+        sh::BlockMemberInfo blockInfo = encoder->encodeType(uniform.type, uniform.arraySize, false);
+
         if (!linkedUniform)
         {
             linkedUniform = new gl::LinkedUniform(uniform.type, uniform.precision, fullName, uniform.arraySize,
                                               -1, sh::BlockMemberInfo::getDefaultBlockInfo());
             ASSERT(linkedUniform);
-            linkedUniform->registerElement = encoder->getCurrentElement();
+            linkedUniform->registerElement = sh::HLSLBlockEncoder::getBlockRegisterElement(blockInfo);
             mUniforms.push_back(linkedUniform);
         }
 
-        ASSERT(linkedUniform->registerElement == encoder->getCurrentElement());
-
         if (shader == GL_FRAGMENT_SHADER)
         {
-            linkedUniform->psRegisterIndex = encoder->getCurrentRegister();
+            linkedUniform->psRegisterIndex = sh::HLSLBlockEncoder::getBlockRegister(blockInfo);
         }
         else if (shader == GL_VERTEX_SHADER)
         {
-            linkedUniform->vsRegisterIndex = encoder->getCurrentRegister();
+            linkedUniform->vsRegisterIndex = sh::HLSLBlockEncoder::getBlockRegister(blockInfo);
         }
         else UNREACHABLE();
 
-        // Advance the uniform offset, to track registers allocation for structs
-        encoder->encodeType(uniform.type, uniform.arraySize, false);
-
         // Arrays are treated as aggregate types
         if (uniform.isArray())
         {
             encoder->exitAggregateType();
         }
     }
 }