Commit dc550b2d by Nicolas Capens Committed by Nicolas Capens

Fix storing of non-float SPIR-V constants

Reactor Float scalar and vector constants may not fully preserve the bit pattern of the values they were constructed from. Specifically, signaling NaN values (sNaN) may become quiet NaN values (qNaN). Thus they should not be used for storing SPIR-V constant objects to memory. Interpret the data as integer instead. Note Object::constantValue is already a uint32_t array. Bug: b/140302841 Change-Id: Ifd51eec9d2b7adab8fef5de74e2e30d080a28fd5 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/35909 Presubmit-Ready: Nicolas Capens <nicolascapens@google.com> Kokoro-Presubmit: kokoro <noreply+kokoro@google.com> Tested-by: 's avatarNicolas Capens <nicolascapens@google.com> Reviewed-by: 's avatarChris Forbes <chrisforbes@google.com>
parent b1d3bbfc
......@@ -773,11 +773,11 @@ namespace sw
break;
case spv::OpConstantFalse:
case spv::OpSpecConstantFalse:
CreateConstant(insn).constantValue[0] = 0; // represent boolean false as zero
CreateConstant(insn).constantValue[0] = 0; // Represent Boolean false as zero.
break;
case spv::OpConstantTrue:
case spv::OpSpecConstantTrue:
CreateConstant(insn).constantValue[0] = ~0u; // represent boolean true as all bits set
CreateConstant(insn).constantValue[0] = ~0u; // Represent Boolean true as all bits set.
break;
case spv::OpConstantNull:
case spv::OpUndef:
......@@ -802,7 +802,9 @@ namespace sw
auto &constituent = getObject(insn.word(i + 3));
auto &constituentTy = getType(constituent.type);
for (auto j = 0u; j < constituentTy.sizeInComponents; j++)
{
object.constantValue[offset++] = constituent.constantValue[j];
}
}
auto objectId = Object::ID(insn.word(2));
......@@ -2997,12 +2999,12 @@ namespace sw
if (object.kind == Object::Kind::Constant)
{
// Constant source data.
auto src = reinterpret_cast<float *>(object.constantValue.get());
const uint32_t *src = object.constantValue.get();
VisitMemoryObject(pointerId, [&](uint32_t i, uint32_t offset)
{
auto p = ptr + offset;
if (interleavedByLane) { p = interleaveByLane(p); }
SIMD::Store(p, SIMD::Float(src[i]), robustness, mask, atomic, memoryOrder);
SIMD::Store(p, SIMD::Int(src[i]), robustness, mask, atomic, memoryOrder);
});
}
else
......
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