mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-26 17:14:18 +01:00
Introduce OffsetMember
for offset-based union members
The offset of a member in a structure was determined by its relative position and compiler alignment. This is unoptimal for larger structures such as those found in GPU Engines that are primarily named by offset rather than relative positioning and end up requiring a massive amount of padding to function as is. A solution to this problem was simply to supply member offsets directly which can be done by using `OffsetMember` alongside a `union`.
This commit is contained in:
parent
fb476567ff
commit
cc7b2a0ab8
@ -55,7 +55,7 @@ namespace skyline::util {
|
|||||||
return static_cast<Return>(item);
|
return static_cast<Return>(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template<typename T>
|
||||||
concept IsPointerOrUnsignedIntegral = (std::is_unsigned_v<T> && std::is_integral_v<T>) || std::is_pointer_v<T>;
|
concept IsPointerOrUnsignedIntegral = (std::is_unsigned_v<T> && std::is_integral_v<T>) || std::is_pointer_v<T>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -231,4 +231,24 @@ namespace skyline::util {
|
|||||||
To BitCast(const From &from) {
|
To BitCast(const From &from) {
|
||||||
return *reinterpret_cast<const To *>(&from);
|
return *reinterpret_cast<const To *>(&from);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief A utility type for placing elements by offset in unions rather than relative position in structs
|
||||||
|
* @tparam PadType The type of a unit of padding, total size of padding is `sizeof(PadType) * Offset`
|
||||||
|
*/
|
||||||
|
template<size_t Offset, typename ValueType, typename PadType = u8>
|
||||||
|
struct OffsetMember {
|
||||||
|
private:
|
||||||
|
PadType _pad_[Offset];
|
||||||
|
ValueType value;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ValueType &operator*() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
ValueType *operator->() {
|
||||||
|
return &value;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user