Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2013 The ANGLE Project Authors. All rights reserved. |
| 3 | // Use of this source code is governed by a BSD-style license that can be |
| 4 | // found in the LICENSE file. |
| 5 | // |
| 6 | |
Geoff Lang | 1773282 | 2013-08-29 13:46:49 -0400 | [diff] [blame] | 7 | #include "compiler/translator/ValidateOutputs.h" |
| 8 | #include "compiler/translator/InfoSink.h" |
| 9 | #include "compiler/translator/InitializeParseContext.h" |
Jamie Madill | 6b9cb25 | 2013-10-17 10:45:47 -0400 | [diff] [blame] | 10 | #include "compiler/translator/ParseContext.h" |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 11 | |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 12 | namespace |
| 13 | { |
| 14 | void error(int *errorCount, TInfoSinkBase &sink, const TIntermSymbol &symbol, const char *reason) |
| 15 | { |
| 16 | sink.prefix(EPrefixError); |
| 17 | sink.location(symbol.getLine()); |
| 18 | sink << "'" << symbol.getSymbol() << "' : " << reason << "\n"; |
| 19 | (*errorCount)++; |
| 20 | } |
| 21 | |
| 22 | } // namespace |
| 23 | |
| 24 | ValidateOutputs::ValidateOutputs(const TExtensionBehavior &extBehavior, int maxDrawBuffers) |
Olli Etuaho | 3d0d9a4 | 2015-06-01 12:16:36 +0300 | [diff] [blame] | 25 | : TIntermTraverser(true, false, false), |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 26 | mMaxDrawBuffers(maxDrawBuffers), |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 27 | mAllowUnspecifiedOutputLocationResolution( |
| 28 | IsExtensionEnabled(extBehavior, "GL_EXT_blend_func_extended")) |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 29 | { |
| 30 | } |
| 31 | |
| 32 | void ValidateOutputs::visitSymbol(TIntermSymbol *symbol) |
| 33 | { |
| 34 | TString name = symbol->getSymbol(); |
| 35 | TQualifier qualifier = symbol->getQualifier(); |
| 36 | |
Jamie Madill | 5ed2398 | 2016-04-22 15:08:57 -0400 | [diff] [blame] | 37 | if (mVisitedSymbols.count(name.c_str()) == 1) |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 38 | return; |
| 39 | |
Jamie Madill | 5ed2398 | 2016-04-22 15:08:57 -0400 | [diff] [blame] | 40 | mVisitedSymbols.insert(name.c_str()); |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 41 | |
Jamie Madill | 1957181 | 2013-08-12 15:26:34 -0700 | [diff] [blame] | 42 | if (qualifier == EvqFragmentOut) |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 43 | { |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 44 | if (symbol->getType().getLayoutQualifier().location == -1) |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 45 | { |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 46 | mUnspecifiedLocationOutputs.push_back(symbol); |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 47 | } |
| 48 | else |
| 49 | { |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 50 | mOutputs.push_back(symbol); |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 51 | } |
| 52 | } |
| 53 | } |
| 54 | |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 55 | int ValidateOutputs::validateAndCountErrors(TInfoSinkBase &sink) const |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 56 | { |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 57 | OutputVector validOutputs(mMaxDrawBuffers); |
| 58 | int errorCount = 0; |
| 59 | |
| 60 | for (const auto &symbol : mOutputs) |
| 61 | { |
| 62 | const TType &type = symbol->getType(); |
Olli Etuaho | 856c497 | 2016-08-08 11:38:39 +0300 | [diff] [blame^] | 63 | const size_t elementCount = static_cast<size_t>(type.isArray() ? type.getArraySize() : 1u); |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 64 | const size_t location = static_cast<size_t>(type.getLayoutQualifier().location); |
| 65 | |
| 66 | ASSERT(type.getLayoutQualifier().location != -1); |
| 67 | |
| 68 | if (location + elementCount <= validOutputs.size()) |
| 69 | { |
| 70 | for (size_t elementIndex = 0; elementIndex < elementCount; elementIndex++) |
| 71 | { |
| 72 | const size_t offsetLocation = location + elementIndex; |
| 73 | if (validOutputs[offsetLocation]) |
| 74 | { |
| 75 | std::stringstream strstr; |
| 76 | strstr << "conflicting output locations with previously defined output '" |
| 77 | << validOutputs[offsetLocation]->getSymbol() << "'"; |
| 78 | error(&errorCount, sink, *symbol, strstr.str().c_str()); |
| 79 | } |
| 80 | else |
| 81 | { |
| 82 | validOutputs[offsetLocation] = symbol; |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | else |
| 87 | { |
| 88 | if (elementCount > 0) |
| 89 | { |
| 90 | error(&errorCount, sink, *symbol, |
| 91 | elementCount > 1 ? "output array locations would exceed MAX_DRAW_BUFFERS" |
| 92 | : "output location must be < MAX_DRAW_BUFFERS"); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | if (!mAllowUnspecifiedOutputLocationResolution && |
| 98 | ((!mOutputs.empty() && !mUnspecifiedLocationOutputs.empty()) || |
| 99 | mUnspecifiedLocationOutputs.size() > 1)) |
| 100 | { |
| 101 | for (const auto &symbol : mUnspecifiedLocationOutputs) |
| 102 | { |
| 103 | error(&errorCount, sink, *symbol, |
| 104 | "must explicitly specify all locations when using multiple fragment outputs"); |
| 105 | } |
| 106 | } |
| 107 | return errorCount; |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 108 | } |