Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 5851ef4

Browse files
committed
Don't treat SIMD::Float preferentially
Intermediate::Scalar was defined as RValue<SIMD::Float>, even though it can hold integers as well. Use abstract Reactor values instead which don't have a statically defined type. This change does not yet avoid bitcasting on access. The EmitLoad() implementation still assumes values come in as float. Bug b/128539387 Change-Id: I18f449ebf68db7ddd81679d6d028911e6c02fc38 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/26868 Presubmit-Ready: Nicolas Capens <[email protected]> Kokoro-Presubmit: kokoro <[email protected]> Tested-by: Nicolas Capens <[email protected]> Reviewed-by: Ben Clayton <[email protected]> Reviewed-by: Chris Forbes <[email protected]>
1 parent 3e485a4 commit 5851ef4

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

src/Pipeline/SpirvShader.hpp

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -66,49 +66,46 @@ namespace sw
6666
class Intermediate
6767
{
6868
public:
69-
using Scalar = RValue<SIMD::Float>;
70-
71-
Intermediate(uint32_t size) : contents(new ContentsType[size]), size(size) {
69+
Intermediate(uint32_t size) : scalar(new rr::Value*[size]), size(size) {
7270
#if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
73-
memset(contents, 0, sizeof(ContentsType) * size);
71+
memset(scalar, 0, sizeof(rr::Value*) * size);
7472
#endif
7573
}
7674

7775
~Intermediate()
7876
{
79-
for (auto i = 0u; i < size; i++)
80-
reinterpret_cast<Scalar *>(&contents[i])->~Scalar();
81-
delete [] contents;
77+
delete[] scalar;
8278
}
8379

84-
void emplace(uint32_t n, Scalar&& value)
80+
void emplace(uint32_t i, RValue<SIMD::Float> &&scalar) { emplace(i, scalar.value); }
81+
void emplace(uint32_t i, RValue<SIMD::Int> &&scalar) { emplace(i, scalar.value); }
82+
void emplace(uint32_t i, RValue<SIMD::UInt> &&scalar) { emplace(i, scalar.value); }
83+
84+
void emplace(uint32_t i, const RValue<SIMD::Float> &scalar) { emplace(i, scalar.value); }
85+
void emplace(uint32_t i, const RValue<SIMD::Int> &scalar) { emplace(i, scalar.value); }
86+
void emplace(uint32_t i, const RValue<SIMD::UInt> &scalar) { emplace(i, scalar.value); }
87+
88+
// Value retrieval functions.
89+
RValue<SIMD::Float> Float(uint32_t i) const
8590
{
86-
ASSERT(n < size);
87-
ASSERT(reinterpret_cast<Scalar const *>(&contents[n])->value == nullptr);
88-
new (&contents[n]) Scalar(value);
91+
ASSERT(i < size);
92+
ASSERT(scalar[i] != nullptr);
93+
return As<SIMD::Float>(scalar[i]); // TODO(b/128539387): RValue<SIMD::Float>(scalar)
8994
}
9095

91-
void emplace(uint32_t n, const Scalar& value)
96+
RValue<SIMD::Int> Int(uint32_t i) const
9297
{
93-
ASSERT(n < size);
94-
ASSERT(reinterpret_cast<Scalar const *>(&contents[n])->value == nullptr);
95-
new (&contents[n]) Scalar(value);
98+
ASSERT(i < size);
99+
ASSERT(scalar[i] != nullptr);
100+
return As<SIMD::Int>(scalar[i]); // TODO(b/128539387): RValue<SIMD::Int>(scalar)
96101
}
97102

98-
// Emplace with cast helpers.
99-
void emplace(uint32_t n, const RValue<SIMD::Int>& value) { emplace(n, As<SIMD::Float>(value)); }
100-
void emplace(uint32_t n, const RValue<SIMD::UInt>& value) { emplace(n, As<SIMD::Float>(value)); }
101-
102-
// Value retrieval functions.
103-
RValue<SIMD::Float> Float(uint32_t i) const
103+
RValue<SIMD::UInt> UInt(uint32_t i) const
104104
{
105105
ASSERT(i < size);
106-
auto scalar = reinterpret_cast<Scalar const *>(&contents[i]);
107-
ASSERT(scalar->value != nullptr);
108-
return *scalar;
106+
ASSERT(scalar[i] != nullptr);
107+
return As<SIMD::UInt>(scalar[i]); // TODO(b/128539387): RValue<SIMD::UInt>(scalar)
109108
}
110-
RValue<SIMD::Int> Int(uint32_t i) const { return As<SIMD::Int>(Float(i)); }
111-
RValue<SIMD::UInt> UInt(uint32_t i) const { return As<SIMD::UInt>(Float(i)); }
112109

113110
// No copy/move construction or assignment
114111
Intermediate(Intermediate const &) = delete;
@@ -117,9 +114,14 @@ namespace sw
117114
Intermediate & operator=(Intermediate &&) = delete;
118115

119116
private:
120-
using ContentsType = std::aligned_storage<sizeof(Scalar), alignof(Scalar)>::type;
117+
void emplace(uint32_t i, rr::Value *value)
118+
{
119+
ASSERT(i < size);
120+
ASSERT(scalar[i] == nullptr);
121+
scalar[i] = value;
122+
}
121123

122-
ContentsType *contents;
124+
rr::Value **const scalar;
123125
uint32_t size;
124126
};
125127

0 commit comments

Comments
 (0)