mirror of
https://github.com/RPCSX/rpcsx.git
synced 2026-04-05 06:26:49 +00:00
gpu rewrite initial commit
This commit is contained in:
parent
0d4ed51cd9
commit
4cf808facd
133 changed files with 35491 additions and 4 deletions
37
rx/include/rx/FunctionRef.hpp
Normal file
37
rx/include/rx/FunctionRef.hpp
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
#pragma once
|
||||
|
||||
#include <compare>
|
||||
#include <utility>
|
||||
|
||||
namespace rx {
|
||||
template <typename> class FunctionRef;
|
||||
template <typename RT, typename... ArgsT> class FunctionRef<RT(ArgsT...)> {
|
||||
void *context = nullptr;
|
||||
RT (*invoke)(void *, ArgsT...) = nullptr;
|
||||
|
||||
public:
|
||||
constexpr FunctionRef() = default;
|
||||
|
||||
template <typename T>
|
||||
constexpr FunctionRef(T &&object)
|
||||
requires requires(ArgsT... args) { RT(object(args...)); }
|
||||
: context(
|
||||
const_cast<std::remove_const_t<std::remove_cvref_t<T>> *>(&object)),
|
||||
invoke(+[](void *context, ArgsT... args) -> RT {
|
||||
return (*reinterpret_cast<T *>(context))(std::move(args)...);
|
||||
}) {}
|
||||
|
||||
template <typename... InvokeArgsT>
|
||||
constexpr RT operator()(InvokeArgsT &&...args) const
|
||||
requires requires(void *context) {
|
||||
invoke(context, std::forward<InvokeArgsT>(args)...);
|
||||
}
|
||||
{
|
||||
return invoke(context, std::forward<InvokeArgsT>(args)...);
|
||||
}
|
||||
|
||||
constexpr explicit operator bool() const { return invoke != nullptr; }
|
||||
constexpr bool operator==(std::nullptr_t) const { return invoke == nullptr; }
|
||||
constexpr auto operator<=>(const FunctionRef &) const = default;
|
||||
};
|
||||
} // namespace rx
|
||||
41
rx/include/rx/TypeId.hpp
Normal file
41
rx/include/rx/TypeId.hpp
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
#pragma once
|
||||
|
||||
#include <compare>
|
||||
#include <cstddef>
|
||||
#include <functional>
|
||||
|
||||
namespace rx {
|
||||
namespace detail {
|
||||
template <typename> char mRawTypeId = 0;
|
||||
template <typename T> constexpr const void *getTypeIdImpl() {
|
||||
return &mRawTypeId<T>;
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
class TypeId {
|
||||
const void *mId = detail::getTypeIdImpl<void>();
|
||||
|
||||
public:
|
||||
constexpr const void *getOpaque() const { return mId; }
|
||||
|
||||
constexpr static TypeId createFromOpaque(const void *id) {
|
||||
TypeId result;
|
||||
result.mId = id;
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T> constexpr static TypeId get() {
|
||||
return createFromOpaque(detail::getTypeIdImpl<T>());
|
||||
}
|
||||
|
||||
constexpr auto operator<=>(const TypeId &other) const = default;
|
||||
};
|
||||
} // namespace rx
|
||||
|
||||
namespace std {
|
||||
template <> struct hash<rx::TypeId> {
|
||||
constexpr std::size_t operator()(const rx::TypeId &id) const noexcept {
|
||||
return std::hash<const void *>{}(id.getOpaque());
|
||||
}
|
||||
};
|
||||
} // namespace std
|
||||
12
rx/include/rx/bits.hpp
Normal file
12
rx/include/rx/bits.hpp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
namespace rx {
|
||||
template <typename T>
|
||||
inline constexpr T getBits(T value, unsigned end, unsigned begin) {
|
||||
return (value >> begin) & ((1ull << (end - begin + 1)) - 1);
|
||||
}
|
||||
|
||||
template <typename T> inline constexpr T getBit(T value, unsigned bit) {
|
||||
return (value >> bit) & 1;
|
||||
}
|
||||
} // namespace rx
|
||||
Loading…
Add table
Add a link
Reference in a new issue