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