mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2024-12-24 00:41:49 +01:00
command_processor: Resolve undefined behavior type punning
We can use std::memcpy to achieve the same behavior without undefined behavior. Once Citra moves to C++20 we can convert this over to std::bit_cast.
This commit is contained in:
parent
5ac4636a14
commit
41b7df4a32
@ -4,6 +4,7 @@
|
||||
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include "common/assert.h"
|
||||
@ -86,8 +87,11 @@ static void WriteUniformFloatReg(ShaderRegs& config, Shader::ShaderSetup& setup,
|
||||
|
||||
// NOTE: The destination component order indeed is "backwards"
|
||||
if (uniform_setup.IsFloat32()) {
|
||||
for (auto i : {0, 1, 2, 3})
|
||||
uniform[3 - i] = float24::FromFloat32(*(float*)(&uniform_write_buffer[i]));
|
||||
for (auto i : {0, 1, 2, 3}) {
|
||||
float buffer_value;
|
||||
std::memcpy(&buffer_value, &uniform_write_buffer[i], sizeof(float));
|
||||
uniform[3 - i] = float24::FromFloat32(buffer_value);
|
||||
}
|
||||
} else {
|
||||
// TODO: Untested
|
||||
uniform.w = float24::FromRaw(uniform_write_buffer[0] >> 8);
|
||||
|
Loading…
Reference in New Issue
Block a user