Skip to content
Permalink
Browse files

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.
  • Loading branch information...
lioncash committed May 30, 2019
1 parent 149a97e commit 954246d10ec3c9b6c84569f217d6728e53529341
Showing with 6 additions and 10 deletions.
  1. +6 −10 Source/Core/VideoCommon/ShaderGenCommon.h
@@ -69,18 +69,18 @@ class ShaderUid : public ShaderGeneratorInterface

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 @@ class ShaderUid : public ShaderGeneratorInterface
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

0 comments on commit 954246d

Please sign in to comment.
You can’t perform that action at this time.