daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
Nicolas Capens | b1f45b7 | 2013-12-19 17:37:19 -0500 | [diff] [blame] | 2 | // Copyright (c) 2002-2014 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 7 | #include "compiler/translator/OutputHLSL.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 8 | |
daniel@transgaming.com | 7a7003c | 2010-04-29 03:35:33 +0000 | [diff] [blame] | 9 | #include <algorithm> |
shannon.woods@transgaming.com | fff89b3 | 2013-02-28 23:20:15 +0000 | [diff] [blame] | 10 | #include <cfloat> |
| 11 | #include <stdio.h> |
daniel@transgaming.com | 7a7003c | 2010-04-29 03:35:33 +0000 | [diff] [blame] | 12 | |
Jamie Madill | 9e0478f | 2015-01-13 11:13:54 -0500 | [diff] [blame] | 13 | #include "common/angleutils.h" |
| 14 | #include "common/utilities.h" |
Olli Etuaho | 8efc5ad | 2015-03-03 17:21:10 +0200 | [diff] [blame] | 15 | #include "compiler/translator/BuiltInFunctionEmulator.h" |
Jamie Madill | 9e0478f | 2015-01-13 11:13:54 -0500 | [diff] [blame] | 16 | #include "compiler/translator/BuiltInFunctionEmulatorHLSL.h" |
| 17 | #include "compiler/translator/DetectDiscontinuity.h" |
| 18 | #include "compiler/translator/FlagStd140Structs.h" |
| 19 | #include "compiler/translator/InfoSink.h" |
| 20 | #include "compiler/translator/NodeSearch.h" |
Olli Etuaho | 2cd7a0e | 2015-02-27 13:57:32 +0200 | [diff] [blame] | 21 | #include "compiler/translator/RemoveSwitchFallThrough.h" |
Jamie Madill | 9e0478f | 2015-01-13 11:13:54 -0500 | [diff] [blame] | 22 | #include "compiler/translator/RewriteElseBlocks.h" |
| 23 | #include "compiler/translator/SearchSymbol.h" |
| 24 | #include "compiler/translator/StructureHLSL.h" |
| 25 | #include "compiler/translator/TranslatorHLSL.h" |
| 26 | #include "compiler/translator/UnfoldShortCircuit.h" |
| 27 | #include "compiler/translator/UniformHLSL.h" |
| 28 | #include "compiler/translator/UtilsHLSL.h" |
| 29 | #include "compiler/translator/blocklayout.h" |
| 30 | #include "compiler/translator/compilerdebug.h" |
| 31 | #include "compiler/translator/util.h" |
| 32 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 33 | namespace sh |
| 34 | { |
daniel@transgaming.com | 005c739 | 2010-04-15 20:45:27 +0000 | [diff] [blame] | 35 | |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 36 | TString OutputHLSL::TextureFunction::name() const |
| 37 | { |
| 38 | TString name = "gl_texture"; |
| 39 | |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 40 | if (IsSampler2D(sampler)) |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 41 | { |
| 42 | name += "2D"; |
| 43 | } |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 44 | else if (IsSampler3D(sampler)) |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 45 | { |
| 46 | name += "3D"; |
| 47 | } |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 48 | else if (IsSamplerCube(sampler)) |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 49 | { |
| 50 | name += "Cube"; |
| 51 | } |
| 52 | else UNREACHABLE(); |
| 53 | |
| 54 | if (proj) |
| 55 | { |
| 56 | name += "Proj"; |
| 57 | } |
| 58 | |
Nicolas Capens | b1f45b7 | 2013-12-19 17:37:19 -0500 | [diff] [blame] | 59 | if (offset) |
| 60 | { |
| 61 | name += "Offset"; |
| 62 | } |
| 63 | |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 64 | switch(method) |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 65 | { |
Nicolas Capens | fc01454 | 2014-02-18 14:47:13 -0500 | [diff] [blame] | 66 | case IMPLICIT: break; |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 67 | case BIAS: break; // Extra parameter makes the signature unique |
Nicolas Capens | fc01454 | 2014-02-18 14:47:13 -0500 | [diff] [blame] | 68 | case LOD: name += "Lod"; break; |
| 69 | case LOD0: name += "Lod0"; break; |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 70 | case LOD0BIAS: name += "Lod0"; break; // Extra parameter makes the signature unique |
Nicolas Capens | fc01454 | 2014-02-18 14:47:13 -0500 | [diff] [blame] | 71 | case SIZE: name += "Size"; break; |
| 72 | case FETCH: name += "Fetch"; break; |
Nicolas Capens | d11d549 | 2014-02-19 17:06:10 -0500 | [diff] [blame] | 73 | case GRAD: name += "Grad"; break; |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 74 | default: UNREACHABLE(); |
| 75 | } |
| 76 | |
| 77 | return name + "("; |
| 78 | } |
| 79 | |
| 80 | bool OutputHLSL::TextureFunction::operator<(const TextureFunction &rhs) const |
| 81 | { |
| 82 | if (sampler < rhs.sampler) return true; |
Nicolas Capens | 04296f8 | 2014-04-14 14:24:38 -0400 | [diff] [blame] | 83 | if (sampler > rhs.sampler) return false; |
| 84 | |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 85 | if (coords < rhs.coords) return true; |
Nicolas Capens | 04296f8 | 2014-04-14 14:24:38 -0400 | [diff] [blame] | 86 | if (coords > rhs.coords) return false; |
| 87 | |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 88 | if (!proj && rhs.proj) return true; |
Nicolas Capens | 04296f8 | 2014-04-14 14:24:38 -0400 | [diff] [blame] | 89 | if (proj && !rhs.proj) return false; |
| 90 | |
| 91 | if (!offset && rhs.offset) return true; |
| 92 | if (offset && !rhs.offset) return false; |
| 93 | |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 94 | if (method < rhs.method) return true; |
Nicolas Capens | 04296f8 | 2014-04-14 14:24:38 -0400 | [diff] [blame] | 95 | if (method > rhs.method) return false; |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 96 | |
| 97 | return false; |
| 98 | } |
| 99 | |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 100 | OutputHLSL::OutputHLSL(sh::GLenum shaderType, int shaderVersion, |
| 101 | const TExtensionBehavior &extensionBehavior, |
| 102 | const char *sourcePath, ShShaderOutput outputType, |
| 103 | int numRenderTargets, const std::vector<Uniform> &uniforms, |
| 104 | int compileOptions) |
Jamie Madill | 54ad4f8 | 2014-09-03 09:40:46 -0400 | [diff] [blame] | 105 | : TIntermTraverser(true, true, true), |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 106 | mShaderType(shaderType), |
| 107 | mShaderVersion(shaderVersion), |
| 108 | mExtensionBehavior(extensionBehavior), |
| 109 | mSourcePath(sourcePath), |
| 110 | mOutputType(outputType), |
| 111 | mNumRenderTargets(numRenderTargets), |
| 112 | mCompileOptions(compileOptions) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 113 | { |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 114 | mUnfoldShortCircuit = new UnfoldShortCircuit(this); |
daniel@transgaming.com | f9ef107 | 2010-04-22 13:35:16 +0000 | [diff] [blame] | 115 | mInsideFunction = false; |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 116 | |
shannon.woods%transgaming.com@gtempaccount.com | aa8b5cf | 2013-04-13 03:31:55 +0000 | [diff] [blame] | 117 | mUsesFragColor = false; |
| 118 | mUsesFragData = false; |
daniel@transgaming.com | d7c9810 | 2010-05-14 17:30:48 +0000 | [diff] [blame] | 119 | mUsesDepthRange = false; |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 120 | mUsesFragCoord = false; |
| 121 | mUsesPointCoord = false; |
| 122 | mUsesFrontFacing = false; |
| 123 | mUsesPointSize = false; |
Gregoire Payen de La Garanderie | b3dced2 | 2015-01-12 14:54:55 +0000 | [diff] [blame] | 124 | mUsesInstanceID = false; |
Jamie Madill | 2aeb26a | 2013-07-08 14:02:55 -0400 | [diff] [blame] | 125 | mUsesFragDepth = false; |
daniel@transgaming.com | d7c9810 | 2010-05-14 17:30:48 +0000 | [diff] [blame] | 126 | mUsesXor = false; |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 127 | mUsesDiscardRewriting = false; |
Nicolas Capens | 655fe36 | 2014-04-11 13:12:34 -0400 | [diff] [blame] | 128 | mUsesNestedBreak = false; |
Arun Patole | 44efa0b | 2015-03-04 17:11:05 +0530 | [diff] [blame] | 129 | mRequiresIEEEStrictCompiling = false; |
daniel@transgaming.com | 005c739 | 2010-04-15 20:45:27 +0000 | [diff] [blame] | 130 | |
daniel@transgaming.com | b6ef8f1 | 2010-11-15 16:41:14 +0000 | [diff] [blame] | 131 | mUniqueIndex = 0; |
daniel@transgaming.com | 89431aa | 2012-05-31 01:20:29 +0000 | [diff] [blame] | 132 | |
| 133 | mContainsLoopDiscontinuity = false; |
Corentin Wallez | 80bacde | 2014-11-10 12:07:37 -0800 | [diff] [blame] | 134 | mContainsAnyLoop = false; |
daniel@transgaming.com | 89431aa | 2012-05-31 01:20:29 +0000 | [diff] [blame] | 135 | mOutputLod0Function = false; |
daniel@transgaming.com | e11100c | 2012-05-31 01:20:32 +0000 | [diff] [blame] | 136 | mInsideDiscontinuousLoop = false; |
Nicolas Capens | 655fe36 | 2014-04-11 13:12:34 -0400 | [diff] [blame] | 137 | mNestedLoopDepth = 0; |
daniel@transgaming.com | e9b3f60 | 2012-07-11 20:37:31 +0000 | [diff] [blame] | 138 | |
| 139 | mExcessiveLoopIndex = NULL; |
daniel@transgaming.com | 652468c | 2012-12-20 21:11:57 +0000 | [diff] [blame] | 140 | |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 141 | mStructureHLSL = new StructureHLSL; |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 142 | mUniformHLSL = new UniformHLSL(mStructureHLSL, outputType, uniforms); |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 143 | |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 144 | if (mOutputType == SH_HLSL9_OUTPUT) |
daniel@transgaming.com | a390e1e | 2013-01-11 04:09:39 +0000 | [diff] [blame] | 145 | { |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 146 | if (mShaderType == GL_FRAGMENT_SHADER) |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 147 | { |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 148 | // Reserve registers for dx_DepthRange, dx_ViewCoords and dx_DepthFront |
| 149 | mUniformHLSL->reserveUniformRegisters(3); |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 150 | } |
| 151 | else |
| 152 | { |
Cooper Partin | e6664f0 | 2015-01-09 16:22:24 -0800 | [diff] [blame] | 153 | // Reserve registers for dx_DepthRange, dx_ViewAdjust and dx_ViewCoords |
| 154 | mUniformHLSL->reserveUniformRegisters(3); |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 155 | } |
daniel@transgaming.com | a390e1e | 2013-01-11 04:09:39 +0000 | [diff] [blame] | 156 | } |
daniel@transgaming.com | a390e1e | 2013-01-11 04:09:39 +0000 | [diff] [blame] | 157 | |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 158 | // Reserve registers for the default uniform block and driver constants |
| 159 | mUniformHLSL->reserveInterfaceBlockRegisters(2); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 160 | } |
| 161 | |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 162 | OutputHLSL::~OutputHLSL() |
| 163 | { |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 164 | SafeDelete(mUnfoldShortCircuit); |
| 165 | SafeDelete(mStructureHLSL); |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 166 | SafeDelete(mUniformHLSL); |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 167 | } |
| 168 | |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 169 | void OutputHLSL::output(TIntermNode *treeRoot, TInfoSinkBase &objSink) |
daniel@transgaming.com | 950f993 | 2010-04-13 03:26:14 +0000 | [diff] [blame] | 170 | { |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 171 | mContainsLoopDiscontinuity = mShaderType == GL_FRAGMENT_SHADER && containsLoopDiscontinuity(treeRoot); |
| 172 | mContainsAnyLoop = containsAnyLoop(treeRoot); |
| 173 | const std::vector<TIntermTyped*> &flaggedStructs = FlagStd140ValueStructs(treeRoot); |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 174 | makeFlaggedStructMaps(flaggedStructs); |
daniel@transgaming.com | 89431aa | 2012-05-31 01:20:29 +0000 | [diff] [blame] | 175 | |
Jamie Madill | e53c98b | 2014-02-03 11:57:13 -0500 | [diff] [blame] | 176 | // Work around D3D9 bug that would manifest in vertex shaders with selection blocks which |
| 177 | // use a vertex attribute as a condition, and some related computation in the else block. |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 178 | if (mOutputType == SH_HLSL9_OUTPUT && mShaderType == GL_VERTEX_SHADER) |
Jamie Madill | e53c98b | 2014-02-03 11:57:13 -0500 | [diff] [blame] | 179 | { |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 180 | RewriteElseBlocks(treeRoot); |
Jamie Madill | e53c98b | 2014-02-03 11:57:13 -0500 | [diff] [blame] | 181 | } |
| 182 | |
Olli Etuaho | 8efc5ad | 2015-03-03 17:21:10 +0200 | [diff] [blame] | 183 | BuiltInFunctionEmulator builtInFunctionEmulator; |
| 184 | InitBuiltInFunctionEmulatorForHLSL(&builtInFunctionEmulator); |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 185 | builtInFunctionEmulator.MarkBuiltInFunctionsForEmulation(treeRoot); |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame] | 186 | |
Jamie Madill | 3799714 | 2015-01-28 10:06:34 -0500 | [diff] [blame] | 187 | // Output the body and footer first to determine what has to go in the header |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame] | 188 | mInfoSinkStack.push(&mBody); |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 189 | treeRoot->traverse(this); |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame] | 190 | mInfoSinkStack.pop(); |
| 191 | |
Jamie Madill | 3799714 | 2015-01-28 10:06:34 -0500 | [diff] [blame] | 192 | mInfoSinkStack.push(&mFooter); |
| 193 | if (!mDeferredGlobalInitializers.empty()) |
| 194 | { |
| 195 | writeDeferredGlobalInitializers(mFooter); |
| 196 | } |
| 197 | mInfoSinkStack.pop(); |
| 198 | |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame] | 199 | mInfoSinkStack.push(&mHeader); |
Olli Etuaho | e17e319 | 2015-01-02 12:47:59 +0200 | [diff] [blame] | 200 | header(&builtInFunctionEmulator); |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame] | 201 | mInfoSinkStack.pop(); |
daniel@transgaming.com | 950f993 | 2010-04-13 03:26:14 +0000 | [diff] [blame] | 202 | |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 203 | objSink << mHeader.c_str(); |
| 204 | objSink << mBody.c_str(); |
| 205 | objSink << mFooter.c_str(); |
Olli Etuaho | e17e319 | 2015-01-02 12:47:59 +0200 | [diff] [blame] | 206 | |
| 207 | builtInFunctionEmulator.Cleanup(); |
daniel@transgaming.com | 950f993 | 2010-04-13 03:26:14 +0000 | [diff] [blame] | 208 | } |
| 209 | |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 210 | void OutputHLSL::makeFlaggedStructMaps(const std::vector<TIntermTyped *> &flaggedStructs) |
| 211 | { |
| 212 | for (unsigned int structIndex = 0; structIndex < flaggedStructs.size(); structIndex++) |
| 213 | { |
| 214 | TIntermTyped *flaggedNode = flaggedStructs[structIndex]; |
| 215 | |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame] | 216 | TInfoSinkBase structInfoSink; |
| 217 | mInfoSinkStack.push(&structInfoSink); |
| 218 | |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 219 | // This will mark the necessary block elements as referenced |
| 220 | flaggedNode->traverse(this); |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame] | 221 | |
| 222 | TString structName(structInfoSink.c_str()); |
| 223 | mInfoSinkStack.pop(); |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 224 | |
| 225 | mFlaggedStructOriginalNames[flaggedNode] = structName; |
| 226 | |
| 227 | for (size_t pos = structName.find('.'); pos != std::string::npos; pos = structName.find('.')) |
| 228 | { |
| 229 | structName.erase(pos, 1); |
| 230 | } |
| 231 | |
| 232 | mFlaggedStructMappedNames[flaggedNode] = "map" + structName; |
| 233 | } |
| 234 | } |
| 235 | |
Jamie Madill | 4e1fd41 | 2014-07-10 17:50:10 -0400 | [diff] [blame] | 236 | const std::map<std::string, unsigned int> &OutputHLSL::getInterfaceBlockRegisterMap() const |
| 237 | { |
| 238 | return mUniformHLSL->getInterfaceBlockRegisterMap(); |
| 239 | } |
| 240 | |
Jamie Madill | 9fe25e9 | 2014-07-18 10:33:08 -0400 | [diff] [blame] | 241 | const std::map<std::string, unsigned int> &OutputHLSL::getUniformRegisterMap() const |
| 242 | { |
| 243 | return mUniformHLSL->getUniformRegisterMap(); |
| 244 | } |
| 245 | |
daniel@transgaming.com | 0b6b834 | 2010-04-26 15:33:45 +0000 | [diff] [blame] | 246 | int OutputHLSL::vectorSize(const TType &type) const |
| 247 | { |
shannonwoods@chromium.org | 9bd22fa | 2013-05-30 00:18:47 +0000 | [diff] [blame] | 248 | int elementSize = type.isMatrix() ? type.getCols() : 1; |
daniel@transgaming.com | 0b6b834 | 2010-04-26 15:33:45 +0000 | [diff] [blame] | 249 | int arraySize = type.isArray() ? type.getArraySize() : 1; |
| 250 | |
| 251 | return elementSize * arraySize; |
| 252 | } |
| 253 | |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 254 | TString OutputHLSL::structInitializerString(int indent, const TStructure &structure, const TString &rhsStructName) |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 255 | { |
| 256 | TString init; |
| 257 | |
| 258 | TString preIndentString; |
| 259 | TString fullIndentString; |
| 260 | |
| 261 | for (int spaces = 0; spaces < (indent * 4); spaces++) |
| 262 | { |
| 263 | preIndentString += ' '; |
| 264 | } |
| 265 | |
| 266 | for (int spaces = 0; spaces < ((indent+1) * 4); spaces++) |
| 267 | { |
| 268 | fullIndentString += ' '; |
| 269 | } |
| 270 | |
| 271 | init += preIndentString + "{\n"; |
| 272 | |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 273 | const TFieldList &fields = structure.fields(); |
| 274 | for (unsigned int fieldIndex = 0; fieldIndex < fields.size(); fieldIndex++) |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 275 | { |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 276 | const TField &field = *fields[fieldIndex]; |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 277 | const TString &fieldName = rhsStructName + "." + Decorate(field.name()); |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 278 | const TType &fieldType = *field.type(); |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 279 | |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 280 | if (fieldType.getStruct()) |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 281 | { |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 282 | init += structInitializerString(indent + 1, *fieldType.getStruct(), fieldName); |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 283 | } |
| 284 | else |
| 285 | { |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 286 | init += fullIndentString + fieldName + ",\n"; |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | |
| 290 | init += preIndentString + "}" + (indent == 0 ? ";" : ",") + "\n"; |
| 291 | |
| 292 | return init; |
| 293 | } |
| 294 | |
Olli Etuaho | 8efc5ad | 2015-03-03 17:21:10 +0200 | [diff] [blame] | 295 | void OutputHLSL::header(const BuiltInFunctionEmulator *builtInFunctionEmulator) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 296 | { |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame] | 297 | TInfoSinkBase &out = getInfoSink(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 298 | |
daniel@transgaming.com | 8803b85 | 2012-12-20 21:11:47 +0000 | [diff] [blame] | 299 | TString varyings; |
| 300 | TString attributes; |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 301 | TString flaggedStructs; |
daniel@transgaming.com | 8803b85 | 2012-12-20 21:11:47 +0000 | [diff] [blame] | 302 | |
Jamie Madill | 829f59e | 2013-11-13 19:40:54 -0500 | [diff] [blame] | 303 | for (std::map<TIntermTyped*, TString>::const_iterator flaggedStructIt = mFlaggedStructMappedNames.begin(); flaggedStructIt != mFlaggedStructMappedNames.end(); flaggedStructIt++) |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 304 | { |
| 305 | TIntermTyped *structNode = flaggedStructIt->first; |
| 306 | const TString &mappedName = flaggedStructIt->second; |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 307 | const TStructure &structure = *structNode->getType().getStruct(); |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 308 | const TString &originalName = mFlaggedStructOriginalNames[structNode]; |
| 309 | |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 310 | flaggedStructs += "static " + Decorate(structure.name()) + " " + mappedName + " =\n"; |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 311 | flaggedStructs += structInitializerString(0, structure, originalName); |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 312 | flaggedStructs += "\n"; |
| 313 | } |
| 314 | |
daniel@transgaming.com | 8803b85 | 2012-12-20 21:11:47 +0000 | [diff] [blame] | 315 | for (ReferencedSymbols::const_iterator varying = mReferencedVaryings.begin(); varying != mReferencedVaryings.end(); varying++) |
| 316 | { |
| 317 | const TType &type = varying->second->getType(); |
| 318 | const TString &name = varying->second->getSymbol(); |
| 319 | |
| 320 | // Program linking depends on this exact format |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 321 | varyings += "static " + InterpolationString(type.getQualifier()) + " " + TypeString(type) + " " + |
| 322 | Decorate(name) + ArrayString(type) + " = " + initializer(type) + ";\n"; |
daniel@transgaming.com | 8803b85 | 2012-12-20 21:11:47 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | for (ReferencedSymbols::const_iterator attribute = mReferencedAttributes.begin(); attribute != mReferencedAttributes.end(); attribute++) |
| 326 | { |
| 327 | const TType &type = attribute->second->getType(); |
| 328 | const TString &name = attribute->second->getSymbol(); |
| 329 | |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 330 | attributes += "static " + TypeString(type) + " " + Decorate(name) + ArrayString(type) + " = " + initializer(type) + ";\n"; |
daniel@transgaming.com | 8803b85 | 2012-12-20 21:11:47 +0000 | [diff] [blame] | 331 | } |
| 332 | |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 333 | out << mStructureHLSL->structsHeader(); |
Jamie Madill | 529077d | 2013-06-20 11:55:54 -0400 | [diff] [blame] | 334 | |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 335 | out << mUniformHLSL->uniformsHeader(mOutputType, mReferencedUniforms); |
| 336 | out << mUniformHLSL->interfaceBlocksHeader(mReferencedInterfaceBlocks); |
| 337 | |
Jamie Madill | 55e79e0 | 2015-02-09 15:35:00 -0500 | [diff] [blame] | 338 | if (!mStructEqualityFunctions.empty()) |
| 339 | { |
| 340 | out << "\n// Structure equality functions\n\n"; |
| 341 | for (const auto &eqFunction : mStructEqualityFunctions) |
| 342 | { |
| 343 | out << eqFunction.functionDefinition << "\n"; |
| 344 | } |
| 345 | } |
| 346 | |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 347 | if (mUsesDiscardRewriting) |
| 348 | { |
Nicolas Capens | 5e0c80a | 2014-10-10 10:11:54 -0400 | [diff] [blame] | 349 | out << "#define ANGLE_USES_DISCARD_REWRITING\n"; |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 350 | } |
| 351 | |
Nicolas Capens | 655fe36 | 2014-04-11 13:12:34 -0400 | [diff] [blame] | 352 | if (mUsesNestedBreak) |
| 353 | { |
Nicolas Capens | 5e0c80a | 2014-10-10 10:11:54 -0400 | [diff] [blame] | 354 | out << "#define ANGLE_USES_NESTED_BREAK\n"; |
Nicolas Capens | 655fe36 | 2014-04-11 13:12:34 -0400 | [diff] [blame] | 355 | } |
| 356 | |
Arun Patole | 44efa0b | 2015-03-04 17:11:05 +0530 | [diff] [blame] | 357 | if (mRequiresIEEEStrictCompiling) |
| 358 | { |
| 359 | out << "#define ANGLE_REQUIRES_IEEE_STRICT_COMPILING\n"; |
| 360 | } |
| 361 | |
Nicolas Capens | 5e0c80a | 2014-10-10 10:11:54 -0400 | [diff] [blame] | 362 | out << "#ifdef ANGLE_ENABLE_LOOP_FLATTEN\n" |
| 363 | "#define LOOP [loop]\n" |
| 364 | "#define FLATTEN [flatten]\n" |
| 365 | "#else\n" |
| 366 | "#define LOOP\n" |
| 367 | "#define FLATTEN\n" |
| 368 | "#endif\n"; |
| 369 | |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 370 | if (mShaderType == GL_FRAGMENT_SHADER) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 371 | { |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 372 | TExtensionBehavior::const_iterator iter = mExtensionBehavior.find("GL_EXT_draw_buffers"); |
| 373 | const bool usingMRTExtension = (iter != mExtensionBehavior.end() && (iter->second == EBhEnable || iter->second == EBhRequire)); |
shannon.woods%transgaming.com@gtempaccount.com | aa8b5cf | 2013-04-13 03:31:55 +0000 | [diff] [blame] | 374 | |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 375 | out << "// Varyings\n"; |
| 376 | out << varyings; |
Jamie Madill | 46131a3 | 2013-06-20 11:55:50 -0400 | [diff] [blame] | 377 | out << "\n"; |
| 378 | |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 379 | if (mShaderVersion >= 300) |
shannon.woods%transgaming.com@gtempaccount.com | a28864c | 2013-04-13 03:32:03 +0000 | [diff] [blame] | 380 | { |
Jamie Madill | 829f59e | 2013-11-13 19:40:54 -0500 | [diff] [blame] | 381 | for (ReferencedSymbols::const_iterator outputVariableIt = mReferencedOutputVariables.begin(); outputVariableIt != mReferencedOutputVariables.end(); outputVariableIt++) |
shannon.woods%transgaming.com@gtempaccount.com | a28864c | 2013-04-13 03:32:03 +0000 | [diff] [blame] | 382 | { |
Jamie Madill | 46131a3 | 2013-06-20 11:55:50 -0400 | [diff] [blame] | 383 | const TString &variableName = outputVariableIt->first; |
| 384 | const TType &variableType = outputVariableIt->second->getType(); |
Jamie Madill | 46131a3 | 2013-06-20 11:55:50 -0400 | [diff] [blame] | 385 | |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 386 | out << "static " + TypeString(variableType) + " out_" + variableName + ArrayString(variableType) + |
Jamie Madill | 46131a3 | 2013-06-20 11:55:50 -0400 | [diff] [blame] | 387 | " = " + initializer(variableType) + ";\n"; |
shannon.woods%transgaming.com@gtempaccount.com | a28864c | 2013-04-13 03:32:03 +0000 | [diff] [blame] | 388 | } |
shannon.woods%transgaming.com@gtempaccount.com | a28864c | 2013-04-13 03:32:03 +0000 | [diff] [blame] | 389 | } |
Jamie Madill | 46131a3 | 2013-06-20 11:55:50 -0400 | [diff] [blame] | 390 | else |
| 391 | { |
| 392 | const unsigned int numColorValues = usingMRTExtension ? mNumRenderTargets : 1; |
| 393 | |
| 394 | out << "static float4 gl_Color[" << numColorValues << "] =\n" |
| 395 | "{\n"; |
| 396 | for (unsigned int i = 0; i < numColorValues; i++) |
| 397 | { |
| 398 | out << " float4(0, 0, 0, 0)"; |
| 399 | if (i + 1 != numColorValues) |
| 400 | { |
| 401 | out << ","; |
| 402 | } |
| 403 | out << "\n"; |
| 404 | } |
| 405 | |
| 406 | out << "};\n"; |
| 407 | } |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 408 | |
Jamie Madill | 2aeb26a | 2013-07-08 14:02:55 -0400 | [diff] [blame] | 409 | if (mUsesFragDepth) |
| 410 | { |
| 411 | out << "static float gl_Depth = 0.0;\n"; |
| 412 | } |
| 413 | |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 414 | if (mUsesFragCoord) |
| 415 | { |
| 416 | out << "static float4 gl_FragCoord = float4(0, 0, 0, 0);\n"; |
| 417 | } |
| 418 | |
| 419 | if (mUsesPointCoord) |
| 420 | { |
| 421 | out << "static float2 gl_PointCoord = float2(0.5, 0.5);\n"; |
| 422 | } |
| 423 | |
| 424 | if (mUsesFrontFacing) |
| 425 | { |
| 426 | out << "static bool gl_FrontFacing = false;\n"; |
| 427 | } |
| 428 | |
| 429 | out << "\n"; |
| 430 | |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 431 | if (mUsesDepthRange) |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 432 | { |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 433 | out << "struct gl_DepthRangeParameters\n" |
| 434 | "{\n" |
| 435 | " float near;\n" |
| 436 | " float far;\n" |
| 437 | " float diff;\n" |
| 438 | "};\n" |
| 439 | "\n"; |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 440 | } |
| 441 | |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 442 | if (mOutputType == SH_HLSL11_OUTPUT) |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 443 | { |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 444 | out << "cbuffer DriverConstants : register(b1)\n" |
| 445 | "{\n"; |
| 446 | |
| 447 | if (mUsesDepthRange) |
| 448 | { |
| 449 | out << " float3 dx_DepthRange : packoffset(c0);\n"; |
| 450 | } |
| 451 | |
| 452 | if (mUsesFragCoord) |
| 453 | { |
shannon.woods@transgaming.com | a14ecf3 | 2013-02-28 23:09:42 +0000 | [diff] [blame] | 454 | out << " float4 dx_ViewCoords : packoffset(c1);\n"; |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | if (mUsesFragCoord || mUsesFrontFacing) |
| 458 | { |
| 459 | out << " float3 dx_DepthFront : packoffset(c2);\n"; |
| 460 | } |
| 461 | |
| 462 | out << "};\n"; |
| 463 | } |
| 464 | else |
| 465 | { |
| 466 | if (mUsesDepthRange) |
| 467 | { |
| 468 | out << "uniform float3 dx_DepthRange : register(c0);"; |
| 469 | } |
| 470 | |
| 471 | if (mUsesFragCoord) |
| 472 | { |
shannon.woods@transgaming.com | a14ecf3 | 2013-02-28 23:09:42 +0000 | [diff] [blame] | 473 | out << "uniform float4 dx_ViewCoords : register(c1);\n"; |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | if (mUsesFragCoord || mUsesFrontFacing) |
| 477 | { |
| 478 | out << "uniform float3 dx_DepthFront : register(c2);\n"; |
| 479 | } |
| 480 | } |
| 481 | |
| 482 | out << "\n"; |
| 483 | |
| 484 | if (mUsesDepthRange) |
| 485 | { |
| 486 | out << "static gl_DepthRangeParameters gl_DepthRange = {dx_DepthRange.x, dx_DepthRange.y, dx_DepthRange.z};\n" |
| 487 | "\n"; |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 488 | } |
daniel@transgaming.com | 5024cc4 | 2010-04-20 18:52:04 +0000 | [diff] [blame] | 489 | |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 490 | if (!flaggedStructs.empty()) |
shannonwoods@chromium.org | 4a643ae | 2013-05-30 00:12:27 +0000 | [diff] [blame] | 491 | { |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 492 | out << "// Std140 Structures accessed by value\n"; |
shannonwoods@chromium.org | 4a643ae | 2013-05-30 00:12:27 +0000 | [diff] [blame] | 493 | out << "\n"; |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 494 | out << flaggedStructs; |
| 495 | out << "\n"; |
shannonwoods@chromium.org | 4a643ae | 2013-05-30 00:12:27 +0000 | [diff] [blame] | 496 | } |
| 497 | |
shannon.woods%transgaming.com@gtempaccount.com | aa8b5cf | 2013-04-13 03:31:55 +0000 | [diff] [blame] | 498 | if (usingMRTExtension && mNumRenderTargets > 1) |
| 499 | { |
| 500 | out << "#define GL_USES_MRT\n"; |
| 501 | } |
| 502 | |
| 503 | if (mUsesFragColor) |
| 504 | { |
| 505 | out << "#define GL_USES_FRAG_COLOR\n"; |
| 506 | } |
| 507 | |
| 508 | if (mUsesFragData) |
| 509 | { |
| 510 | out << "#define GL_USES_FRAG_DATA\n"; |
| 511 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 512 | } |
daniel@transgaming.com | d25ab25 | 2010-03-30 03:36:26 +0000 | [diff] [blame] | 513 | else // Vertex shader |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 514 | { |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 515 | out << "// Attributes\n"; |
| 516 | out << attributes; |
| 517 | out << "\n" |
| 518 | "static float4 gl_Position = float4(0, 0, 0, 0);\n"; |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 519 | |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 520 | if (mUsesPointSize) |
| 521 | { |
| 522 | out << "static float gl_PointSize = float(1);\n"; |
| 523 | } |
| 524 | |
Gregoire Payen de La Garanderie | b3dced2 | 2015-01-12 14:54:55 +0000 | [diff] [blame] | 525 | if (mUsesInstanceID) |
| 526 | { |
| 527 | out << "static int gl_InstanceID;"; |
| 528 | } |
| 529 | |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 530 | out << "\n" |
| 531 | "// Varyings\n"; |
| 532 | out << varyings; |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 533 | out << "\n"; |
| 534 | |
| 535 | if (mUsesDepthRange) |
| 536 | { |
| 537 | out << "struct gl_DepthRangeParameters\n" |
| 538 | "{\n" |
| 539 | " float near;\n" |
| 540 | " float far;\n" |
| 541 | " float diff;\n" |
| 542 | "};\n" |
| 543 | "\n"; |
| 544 | } |
| 545 | |
| 546 | if (mOutputType == SH_HLSL11_OUTPUT) |
| 547 | { |
Austin Kinross | 4fd18b1 | 2014-12-22 12:32:05 -0800 | [diff] [blame] | 548 | out << "cbuffer DriverConstants : register(b1)\n" |
| 549 | "{\n"; |
| 550 | |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 551 | if (mUsesDepthRange) |
| 552 | { |
Austin Kinross | 4fd18b1 | 2014-12-22 12:32:05 -0800 | [diff] [blame] | 553 | out << " float3 dx_DepthRange : packoffset(c0);\n"; |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 554 | } |
Austin Kinross | 4fd18b1 | 2014-12-22 12:32:05 -0800 | [diff] [blame] | 555 | |
Cooper Partin | e6664f0 | 2015-01-09 16:22:24 -0800 | [diff] [blame] | 556 | // dx_ViewAdjust and dx_ViewCoords will only be used in Feature Level 9 shaders. |
Austin Kinross | 4fd18b1 | 2014-12-22 12:32:05 -0800 | [diff] [blame] | 557 | // However, we declare it for all shaders (including Feature Level 10+). |
| 558 | // The bytecode is the same whether we declare it or not, since D3DCompiler removes it if it's unused. |
| 559 | out << " float4 dx_ViewAdjust : packoffset(c1);\n"; |
Cooper Partin | e6664f0 | 2015-01-09 16:22:24 -0800 | [diff] [blame] | 560 | out << " float2 dx_ViewCoords : packoffset(c2);\n"; |
Austin Kinross | 4fd18b1 | 2014-12-22 12:32:05 -0800 | [diff] [blame] | 561 | |
| 562 | out << "};\n" |
| 563 | "\n"; |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 564 | } |
| 565 | else |
| 566 | { |
| 567 | if (mUsesDepthRange) |
| 568 | { |
| 569 | out << "uniform float3 dx_DepthRange : register(c0);\n"; |
| 570 | } |
| 571 | |
Cooper Partin | e6664f0 | 2015-01-09 16:22:24 -0800 | [diff] [blame] | 572 | out << "uniform float4 dx_ViewAdjust : register(c1);\n"; |
| 573 | out << "uniform float2 dx_ViewCoords : register(c2);\n" |
shannon.woods@transgaming.com | a14ecf3 | 2013-02-28 23:09:42 +0000 | [diff] [blame] | 574 | "\n"; |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 575 | } |
| 576 | |
shannon.woods@transgaming.com | 46a5b87 | 2013-01-25 21:52:57 +0000 | [diff] [blame] | 577 | if (mUsesDepthRange) |
| 578 | { |
| 579 | out << "static gl_DepthRangeParameters gl_DepthRange = {dx_DepthRange.x, dx_DepthRange.y, dx_DepthRange.z};\n" |
| 580 | "\n"; |
| 581 | } |
| 582 | |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 583 | if (!flaggedStructs.empty()) |
shannonwoods@chromium.org | 4a643ae | 2013-05-30 00:12:27 +0000 | [diff] [blame] | 584 | { |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 585 | out << "// Std140 Structures accessed by value\n"; |
shannonwoods@chromium.org | 4a643ae | 2013-05-30 00:12:27 +0000 | [diff] [blame] | 586 | out << "\n"; |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 587 | out << flaggedStructs; |
| 588 | out << "\n"; |
shannonwoods@chromium.org | 4a643ae | 2013-05-30 00:12:27 +0000 | [diff] [blame] | 589 | } |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 590 | } |
shannonwoods@chromium.org | 4a643ae | 2013-05-30 00:12:27 +0000 | [diff] [blame] | 591 | |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 592 | for (TextureFunctionSet::const_iterator textureFunction = mUsesTexture.begin(); textureFunction != mUsesTexture.end(); textureFunction++) |
| 593 | { |
| 594 | // Return type |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 595 | if (textureFunction->method == TextureFunction::SIZE) |
daniel@transgaming.com | 1579519 | 2011-05-11 15:36:20 +0000 | [diff] [blame] | 596 | { |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 597 | switch(textureFunction->sampler) |
| 598 | { |
Nicolas Capens | cb127d3 | 2013-07-15 17:26:18 -0400 | [diff] [blame] | 599 | case EbtSampler2D: out << "int2 "; break; |
| 600 | case EbtSampler3D: out << "int3 "; break; |
| 601 | case EbtSamplerCube: out << "int2 "; break; |
| 602 | case EbtSampler2DArray: out << "int3 "; break; |
| 603 | case EbtISampler2D: out << "int2 "; break; |
| 604 | case EbtISampler3D: out << "int3 "; break; |
| 605 | case EbtISamplerCube: out << "int2 "; break; |
| 606 | case EbtISampler2DArray: out << "int3 "; break; |
| 607 | case EbtUSampler2D: out << "int2 "; break; |
| 608 | case EbtUSampler3D: out << "int3 "; break; |
| 609 | case EbtUSamplerCube: out << "int2 "; break; |
| 610 | case EbtUSampler2DArray: out << "int3 "; break; |
| 611 | case EbtSampler2DShadow: out << "int2 "; break; |
| 612 | case EbtSamplerCubeShadow: out << "int2 "; break; |
| 613 | case EbtSampler2DArrayShadow: out << "int3 "; break; |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 614 | default: UNREACHABLE(); |
| 615 | } |
| 616 | } |
| 617 | else // Sampling function |
| 618 | { |
| 619 | switch(textureFunction->sampler) |
| 620 | { |
Nicolas Capens | cb127d3 | 2013-07-15 17:26:18 -0400 | [diff] [blame] | 621 | case EbtSampler2D: out << "float4 "; break; |
| 622 | case EbtSampler3D: out << "float4 "; break; |
| 623 | case EbtSamplerCube: out << "float4 "; break; |
| 624 | case EbtSampler2DArray: out << "float4 "; break; |
| 625 | case EbtISampler2D: out << "int4 "; break; |
| 626 | case EbtISampler3D: out << "int4 "; break; |
| 627 | case EbtISamplerCube: out << "int4 "; break; |
| 628 | case EbtISampler2DArray: out << "int4 "; break; |
| 629 | case EbtUSampler2D: out << "uint4 "; break; |
| 630 | case EbtUSampler3D: out << "uint4 "; break; |
| 631 | case EbtUSamplerCube: out << "uint4 "; break; |
| 632 | case EbtUSampler2DArray: out << "uint4 "; break; |
| 633 | case EbtSampler2DShadow: out << "float "; break; |
| 634 | case EbtSamplerCubeShadow: out << "float "; break; |
| 635 | case EbtSampler2DArrayShadow: out << "float "; break; |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 636 | default: UNREACHABLE(); |
| 637 | } |
daniel@transgaming.com | 1579519 | 2011-05-11 15:36:20 +0000 | [diff] [blame] | 638 | } |
| 639 | |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 640 | // Function name |
| 641 | out << textureFunction->name(); |
| 642 | |
| 643 | // Argument list |
| 644 | int hlslCoords = 4; |
| 645 | |
| 646 | if (mOutputType == SH_HLSL9_OUTPUT) |
daniel@transgaming.com | 1579519 | 2011-05-11 15:36:20 +0000 | [diff] [blame] | 647 | { |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 648 | switch(textureFunction->sampler) |
shannon.woods@transgaming.com | fb256be | 2013-01-25 21:49:25 +0000 | [diff] [blame] | 649 | { |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 650 | case EbtSampler2D: out << "sampler2D s"; hlslCoords = 2; break; |
| 651 | case EbtSamplerCube: out << "samplerCUBE s"; hlslCoords = 3; break; |
| 652 | default: UNREACHABLE(); |
shannon.woods@transgaming.com | fb256be | 2013-01-25 21:49:25 +0000 | [diff] [blame] | 653 | } |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 654 | |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 655 | switch(textureFunction->method) |
shannon.woods@transgaming.com | fb256be | 2013-01-25 21:49:25 +0000 | [diff] [blame] | 656 | { |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 657 | case TextureFunction::IMPLICIT: break; |
| 658 | case TextureFunction::BIAS: hlslCoords = 4; break; |
| 659 | case TextureFunction::LOD: hlslCoords = 4; break; |
| 660 | case TextureFunction::LOD0: hlslCoords = 4; break; |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 661 | case TextureFunction::LOD0BIAS: hlslCoords = 4; break; |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 662 | default: UNREACHABLE(); |
shannon.woods@transgaming.com | fb256be | 2013-01-25 21:49:25 +0000 | [diff] [blame] | 663 | } |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 664 | } |
| 665 | else if (mOutputType == SH_HLSL11_OUTPUT) |
| 666 | { |
| 667 | switch(textureFunction->sampler) |
| 668 | { |
Nicolas Capens | cb127d3 | 2013-07-15 17:26:18 -0400 | [diff] [blame] | 669 | case EbtSampler2D: out << "Texture2D x, SamplerState s"; hlslCoords = 2; break; |
| 670 | case EbtSampler3D: out << "Texture3D x, SamplerState s"; hlslCoords = 3; break; |
| 671 | case EbtSamplerCube: out << "TextureCube x, SamplerState s"; hlslCoords = 3; break; |
| 672 | case EbtSampler2DArray: out << "Texture2DArray x, SamplerState s"; hlslCoords = 3; break; |
| 673 | case EbtISampler2D: out << "Texture2D<int4> x, SamplerState s"; hlslCoords = 2; break; |
| 674 | case EbtISampler3D: out << "Texture3D<int4> x, SamplerState s"; hlslCoords = 3; break; |
Nicolas Capens | 0027fa9 | 2014-02-20 14:26:42 -0500 | [diff] [blame] | 675 | case EbtISamplerCube: out << "Texture2DArray<int4> x, SamplerState s"; hlslCoords = 3; break; |
Nicolas Capens | cb127d3 | 2013-07-15 17:26:18 -0400 | [diff] [blame] | 676 | case EbtISampler2DArray: out << "Texture2DArray<int4> x, SamplerState s"; hlslCoords = 3; break; |
| 677 | case EbtUSampler2D: out << "Texture2D<uint4> x, SamplerState s"; hlslCoords = 2; break; |
| 678 | case EbtUSampler3D: out << "Texture3D<uint4> x, SamplerState s"; hlslCoords = 3; break; |
Nicolas Capens | 0027fa9 | 2014-02-20 14:26:42 -0500 | [diff] [blame] | 679 | case EbtUSamplerCube: out << "Texture2DArray<uint4> x, SamplerState s"; hlslCoords = 3; break; |
Nicolas Capens | cb127d3 | 2013-07-15 17:26:18 -0400 | [diff] [blame] | 680 | case EbtUSampler2DArray: out << "Texture2DArray<uint4> x, SamplerState s"; hlslCoords = 3; break; |
| 681 | case EbtSampler2DShadow: out << "Texture2D x, SamplerComparisonState s"; hlslCoords = 2; break; |
| 682 | case EbtSamplerCubeShadow: out << "TextureCube x, SamplerComparisonState s"; hlslCoords = 3; break; |
| 683 | case EbtSampler2DArrayShadow: out << "Texture2DArray x, SamplerComparisonState s"; hlslCoords = 3; break; |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 684 | default: UNREACHABLE(); |
| 685 | } |
| 686 | } |
| 687 | else UNREACHABLE(); |
| 688 | |
Nicolas Capens | fc01454 | 2014-02-18 14:47:13 -0500 | [diff] [blame] | 689 | if (textureFunction->method == TextureFunction::FETCH) // Integer coordinates |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 690 | { |
Nicolas Capens | fc01454 | 2014-02-18 14:47:13 -0500 | [diff] [blame] | 691 | switch(textureFunction->coords) |
| 692 | { |
| 693 | case 2: out << ", int2 t"; break; |
| 694 | case 3: out << ", int3 t"; break; |
| 695 | default: UNREACHABLE(); |
| 696 | } |
| 697 | } |
| 698 | else // Floating-point coordinates (except textureSize) |
| 699 | { |
| 700 | switch(textureFunction->coords) |
| 701 | { |
| 702 | case 1: out << ", int lod"; break; // textureSize() |
| 703 | case 2: out << ", float2 t"; break; |
| 704 | case 3: out << ", float3 t"; break; |
| 705 | case 4: out << ", float4 t"; break; |
| 706 | default: UNREACHABLE(); |
| 707 | } |
daniel@transgaming.com | 1579519 | 2011-05-11 15:36:20 +0000 | [diff] [blame] | 708 | } |
| 709 | |
Nicolas Capens | d11d549 | 2014-02-19 17:06:10 -0500 | [diff] [blame] | 710 | if (textureFunction->method == TextureFunction::GRAD) |
| 711 | { |
| 712 | switch(textureFunction->sampler) |
| 713 | { |
| 714 | case EbtSampler2D: |
| 715 | case EbtISampler2D: |
| 716 | case EbtUSampler2D: |
| 717 | case EbtSampler2DArray: |
| 718 | case EbtISampler2DArray: |
| 719 | case EbtUSampler2DArray: |
| 720 | case EbtSampler2DShadow: |
| 721 | case EbtSampler2DArrayShadow: |
| 722 | out << ", float2 ddx, float2 ddy"; |
| 723 | break; |
| 724 | case EbtSampler3D: |
| 725 | case EbtISampler3D: |
| 726 | case EbtUSampler3D: |
| 727 | case EbtSamplerCube: |
| 728 | case EbtISamplerCube: |
| 729 | case EbtUSamplerCube: |
| 730 | case EbtSamplerCubeShadow: |
| 731 | out << ", float3 ddx, float3 ddy"; |
| 732 | break; |
| 733 | default: UNREACHABLE(); |
| 734 | } |
| 735 | } |
| 736 | |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 737 | switch(textureFunction->method) |
daniel@transgaming.com | 1579519 | 2011-05-11 15:36:20 +0000 | [diff] [blame] | 738 | { |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 739 | case TextureFunction::IMPLICIT: break; |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 740 | case TextureFunction::BIAS: break; // Comes after the offset parameter |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 741 | case TextureFunction::LOD: out << ", float lod"; break; |
| 742 | case TextureFunction::LOD0: break; |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 743 | case TextureFunction::LOD0BIAS: break; // Comes after the offset parameter |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 744 | case TextureFunction::SIZE: break; |
Nicolas Capens | fc01454 | 2014-02-18 14:47:13 -0500 | [diff] [blame] | 745 | case TextureFunction::FETCH: out << ", int mip"; break; |
Nicolas Capens | d11d549 | 2014-02-19 17:06:10 -0500 | [diff] [blame] | 746 | case TextureFunction::GRAD: break; |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 747 | default: UNREACHABLE(); |
daniel@transgaming.com | 1579519 | 2011-05-11 15:36:20 +0000 | [diff] [blame] | 748 | } |
| 749 | |
Nicolas Capens | b1f45b7 | 2013-12-19 17:37:19 -0500 | [diff] [blame] | 750 | if (textureFunction->offset) |
| 751 | { |
| 752 | switch(textureFunction->sampler) |
| 753 | { |
| 754 | case EbtSampler2D: out << ", int2 offset"; break; |
| 755 | case EbtSampler3D: out << ", int3 offset"; break; |
| 756 | case EbtSampler2DArray: out << ", int2 offset"; break; |
| 757 | case EbtISampler2D: out << ", int2 offset"; break; |
| 758 | case EbtISampler3D: out << ", int3 offset"; break; |
| 759 | case EbtISampler2DArray: out << ", int2 offset"; break; |
| 760 | case EbtUSampler2D: out << ", int2 offset"; break; |
| 761 | case EbtUSampler3D: out << ", int3 offset"; break; |
| 762 | case EbtUSampler2DArray: out << ", int2 offset"; break; |
| 763 | case EbtSampler2DShadow: out << ", int2 offset"; break; |
Nicolas Capens | bf7db10 | 2014-02-19 17:20:28 -0500 | [diff] [blame] | 764 | case EbtSampler2DArrayShadow: out << ", int2 offset"; break; |
Nicolas Capens | b1f45b7 | 2013-12-19 17:37:19 -0500 | [diff] [blame] | 765 | default: UNREACHABLE(); |
| 766 | } |
| 767 | } |
| 768 | |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 769 | if (textureFunction->method == TextureFunction::BIAS || |
| 770 | textureFunction->method == TextureFunction::LOD0BIAS) |
Nicolas Capens | b1f45b7 | 2013-12-19 17:37:19 -0500 | [diff] [blame] | 771 | { |
| 772 | out << ", float bias"; |
| 773 | } |
| 774 | |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 775 | out << ")\n" |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 776 | "{\n"; |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 777 | |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 778 | if (textureFunction->method == TextureFunction::SIZE) |
| 779 | { |
| 780 | if (IsSampler2D(textureFunction->sampler) || IsSamplerCube(textureFunction->sampler)) |
| 781 | { |
| 782 | if (IsSamplerArray(textureFunction->sampler)) |
| 783 | { |
| 784 | out << " uint width; uint height; uint layers; uint numberOfLevels;\n" |
| 785 | " x.GetDimensions(lod, width, height, layers, numberOfLevels);\n"; |
| 786 | } |
| 787 | else |
| 788 | { |
| 789 | out << " uint width; uint height; uint numberOfLevels;\n" |
| 790 | " x.GetDimensions(lod, width, height, numberOfLevels);\n"; |
| 791 | } |
| 792 | } |
| 793 | else if (IsSampler3D(textureFunction->sampler)) |
| 794 | { |
| 795 | out << " uint width; uint height; uint depth; uint numberOfLevels;\n" |
| 796 | " x.GetDimensions(lod, width, height, depth, numberOfLevels);\n"; |
| 797 | } |
| 798 | else UNREACHABLE(); |
| 799 | |
| 800 | switch(textureFunction->sampler) |
| 801 | { |
Nicolas Capens | cb127d3 | 2013-07-15 17:26:18 -0400 | [diff] [blame] | 802 | case EbtSampler2D: out << " return int2(width, height);"; break; |
| 803 | case EbtSampler3D: out << " return int3(width, height, depth);"; break; |
| 804 | case EbtSamplerCube: out << " return int2(width, height);"; break; |
| 805 | case EbtSampler2DArray: out << " return int3(width, height, layers);"; break; |
| 806 | case EbtISampler2D: out << " return int2(width, height);"; break; |
| 807 | case EbtISampler3D: out << " return int3(width, height, depth);"; break; |
| 808 | case EbtISamplerCube: out << " return int2(width, height);"; break; |
| 809 | case EbtISampler2DArray: out << " return int3(width, height, layers);"; break; |
| 810 | case EbtUSampler2D: out << " return int2(width, height);"; break; |
| 811 | case EbtUSampler3D: out << " return int3(width, height, depth);"; break; |
| 812 | case EbtUSamplerCube: out << " return int2(width, height);"; break; |
| 813 | case EbtUSampler2DArray: out << " return int3(width, height, layers);"; break; |
| 814 | case EbtSampler2DShadow: out << " return int2(width, height);"; break; |
| 815 | case EbtSamplerCubeShadow: out << " return int2(width, height);"; break; |
| 816 | case EbtSampler2DArrayShadow: out << " return int3(width, height, layers);"; break; |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 817 | default: UNREACHABLE(); |
| 818 | } |
| 819 | } |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 820 | else |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 821 | { |
Nicolas Capens | 0027fa9 | 2014-02-20 14:26:42 -0500 | [diff] [blame] | 822 | if (IsIntegerSampler(textureFunction->sampler) && IsSamplerCube(textureFunction->sampler)) |
| 823 | { |
| 824 | out << " float width; float height; float layers; float levels;\n"; |
| 825 | |
| 826 | out << " uint mip = 0;\n"; |
| 827 | |
| 828 | out << " x.GetDimensions(mip, width, height, layers, levels);\n"; |
| 829 | |
| 830 | out << " bool xMajor = abs(t.x) > abs(t.y) && abs(t.x) > abs(t.z);\n"; |
| 831 | out << " bool yMajor = abs(t.y) > abs(t.z) && abs(t.y) > abs(t.x);\n"; |
| 832 | out << " bool zMajor = abs(t.z) > abs(t.x) && abs(t.z) > abs(t.y);\n"; |
| 833 | out << " bool negative = (xMajor && t.x < 0.0f) || (yMajor && t.y < 0.0f) || (zMajor && t.z < 0.0f);\n"; |
| 834 | |
| 835 | // FACE_POSITIVE_X = 000b |
| 836 | // FACE_NEGATIVE_X = 001b |
| 837 | // FACE_POSITIVE_Y = 010b |
| 838 | // FACE_NEGATIVE_Y = 011b |
| 839 | // FACE_POSITIVE_Z = 100b |
| 840 | // FACE_NEGATIVE_Z = 101b |
| 841 | out << " int face = (int)negative + (int)yMajor * 2 + (int)zMajor * 4;\n"; |
| 842 | |
| 843 | out << " float u = xMajor ? -t.z : (yMajor && t.y < 0.0f ? -t.x : t.x);\n"; |
| 844 | out << " float v = yMajor ? t.z : (negative ? t.y : -t.y);\n"; |
| 845 | out << " float m = xMajor ? t.x : (yMajor ? t.y : t.z);\n"; |
| 846 | |
| 847 | out << " t.x = (u * 0.5f / m) + 0.5f;\n"; |
| 848 | out << " t.y = (v * 0.5f / m) + 0.5f;\n"; |
| 849 | } |
| 850 | else if (IsIntegerSampler(textureFunction->sampler) && |
| 851 | textureFunction->method != TextureFunction::FETCH) |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 852 | { |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 853 | if (IsSampler2D(textureFunction->sampler)) |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 854 | { |
Nicolas Capens | 93e50de | 2013-07-09 13:46:28 -0400 | [diff] [blame] | 855 | if (IsSamplerArray(textureFunction->sampler)) |
| 856 | { |
Nicolas Capens | 9edebd6 | 2013-08-06 10:59:10 -0400 | [diff] [blame] | 857 | out << " float width; float height; float layers; float levels;\n"; |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 858 | |
Nicolas Capens | 9edebd6 | 2013-08-06 10:59:10 -0400 | [diff] [blame] | 859 | if (textureFunction->method == TextureFunction::LOD0) |
| 860 | { |
| 861 | out << " uint mip = 0;\n"; |
| 862 | } |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 863 | else if (textureFunction->method == TextureFunction::LOD0BIAS) |
| 864 | { |
| 865 | out << " uint mip = bias;\n"; |
| 866 | } |
Nicolas Capens | 9edebd6 | 2013-08-06 10:59:10 -0400 | [diff] [blame] | 867 | else |
| 868 | { |
| 869 | if (textureFunction->method == TextureFunction::IMPLICIT || |
| 870 | textureFunction->method == TextureFunction::BIAS) |
| 871 | { |
| 872 | out << " x.GetDimensions(0, width, height, layers, levels);\n" |
| 873 | " float2 tSized = float2(t.x * width, t.y * height);\n" |
| 874 | " float dx = length(ddx(tSized));\n" |
| 875 | " float dy = length(ddy(tSized));\n" |
Jamie Madill | 03847b6 | 2013-11-13 19:42:39 -0500 | [diff] [blame] | 876 | " float lod = log2(max(dx, dy));\n"; |
Nicolas Capens | 9edebd6 | 2013-08-06 10:59:10 -0400 | [diff] [blame] | 877 | |
| 878 | if (textureFunction->method == TextureFunction::BIAS) |
| 879 | { |
| 880 | out << " lod += bias;\n"; |
| 881 | } |
| 882 | } |
Nicolas Capens | d11d549 | 2014-02-19 17:06:10 -0500 | [diff] [blame] | 883 | else if (textureFunction->method == TextureFunction::GRAD) |
| 884 | { |
| 885 | out << " x.GetDimensions(0, width, height, layers, levels);\n" |
| 886 | " float lod = log2(max(length(ddx), length(ddy)));\n"; |
| 887 | } |
Nicolas Capens | 9edebd6 | 2013-08-06 10:59:10 -0400 | [diff] [blame] | 888 | |
| 889 | out << " uint mip = uint(min(max(round(lod), 0), levels - 1));\n"; |
| 890 | } |
| 891 | |
| 892 | out << " x.GetDimensions(mip, width, height, layers, levels);\n"; |
Nicolas Capens | 93e50de | 2013-07-09 13:46:28 -0400 | [diff] [blame] | 893 | } |
| 894 | else |
| 895 | { |
Nicolas Capens | 9edebd6 | 2013-08-06 10:59:10 -0400 | [diff] [blame] | 896 | out << " float width; float height; float levels;\n"; |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 897 | |
Nicolas Capens | 9edebd6 | 2013-08-06 10:59:10 -0400 | [diff] [blame] | 898 | if (textureFunction->method == TextureFunction::LOD0) |
| 899 | { |
| 900 | out << " uint mip = 0;\n"; |
| 901 | } |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 902 | else if (textureFunction->method == TextureFunction::LOD0BIAS) |
| 903 | { |
| 904 | out << " uint mip = bias;\n"; |
| 905 | } |
Nicolas Capens | 9edebd6 | 2013-08-06 10:59:10 -0400 | [diff] [blame] | 906 | else |
| 907 | { |
| 908 | if (textureFunction->method == TextureFunction::IMPLICIT || |
| 909 | textureFunction->method == TextureFunction::BIAS) |
| 910 | { |
| 911 | out << " x.GetDimensions(0, width, height, levels);\n" |
| 912 | " float2 tSized = float2(t.x * width, t.y * height);\n" |
| 913 | " float dx = length(ddx(tSized));\n" |
| 914 | " float dy = length(ddy(tSized));\n" |
Jamie Madill | 03847b6 | 2013-11-13 19:42:39 -0500 | [diff] [blame] | 915 | " float lod = log2(max(dx, dy));\n"; |
Nicolas Capens | 9edebd6 | 2013-08-06 10:59:10 -0400 | [diff] [blame] | 916 | |
| 917 | if (textureFunction->method == TextureFunction::BIAS) |
| 918 | { |
| 919 | out << " lod += bias;\n"; |
| 920 | } |
| 921 | } |
Nicolas Capens | 2adc256 | 2014-02-14 23:50:59 -0500 | [diff] [blame] | 922 | else if (textureFunction->method == TextureFunction::LOD) |
| 923 | { |
| 924 | out << " x.GetDimensions(0, width, height, levels);\n"; |
| 925 | } |
Nicolas Capens | d11d549 | 2014-02-19 17:06:10 -0500 | [diff] [blame] | 926 | else if (textureFunction->method == TextureFunction::GRAD) |
| 927 | { |
| 928 | out << " x.GetDimensions(0, width, height, levels);\n" |
| 929 | " float lod = log2(max(length(ddx), length(ddy)));\n"; |
| 930 | } |
Nicolas Capens | 9edebd6 | 2013-08-06 10:59:10 -0400 | [diff] [blame] | 931 | |
| 932 | out << " uint mip = uint(min(max(round(lod), 0), levels - 1));\n"; |
| 933 | } |
| 934 | |
| 935 | out << " x.GetDimensions(mip, width, height, levels);\n"; |
Nicolas Capens | 93e50de | 2013-07-09 13:46:28 -0400 | [diff] [blame] | 936 | } |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 937 | } |
| 938 | else if (IsSampler3D(textureFunction->sampler)) |
| 939 | { |
Nicolas Capens | 9edebd6 | 2013-08-06 10:59:10 -0400 | [diff] [blame] | 940 | out << " float width; float height; float depth; float levels;\n"; |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 941 | |
Nicolas Capens | 9edebd6 | 2013-08-06 10:59:10 -0400 | [diff] [blame] | 942 | if (textureFunction->method == TextureFunction::LOD0) |
| 943 | { |
| 944 | out << " uint mip = 0;\n"; |
| 945 | } |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 946 | else if (textureFunction->method == TextureFunction::LOD0BIAS) |
| 947 | { |
| 948 | out << " uint mip = bias;\n"; |
| 949 | } |
Nicolas Capens | 9edebd6 | 2013-08-06 10:59:10 -0400 | [diff] [blame] | 950 | else |
| 951 | { |
| 952 | if (textureFunction->method == TextureFunction::IMPLICIT || |
| 953 | textureFunction->method == TextureFunction::BIAS) |
| 954 | { |
| 955 | out << " x.GetDimensions(0, width, height, depth, levels);\n" |
| 956 | " float3 tSized = float3(t.x * width, t.y * height, t.z * depth);\n" |
| 957 | " float dx = length(ddx(tSized));\n" |
| 958 | " float dy = length(ddy(tSized));\n" |
Jamie Madill | 03847b6 | 2013-11-13 19:42:39 -0500 | [diff] [blame] | 959 | " float lod = log2(max(dx, dy));\n"; |
Nicolas Capens | 9edebd6 | 2013-08-06 10:59:10 -0400 | [diff] [blame] | 960 | |
| 961 | if (textureFunction->method == TextureFunction::BIAS) |
| 962 | { |
| 963 | out << " lod += bias;\n"; |
| 964 | } |
| 965 | } |
Nicolas Capens | d11d549 | 2014-02-19 17:06:10 -0500 | [diff] [blame] | 966 | else if (textureFunction->method == TextureFunction::GRAD) |
| 967 | { |
| 968 | out << " x.GetDimensions(0, width, height, depth, levels);\n" |
| 969 | " float lod = log2(max(length(ddx), length(ddy)));\n"; |
| 970 | } |
Nicolas Capens | 9edebd6 | 2013-08-06 10:59:10 -0400 | [diff] [blame] | 971 | |
| 972 | out << " uint mip = uint(min(max(round(lod), 0), levels - 1));\n"; |
| 973 | } |
| 974 | |
| 975 | out << " x.GetDimensions(mip, width, height, depth, levels);\n"; |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 976 | } |
| 977 | else UNREACHABLE(); |
| 978 | } |
| 979 | |
| 980 | out << " return "; |
| 981 | |
| 982 | // HLSL intrinsic |
| 983 | if (mOutputType == SH_HLSL9_OUTPUT) |
| 984 | { |
| 985 | switch(textureFunction->sampler) |
| 986 | { |
| 987 | case EbtSampler2D: out << "tex2D"; break; |
| 988 | case EbtSamplerCube: out << "texCUBE"; break; |
| 989 | default: UNREACHABLE(); |
| 990 | } |
| 991 | |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 992 | switch(textureFunction->method) |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 993 | { |
| 994 | case TextureFunction::IMPLICIT: out << "(s, "; break; |
| 995 | case TextureFunction::BIAS: out << "bias(s, "; break; |
| 996 | case TextureFunction::LOD: out << "lod(s, "; break; |
| 997 | case TextureFunction::LOD0: out << "lod(s, "; break; |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 998 | case TextureFunction::LOD0BIAS: out << "lod(s, "; break; |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 999 | default: UNREACHABLE(); |
| 1000 | } |
| 1001 | } |
| 1002 | else if (mOutputType == SH_HLSL11_OUTPUT) |
| 1003 | { |
Nicolas Capens | d11d549 | 2014-02-19 17:06:10 -0500 | [diff] [blame] | 1004 | if (textureFunction->method == TextureFunction::GRAD) |
| 1005 | { |
| 1006 | if (IsIntegerSampler(textureFunction->sampler)) |
| 1007 | { |
| 1008 | out << "x.Load("; |
| 1009 | } |
| 1010 | else if (IsShadowSampler(textureFunction->sampler)) |
| 1011 | { |
| 1012 | out << "x.SampleCmpLevelZero(s, "; |
| 1013 | } |
| 1014 | else |
| 1015 | { |
| 1016 | out << "x.SampleGrad(s, "; |
| 1017 | } |
| 1018 | } |
| 1019 | else if (IsIntegerSampler(textureFunction->sampler) || |
| 1020 | textureFunction->method == TextureFunction::FETCH) |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 1021 | { |
| 1022 | out << "x.Load("; |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 1023 | } |
Nicolas Capens | cb127d3 | 2013-07-15 17:26:18 -0400 | [diff] [blame] | 1024 | else if (IsShadowSampler(textureFunction->sampler)) |
| 1025 | { |
Gregoire Payen de La Garanderie | 5cc9ac8 | 2015-02-20 11:27:56 +0000 | [diff] [blame] | 1026 | switch(textureFunction->method) |
| 1027 | { |
| 1028 | case TextureFunction::IMPLICIT: out << "x.SampleCmp(s, "; break; |
| 1029 | case TextureFunction::BIAS: out << "x.SampleCmp(s, "; break; |
| 1030 | case TextureFunction::LOD: out << "x.SampleCmp(s, "; break; |
| 1031 | case TextureFunction::LOD0: out << "x.SampleCmpLevelZero(s, "; break; |
| 1032 | case TextureFunction::LOD0BIAS: out << "x.SampleCmpLevelZero(s, "; break; |
| 1033 | default: UNREACHABLE(); |
| 1034 | } |
Nicolas Capens | cb127d3 | 2013-07-15 17:26:18 -0400 | [diff] [blame] | 1035 | } |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 1036 | else |
| 1037 | { |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 1038 | switch(textureFunction->method) |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 1039 | { |
| 1040 | case TextureFunction::IMPLICIT: out << "x.Sample(s, "; break; |
| 1041 | case TextureFunction::BIAS: out << "x.SampleBias(s, "; break; |
| 1042 | case TextureFunction::LOD: out << "x.SampleLevel(s, "; break; |
| 1043 | case TextureFunction::LOD0: out << "x.SampleLevel(s, "; break; |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 1044 | case TextureFunction::LOD0BIAS: out << "x.SampleLevel(s, "; break; |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 1045 | default: UNREACHABLE(); |
| 1046 | } |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 1047 | } |
Nicolas Capens | 9fe6f98 | 2013-06-24 16:05:25 -0400 | [diff] [blame] | 1048 | } |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 1049 | else UNREACHABLE(); |
Nicolas Capens | 9fe6f98 | 2013-06-24 16:05:25 -0400 | [diff] [blame] | 1050 | |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 1051 | // Integer sampling requires integer addresses |
| 1052 | TString addressx = ""; |
| 1053 | TString addressy = ""; |
| 1054 | TString addressz = ""; |
| 1055 | TString close = ""; |
| 1056 | |
Nicolas Capens | fc01454 | 2014-02-18 14:47:13 -0500 | [diff] [blame] | 1057 | if (IsIntegerSampler(textureFunction->sampler) || |
| 1058 | textureFunction->method == TextureFunction::FETCH) |
Nicolas Capens | 9fe6f98 | 2013-06-24 16:05:25 -0400 | [diff] [blame] | 1059 | { |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 1060 | switch(hlslCoords) |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 1061 | { |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 1062 | case 2: out << "int3("; break; |
| 1063 | case 3: out << "int4("; break; |
| 1064 | default: UNREACHABLE(); |
| 1065 | } |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 1066 | |
Nicolas Capens | fc01454 | 2014-02-18 14:47:13 -0500 | [diff] [blame] | 1067 | // Convert from normalized floating-point to integer |
| 1068 | if (textureFunction->method != TextureFunction::FETCH) |
Nicolas Capens | 93e50de | 2013-07-09 13:46:28 -0400 | [diff] [blame] | 1069 | { |
Nicolas Capens | fc01454 | 2014-02-18 14:47:13 -0500 | [diff] [blame] | 1070 | addressx = "int(floor(width * frac(("; |
| 1071 | addressy = "int(floor(height * frac(("; |
Nicolas Capens | 93e50de | 2013-07-09 13:46:28 -0400 | [diff] [blame] | 1072 | |
Nicolas Capens | fc01454 | 2014-02-18 14:47:13 -0500 | [diff] [blame] | 1073 | if (IsSamplerArray(textureFunction->sampler)) |
| 1074 | { |
| 1075 | addressz = "int(max(0, min(layers - 1, floor(0.5 + "; |
| 1076 | } |
Nicolas Capens | 0027fa9 | 2014-02-20 14:26:42 -0500 | [diff] [blame] | 1077 | else if (IsSamplerCube(textureFunction->sampler)) |
| 1078 | { |
| 1079 | addressz = "(((("; |
| 1080 | } |
Nicolas Capens | fc01454 | 2014-02-18 14:47:13 -0500 | [diff] [blame] | 1081 | else |
| 1082 | { |
| 1083 | addressz = "int(floor(depth * frac(("; |
| 1084 | } |
| 1085 | |
| 1086 | close = "))))"; |
| 1087 | } |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 1088 | } |
| 1089 | else |
| 1090 | { |
| 1091 | switch(hlslCoords) |
| 1092 | { |
| 1093 | case 2: out << "float2("; break; |
| 1094 | case 3: out << "float3("; break; |
| 1095 | case 4: out << "float4("; break; |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 1096 | default: UNREACHABLE(); |
| 1097 | } |
Nicolas Capens | 9fe6f98 | 2013-06-24 16:05:25 -0400 | [diff] [blame] | 1098 | } |
Nicolas Capens | 9fe6f98 | 2013-06-24 16:05:25 -0400 | [diff] [blame] | 1099 | |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 1100 | TString proj = ""; // Only used for projected textures |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 1101 | |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 1102 | if (textureFunction->proj) |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 1103 | { |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 1104 | switch(textureFunction->coords) |
| 1105 | { |
| 1106 | case 3: proj = " / t.z"; break; |
| 1107 | case 4: proj = " / t.w"; break; |
| 1108 | default: UNREACHABLE(); |
| 1109 | } |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 1110 | } |
daniel@transgaming.com | 1579519 | 2011-05-11 15:36:20 +0000 | [diff] [blame] | 1111 | |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 1112 | out << addressx + ("t.x" + proj) + close + ", " + addressy + ("t.y" + proj) + close; |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 1113 | |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 1114 | if (mOutputType == SH_HLSL9_OUTPUT) |
| 1115 | { |
| 1116 | if (hlslCoords >= 3) |
| 1117 | { |
| 1118 | if (textureFunction->coords < 3) |
| 1119 | { |
| 1120 | out << ", 0"; |
| 1121 | } |
| 1122 | else |
| 1123 | { |
| 1124 | out << ", t.z" + proj; |
| 1125 | } |
| 1126 | } |
| 1127 | |
| 1128 | if (hlslCoords == 4) |
| 1129 | { |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 1130 | switch(textureFunction->method) |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 1131 | { |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 1132 | case TextureFunction::BIAS: out << ", bias"; break; |
| 1133 | case TextureFunction::LOD: out << ", lod"; break; |
| 1134 | case TextureFunction::LOD0: out << ", 0"; break; |
| 1135 | case TextureFunction::LOD0BIAS: out << ", bias"; break; |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 1136 | default: UNREACHABLE(); |
| 1137 | } |
| 1138 | } |
| 1139 | |
| 1140 | out << "));\n"; |
| 1141 | } |
| 1142 | else if (mOutputType == SH_HLSL11_OUTPUT) |
| 1143 | { |
| 1144 | if (hlslCoords >= 3) |
| 1145 | { |
Nicolas Capens | 0027fa9 | 2014-02-20 14:26:42 -0500 | [diff] [blame] | 1146 | if (IsIntegerSampler(textureFunction->sampler) && IsSamplerCube(textureFunction->sampler)) |
| 1147 | { |
| 1148 | out << ", face"; |
| 1149 | } |
| 1150 | else |
| 1151 | { |
| 1152 | out << ", " + addressz + ("t.z" + proj) + close; |
| 1153 | } |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 1154 | } |
| 1155 | |
Nicolas Capens | d11d549 | 2014-02-19 17:06:10 -0500 | [diff] [blame] | 1156 | if (textureFunction->method == TextureFunction::GRAD) |
| 1157 | { |
| 1158 | if (IsIntegerSampler(textureFunction->sampler)) |
| 1159 | { |
Nicolas Capens | 0027fa9 | 2014-02-20 14:26:42 -0500 | [diff] [blame] | 1160 | out << ", mip)"; |
Nicolas Capens | d11d549 | 2014-02-19 17:06:10 -0500 | [diff] [blame] | 1161 | } |
| 1162 | else if (IsShadowSampler(textureFunction->sampler)) |
| 1163 | { |
Nicolas Capens | 0027fa9 | 2014-02-20 14:26:42 -0500 | [diff] [blame] | 1164 | // Compare value |
Gregoire Payen de La Garanderie | 5cc9ac8 | 2015-02-20 11:27:56 +0000 | [diff] [blame] | 1165 | if (textureFunction->proj) |
Nicolas Capens | d11d549 | 2014-02-19 17:06:10 -0500 | [diff] [blame] | 1166 | { |
Gregoire Payen de La Garanderie | 5cc9ac8 | 2015-02-20 11:27:56 +0000 | [diff] [blame] | 1167 | // According to ESSL 3.00.4 sec 8.8 p95 on textureProj: |
| 1168 | // The resulting third component of P' in the shadow forms is used as Dref |
| 1169 | out << "), t.z" << proj; |
| 1170 | } |
| 1171 | else |
| 1172 | { |
| 1173 | switch(textureFunction->coords) |
| 1174 | { |
| 1175 | case 3: out << "), t.z"; break; |
| 1176 | case 4: out << "), t.w"; break; |
| 1177 | default: UNREACHABLE(); |
| 1178 | } |
Nicolas Capens | d11d549 | 2014-02-19 17:06:10 -0500 | [diff] [blame] | 1179 | } |
| 1180 | } |
| 1181 | else |
| 1182 | { |
| 1183 | out << "), ddx, ddy"; |
| 1184 | } |
| 1185 | } |
| 1186 | else if (IsIntegerSampler(textureFunction->sampler) || |
| 1187 | textureFunction->method == TextureFunction::FETCH) |
Nicolas Capens | cb127d3 | 2013-07-15 17:26:18 -0400 | [diff] [blame] | 1188 | { |
Nicolas Capens | b1f45b7 | 2013-12-19 17:37:19 -0500 | [diff] [blame] | 1189 | out << ", mip)"; |
Nicolas Capens | cb127d3 | 2013-07-15 17:26:18 -0400 | [diff] [blame] | 1190 | } |
| 1191 | else if (IsShadowSampler(textureFunction->sampler)) |
| 1192 | { |
| 1193 | // Compare value |
Gregoire Payen de La Garanderie | 5cc9ac8 | 2015-02-20 11:27:56 +0000 | [diff] [blame] | 1194 | if (textureFunction->proj) |
Nicolas Capens | cb127d3 | 2013-07-15 17:26:18 -0400 | [diff] [blame] | 1195 | { |
Gregoire Payen de La Garanderie | 5cc9ac8 | 2015-02-20 11:27:56 +0000 | [diff] [blame] | 1196 | // According to ESSL 3.00.4 sec 8.8 p95 on textureProj: |
| 1197 | // The resulting third component of P' in the shadow forms is used as Dref |
| 1198 | out << "), t.z" << proj; |
| 1199 | } |
| 1200 | else |
| 1201 | { |
| 1202 | switch(textureFunction->coords) |
| 1203 | { |
| 1204 | case 3: out << "), t.z"; break; |
| 1205 | case 4: out << "), t.w"; break; |
| 1206 | default: UNREACHABLE(); |
| 1207 | } |
Nicolas Capens | cb127d3 | 2013-07-15 17:26:18 -0400 | [diff] [blame] | 1208 | } |
| 1209 | } |
| 1210 | else |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 1211 | { |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 1212 | switch(textureFunction->method) |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 1213 | { |
Nicolas Capens | b1f45b7 | 2013-12-19 17:37:19 -0500 | [diff] [blame] | 1214 | case TextureFunction::IMPLICIT: out << ")"; break; |
| 1215 | case TextureFunction::BIAS: out << "), bias"; break; |
| 1216 | case TextureFunction::LOD: out << "), lod"; break; |
| 1217 | case TextureFunction::LOD0: out << "), 0"; break; |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 1218 | case TextureFunction::LOD0BIAS: out << "), bias"; break; |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 1219 | default: UNREACHABLE(); |
| 1220 | } |
| 1221 | } |
Nicolas Capens | b1f45b7 | 2013-12-19 17:37:19 -0500 | [diff] [blame] | 1222 | |
| 1223 | if (textureFunction->offset) |
| 1224 | { |
| 1225 | out << ", offset"; |
| 1226 | } |
| 1227 | |
| 1228 | out << ");"; |
Nicolas Capens | 6d232bb | 2013-07-08 15:56:38 -0400 | [diff] [blame] | 1229 | } |
| 1230 | else UNREACHABLE(); |
| 1231 | } |
| 1232 | |
| 1233 | out << "\n" |
| 1234 | "}\n" |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 1235 | "\n"; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1236 | } |
| 1237 | |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 1238 | if (mUsesFragCoord) |
| 1239 | { |
| 1240 | out << "#define GL_USES_FRAG_COORD\n"; |
| 1241 | } |
| 1242 | |
| 1243 | if (mUsesPointCoord) |
| 1244 | { |
| 1245 | out << "#define GL_USES_POINT_COORD\n"; |
| 1246 | } |
| 1247 | |
| 1248 | if (mUsesFrontFacing) |
| 1249 | { |
| 1250 | out << "#define GL_USES_FRONT_FACING\n"; |
| 1251 | } |
| 1252 | |
| 1253 | if (mUsesPointSize) |
| 1254 | { |
| 1255 | out << "#define GL_USES_POINT_SIZE\n"; |
| 1256 | } |
| 1257 | |
Jamie Madill | 2aeb26a | 2013-07-08 14:02:55 -0400 | [diff] [blame] | 1258 | if (mUsesFragDepth) |
| 1259 | { |
| 1260 | out << "#define GL_USES_FRAG_DEPTH\n"; |
| 1261 | } |
| 1262 | |
shannonwoods@chromium.org | 0329988 | 2013-05-30 00:05:26 +0000 | [diff] [blame] | 1263 | if (mUsesDepthRange) |
| 1264 | { |
| 1265 | out << "#define GL_USES_DEPTH_RANGE\n"; |
| 1266 | } |
| 1267 | |
daniel@transgaming.com | d7c9810 | 2010-05-14 17:30:48 +0000 | [diff] [blame] | 1268 | if (mUsesXor) |
| 1269 | { |
| 1270 | out << "bool xor(bool p, bool q)\n" |
| 1271 | "{\n" |
| 1272 | " return (p || q) && !(p && q);\n" |
| 1273 | "}\n" |
| 1274 | "\n"; |
| 1275 | } |
| 1276 | |
Olli Etuaho | 95cd3c6 | 2015-03-03 16:45:32 +0200 | [diff] [blame] | 1277 | builtInFunctionEmulator->OutputEmulatedFunctions(out); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | void OutputHLSL::visitSymbol(TIntermSymbol *node) |
| 1281 | { |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame] | 1282 | TInfoSinkBase &out = getInfoSink(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1283 | |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 1284 | // Handle accessing std140 structs by value |
| 1285 | if (mFlaggedStructMappedNames.count(node) > 0) |
| 1286 | { |
| 1287 | out << mFlaggedStructMappedNames[node]; |
| 1288 | return; |
| 1289 | } |
| 1290 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1291 | TString name = node->getSymbol(); |
| 1292 | |
shannon.woods%transgaming.com@gtempaccount.com | e7d4a24 | 2013-04-13 03:38:33 +0000 | [diff] [blame] | 1293 | if (name == "gl_DepthRange") |
daniel@transgaming.com | d7c9810 | 2010-05-14 17:30:48 +0000 | [diff] [blame] | 1294 | { |
| 1295 | mUsesDepthRange = true; |
| 1296 | out << name; |
| 1297 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1298 | else |
| 1299 | { |
daniel@transgaming.com | 86f7c9d | 2010-04-20 18:52:06 +0000 | [diff] [blame] | 1300 | TQualifier qualifier = node->getQualifier(); |
| 1301 | |
| 1302 | if (qualifier == EvqUniform) |
| 1303 | { |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 1304 | const TType& nodeType = node->getType(); |
| 1305 | const TInterfaceBlock* interfaceBlock = nodeType.getInterfaceBlock(); |
| 1306 | |
| 1307 | if (interfaceBlock) |
shannonwoods@chromium.org | 4a643ae | 2013-05-30 00:12:27 +0000 | [diff] [blame] | 1308 | { |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 1309 | mReferencedInterfaceBlocks[interfaceBlock->name()] = node; |
shannonwoods@chromium.org | 4430b0d | 2013-05-30 00:12:34 +0000 | [diff] [blame] | 1310 | } |
shannonwoods@chromium.org | 4a643ae | 2013-05-30 00:12:27 +0000 | [diff] [blame] | 1311 | else |
| 1312 | { |
| 1313 | mReferencedUniforms[name] = node; |
shannonwoods@chromium.org | 4a643ae | 2013-05-30 00:12:27 +0000 | [diff] [blame] | 1314 | } |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 1315 | |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 1316 | out << DecorateUniform(name, nodeType); |
daniel@transgaming.com | 86f7c9d | 2010-04-20 18:52:06 +0000 | [diff] [blame] | 1317 | } |
Jamie Madill | 1957181 | 2013-08-12 15:26:34 -0700 | [diff] [blame] | 1318 | else if (qualifier == EvqAttribute || qualifier == EvqVertexIn) |
daniel@transgaming.com | 86f7c9d | 2010-04-20 18:52:06 +0000 | [diff] [blame] | 1319 | { |
daniel@transgaming.com | 8803b85 | 2012-12-20 21:11:47 +0000 | [diff] [blame] | 1320 | mReferencedAttributes[name] = node; |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 1321 | out << Decorate(name); |
daniel@transgaming.com | 86f7c9d | 2010-04-20 18:52:06 +0000 | [diff] [blame] | 1322 | } |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 1323 | else if (IsVarying(qualifier)) |
daniel@transgaming.com | 86f7c9d | 2010-04-20 18:52:06 +0000 | [diff] [blame] | 1324 | { |
daniel@transgaming.com | 8803b85 | 2012-12-20 21:11:47 +0000 | [diff] [blame] | 1325 | mReferencedVaryings[name] = node; |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 1326 | out << Decorate(name); |
daniel@transgaming.com | 86f7c9d | 2010-04-20 18:52:06 +0000 | [diff] [blame] | 1327 | } |
Jamie Madill | 1957181 | 2013-08-12 15:26:34 -0700 | [diff] [blame] | 1328 | else if (qualifier == EvqFragmentOut) |
Jamie Madill | 46131a3 | 2013-06-20 11:55:50 -0400 | [diff] [blame] | 1329 | { |
| 1330 | mReferencedOutputVariables[name] = node; |
| 1331 | out << "out_" << name; |
| 1332 | } |
| 1333 | else if (qualifier == EvqFragColor) |
shannon.woods%transgaming.com@gtempaccount.com | e7d4a24 | 2013-04-13 03:38:33 +0000 | [diff] [blame] | 1334 | { |
| 1335 | out << "gl_Color[0]"; |
| 1336 | mUsesFragColor = true; |
| 1337 | } |
| 1338 | else if (qualifier == EvqFragData) |
| 1339 | { |
| 1340 | out << "gl_Color"; |
| 1341 | mUsesFragData = true; |
| 1342 | } |
| 1343 | else if (qualifier == EvqFragCoord) |
| 1344 | { |
| 1345 | mUsesFragCoord = true; |
| 1346 | out << name; |
| 1347 | } |
| 1348 | else if (qualifier == EvqPointCoord) |
| 1349 | { |
| 1350 | mUsesPointCoord = true; |
| 1351 | out << name; |
| 1352 | } |
| 1353 | else if (qualifier == EvqFrontFacing) |
| 1354 | { |
| 1355 | mUsesFrontFacing = true; |
| 1356 | out << name; |
| 1357 | } |
| 1358 | else if (qualifier == EvqPointSize) |
| 1359 | { |
| 1360 | mUsesPointSize = true; |
| 1361 | out << name; |
| 1362 | } |
Gregoire Payen de La Garanderie | b3dced2 | 2015-01-12 14:54:55 +0000 | [diff] [blame] | 1363 | else if (qualifier == EvqInstanceID) |
| 1364 | { |
| 1365 | mUsesInstanceID = true; |
| 1366 | out << name; |
| 1367 | } |
Jamie Madill | 2aeb26a | 2013-07-08 14:02:55 -0400 | [diff] [blame] | 1368 | else if (name == "gl_FragDepthEXT") |
| 1369 | { |
| 1370 | mUsesFragDepth = true; |
| 1371 | out << "gl_Depth"; |
| 1372 | } |
Jamie Madill | e53c98b | 2014-02-03 11:57:13 -0500 | [diff] [blame] | 1373 | else if (qualifier == EvqInternal) |
| 1374 | { |
| 1375 | out << name; |
| 1376 | } |
daniel@transgaming.com | c72c641 | 2011-09-20 16:09:17 +0000 | [diff] [blame] | 1377 | else |
| 1378 | { |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 1379 | out << Decorate(name); |
daniel@transgaming.com | c72c641 | 2011-09-20 16:09:17 +0000 | [diff] [blame] | 1380 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1381 | } |
| 1382 | } |
| 1383 | |
Jamie Madill | 4cfb1e8 | 2014-07-07 12:49:23 -0400 | [diff] [blame] | 1384 | void OutputHLSL::visitRaw(TIntermRaw *node) |
| 1385 | { |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame] | 1386 | getInfoSink() << node->getRawText(); |
Jamie Madill | 4cfb1e8 | 2014-07-07 12:49:23 -0400 | [diff] [blame] | 1387 | } |
| 1388 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1389 | bool OutputHLSL::visitBinary(Visit visit, TIntermBinary *node) |
| 1390 | { |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame] | 1391 | TInfoSinkBase &out = getInfoSink(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1392 | |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 1393 | // Handle accessing std140 structs by value |
| 1394 | if (mFlaggedStructMappedNames.count(node) > 0) |
| 1395 | { |
| 1396 | out << mFlaggedStructMappedNames[node]; |
| 1397 | return false; |
| 1398 | } |
| 1399 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1400 | switch (node->getOp()) |
| 1401 | { |
daniel@transgaming.com | 93a96c3 | 2010-03-28 19:36:13 +0000 | [diff] [blame] | 1402 | case EOpAssign: outputTriplet(visit, "(", " = ", ")"); break; |
daniel@transgaming.com | b6ef8f1 | 2010-11-15 16:41:14 +0000 | [diff] [blame] | 1403 | case EOpInitialize: |
| 1404 | if (visit == PreVisit) |
| 1405 | { |
| 1406 | // GLSL allows to write things like "float x = x;" where a new variable x is defined |
| 1407 | // and the value of an existing variable x is assigned. HLSL uses C semantics (the |
| 1408 | // new variable is created before the assignment is evaluated), so we need to convert |
| 1409 | // this to "float t = x, x = t;". |
| 1410 | |
daniel@transgaming.com | bdfb2e5 | 2010-11-15 16:41:20 +0000 | [diff] [blame] | 1411 | TIntermSymbol *symbolNode = node->getLeft()->getAsSymbolNode(); |
Jamie Madill | 3799714 | 2015-01-28 10:06:34 -0500 | [diff] [blame] | 1412 | ASSERT(symbolNode); |
daniel@transgaming.com | bdfb2e5 | 2010-11-15 16:41:20 +0000 | [diff] [blame] | 1413 | TIntermTyped *expression = node->getRight(); |
daniel@transgaming.com | b6ef8f1 | 2010-11-15 16:41:14 +0000 | [diff] [blame] | 1414 | |
Jamie Madill | 3799714 | 2015-01-28 10:06:34 -0500 | [diff] [blame] | 1415 | // TODO (jmadill): do a 'deep' scan to know if an expression is statically const |
| 1416 | if (symbolNode->getQualifier() == EvqGlobal && expression->getQualifier() != EvqConst) |
daniel@transgaming.com | bdfb2e5 | 2010-11-15 16:41:20 +0000 | [diff] [blame] | 1417 | { |
Jamie Madill | 3799714 | 2015-01-28 10:06:34 -0500 | [diff] [blame] | 1418 | // For variables which are not constant, defer their real initialization until |
| 1419 | // after we initialize other globals: uniforms, attributes and varyings. |
| 1420 | mDeferredGlobalInitializers.push_back(std::make_pair(symbolNode, expression)); |
| 1421 | const TString &initString = initializer(node->getType()); |
| 1422 | node->setRight(new TIntermRaw(node->getType(), initString)); |
| 1423 | } |
| 1424 | else if (writeSameSymbolInitializer(out, symbolNode, expression)) |
| 1425 | { |
| 1426 | // Skip initializing the rest of the expression |
daniel@transgaming.com | bdfb2e5 | 2010-11-15 16:41:20 +0000 | [diff] [blame] | 1427 | return false; |
| 1428 | } |
| 1429 | } |
| 1430 | else if (visit == InVisit) |
| 1431 | { |
| 1432 | out << " = "; |
daniel@transgaming.com | b6ef8f1 | 2010-11-15 16:41:14 +0000 | [diff] [blame] | 1433 | } |
| 1434 | break; |
daniel@transgaming.com | 93a96c3 | 2010-03-28 19:36:13 +0000 | [diff] [blame] | 1435 | case EOpAddAssign: outputTriplet(visit, "(", " += ", ")"); break; |
| 1436 | case EOpSubAssign: outputTriplet(visit, "(", " -= ", ")"); break; |
| 1437 | case EOpMulAssign: outputTriplet(visit, "(", " *= ", ")"); break; |
| 1438 | case EOpVectorTimesScalarAssign: outputTriplet(visit, "(", " *= ", ")"); break; |
| 1439 | case EOpMatrixTimesScalarAssign: outputTriplet(visit, "(", " *= ", ")"); break; |
| 1440 | case EOpVectorTimesMatrixAssign: |
daniel@transgaming.com | 8976c1e | 2010-04-13 19:53:27 +0000 | [diff] [blame] | 1441 | if (visit == PreVisit) |
| 1442 | { |
| 1443 | out << "("; |
| 1444 | } |
| 1445 | else if (visit == InVisit) |
| 1446 | { |
| 1447 | out << " = mul("; |
| 1448 | node->getLeft()->traverse(this); |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 1449 | out << ", transpose("; |
daniel@transgaming.com | 8976c1e | 2010-04-13 19:53:27 +0000 | [diff] [blame] | 1450 | } |
| 1451 | else |
| 1452 | { |
daniel@transgaming.com | 3aa7420 | 2010-04-29 03:39:04 +0000 | [diff] [blame] | 1453 | out << ")))"; |
daniel@transgaming.com | 8976c1e | 2010-04-13 19:53:27 +0000 | [diff] [blame] | 1454 | } |
| 1455 | break; |
daniel@transgaming.com | 93a96c3 | 2010-03-28 19:36:13 +0000 | [diff] [blame] | 1456 | case EOpMatrixTimesMatrixAssign: |
| 1457 | if (visit == PreVisit) |
| 1458 | { |
| 1459 | out << "("; |
| 1460 | } |
| 1461 | else if (visit == InVisit) |
| 1462 | { |
Olli Etuaho | fc7fab7 | 2015-03-06 12:03:18 +0200 | [diff] [blame] | 1463 | out << " = transpose(mul(transpose("; |
daniel@transgaming.com | 93a96c3 | 2010-03-28 19:36:13 +0000 | [diff] [blame] | 1464 | node->getLeft()->traverse(this); |
Olli Etuaho | fc7fab7 | 2015-03-06 12:03:18 +0200 | [diff] [blame] | 1465 | out << "), transpose("; |
daniel@transgaming.com | 93a96c3 | 2010-03-28 19:36:13 +0000 | [diff] [blame] | 1466 | } |
| 1467 | else |
| 1468 | { |
Olli Etuaho | fc7fab7 | 2015-03-06 12:03:18 +0200 | [diff] [blame] | 1469 | out << "))))"; |
daniel@transgaming.com | 93a96c3 | 2010-03-28 19:36:13 +0000 | [diff] [blame] | 1470 | } |
| 1471 | break; |
| 1472 | case EOpDivAssign: outputTriplet(visit, "(", " /= ", ")"); break; |
Olli Etuaho | ff805cc | 2015-02-13 10:59:34 +0200 | [diff] [blame] | 1473 | case EOpIModAssign: outputTriplet(visit, "(", " %= ", ")"); break; |
Olli Etuaho | 31b5fc6 | 2015-01-16 12:13:36 +0200 | [diff] [blame] | 1474 | case EOpBitShiftLeftAssign: outputTriplet(visit, "(", " <<= ", ")"); break; |
| 1475 | case EOpBitShiftRightAssign: outputTriplet(visit, "(", " >>= ", ")"); break; |
| 1476 | case EOpBitwiseAndAssign: outputTriplet(visit, "(", " &= ", ")"); break; |
| 1477 | case EOpBitwiseXorAssign: outputTriplet(visit, "(", " ^= ", ")"); break; |
| 1478 | case EOpBitwiseOrAssign: outputTriplet(visit, "(", " |= ", ")"); break; |
Jamie Madill | b4e664b | 2013-06-20 11:55:54 -0400 | [diff] [blame] | 1479 | case EOpIndexDirect: |
Jamie Madill | b4e664b | 2013-06-20 11:55:54 -0400 | [diff] [blame] | 1480 | { |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 1481 | const TType& leftType = node->getLeft()->getType(); |
| 1482 | if (leftType.isInterfaceBlock()) |
Jamie Madill | b4e664b | 2013-06-20 11:55:54 -0400 | [diff] [blame] | 1483 | { |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 1484 | if (visit == PreVisit) |
| 1485 | { |
| 1486 | TInterfaceBlock* interfaceBlock = leftType.getInterfaceBlock(); |
| 1487 | const int arrayIndex = node->getRight()->getAsConstantUnion()->getIConst(0); |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 1488 | mReferencedInterfaceBlocks[interfaceBlock->instanceName()] = node->getLeft()->getAsSymbolNode(); |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 1489 | out << mUniformHLSL->interfaceBlockInstanceString(*interfaceBlock, arrayIndex); |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 1490 | return false; |
| 1491 | } |
Jamie Madill | b4e664b | 2013-06-20 11:55:54 -0400 | [diff] [blame] | 1492 | } |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 1493 | else |
| 1494 | { |
| 1495 | outputTriplet(visit, "", "[", "]"); |
| 1496 | } |
Jamie Madill | b4e664b | 2013-06-20 11:55:54 -0400 | [diff] [blame] | 1497 | } |
| 1498 | break; |
| 1499 | case EOpIndexIndirect: |
| 1500 | // We do not currently support indirect references to interface blocks |
| 1501 | ASSERT(node->getLeft()->getBasicType() != EbtInterfaceBlock); |
| 1502 | outputTriplet(visit, "", "[", "]"); |
| 1503 | break; |
daniel@transgaming.com | a54da4e | 2010-05-07 13:03:28 +0000 | [diff] [blame] | 1504 | case EOpIndexDirectStruct: |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 1505 | if (visit == InVisit) |
| 1506 | { |
| 1507 | const TStructure* structure = node->getLeft()->getType().getStruct(); |
| 1508 | const TIntermConstantUnion* index = node->getRight()->getAsConstantUnion(); |
| 1509 | const TField* field = structure->fields()[index->getIConst(0)]; |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 1510 | out << "." + DecorateField(field->name(), *structure); |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 1511 | |
| 1512 | return false; |
| 1513 | } |
| 1514 | break; |
shannonwoods@chromium.org | 4430b0d | 2013-05-30 00:12:34 +0000 | [diff] [blame] | 1515 | case EOpIndexDirectInterfaceBlock: |
daniel@transgaming.com | a54da4e | 2010-05-07 13:03:28 +0000 | [diff] [blame] | 1516 | if (visit == InVisit) |
| 1517 | { |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 1518 | const TInterfaceBlock* interfaceBlock = node->getLeft()->getType().getInterfaceBlock(); |
| 1519 | const TIntermConstantUnion* index = node->getRight()->getAsConstantUnion(); |
| 1520 | const TField* field = interfaceBlock->fields()[index->getIConst(0)]; |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 1521 | out << "." + Decorate(field->name()); |
daniel@transgaming.com | a54da4e | 2010-05-07 13:03:28 +0000 | [diff] [blame] | 1522 | |
| 1523 | return false; |
| 1524 | } |
| 1525 | break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1526 | case EOpVectorSwizzle: |
| 1527 | if (visit == InVisit) |
| 1528 | { |
| 1529 | out << "."; |
| 1530 | |
| 1531 | TIntermAggregate *swizzle = node->getRight()->getAsAggregate(); |
| 1532 | |
| 1533 | if (swizzle) |
| 1534 | { |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 1535 | TIntermSequence *sequence = swizzle->getSequence(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1536 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 1537 | for (TIntermSequence::iterator sit = sequence->begin(); sit != sequence->end(); sit++) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1538 | { |
| 1539 | TIntermConstantUnion *element = (*sit)->getAsConstantUnion(); |
| 1540 | |
| 1541 | if (element) |
| 1542 | { |
shannon.woods%transgaming.com@gtempaccount.com | c0d0c22 | 2013-04-13 03:29:36 +0000 | [diff] [blame] | 1543 | int i = element->getIConst(0); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1544 | |
| 1545 | switch (i) |
| 1546 | { |
| 1547 | case 0: out << "x"; break; |
| 1548 | case 1: out << "y"; break; |
| 1549 | case 2: out << "z"; break; |
| 1550 | case 3: out << "w"; break; |
| 1551 | default: UNREACHABLE(); |
| 1552 | } |
| 1553 | } |
| 1554 | else UNREACHABLE(); |
| 1555 | } |
| 1556 | } |
| 1557 | else UNREACHABLE(); |
| 1558 | |
| 1559 | return false; // Fully processed |
| 1560 | } |
| 1561 | break; |
| 1562 | case EOpAdd: outputTriplet(visit, "(", " + ", ")"); break; |
| 1563 | case EOpSub: outputTriplet(visit, "(", " - ", ")"); break; |
| 1564 | case EOpMul: outputTriplet(visit, "(", " * ", ")"); break; |
| 1565 | case EOpDiv: outputTriplet(visit, "(", " / ", ")"); break; |
Olli Etuaho | ff805cc | 2015-02-13 10:59:34 +0200 | [diff] [blame] | 1566 | case EOpIMod: outputTriplet(visit, "(", " % ", ")"); break; |
Olli Etuaho | 31b5fc6 | 2015-01-16 12:13:36 +0200 | [diff] [blame] | 1567 | case EOpBitShiftLeft: outputTriplet(visit, "(", " << ", ")"); break; |
| 1568 | case EOpBitShiftRight: outputTriplet(visit, "(", " >> ", ")"); break; |
| 1569 | case EOpBitwiseAnd: outputTriplet(visit, "(", " & ", ")"); break; |
| 1570 | case EOpBitwiseXor: outputTriplet(visit, "(", " ^ ", ")"); break; |
| 1571 | case EOpBitwiseOr: outputTriplet(visit, "(", " | ", ")"); break; |
daniel@transgaming.com | 49bce7e | 2010-03-17 03:58:51 +0000 | [diff] [blame] | 1572 | case EOpEqual: |
daniel@transgaming.com | 49bce7e | 2010-03-17 03:58:51 +0000 | [diff] [blame] | 1573 | case EOpNotEqual: |
daniel@transgaming.com | d91cfe7 | 2010-04-13 03:26:17 +0000 | [diff] [blame] | 1574 | if (node->getLeft()->isScalar()) |
daniel@transgaming.com | 49bce7e | 2010-03-17 03:58:51 +0000 | [diff] [blame] | 1575 | { |
daniel@transgaming.com | d91cfe7 | 2010-04-13 03:26:17 +0000 | [diff] [blame] | 1576 | if (node->getOp() == EOpEqual) |
| 1577 | { |
| 1578 | outputTriplet(visit, "(", " == ", ")"); |
| 1579 | } |
| 1580 | else |
| 1581 | { |
| 1582 | outputTriplet(visit, "(", " != ", ")"); |
| 1583 | } |
| 1584 | } |
daniel@transgaming.com | 49bce7e | 2010-03-17 03:58:51 +0000 | [diff] [blame] | 1585 | else |
| 1586 | { |
Jamie Madill | 55e79e0 | 2015-02-09 15:35:00 -0500 | [diff] [blame] | 1587 | if (visit == PreVisit && node->getOp() == EOpNotEqual) |
daniel@transgaming.com | d91cfe7 | 2010-04-13 03:26:17 +0000 | [diff] [blame] | 1588 | { |
Jamie Madill | 55e79e0 | 2015-02-09 15:35:00 -0500 | [diff] [blame] | 1589 | out << "!"; |
| 1590 | } |
| 1591 | |
| 1592 | if (node->getLeft()->getBasicType() == EbtStruct) |
| 1593 | { |
| 1594 | const TStructure &structure = *node->getLeft()->getType().getStruct(); |
| 1595 | const TString &functionName = addStructEqualityFunction(structure); |
Daniel Bratell | 2919008 | 2015-02-20 16:42:54 +0100 | [diff] [blame] | 1596 | outputTriplet(visit, (functionName + "(").c_str(), ", ", ")"); |
daniel@transgaming.com | d91cfe7 | 2010-04-13 03:26:17 +0000 | [diff] [blame] | 1597 | } |
| 1598 | else |
| 1599 | { |
Jamie Madill | 55e79e0 | 2015-02-09 15:35:00 -0500 | [diff] [blame] | 1600 | ASSERT(node->getLeft()->isMatrix() || node->getLeft()->isVector()); |
| 1601 | outputTriplet(visit, "all(", " == ", ")"); |
daniel@transgaming.com | d91cfe7 | 2010-04-13 03:26:17 +0000 | [diff] [blame] | 1602 | } |
daniel@transgaming.com | 49bce7e | 2010-03-17 03:58:51 +0000 | [diff] [blame] | 1603 | } |
| 1604 | break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1605 | case EOpLessThan: outputTriplet(visit, "(", " < ", ")"); break; |
| 1606 | case EOpGreaterThan: outputTriplet(visit, "(", " > ", ")"); break; |
| 1607 | case EOpLessThanEqual: outputTriplet(visit, "(", " <= ", ")"); break; |
| 1608 | case EOpGreaterThanEqual: outputTriplet(visit, "(", " >= ", ")"); break; |
| 1609 | case EOpVectorTimesScalar: outputTriplet(visit, "(", " * ", ")"); break; |
daniel@transgaming.com | 93a96c3 | 2010-03-28 19:36:13 +0000 | [diff] [blame] | 1610 | case EOpMatrixTimesScalar: outputTriplet(visit, "(", " * ", ")"); break; |
daniel@transgaming.com | 8976c1e | 2010-04-13 19:53:27 +0000 | [diff] [blame] | 1611 | case EOpVectorTimesMatrix: outputTriplet(visit, "mul(", ", transpose(", "))"); break; |
| 1612 | case EOpMatrixTimesVector: outputTriplet(visit, "mul(transpose(", "), ", ")"); break; |
daniel@transgaming.com | 69f084b | 2010-04-23 18:34:46 +0000 | [diff] [blame] | 1613 | case EOpMatrixTimesMatrix: outputTriplet(visit, "transpose(mul(transpose(", "), transpose(", ")))"); break; |
daniel@transgaming.com | 8915eba | 2012-04-28 00:34:44 +0000 | [diff] [blame] | 1614 | case EOpLogicalOr: |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 1615 | if (node->getRight()->hasSideEffects()) |
| 1616 | { |
| 1617 | out << "s" << mUnfoldShortCircuit->getNextTemporaryIndex(); |
| 1618 | return false; |
| 1619 | } |
| 1620 | else |
| 1621 | { |
| 1622 | outputTriplet(visit, "(", " || ", ")"); |
| 1623 | return true; |
| 1624 | } |
daniel@transgaming.com | d7c9810 | 2010-05-14 17:30:48 +0000 | [diff] [blame] | 1625 | case EOpLogicalXor: |
| 1626 | mUsesXor = true; |
| 1627 | outputTriplet(visit, "xor(", ", ", ")"); |
| 1628 | break; |
daniel@transgaming.com | 8915eba | 2012-04-28 00:34:44 +0000 | [diff] [blame] | 1629 | case EOpLogicalAnd: |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 1630 | if (node->getRight()->hasSideEffects()) |
| 1631 | { |
| 1632 | out << "s" << mUnfoldShortCircuit->getNextTemporaryIndex(); |
| 1633 | return false; |
| 1634 | } |
| 1635 | else |
| 1636 | { |
| 1637 | outputTriplet(visit, "(", " && ", ")"); |
| 1638 | return true; |
| 1639 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1640 | default: UNREACHABLE(); |
| 1641 | } |
| 1642 | |
| 1643 | return true; |
| 1644 | } |
| 1645 | |
| 1646 | bool OutputHLSL::visitUnary(Visit visit, TIntermUnary *node) |
| 1647 | { |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1648 | switch (node->getOp()) |
| 1649 | { |
Nicolas Capens | 16004fc | 2014-06-11 11:29:11 -0400 | [diff] [blame] | 1650 | case EOpNegative: outputTriplet(visit, "(-", "", ")"); break; |
Zhenyao Mo | de1e00e | 2014-10-09 16:55:32 -0700 | [diff] [blame] | 1651 | case EOpPositive: outputTriplet(visit, "(+", "", ")"); break; |
Nicolas Capens | 16004fc | 2014-06-11 11:29:11 -0400 | [diff] [blame] | 1652 | case EOpVectorLogicalNot: outputTriplet(visit, "(!", "", ")"); break; |
| 1653 | case EOpLogicalNot: outputTriplet(visit, "(!", "", ")"); break; |
Olli Etuaho | 31b5fc6 | 2015-01-16 12:13:36 +0200 | [diff] [blame] | 1654 | case EOpBitwiseNot: outputTriplet(visit, "(~", "", ")"); break; |
Nicolas Capens | 16004fc | 2014-06-11 11:29:11 -0400 | [diff] [blame] | 1655 | case EOpPostIncrement: outputTriplet(visit, "(", "", "++)"); break; |
| 1656 | case EOpPostDecrement: outputTriplet(visit, "(", "", "--)"); break; |
| 1657 | case EOpPreIncrement: outputTriplet(visit, "(++", "", ")"); break; |
| 1658 | case EOpPreDecrement: outputTriplet(visit, "(--", "", ")"); break; |
daniel@transgaming.com | 67de6d6 | 2010-04-29 03:35:30 +0000 | [diff] [blame] | 1659 | case EOpRadians: outputTriplet(visit, "radians(", "", ")"); break; |
| 1660 | case EOpDegrees: outputTriplet(visit, "degrees(", "", ")"); break; |
| 1661 | case EOpSin: outputTriplet(visit, "sin(", "", ")"); break; |
| 1662 | case EOpCos: outputTriplet(visit, "cos(", "", ")"); break; |
| 1663 | case EOpTan: outputTriplet(visit, "tan(", "", ")"); break; |
| 1664 | case EOpAsin: outputTriplet(visit, "asin(", "", ")"); break; |
| 1665 | case EOpAcos: outputTriplet(visit, "acos(", "", ")"); break; |
| 1666 | case EOpAtan: outputTriplet(visit, "atan(", "", ")"); break; |
Olli Etuaho | 5c9cd3d | 2014-12-18 13:04:25 +0200 | [diff] [blame] | 1667 | case EOpSinh: outputTriplet(visit, "sinh(", "", ")"); break; |
| 1668 | case EOpCosh: outputTriplet(visit, "cosh(", "", ")"); break; |
| 1669 | case EOpTanh: outputTriplet(visit, "tanh(", "", ")"); break; |
| 1670 | case EOpAsinh: |
| 1671 | ASSERT(node->getUseEmulatedFunction()); |
| 1672 | writeEmulatedFunctionTriplet(visit, "asinh("); |
| 1673 | break; |
| 1674 | case EOpAcosh: |
| 1675 | ASSERT(node->getUseEmulatedFunction()); |
| 1676 | writeEmulatedFunctionTriplet(visit, "acosh("); |
| 1677 | break; |
| 1678 | case EOpAtanh: |
| 1679 | ASSERT(node->getUseEmulatedFunction()); |
| 1680 | writeEmulatedFunctionTriplet(visit, "atanh("); |
| 1681 | break; |
daniel@transgaming.com | 67de6d6 | 2010-04-29 03:35:30 +0000 | [diff] [blame] | 1682 | case EOpExp: outputTriplet(visit, "exp(", "", ")"); break; |
| 1683 | case EOpLog: outputTriplet(visit, "log(", "", ")"); break; |
| 1684 | case EOpExp2: outputTriplet(visit, "exp2(", "", ")"); break; |
| 1685 | case EOpLog2: outputTriplet(visit, "log2(", "", ")"); break; |
| 1686 | case EOpSqrt: outputTriplet(visit, "sqrt(", "", ")"); break; |
| 1687 | case EOpInverseSqrt: outputTriplet(visit, "rsqrt(", "", ")"); break; |
| 1688 | case EOpAbs: outputTriplet(visit, "abs(", "", ")"); break; |
| 1689 | case EOpSign: outputTriplet(visit, "sign(", "", ")"); break; |
| 1690 | case EOpFloor: outputTriplet(visit, "floor(", "", ")"); break; |
Qingqing Deng | 5dbece5 | 2015-02-27 20:35:38 -0800 | [diff] [blame] | 1691 | case EOpTrunc: outputTriplet(visit, "trunc(", "", ")"); break; |
| 1692 | case EOpRound: outputTriplet(visit, "round(", "", ")"); break; |
| 1693 | case EOpRoundEven: |
| 1694 | ASSERT(node->getUseEmulatedFunction()); |
| 1695 | writeEmulatedFunctionTriplet(visit, "roundEven("); |
| 1696 | break; |
daniel@transgaming.com | 67de6d6 | 2010-04-29 03:35:30 +0000 | [diff] [blame] | 1697 | case EOpCeil: outputTriplet(visit, "ceil(", "", ")"); break; |
| 1698 | case EOpFract: outputTriplet(visit, "frac(", "", ")"); break; |
Arun Patole | 44efa0b | 2015-03-04 17:11:05 +0530 | [diff] [blame] | 1699 | case EOpIsNan: |
| 1700 | outputTriplet(visit, "isnan(", "", ")"); |
| 1701 | mRequiresIEEEStrictCompiling = true; |
| 1702 | break; |
Arun Patole | 0c1726e | 2015-02-18 14:35:02 +0530 | [diff] [blame] | 1703 | case EOpIsInf: outputTriplet(visit, "isinf(", "", ")"); break; |
Olli Etuaho | e8d2c07 | 2015-01-08 16:33:54 +0200 | [diff] [blame] | 1704 | case EOpFloatBitsToInt: outputTriplet(visit, "asint(", "", ")"); break; |
| 1705 | case EOpFloatBitsToUint: outputTriplet(visit, "asuint(", "", ")"); break; |
| 1706 | case EOpIntBitsToFloat: outputTriplet(visit, "asfloat(", "", ")"); break; |
| 1707 | case EOpUintBitsToFloat: outputTriplet(visit, "asfloat(", "", ")"); break; |
Olli Etuaho | 7700ff6 | 2015-01-15 12:16:29 +0200 | [diff] [blame] | 1708 | case EOpPackSnorm2x16: |
| 1709 | ASSERT(node->getUseEmulatedFunction()); |
| 1710 | writeEmulatedFunctionTriplet(visit, "packSnorm2x16("); |
| 1711 | break; |
| 1712 | case EOpPackUnorm2x16: |
| 1713 | ASSERT(node->getUseEmulatedFunction()); |
| 1714 | writeEmulatedFunctionTriplet(visit, "packUnorm2x16("); |
| 1715 | break; |
| 1716 | case EOpPackHalf2x16: |
| 1717 | ASSERT(node->getUseEmulatedFunction()); |
| 1718 | writeEmulatedFunctionTriplet(visit, "packHalf2x16("); |
| 1719 | break; |
| 1720 | case EOpUnpackSnorm2x16: |
| 1721 | ASSERT(node->getUseEmulatedFunction()); |
| 1722 | writeEmulatedFunctionTriplet(visit, "unpackSnorm2x16("); |
| 1723 | break; |
| 1724 | case EOpUnpackUnorm2x16: |
| 1725 | ASSERT(node->getUseEmulatedFunction()); |
| 1726 | writeEmulatedFunctionTriplet(visit, "unpackUnorm2x16("); |
| 1727 | break; |
| 1728 | case EOpUnpackHalf2x16: |
| 1729 | ASSERT(node->getUseEmulatedFunction()); |
| 1730 | writeEmulatedFunctionTriplet(visit, "unpackHalf2x16("); |
| 1731 | break; |
daniel@transgaming.com | 67de6d6 | 2010-04-29 03:35:30 +0000 | [diff] [blame] | 1732 | case EOpLength: outputTriplet(visit, "length(", "", ")"); break; |
| 1733 | case EOpNormalize: outputTriplet(visit, "normalize(", "", ")"); break; |
daniel@transgaming.com | ddbb45d | 2012-05-31 01:21:41 +0000 | [diff] [blame] | 1734 | case EOpDFdx: |
| 1735 | if(mInsideDiscontinuousLoop || mOutputLod0Function) |
| 1736 | { |
| 1737 | outputTriplet(visit, "(", "", ", 0.0)"); |
| 1738 | } |
| 1739 | else |
| 1740 | { |
| 1741 | outputTriplet(visit, "ddx(", "", ")"); |
| 1742 | } |
| 1743 | break; |
| 1744 | case EOpDFdy: |
| 1745 | if(mInsideDiscontinuousLoop || mOutputLod0Function) |
| 1746 | { |
| 1747 | outputTriplet(visit, "(", "", ", 0.0)"); |
| 1748 | } |
| 1749 | else |
| 1750 | { |
apatrick@chromium.org | 9616e58 | 2012-06-22 18:27:01 +0000 | [diff] [blame] | 1751 | outputTriplet(visit, "ddy(", "", ")"); |
daniel@transgaming.com | ddbb45d | 2012-05-31 01:21:41 +0000 | [diff] [blame] | 1752 | } |
| 1753 | break; |
| 1754 | case EOpFwidth: |
| 1755 | if(mInsideDiscontinuousLoop || mOutputLod0Function) |
| 1756 | { |
| 1757 | outputTriplet(visit, "(", "", ", 0.0)"); |
| 1758 | } |
| 1759 | else |
| 1760 | { |
| 1761 | outputTriplet(visit, "fwidth(", "", ")"); |
| 1762 | } |
| 1763 | break; |
Olli Etuaho | e39706d | 2014-12-30 16:40:36 +0200 | [diff] [blame] | 1764 | case EOpTranspose: outputTriplet(visit, "transpose(", "", ")"); break; |
| 1765 | case EOpDeterminant: outputTriplet(visit, "determinant(transpose(", "", "))"); break; |
Olli Etuaho | abf6dad | 2015-01-14 14:45:16 +0200 | [diff] [blame] | 1766 | case EOpInverse: |
| 1767 | ASSERT(node->getUseEmulatedFunction()); |
| 1768 | writeEmulatedFunctionTriplet(visit, "inverse("); |
| 1769 | break; |
Olli Etuaho | e39706d | 2014-12-30 16:40:36 +0200 | [diff] [blame] | 1770 | |
daniel@transgaming.com | 67de6d6 | 2010-04-29 03:35:30 +0000 | [diff] [blame] | 1771 | case EOpAny: outputTriplet(visit, "any(", "", ")"); break; |
| 1772 | case EOpAll: outputTriplet(visit, "all(", "", ")"); break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1773 | default: UNREACHABLE(); |
| 1774 | } |
| 1775 | |
| 1776 | return true; |
| 1777 | } |
| 1778 | |
| 1779 | bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) |
| 1780 | { |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame] | 1781 | TInfoSinkBase &out = getInfoSink(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1782 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1783 | switch (node->getOp()) |
| 1784 | { |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 1785 | case EOpSequence: |
| 1786 | { |
daniel@transgaming.com | f9ef107 | 2010-04-22 13:35:16 +0000 | [diff] [blame] | 1787 | if (mInsideFunction) |
| 1788 | { |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 1789 | outputLineDirective(node->getLine().first_line); |
daniel@transgaming.com | f9ef107 | 2010-04-22 13:35:16 +0000 | [diff] [blame] | 1790 | out << "{\n"; |
| 1791 | } |
| 1792 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 1793 | for (TIntermSequence::iterator sit = node->getSequence()->begin(); sit != node->getSequence()->end(); sit++) |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 1794 | { |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 1795 | outputLineDirective((*sit)->getLine().first_line); |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 1796 | |
daniel@transgaming.com | 44fffee | 2012-04-28 00:34:20 +0000 | [diff] [blame] | 1797 | traverseStatements(*sit); |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 1798 | |
Olli Etuaho | 05ae50d | 2015-02-20 10:16:47 +0200 | [diff] [blame] | 1799 | // Don't output ; after case labels, they're terminated by : |
| 1800 | // This is needed especially since outputting a ; after a case statement would turn empty |
| 1801 | // case statements into non-empty case statements, disallowing fall-through from them. |
| 1802 | if ((*sit)->getAsCaseNode() == nullptr) |
| 1803 | out << ";\n"; |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 1804 | } |
| 1805 | |
daniel@transgaming.com | f9ef107 | 2010-04-22 13:35:16 +0000 | [diff] [blame] | 1806 | if (mInsideFunction) |
| 1807 | { |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 1808 | outputLineDirective(node->getLine().last_line); |
daniel@transgaming.com | f9ef107 | 2010-04-22 13:35:16 +0000 | [diff] [blame] | 1809 | out << "}\n"; |
| 1810 | } |
| 1811 | |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 1812 | return false; |
| 1813 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1814 | case EOpDeclaration: |
| 1815 | if (visit == PreVisit) |
| 1816 | { |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 1817 | TIntermSequence *sequence = node->getSequence(); |
| 1818 | TIntermTyped *variable = (*sequence)[0]->getAsTyped(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1819 | |
daniel@transgaming.com | d25ab25 | 2010-03-30 03:36:26 +0000 | [diff] [blame] | 1820 | if (variable && (variable->getQualifier() == EvqTemporary || variable->getQualifier() == EvqGlobal)) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1821 | { |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 1822 | TStructure *structure = variable->getType().getStruct(); |
| 1823 | |
| 1824 | if (structure) |
daniel@transgaming.com | ead2304 | 2010-04-29 03:35:36 +0000 | [diff] [blame] | 1825 | { |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 1826 | mStructureHLSL->addConstructor(variable->getType(), StructNameString(*structure), NULL); |
daniel@transgaming.com | ead2304 | 2010-04-29 03:35:36 +0000 | [diff] [blame] | 1827 | } |
| 1828 | |
daniel@transgaming.com | fe56515 | 2010-04-10 05:29:07 +0000 | [diff] [blame] | 1829 | if (!variable->getAsSymbolNode() || variable->getAsSymbolNode()->getSymbol() != "") // Variable declaration |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1830 | { |
Jamie Madill | 3799714 | 2015-01-28 10:06:34 -0500 | [diff] [blame] | 1831 | for (const auto &seqElement : *sequence) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1832 | { |
Jamie Madill | 3799714 | 2015-01-28 10:06:34 -0500 | [diff] [blame] | 1833 | if (isSingleStatement(seqElement)) |
Nicolas Capens | fa41aa0 | 2014-10-06 17:40:13 -0400 | [diff] [blame] | 1834 | { |
Jamie Madill | 3799714 | 2015-01-28 10:06:34 -0500 | [diff] [blame] | 1835 | mUnfoldShortCircuit->traverse(seqElement); |
Nicolas Capens | fa41aa0 | 2014-10-06 17:40:13 -0400 | [diff] [blame] | 1836 | } |
| 1837 | |
Nicolas Capens | d974db4 | 2014-10-07 10:50:19 -0400 | [diff] [blame] | 1838 | if (!mInsideFunction) |
| 1839 | { |
| 1840 | out << "static "; |
| 1841 | } |
| 1842 | |
| 1843 | out << TypeString(variable->getType()) + " "; |
| 1844 | |
Jamie Madill | 3799714 | 2015-01-28 10:06:34 -0500 | [diff] [blame] | 1845 | TIntermSymbol *symbol = seqElement->getAsSymbolNode(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1846 | |
daniel@transgaming.com | fe56515 | 2010-04-10 05:29:07 +0000 | [diff] [blame] | 1847 | if (symbol) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1848 | { |
daniel@transgaming.com | fe56515 | 2010-04-10 05:29:07 +0000 | [diff] [blame] | 1849 | symbol->traverse(this); |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 1850 | out << ArrayString(symbol->getType()); |
Jamie Madill | 79bb0d9 | 2013-12-09 16:20:28 -0500 | [diff] [blame] | 1851 | out << " = " + initializer(symbol->getType()); |
daniel@transgaming.com | fe56515 | 2010-04-10 05:29:07 +0000 | [diff] [blame] | 1852 | } |
| 1853 | else |
| 1854 | { |
Jamie Madill | 3799714 | 2015-01-28 10:06:34 -0500 | [diff] [blame] | 1855 | seqElement->traverse(this); |
daniel@transgaming.com | fe56515 | 2010-04-10 05:29:07 +0000 | [diff] [blame] | 1856 | } |
| 1857 | |
Jamie Madill | 3799714 | 2015-01-28 10:06:34 -0500 | [diff] [blame] | 1858 | if (seqElement != sequence->back()) |
daniel@transgaming.com | fe56515 | 2010-04-10 05:29:07 +0000 | [diff] [blame] | 1859 | { |
Nicolas Capens | d974db4 | 2014-10-07 10:50:19 -0400 | [diff] [blame] | 1860 | out << ";\n"; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1861 | } |
| 1862 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1863 | } |
daniel@transgaming.com | fe56515 | 2010-04-10 05:29:07 +0000 | [diff] [blame] | 1864 | else if (variable->getAsSymbolNode() && variable->getAsSymbolNode()->getSymbol() == "") // Type (struct) declaration |
| 1865 | { |
daniel@transgaming.com | ead2304 | 2010-04-29 03:35:36 +0000 | [diff] [blame] | 1866 | // Already added to constructor map |
daniel@transgaming.com | fe56515 | 2010-04-10 05:29:07 +0000 | [diff] [blame] | 1867 | } |
| 1868 | else UNREACHABLE(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1869 | } |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 1870 | else if (variable && IsVaryingOut(variable->getQualifier())) |
shannon.woods@transgaming.com | cb332ab | 2013-02-28 23:12:18 +0000 | [diff] [blame] | 1871 | { |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 1872 | for (TIntermSequence::iterator sit = sequence->begin(); sit != sequence->end(); sit++) |
shannon.woods@transgaming.com | cb332ab | 2013-02-28 23:12:18 +0000 | [diff] [blame] | 1873 | { |
| 1874 | TIntermSymbol *symbol = (*sit)->getAsSymbolNode(); |
| 1875 | |
| 1876 | if (symbol) |
| 1877 | { |
| 1878 | // Vertex (output) varyings which are declared but not written to should still be declared to allow successful linking |
| 1879 | mReferencedVaryings[symbol->getSymbol()] = symbol; |
| 1880 | } |
| 1881 | else |
| 1882 | { |
| 1883 | (*sit)->traverse(this); |
| 1884 | } |
| 1885 | } |
| 1886 | } |
| 1887 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1888 | return false; |
| 1889 | } |
| 1890 | else if (visit == InVisit) |
| 1891 | { |
| 1892 | out << ", "; |
| 1893 | } |
| 1894 | break; |
Jamie Madill | 3b5c2da | 2014-08-19 15:23:32 -0400 | [diff] [blame] | 1895 | case EOpInvariantDeclaration: |
| 1896 | // Do not do any translation |
| 1897 | return false; |
daniel@transgaming.com | d1acd1e | 2010-04-13 03:25:57 +0000 | [diff] [blame] | 1898 | case EOpPrototype: |
| 1899 | if (visit == PreVisit) |
| 1900 | { |
Olli Etuaho | 76acee8 | 2014-11-04 13:44:03 +0200 | [diff] [blame] | 1901 | out << TypeString(node->getType()) << " " << Decorate(TFunction::unmangleName(node->getName())) << (mOutputLod0Function ? "Lod0(" : "("); |
daniel@transgaming.com | d1acd1e | 2010-04-13 03:25:57 +0000 | [diff] [blame] | 1902 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 1903 | TIntermSequence *arguments = node->getSequence(); |
daniel@transgaming.com | d1acd1e | 2010-04-13 03:25:57 +0000 | [diff] [blame] | 1904 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 1905 | for (unsigned int i = 0; i < arguments->size(); i++) |
daniel@transgaming.com | d1acd1e | 2010-04-13 03:25:57 +0000 | [diff] [blame] | 1906 | { |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 1907 | TIntermSymbol *symbol = (*arguments)[i]->getAsSymbolNode(); |
daniel@transgaming.com | d1acd1e | 2010-04-13 03:25:57 +0000 | [diff] [blame] | 1908 | |
| 1909 | if (symbol) |
| 1910 | { |
| 1911 | out << argumentString(symbol); |
| 1912 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 1913 | if (i < arguments->size() - 1) |
daniel@transgaming.com | d1acd1e | 2010-04-13 03:25:57 +0000 | [diff] [blame] | 1914 | { |
| 1915 | out << ", "; |
| 1916 | } |
| 1917 | } |
| 1918 | else UNREACHABLE(); |
| 1919 | } |
| 1920 | |
| 1921 | out << ");\n"; |
| 1922 | |
daniel@transgaming.com | 0e5bb40 | 2012-10-17 18:24:53 +0000 | [diff] [blame] | 1923 | // Also prototype the Lod0 variant if needed |
| 1924 | if (mContainsLoopDiscontinuity && !mOutputLod0Function) |
| 1925 | { |
| 1926 | mOutputLod0Function = true; |
| 1927 | node->traverse(this); |
| 1928 | mOutputLod0Function = false; |
| 1929 | } |
| 1930 | |
daniel@transgaming.com | d1acd1e | 2010-04-13 03:25:57 +0000 | [diff] [blame] | 1931 | return false; |
| 1932 | } |
| 1933 | break; |
daniel@transgaming.com | ed2180d | 2012-03-26 17:08:54 +0000 | [diff] [blame] | 1934 | case EOpComma: outputTriplet(visit, "(", ", ", ")"); break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1935 | case EOpFunction: |
| 1936 | { |
alokp@chromium.org | 4388487 | 2010-03-30 00:08:52 +0000 | [diff] [blame] | 1937 | TString name = TFunction::unmangleName(node->getName()); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1938 | |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 1939 | out << TypeString(node->getType()) << " "; |
daniel@transgaming.com | 0e9704b | 2012-05-31 01:20:13 +0000 | [diff] [blame] | 1940 | |
| 1941 | if (name == "main") |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1942 | { |
daniel@transgaming.com | 0e9704b | 2012-05-31 01:20:13 +0000 | [diff] [blame] | 1943 | out << "gl_main("; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1944 | } |
daniel@transgaming.com | 0e9704b | 2012-05-31 01:20:13 +0000 | [diff] [blame] | 1945 | else |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1946 | { |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 1947 | out << Decorate(name) << (mOutputLod0Function ? "Lod0(" : "("); |
daniel@transgaming.com | 0e9704b | 2012-05-31 01:20:13 +0000 | [diff] [blame] | 1948 | } |
daniel@transgaming.com | 6369186 | 2010-04-29 03:32:42 +0000 | [diff] [blame] | 1949 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 1950 | TIntermSequence *sequence = node->getSequence(); |
| 1951 | TIntermSequence *arguments = (*sequence)[0]->getAsAggregate()->getSequence(); |
daniel@transgaming.com | 0e9704b | 2012-05-31 01:20:13 +0000 | [diff] [blame] | 1952 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 1953 | for (unsigned int i = 0; i < arguments->size(); i++) |
daniel@transgaming.com | 0e9704b | 2012-05-31 01:20:13 +0000 | [diff] [blame] | 1954 | { |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 1955 | TIntermSymbol *symbol = (*arguments)[i]->getAsSymbolNode(); |
daniel@transgaming.com | 0e9704b | 2012-05-31 01:20:13 +0000 | [diff] [blame] | 1956 | |
| 1957 | if (symbol) |
| 1958 | { |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 1959 | TStructure *structure = symbol->getType().getStruct(); |
| 1960 | |
| 1961 | if (structure) |
daniel@transgaming.com | 0e9704b | 2012-05-31 01:20:13 +0000 | [diff] [blame] | 1962 | { |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 1963 | mStructureHLSL->addConstructor(symbol->getType(), StructNameString(*structure), NULL); |
daniel@transgaming.com | 0e9704b | 2012-05-31 01:20:13 +0000 | [diff] [blame] | 1964 | } |
| 1965 | |
| 1966 | out << argumentString(symbol); |
| 1967 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 1968 | if (i < arguments->size() - 1) |
daniel@transgaming.com | 0e9704b | 2012-05-31 01:20:13 +0000 | [diff] [blame] | 1969 | { |
| 1970 | out << ", "; |
| 1971 | } |
| 1972 | } |
| 1973 | else UNREACHABLE(); |
| 1974 | } |
| 1975 | |
| 1976 | out << ")\n" |
| 1977 | "{\n"; |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 1978 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 1979 | if (sequence->size() > 1) |
daniel@transgaming.com | 0e9704b | 2012-05-31 01:20:13 +0000 | [diff] [blame] | 1980 | { |
| 1981 | mInsideFunction = true; |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 1982 | (*sequence)[1]->traverse(this); |
daniel@transgaming.com | f9ef107 | 2010-04-22 13:35:16 +0000 | [diff] [blame] | 1983 | mInsideFunction = false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1984 | } |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 1985 | |
daniel@transgaming.com | 0e9704b | 2012-05-31 01:20:13 +0000 | [diff] [blame] | 1986 | out << "}\n"; |
| 1987 | |
daniel@transgaming.com | 89431aa | 2012-05-31 01:20:29 +0000 | [diff] [blame] | 1988 | if (mContainsLoopDiscontinuity && !mOutputLod0Function) |
| 1989 | { |
daniel@transgaming.com | ecdf44a | 2012-06-01 01:45:15 +0000 | [diff] [blame] | 1990 | if (name != "main") |
daniel@transgaming.com | 89431aa | 2012-05-31 01:20:29 +0000 | [diff] [blame] | 1991 | { |
| 1992 | mOutputLod0Function = true; |
| 1993 | node->traverse(this); |
| 1994 | mOutputLod0Function = false; |
| 1995 | } |
| 1996 | } |
| 1997 | |
daniel@transgaming.com | 0e9704b | 2012-05-31 01:20:13 +0000 | [diff] [blame] | 1998 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1999 | } |
| 2000 | break; |
| 2001 | case EOpFunctionCall: |
| 2002 | { |
shannon.woods@transgaming.com | 01a5cf9 | 2013-02-28 23:13:51 +0000 | [diff] [blame] | 2003 | TString name = TFunction::unmangleName(node->getName()); |
| 2004 | bool lod0 = mInsideDiscontinuousLoop || mOutputLod0Function; |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 2005 | TIntermSequence *arguments = node->getSequence(); |
shannon.woods@transgaming.com | 01a5cf9 | 2013-02-28 23:13:51 +0000 | [diff] [blame] | 2006 | |
| 2007 | if (node->isUserDefined()) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2008 | { |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 2009 | out << Decorate(name) << (lod0 ? "Lod0(" : "("); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2010 | } |
| 2011 | else |
| 2012 | { |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 2013 | TBasicType samplerType = (*arguments)[0]->getAsTyped()->getType().getBasicType(); |
shannonwoods@chromium.org | c6ac65f | 2013-05-30 00:02:50 +0000 | [diff] [blame] | 2014 | |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 2015 | TextureFunction textureFunction; |
| 2016 | textureFunction.sampler = samplerType; |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 2017 | textureFunction.coords = (*arguments)[1]->getAsTyped()->getNominalSize(); |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 2018 | textureFunction.method = TextureFunction::IMPLICIT; |
| 2019 | textureFunction.proj = false; |
Nicolas Capens | b1f45b7 | 2013-12-19 17:37:19 -0500 | [diff] [blame] | 2020 | textureFunction.offset = false; |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 2021 | |
| 2022 | if (name == "texture2D" || name == "textureCube" || name == "texture") |
shannon.woods@transgaming.com | 01a5cf9 | 2013-02-28 23:13:51 +0000 | [diff] [blame] | 2023 | { |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 2024 | textureFunction.method = TextureFunction::IMPLICIT; |
shannon.woods@transgaming.com | 01a5cf9 | 2013-02-28 23:13:51 +0000 | [diff] [blame] | 2025 | } |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 2026 | else if (name == "texture2DProj" || name == "textureProj") |
shannon.woods@transgaming.com | 01a5cf9 | 2013-02-28 23:13:51 +0000 | [diff] [blame] | 2027 | { |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 2028 | textureFunction.method = TextureFunction::IMPLICIT; |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 2029 | textureFunction.proj = true; |
shannon.woods@transgaming.com | 01a5cf9 | 2013-02-28 23:13:51 +0000 | [diff] [blame] | 2030 | } |
Nicolas Capens | 4648508 | 2014-04-15 13:12:50 -0400 | [diff] [blame] | 2031 | else if (name == "texture2DLod" || name == "textureCubeLod" || name == "textureLod" || |
| 2032 | name == "texture2DLodEXT" || name == "textureCubeLodEXT") |
Nicolas Capens | 9fe6f98 | 2013-06-24 16:05:25 -0400 | [diff] [blame] | 2033 | { |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 2034 | textureFunction.method = TextureFunction::LOD; |
Nicolas Capens | 9fe6f98 | 2013-06-24 16:05:25 -0400 | [diff] [blame] | 2035 | } |
Nicolas Capens | 4648508 | 2014-04-15 13:12:50 -0400 | [diff] [blame] | 2036 | else if (name == "texture2DProjLod" || name == "textureProjLod" || name == "texture2DProjLodEXT") |
Nicolas Capens | 9fe6f98 | 2013-06-24 16:05:25 -0400 | [diff] [blame] | 2037 | { |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 2038 | textureFunction.method = TextureFunction::LOD; |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 2039 | textureFunction.proj = true; |
shannon.woods@transgaming.com | 01a5cf9 | 2013-02-28 23:13:51 +0000 | [diff] [blame] | 2040 | } |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 2041 | else if (name == "textureSize") |
| 2042 | { |
| 2043 | textureFunction.method = TextureFunction::SIZE; |
| 2044 | } |
Nicolas Capens | b1f45b7 | 2013-12-19 17:37:19 -0500 | [diff] [blame] | 2045 | else if (name == "textureOffset") |
| 2046 | { |
| 2047 | textureFunction.method = TextureFunction::IMPLICIT; |
| 2048 | textureFunction.offset = true; |
| 2049 | } |
Nicolas Capens | df86c6b | 2014-02-14 20:09:17 -0500 | [diff] [blame] | 2050 | else if (name == "textureProjOffset") |
| 2051 | { |
| 2052 | textureFunction.method = TextureFunction::IMPLICIT; |
| 2053 | textureFunction.offset = true; |
| 2054 | textureFunction.proj = true; |
| 2055 | } |
| 2056 | else if (name == "textureLodOffset") |
| 2057 | { |
| 2058 | textureFunction.method = TextureFunction::LOD; |
| 2059 | textureFunction.offset = true; |
| 2060 | } |
Nicolas Capens | 2adc256 | 2014-02-14 23:50:59 -0500 | [diff] [blame] | 2061 | else if (name == "textureProjLodOffset") |
| 2062 | { |
| 2063 | textureFunction.method = TextureFunction::LOD; |
| 2064 | textureFunction.proj = true; |
| 2065 | textureFunction.offset = true; |
| 2066 | } |
Nicolas Capens | fc01454 | 2014-02-18 14:47:13 -0500 | [diff] [blame] | 2067 | else if (name == "texelFetch") |
| 2068 | { |
| 2069 | textureFunction.method = TextureFunction::FETCH; |
| 2070 | } |
| 2071 | else if (name == "texelFetchOffset") |
| 2072 | { |
| 2073 | textureFunction.method = TextureFunction::FETCH; |
| 2074 | textureFunction.offset = true; |
| 2075 | } |
Nicolas Capens | 4648508 | 2014-04-15 13:12:50 -0400 | [diff] [blame] | 2076 | else if (name == "textureGrad" || name == "texture2DGradEXT") |
Nicolas Capens | d11d549 | 2014-02-19 17:06:10 -0500 | [diff] [blame] | 2077 | { |
| 2078 | textureFunction.method = TextureFunction::GRAD; |
| 2079 | } |
Nicolas Capens | bf7db10 | 2014-02-19 17:20:28 -0500 | [diff] [blame] | 2080 | else if (name == "textureGradOffset") |
| 2081 | { |
| 2082 | textureFunction.method = TextureFunction::GRAD; |
| 2083 | textureFunction.offset = true; |
| 2084 | } |
Nicolas Capens | 4648508 | 2014-04-15 13:12:50 -0400 | [diff] [blame] | 2085 | else if (name == "textureProjGrad" || name == "texture2DProjGradEXT" || name == "textureCubeGradEXT") |
Nicolas Capens | f7378e3 | 2014-02-19 17:29:32 -0500 | [diff] [blame] | 2086 | { |
| 2087 | textureFunction.method = TextureFunction::GRAD; |
| 2088 | textureFunction.proj = true; |
| 2089 | } |
| 2090 | else if (name == "textureProjGradOffset") |
| 2091 | { |
| 2092 | textureFunction.method = TextureFunction::GRAD; |
| 2093 | textureFunction.proj = true; |
| 2094 | textureFunction.offset = true; |
| 2095 | } |
shannon.woods@transgaming.com | 01a5cf9 | 2013-02-28 23:13:51 +0000 | [diff] [blame] | 2096 | else UNREACHABLE(); |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 2097 | |
Nicolas Capens | b1f45b7 | 2013-12-19 17:37:19 -0500 | [diff] [blame] | 2098 | if (textureFunction.method == TextureFunction::IMPLICIT) // Could require lod 0 or have a bias argument |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 2099 | { |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 2100 | unsigned int mandatoryArgumentCount = 2; // All functions have sampler and coordinate arguments |
| 2101 | |
| 2102 | if (textureFunction.offset) |
| 2103 | { |
| 2104 | mandatoryArgumentCount++; |
| 2105 | } |
| 2106 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 2107 | bool bias = (arguments->size() > mandatoryArgumentCount); // Bias argument is optional |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 2108 | |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 2109 | if (lod0 || mShaderType == GL_VERTEX_SHADER) |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 2110 | { |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 2111 | if (bias) |
| 2112 | { |
| 2113 | textureFunction.method = TextureFunction::LOD0BIAS; |
| 2114 | } |
| 2115 | else |
| 2116 | { |
| 2117 | textureFunction.method = TextureFunction::LOD0; |
| 2118 | } |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 2119 | } |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 2120 | else if (bias) |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 2121 | { |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 2122 | textureFunction.method = TextureFunction::BIAS; |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 2123 | } |
| 2124 | } |
| 2125 | |
| 2126 | mUsesTexture.insert(textureFunction); |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 2127 | |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 2128 | out << textureFunction.name(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2129 | } |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 2130 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 2131 | for (TIntermSequence::iterator arg = arguments->begin(); arg != arguments->end(); arg++) |
shannon.woods@transgaming.com | 01a5cf9 | 2013-02-28 23:13:51 +0000 | [diff] [blame] | 2132 | { |
| 2133 | if (mOutputType == SH_HLSL11_OUTPUT && IsSampler((*arg)->getAsTyped()->getBasicType())) |
| 2134 | { |
| 2135 | out << "texture_"; |
| 2136 | (*arg)->traverse(this); |
| 2137 | out << ", sampler_"; |
| 2138 | } |
| 2139 | |
| 2140 | (*arg)->traverse(this); |
| 2141 | |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 2142 | if (arg < arguments->end() - 1) |
shannon.woods@transgaming.com | 01a5cf9 | 2013-02-28 23:13:51 +0000 | [diff] [blame] | 2143 | { |
| 2144 | out << ", "; |
| 2145 | } |
| 2146 | } |
| 2147 | |
| 2148 | out << ")"; |
| 2149 | |
| 2150 | return false; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2151 | } |
| 2152 | break; |
Nicolas Capens | 1af18dc | 2014-06-11 11:07:32 -0400 | [diff] [blame] | 2153 | case EOpParameters: outputTriplet(visit, "(", ", ", ")\n{\n"); break; |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 2154 | case EOpConstructFloat: outputConstructor(visit, node->getType(), "vec1", node->getSequence()); break; |
| 2155 | case EOpConstructVec2: outputConstructor(visit, node->getType(), "vec2", node->getSequence()); break; |
| 2156 | case EOpConstructVec3: outputConstructor(visit, node->getType(), "vec3", node->getSequence()); break; |
| 2157 | case EOpConstructVec4: outputConstructor(visit, node->getType(), "vec4", node->getSequence()); break; |
| 2158 | case EOpConstructBool: outputConstructor(visit, node->getType(), "bvec1", node->getSequence()); break; |
| 2159 | case EOpConstructBVec2: outputConstructor(visit, node->getType(), "bvec2", node->getSequence()); break; |
| 2160 | case EOpConstructBVec3: outputConstructor(visit, node->getType(), "bvec3", node->getSequence()); break; |
| 2161 | case EOpConstructBVec4: outputConstructor(visit, node->getType(), "bvec4", node->getSequence()); break; |
| 2162 | case EOpConstructInt: outputConstructor(visit, node->getType(), "ivec1", node->getSequence()); break; |
| 2163 | case EOpConstructIVec2: outputConstructor(visit, node->getType(), "ivec2", node->getSequence()); break; |
| 2164 | case EOpConstructIVec3: outputConstructor(visit, node->getType(), "ivec3", node->getSequence()); break; |
| 2165 | case EOpConstructIVec4: outputConstructor(visit, node->getType(), "ivec4", node->getSequence()); break; |
| 2166 | case EOpConstructUInt: outputConstructor(visit, node->getType(), "uvec1", node->getSequence()); break; |
| 2167 | case EOpConstructUVec2: outputConstructor(visit, node->getType(), "uvec2", node->getSequence()); break; |
| 2168 | case EOpConstructUVec3: outputConstructor(visit, node->getType(), "uvec3", node->getSequence()); break; |
| 2169 | case EOpConstructUVec4: outputConstructor(visit, node->getType(), "uvec4", node->getSequence()); break; |
| 2170 | case EOpConstructMat2: outputConstructor(visit, node->getType(), "mat2", node->getSequence()); break; |
| 2171 | case EOpConstructMat3: outputConstructor(visit, node->getType(), "mat3", node->getSequence()); break; |
| 2172 | case EOpConstructMat4: outputConstructor(visit, node->getType(), "mat4", node->getSequence()); break; |
daniel@transgaming.com | 7a7003c | 2010-04-29 03:35:33 +0000 | [diff] [blame] | 2173 | case EOpConstructStruct: |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 2174 | { |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 2175 | const TString &structName = StructNameString(*node->getType().getStruct()); |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 2176 | mStructureHLSL->addConstructor(node->getType(), structName, node->getSequence()); |
Daniel Bratell | 2919008 | 2015-02-20 16:42:54 +0100 | [diff] [blame] | 2177 | outputTriplet(visit, (structName + "_ctor(").c_str(), ", ", ")"); |
Jamie Madill | bfa91f4 | 2014-06-05 15:45:18 -0400 | [diff] [blame] | 2178 | } |
daniel@transgaming.com | 7a7003c | 2010-04-29 03:35:33 +0000 | [diff] [blame] | 2179 | break; |
daniel@transgaming.com | fe56515 | 2010-04-10 05:29:07 +0000 | [diff] [blame] | 2180 | case EOpLessThan: outputTriplet(visit, "(", " < ", ")"); break; |
| 2181 | case EOpGreaterThan: outputTriplet(visit, "(", " > ", ")"); break; |
| 2182 | case EOpLessThanEqual: outputTriplet(visit, "(", " <= ", ")"); break; |
| 2183 | case EOpGreaterThanEqual: outputTriplet(visit, "(", " >= ", ")"); break; |
| 2184 | case EOpVectorEqual: outputTriplet(visit, "(", " == ", ")"); break; |
| 2185 | case EOpVectorNotEqual: outputTriplet(visit, "(", " != ", ")"); break; |
daniel@transgaming.com | d7c9810 | 2010-05-14 17:30:48 +0000 | [diff] [blame] | 2186 | case EOpMod: |
Olli Etuaho | e17e319 | 2015-01-02 12:47:59 +0200 | [diff] [blame] | 2187 | ASSERT(node->getUseEmulatedFunction()); |
| 2188 | writeEmulatedFunctionTriplet(visit, "mod("); |
daniel@transgaming.com | d7c9810 | 2010-05-14 17:30:48 +0000 | [diff] [blame] | 2189 | break; |
Olli Etuaho | b6e07a6 | 2015-02-16 12:22:10 +0200 | [diff] [blame] | 2190 | case EOpModf: outputTriplet(visit, "modf(", ", ", ")"); break; |
daniel@transgaming.com | fe56515 | 2010-04-10 05:29:07 +0000 | [diff] [blame] | 2191 | case EOpPow: outputTriplet(visit, "pow(", ", ", ")"); break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2192 | case EOpAtan: |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 2193 | ASSERT(node->getSequence()->size() == 2); // atan(x) is a unary operator |
Olli Etuaho | e17e319 | 2015-01-02 12:47:59 +0200 | [diff] [blame] | 2194 | ASSERT(node->getUseEmulatedFunction()); |
| 2195 | writeEmulatedFunctionTriplet(visit, "atan("); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2196 | break; |
| 2197 | case EOpMin: outputTriplet(visit, "min(", ", ", ")"); break; |
| 2198 | case EOpMax: outputTriplet(visit, "max(", ", ", ")"); break; |
| 2199 | case EOpClamp: outputTriplet(visit, "clamp(", ", ", ")"); break; |
| 2200 | case EOpMix: outputTriplet(visit, "lerp(", ", ", ")"); break; |
| 2201 | case EOpStep: outputTriplet(visit, "step(", ", ", ")"); break; |
| 2202 | case EOpSmoothStep: outputTriplet(visit, "smoothstep(", ", ", ")"); break; |
| 2203 | case EOpDistance: outputTriplet(visit, "distance(", ", ", ")"); break; |
| 2204 | case EOpDot: outputTriplet(visit, "dot(", ", ", ")"); break; |
| 2205 | case EOpCross: outputTriplet(visit, "cross(", ", ", ")"); break; |
daniel@transgaming.com | 0bbb031 | 2010-04-26 15:33:39 +0000 | [diff] [blame] | 2206 | case EOpFaceForward: |
Olli Etuaho | e17e319 | 2015-01-02 12:47:59 +0200 | [diff] [blame] | 2207 | ASSERT(node->getUseEmulatedFunction()); |
| 2208 | writeEmulatedFunctionTriplet(visit, "faceforward("); |
daniel@transgaming.com | 0bbb031 | 2010-04-26 15:33:39 +0000 | [diff] [blame] | 2209 | break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2210 | case EOpReflect: outputTriplet(visit, "reflect(", ", ", ")"); break; |
| 2211 | case EOpRefract: outputTriplet(visit, "refract(", ", ", ")"); break; |
Olli Etuaho | e39706d | 2014-12-30 16:40:36 +0200 | [diff] [blame] | 2212 | case EOpOuterProduct: |
| 2213 | ASSERT(node->getUseEmulatedFunction()); |
| 2214 | writeEmulatedFunctionTriplet(visit, "outerProduct("); |
| 2215 | break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2216 | case EOpMul: outputTriplet(visit, "(", " * ", ")"); break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2217 | default: UNREACHABLE(); |
| 2218 | } |
| 2219 | |
| 2220 | return true; |
| 2221 | } |
| 2222 | |
| 2223 | bool OutputHLSL::visitSelection(Visit visit, TIntermSelection *node) |
| 2224 | { |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame] | 2225 | TInfoSinkBase &out = getInfoSink(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2226 | |
alokp@chromium.org | 60fe407 | 2010-03-29 20:58:29 +0000 | [diff] [blame] | 2227 | if (node->usesTernaryOperator()) |
| 2228 | { |
daniel@transgaming.com | f8f8f36 | 2012-04-28 00:35:00 +0000 | [diff] [blame] | 2229 | out << "s" << mUnfoldShortCircuit->getNextTemporaryIndex(); |
alokp@chromium.org | 60fe407 | 2010-03-29 20:58:29 +0000 | [diff] [blame] | 2230 | } |
| 2231 | else // if/else statement |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2232 | { |
daniel@transgaming.com | f8f8f36 | 2012-04-28 00:35:00 +0000 | [diff] [blame] | 2233 | mUnfoldShortCircuit->traverse(node->getCondition()); |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 2234 | |
Corentin Wallez | 80bacde | 2014-11-10 12:07:37 -0800 | [diff] [blame] | 2235 | // D3D errors when there is a gradient operation in a loop in an unflattened if |
| 2236 | // however flattening all the ifs in branch heavy shaders made D3D error too. |
| 2237 | // As a temporary workaround we flatten the ifs only if there is at least a loop |
| 2238 | // present somewhere in the shader. |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 2239 | if (mShaderType == GL_FRAGMENT_SHADER && mContainsAnyLoop) |
Corentin Wallez | 80bacde | 2014-11-10 12:07:37 -0800 | [diff] [blame] | 2240 | { |
| 2241 | out << "FLATTEN "; |
| 2242 | } |
| 2243 | |
| 2244 | out << "if ("; |
daniel@transgaming.com | 3d53fda | 2010-03-21 04:30:55 +0000 | [diff] [blame] | 2245 | |
| 2246 | node->getCondition()->traverse(this); |
| 2247 | |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 2248 | out << ")\n"; |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 2249 | |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 2250 | outputLineDirective(node->getLine().first_line); |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 2251 | out << "{\n"; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2252 | |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 2253 | bool discard = false; |
| 2254 | |
daniel@transgaming.com | bb88532 | 2010-04-15 20:45:24 +0000 | [diff] [blame] | 2255 | if (node->getTrueBlock()) |
| 2256 | { |
daniel@transgaming.com | 44fffee | 2012-04-28 00:34:20 +0000 | [diff] [blame] | 2257 | traverseStatements(node->getTrueBlock()); |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 2258 | |
| 2259 | // Detect true discard |
| 2260 | discard = (discard || FindDiscard::search(node->getTrueBlock())); |
daniel@transgaming.com | bb88532 | 2010-04-15 20:45:24 +0000 | [diff] [blame] | 2261 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2262 | |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 2263 | outputLineDirective(node->getLine().first_line); |
daniel@transgaming.com | 44fffee | 2012-04-28 00:34:20 +0000 | [diff] [blame] | 2264 | out << ";\n}\n"; |
daniel@transgaming.com | 3d53fda | 2010-03-21 04:30:55 +0000 | [diff] [blame] | 2265 | |
| 2266 | if (node->getFalseBlock()) |
| 2267 | { |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 2268 | out << "else\n"; |
daniel@transgaming.com | 3d53fda | 2010-03-21 04:30:55 +0000 | [diff] [blame] | 2269 | |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 2270 | outputLineDirective(node->getFalseBlock()->getLine().first_line); |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 2271 | out << "{\n"; |
| 2272 | |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 2273 | outputLineDirective(node->getFalseBlock()->getLine().first_line); |
daniel@transgaming.com | 44fffee | 2012-04-28 00:34:20 +0000 | [diff] [blame] | 2274 | traverseStatements(node->getFalseBlock()); |
daniel@transgaming.com | 3d53fda | 2010-03-21 04:30:55 +0000 | [diff] [blame] | 2275 | |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 2276 | outputLineDirective(node->getFalseBlock()->getLine().first_line); |
daniel@transgaming.com | 44fffee | 2012-04-28 00:34:20 +0000 | [diff] [blame] | 2277 | out << ";\n}\n"; |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 2278 | |
| 2279 | // Detect false discard |
| 2280 | discard = (discard || FindDiscard::search(node->getFalseBlock())); |
| 2281 | } |
| 2282 | |
| 2283 | // ANGLE issue 486: Detect problematic conditional discard |
| 2284 | if (discard && FindSideEffectRewriting::search(node)) |
| 2285 | { |
| 2286 | mUsesDiscardRewriting = true; |
daniel@transgaming.com | 3d53fda | 2010-03-21 04:30:55 +0000 | [diff] [blame] | 2287 | } |
| 2288 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2289 | |
| 2290 | return false; |
| 2291 | } |
| 2292 | |
Olli Etuaho | 05ae50d | 2015-02-20 10:16:47 +0200 | [diff] [blame] | 2293 | bool OutputHLSL::visitSwitch(Visit visit, TIntermSwitch *node) |
Olli Etuaho | 3c1dfb5 | 2015-02-20 11:34:03 +0200 | [diff] [blame] | 2294 | { |
Olli Etuaho | 05ae50d | 2015-02-20 10:16:47 +0200 | [diff] [blame] | 2295 | if (node->getStatementList()) |
| 2296 | { |
Olli Etuaho | 2cd7a0e | 2015-02-27 13:57:32 +0200 | [diff] [blame] | 2297 | node->setStatementList(RemoveSwitchFallThrough::removeFallThrough(node->getStatementList())); |
Olli Etuaho | 05ae50d | 2015-02-20 10:16:47 +0200 | [diff] [blame] | 2298 | outputTriplet(visit, "switch (", ") ", ""); |
| 2299 | // The curly braces get written when visiting the statementList aggregate |
| 2300 | } |
| 2301 | else |
| 2302 | { |
| 2303 | // No statementList, so it won't output curly braces |
| 2304 | outputTriplet(visit, "switch (", ") {", "}\n"); |
| 2305 | } |
| 2306 | return true; |
Olli Etuaho | 3c1dfb5 | 2015-02-20 11:34:03 +0200 | [diff] [blame] | 2307 | } |
| 2308 | |
Olli Etuaho | 05ae50d | 2015-02-20 10:16:47 +0200 | [diff] [blame] | 2309 | bool OutputHLSL::visitCase(Visit visit, TIntermCase *node) |
Olli Etuaho | 3c1dfb5 | 2015-02-20 11:34:03 +0200 | [diff] [blame] | 2310 | { |
Olli Etuaho | 05ae50d | 2015-02-20 10:16:47 +0200 | [diff] [blame] | 2311 | if (node->hasCondition()) |
| 2312 | { |
| 2313 | outputTriplet(visit, "case (", "", "):\n"); |
| 2314 | return true; |
| 2315 | } |
| 2316 | else |
| 2317 | { |
| 2318 | TInfoSinkBase &out = getInfoSink(); |
| 2319 | out << "default:\n"; |
| 2320 | return false; |
| 2321 | } |
Olli Etuaho | 3c1dfb5 | 2015-02-20 11:34:03 +0200 | [diff] [blame] | 2322 | } |
| 2323 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2324 | void OutputHLSL::visitConstantUnion(TIntermConstantUnion *node) |
| 2325 | { |
daniel@transgaming.com | a54da4e | 2010-05-07 13:03:28 +0000 | [diff] [blame] | 2326 | writeConstantUnion(node->getType(), node->getUnionArrayPointer()); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2327 | } |
| 2328 | |
| 2329 | bool OutputHLSL::visitLoop(Visit visit, TIntermLoop *node) |
| 2330 | { |
Nicolas Capens | 655fe36 | 2014-04-11 13:12:34 -0400 | [diff] [blame] | 2331 | mNestedLoopDepth++; |
| 2332 | |
daniel@transgaming.com | e11100c | 2012-05-31 01:20:32 +0000 | [diff] [blame] | 2333 | bool wasDiscontinuous = mInsideDiscontinuousLoop; |
| 2334 | |
shannon.woods@transgaming.com | e91615c | 2013-01-25 21:56:03 +0000 | [diff] [blame] | 2335 | if (mContainsLoopDiscontinuity && !mInsideDiscontinuousLoop) |
daniel@transgaming.com | e11100c | 2012-05-31 01:20:32 +0000 | [diff] [blame] | 2336 | { |
| 2337 | mInsideDiscontinuousLoop = containsLoopDiscontinuity(node); |
| 2338 | } |
| 2339 | |
shannon.woods@transgaming.com | 9cbce92 | 2013-02-28 23:14:24 +0000 | [diff] [blame] | 2340 | if (mOutputType == SH_HLSL9_OUTPUT) |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2341 | { |
shannon.woods@transgaming.com | 9cbce92 | 2013-02-28 23:14:24 +0000 | [diff] [blame] | 2342 | if (handleExcessiveLoop(node)) |
| 2343 | { |
Nicolas Capens | 655fe36 | 2014-04-11 13:12:34 -0400 | [diff] [blame] | 2344 | mInsideDiscontinuousLoop = wasDiscontinuous; |
| 2345 | mNestedLoopDepth--; |
| 2346 | |
shannon.woods@transgaming.com | 9cbce92 | 2013-02-28 23:14:24 +0000 | [diff] [blame] | 2347 | return false; |
| 2348 | } |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2349 | } |
| 2350 | |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame] | 2351 | TInfoSinkBase &out = getInfoSink(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2352 | |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame] | 2353 | if (node->getType() == ELoopDoWhile) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2354 | { |
Nicolas Capens | 5e0c80a | 2014-10-10 10:11:54 -0400 | [diff] [blame] | 2355 | out << "{LOOP do\n"; |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 2356 | |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 2357 | outputLineDirective(node->getLine().first_line); |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 2358 | out << "{\n"; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2359 | } |
| 2360 | else |
| 2361 | { |
Nicolas Capens | 5e0c80a | 2014-10-10 10:11:54 -0400 | [diff] [blame] | 2362 | out << "{LOOP for("; |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 2363 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2364 | if (node->getInit()) |
| 2365 | { |
| 2366 | node->getInit()->traverse(this); |
| 2367 | } |
| 2368 | |
| 2369 | out << "; "; |
| 2370 | |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame] | 2371 | if (node->getCondition()) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2372 | { |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame] | 2373 | node->getCondition()->traverse(this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2374 | } |
| 2375 | |
| 2376 | out << "; "; |
| 2377 | |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame] | 2378 | if (node->getExpression()) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2379 | { |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame] | 2380 | node->getExpression()->traverse(this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2381 | } |
| 2382 | |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 2383 | out << ")\n"; |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 2384 | |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 2385 | outputLineDirective(node->getLine().first_line); |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 2386 | out << "{\n"; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2387 | } |
| 2388 | |
| 2389 | if (node->getBody()) |
| 2390 | { |
daniel@transgaming.com | 44fffee | 2012-04-28 00:34:20 +0000 | [diff] [blame] | 2391 | traverseStatements(node->getBody()); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2392 | } |
| 2393 | |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 2394 | outputLineDirective(node->getLine().first_line); |
daniel@transgaming.com | 7fb81e8 | 2011-09-23 18:20:46 +0000 | [diff] [blame] | 2395 | out << ";}\n"; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2396 | |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame] | 2397 | if (node->getType() == ELoopDoWhile) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2398 | { |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 2399 | outputLineDirective(node->getCondition()->getLine().first_line); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2400 | out << "while(\n"; |
| 2401 | |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame] | 2402 | node->getCondition()->traverse(this); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2403 | |
daniel@transgaming.com | 7353698 | 2012-03-21 20:45:49 +0000 | [diff] [blame] | 2404 | out << ");"; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2405 | } |
| 2406 | |
daniel@transgaming.com | 7353698 | 2012-03-21 20:45:49 +0000 | [diff] [blame] | 2407 | out << "}\n"; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2408 | |
daniel@transgaming.com | e11100c | 2012-05-31 01:20:32 +0000 | [diff] [blame] | 2409 | mInsideDiscontinuousLoop = wasDiscontinuous; |
Nicolas Capens | 655fe36 | 2014-04-11 13:12:34 -0400 | [diff] [blame] | 2410 | mNestedLoopDepth--; |
daniel@transgaming.com | e11100c | 2012-05-31 01:20:32 +0000 | [diff] [blame] | 2411 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2412 | return false; |
| 2413 | } |
| 2414 | |
| 2415 | bool OutputHLSL::visitBranch(Visit visit, TIntermBranch *node) |
| 2416 | { |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame] | 2417 | TInfoSinkBase &out = getInfoSink(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2418 | |
| 2419 | switch (node->getFlowOp()) |
| 2420 | { |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 2421 | case EOpKill: |
| 2422 | outputTriplet(visit, "discard;\n", "", ""); |
| 2423 | break; |
daniel@transgaming.com | 8c77f85 | 2012-07-11 20:37:35 +0000 | [diff] [blame] | 2424 | case EOpBreak: |
| 2425 | if (visit == PreVisit) |
| 2426 | { |
Nicolas Capens | 655fe36 | 2014-04-11 13:12:34 -0400 | [diff] [blame] | 2427 | if (mNestedLoopDepth > 1) |
| 2428 | { |
| 2429 | mUsesNestedBreak = true; |
| 2430 | } |
| 2431 | |
daniel@transgaming.com | 8c77f85 | 2012-07-11 20:37:35 +0000 | [diff] [blame] | 2432 | if (mExcessiveLoopIndex) |
| 2433 | { |
| 2434 | out << "{Break"; |
| 2435 | mExcessiveLoopIndex->traverse(this); |
| 2436 | out << " = true; break;}\n"; |
| 2437 | } |
| 2438 | else |
| 2439 | { |
| 2440 | out << "break;\n"; |
| 2441 | } |
| 2442 | } |
| 2443 | break; |
apatrick@chromium.org | 05a5d8e | 2011-02-16 19:07:20 +0000 | [diff] [blame] | 2444 | case EOpContinue: outputTriplet(visit, "continue;\n", "", ""); break; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2445 | case EOpReturn: |
| 2446 | if (visit == PreVisit) |
| 2447 | { |
| 2448 | if (node->getExpression()) |
| 2449 | { |
| 2450 | out << "return "; |
| 2451 | } |
| 2452 | else |
| 2453 | { |
| 2454 | out << "return;\n"; |
| 2455 | } |
| 2456 | } |
| 2457 | else if (visit == PostVisit) |
| 2458 | { |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 2459 | if (node->getExpression()) |
| 2460 | { |
| 2461 | out << ";\n"; |
| 2462 | } |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2463 | } |
| 2464 | break; |
| 2465 | default: UNREACHABLE(); |
| 2466 | } |
| 2467 | |
| 2468 | return true; |
| 2469 | } |
| 2470 | |
daniel@transgaming.com | 44fffee | 2012-04-28 00:34:20 +0000 | [diff] [blame] | 2471 | void OutputHLSL::traverseStatements(TIntermNode *node) |
| 2472 | { |
| 2473 | if (isSingleStatement(node)) |
| 2474 | { |
daniel@transgaming.com | f8f8f36 | 2012-04-28 00:35:00 +0000 | [diff] [blame] | 2475 | mUnfoldShortCircuit->traverse(node); |
daniel@transgaming.com | 44fffee | 2012-04-28 00:34:20 +0000 | [diff] [blame] | 2476 | } |
| 2477 | |
| 2478 | node->traverse(this); |
| 2479 | } |
| 2480 | |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 2481 | bool OutputHLSL::isSingleStatement(TIntermNode *node) |
| 2482 | { |
| 2483 | TIntermAggregate *aggregate = node->getAsAggregate(); |
| 2484 | |
| 2485 | if (aggregate) |
| 2486 | { |
| 2487 | if (aggregate->getOp() == EOpSequence) |
| 2488 | { |
| 2489 | return false; |
| 2490 | } |
Nicolas Capens | fa41aa0 | 2014-10-06 17:40:13 -0400 | [diff] [blame] | 2491 | else if (aggregate->getOp() == EOpDeclaration) |
| 2492 | { |
| 2493 | // Declaring multiple comma-separated variables must be considered multiple statements |
| 2494 | // because each individual declaration has side effects which are visible in the next. |
| 2495 | return false; |
| 2496 | } |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 2497 | else |
| 2498 | { |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 2499 | for (TIntermSequence::iterator sit = aggregate->getSequence()->begin(); sit != aggregate->getSequence()->end(); sit++) |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 2500 | { |
| 2501 | if (!isSingleStatement(*sit)) |
| 2502 | { |
| 2503 | return false; |
| 2504 | } |
| 2505 | } |
| 2506 | |
| 2507 | return true; |
| 2508 | } |
| 2509 | } |
| 2510 | |
| 2511 | return true; |
| 2512 | } |
| 2513 | |
daniel@transgaming.com | 06eb0d4 | 2012-05-31 01:17:14 +0000 | [diff] [blame] | 2514 | // Handle loops with more than 254 iterations (unsupported by D3D9) by splitting them |
| 2515 | // (The D3D documentation says 255 iterations, but the compiler complains at anything more than 254). |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2516 | bool OutputHLSL::handleExcessiveLoop(TIntermLoop *node) |
| 2517 | { |
daniel@transgaming.com | 06eb0d4 | 2012-05-31 01:17:14 +0000 | [diff] [blame] | 2518 | const int MAX_LOOP_ITERATIONS = 254; |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame] | 2519 | TInfoSinkBase &out = getInfoSink(); |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2520 | |
| 2521 | // Parse loops of the form: |
| 2522 | // for(int index = initial; index [comparator] limit; index += increment) |
| 2523 | TIntermSymbol *index = NULL; |
| 2524 | TOperator comparator = EOpNull; |
| 2525 | int initial = 0; |
| 2526 | int limit = 0; |
| 2527 | int increment = 0; |
| 2528 | |
| 2529 | // Parse index name and intial value |
| 2530 | if (node->getInit()) |
| 2531 | { |
| 2532 | TIntermAggregate *init = node->getInit()->getAsAggregate(); |
| 2533 | |
| 2534 | if (init) |
| 2535 | { |
Zhenyao Mo | e40d1e9 | 2014-07-16 17:40:36 -0700 | [diff] [blame] | 2536 | TIntermSequence *sequence = init->getSequence(); |
| 2537 | TIntermTyped *variable = (*sequence)[0]->getAsTyped(); |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2538 | |
| 2539 | if (variable && variable->getQualifier() == EvqTemporary) |
| 2540 | { |
| 2541 | TIntermBinary *assign = variable->getAsBinaryNode(); |
| 2542 | |
| 2543 | if (assign->getOp() == EOpInitialize) |
| 2544 | { |
| 2545 | TIntermSymbol *symbol = assign->getLeft()->getAsSymbolNode(); |
| 2546 | TIntermConstantUnion *constant = assign->getRight()->getAsConstantUnion(); |
| 2547 | |
| 2548 | if (symbol && constant) |
| 2549 | { |
shannonwoods@chromium.org | 09e0988 | 2013-05-30 00:18:25 +0000 | [diff] [blame] | 2550 | if (constant->getBasicType() == EbtInt && constant->isScalar()) |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2551 | { |
| 2552 | index = symbol; |
shannon.woods%transgaming.com@gtempaccount.com | c0d0c22 | 2013-04-13 03:29:36 +0000 | [diff] [blame] | 2553 | initial = constant->getIConst(0); |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2554 | } |
| 2555 | } |
| 2556 | } |
| 2557 | } |
| 2558 | } |
| 2559 | } |
| 2560 | |
| 2561 | // Parse comparator and limit value |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame] | 2562 | if (index != NULL && node->getCondition()) |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2563 | { |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame] | 2564 | TIntermBinary *test = node->getCondition()->getAsBinaryNode(); |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 2565 | |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2566 | if (test && test->getLeft()->getAsSymbolNode()->getId() == index->getId()) |
| 2567 | { |
| 2568 | TIntermConstantUnion *constant = test->getRight()->getAsConstantUnion(); |
| 2569 | |
| 2570 | if (constant) |
| 2571 | { |
shannonwoods@chromium.org | 09e0988 | 2013-05-30 00:18:25 +0000 | [diff] [blame] | 2572 | if (constant->getBasicType() == EbtInt && constant->isScalar()) |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2573 | { |
| 2574 | comparator = test->getOp(); |
shannon.woods%transgaming.com@gtempaccount.com | c0d0c22 | 2013-04-13 03:29:36 +0000 | [diff] [blame] | 2575 | limit = constant->getIConst(0); |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2576 | } |
| 2577 | } |
| 2578 | } |
| 2579 | } |
| 2580 | |
| 2581 | // Parse increment |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame] | 2582 | if (index != NULL && comparator != EOpNull && node->getExpression()) |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2583 | { |
alokp@chromium.org | 5281355 | 2010-11-16 18:36:09 +0000 | [diff] [blame] | 2584 | TIntermBinary *binaryTerminal = node->getExpression()->getAsBinaryNode(); |
| 2585 | TIntermUnary *unaryTerminal = node->getExpression()->getAsUnaryNode(); |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 2586 | |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2587 | if (binaryTerminal) |
| 2588 | { |
| 2589 | TOperator op = binaryTerminal->getOp(); |
| 2590 | TIntermConstantUnion *constant = binaryTerminal->getRight()->getAsConstantUnion(); |
| 2591 | |
| 2592 | if (constant) |
| 2593 | { |
shannonwoods@chromium.org | 09e0988 | 2013-05-30 00:18:25 +0000 | [diff] [blame] | 2594 | if (constant->getBasicType() == EbtInt && constant->isScalar()) |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2595 | { |
shannon.woods%transgaming.com@gtempaccount.com | c0d0c22 | 2013-04-13 03:29:36 +0000 | [diff] [blame] | 2596 | int value = constant->getIConst(0); |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2597 | |
| 2598 | switch (op) |
| 2599 | { |
| 2600 | case EOpAddAssign: increment = value; break; |
| 2601 | case EOpSubAssign: increment = -value; break; |
| 2602 | default: UNIMPLEMENTED(); |
| 2603 | } |
| 2604 | } |
| 2605 | } |
| 2606 | } |
| 2607 | else if (unaryTerminal) |
| 2608 | { |
| 2609 | TOperator op = unaryTerminal->getOp(); |
| 2610 | |
| 2611 | switch (op) |
| 2612 | { |
| 2613 | case EOpPostIncrement: increment = 1; break; |
| 2614 | case EOpPostDecrement: increment = -1; break; |
| 2615 | case EOpPreIncrement: increment = 1; break; |
| 2616 | case EOpPreDecrement: increment = -1; break; |
| 2617 | default: UNIMPLEMENTED(); |
| 2618 | } |
| 2619 | } |
| 2620 | } |
| 2621 | |
| 2622 | if (index != NULL && comparator != EOpNull && increment != 0) |
| 2623 | { |
| 2624 | if (comparator == EOpLessThanEqual) |
| 2625 | { |
| 2626 | comparator = EOpLessThan; |
| 2627 | limit += 1; |
| 2628 | } |
| 2629 | |
| 2630 | if (comparator == EOpLessThan) |
| 2631 | { |
daniel@transgaming.com | f1f538e | 2011-02-09 16:30:01 +0000 | [diff] [blame] | 2632 | int iterations = (limit - initial) / increment; |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2633 | |
daniel@transgaming.com | 06eb0d4 | 2012-05-31 01:17:14 +0000 | [diff] [blame] | 2634 | if (iterations <= MAX_LOOP_ITERATIONS) |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2635 | { |
| 2636 | return false; // Not an excessive loop |
| 2637 | } |
| 2638 | |
daniel@transgaming.com | e9b3f60 | 2012-07-11 20:37:31 +0000 | [diff] [blame] | 2639 | TIntermSymbol *restoreIndex = mExcessiveLoopIndex; |
| 2640 | mExcessiveLoopIndex = index; |
| 2641 | |
daniel@transgaming.com | 0933b0c | 2012-07-11 20:37:28 +0000 | [diff] [blame] | 2642 | out << "{int "; |
| 2643 | index->traverse(this); |
daniel@transgaming.com | 8c77f85 | 2012-07-11 20:37:35 +0000 | [diff] [blame] | 2644 | out << ";\n" |
| 2645 | "bool Break"; |
| 2646 | index->traverse(this); |
| 2647 | out << " = false;\n"; |
daniel@transgaming.com | c264de4 | 2012-07-11 20:37:25 +0000 | [diff] [blame] | 2648 | |
daniel@transgaming.com | 5b60f5e | 2012-07-11 20:37:38 +0000 | [diff] [blame] | 2649 | bool firstLoopFragment = true; |
| 2650 | |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2651 | while (iterations > 0) |
| 2652 | { |
daniel@transgaming.com | 06eb0d4 | 2012-05-31 01:17:14 +0000 | [diff] [blame] | 2653 | int clampedLimit = initial + increment * std::min(MAX_LOOP_ITERATIONS, iterations); |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2654 | |
daniel@transgaming.com | 5b60f5e | 2012-07-11 20:37:38 +0000 | [diff] [blame] | 2655 | if (!firstLoopFragment) |
| 2656 | { |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 2657 | out << "if (!Break"; |
daniel@transgaming.com | 5b60f5e | 2012-07-11 20:37:38 +0000 | [diff] [blame] | 2658 | index->traverse(this); |
| 2659 | out << ") {\n"; |
| 2660 | } |
daniel@transgaming.com | 2fe20a8 | 2012-07-11 20:37:41 +0000 | [diff] [blame] | 2661 | |
| 2662 | if (iterations <= MAX_LOOP_ITERATIONS) // Last loop fragment |
| 2663 | { |
| 2664 | mExcessiveLoopIndex = NULL; // Stops setting the Break flag |
| 2665 | } |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 2666 | |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2667 | // for(int index = initial; index < clampedLimit; index += increment) |
| 2668 | |
Nicolas Capens | 5e0c80a | 2014-10-10 10:11:54 -0400 | [diff] [blame] | 2669 | out << "LOOP for("; |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2670 | index->traverse(this); |
| 2671 | out << " = "; |
| 2672 | out << initial; |
| 2673 | |
| 2674 | out << "; "; |
| 2675 | index->traverse(this); |
| 2676 | out << " < "; |
| 2677 | out << clampedLimit; |
| 2678 | |
| 2679 | out << "; "; |
| 2680 | index->traverse(this); |
| 2681 | out << " += "; |
| 2682 | out << increment; |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 2683 | out << ")\n"; |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 2684 | |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 2685 | outputLineDirective(node->getLine().first_line); |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 2686 | out << "{\n"; |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2687 | |
| 2688 | if (node->getBody()) |
| 2689 | { |
| 2690 | node->getBody()->traverse(this); |
| 2691 | } |
| 2692 | |
Jamie Madill | 075edd8 | 2013-07-08 13:30:19 -0400 | [diff] [blame] | 2693 | outputLineDirective(node->getLine().first_line); |
daniel@transgaming.com | 5b60f5e | 2012-07-11 20:37:38 +0000 | [diff] [blame] | 2694 | out << ";}\n"; |
| 2695 | |
| 2696 | if (!firstLoopFragment) |
| 2697 | { |
| 2698 | out << "}\n"; |
| 2699 | } |
| 2700 | |
| 2701 | firstLoopFragment = false; |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2702 | |
daniel@transgaming.com | 06eb0d4 | 2012-05-31 01:17:14 +0000 | [diff] [blame] | 2703 | initial += MAX_LOOP_ITERATIONS * increment; |
| 2704 | iterations -= MAX_LOOP_ITERATIONS; |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2705 | } |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 2706 | |
daniel@transgaming.com | c264de4 | 2012-07-11 20:37:25 +0000 | [diff] [blame] | 2707 | out << "}"; |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2708 | |
daniel@transgaming.com | e9b3f60 | 2012-07-11 20:37:31 +0000 | [diff] [blame] | 2709 | mExcessiveLoopIndex = restoreIndex; |
| 2710 | |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 2711 | return true; |
| 2712 | } |
| 2713 | else UNIMPLEMENTED(); |
| 2714 | } |
| 2715 | |
| 2716 | return false; // Not handled as an excessive loop |
| 2717 | } |
| 2718 | |
Daniel Bratell | 2919008 | 2015-02-20 16:42:54 +0100 | [diff] [blame] | 2719 | void OutputHLSL::outputTriplet(Visit visit, const char *preString, const char *inString, const char *postString) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2720 | { |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame] | 2721 | TInfoSinkBase &out = getInfoSink(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2722 | |
daniel@transgaming.com | 67de6d6 | 2010-04-29 03:35:30 +0000 | [diff] [blame] | 2723 | if (visit == PreVisit) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2724 | { |
| 2725 | out << preString; |
| 2726 | } |
daniel@transgaming.com | 67de6d6 | 2010-04-29 03:35:30 +0000 | [diff] [blame] | 2727 | else if (visit == InVisit) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2728 | { |
| 2729 | out << inString; |
| 2730 | } |
daniel@transgaming.com | 67de6d6 | 2010-04-29 03:35:30 +0000 | [diff] [blame] | 2731 | else if (visit == PostVisit) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2732 | { |
| 2733 | out << postString; |
| 2734 | } |
| 2735 | } |
| 2736 | |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 2737 | void OutputHLSL::outputLineDirective(int line) |
| 2738 | { |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 2739 | if ((mCompileOptions & SH_LINE_DIRECTIVES) && (line > 0)) |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 2740 | { |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame] | 2741 | TInfoSinkBase &out = getInfoSink(); |
| 2742 | |
| 2743 | out << "\n"; |
| 2744 | out << "#line " << line; |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 2745 | |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 2746 | if (mSourcePath) |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 2747 | { |
Olli Etuaho | a3a5cc6 | 2015-02-13 13:12:22 +0200 | [diff] [blame] | 2748 | out << " \"" << mSourcePath << "\""; |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 2749 | } |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 2750 | |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame] | 2751 | out << "\n"; |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 2752 | } |
| 2753 | } |
| 2754 | |
daniel@transgaming.com | d1acd1e | 2010-04-13 03:25:57 +0000 | [diff] [blame] | 2755 | TString OutputHLSL::argumentString(const TIntermSymbol *symbol) |
| 2756 | { |
| 2757 | TQualifier qualifier = symbol->getQualifier(); |
| 2758 | const TType &type = symbol->getType(); |
daniel@transgaming.com | 005c739 | 2010-04-15 20:45:27 +0000 | [diff] [blame] | 2759 | TString name = symbol->getSymbol(); |
daniel@transgaming.com | d1acd1e | 2010-04-13 03:25:57 +0000 | [diff] [blame] | 2760 | |
daniel@transgaming.com | 005c739 | 2010-04-15 20:45:27 +0000 | [diff] [blame] | 2761 | if (name.empty()) // HLSL demands named arguments, also for prototypes |
| 2762 | { |
daniel@transgaming.com | b6ef8f1 | 2010-11-15 16:41:14 +0000 | [diff] [blame] | 2763 | name = "x" + str(mUniqueIndex++); |
daniel@transgaming.com | 005c739 | 2010-04-15 20:45:27 +0000 | [diff] [blame] | 2764 | } |
| 2765 | else |
| 2766 | { |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 2767 | name = Decorate(name); |
daniel@transgaming.com | 005c739 | 2010-04-15 20:45:27 +0000 | [diff] [blame] | 2768 | } |
| 2769 | |
shannon.woods@transgaming.com | 01a5cf9 | 2013-02-28 23:13:51 +0000 | [diff] [blame] | 2770 | if (mOutputType == SH_HLSL11_OUTPUT && IsSampler(type.getBasicType())) |
| 2771 | { |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 2772 | return QualifierString(qualifier) + " " + TextureString(type) + " texture_" + name + ArrayString(type) + ", " + |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 2773 | QualifierString(qualifier) + " " + SamplerString(type) + " sampler_" + name + ArrayString(type); |
shannon.woods@transgaming.com | 01a5cf9 | 2013-02-28 23:13:51 +0000 | [diff] [blame] | 2774 | } |
| 2775 | |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 2776 | return QualifierString(qualifier) + " " + TypeString(type) + " " + name + ArrayString(type); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | TString OutputHLSL::initializer(const TType &type) |
| 2780 | { |
| 2781 | TString string; |
| 2782 | |
Jamie Madill | 94bf7f2 | 2013-07-08 13:31:15 -0400 | [diff] [blame] | 2783 | size_t size = type.getObjectSize(); |
| 2784 | for (size_t component = 0; component < size; component++) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2785 | { |
daniel@transgaming.com | ead2304 | 2010-04-29 03:35:36 +0000 | [diff] [blame] | 2786 | string += "0"; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2787 | |
Jamie Madill | 94bf7f2 | 2013-07-08 13:31:15 -0400 | [diff] [blame] | 2788 | if (component + 1 < size) |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2789 | { |
| 2790 | string += ", "; |
| 2791 | } |
| 2792 | } |
| 2793 | |
daniel@transgaming.com | ead2304 | 2010-04-29 03:35:36 +0000 | [diff] [blame] | 2794 | return "{" + string + "}"; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2795 | } |
daniel@transgaming.com | 72d0b52 | 2010-04-13 19:53:44 +0000 | [diff] [blame] | 2796 | |
Daniel Bratell | 2919008 | 2015-02-20 16:42:54 +0100 | [diff] [blame] | 2797 | void OutputHLSL::outputConstructor(Visit visit, const TType &type, const char *name, const TIntermSequence *parameters) |
Nicolas Capens | 1af18dc | 2014-06-11 11:07:32 -0400 | [diff] [blame] | 2798 | { |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame] | 2799 | TInfoSinkBase &out = getInfoSink(); |
Nicolas Capens | 1af18dc | 2014-06-11 11:07:32 -0400 | [diff] [blame] | 2800 | |
| 2801 | if (visit == PreVisit) |
| 2802 | { |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 2803 | mStructureHLSL->addConstructor(type, name, parameters); |
Nicolas Capens | 1af18dc | 2014-06-11 11:07:32 -0400 | [diff] [blame] | 2804 | |
Daniel Bratell | 2919008 | 2015-02-20 16:42:54 +0100 | [diff] [blame] | 2805 | out << name << "("; |
Nicolas Capens | 1af18dc | 2014-06-11 11:07:32 -0400 | [diff] [blame] | 2806 | } |
| 2807 | else if (visit == InVisit) |
| 2808 | { |
| 2809 | out << ", "; |
| 2810 | } |
| 2811 | else if (visit == PostVisit) |
| 2812 | { |
| 2813 | out << ")"; |
| 2814 | } |
| 2815 | } |
| 2816 | |
daniel@transgaming.com | a54da4e | 2010-05-07 13:03:28 +0000 | [diff] [blame] | 2817 | const ConstantUnion *OutputHLSL::writeConstantUnion(const TType &type, const ConstantUnion *constUnion) |
| 2818 | { |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame] | 2819 | TInfoSinkBase &out = getInfoSink(); |
daniel@transgaming.com | a54da4e | 2010-05-07 13:03:28 +0000 | [diff] [blame] | 2820 | |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 2821 | const TStructure* structure = type.getStruct(); |
| 2822 | if (structure) |
daniel@transgaming.com | a54da4e | 2010-05-07 13:03:28 +0000 | [diff] [blame] | 2823 | { |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 2824 | out << StructNameString(*structure) + "_ctor("; |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 2825 | |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 2826 | const TFieldList& fields = structure->fields(); |
daniel@transgaming.com | a54da4e | 2010-05-07 13:03:28 +0000 | [diff] [blame] | 2827 | |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 2828 | for (size_t i = 0; i < fields.size(); i++) |
daniel@transgaming.com | a54da4e | 2010-05-07 13:03:28 +0000 | [diff] [blame] | 2829 | { |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 2830 | const TType *fieldType = fields[i]->type(); |
daniel@transgaming.com | a54da4e | 2010-05-07 13:03:28 +0000 | [diff] [blame] | 2831 | constUnion = writeConstantUnion(*fieldType, constUnion); |
| 2832 | |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 2833 | if (i != fields.size() - 1) |
daniel@transgaming.com | a54da4e | 2010-05-07 13:03:28 +0000 | [diff] [blame] | 2834 | { |
| 2835 | out << ", "; |
| 2836 | } |
| 2837 | } |
| 2838 | |
| 2839 | out << ")"; |
| 2840 | } |
| 2841 | else |
| 2842 | { |
Jamie Madill | 94bf7f2 | 2013-07-08 13:31:15 -0400 | [diff] [blame] | 2843 | size_t size = type.getObjectSize(); |
daniel@transgaming.com | a54da4e | 2010-05-07 13:03:28 +0000 | [diff] [blame] | 2844 | bool writeType = size > 1; |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 2845 | |
daniel@transgaming.com | a54da4e | 2010-05-07 13:03:28 +0000 | [diff] [blame] | 2846 | if (writeType) |
| 2847 | { |
Jamie Madill | 033dae6 | 2014-06-18 12:56:28 -0400 | [diff] [blame] | 2848 | out << TypeString(type) << "("; |
daniel@transgaming.com | a54da4e | 2010-05-07 13:03:28 +0000 | [diff] [blame] | 2849 | } |
| 2850 | |
Jamie Madill | 94bf7f2 | 2013-07-08 13:31:15 -0400 | [diff] [blame] | 2851 | for (size_t i = 0; i < size; i++, constUnion++) |
daniel@transgaming.com | a54da4e | 2010-05-07 13:03:28 +0000 | [diff] [blame] | 2852 | { |
| 2853 | switch (constUnion->getType()) |
| 2854 | { |
daniel@transgaming.com | 6c1203f | 2013-01-11 04:12:43 +0000 | [diff] [blame] | 2855 | case EbtFloat: out << std::min(FLT_MAX, std::max(-FLT_MAX, constUnion->getFConst())); break; |
daniel@transgaming.com | a54da4e | 2010-05-07 13:03:28 +0000 | [diff] [blame] | 2856 | case EbtInt: out << constUnion->getIConst(); break; |
Nicolas Capens | c0f7c61 | 2013-06-05 11:46:09 -0400 | [diff] [blame] | 2857 | case EbtUInt: out << constUnion->getUConst(); break; |
alokp@chromium.org | 4e4facd | 2010-06-02 15:21:22 +0000 | [diff] [blame] | 2858 | case EbtBool: out << constUnion->getBConst(); break; |
daniel@transgaming.com | a54da4e | 2010-05-07 13:03:28 +0000 | [diff] [blame] | 2859 | default: UNREACHABLE(); |
| 2860 | } |
| 2861 | |
| 2862 | if (i != size - 1) |
| 2863 | { |
| 2864 | out << ", "; |
| 2865 | } |
| 2866 | } |
| 2867 | |
| 2868 | if (writeType) |
| 2869 | { |
| 2870 | out << ")"; |
| 2871 | } |
| 2872 | } |
| 2873 | |
| 2874 | return constUnion; |
| 2875 | } |
| 2876 | |
Olli Etuaho | 5c9cd3d | 2014-12-18 13:04:25 +0200 | [diff] [blame] | 2877 | void OutputHLSL::writeEmulatedFunctionTriplet(Visit visit, const char *preStr) |
| 2878 | { |
| 2879 | TString preString = BuiltInFunctionEmulator::GetEmulatedFunctionName(preStr); |
| 2880 | outputTriplet(visit, preString.c_str(), ", ", ")"); |
| 2881 | } |
| 2882 | |
Jamie Madill | 3799714 | 2015-01-28 10:06:34 -0500 | [diff] [blame] | 2883 | bool OutputHLSL::writeSameSymbolInitializer(TInfoSinkBase &out, TIntermSymbol *symbolNode, TIntermTyped *expression) |
| 2884 | { |
| 2885 | sh::SearchSymbol searchSymbol(symbolNode->getSymbol()); |
| 2886 | expression->traverse(&searchSymbol); |
| 2887 | |
| 2888 | if (searchSymbol.foundMatch()) |
| 2889 | { |
| 2890 | // Type already printed |
| 2891 | out << "t" + str(mUniqueIndex) + " = "; |
| 2892 | expression->traverse(this); |
| 2893 | out << ", "; |
| 2894 | symbolNode->traverse(this); |
| 2895 | out << " = t" + str(mUniqueIndex); |
| 2896 | |
| 2897 | mUniqueIndex++; |
| 2898 | return true; |
| 2899 | } |
| 2900 | |
| 2901 | return false; |
| 2902 | } |
| 2903 | |
| 2904 | void OutputHLSL::writeDeferredGlobalInitializers(TInfoSinkBase &out) |
| 2905 | { |
| 2906 | out << "#define ANGLE_USES_DEFERRED_INIT\n" |
| 2907 | << "\n" |
| 2908 | << "void initializeDeferredGlobals()\n" |
| 2909 | << "{\n"; |
| 2910 | |
| 2911 | for (const auto &deferredGlobal : mDeferredGlobalInitializers) |
| 2912 | { |
| 2913 | TIntermSymbol *symbol = deferredGlobal.first; |
| 2914 | TIntermTyped *expression = deferredGlobal.second; |
| 2915 | ASSERT(symbol); |
| 2916 | ASSERT(symbol->getQualifier() == EvqGlobal && expression->getQualifier() != EvqConst); |
| 2917 | |
| 2918 | out << " " << Decorate(symbol->getSymbol()) << " = "; |
| 2919 | |
| 2920 | if (!writeSameSymbolInitializer(out, symbol, expression)) |
| 2921 | { |
| 2922 | ASSERT(mInfoSinkStack.top() == &out); |
| 2923 | expression->traverse(this); |
| 2924 | } |
| 2925 | |
| 2926 | out << ";\n"; |
| 2927 | } |
| 2928 | |
| 2929 | out << "}\n" |
| 2930 | << "\n"; |
| 2931 | } |
| 2932 | |
Jamie Madill | 55e79e0 | 2015-02-09 15:35:00 -0500 | [diff] [blame] | 2933 | TString OutputHLSL::addStructEqualityFunction(const TStructure &structure) |
| 2934 | { |
| 2935 | const TFieldList &fields = structure.fields(); |
| 2936 | |
| 2937 | for (const auto &eqFunction : mStructEqualityFunctions) |
| 2938 | { |
| 2939 | if (eqFunction.structure == &structure) |
| 2940 | { |
| 2941 | return eqFunction.functionName; |
| 2942 | } |
| 2943 | } |
| 2944 | |
| 2945 | const TString &structNameString = StructNameString(structure); |
| 2946 | |
| 2947 | StructEqualityFunction function; |
| 2948 | function.structure = &structure; |
| 2949 | function.functionName = "angle_eq_" + structNameString; |
| 2950 | |
| 2951 | TString &func = function.functionDefinition; |
| 2952 | |
| 2953 | func = "bool " + function.functionName + "(" + structNameString + " a, " + structNameString + " b)\n" + |
| 2954 | "{\n" |
| 2955 | " return "; |
| 2956 | |
| 2957 | for (size_t i = 0; i < fields.size(); i++) |
| 2958 | { |
| 2959 | const TField *field = fields[i]; |
| 2960 | const TType *fieldType = field->type(); |
| 2961 | |
| 2962 | const TString &fieldNameA = "a." + Decorate(field->name()); |
| 2963 | const TString &fieldNameB = "b." + Decorate(field->name()); |
| 2964 | |
| 2965 | if (i > 0) |
| 2966 | { |
| 2967 | func += " && "; |
| 2968 | } |
| 2969 | |
| 2970 | if (fieldType->getBasicType() == EbtStruct) |
| 2971 | { |
| 2972 | const TStructure &fieldStruct = *fieldType->getStruct(); |
| 2973 | const TString &functionName = addStructEqualityFunction(fieldStruct); |
| 2974 | func += functionName + "(" + fieldNameA + ", " + fieldNameB + ")"; |
| 2975 | } |
| 2976 | else if (fieldType->isScalar()) |
| 2977 | { |
| 2978 | func += "(" + fieldNameA + " == " + fieldNameB + ")"; |
| 2979 | } |
| 2980 | else |
| 2981 | { |
| 2982 | ASSERT(fieldType->isMatrix() || fieldType->isVector()); |
| 2983 | func += "all(" + fieldNameA + " == " + fieldNameB + ")"; |
| 2984 | } |
| 2985 | } |
| 2986 | |
| 2987 | func = func + ";\n" + "}\n"; |
| 2988 | |
| 2989 | mStructEqualityFunctions.push_back(function); |
| 2990 | |
| 2991 | return function.functionName; |
| 2992 | } |
| 2993 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 2994 | } |