Commit b2d6a9be by Olli Etuaho

Stub simplifying array assignment for HLSL output

Add an AST traverser that rejects shaders with expressions that use the return value of an assignment where an array is assigned to another array. In the future this should be made into a tool that can simplify these expressions so that return values of array assignments are not used. In its current form this code prevents OutputHLSL from producing garbage code when the original code contains expressions like a = (b = c); where a, b, and c are all arrays. BUG=angleproject:960 Change-Id: I11353d7ed7160c853e58a0ef3471ca439cb314c8 Reviewed-on: https://chromium-review.googlesource.com/263070Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 1269076c
......@@ -153,6 +153,8 @@
'compiler/translator/RemoveSwitchFallThrough.h',
'compiler/translator/RewriteElseBlocks.cpp',
'compiler/translator/RewriteElseBlocks.h',
'compiler/translator/SimplifyArrayAssignment.cpp',
'compiler/translator/SimplifyArrayAssignment.h',
'compiler/translator/StructureHLSL.cpp',
'compiler/translator/StructureHLSL.h',
'compiler/translator/TranslatorHLSL.cpp',
......
//
// Copyright (c) 2002-2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
#include "compiler/translator/SimplifyArrayAssignment.h"
bool SimplifyArrayAssignment::visitBinary(Visit visit, TIntermBinary *node)
{
switch (node->getOp())
{
case EOpAssign:
{
TIntermNode *parent = getParentNode();
if (node->getLeft()->isArray() && parent != nullptr)
{
TIntermAggregate *parentAgg = parent->getAsAggregate();
if (parentAgg != nullptr && parentAgg->getOp() == EOpSequence)
{
// This case is fine, the result of the assignment is not used.
break;
}
// The result of the assignment needs to be stored into a temporary variable,
// the assignment needs to be replaced with a reference to the temporary variable,
// and the temporary variable needs to finally be assigned to the target variable.
// This also needs to interact correctly with unfolding short circuiting operators.
UNIMPLEMENTED();
}
}
break;
default:
break;
}
return true;
}
//
// Copyright (c) 2002-2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// SimplifyArrayAssignment is an AST traverser to replace statements where
// the return value of array assignment is used with statements where
// the return value of array assignment is not used.
//
#ifndef COMPILER_TRANSLATOR_SIMPLIFYARRAYASSIGNMENT_H_
#define COMPILER_TRANSLATOR_SIMPLIFYARRAYASSIGNMENT_H_
#include "common/angleutils.h"
#include "compiler/translator/IntermNode.h"
class SimplifyArrayAssignment : public TIntermTraverser
{
public:
SimplifyArrayAssignment() { }
virtual bool visitBinary(Visit visit, TIntermBinary *node);
};
#endif // COMPILER_TRANSLATOR_SIMPLIFYARRAYASSIGNMENT_H_
......@@ -7,6 +7,7 @@
#include "compiler/translator/TranslatorHLSL.h"
#include "compiler/translator/OutputHLSL.h"
#include "compiler/translator/SimplifyArrayAssignment.h"
TranslatorHLSL::TranslatorHLSL(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output)
: TCompiler(type, spec, output)
......@@ -18,6 +19,9 @@ void TranslatorHLSL::translate(TIntermNode *root, int compileOptions)
const ShBuiltInResources &resources = getResources();
int numRenderTargets = resources.EXT_draw_buffers ? resources.MaxDrawBuffers : 1;
SimplifyArrayAssignment simplify;
root->traverse(&simplify);
sh::OutputHLSL outputHLSL(getShaderType(), getShaderVersion(), getExtensionBehavior(),
getSourcePath(), getOutputType(), numRenderTargets, getUniforms(), compileOptions);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment