Commit baf328ab by Nicolas Capens Committed by Nicolas Capens

Fix construction of SPIR-V constant float objects

Constructing a constant SIMD::Float is not guaranteed to preserve the data's exact bit pattern, but SPIR-V provides 32-bit words representing "the bit pattern for the constant". Thus we must first construct an integer constant, and bitcast to float. Bug: b/140302841 Change-Id: I1a84dab9d1adbdc15f8a3b2fc639c637d2841174 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/36208 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 a070dcf0
......@@ -1108,17 +1108,21 @@ namespace sw
RValue<SIMD::Float> Float(uint32_t i) const
{
if (intermediate != nullptr)
if (intermediate)
{
return intermediate->Float(i);
}
auto constantValue = reinterpret_cast<float *>(obj.constantValue.get());
return SIMD::Float(constantValue[i]);
// Constructing a constant SIMD::Float is not guaranteed to preserve the data's exact
// bit pattern, but SPIR-V provides 32-bit words representing "the bit pattern for the constant".
// Thus we must first construct an integer constant, and bitcast to float.
auto constantValue = reinterpret_cast<uint32_t *>(obj.constantValue.get());
return As<SIMD::Float>(SIMD::UInt(constantValue[i]));
}
RValue<SIMD::Int> Int(uint32_t i) const
{
if (intermediate != nullptr)
if (intermediate)
{
return intermediate->Int(i);
}
......@@ -1128,7 +1132,7 @@ namespace sw
RValue<SIMD::UInt> UInt(uint32_t i) const
{
if (intermediate != nullptr)
if (intermediate)
{
return intermediate->UInt(i);
}
......
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