2 // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
7 #include "compiler/translator/OutputHLSL.h"
9 #include "common/angleutils.h"
10 #include "compiler/translator/compilerdebug.h"
11 #include "compiler/translator/DetectDiscontinuity.h"
12 #include "compiler/translator/InfoSink.h"
13 #include "compiler/translator/SearchSymbol.h"
14 #include "compiler/translator/UnfoldShortCircuit.h"
15 #include "compiler/translator/NodeSearch.h"
16 #include "compiler/translator/RewriteElseBlocks.h"
25 OutputHLSL::OutputHLSL(TParseContext &context, const ShBuiltInResources& resources, ShShaderOutput outputType)
26 : TIntermTraverser(true, true, true), mContext(context), mOutputType(outputType)
28 mUnfoldShortCircuit = new UnfoldShortCircuit(context, this);
29 mInsideFunction = false;
31 mUsesTexture2D = false;
32 mUsesTexture2D_bias = false;
33 mUsesTexture2DProj = false;
34 mUsesTexture2DProj_bias = false;
35 mUsesTexture2DProjLod = false;
36 mUsesTexture2DLod = false;
37 mUsesTextureCube = false;
38 mUsesTextureCube_bias = false;
39 mUsesTextureCubeLod = false;
40 mUsesTexture2DLod0 = false;
41 mUsesTexture2DLod0_bias = false;
42 mUsesTexture2DProjLod0 = false;
43 mUsesTexture2DProjLod0_bias = false;
44 mUsesTextureCubeLod0 = false;
45 mUsesTextureCubeLod0_bias = false;
46 mUsesFragColor = false;
47 mUsesFragData = false;
48 mUsesDepthRange = false;
49 mUsesFragCoord = false;
50 mUsesPointCoord = false;
51 mUsesFrontFacing = false;
52 mUsesPointSize = false;
53 mUsesFragDepth = false;
62 mUsesFaceforward1 = false;
63 mUsesFaceforward2 = false;
64 mUsesFaceforward3 = false;
65 mUsesFaceforward4 = false;
70 mUsesDiscardRewriting = false;
72 mNumRenderTargets = resources.EXT_draw_buffers ? resources.MaxDrawBuffers : 1;
78 mContainsLoopDiscontinuity = false;
79 mOutputLod0Function = false;
80 mInsideDiscontinuousLoop = false;
82 mExcessiveLoopIndex = NULL;
84 if (mOutputType == SH_HLSL9_OUTPUT)
86 if (mContext.shaderType == SH_FRAGMENT_SHADER)
88 mUniformRegister = 3; // Reserve registers for dx_DepthRange, dx_ViewCoords and dx_DepthFront
92 mUniformRegister = 2; // Reserve registers for dx_DepthRange and dx_ViewAdjust
100 mSamplerRegister = 0;
103 OutputHLSL::~OutputHLSL()
105 delete mUnfoldShortCircuit;
108 void OutputHLSL::output()
110 mContainsLoopDiscontinuity = mContext.shaderType == SH_FRAGMENT_SHADER && containsLoopDiscontinuity(mContext.treeRoot);
112 // Work around D3D9 bug that would manifest in vertex shaders with selection blocks which
113 // use a vertex attribute as a condition, and some related computation in the else block.
114 if (mOutputType == SH_HLSL9_OUTPUT && mContext.shaderType == SH_VERTEX_SHADER)
116 RewriteElseBlocks(mContext.treeRoot);
119 mContext.treeRoot->traverse(this); // Output the body first to determine what has to go in the header
122 mContext.infoSink().obj << mHeader.c_str();
123 mContext.infoSink().obj << mBody.c_str();
126 TInfoSinkBase &OutputHLSL::getBodyStream()
131 const ActiveUniforms &OutputHLSL::getUniforms()
133 return mActiveUniforms;
136 int OutputHLSL::vectorSize(const TType &type) const
138 int elementSize = type.isMatrix() ? type.getNominalSize() : 1;
139 int arraySize = type.isArray() ? type.getArraySize() : 1;
141 return elementSize * arraySize;
144 void OutputHLSL::header()
146 ShShaderType shaderType = mContext.shaderType;
147 TInfoSinkBase &out = mHeader;
149 for (StructDeclarations::iterator structDeclaration = mStructDeclarations.begin(); structDeclaration != mStructDeclarations.end(); structDeclaration++)
151 out << *structDeclaration;
154 for (Constructors::iterator constructor = mConstructors.begin(); constructor != mConstructors.end(); constructor++)
163 for (ReferencedSymbols::const_iterator uniform = mReferencedUniforms.begin(); uniform != mReferencedUniforms.end(); uniform++)
165 const TType &type = uniform->second->getType();
166 const TString &name = uniform->second->getSymbol();
168 if (mOutputType == SH_HLSL11_OUTPUT && IsSampler(type.getBasicType())) // Also declare the texture
170 int index = samplerRegister(mReferencedUniforms[name]);
172 uniforms += "uniform SamplerState sampler_" + decorateUniform(name, type) + arrayString(type) +
173 " : register(s" + str(index) + ");\n";
175 uniforms += "uniform " + textureString(type) + " texture_" + decorateUniform(name, type) + arrayString(type) +
176 " : register(t" + str(index) + ");\n";
180 uniforms += "uniform " + typeString(type) + " " + decorateUniform(name, type) + arrayString(type) +
181 " : register(" + registerString(mReferencedUniforms[name]) + ");\n";
185 for (ReferencedSymbols::const_iterator varying = mReferencedVaryings.begin(); varying != mReferencedVaryings.end(); varying++)
187 const TType &type = varying->second->getType();
188 const TString &name = varying->second->getSymbol();
190 // Program linking depends on this exact format
191 varyings += "static " + typeString(type) + " " + decorate(name) + arrayString(type) + " = " + initializer(type) + ";\n";
194 for (ReferencedSymbols::const_iterator attribute = mReferencedAttributes.begin(); attribute != mReferencedAttributes.end(); attribute++)
196 const TType &type = attribute->second->getType();
197 const TString &name = attribute->second->getSymbol();
199 attributes += "static " + typeString(type) + " " + decorate(name) + arrayString(type) + " = " + initializer(type) + ";\n";
202 if (mUsesDiscardRewriting)
204 out << "#define ANGLE_USES_DISCARD_REWRITING" << "\n";
207 if (shaderType == SH_FRAGMENT_SHADER)
209 TExtensionBehavior::const_iterator iter = mContext.extensionBehavior().find("GL_EXT_draw_buffers");
210 const bool usingMRTExtension = (iter != mContext.extensionBehavior().end() && (iter->second == EBhEnable || iter->second == EBhRequire));
212 const unsigned int numColorValues = usingMRTExtension ? mNumRenderTargets : 1;
214 out << "// Varyings\n";
217 "static float4 gl_Color[" << numColorValues << "] =\n"
219 for (unsigned int i = 0; i < numColorValues; i++)
221 out << " float4(0, 0, 0, 0)";
222 if (i + 1 != numColorValues)
232 out << "static float gl_Depth = 0.0;\n";
237 out << "static float4 gl_FragCoord = float4(0, 0, 0, 0);\n";
242 out << "static float2 gl_PointCoord = float2(0.5, 0.5);\n";
245 if (mUsesFrontFacing)
247 out << "static bool gl_FrontFacing = false;\n";
254 out << "struct gl_DepthRangeParameters\n"
263 if (mOutputType == SH_HLSL11_OUTPUT)
265 out << "cbuffer DriverConstants : register(b1)\n"
270 out << " float3 dx_DepthRange : packoffset(c0);\n";
275 out << " float4 dx_ViewCoords : packoffset(c1);\n";
278 if (mUsesFragCoord || mUsesFrontFacing)
280 out << " float3 dx_DepthFront : packoffset(c2);\n";
289 out << "uniform float3 dx_DepthRange : register(c0);";
294 out << "uniform float4 dx_ViewCoords : register(c1);\n";
297 if (mUsesFragCoord || mUsesFrontFacing)
299 out << "uniform float3 dx_DepthFront : register(c2);\n";
307 out << "static gl_DepthRangeParameters gl_DepthRange = {dx_DepthRange.x, dx_DepthRange.y, dx_DepthRange.z};\n"
316 if (mOutputType == SH_HLSL9_OUTPUT)
318 out << "float4 gl_texture2D(sampler2D s, float2 t)\n"
320 " return tex2D(s, t);\n"
324 else if (mOutputType == SH_HLSL11_OUTPUT)
326 out << "float4 gl_texture2D(Texture2D t, SamplerState s, float2 uv)\n"
328 " return t.Sample(s, uv);\n"
335 if (mUsesTexture2D_bias)
337 if (mOutputType == SH_HLSL9_OUTPUT)
339 out << "float4 gl_texture2D(sampler2D s, float2 t, float bias)\n"
341 " return tex2Dbias(s, float4(t.x, t.y, 0, bias));\n"
345 else if (mOutputType == SH_HLSL11_OUTPUT)
347 out << "float4 gl_texture2D(Texture2D t, SamplerState s, float2 uv, float bias)\n"
349 " return t.SampleBias(s, uv, bias);\n"
356 if (mUsesTexture2DProj)
358 if (mOutputType == SH_HLSL9_OUTPUT)
360 out << "float4 gl_texture2DProj(sampler2D s, float3 t)\n"
362 " return tex2Dproj(s, float4(t.x, t.y, 0, t.z));\n"
365 "float4 gl_texture2DProj(sampler2D s, float4 t)\n"
367 " return tex2Dproj(s, t);\n"
371 else if (mOutputType == SH_HLSL11_OUTPUT)
373 out << "float4 gl_texture2DProj(Texture2D t, SamplerState s, float3 uvw)\n"
375 " return t.Sample(s, float2(uvw.x / uvw.z, uvw.y / uvw.z));\n"
378 "float4 gl_texture2DProj(Texture2D t, SamplerState s, float4 uvw)\n"
380 " return t.Sample(s, float2(uvw.x / uvw.w, uvw.y / uvw.w));\n"
387 if (mUsesTexture2DProj_bias)
389 if (mOutputType == SH_HLSL9_OUTPUT)
391 out << "float4 gl_texture2DProj(sampler2D s, float3 t, float bias)\n"
393 " return tex2Dbias(s, float4(t.x / t.z, t.y / t.z, 0, bias));\n"
396 "float4 gl_texture2DProj(sampler2D s, float4 t, float bias)\n"
398 " return tex2Dbias(s, float4(t.x / t.w, t.y / t.w, 0, bias));\n"
402 else if (mOutputType == SH_HLSL11_OUTPUT)
404 out << "float4 gl_texture2DProj(Texture2D t, SamplerState s, float3 uvw, float bias)\n"
406 " return t.SampleBias(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), bias);\n"
409 "float4 gl_texture2DProj(Texture2D t, SamplerState s, float4 uvw, float bias)\n"
411 " return t.SampleBias(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), bias);\n"
418 if (mUsesTextureCube)
420 if (mOutputType == SH_HLSL9_OUTPUT)
422 out << "float4 gl_textureCube(samplerCUBE s, float3 t)\n"
424 " return texCUBE(s, t);\n"
428 else if (mOutputType == SH_HLSL11_OUTPUT)
430 out << "float4 gl_textureCube(TextureCube t, SamplerState s, float3 uvw)\n"
432 " return t.Sample(s, uvw);\n"
439 if (mUsesTextureCube_bias)
441 if (mOutputType == SH_HLSL9_OUTPUT)
443 out << "float4 gl_textureCube(samplerCUBE s, float3 t, float bias)\n"
445 " return texCUBEbias(s, float4(t.x, t.y, t.z, bias));\n"
449 else if (mOutputType == SH_HLSL11_OUTPUT)
451 out << "float4 gl_textureCube(TextureCube t, SamplerState s, float3 uvw, float bias)\n"
453 " return t.SampleBias(s, uvw, bias);\n"
460 // These *Lod0 intrinsics are not available in GL fragment shaders.
461 // They are used to sample using discontinuous texture coordinates.
462 if (mUsesTexture2DLod0)
464 if (mOutputType == SH_HLSL9_OUTPUT)
466 out << "float4 gl_texture2DLod0(sampler2D s, float2 t)\n"
468 " return tex2Dlod(s, float4(t.x, t.y, 0, 0));\n"
472 else if (mOutputType == SH_HLSL11_OUTPUT)
474 out << "float4 gl_texture2DLod0(Texture2D t, SamplerState s, float2 uv)\n"
476 " return t.SampleLevel(s, uv, 0);\n"
483 if (mUsesTexture2DLod0_bias)
485 if (mOutputType == SH_HLSL9_OUTPUT)
487 out << "float4 gl_texture2DLod0(sampler2D s, float2 t, float bias)\n"
489 " return tex2Dlod(s, float4(t.x, t.y, 0, 0));\n"
493 else if (mOutputType == SH_HLSL11_OUTPUT)
495 out << "float4 gl_texture2DLod0(Texture2D t, SamplerState s, float2 uv, float bias)\n"
497 " return t.SampleLevel(s, uv, 0);\n"
504 if (mUsesTexture2DProjLod0)
506 if (mOutputType == SH_HLSL9_OUTPUT)
508 out << "float4 gl_texture2DProjLod0(sampler2D s, float3 t)\n"
510 " return tex2Dlod(s, float4(t.x / t.z, t.y / t.z, 0, 0));\n"
513 "float4 gl_texture2DProjLod(sampler2D s, float4 t)\n"
515 " return tex2Dlod(s, float4(t.x / t.w, t.y / t.w, 0, 0));\n"
519 else if (mOutputType == SH_HLSL11_OUTPUT)
521 out << "float4 gl_texture2DProjLod0(Texture2D t, SamplerState s, float3 uvw)\n"
523 " return t.SampleLevel(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), 0);\n"
526 "float4 gl_texture2DProjLod0(Texture2D t, SamplerState s, float4 uvw)\n"
528 " return t.SampleLevel(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), 0);\n"
535 if (mUsesTexture2DProjLod0_bias)
537 if (mOutputType == SH_HLSL9_OUTPUT)
539 out << "float4 gl_texture2DProjLod0_bias(sampler2D s, float3 t, float bias)\n"
541 " return tex2Dlod(s, float4(t.x / t.z, t.y / t.z, 0, 0));\n"
544 "float4 gl_texture2DProjLod_bias(sampler2D s, float4 t, float bias)\n"
546 " return tex2Dlod(s, float4(t.x / t.w, t.y / t.w, 0, 0));\n"
550 else if (mOutputType == SH_HLSL11_OUTPUT)
552 out << "float4 gl_texture2DProjLod_bias(Texture2D t, SamplerState s, float3 uvw, float bias)\n"
554 " return t.SampleLevel(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), 0);\n"
557 "float4 gl_texture2DProjLod_bias(Texture2D t, SamplerState s, float4 uvw, float bias)\n"
559 " return t.SampleLevel(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), 0);\n"
566 if (mUsesTextureCubeLod0)
568 if (mOutputType == SH_HLSL9_OUTPUT)
570 out << "float4 gl_textureCubeLod0(samplerCUBE s, float3 t)\n"
572 " return texCUBElod(s, float4(t.x, t.y, t.z, 0));\n"
576 else if (mOutputType == SH_HLSL11_OUTPUT)
578 out << "float4 gl_textureCubeLod0(TextureCube t, SamplerState s, float3 uvw)\n"
580 " return t.SampleLevel(s, uvw, 0);\n"
587 if (mUsesTextureCubeLod0_bias)
589 if (mOutputType == SH_HLSL9_OUTPUT)
591 out << "float4 gl_textureCubeLod0(samplerCUBE s, float3 t, float bias)\n"
593 " return texCUBElod(s, float4(t.x, t.y, t.z, 0));\n"
597 else if (mOutputType == SH_HLSL11_OUTPUT)
599 out << "float4 gl_textureCubeLod0(TextureCube t, SamplerState s, float3 uvw, float bias)\n"
601 " return t.SampleLevel(s, uvw, 0);\n"
608 if (usingMRTExtension && mNumRenderTargets > 1)
610 out << "#define GL_USES_MRT\n";
615 out << "#define GL_USES_FRAG_COLOR\n";
620 out << "#define GL_USES_FRAG_DATA\n";
623 else // Vertex shader
625 out << "// Attributes\n";
628 "static float4 gl_Position = float4(0, 0, 0, 0);\n";
632 out << "static float gl_PointSize = float(1);\n";
642 out << "struct gl_DepthRangeParameters\n"
651 if (mOutputType == SH_HLSL11_OUTPUT)
655 out << "cbuffer DriverConstants : register(b1)\n"
657 " float3 dx_DepthRange : packoffset(c0);\n"
666 out << "uniform float3 dx_DepthRange : register(c0);\n";
669 out << "uniform float4 dx_ViewAdjust : register(c1);\n"
675 out << "static gl_DepthRangeParameters gl_DepthRange = {dx_DepthRange.x, dx_DepthRange.y, dx_DepthRange.z};\n"
684 if (mOutputType == SH_HLSL9_OUTPUT)
686 out << "float4 gl_texture2D(sampler2D s, float2 t)\n"
688 " return tex2Dlod(s, float4(t.x, t.y, 0, 0));\n"
692 else if (mOutputType == SH_HLSL11_OUTPUT)
694 out << "float4 gl_texture2D(Texture2D t, SamplerState s, float2 uv)\n"
696 " return t.SampleLevel(s, uv, 0);\n"
703 if (mUsesTexture2DLod)
705 if (mOutputType == SH_HLSL9_OUTPUT)
707 out << "float4 gl_texture2DLod(sampler2D s, float2 t, float lod)\n"
709 " return tex2Dlod(s, float4(t.x, t.y, 0, lod));\n"
713 else if (mOutputType == SH_HLSL11_OUTPUT)
715 out << "float4 gl_texture2DLod(Texture2D t, SamplerState s, float2 uv, float lod)\n"
717 " return t.SampleLevel(s, uv, lod);\n"
724 if (mUsesTexture2DProj)
726 if (mOutputType == SH_HLSL9_OUTPUT)
728 out << "float4 gl_texture2DProj(sampler2D s, float3 t)\n"
730 " return tex2Dlod(s, float4(t.x / t.z, t.y / t.z, 0, 0));\n"
733 "float4 gl_texture2DProj(sampler2D s, float4 t)\n"
735 " return tex2Dlod(s, float4(t.x / t.w, t.y / t.w, 0, 0));\n"
739 else if (mOutputType == SH_HLSL11_OUTPUT)
741 out << "float4 gl_texture2DProj(Texture2D t, SamplerState s, float3 uvw)\n"
743 " return t.SampleLevel(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), 0);\n"
746 "float4 gl_texture2DProj(Texture2D t, SamplerState s, float4 uvw)\n"
748 " return t.SampleLevel(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), 0);\n"
755 if (mUsesTexture2DProjLod)
757 if (mOutputType == SH_HLSL9_OUTPUT)
759 out << "float4 gl_texture2DProjLod(sampler2D s, float3 t, float lod)\n"
761 " return tex2Dlod(s, float4(t.x / t.z, t.y / t.z, 0, lod));\n"
764 "float4 gl_texture2DProjLod(sampler2D s, float4 t, float lod)\n"
766 " return tex2Dlod(s, float4(t.x / t.w, t.y / t.w, 0, lod));\n"
770 else if (mOutputType == SH_HLSL11_OUTPUT)
772 out << "float4 gl_texture2DProjLod(Texture2D t, SamplerState s, float3 uvw, float lod)\n"
774 " return t.SampleLevel(s, float2(uvw.x / uvw.z, uvw.y / uvw.z), lod);\n"
777 "float4 gl_texture2DProjLod(Texture2D t, SamplerState s, float4 uvw, float lod)\n"
779 " return t.SampleLevel(s, float2(uvw.x / uvw.w, uvw.y / uvw.w), lod);\n"
786 if (mUsesTextureCube)
788 if (mOutputType == SH_HLSL9_OUTPUT)
790 out << "float4 gl_textureCube(samplerCUBE s, float3 t)\n"
792 " return texCUBElod(s, float4(t.x, t.y, t.z, 0));\n"
796 else if (mOutputType == SH_HLSL11_OUTPUT)
798 out << "float4 gl_textureCube(TextureCube t, SamplerState s, float3 uvw)\n"
800 " return t.SampleLevel(s, uvw, 0);\n"
807 if (mUsesTextureCubeLod)
809 if (mOutputType == SH_HLSL9_OUTPUT)
811 out << "float4 gl_textureCubeLod(samplerCUBE s, float3 t, float lod)\n"
813 " return texCUBElod(s, float4(t.x, t.y, t.z, lod));\n"
817 else if (mOutputType == SH_HLSL11_OUTPUT)
819 out << "float4 gl_textureCubeLod(TextureCube t, SamplerState s, float3 uvw, float lod)\n"
821 " return t.SampleLevel(s, uvw, lod);\n"
831 out << "#define GL_USES_FRAG_COORD\n";
836 out << "#define GL_USES_POINT_COORD\n";
839 if (mUsesFrontFacing)
841 out << "#define GL_USES_FRONT_FACING\n";
846 out << "#define GL_USES_POINT_SIZE\n";
851 out << "#define GL_USES_FRAG_DEPTH\n";
856 out << "#define GL_USES_DEPTH_RANGE\n";
861 out << "bool xor(bool p, bool q)\n"
863 " return (p || q) && !(p && q);\n"
870 out << "float mod(float x, float y)\n"
872 " return x - y * floor(x / y);\n"
879 out << "float2 mod(float2 x, float2 y)\n"
881 " return x - y * floor(x / y);\n"
888 out << "float2 mod(float2 x, float y)\n"
890 " return x - y * floor(x / y);\n"
897 out << "float3 mod(float3 x, float3 y)\n"
899 " return x - y * floor(x / y);\n"
906 out << "float3 mod(float3 x, float y)\n"
908 " return x - y * floor(x / y);\n"
915 out << "float4 mod(float4 x, float4 y)\n"
917 " return x - y * floor(x / y);\n"
924 out << "float4 mod(float4 x, float y)\n"
926 " return x - y * floor(x / y);\n"
931 if (mUsesFaceforward1)
933 out << "float faceforward(float N, float I, float Nref)\n"
935 " if(dot(Nref, I) >= 0)\n"
947 if (mUsesFaceforward2)
949 out << "float2 faceforward(float2 N, float2 I, float2 Nref)\n"
951 " if(dot(Nref, I) >= 0)\n"
963 if (mUsesFaceforward3)
965 out << "float3 faceforward(float3 N, float3 I, float3 Nref)\n"
967 " if(dot(Nref, I) >= 0)\n"
979 if (mUsesFaceforward4)
981 out << "float4 faceforward(float4 N, float4 I, float4 Nref)\n"
983 " if(dot(Nref, I) >= 0)\n"
997 out << "float atanyx(float y, float x)\n"
999 " if(x == 0 && y == 0) x = 1;\n" // Avoid producing a NaN
1000 " return atan2(y, x);\n"
1006 out << "float2 atanyx(float2 y, float2 x)\n"
1008 " if(x[0] == 0 && y[0] == 0) x[0] = 1;\n"
1009 " if(x[1] == 0 && y[1] == 0) x[1] = 1;\n"
1010 " return float2(atan2(y[0], x[0]), atan2(y[1], x[1]));\n"
1016 out << "float3 atanyx(float3 y, float3 x)\n"
1018 " if(x[0] == 0 && y[0] == 0) x[0] = 1;\n"
1019 " if(x[1] == 0 && y[1] == 0) x[1] = 1;\n"
1020 " if(x[2] == 0 && y[2] == 0) x[2] = 1;\n"
1021 " return float3(atan2(y[0], x[0]), atan2(y[1], x[1]), atan2(y[2], x[2]));\n"
1027 out << "float4 atanyx(float4 y, float4 x)\n"
1029 " if(x[0] == 0 && y[0] == 0) x[0] = 1;\n"
1030 " if(x[1] == 0 && y[1] == 0) x[1] = 1;\n"
1031 " if(x[2] == 0 && y[2] == 0) x[2] = 1;\n"
1032 " if(x[3] == 0 && y[3] == 0) x[3] = 1;\n"
1033 " return float4(atan2(y[0], x[0]), atan2(y[1], x[1]), atan2(y[2], x[2]), atan2(y[3], x[3]));\n"
1038 void OutputHLSL::visitSymbol(TIntermSymbol *node)
1040 TInfoSinkBase &out = mBody;
1042 TString name = node->getSymbol();
1044 if (name == "gl_FragColor")
1046 out << "gl_Color[0]";
1047 mUsesFragColor = true;
1049 else if (name == "gl_FragData")
1052 mUsesFragData = true;
1054 else if (name == "gl_DepthRange")
1056 mUsesDepthRange = true;
1059 else if (name == "gl_FragCoord")
1061 mUsesFragCoord = true;
1064 else if (name == "gl_PointCoord")
1066 mUsesPointCoord = true;
1069 else if (name == "gl_FrontFacing")
1071 mUsesFrontFacing = true;
1074 else if (name == "gl_PointSize")
1076 mUsesPointSize = true;
1079 else if (name == "gl_FragDepthEXT")
1081 mUsesFragDepth = true;
1086 TQualifier qualifier = node->getQualifier();
1088 if (qualifier == EvqUniform)
1090 mReferencedUniforms[name] = node;
1091 out << decorateUniform(name, node->getType());
1093 else if (qualifier == EvqAttribute)
1095 mReferencedAttributes[name] = node;
1096 out << decorate(name);
1098 else if (qualifier == EvqVaryingOut || qualifier == EvqInvariantVaryingOut || qualifier == EvqVaryingIn || qualifier == EvqInvariantVaryingIn)
1100 mReferencedVaryings[name] = node;
1101 out << decorate(name);
1103 else if (qualifier == EvqInternal)
1109 out << decorate(name);
1114 bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node)
1116 TInfoSinkBase &out = mBody;
1118 switch (node->getOp())
1120 case EOpAssign: outputTriplet(visit, "(", " = ", ")"); break;
1122 if (visit == PreVisit)
1124 // GLSL allows to write things like "float x = x;" where a new variable x is defined
1125 // and the value of an existing variable x is assigned. HLSL uses C semantics (the
1126 // new variable is created before the assignment is evaluated), so we need to convert
1127 // this to "float t = x, x = t;".
1129 TIntermSymbol *symbolNode = node->getLeft()->getAsSymbolNode();
1130 TIntermTyped *expression = node->getRight();
1132 sh::SearchSymbol searchSymbol(symbolNode->getSymbol());
1133 expression->traverse(&searchSymbol);
1134 bool sameSymbol = searchSymbol.foundMatch();
1138 // Type already printed
1139 out << "t" + str(mUniqueIndex) + " = ";
1140 expression->traverse(this);
1142 symbolNode->traverse(this);
1143 out << " = t" + str(mUniqueIndex);
1149 else if (visit == InVisit)
1154 case EOpAddAssign: outputTriplet(visit, "(", " += ", ")"); break;
1155 case EOpSubAssign: outputTriplet(visit, "(", " -= ", ")"); break;
1156 case EOpMulAssign: outputTriplet(visit, "(", " *= ", ")"); break;
1157 case EOpVectorTimesScalarAssign: outputTriplet(visit, "(", " *= ", ")"); break;
1158 case EOpMatrixTimesScalarAssign: outputTriplet(visit, "(", " *= ", ")"); break;
1159 case EOpVectorTimesMatrixAssign:
1160 if (visit == PreVisit)
1164 else if (visit == InVisit)
1167 node->getLeft()->traverse(this);
1168 out << ", transpose(";
1175 case EOpMatrixTimesMatrixAssign:
1176 if (visit == PreVisit)
1180 else if (visit == InVisit)
1183 node->getLeft()->traverse(this);
1191 case EOpDivAssign: outputTriplet(visit, "(", " /= ", ")"); break;
1192 case EOpIndexDirect: outputTriplet(visit, "", "[", "]"); break;
1193 case EOpIndexIndirect: outputTriplet(visit, "", "[", "]"); break;
1194 case EOpIndexDirectStruct:
1195 if (visit == InVisit)
1197 const TStructure* structure = node->getLeft()->getType().getStruct();
1198 const TIntermConstantUnion* index = node->getRight()->getAsConstantUnion();
1199 const TField* field = structure->fields()[index->getIConst(0)];
1200 out << "." + decorateField(field->name(), node->getLeft()->getType());
1205 case EOpVectorSwizzle:
1206 if (visit == InVisit)
1210 TIntermAggregate *swizzle = node->getRight()->getAsAggregate();
1214 TIntermSequence &sequence = swizzle->getSequence();
1216 for (TIntermSequence::iterator sit = sequence.begin(); sit != sequence.end(); sit++)
1218 TIntermConstantUnion *element = (*sit)->getAsConstantUnion();
1222 int i = element->getIConst(0);
1226 case 0: out << "x"; break;
1227 case 1: out << "y"; break;
1228 case 2: out << "z"; break;
1229 case 3: out << "w"; break;
1230 default: UNREACHABLE();
1238 return false; // Fully processed
1241 case EOpAdd: outputTriplet(visit, "(", " + ", ")"); break;
1242 case EOpSub: outputTriplet(visit, "(", " - ", ")"); break;
1243 case EOpMul: outputTriplet(visit, "(", " * ", ")"); break;
1244 case EOpDiv: outputTriplet(visit, "(", " / ", ")"); break;
1247 if (node->getLeft()->isScalar())
1249 if (node->getOp() == EOpEqual)
1251 outputTriplet(visit, "(", " == ", ")");
1255 outputTriplet(visit, "(", " != ", ")");
1258 else if (node->getLeft()->getBasicType() == EbtStruct)
1260 if (node->getOp() == EOpEqual)
1269 const TFieldList &fields = node->getLeft()->getType().getStruct()->fields();
1271 for (size_t i = 0; i < fields.size(); i++)
1273 const TField *field = fields[i];
1275 node->getLeft()->traverse(this);
1276 out << "." + decorateField(field->name(), node->getLeft()->getType()) + " == ";
1277 node->getRight()->traverse(this);
1278 out << "." + decorateField(field->name(), node->getLeft()->getType());
1280 if (i < fields.size() - 1)
1292 ASSERT(node->getLeft()->isMatrix() || node->getLeft()->isVector());
1294 if (node->getOp() == EOpEqual)
1296 outputTriplet(visit, "all(", " == ", ")");
1300 outputTriplet(visit, "!all(", " == ", ")");
1304 case EOpLessThan: outputTriplet(visit, "(", " < ", ")"); break;
1305 case EOpGreaterThan: outputTriplet(visit, "(", " > ", ")"); break;
1306 case EOpLessThanEqual: outputTriplet(visit, "(", " <= ", ")"); break;
1307 case EOpGreaterThanEqual: outputTriplet(visit, "(", " >= ", ")"); break;
1308 case EOpVectorTimesScalar: outputTriplet(visit, "(", " * ", ")"); break;
1309 case EOpMatrixTimesScalar: outputTriplet(visit, "(", " * ", ")"); break;
1310 case EOpVectorTimesMatrix: outputTriplet(visit, "mul(", ", transpose(", "))"); break;
1311 case EOpMatrixTimesVector: outputTriplet(visit, "mul(transpose(", "), ", ")"); break;
1312 case EOpMatrixTimesMatrix: outputTriplet(visit, "transpose(mul(transpose(", "), transpose(", ")))"); break;
1314 if (node->getRight()->hasSideEffects())
1316 out << "s" << mUnfoldShortCircuit->getNextTemporaryIndex();
1321 outputTriplet(visit, "(", " || ", ")");
1326 outputTriplet(visit, "xor(", ", ", ")");
1329 if (node->getRight()->hasSideEffects())
1331 out << "s" << mUnfoldShortCircuit->getNextTemporaryIndex();
1336 outputTriplet(visit, "(", " && ", ")");
1339 default: UNREACHABLE();
1345 bool OutputHLSL::visitUnary(Visit visit, TIntermUnary *node)
1347 switch (node->getOp())
1349 case EOpNegative: outputTriplet(visit, "(-", "", ")"); break;
1350 case EOpVectorLogicalNot: outputTriplet(visit, "(!", "", ")"); break;
1351 case EOpLogicalNot: outputTriplet(visit, "(!", "", ")"); break;
1352 case EOpPostIncrement: outputTriplet(visit, "(", "", "++)"); break;
1353 case EOpPostDecrement: outputTriplet(visit, "(", "", "--)"); break;
1354 case EOpPreIncrement: outputTriplet(visit, "(++", "", ")"); break;
1355 case EOpPreDecrement: outputTriplet(visit, "(--", "", ")"); break;
1356 case EOpConvIntToBool:
1357 case EOpConvFloatToBool:
1358 switch (node->getOperand()->getType().getNominalSize())
1360 case 1: outputTriplet(visit, "bool(", "", ")"); break;
1361 case 2: outputTriplet(visit, "bool2(", "", ")"); break;
1362 case 3: outputTriplet(visit, "bool3(", "", ")"); break;
1363 case 4: outputTriplet(visit, "bool4(", "", ")"); break;
1364 default: UNREACHABLE();
1367 case EOpConvBoolToFloat:
1368 case EOpConvIntToFloat:
1369 switch (node->getOperand()->getType().getNominalSize())
1371 case 1: outputTriplet(visit, "float(", "", ")"); break;
1372 case 2: outputTriplet(visit, "float2(", "", ")"); break;
1373 case 3: outputTriplet(visit, "float3(", "", ")"); break;
1374 case 4: outputTriplet(visit, "float4(", "", ")"); break;
1375 default: UNREACHABLE();
1378 case EOpConvFloatToInt:
1379 case EOpConvBoolToInt:
1380 switch (node->getOperand()->getType().getNominalSize())
1382 case 1: outputTriplet(visit, "int(", "", ")"); break;
1383 case 2: outputTriplet(visit, "int2(", "", ")"); break;
1384 case 3: outputTriplet(visit, "int3(", "", ")"); break;
1385 case 4: outputTriplet(visit, "int4(", "", ")"); break;
1386 default: UNREACHABLE();
1389 case EOpRadians: outputTriplet(visit, "radians(", "", ")"); break;
1390 case EOpDegrees: outputTriplet(visit, "degrees(", "", ")"); break;
1391 case EOpSin: outputTriplet(visit, "sin(", "", ")"); break;
1392 case EOpCos: outputTriplet(visit, "cos(", "", ")"); break;
1393 case EOpTan: outputTriplet(visit, "tan(", "", ")"); break;
1394 case EOpAsin: outputTriplet(visit, "asin(", "", ")"); break;
1395 case EOpAcos: outputTriplet(visit, "acos(", "", ")"); break;
1396 case EOpAtan: outputTriplet(visit, "atan(", "", ")"); break;
1397 case EOpExp: outputTriplet(visit, "exp(", "", ")"); break;
1398 case EOpLog: outputTriplet(visit, "log(", "", ")"); break;
1399 case EOpExp2: outputTriplet(visit, "exp2(", "", ")"); break;
1400 case EOpLog2: outputTriplet(visit, "log2(", "", ")"); break;
1401 case EOpSqrt: outputTriplet(visit, "sqrt(", "", ")"); break;
1402 case EOpInverseSqrt: outputTriplet(visit, "rsqrt(", "", ")"); break;
1403 case EOpAbs: outputTriplet(visit, "abs(", "", ")"); break;
1404 case EOpSign: outputTriplet(visit, "sign(", "", ")"); break;
1405 case EOpFloor: outputTriplet(visit, "floor(", "", ")"); break;
1406 case EOpCeil: outputTriplet(visit, "ceil(", "", ")"); break;
1407 case EOpFract: outputTriplet(visit, "frac(", "", ")"); break;
1408 case EOpLength: outputTriplet(visit, "length(", "", ")"); break;
1409 case EOpNormalize: outputTriplet(visit, "normalize(", "", ")"); break;
1411 if(mInsideDiscontinuousLoop || mOutputLod0Function)
1413 outputTriplet(visit, "(", "", ", 0.0)");
1417 outputTriplet(visit, "ddx(", "", ")");
1421 if(mInsideDiscontinuousLoop || mOutputLod0Function)
1423 outputTriplet(visit, "(", "", ", 0.0)");
1427 outputTriplet(visit, "ddy(", "", ")");
1431 if(mInsideDiscontinuousLoop || mOutputLod0Function)
1433 outputTriplet(visit, "(", "", ", 0.0)");
1437 outputTriplet(visit, "fwidth(", "", ")");
1440 case EOpAny: outputTriplet(visit, "any(", "", ")"); break;
1441 case EOpAll: outputTriplet(visit, "all(", "", ")"); break;
1442 default: UNREACHABLE();
1448 bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
1450 TInfoSinkBase &out = mBody;
1452 switch (node->getOp())
1456 if (mInsideFunction)
1458 outputLineDirective(node->getLine().first_line);
1463 if (mScopeBracket.size() < mScopeDepth)
1465 mScopeBracket.push_back(0); // New scope level
1469 mScopeBracket[mScopeDepth - 1]++; // New scope at existing level
1473 for (TIntermSequence::iterator sit = node->getSequence().begin(); sit != node->getSequence().end(); sit++)
1475 outputLineDirective((*sit)->getLine().first_line);
1477 traverseStatements(*sit);
1482 if (mInsideFunction)
1484 outputLineDirective(node->getLine().last_line);
1492 case EOpDeclaration:
1493 if (visit == PreVisit)
1495 TIntermSequence &sequence = node->getSequence();
1496 TIntermTyped *variable = sequence[0]->getAsTyped();
1498 if (variable && (variable->getQualifier() == EvqTemporary || variable->getQualifier() == EvqGlobal))
1500 if (variable->getType().getStruct())
1502 addConstructor(variable->getType(), scopedStruct(variable->getType().getStruct()->name()), NULL);
1505 if (!variable->getAsSymbolNode() || variable->getAsSymbolNode()->getSymbol() != "") // Variable declaration
1507 if (!mInsideFunction)
1512 out << typeString(variable->getType()) + " ";
1514 for (TIntermSequence::iterator sit = sequence.begin(); sit != sequence.end(); sit++)
1516 TIntermSymbol *symbol = (*sit)->getAsSymbolNode();
1520 symbol->traverse(this);
1521 out << arrayString(symbol->getType());
1522 out << " = " + initializer(symbol->getType());
1526 (*sit)->traverse(this);
1529 if (*sit != sequence.back())
1535 else if (variable->getAsSymbolNode() && variable->getAsSymbolNode()->getSymbol() == "") // Type (struct) declaration
1537 // Already added to constructor map
1541 else if (variable && (variable->getQualifier() == EvqVaryingOut || variable->getQualifier() == EvqInvariantVaryingOut))
1543 for (TIntermSequence::iterator sit = sequence.begin(); sit != sequence.end(); sit++)
1545 TIntermSymbol *symbol = (*sit)->getAsSymbolNode();
1549 // Vertex (output) varyings which are declared but not written to should still be declared to allow successful linking
1550 mReferencedVaryings[symbol->getSymbol()] = symbol;
1554 (*sit)->traverse(this);
1561 else if (visit == InVisit)
1567 if (visit == PreVisit)
1569 out << typeString(node->getType()) << " " << decorate(node->getName()) << (mOutputLod0Function ? "Lod0(" : "(");
1571 TIntermSequence &arguments = node->getSequence();
1573 for (unsigned int i = 0; i < arguments.size(); i++)
1575 TIntermSymbol *symbol = arguments[i]->getAsSymbolNode();
1579 out << argumentString(symbol);
1581 if (i < arguments.size() - 1)
1591 // Also prototype the Lod0 variant if needed
1592 if (mContainsLoopDiscontinuity && !mOutputLod0Function)
1594 mOutputLod0Function = true;
1595 node->traverse(this);
1596 mOutputLod0Function = false;
1602 case EOpComma: outputTriplet(visit, "(", ", ", ")"); break;
1605 TString name = TFunction::unmangleName(node->getName());
1607 out << typeString(node->getType()) << " ";
1615 out << decorate(name) << (mOutputLod0Function ? "Lod0(" : "(");
1618 TIntermSequence &sequence = node->getSequence();
1619 TIntermSequence &arguments = sequence[0]->getAsAggregate()->getSequence();
1621 for (unsigned int i = 0; i < arguments.size(); i++)
1623 TIntermSymbol *symbol = arguments[i]->getAsSymbolNode();
1627 if (symbol->getType().getStruct())
1629 addConstructor(symbol->getType(), scopedStruct(symbol->getType().getStruct()->name()), NULL);
1632 out << argumentString(symbol);
1634 if (i < arguments.size() - 1)
1645 if (sequence.size() > 1)
1647 mInsideFunction = true;
1648 sequence[1]->traverse(this);
1649 mInsideFunction = false;
1654 if (mContainsLoopDiscontinuity && !mOutputLod0Function)
1658 mOutputLod0Function = true;
1659 node->traverse(this);
1660 mOutputLod0Function = false;
1667 case EOpFunctionCall:
1669 TString name = TFunction::unmangleName(node->getName());
1670 bool lod0 = mInsideDiscontinuousLoop || mOutputLod0Function;
1672 if (node->isUserDefined())
1674 out << decorate(name) << (lod0 ? "Lod0(" : "(");
1678 if (name == "texture2D")
1682 if (node->getSequence().size() == 2)
1684 mUsesTexture2D = true;
1686 else if (node->getSequence().size() == 3)
1688 mUsesTexture2D_bias = true;
1692 out << "gl_texture2D(";
1696 if (node->getSequence().size() == 2)
1698 mUsesTexture2DLod0 = true;
1700 else if (node->getSequence().size() == 3)
1702 mUsesTexture2DLod0_bias = true;
1706 out << "gl_texture2DLod0(";
1709 else if (name == "texture2DProj")
1713 if (node->getSequence().size() == 2)
1715 mUsesTexture2DProj = true;
1717 else if (node->getSequence().size() == 3)
1719 mUsesTexture2DProj_bias = true;
1723 out << "gl_texture2DProj(";
1727 if (node->getSequence().size() == 2)
1729 mUsesTexture2DProjLod0 = true;
1731 else if (node->getSequence().size() == 3)
1733 mUsesTexture2DProjLod0_bias = true;
1737 out << "gl_texture2DProjLod0(";
1740 else if (name == "textureCube")
1744 if (node->getSequence().size() == 2)
1746 mUsesTextureCube = true;
1748 else if (node->getSequence().size() == 3)
1750 mUsesTextureCube_bias = true;
1754 out << "gl_textureCube(";
1758 if (node->getSequence().size() == 2)
1760 mUsesTextureCubeLod0 = true;
1762 else if (node->getSequence().size() == 3)
1764 mUsesTextureCubeLod0_bias = true;
1768 out << "gl_textureCubeLod0(";
1771 else if (name == "texture2DLod")
1773 if (node->getSequence().size() == 3)
1775 mUsesTexture2DLod = true;
1779 out << "gl_texture2DLod(";
1781 else if (name == "texture2DProjLod")
1783 if (node->getSequence().size() == 3)
1785 mUsesTexture2DProjLod = true;
1789 out << "gl_texture2DProjLod(";
1791 else if (name == "textureCubeLod")
1793 if (node->getSequence().size() == 3)
1795 mUsesTextureCubeLod = true;
1799 out << "gl_textureCubeLod(";
1804 TIntermSequence &arguments = node->getSequence();
1806 for (TIntermSequence::iterator arg = arguments.begin(); arg != arguments.end(); arg++)
1808 if (mOutputType == SH_HLSL11_OUTPUT && IsSampler((*arg)->getAsTyped()->getBasicType()))
1811 (*arg)->traverse(this);
1812 out << ", sampler_";
1815 (*arg)->traverse(this);
1817 if (arg < arguments.end() - 1)
1828 case EOpParameters: outputTriplet(visit, "(", ", ", ")\n{\n"); break;
1829 case EOpConstructFloat:
1830 addConstructor(node->getType(), "vec1", &node->getSequence());
1831 outputTriplet(visit, "vec1(", "", ")");
1833 case EOpConstructVec2:
1834 addConstructor(node->getType(), "vec2", &node->getSequence());
1835 outputTriplet(visit, "vec2(", ", ", ")");
1837 case EOpConstructVec3:
1838 addConstructor(node->getType(), "vec3", &node->getSequence());
1839 outputTriplet(visit, "vec3(", ", ", ")");
1841 case EOpConstructVec4:
1842 addConstructor(node->getType(), "vec4", &node->getSequence());
1843 outputTriplet(visit, "vec4(", ", ", ")");
1845 case EOpConstructBool:
1846 addConstructor(node->getType(), "bvec1", &node->getSequence());
1847 outputTriplet(visit, "bvec1(", "", ")");
1849 case EOpConstructBVec2:
1850 addConstructor(node->getType(), "bvec2", &node->getSequence());
1851 outputTriplet(visit, "bvec2(", ", ", ")");
1853 case EOpConstructBVec3:
1854 addConstructor(node->getType(), "bvec3", &node->getSequence());
1855 outputTriplet(visit, "bvec3(", ", ", ")");
1857 case EOpConstructBVec4:
1858 addConstructor(node->getType(), "bvec4", &node->getSequence());
1859 outputTriplet(visit, "bvec4(", ", ", ")");
1861 case EOpConstructInt:
1862 addConstructor(node->getType(), "ivec1", &node->getSequence());
1863 outputTriplet(visit, "ivec1(", "", ")");
1865 case EOpConstructIVec2:
1866 addConstructor(node->getType(), "ivec2", &node->getSequence());
1867 outputTriplet(visit, "ivec2(", ", ", ")");
1869 case EOpConstructIVec3:
1870 addConstructor(node->getType(), "ivec3", &node->getSequence());
1871 outputTriplet(visit, "ivec3(", ", ", ")");
1873 case EOpConstructIVec4:
1874 addConstructor(node->getType(), "ivec4", &node->getSequence());
1875 outputTriplet(visit, "ivec4(", ", ", ")");
1877 case EOpConstructMat2:
1878 addConstructor(node->getType(), "mat2", &node->getSequence());
1879 outputTriplet(visit, "mat2(", ", ", ")");
1881 case EOpConstructMat3:
1882 addConstructor(node->getType(), "mat3", &node->getSequence());
1883 outputTriplet(visit, "mat3(", ", ", ")");
1885 case EOpConstructMat4:
1886 addConstructor(node->getType(), "mat4", &node->getSequence());
1887 outputTriplet(visit, "mat4(", ", ", ")");
1889 case EOpConstructStruct:
1890 addConstructor(node->getType(), scopedStruct(node->getType().getStruct()->name()), &node->getSequence());
1891 outputTriplet(visit, structLookup(node->getType().getStruct()->name()) + "_ctor(", ", ", ")");
1893 case EOpLessThan: outputTriplet(visit, "(", " < ", ")"); break;
1894 case EOpGreaterThan: outputTriplet(visit, "(", " > ", ")"); break;
1895 case EOpLessThanEqual: outputTriplet(visit, "(", " <= ", ")"); break;
1896 case EOpGreaterThanEqual: outputTriplet(visit, "(", " >= ", ")"); break;
1897 case EOpVectorEqual: outputTriplet(visit, "(", " == ", ")"); break;
1898 case EOpVectorNotEqual: outputTriplet(visit, "(", " != ", ")"); break;
1901 // We need to look at the number of components in both arguments
1902 switch (node->getSequence()[0]->getAsTyped()->getNominalSize() * 10
1903 + node->getSequence()[1]->getAsTyped()->getNominalSize())
1905 case 11: mUsesMod1 = true; break;
1906 case 22: mUsesMod2v = true; break;
1907 case 21: mUsesMod2f = true; break;
1908 case 33: mUsesMod3v = true; break;
1909 case 31: mUsesMod3f = true; break;
1910 case 44: mUsesMod4v = true; break;
1911 case 41: mUsesMod4f = true; break;
1912 default: UNREACHABLE();
1915 outputTriplet(visit, "mod(", ", ", ")");
1918 case EOpPow: outputTriplet(visit, "pow(", ", ", ")"); break;
1920 ASSERT(node->getSequence().size() == 2); // atan(x) is a unary operator
1921 switch (node->getSequence()[0]->getAsTyped()->getNominalSize())
1923 case 1: mUsesAtan2_1 = true; break;
1924 case 2: mUsesAtan2_2 = true; break;
1925 case 3: mUsesAtan2_3 = true; break;
1926 case 4: mUsesAtan2_4 = true; break;
1927 default: UNREACHABLE();
1929 outputTriplet(visit, "atanyx(", ", ", ")");
1931 case EOpMin: outputTriplet(visit, "min(", ", ", ")"); break;
1932 case EOpMax: outputTriplet(visit, "max(", ", ", ")"); break;
1933 case EOpClamp: outputTriplet(visit, "clamp(", ", ", ")"); break;
1934 case EOpMix: outputTriplet(visit, "lerp(", ", ", ")"); break;
1935 case EOpStep: outputTriplet(visit, "step(", ", ", ")"); break;
1936 case EOpSmoothStep: outputTriplet(visit, "smoothstep(", ", ", ")"); break;
1937 case EOpDistance: outputTriplet(visit, "distance(", ", ", ")"); break;
1938 case EOpDot: outputTriplet(visit, "dot(", ", ", ")"); break;
1939 case EOpCross: outputTriplet(visit, "cross(", ", ", ")"); break;
1940 case EOpFaceForward:
1942 switch (node->getSequence()[0]->getAsTyped()->getNominalSize()) // Number of components in the first argument
1944 case 1: mUsesFaceforward1 = true; break;
1945 case 2: mUsesFaceforward2 = true; break;
1946 case 3: mUsesFaceforward3 = true; break;
1947 case 4: mUsesFaceforward4 = true; break;
1948 default: UNREACHABLE();
1951 outputTriplet(visit, "faceforward(", ", ", ")");
1954 case EOpReflect: outputTriplet(visit, "reflect(", ", ", ")"); break;
1955 case EOpRefract: outputTriplet(visit, "refract(", ", ", ")"); break;
1956 case EOpMul: outputTriplet(visit, "(", " * ", ")"); break;
1957 default: UNREACHABLE();
1963 bool OutputHLSL::visitSelection(Visit visit, TIntermSelection *node)
1965 TInfoSinkBase &out = mBody;
1967 if (node->usesTernaryOperator())
1969 out << "s" << mUnfoldShortCircuit->getNextTemporaryIndex();
1971 else // if/else statement
1973 mUnfoldShortCircuit->traverse(node->getCondition());
1977 node->getCondition()->traverse(this);
1981 outputLineDirective(node->getLine().first_line);
1984 bool discard = false;
1986 if (node->getTrueBlock())
1988 traverseStatements(node->getTrueBlock());
1990 // Detect true discard
1991 discard = (discard || FindDiscard::search(node->getTrueBlock()));
1994 outputLineDirective(node->getLine().first_line);
1997 if (node->getFalseBlock())
2001 outputLineDirective(node->getFalseBlock()->getLine().first_line);
2004 outputLineDirective(node->getFalseBlock()->getLine().first_line);
2005 traverseStatements(node->getFalseBlock());
2007 outputLineDirective(node->getFalseBlock()->getLine().first_line);
2010 // Detect false discard
2011 discard = (discard || FindDiscard::search(node->getFalseBlock()));
2014 // ANGLE issue 486: Detect problematic conditional discard
2015 if (discard && FindSideEffectRewriting::search(node))
2017 mUsesDiscardRewriting = true;
2024 void OutputHLSL::visitConstantUnion(TIntermConstantUnion *node)
2026 writeConstantUnion(node->getType(), node->getUnionArrayPointer());
2029 bool OutputHLSL::visitLoop(Visit visit, TIntermLoop *node)
2031 bool wasDiscontinuous = mInsideDiscontinuousLoop;
2033 if (mContainsLoopDiscontinuity && !mInsideDiscontinuousLoop)
2035 mInsideDiscontinuousLoop = containsLoopDiscontinuity(node);
2038 if (mOutputType == SH_HLSL9_OUTPUT)
2040 if (handleExcessiveLoop(node))
2046 TInfoSinkBase &out = mBody;
2048 if (node->getType() == ELoopDoWhile)
2052 outputLineDirective(node->getLine().first_line);
2059 if (node->getInit())
2061 node->getInit()->traverse(this);
2066 if (node->getCondition())
2068 node->getCondition()->traverse(this);
2073 if (node->getExpression())
2075 node->getExpression()->traverse(this);
2080 outputLineDirective(node->getLine().first_line);
2084 if (node->getBody())
2086 traverseStatements(node->getBody());
2089 outputLineDirective(node->getLine().first_line);
2092 if (node->getType() == ELoopDoWhile)
2094 outputLineDirective(node->getCondition()->getLine().first_line);
2097 node->getCondition()->traverse(this);
2104 mInsideDiscontinuousLoop = wasDiscontinuous;
2109 bool OutputHLSL::visitBranch(Visit visit, TIntermBranch *node)
2111 TInfoSinkBase &out = mBody;
2113 switch (node->getFlowOp())
2116 outputTriplet(visit, "discard;\n", "", "");
2119 if (visit == PreVisit)
2121 if (mExcessiveLoopIndex)
2124 mExcessiveLoopIndex->traverse(this);
2125 out << " = true; break;}\n";
2133 case EOpContinue: outputTriplet(visit, "continue;\n", "", ""); break;
2135 if (visit == PreVisit)
2137 if (node->getExpression())
2146 else if (visit == PostVisit)
2148 if (node->getExpression())
2154 default: UNREACHABLE();
2160 void OutputHLSL::traverseStatements(TIntermNode *node)
2162 if (isSingleStatement(node))
2164 mUnfoldShortCircuit->traverse(node);
2167 node->traverse(this);
2170 bool OutputHLSL::isSingleStatement(TIntermNode *node)
2172 TIntermAggregate *aggregate = node->getAsAggregate();
2176 if (aggregate->getOp() == EOpSequence)
2182 for (TIntermSequence::iterator sit = aggregate->getSequence().begin(); sit != aggregate->getSequence().end(); sit++)
2184 if (!isSingleStatement(*sit))
2197 // Handle loops with more than 254 iterations (unsupported by D3D9) by splitting them
2198 // (The D3D documentation says 255 iterations, but the compiler complains at anything more than 254).
2199 bool OutputHLSL::handleExcessiveLoop(TIntermLoop *node)
2201 const int MAX_LOOP_ITERATIONS = 254;
2202 TInfoSinkBase &out = mBody;
2204 // Parse loops of the form:
2205 // for(int index = initial; index [comparator] limit; index += increment)
2206 TIntermSymbol *index = NULL;
2207 TOperator comparator = EOpNull;
2212 // Parse index name and intial value
2213 if (node->getInit())
2215 TIntermAggregate *init = node->getInit()->getAsAggregate();
2219 TIntermSequence &sequence = init->getSequence();
2220 TIntermTyped *variable = sequence[0]->getAsTyped();
2222 if (variable && variable->getQualifier() == EvqTemporary)
2224 TIntermBinary *assign = variable->getAsBinaryNode();
2226 if (assign->getOp() == EOpInitialize)
2228 TIntermSymbol *symbol = assign->getLeft()->getAsSymbolNode();
2229 TIntermConstantUnion *constant = assign->getRight()->getAsConstantUnion();
2231 if (symbol && constant)
2233 if (constant->getBasicType() == EbtInt && constant->getNominalSize() == 1)
2236 initial = constant->getIConst(0);
2244 // Parse comparator and limit value
2245 if (index != NULL && node->getCondition())
2247 TIntermBinary *test = node->getCondition()->getAsBinaryNode();
2249 if (test && test->getLeft()->getAsSymbolNode()->getId() == index->getId())
2251 TIntermConstantUnion *constant = test->getRight()->getAsConstantUnion();
2255 if (constant->getBasicType() == EbtInt && constant->getNominalSize() == 1)
2257 comparator = test->getOp();
2258 limit = constant->getIConst(0);
2265 if (index != NULL && comparator != EOpNull && node->getExpression())
2267 TIntermBinary *binaryTerminal = node->getExpression()->getAsBinaryNode();
2268 TIntermUnary *unaryTerminal = node->getExpression()->getAsUnaryNode();
2272 TOperator op = binaryTerminal->getOp();
2273 TIntermConstantUnion *constant = binaryTerminal->getRight()->getAsConstantUnion();
2277 if (constant->getBasicType() == EbtInt && constant->getNominalSize() == 1)
2279 int value = constant->getIConst(0);
2283 case EOpAddAssign: increment = value; break;
2284 case EOpSubAssign: increment = -value; break;
2285 default: UNIMPLEMENTED();
2290 else if (unaryTerminal)
2292 TOperator op = unaryTerminal->getOp();
2296 case EOpPostIncrement: increment = 1; break;
2297 case EOpPostDecrement: increment = -1; break;
2298 case EOpPreIncrement: increment = 1; break;
2299 case EOpPreDecrement: increment = -1; break;
2300 default: UNIMPLEMENTED();
2305 if (index != NULL && comparator != EOpNull && increment != 0)
2307 if (comparator == EOpLessThanEqual)
2309 comparator = EOpLessThan;
2313 if (comparator == EOpLessThan)
2315 int iterations = (limit - initial) / increment;
2317 if (iterations <= MAX_LOOP_ITERATIONS)
2319 return false; // Not an excessive loop
2322 TIntermSymbol *restoreIndex = mExcessiveLoopIndex;
2323 mExcessiveLoopIndex = index;
2326 index->traverse(this);
2329 index->traverse(this);
2330 out << " = false;\n";
2332 bool firstLoopFragment = true;
2334 while (iterations > 0)
2336 int clampedLimit = initial + increment * std::min(MAX_LOOP_ITERATIONS, iterations);
2338 if (!firstLoopFragment)
2340 out << "if (!Break";
2341 index->traverse(this);
2345 if (iterations <= MAX_LOOP_ITERATIONS) // Last loop fragment
2347 mExcessiveLoopIndex = NULL; // Stops setting the Break flag
2350 // for(int index = initial; index < clampedLimit; index += increment)
2353 index->traverse(this);
2358 index->traverse(this);
2360 out << clampedLimit;
2363 index->traverse(this);
2368 outputLineDirective(node->getLine().first_line);
2371 if (node->getBody())
2373 node->getBody()->traverse(this);
2376 outputLineDirective(node->getLine().first_line);
2379 if (!firstLoopFragment)
2384 firstLoopFragment = false;
2386 initial += MAX_LOOP_ITERATIONS * increment;
2387 iterations -= MAX_LOOP_ITERATIONS;
2392 mExcessiveLoopIndex = restoreIndex;
2396 else UNIMPLEMENTED();
2399 return false; // Not handled as an excessive loop
2402 void OutputHLSL::outputTriplet(Visit visit, const TString &preString, const TString &inString, const TString &postString)
2404 TInfoSinkBase &out = mBody;
2406 if (visit == PreVisit)
2410 else if (visit == InVisit)
2414 else if (visit == PostVisit)
2420 void OutputHLSL::outputLineDirective(int line)
2422 if ((mContext.compileOptions & SH_LINE_DIRECTIVES) && (line > 0))
2425 mBody << "#line " << line;
2427 if (mContext.sourcePath)
2429 mBody << " \"" << mContext.sourcePath << "\"";
2436 TString OutputHLSL::argumentString(const TIntermSymbol *symbol)
2438 TQualifier qualifier = symbol->getQualifier();
2439 const TType &type = symbol->getType();
2440 TString name = symbol->getSymbol();
2442 if (name.empty()) // HLSL demands named arguments, also for prototypes
2444 name = "x" + str(mUniqueIndex++);
2448 name = decorate(name);
2451 if (mOutputType == SH_HLSL11_OUTPUT && IsSampler(type.getBasicType()))
2453 return qualifierString(qualifier) + " " + textureString(type) + " texture_" + name + arrayString(type) + ", " +
2454 qualifierString(qualifier) + " SamplerState sampler_" + name + arrayString(type);
2457 return qualifierString(qualifier) + " " + typeString(type) + " " + name + arrayString(type);
2460 TString OutputHLSL::qualifierString(TQualifier qualifier)
2464 case EvqIn: return "in";
2465 case EvqOut: return "out";
2466 case EvqInOut: return "inout";
2467 case EvqConstReadOnly: return "const";
2468 default: UNREACHABLE();
2474 TString OutputHLSL::typeString(const TType &type)
2476 if (type.getBasicType() == EbtStruct)
2478 const TString& typeName = type.getStruct()->name();
2481 return structLookup(typeName);
2483 else // Nameless structure, define in place
2485 const TFieldList &fields = type.getStruct()->fields();
2487 TString string = "struct\n"
2490 for (unsigned int i = 0; i < fields.size(); i++)
2492 const TField *field = fields[i];
2494 string += " " + typeString(*field->type()) + " " + decorate(field->name()) + arrayString(*field->type()) + ";\n";
2502 else if (type.isMatrix())
2504 switch (type.getNominalSize())
2506 case 2: return "float2x2";
2507 case 3: return "float3x3";
2508 case 4: return "float4x4";
2513 switch (type.getBasicType())
2516 switch (type.getNominalSize())
2518 case 1: return "float";
2519 case 2: return "float2";
2520 case 3: return "float3";
2521 case 4: return "float4";
2524 switch (type.getNominalSize())
2526 case 1: return "int";
2527 case 2: return "int2";
2528 case 3: return "int3";
2529 case 4: return "int4";
2532 switch (type.getNominalSize())
2534 case 1: return "bool";
2535 case 2: return "bool2";
2536 case 3: return "bool3";
2537 case 4: return "bool4";
2543 case EbtSamplerCube:
2544 return "samplerCUBE";
2545 case EbtSamplerExternalOES:
2553 return "<unknown type>";
2556 TString OutputHLSL::textureString(const TType &type)
2558 switch (type.getBasicType())
2562 case EbtSamplerCube:
2563 return "TextureCube";
2564 case EbtSamplerExternalOES:
2571 return "<unknown texture type>";
2574 TString OutputHLSL::arrayString(const TType &type)
2576 if (!type.isArray())
2581 return "[" + str(type.getArraySize()) + "]";
2584 TString OutputHLSL::initializer(const TType &type)
2588 size_t size = type.getObjectSize();
2589 for (size_t component = 0; component < size; component++)
2593 if (component + 1 < size)
2599 return "{" + string + "}";
2602 void OutputHLSL::addConstructor(const TType &type, const TString &name, const TIntermSequence *parameters)
2606 return; // Nameless structures don't have constructors
2609 if (type.getStruct() && mStructNames.find(decorate(name)) != mStructNames.end())
2611 return; // Already added
2614 TType ctorType = type;
2615 ctorType.clearArrayness();
2616 ctorType.setPrecision(EbpHigh);
2617 ctorType.setQualifier(EvqTemporary);
2619 TString ctorName = type.getStruct() ? decorate(name) : name;
2621 typedef std::vector<TType> ParameterArray;
2622 ParameterArray ctorParameters;
2624 if (type.getStruct())
2626 mStructNames.insert(decorate(name));
2629 structure += "struct " + decorate(name) + "\n"
2632 const TFieldList &fields = type.getStruct()->fields();
2634 for (unsigned int i = 0; i < fields.size(); i++)
2636 const TField *field = fields[i];
2638 structure += " " + typeString(*field->type()) + " " + decorateField(field->name(), type) + arrayString(*field->type()) + ";\n";
2641 structure += "};\n";
2643 if (std::find(mStructDeclarations.begin(), mStructDeclarations.end(), structure) == mStructDeclarations.end())
2645 mStructDeclarations.push_back(structure);
2648 for (unsigned int i = 0; i < fields.size(); i++)
2650 ctorParameters.push_back(*fields[i]->type());
2653 else if (parameters)
2655 for (TIntermSequence::const_iterator parameter = parameters->begin(); parameter != parameters->end(); parameter++)
2657 ctorParameters.push_back((*parameter)->getAsTyped()->getType());
2662 TString constructor;
2664 if (ctorType.getStruct())
2666 constructor += ctorName + " " + ctorName + "_ctor(";
2668 else // Built-in type
2670 constructor += typeString(ctorType) + " " + ctorName + "(";
2673 for (unsigned int parameter = 0; parameter < ctorParameters.size(); parameter++)
2675 const TType &type = ctorParameters[parameter];
2677 constructor += typeString(type) + " x" + str(parameter) + arrayString(type);
2679 if (parameter < ctorParameters.size() - 1)
2681 constructor += ", ";
2685 constructor += ")\n"
2688 if (ctorType.getStruct())
2690 constructor += " " + ctorName + " structure = {";
2694 constructor += " return " + typeString(ctorType) + "(";
2697 if (ctorType.isMatrix() && ctorParameters.size() == 1)
2699 int dim = ctorType.getNominalSize();
2700 const TType ¶meter = ctorParameters[0];
2702 if (parameter.isScalar())
2704 for (int row = 0; row < dim; row++)
2706 for (int col = 0; col < dim; col++)
2708 constructor += TString((row == col) ? "x0" : "0.0");
2710 if (row < dim - 1 || col < dim - 1)
2712 constructor += ", ";
2717 else if (parameter.isMatrix())
2719 for (int row = 0; row < dim; row++)
2721 for (int col = 0; col < dim; col++)
2723 if (row < parameter.getNominalSize() && col < parameter.getNominalSize())
2725 constructor += TString("x0") + "[" + str(row) + "]" + "[" + str(col) + "]";
2729 constructor += TString((row == col) ? "1.0" : "0.0");
2732 if (row < dim - 1 || col < dim - 1)
2734 constructor += ", ";
2743 size_t remainingComponents = ctorType.getObjectSize();
2744 size_t parameterIndex = 0;
2746 while (remainingComponents > 0)
2748 const TType ¶meter = ctorParameters[parameterIndex];
2749 const size_t parameterSize = parameter.getObjectSize();
2750 bool moreParameters = parameterIndex + 1 < ctorParameters.size();
2752 constructor += "x" + str(parameterIndex);
2754 if (parameter.isScalar())
2756 ASSERT(parameterSize <= remainingComponents);
2757 remainingComponents -= parameterSize;
2759 else if (parameter.isVector())
2761 if (remainingComponents == parameterSize || moreParameters)
2763 ASSERT(parameterSize <= remainingComponents);
2764 remainingComponents -= parameterSize;
2766 else if (remainingComponents < static_cast<size_t>(parameter.getNominalSize()))
2768 switch (remainingComponents)
2770 case 1: constructor += ".x"; break;
2771 case 2: constructor += ".xy"; break;
2772 case 3: constructor += ".xyz"; break;
2773 case 4: constructor += ".xyzw"; break;
2774 default: UNREACHABLE();
2777 remainingComponents = 0;
2781 else if (parameter.isMatrix() || parameter.getStruct())
2783 ASSERT(remainingComponents == parameterSize || moreParameters);
2784 ASSERT(parameterSize <= remainingComponents);
2786 remainingComponents -= parameterSize;
2795 if (remainingComponents)
2797 constructor += ", ";
2802 if (ctorType.getStruct())
2804 constructor += "};\n"
2805 " return structure;\n"
2810 constructor += ");\n"
2814 mConstructors.insert(constructor);
2817 const ConstantUnion *OutputHLSL::writeConstantUnion(const TType &type, const ConstantUnion *constUnion)
2819 TInfoSinkBase &out = mBody;
2821 if (type.getBasicType() == EbtStruct)
2823 out << structLookup(type.getStruct()->name()) + "_ctor(";
2825 const TFieldList &fields = type.getStruct()->fields();
2827 for (size_t i = 0; i < fields.size(); i++)
2829 const TType *fieldType = fields[i]->type();
2831 constUnion = writeConstantUnion(*fieldType, constUnion);
2833 if (i != fields.size() - 1)
2843 size_t size = type.getObjectSize();
2844 bool writeType = size > 1;
2848 out << typeString(type) << "(";
2851 for (size_t i = 0; i < size; i++, constUnion++)
2853 switch (constUnion->getType())
2855 case EbtFloat: out << std::min(FLT_MAX, std::max(-FLT_MAX, constUnion->getFConst())); break;
2856 case EbtInt: out << constUnion->getIConst(); break;
2857 case EbtBool: out << constUnion->getBConst(); break;
2858 default: UNREACHABLE();
2876 TString OutputHLSL::scopeString(unsigned int depthLimit)
2880 for (unsigned int i = 0; i < mScopeBracket.size() && i < depthLimit; i++)
2882 string += "_" + str(i);
2888 TString OutputHLSL::scopedStruct(const TString &typeName)
2895 return typeName + scopeString(mScopeDepth);
2898 TString OutputHLSL::structLookup(const TString &typeName)
2900 for (int depth = mScopeDepth; depth >= 0; depth--)
2902 TString scopedName = decorate(typeName + scopeString(depth));
2904 for (StructNames::iterator structName = mStructNames.begin(); structName != mStructNames.end(); structName++)
2906 if (*structName == scopedName)
2913 UNREACHABLE(); // Should have found a matching constructor
2918 TString OutputHLSL::decorate(const TString &string)
2920 if (string.compare(0, 3, "gl_") != 0 && string.compare(0, 3, "dx_") != 0)
2922 return "_" + string;
2928 TString OutputHLSL::decorateUniform(const TString &string, const TType &type)
2930 if (type.getBasicType() == EbtSamplerExternalOES)
2932 return "ex_" + string;
2935 return decorate(string);
2938 TString OutputHLSL::decorateField(const TString &string, const TType &structure)
2940 if (structure.getStruct()->name().compare(0, 3, "gl_") != 0)
2942 return decorate(string);
2948 TString OutputHLSL::registerString(TIntermSymbol *operand)
2950 ASSERT(operand->getQualifier() == EvqUniform);
2952 if (IsSampler(operand->getBasicType()))
2954 return "s" + str(samplerRegister(operand));
2957 return "c" + str(uniformRegister(operand));
2960 int OutputHLSL::samplerRegister(TIntermSymbol *sampler)
2962 const TType &type = sampler->getType();
2963 ASSERT(IsSampler(type.getBasicType()));
2965 int index = mSamplerRegister;
2966 mSamplerRegister += sampler->totalRegisterCount();
2968 declareUniform(type, sampler->getSymbol(), index);
2973 int OutputHLSL::uniformRegister(TIntermSymbol *uniform)
2975 const TType &type = uniform->getType();
2976 ASSERT(!IsSampler(type.getBasicType()));
2978 int index = mUniformRegister;
2979 mUniformRegister += uniform->totalRegisterCount();
2981 declareUniform(type, uniform->getSymbol(), index);
2986 void OutputHLSL::declareUniform(const TType &type, const TString &name, int index)
2988 TStructure *structure = type.getStruct();
2992 mActiveUniforms.push_back(Uniform(glVariableType(type), glVariablePrecision(type), name.c_str(), type.getArraySize(), index));
2996 const TFieldList &fields = structure->fields();
3000 int elementIndex = index;
3002 for (int i = 0; i < type.getArraySize(); i++)
3004 for (size_t j = 0; j < fields.size(); j++)
3006 const TType &fieldType = *fields[j]->type();
3007 const TString uniformName = name + "[" + str(i) + "]." + fields[j]->name();
3008 declareUniform(fieldType, uniformName, elementIndex);
3009 elementIndex += fieldType.totalRegisterCount();
3015 int fieldIndex = index;
3017 for (size_t i = 0; i < fields.size(); i++)
3019 const TType &fieldType = *fields[i]->type();
3020 const TString uniformName = name + "." + fields[i]->name();
3021 declareUniform(fieldType, uniformName, fieldIndex);
3022 fieldIndex += fieldType.totalRegisterCount();
3028 GLenum OutputHLSL::glVariableType(const TType &type)
3030 if (type.getBasicType() == EbtFloat)
3032 if (type.isScalar())
3036 else if (type.isVector())
3038 switch(type.getNominalSize())
3040 case 2: return GL_FLOAT_VEC2;
3041 case 3: return GL_FLOAT_VEC3;
3042 case 4: return GL_FLOAT_VEC4;
3043 default: UNREACHABLE();
3046 else if (type.isMatrix())
3048 switch(type.getNominalSize())
3050 case 2: return GL_FLOAT_MAT2;
3051 case 3: return GL_FLOAT_MAT3;
3052 case 4: return GL_FLOAT_MAT4;
3053 default: UNREACHABLE();
3058 else if (type.getBasicType() == EbtInt)
3060 if (type.isScalar())
3064 else if (type.isVector())
3066 switch(type.getNominalSize())
3068 case 2: return GL_INT_VEC2;
3069 case 3: return GL_INT_VEC3;
3070 case 4: return GL_INT_VEC4;
3071 default: UNREACHABLE();
3076 else if (type.getBasicType() == EbtBool)
3078 if (type.isScalar())
3082 else if (type.isVector())
3084 switch(type.getNominalSize())
3086 case 2: return GL_BOOL_VEC2;
3087 case 3: return GL_BOOL_VEC3;
3088 case 4: return GL_BOOL_VEC4;
3089 default: UNREACHABLE();
3094 else if (type.getBasicType() == EbtSampler2D)
3096 return GL_SAMPLER_2D;
3098 else if (type.getBasicType() == EbtSamplerCube)
3100 return GL_SAMPLER_CUBE;
3107 GLenum OutputHLSL::glVariablePrecision(const TType &type)
3109 if (type.getBasicType() == EbtFloat)
3111 switch (type.getPrecision())
3113 case EbpHigh: return GL_HIGH_FLOAT;
3114 case EbpMedium: return GL_MEDIUM_FLOAT;
3115 case EbpLow: return GL_LOW_FLOAT;
3117 // Should be defined as the default precision by the parser
3118 default: UNREACHABLE();
3121 else if (type.getBasicType() == EbtInt)
3123 switch (type.getPrecision())
3125 case EbpHigh: return GL_HIGH_INT;
3126 case EbpMedium: return GL_MEDIUM_INT;
3127 case EbpLow: return GL_LOW_INT;
3129 // Should be defined as the default precision by the parser
3130 default: UNREACHABLE();
3134 // Other types (boolean, sampler) don't have a precision