Hash :
35bc74d6
Author :
Date :
2018-08-03T14:07:59
ES31: Support atomic functions on D3D11 - Part II This patch adds the support of translating atomicExchange and atomicCompSwap without return value on D3D11 back-ends. As the last parameter of the HLSL intrinsic functions InterlockedExchange and InterlockedCompareExchange is not optional, when there is a call of either atomicExchange or atomicCompSwap without return value, we add a temporary variable for it, so that we can directly translate all of such calls in outputHLSL.cpp. BUG=angleproject:2682 TEST=angle_end2end_tests Change-Id: I7e9c6d3c7d1846c865909b2f5a26592846c82582 Reviewed-on: https://chromium-review.googlesource.com/1161744 Reviewed-by: Geoff Lang <geofflang@chromium.org> Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
//
// Copyright (c) 2018 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.
//
// Implementation of the function RewriteAtomicFunctionExpressions.
// See the header for more details.
#include "RewriteAtomicFunctionExpressions.h"
#include "compiler/translator/tree_util/IntermNodePatternMatcher.h"
#include "compiler/translator/tree_util/IntermNode_util.h"
#include "compiler/translator/tree_util/IntermTraverse.h"
namespace sh
{
namespace
{
// Traverser that simplifies all the atomic function expressions into the ones that can be directly
// translated into HLSL.
class RewriteAtomicFunctionExpressionsTraverser : public TIntermTraverser
{
public:
RewriteAtomicFunctionExpressionsTraverser(TSymbolTable *symbolTable);
bool visitAggregate(Visit visit, TIntermAggregate *node) override;
private:
static bool IsAtomicExchangeOrCompSwapNoReturnValue(TIntermAggregate *node,
TIntermNode *parentNode);
void separateAtomicFunctionCallNode(TIntermAggregate *oldAtomicFunctionNode);
};
RewriteAtomicFunctionExpressionsTraverser::RewriteAtomicFunctionExpressionsTraverser(
TSymbolTable *symbolTable)
: TIntermTraverser(true, false, false, symbolTable)
{
}
void RewriteAtomicFunctionExpressionsTraverser::separateAtomicFunctionCallNode(
TIntermAggregate *oldAtomicFunctionNode)
{
ASSERT(oldAtomicFunctionNode);
TIntermSequence insertions;
// Declare a temporary variable
TIntermDeclaration *returnVariableDeclaration;
TVariable *returnVariable = DeclareTempVariable(mSymbolTable, &oldAtomicFunctionNode->getType(),
EvqTemporary, &returnVariableDeclaration);
insertions.push_back(returnVariableDeclaration);
// Use this variable as the return value of the atomic function call.
TIntermBinary *atomicFunctionAssignment = new TIntermBinary(
TOperator::EOpAssign, CreateTempSymbolNode(returnVariable), oldAtomicFunctionNode);
insertStatementsInParentBlock(insertions);
queueReplacement(atomicFunctionAssignment, OriginalNode::IS_DROPPED);
}
bool RewriteAtomicFunctionExpressionsTraverser::IsAtomicExchangeOrCompSwapNoReturnValue(
TIntermAggregate *node,
TIntermNode *parentNode)
{
ASSERT(node);
return (node->getOp() == EOpAtomicExchange || node->getOp() == EOpAtomicCompSwap) &&
parentNode && parentNode->getAsBlock();
}
bool RewriteAtomicFunctionExpressionsTraverser::visitAggregate(Visit visit, TIntermAggregate *node)
{
if (IsAtomicExchangeOrCompSwapNoReturnValue(node, getParentNode()))
{
separateAtomicFunctionCallNode(node);
return false;
}
return true;
}
} // anonymous namespace
void RewriteAtomicFunctionExpressions(TIntermNode *root, TSymbolTable *symbolTable)
{
RewriteAtomicFunctionExpressionsTraverser traverser(symbolTable);
traverser.traverse(root);
traverser.updateTree();
}
} // namespace sh