Assign constant registers manually in HLSL.

TRAC #22293
Signed-off-by: Daniel Koch
Signed-off-by: Shannon Woods
Author: Nicolas Capens

git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1622 736b8ea6-26fd-11df-bfd4-992fa37f6226
diff --git a/src/compiler/OutputHLSL.cpp b/src/compiler/OutputHLSL.cpp
index d20e9b3..9fafc6d 100644
--- a/src/compiler/OutputHLSL.cpp
+++ b/src/compiler/OutputHLSL.cpp
@@ -89,6 +89,9 @@
     mInsideDiscontinuousLoop = false;
 
     mExcessiveLoopIndex = NULL;
+
+    mUniformRegister = 0;
+    mSamplerRegister = 0;
 }
 
 OutputHLSL::~OutputHLSL()
@@ -144,7 +147,8 @@
         const TType &type = uniform->second->getType();
         const TString &name = uniform->second->getSymbol();
 
-        uniforms += "uniform " + typeString(type) + " " + decorateUniform(name, type) + arrayString(type) + ";\n";
+        uniforms += "uniform " + typeString(type) + " " + decorateUniform(name, type) + arrayString(type) + 
+                    " : register(" + registerString(mReferencedUniforms[name]) + ");\n";
     }
 
     for (ReferencedSymbols::const_iterator varying = mReferencedVaryings.begin(); varying != mReferencedVaryings.end(); varying++)
@@ -2591,4 +2595,39 @@
 
     return string;
 }
+
+TString OutputHLSL::registerString(TIntermSymbol *operand)
+{
+    ASSERT(operand->getQualifier() == EvqUniform);
+
+    if (IsSampler(operand->getBasicType()))
+    {
+        return "s" + str(samplerRegister(operand));
+    }
+
+    return "c" + str(uniformRegister(operand));
+}
+
+int OutputHLSL::samplerRegister(TIntermSymbol *sampler)
+{
+    const TType &type = sampler->getType();
+    ASSERT(IsSampler(type.getBasicType()));
+
+    int index = mSamplerRegister;
+    mSamplerRegister += sampler->totalRegisterCount();
+
+    return index;
+}
+
+int OutputHLSL::uniformRegister(TIntermSymbol *uniform)
+{
+    const TType &type = uniform->getType();
+    ASSERT(!IsSampler(type.getBasicType()));
+
+    int index = mUniformRegister;
+    mUniformRegister += uniform->totalRegisterCount();
+
+    return index;
+}
+
 }