Fix API reported packing rules for matrices and arrays in shared layout to be consistent with HLSL.

HLSL does not round up the final array/matrix block to the register alignment, allowing for more compact order.

TRAC #22856

Signed-off-by: Geoff Lang
Signed-off-by: Shannon Woods
Authored-by: Jamie Madill
diff --git a/src/compiler/Uniform.cpp b/src/compiler/Uniform.cpp
index 111e83d..8a8b998 100644
--- a/src/compiler/Uniform.cpp
+++ b/src/compiler/Uniform.cpp
@@ -73,12 +73,15 @@
 
             if (uniform.arraySize > 0)
             {
-                *currentOffset += arrayStride * uniform.arraySize;
+                *currentOffset += arrayStride * (uniform.arraySize - 1);
             }
-            else if (gl::IsMatrixType(uniform.type))
+
+            if (gl::IsMatrixType(uniform.type))
             {
                 const int componentGroups = (isRowMajorMatrix ? gl::VariableRowCount(uniform.type) : gl::VariableColumnCount(uniform.type));
-                *currentOffset += matrixStride * componentGroups;
+                const int numComponents = (isRowMajorMatrix ? gl::VariableColumnCount(uniform.type) : gl::VariableRowCount(uniform.type));
+                *currentOffset += matrixStride * (componentGroups - 1);
+                *currentOffset += numComponents;
             }
             else
             {
@@ -156,7 +159,7 @@
     else
     {
         int numComponents = gl::UniformComponentCount(uniform.type);
-        if ((numComponents + (*currentOffset % registerSize)) >= registerSize)
+        if ((numComponents + (*currentOffset % registerSize)) > registerSize)
         {
             *currentOffset = rx::roundUp(*currentOffset, registerSize);
         }