Commit 51b03d58 by Ben Clayton

SpirvShaderDebugger: Fix store() of arrays

``` template<typename T, std::size_t N> void store(const rr::RValue<rr::Pointer<rr::Byte>> &ptr, const std::array<T, N> &val) ``` was completely broken as it was using `sizeof(T)` for element offsets. All uses of this overload use Reactor values for T, and so `sizeof(T)` evaluates to the size of the compiler type, not the runtime data type. Also remove the useless `for(int i = 0; i < N; i++)` in `buildGlobal()`. This iterator isn't used, so we're just doing the same calls to `put()` `N` times. Bug: b/170383642 Change-Id: I9ba9efce07e886087124118122de56a4d31c5503 Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/49129 Kokoro-Result: kokoro <noreply+kokoro@google.com> Reviewed-by: 's avatarNicolas Capens <nicolascapens@google.com> Tested-by: 's avatarBen Clayton <bclayton@google.com>
parent 19612714
...@@ -146,28 +146,35 @@ std::shared_ptr<vk::dbg::Value> makeDbgValue(const sw::vec<T, N> &vec) ...@@ -146,28 +146,35 @@ std::shared_ptr<vk::dbg::Value> makeDbgValue(const sw::vec<T, N> &vec)
}); });
} }
// store() emits a store instruction to write sizeof(T) bytes from val into ptr. // store() emits a store instruction to copy val into ptr.
template<typename T> template<typename T>
void store(const rr::RValue<rr::Pointer<rr::Byte>> &ptr, const rr::RValue<T> &val) void store(const rr::RValue<rr::Pointer<rr::Byte>> &ptr, const rr::RValue<T> &val)
{ {
*rr::Pointer<T>(ptr) = val; *rr::Pointer<T>(ptr) = val;
} }
// store() emits a store instruction to write sizeof(T) bytes from val into ptr. // store() emits a store instruction to copy val into ptr.
template<typename T> template<typename T>
void store(const rr::RValue<rr::Pointer<rr::Byte>> &ptr, const T &val) void store(const rr::RValue<rr::Pointer<rr::Byte>> &ptr, const T &val)
{ {
*rr::Pointer<T>(ptr) = val; *rr::Pointer<T>(ptr) = val;
} }
// store() emits a store instruction to write sizeof(T) * N bytes from val into // clang-format off
// ptr. template<typename T> struct ReactorTypeSize {};
template<> struct ReactorTypeSize<rr::Int> { static constexpr const int value = 4; };
template<> struct ReactorTypeSize<rr::Float> { static constexpr const int value = 4; };
template<> struct ReactorTypeSize<rr::Int4> { static constexpr const int value = 16; };
template<> struct ReactorTypeSize<rr::Float4> { static constexpr const int value = 16; };
// clang-format on
// store() emits a store instruction to copy val into ptr.
template<typename T, std::size_t N> template<typename T, std::size_t N>
void store(const rr::RValue<rr::Pointer<rr::Byte>> &ptr, const std::array<T, N> &val) void store(const rr::RValue<rr::Pointer<rr::Byte>> &ptr, const std::array<T, N> &val)
{ {
for(std::size_t i = 0; i < N; i++) for(std::size_t i = 0; i < N; i++)
{ {
store<T>(ptr + i * sizeof(T), val[i]); store<T>(ptr + i * ReactorTypeSize<T>::value, val[i]);
} }
} }
...@@ -2346,11 +2353,8 @@ void SpirvShader::Impl::Debugger::State::Data::buildGlobal(const char *name, con ...@@ -2346,11 +2353,8 @@ void SpirvShader::Impl::Debugger::State::Data::buildGlobal(const char *name, con
{ {
for(int lane = 0; lane < sw::SIMD::Width; lane++) for(int lane = 0; lane < sw::SIMD::Width; lane++)
{ {
for(int i = 0; i < N; i++)
{
globals.lanes[lane]->put(name, makeDbgValue(simd[lane])); globals.lanes[lane]->put(name, makeDbgValue(simd[lane]));
} }
}
} }
void SpirvShader::Impl::Debugger::State::Data::buildGlobals(State *state) void SpirvShader::Impl::Debugger::State::Data::buildGlobals(State *state)
......
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