Hash :
f563fdc9
Author :
Date :
2019-01-31T13:53:59
Reland "Fix unit test for setting locale creating malformed HLSL shader code Fix malformed HLSL shader code in other locales than classic" This is a reland of 5f662c0042703344eb0eef6d1c123e902e3aefbf Original change's description: > Fix unit test for setting locale creating malformed HLSL shader code > Fix malformed HLSL shader code in other locales than classic > > Bug: angleproject:1433 > Change-Id: I30bad0bd0cfda465ec7200e48e12800d7d8efd26 > Reviewed-on: https://chromium-review.googlesource.com/c/1447862 > Reviewed-by: Geoff Lang <geofflang@chromium.org> > Reviewed-by: Jamie Madill <jmadill@chromium.org> > Commit-Queue: Jonah Ryan-Davis <jonahr@google.com> Bug: angleproject:1433 Change-Id: I94caf7b4c7179119e5a5567c3014d7232df45a13 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/1516192 Reviewed-by: Geoff Lang <geofflang@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Jonah Ryan-Davis <jonahr@google.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 89 90 91 92 93 94 95 96 97 98 99 100 101
//
// 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.
//
// AtomicCounterFunctionHLSL: Class for writing implementation of atomic counter functions into HLSL
// output.
//
#include "compiler/translator/AtomicCounterFunctionHLSL.h"
#include "compiler/translator/Common.h"
#include "compiler/translator/ImmutableStringBuilder.h"
#include "compiler/translator/InfoSink.h"
#include "compiler/translator/IntermNode.h"
namespace sh
{
namespace
{
constexpr ImmutableString kAtomicCounter("atomicCounter");
constexpr ImmutableString kAtomicCounterIncrement("atomicCounterIncrement");
constexpr ImmutableString kAtomicCounterDecrement("atomicCounterDecrement");
constexpr ImmutableString kAtomicCounterBaseName("_acbase_");
} // namespace
ImmutableString AtomicCounterFunctionHLSL::useAtomicCounterFunction(const ImmutableString &name)
{
// The largest string that will be create created is "_acbase_increment" or "_acbase_decrement"
ImmutableStringBuilder hlslFunctionNameSB(kAtomicCounterBaseName.length() +
strlen("increment"));
hlslFunctionNameSB << kAtomicCounterBaseName;
AtomicCounterFunction atomicMethod;
if (kAtomicCounter == name)
{
atomicMethod = AtomicCounterFunction::LOAD;
hlslFunctionNameSB << "load";
}
else if (kAtomicCounterIncrement == name)
{
atomicMethod = AtomicCounterFunction::INCREMENT;
hlslFunctionNameSB << "increment";
}
else if (kAtomicCounterDecrement == name)
{
atomicMethod = AtomicCounterFunction::DECREMENT;
hlslFunctionNameSB << "decrement";
}
else
{
atomicMethod = AtomicCounterFunction::INVALID;
UNREACHABLE();
}
ImmutableString hlslFunctionName(hlslFunctionNameSB);
mAtomicCounterFunctions[hlslFunctionName] = atomicMethod;
return hlslFunctionName;
}
void AtomicCounterFunctionHLSL::atomicCounterFunctionHeader(TInfoSinkBase &out)
{
for (auto &atomicFunction : mAtomicCounterFunctions)
{
out << "uint " << atomicFunction.first
<< "(in RWByteAddressBuffer counter, int address)\n"
"{\n";
switch (atomicFunction.second)
{
case AtomicCounterFunction::INCREMENT:
case AtomicCounterFunction::DECREMENT:
out << " uint ret;\n"
" counter.InterlockedAdd(address, ";
if (atomicFunction.second == AtomicCounterFunction::DECREMENT)
{
out << "0u - ";
}
out << "1u, ret);\n"
<< " return ret;\n";
break;
case AtomicCounterFunction::LOAD:
out << " return counter.Load(address);\n";
break;
default:
UNREACHABLE();
break;
}
out << "}\n\n";
}
}
ImmutableString getAtomicCounterNameForBinding(int binding)
{
std::stringstream counterName = sh::InitializeStream<std::stringstream>();
counterName << kAtomicCounterBaseName << binding;
return ImmutableString(counterName.str());
}
} // namespace sh