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 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 12 | namespace sh |
| 13 | { |
| 14 | |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 15 | namespace |
| 16 | { |
| 17 | void error(int *errorCount, TInfoSinkBase &sink, const TIntermSymbol &symbol, const char *reason) |
| 18 | { |
| 19 | sink.prefix(EPrefixError); |
| 20 | sink.location(symbol.getLine()); |
| 21 | sink << "'" << symbol.getSymbol() << "' : " << reason << "\n"; |
| 22 | (*errorCount)++; |
| 23 | } |
| 24 | |
| 25 | } // namespace |
| 26 | |
| 27 | ValidateOutputs::ValidateOutputs(const TExtensionBehavior &extBehavior, int maxDrawBuffers) |
Olli Etuaho | 3d0d9a4 | 2015-06-01 12:16:36 +0300 | [diff] [blame] | 28 | : TIntermTraverser(true, false, false), |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 29 | mMaxDrawBuffers(maxDrawBuffers), |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 30 | mAllowUnspecifiedOutputLocationResolution( |
| 31 | IsExtensionEnabled(extBehavior, "GL_EXT_blend_func_extended")) |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 32 | { |
| 33 | } |
| 34 | |
| 35 | void ValidateOutputs::visitSymbol(TIntermSymbol *symbol) |
| 36 | { |
| 37 | TString name = symbol->getSymbol(); |
| 38 | TQualifier qualifier = symbol->getQualifier(); |
| 39 | |
Jamie Madill | 5ed2398 | 2016-04-22 15:08:57 -0400 | [diff] [blame] | 40 | if (mVisitedSymbols.count(name.c_str()) == 1) |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 41 | return; |
| 42 | |
Jamie Madill | 5ed2398 | 2016-04-22 15:08:57 -0400 | [diff] [blame] | 43 | mVisitedSymbols.insert(name.c_str()); |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 44 | |
Jamie Madill | 1957181 | 2013-08-12 15:26:34 -0700 | [diff] [blame] | 45 | if (qualifier == EvqFragmentOut) |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 46 | { |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 47 | if (symbol->getType().getLayoutQualifier().location == -1) |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 48 | { |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 49 | mUnspecifiedLocationOutputs.push_back(symbol); |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 50 | } |
| 51 | else |
| 52 | { |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 53 | mOutputs.push_back(symbol); |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 54 | } |
| 55 | } |
| 56 | } |
| 57 | |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 58 | int ValidateOutputs::validateAndCountErrors(TInfoSinkBase &sink) const |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 59 | { |
Kimmo Kinnunen | b18609b | 2015-07-16 14:13:11 +0300 | [diff] [blame] | 60 | OutputVector validOutputs(mMaxDrawBuffers); |
| 61 | int errorCount = 0; |
| 62 | |
| 63 | for (const auto &symbol : mOutputs) |
| 64 | { |
| 65 | const TType &type = symbol->getType(); |
Olli Etuaho | 856c497 | 2016-08-08 11:38:39 +0300 | [diff] [blame] | 66 | 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] | 67 | const size_t location = static_cast<size_t>(type.getLayoutQualifier().location); |
| 68 | |
| 69 | ASSERT(type.getLayoutQualifier().location != -1); |
| 70 | |
| 71 | if (location + elementCount <= validOutputs.size()) |
| 72 | { |
| 73 | for (size_t elementIndex = 0; elementIndex < elementCount; elementIndex++) |
| 74 | { |
| 75 | const size_t offsetLocation = location + elementIndex; |
| 76 | if (validOutputs[offsetLocation]) |
| 77 | { |
| 78 | std::stringstream strstr; |
| 79 | strstr << "conflicting output locations with previously defined output '" |
| 80 | << validOutputs[offsetLocation]->getSymbol() << "'"; |
| 81 | error(&errorCount, sink, *symbol, strstr.str().c_str()); |
| 82 | } |
| 83 | else |
| 84 | { |
| 85 | validOutputs[offsetLocation] = symbol; |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | else |
| 90 | { |
| 91 | if (elementCount > 0) |
| 92 | { |
| 93 | error(&errorCount, sink, *symbol, |
| 94 | elementCount > 1 ? "output array locations would exceed MAX_DRAW_BUFFERS" |
| 95 | : "output location must be < MAX_DRAW_BUFFERS"); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | if (!mAllowUnspecifiedOutputLocationResolution && |
| 101 | ((!mOutputs.empty() && !mUnspecifiedLocationOutputs.empty()) || |
| 102 | mUnspecifiedLocationOutputs.size() > 1)) |
| 103 | { |
| 104 | for (const auto &symbol : mUnspecifiedLocationOutputs) |
| 105 | { |
| 106 | error(&errorCount, sink, *symbol, |
| 107 | "must explicitly specify all locations when using multiple fragment outputs"); |
| 108 | } |
| 109 | } |
| 110 | return errorCount; |
Jamie Madill | 05a80ce | 2013-06-20 11:55:49 -0400 | [diff] [blame] | 111 | } |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 112 | |
| 113 | } // namespace sh |