VideoCommon/ShaderGenCommon: Remove use of a union within ShaderUid

This is only ever used to retrieve a raw view of the given UID data
structure, however it's already valid C++ to retrieve a char/unsigned
char view of an object for bytewise inspection.

u8 maps to unsigned char on all platforms we support, so we can just do
this directly with a reinterpret cast, simplifying the overall
interface.
This commit is contained in:
Lioncash 2019-05-30 02:06:55 -04:00
parent 149a97e396
commit 954246d10e

View File

@ -69,18 +69,18 @@ public:
bool operator==(const ShaderUid& obj) const
{
return memcmp(this->values, obj.values, data.NumValues() * sizeof(*values)) == 0;
return memcmp(&data, &obj.data, data.NumValues() * sizeof(data)) == 0;
}
bool operator!=(const ShaderUid& obj) const
{
return memcmp(this->values, obj.values, data.NumValues() * sizeof(*values)) != 0;
return memcmp(&data, &obj.data, data.NumValues() * sizeof(data)) != 0;
}
// determines the storage order inside STL containers
bool operator<(const ShaderUid& obj) const
{
return memcmp(this->values, obj.values, data.NumValues() * sizeof(*values)) < 0;
return memcmp(&data, &obj.data, data.NumValues() * sizeof(data)) < 0;
}
// Returns a pointer to an internally stored object of the uid_data type.
@ -90,17 +90,13 @@ public:
const uid_data* GetUidData() const { return &data; }
// Returns the raw bytes that make up the shader UID.
const u8* GetUidDataRaw() const { return &values[0]; }
const u8* GetUidDataRaw() const { return reinterpret_cast<const u8*>(&data); }
// Returns the size of the underlying UID data structure in bytes.
size_t GetUidDataSize() const { return sizeof(values); }
size_t GetUidDataSize() const { return sizeof(data); }
private:
union
{
uid_data data{};
u8 values[sizeof(uid_data)];
};
uid_data data{};
};
class ShaderCode : public ShaderGeneratorInterface