Skip to content

Commit 84b0cf1

Browse files
ShabbyXAngle LUCI CQ
authored andcommitted
Translator: Validate gl_FragData xor gl_FragColor early
The translator validates that these two built-ins are not simultaneously used. This validation is moved earlier to the post-parse checks. Bug: angleproject:349994211 Change-Id: I59f1266406c3f82da560f3a18bb88571ab614d75 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/7022017 Reviewed-by: Geoff Lang <[email protected]> Commit-Queue: Shahbaz Youssefi <[email protected]> Reviewed-by: Yuxin Hu <[email protected]>
1 parent 8c15b96 commit 84b0cf1

File tree

2 files changed

+51
-51
lines changed

2 files changed

+51
-51
lines changed

src/compiler/translator/Compiler.cpp

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
#include "compiler/translator/tree_ops/glsl/apple/AddAndTrueToLoopCondition.h"
6464
#include "compiler/translator/tree_ops/glsl/apple/UnfoldShortCircuitAST.h"
6565
#include "compiler/translator/tree_ops/msl/EnsureLoopForwardProgress.h"
66-
#include "compiler/translator/tree_util/BuiltIn.h"
6766
#include "compiler/translator/tree_util/FindSymbolNode.h"
6867
#include "compiler/translator/tree_util/IntermNodePatternMatcher.h"
6968
#include "compiler/translator/tree_util/ReplaceShadowingVariables.h"
@@ -424,51 +423,6 @@ int GetMaxShaderVersionForSpec(ShShaderSpec spec)
424423
}
425424
}
426425

427-
bool ValidateFragColorAndFragData(GLenum shaderType,
428-
int shaderVersion,
429-
const TSymbolTable &symbolTable,
430-
TDiagnostics *diagnostics)
431-
{
432-
if (shaderVersion > 100 || shaderType != GL_FRAGMENT_SHADER)
433-
{
434-
return true;
435-
}
436-
437-
bool usesFragColor = false;
438-
bool usesFragData = false;
439-
// This validation is a bit stricter than the spec - it's only an error to write to
440-
// both FragData and FragColor. But because it's better not to have reads from undefined
441-
// variables, we always return an error if they are both referenced, rather than only if they
442-
// are written.
443-
if (symbolTable.isStaticallyUsed(*BuiltInVariable::gl_FragColor()) ||
444-
symbolTable.isStaticallyUsed(*BuiltInVariable::gl_SecondaryFragColorEXT()))
445-
{
446-
usesFragColor = true;
447-
}
448-
// Extension variables may not always be initialized (saves some time at symbol table init).
449-
bool secondaryFragDataUsed =
450-
symbolTable.gl_SecondaryFragDataEXT() != nullptr &&
451-
symbolTable.isStaticallyUsed(*symbolTable.gl_SecondaryFragDataEXT());
452-
if (symbolTable.isStaticallyUsed(*symbolTable.gl_FragData()) || secondaryFragDataUsed)
453-
{
454-
usesFragData = true;
455-
}
456-
if (usesFragColor && usesFragData)
457-
{
458-
const char *errorMessage = "cannot use both gl_FragData and gl_FragColor";
459-
if (symbolTable.isStaticallyUsed(*BuiltInVariable::gl_SecondaryFragColorEXT()) ||
460-
secondaryFragDataUsed)
461-
{
462-
errorMessage =
463-
"cannot use both output variable sets (gl_FragData, gl_SecondaryFragDataEXT)"
464-
" and (gl_FragColor, gl_SecondaryFragColorEXT)";
465-
}
466-
diagnostics->globalError(errorMessage);
467-
return false;
468-
}
469-
return true;
470-
}
471-
472426
} // namespace
473427

474428
TShHandleBase::TShHandleBase()
@@ -934,11 +888,6 @@ bool TCompiler::checkAndSimplifyAST(TIntermBlock *root,
934888
return false;
935889
}
936890

937-
if (!ValidateFragColorAndFragData(mShaderType, mShaderVersion, mSymbolTable, &mDiagnostics))
938-
{
939-
return false;
940-
}
941-
942891
// Fold expressions that could not be folded before validation that was done as a part of
943892
// parsing.
944893
if (!FoldExpressions(this, root, &mDiagnostics))

src/compiler/translator/ParseContext.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "compiler/translator/ValidateGlobalInitializer.h"
2222
#include "compiler/translator/ValidateSwitch.h"
2323
#include "compiler/translator/glslang.h"
24+
#include "compiler/translator/tree_util/BuiltIn.h"
2425
#include "compiler/translator/tree_util/IntermNode_util.h"
2526
#include "compiler/translator/util.h"
2627

@@ -300,6 +301,51 @@ void MarkClipCullIndex(const TSourceLoc &line, TIntermTyped *indexExpr, ClipCull
300301
info->hasNonConstIndex = true;
301302
}
302303
}
304+
305+
bool ValidateFragColorAndFragData(GLenum shaderType,
306+
int shaderVersion,
307+
const TSymbolTable &symbolTable,
308+
TDiagnostics *diagnostics)
309+
{
310+
if (shaderVersion > 100 || shaderType != GL_FRAGMENT_SHADER)
311+
{
312+
return true;
313+
}
314+
315+
bool usesFragColor = false;
316+
bool usesFragData = false;
317+
// This validation is a bit stricter than the spec - it's only an error to write to
318+
// both FragData and FragColor. But because it's better not to have reads from undefined
319+
// variables, we always return an error if they are both referenced, rather than only if they
320+
// are written.
321+
if (symbolTable.isStaticallyUsed(*BuiltInVariable::gl_FragColor()) ||
322+
symbolTable.isStaticallyUsed(*BuiltInVariable::gl_SecondaryFragColorEXT()))
323+
{
324+
usesFragColor = true;
325+
}
326+
// Extension variables may not always be initialized (saves some time at symbol table init).
327+
bool secondaryFragDataUsed =
328+
symbolTable.gl_SecondaryFragDataEXT() != nullptr &&
329+
symbolTable.isStaticallyUsed(*symbolTable.gl_SecondaryFragDataEXT());
330+
if (symbolTable.isStaticallyUsed(*symbolTable.gl_FragData()) || secondaryFragDataUsed)
331+
{
332+
usesFragData = true;
333+
}
334+
if (usesFragColor && usesFragData)
335+
{
336+
const char *errorMessage = "cannot use both gl_FragData and gl_FragColor";
337+
if (symbolTable.isStaticallyUsed(*BuiltInVariable::gl_SecondaryFragColorEXT()) ||
338+
secondaryFragDataUsed)
339+
{
340+
errorMessage =
341+
"cannot use both output variable sets (gl_FragData, gl_SecondaryFragDataEXT)"
342+
" and (gl_FragColor, gl_SecondaryFragColorEXT)";
343+
}
344+
diagnostics->globalError(errorMessage);
345+
return false;
346+
}
347+
return true;
348+
}
303349
} // namespace
304350

305351
// This tracks each binding point's current default offset for inheritance of subsequent
@@ -8463,6 +8509,11 @@ bool TParseContext::postParseChecks()
84638509
success = false;
84648510
}
84658511

8512+
if (!ValidateFragColorAndFragData(mShaderType, mShaderVersion, symbolTable, mDiagnostics))
8513+
{
8514+
success = false;
8515+
}
8516+
84668517
return success;
84678518
}
84688519

0 commit comments

Comments
 (0)