Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2014 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | // StructureHLSL.cpp: |
| 7 | // Definitions of methods for HLSL translation of GLSL structures. |
| 8 | // |
| 9 | |
| 10 | #include "compiler/translator/StructureHLSL.h" |
| 11 | #include "common/utilities.h" |
| 12 | #include "compiler/translator/OutputHLSL.h" |
| 13 | #include "compiler/translator/Types.h" |
| 14 | #include "compiler/translator/util.h" |
| 15 | #include "compiler/translator/UtilsHLSL.h" |
| 16 | |
| 17 | namespace sh |
| 18 | { |
| 19 | |
Jamie Madill | 33a74bd | 2014-08-18 15:47:59 -0400 | [diff] [blame] | 20 | Std140PaddingHelper::Std140PaddingHelper(const std::map<TString, int> &structElementIndexes, |
| 21 | unsigned *uniqueCounter) |
| 22 | : mPaddingCounter(uniqueCounter), |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 23 | mElementIndex(0), |
Jamie Madill | 80d934b | 2015-02-19 10:16:12 -0500 | [diff] [blame] | 24 | mStructElementIndexes(&structElementIndexes) |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 25 | {} |
| 26 | |
Jamie Madill | 80d934b | 2015-02-19 10:16:12 -0500 | [diff] [blame] | 27 | Std140PaddingHelper::Std140PaddingHelper(const Std140PaddingHelper &other) |
| 28 | : mPaddingCounter(other.mPaddingCounter), |
| 29 | mElementIndex(other.mElementIndex), |
| 30 | mStructElementIndexes(other.mStructElementIndexes) |
| 31 | {} |
| 32 | |
| 33 | Std140PaddingHelper &Std140PaddingHelper::operator=(const Std140PaddingHelper &other) |
| 34 | { |
| 35 | mPaddingCounter = other.mPaddingCounter; |
| 36 | mElementIndex = other.mElementIndex; |
| 37 | mStructElementIndexes = other.mStructElementIndexes; |
| 38 | return *this; |
| 39 | } |
| 40 | |
Jamie Madill | 33a74bd | 2014-08-18 15:47:59 -0400 | [diff] [blame] | 41 | TString Std140PaddingHelper::next() |
| 42 | { |
| 43 | unsigned value = (*mPaddingCounter)++; |
| 44 | return str(value); |
| 45 | } |
| 46 | |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 47 | int Std140PaddingHelper::prePadding(const TType &type) |
| 48 | { |
| 49 | if (type.getBasicType() == EbtStruct || type.isMatrix() || type.isArray()) |
| 50 | { |
| 51 | // no padding needed, HLSL will align the field to a new register |
| 52 | mElementIndex = 0; |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | const GLenum glType = GLVariableType(type); |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 57 | const int numComponents = gl::VariableComponentCount(glType); |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 58 | |
| 59 | if (numComponents >= 4) |
| 60 | { |
| 61 | // no padding needed, HLSL will align the field to a new register |
| 62 | mElementIndex = 0; |
| 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | if (mElementIndex + numComponents > 4) |
| 67 | { |
| 68 | // no padding needed, HLSL will align the field to a new register |
| 69 | mElementIndex = numComponents; |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | const int alignment = numComponents == 3 ? 4 : numComponents; |
| 74 | const int paddingOffset = (mElementIndex % alignment); |
| 75 | const int paddingCount = (paddingOffset != 0 ? (alignment - paddingOffset) : 0); |
| 76 | |
| 77 | mElementIndex += paddingCount; |
| 78 | mElementIndex += numComponents; |
| 79 | mElementIndex %= 4; |
| 80 | |
| 81 | return paddingCount; |
| 82 | } |
| 83 | |
| 84 | TString Std140PaddingHelper::prePaddingString(const TType &type) |
| 85 | { |
| 86 | int paddingCount = prePadding(type); |
| 87 | |
| 88 | TString padding; |
| 89 | |
| 90 | for (int paddingIndex = 0; paddingIndex < paddingCount; paddingIndex++) |
| 91 | { |
Jamie Madill | 33a74bd | 2014-08-18 15:47:59 -0400 | [diff] [blame] | 92 | padding += " float pad_" + next() + ";\n"; |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | return padding; |
| 96 | } |
| 97 | |
| 98 | TString Std140PaddingHelper::postPaddingString(const TType &type, bool useHLSLRowMajorPacking) |
| 99 | { |
| 100 | if (!type.isMatrix() && !type.isArray() && type.getBasicType() != EbtStruct) |
| 101 | { |
| 102 | return ""; |
| 103 | } |
| 104 | |
| 105 | int numComponents = 0; |
| 106 | TStructure *structure = type.getStruct(); |
| 107 | |
| 108 | if (type.isMatrix()) |
| 109 | { |
| 110 | // This method can also be called from structureString, which does not use layout qualifiers. |
| 111 | // Thus, use the method parameter for determining the matrix packing. |
| 112 | // |
| 113 | // Note HLSL row major packing corresponds to GL API column-major, and vice-versa, since we |
| 114 | // wish to always transpose GL matrices to play well with HLSL's matrix array indexing. |
| 115 | // |
| 116 | const bool isRowMajorMatrix = !useHLSLRowMajorPacking; |
| 117 | const GLenum glType = GLVariableType(type); |
| 118 | numComponents = gl::MatrixComponentCount(glType, isRowMajorMatrix); |
| 119 | } |
| 120 | else if (structure) |
| 121 | { |
| 122 | const TString &structName = QualifiedStructNameString(*structure, |
| 123 | useHLSLRowMajorPacking, true); |
Jamie Madill | 80d934b | 2015-02-19 10:16:12 -0500 | [diff] [blame] | 124 | numComponents = mStructElementIndexes->find(structName)->second; |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 125 | |
| 126 | if (numComponents == 0) |
| 127 | { |
| 128 | return ""; |
| 129 | } |
| 130 | } |
| 131 | else |
| 132 | { |
| 133 | const GLenum glType = GLVariableType(type); |
Jamie Madill | f257598 | 2014-06-25 16:04:54 -0400 | [diff] [blame] | 134 | numComponents = gl::VariableComponentCount(glType); |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | TString padding; |
| 138 | for (int paddingOffset = numComponents; paddingOffset < 4; paddingOffset++) |
| 139 | { |
Jamie Madill | 33a74bd | 2014-08-18 15:47:59 -0400 | [diff] [blame] | 140 | padding += " float pad_" + next() + ";\n"; |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 141 | } |
| 142 | return padding; |
| 143 | } |
| 144 | |
| 145 | StructureHLSL::StructureHLSL() |
Jamie Madill | 33a74bd | 2014-08-18 15:47:59 -0400 | [diff] [blame] | 146 | : mUniquePaddingCounter(0) |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 147 | {} |
| 148 | |
Jamie Madill | 33a74bd | 2014-08-18 15:47:59 -0400 | [diff] [blame] | 149 | Std140PaddingHelper StructureHLSL::getPaddingHelper() |
| 150 | { |
| 151 | return Std140PaddingHelper(mStd140StructElementIndexes, &mUniquePaddingCounter); |
| 152 | } |
| 153 | |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 154 | TString StructureHLSL::defineQualified(const TStructure &structure, bool useHLSLRowMajorPacking, bool useStd140Packing) |
| 155 | { |
| 156 | if (useStd140Packing) |
| 157 | { |
Jamie Madill | 33a74bd | 2014-08-18 15:47:59 -0400 | [diff] [blame] | 158 | Std140PaddingHelper padHelper = getPaddingHelper(); |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 159 | return define(structure, useHLSLRowMajorPacking, useStd140Packing, &padHelper); |
| 160 | } |
| 161 | else |
| 162 | { |
| 163 | return define(structure, useHLSLRowMajorPacking, useStd140Packing, NULL); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | TString StructureHLSL::defineNameless(const TStructure &structure) |
| 168 | { |
| 169 | return define(structure, false, false, NULL); |
| 170 | } |
| 171 | |
| 172 | TString StructureHLSL::define(const TStructure &structure, bool useHLSLRowMajorPacking, |
| 173 | bool useStd140Packing, Std140PaddingHelper *padHelper) |
| 174 | { |
| 175 | const TFieldList &fields = structure.fields(); |
| 176 | const bool isNameless = (structure.name() == ""); |
| 177 | const TString &structName = QualifiedStructNameString(structure, useHLSLRowMajorPacking, |
| 178 | useStd140Packing); |
| 179 | const TString declareString = (isNameless ? "struct" : "struct " + structName); |
| 180 | |
| 181 | TString string; |
| 182 | string += declareString + "\n" |
| 183 | "{\n"; |
| 184 | |
| 185 | for (unsigned int i = 0; i < fields.size(); i++) |
| 186 | { |
| 187 | const TField &field = *fields[i]; |
| 188 | const TType &fieldType = *field.type(); |
| 189 | const TStructure *fieldStruct = fieldType.getStruct(); |
| 190 | const TString &fieldTypeString = fieldStruct ? |
| 191 | QualifiedStructNameString(*fieldStruct, useHLSLRowMajorPacking, |
| 192 | useStd140Packing) : |
| 193 | TypeString(fieldType); |
| 194 | |
| 195 | if (padHelper) |
| 196 | { |
| 197 | string += padHelper->prePaddingString(fieldType); |
| 198 | } |
| 199 | |
| 200 | string += " " + fieldTypeString + " " + DecorateField(field.name(), structure) + ArrayString(fieldType) + ";\n"; |
| 201 | |
| 202 | if (padHelper) |
| 203 | { |
| 204 | string += padHelper->postPaddingString(fieldType, useHLSLRowMajorPacking); |
| 205 | } |
| 206 | } |
| 207 | |
| 208 | // Nameless structs do not finish with a semicolon and newline, to leave room for an instance variable |
| 209 | string += (isNameless ? "} " : "};\n"); |
| 210 | |
| 211 | return string; |
| 212 | } |
| 213 | |
Olli Etuaho | be59c2f | 2016-03-07 11:32:34 +0200 | [diff] [blame] | 214 | TString StructureHLSL::addConstructor(const TType &type, |
| 215 | const TString &name, |
| 216 | const TIntermSequence *parameters) |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 217 | { |
| 218 | if (name == "") |
| 219 | { |
Olli Etuaho | be59c2f | 2016-03-07 11:32:34 +0200 | [diff] [blame] | 220 | return TString(); // Nameless structures don't have constructors |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | if (type.getStruct() && mStructNames.find(name) != mStructNames.end()) |
| 224 | { |
Olli Etuaho | be59c2f | 2016-03-07 11:32:34 +0200 | [diff] [blame] | 225 | return TString(name); // Already added |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | TType ctorType = type; |
| 229 | ctorType.clearArrayness(); |
| 230 | ctorType.setPrecision(EbpHigh); |
| 231 | ctorType.setQualifier(EvqTemporary); |
| 232 | |
| 233 | typedef std::vector<TType> ParameterArray; |
| 234 | ParameterArray ctorParameters; |
| 235 | |
Olli Etuaho | be59c2f | 2016-03-07 11:32:34 +0200 | [diff] [blame] | 236 | TString constructorFunctionName; |
| 237 | |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 238 | const TStructure* structure = type.getStruct(); |
| 239 | if (structure) |
| 240 | { |
| 241 | mStructNames.insert(name); |
| 242 | |
| 243 | // Add element index |
| 244 | storeStd140ElementIndex(*structure, false); |
| 245 | storeStd140ElementIndex(*structure, true); |
| 246 | |
| 247 | const TString &structString = defineQualified(*structure, false, false); |
| 248 | |
| 249 | if (std::find(mStructDeclarations.begin(), mStructDeclarations.end(), structString) == mStructDeclarations.end()) |
| 250 | { |
| 251 | // Add row-major packed struct for interface blocks |
| 252 | TString rowMajorString = "#pragma pack_matrix(row_major)\n" + |
| 253 | defineQualified(*structure, true, false) + |
| 254 | "#pragma pack_matrix(column_major)\n"; |
| 255 | |
| 256 | TString std140String = defineQualified(*structure, false, true); |
| 257 | TString std140RowMajorString = "#pragma pack_matrix(row_major)\n" + |
| 258 | defineQualified(*structure, true, true) + |
| 259 | "#pragma pack_matrix(column_major)\n"; |
| 260 | |
| 261 | mStructDeclarations.push_back(structString); |
| 262 | mStructDeclarations.push_back(rowMajorString); |
| 263 | mStructDeclarations.push_back(std140String); |
| 264 | mStructDeclarations.push_back(std140RowMajorString); |
| 265 | } |
| 266 | |
| 267 | const TFieldList &fields = structure->fields(); |
| 268 | for (unsigned int i = 0; i < fields.size(); i++) |
| 269 | { |
| 270 | ctorParameters.push_back(*fields[i]->type()); |
| 271 | } |
Olli Etuaho | be59c2f | 2016-03-07 11:32:34 +0200 | [diff] [blame] | 272 | constructorFunctionName = TString(name); |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 273 | } |
| 274 | else if (parameters) |
| 275 | { |
Olli Etuaho | be59c2f | 2016-03-07 11:32:34 +0200 | [diff] [blame] | 276 | for (auto parameter : *parameters) |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 277 | { |
Olli Etuaho | be59c2f | 2016-03-07 11:32:34 +0200 | [diff] [blame] | 278 | const TType ¶mType = parameter->getAsTyped()->getType(); |
| 279 | ctorParameters.push_back(paramType); |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 280 | } |
Olli Etuaho | be59c2f | 2016-03-07 11:32:34 +0200 | [diff] [blame] | 281 | constructorFunctionName = TString(name) + DisambiguateFunctionName(parameters); |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 282 | } |
| 283 | else UNREACHABLE(); |
| 284 | |
| 285 | TString constructor; |
| 286 | |
| 287 | if (ctorType.getStruct()) |
| 288 | { |
| 289 | constructor += name + " " + name + "_ctor("; |
| 290 | } |
| 291 | else // Built-in type |
| 292 | { |
Olli Etuaho | be59c2f | 2016-03-07 11:32:34 +0200 | [diff] [blame] | 293 | constructor += TypeString(ctorType) + " " + constructorFunctionName + "("; |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 294 | } |
| 295 | |
| 296 | for (unsigned int parameter = 0; parameter < ctorParameters.size(); parameter++) |
| 297 | { |
Austin Kinross | 3ae6465 | 2015-01-26 15:51:39 -0800 | [diff] [blame] | 298 | const TType ¶mType = ctorParameters[parameter]; |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 299 | |
Austin Kinross | 3ae6465 | 2015-01-26 15:51:39 -0800 | [diff] [blame] | 300 | constructor += TypeString(paramType) + " x" + str(parameter) + ArrayString(paramType); |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 301 | |
| 302 | if (parameter < ctorParameters.size() - 1) |
| 303 | { |
| 304 | constructor += ", "; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | constructor += ")\n" |
| 309 | "{\n"; |
| 310 | |
| 311 | if (ctorType.getStruct()) |
| 312 | { |
| 313 | constructor += " " + name + " structure = {"; |
| 314 | } |
| 315 | else |
| 316 | { |
| 317 | constructor += " return " + TypeString(ctorType) + "("; |
| 318 | } |
| 319 | |
| 320 | if (ctorType.isMatrix() && ctorParameters.size() == 1) |
| 321 | { |
| 322 | int rows = ctorType.getRows(); |
| 323 | int cols = ctorType.getCols(); |
| 324 | const TType ¶meter = ctorParameters[0]; |
| 325 | |
| 326 | if (parameter.isScalar()) |
| 327 | { |
Jamie Madill | cf3af0b | 2014-08-01 17:22:16 -0400 | [diff] [blame] | 328 | for (int col = 0; col < cols; col++) |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 329 | { |
Jamie Madill | cf3af0b | 2014-08-01 17:22:16 -0400 | [diff] [blame] | 330 | for (int row = 0; row < rows; row++) |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 331 | { |
| 332 | constructor += TString((row == col) ? "x0" : "0.0"); |
| 333 | |
| 334 | if (row < rows - 1 || col < cols - 1) |
| 335 | { |
| 336 | constructor += ", "; |
| 337 | } |
| 338 | } |
| 339 | } |
| 340 | } |
| 341 | else if (parameter.isMatrix()) |
| 342 | { |
Jamie Madill | f4e39bf | 2014-08-01 17:22:17 -0400 | [diff] [blame] | 343 | for (int col = 0; col < cols; col++) |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 344 | { |
Jamie Madill | f4e39bf | 2014-08-01 17:22:17 -0400 | [diff] [blame] | 345 | for (int row = 0; row < rows; row++) |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 346 | { |
| 347 | if (row < parameter.getRows() && col < parameter.getCols()) |
| 348 | { |
Jamie Madill | f4e39bf | 2014-08-01 17:22:17 -0400 | [diff] [blame] | 349 | constructor += TString("x0") + "[" + str(col) + "][" + str(row) + "]"; |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 350 | } |
| 351 | else |
| 352 | { |
| 353 | constructor += TString((row == col) ? "1.0" : "0.0"); |
| 354 | } |
| 355 | |
| 356 | if (row < rows - 1 || col < cols - 1) |
| 357 | { |
| 358 | constructor += ", "; |
| 359 | } |
| 360 | } |
| 361 | } |
| 362 | } |
| 363 | else |
| 364 | { |
| 365 | ASSERT(rows == 2 && cols == 2 && parameter.isVector() && parameter.getNominalSize() == 4); |
| 366 | |
| 367 | constructor += "x0"; |
| 368 | } |
| 369 | } |
| 370 | else |
| 371 | { |
| 372 | size_t remainingComponents = ctorType.getObjectSize(); |
| 373 | size_t parameterIndex = 0; |
| 374 | |
| 375 | while (remainingComponents > 0) |
| 376 | { |
| 377 | const TType ¶meter = ctorParameters[parameterIndex]; |
| 378 | const size_t parameterSize = parameter.getObjectSize(); |
| 379 | bool moreParameters = parameterIndex + 1 < ctorParameters.size(); |
| 380 | |
| 381 | constructor += "x" + str(parameterIndex); |
| 382 | |
| 383 | if (ctorType.getStruct()) |
| 384 | { |
| 385 | ASSERT(remainingComponents == parameterSize || moreParameters); |
| 386 | ASSERT(parameterSize <= remainingComponents); |
| 387 | |
| 388 | remainingComponents -= parameterSize; |
| 389 | } |
| 390 | else if (parameter.isScalar()) |
| 391 | { |
| 392 | remainingComponents -= parameter.getObjectSize(); |
| 393 | } |
| 394 | else if (parameter.isVector()) |
| 395 | { |
| 396 | if (remainingComponents == parameterSize || moreParameters) |
| 397 | { |
| 398 | ASSERT(parameterSize <= remainingComponents); |
| 399 | remainingComponents -= parameterSize; |
| 400 | } |
| 401 | else if (remainingComponents < static_cast<size_t>(parameter.getNominalSize())) |
| 402 | { |
| 403 | switch (remainingComponents) |
| 404 | { |
| 405 | case 1: constructor += ".x"; break; |
| 406 | case 2: constructor += ".xy"; break; |
| 407 | case 3: constructor += ".xyz"; break; |
| 408 | case 4: constructor += ".xyzw"; break; |
| 409 | default: UNREACHABLE(); |
| 410 | } |
| 411 | |
| 412 | remainingComponents = 0; |
| 413 | } |
| 414 | else UNREACHABLE(); |
| 415 | } |
| 416 | else if (parameter.isMatrix()) |
| 417 | { |
| 418 | int column = 0; |
| 419 | while (remainingComponents > 0 && column < parameter.getCols()) |
| 420 | { |
| 421 | constructor += "[" + str(column) + "]"; |
| 422 | |
| 423 | if (remainingComponents < static_cast<size_t>(parameter.getRows())) |
| 424 | { |
| 425 | switch (remainingComponents) |
| 426 | { |
| 427 | case 1: constructor += ".x"; break; |
| 428 | case 2: constructor += ".xy"; break; |
| 429 | case 3: constructor += ".xyz"; break; |
| 430 | default: UNREACHABLE(); |
| 431 | } |
| 432 | |
| 433 | remainingComponents = 0; |
| 434 | } |
| 435 | else |
| 436 | { |
| 437 | remainingComponents -= parameter.getRows(); |
| 438 | |
| 439 | if (remainingComponents > 0) |
| 440 | { |
| 441 | constructor += ", x" + str(parameterIndex); |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | column++; |
| 446 | } |
| 447 | } |
| 448 | else UNREACHABLE(); |
| 449 | |
| 450 | if (moreParameters) |
| 451 | { |
| 452 | parameterIndex++; |
| 453 | } |
| 454 | |
| 455 | if (remainingComponents) |
| 456 | { |
| 457 | constructor += ", "; |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | if (ctorType.getStruct()) |
| 463 | { |
| 464 | constructor += "};\n" |
| 465 | " return structure;\n" |
| 466 | "}\n"; |
| 467 | } |
| 468 | else |
| 469 | { |
| 470 | constructor += ");\n" |
| 471 | "}\n"; |
| 472 | } |
| 473 | |
| 474 | mConstructors.insert(constructor); |
Olli Etuaho | be59c2f | 2016-03-07 11:32:34 +0200 | [diff] [blame] | 475 | |
| 476 | return constructorFunctionName; |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | std::string StructureHLSL::structsHeader() const |
| 480 | { |
| 481 | TInfoSinkBase out; |
| 482 | |
| 483 | for (size_t structIndex = 0; structIndex < mStructDeclarations.size(); structIndex++) |
| 484 | { |
| 485 | out << mStructDeclarations[structIndex]; |
| 486 | } |
| 487 | |
Jamie Madill | 961d5e9 | 2014-06-20 15:23:34 -0400 | [diff] [blame] | 488 | for (Constructors::const_iterator constructor = mConstructors.begin(); |
| 489 | constructor != mConstructors.end(); |
| 490 | constructor++) |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 491 | { |
| 492 | out << *constructor; |
| 493 | } |
| 494 | |
| 495 | return out.str(); |
| 496 | } |
| 497 | |
| 498 | void StructureHLSL::storeStd140ElementIndex(const TStructure &structure, bool useHLSLRowMajorPacking) |
| 499 | { |
Jamie Madill | 33a74bd | 2014-08-18 15:47:59 -0400 | [diff] [blame] | 500 | Std140PaddingHelper padHelper = getPaddingHelper(); |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 501 | const TFieldList &fields = structure.fields(); |
| 502 | |
| 503 | for (unsigned int i = 0; i < fields.size(); i++) |
| 504 | { |
| 505 | padHelper.prePadding(*fields[i]->type()); |
| 506 | } |
| 507 | |
| 508 | // Add remaining element index to the global map, for use with nested structs in standard layouts |
| 509 | const TString &structName = QualifiedStructNameString(structure, useHLSLRowMajorPacking, true); |
| 510 | mStd140StructElementIndexes[structName] = padHelper.elementIndex(); |
| 511 | } |
| 512 | |
Jamie Madill | 9e5317f | 2014-06-20 14:56:37 -0400 | [diff] [blame] | 513 | } |