Revert previous update to ConstantsData::SetConstantArray<bool> and fix unit tests (#6351)
Signed-off-by: Steve Pham <82231385+spham-amzn@users.noreply.github.com>
This commit is contained in:
@@ -154,20 +154,9 @@ namespace AZ
|
||||
bool isValidAll = true;
|
||||
uint32_t offset = 0;
|
||||
|
||||
// Rather than doing the direct validation against values directly, we have to convert the array_view
|
||||
// to a raw byte array, and then check against the bytes to determine whether or not to set the
|
||||
// uint32 value to 1 (true) or 0 (false). Clang when building in non-debug builds was optimizing out
|
||||
// the actual 1 and 0 values, so an expression like:
|
||||
//
|
||||
// const uint32_t fourByteValue = values[i] ? 1 : 0;
|
||||
//
|
||||
// when values[0] == 205, will instead set 'fourByteValue' is assigned to '205', instead of '1'.
|
||||
// In debug builds, and other microsoft compilers (debug+release), this type of optimization doesnt
|
||||
// occur and we get the expected results instead
|
||||
const AZ::u8* byteValues = reinterpret_cast<const AZ::u8*>(values.data());
|
||||
for (size_t i = 0; i < values.size(); i++)
|
||||
{
|
||||
const uint32_t fourByteValue = byteValues[i] ? 1 : 0;
|
||||
const uint32_t fourByteValue = values[i] ? 1 : 0;
|
||||
const bool isValid = SetConstantRaw(inputIndex, &fourByteValue, offset, elementSize);
|
||||
|
||||
isValidAll &= isValid;
|
||||
|
||||
+1
-1
@@ -265,7 +265,7 @@ namespace UnitTest
|
||||
EXPECT_TRUE(m_srg->SetConstantArray<bool>(inputIndex, AZStd::array<bool, 2>({ asBools[1], asBools[2] })));
|
||||
AZStd::array_view<uint8_t> result = m_srg->GetConstantRaw(inputIndex);
|
||||
AZStd::array_view <uint32_t> resultInUint = AZStd::array_view<uint32_t>(reinterpret_cast<const uint32_t*>(result.data()), 2);
|
||||
ExpectEqual<uint32_t>({ 1 /*true*/, 0 /*false*/ }, resultInUint);
|
||||
EXPECT_THAT(resultInUint, testing::ElementsAre(testing::IsTrue(), testing::IsFalse()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user