Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / angle / src / compiler / translator / OutputHLSL.cpp
index 9fa2da6..af996df 100644 (file)
@@ -13,6 +13,7 @@
 #include "compiler/translator/SearchSymbol.h"
 #include "compiler/translator/UnfoldShortCircuit.h"
 #include "compiler/translator/NodeSearch.h"
+#include "compiler/translator/RewriteElseBlocks.h"
 
 #include <algorithm>
 #include <cfloat>
 
 namespace sh
 {
-// Integer to TString conversion
-TString str(int i)
-{
-    char buffer[20];
-    snprintf(buffer, sizeof(buffer), "%d", i);
-    return buffer;
-}
 
 OutputHLSL::OutputHLSL(TParseContext &context, const ShBuiltInResources& resources, ShShaderOutput outputType)
     : TIntermTraverser(true, true, true), mContext(context), mOutputType(outputType)
@@ -115,6 +109,13 @@ void OutputHLSL::output()
 {
     mContainsLoopDiscontinuity = mContext.shaderType == SH_FRAGMENT_SHADER && containsLoopDiscontinuity(mContext.treeRoot);
 
+    // Work around D3D9 bug that would manifest in vertex shaders with selection blocks which
+    // use a vertex attribute as a condition, and some related computation in the else block.
+    if (mOutputType == SH_HLSL9_OUTPUT && mContext.shaderType == SH_VERTEX_SHADER)
+    {
+        RewriteElseBlocks(mContext.treeRoot);
+    }
+
     mContext.treeRoot->traverse(this);   // Output the body first to determine what has to go in the header
     header();
 
@@ -768,12 +769,12 @@ void OutputHLSL::header()
             }
             else if (mOutputType == SH_HLSL11_OUTPUT)
             {
-                out << "float4 gl_texture2DProj(Texture2D t, SamplerState s, float3 uvw, float lod)\n"
+                out << "float4 gl_texture2DProjLod(Texture2D t, SamplerState s, float3 uvw, float lod)\n"
                        "{\n"
                        "    return t.SampleLevel(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), lod);\n"
                        "}\n"
                        "\n"
-                       "float4 gl_texture2DProj(Texture2D t, SamplerState s, float4 uvw)\n"
+                       "float4 gl_texture2DProjLod(Texture2D t, SamplerState s, float4 uvw, float lod)\n"
                        "{\n"
                        "    return t.SampleLevel(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), lod);\n"
                        "}\n"
@@ -1099,6 +1100,10 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node)
             mReferencedVaryings[name] = node;
             out << decorate(name);
         }
+        else if (qualifier == EvqInternal)
+        {
+            out << name;
+        }
         else
         {
             out << decorate(name);