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