Roms list properly handle sorting + use ircolib's log so i can stop worrying about re-definition of macros and shit
This commit is contained in:
Vendored
+26
-26
@@ -1,43 +1,43 @@
|
||||
#pragma once
|
||||
#include <types.hpp>
|
||||
#include <ircolib/types.hpp>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <filesystem>
|
||||
|
||||
namespace ircolib {
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
namespace ircolib {
|
||||
static inline std::vector<u8> ReadFileBinary(const std::string &path) {
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
return {std::istreambuf_iterator{file}, {}};
|
||||
static inline std::vector<u8> read_file_binary(const std::string &path) {
|
||||
std::ifstream file(path, std::ios::binary);
|
||||
return {std::istreambuf_iterator{file}, {}};
|
||||
}
|
||||
|
||||
static inline void WriteFileBinary(const std::vector<u8> &data, const std::string &path) {
|
||||
std::ofstream file(path, std::ios::binary);
|
||||
std::copy(data.begin(), data.end(), std::ostreambuf_iterator{file});
|
||||
static inline void write_file_binary(const std::vector<u8> &data, const std::string &path) {
|
||||
std::ofstream file(path, std::ios::binary);
|
||||
std::copy(data.begin(), data.end(), std::ostreambuf_iterator{file});
|
||||
}
|
||||
|
||||
static inline void WriteFileBinary(const u8 *data, const size_t size, const std::string &path) {
|
||||
FILE *out = fopen(path.c_str(), "wb");
|
||||
fwrite(data, size, 1, out);
|
||||
fclose(out);
|
||||
static inline void write_file_binary(const u8 *data, const u32 size, const std::string &path) {
|
||||
FILE *out = fopen(path.c_str(), "wb");
|
||||
fwrite(data, size, 1, out);
|
||||
fclose(out);
|
||||
}
|
||||
|
||||
template <size_t Size>
|
||||
static inline void WriteFileBinary(const std::array<u8, Size> &data, const std::string &path) {
|
||||
std::ofstream file(path, std::ios::binary);
|
||||
std::copy(data.begin(), data.end(), std::ostreambuf_iterator{file});
|
||||
static inline void write_file_binary(const std::array<u8, Size> &data, const std::string &path) {
|
||||
std::ofstream file(path, std::ios::binary);
|
||||
std::copy(data.begin(), data.end(), std::ostreambuf_iterator{file});
|
||||
}
|
||||
|
||||
static inline size_t NextPow2(size_t num) {
|
||||
// Taken from "Bit Twiddling Hacks" by Sean Anderson:
|
||||
// https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
|
||||
--num;
|
||||
num |= num >> 1;
|
||||
num |= num >> 2;
|
||||
num |= num >> 4;
|
||||
num |= num >> 8;
|
||||
num |= num >> 16;
|
||||
return num + 1;
|
||||
static inline u32 next_pow2(u32 num) {
|
||||
// Taken from "Bit Twiddling Hacks" by Sean Anderson:
|
||||
// https://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2
|
||||
--num;
|
||||
num |= num >> 1;
|
||||
num |= num >> 2;
|
||||
num |= num >> 4;
|
||||
num |= num >> 8;
|
||||
num |= num >> 16;
|
||||
return num + 1;
|
||||
}
|
||||
} // namespace Util
|
||||
} // namespace ircolib
|
||||
|
||||
Vendored
+42
-43
@@ -1,106 +1,105 @@
|
||||
#pragma once
|
||||
#include <cmath>
|
||||
#include <types.hpp>
|
||||
#include <ircolib/types.hpp>
|
||||
|
||||
namespace ircolib {
|
||||
static inline auto roundCeil(float f) {
|
||||
#ifdef SIMD_SUPPORT
|
||||
__m128 t = _mm_set_ss(f);
|
||||
t = _mm_round_ss(t, t, _MM_FROUND_TO_POS_INF);
|
||||
return _mm_cvtss_f32(t);
|
||||
__m128 t = _mm_set_ss(f);
|
||||
t = _mm_round_ss(t, t, _MM_FROUND_TO_POS_INF);
|
||||
return _mm_cvtss_f32(t);
|
||||
#else
|
||||
return ceilf(f);
|
||||
return ceilf(f);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline auto roundCeil(double f) {
|
||||
#ifdef SIMD_SUPPORT
|
||||
__m128d t = _mm_set_sd(f);
|
||||
t = _mm_round_sd(t, t, _MM_FROUND_TO_POS_INF);
|
||||
return _mm_cvtsd_f64(t);
|
||||
__m128d t = _mm_set_sd(f);
|
||||
t = _mm_round_sd(t, t, _MM_FROUND_TO_POS_INF);
|
||||
return _mm_cvtsd_f64(t);
|
||||
#else
|
||||
return ceil(f);
|
||||
return ceil(f);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline auto roundNearest(float f) {
|
||||
#ifdef SIMD_SUPPORT
|
||||
__m128 t = _mm_set_ss(f);
|
||||
t = _mm_round_ss(t, t, _MM_FROUND_TO_NEAREST_INT);
|
||||
return _mm_cvtss_f32(t);
|
||||
__m128 t = _mm_set_ss(f);
|
||||
t = _mm_round_ss(t, t, _MM_FROUND_TO_NEAREST_INT);
|
||||
return _mm_cvtss_f32(t);
|
||||
#else
|
||||
return roundf(f);
|
||||
return roundf(f);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline auto roundNearest(double f) {
|
||||
#ifdef SIMD_SUPPORT
|
||||
__m128d t = _mm_set_sd(f);
|
||||
t = _mm_round_sd(t, t, _MM_FROUND_TO_NEAREST_INT);
|
||||
return _mm_cvtsd_f64(t);
|
||||
__m128d t = _mm_set_sd(f);
|
||||
t = _mm_round_sd(t, t, _MM_FROUND_TO_NEAREST_INT);
|
||||
return _mm_cvtsd_f64(t);
|
||||
#else
|
||||
return round(f);
|
||||
return round(f);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline auto roundCurrent(float f) {
|
||||
#ifdef SIMD_SUPPORT
|
||||
auto t = _mm_set_ss(f);
|
||||
t = _mm_round_ss(t, t, _MM_FROUND_CUR_DIRECTION);
|
||||
return _mm_cvtss_f32(t);
|
||||
auto t = _mm_set_ss(f);
|
||||
t = _mm_round_ss(t, t, _MM_FROUND_CUR_DIRECTION);
|
||||
return _mm_cvtss_f32(t);
|
||||
#else
|
||||
return rint(f);
|
||||
return rint(f);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline auto roundCurrent(double f) {
|
||||
#ifdef SIMD_SUPPORT
|
||||
auto t = _mm_set_sd(f);
|
||||
t = _mm_round_sd(t, t, _MM_FROUND_CUR_DIRECTION);
|
||||
return _mm_cvtsd_f64(t);
|
||||
auto t = _mm_set_sd(f);
|
||||
t = _mm_round_sd(t, t, _MM_FROUND_CUR_DIRECTION);
|
||||
return _mm_cvtsd_f64(t);
|
||||
#else
|
||||
return rint(f);
|
||||
return rint(f);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static inline auto roundFloor(float f) {
|
||||
#ifdef SIMD_SUPPORT
|
||||
__m128 t = _mm_set_ss(f);
|
||||
t = _mm_round_ss(t, t, _MM_FROUND_TO_NEG_INF);
|
||||
return _mm_cvtss_f32(t);
|
||||
__m128 t = _mm_set_ss(f);
|
||||
t = _mm_round_ss(t, t, _MM_FROUND_TO_NEG_INF);
|
||||
return _mm_cvtss_f32(t);
|
||||
#else
|
||||
return floor(f);
|
||||
return floor(f);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline auto roundFloor(double f) {
|
||||
#ifdef SIMD_SUPPORT
|
||||
__m128d t = _mm_set_sd(f);
|
||||
t = _mm_round_sd(t, t, _MM_FROUND_TO_NEG_INF);
|
||||
return _mm_cvtsd_f64(t);
|
||||
__m128d t = _mm_set_sd(f);
|
||||
t = _mm_round_sd(t, t, _MM_FROUND_TO_NEG_INF);
|
||||
return _mm_cvtsd_f64(t);
|
||||
#else
|
||||
return floor(f);
|
||||
return floor(f);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline auto roundTrunc(float f) {
|
||||
#ifdef SIMD_SUPPORT
|
||||
__m128 t = _mm_set_ss(f);
|
||||
t = _mm_round_ss(t, t, _MM_FROUND_TO_ZERO);
|
||||
return _mm_cvtss_f32(t);
|
||||
__m128 t = _mm_set_ss(f);
|
||||
t = _mm_round_ss(t, t, _MM_FROUND_TO_ZERO);
|
||||
return _mm_cvtss_f32(t);
|
||||
#else
|
||||
return trunc(f);
|
||||
return trunc(f);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline auto roundTrunc(double f) {
|
||||
#ifdef SIMD_SUPPORT
|
||||
__m128d t = _mm_set_sd(f);
|
||||
t = _mm_round_sd(t, t, _MM_FROUND_TO_ZERO);
|
||||
return _mm_cvtsd_f64(t);
|
||||
__m128d t = _mm_set_sd(f);
|
||||
t = _mm_round_sd(t, t, _MM_FROUND_TO_ZERO);
|
||||
return _mm_cvtsd_f64(t);
|
||||
#else
|
||||
return trunc(f);
|
||||
return trunc(f);
|
||||
#endif
|
||||
}
|
||||
} // namespace Util
|
||||
} // namespace ircolib
|
||||
|
||||
Vendored
+61
@@ -0,0 +1,61 @@
|
||||
#pragma once
|
||||
#include <print>
|
||||
#include <ircolib/types.hpp>
|
||||
|
||||
namespace ircolib {
|
||||
enum LogLevel : u8 { Trace, Debug, Info, Warn, Error, Always };
|
||||
|
||||
constexpr LogLevel globalLogLevel = Warn;
|
||||
|
||||
template <typename... Args>
|
||||
void panic(std::format_string<Args...> fmt, Args &&...args) {
|
||||
std::print("[FATAL] ");
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void error(std::format_string<Args...> fmt, Args &&...args) {
|
||||
if (LogLevel::Error >= globalLogLevel) {
|
||||
std::print("[ERROR] ");
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void warn(std::format_string<Args...> fmt, Args &&...args) {
|
||||
if (LogLevel::Warn >= globalLogLevel) {
|
||||
std::print("[WARN] ");
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void info(std::format_string<Args...> fmt, Args &&...args) {
|
||||
if (LogLevel::Info >= globalLogLevel) {
|
||||
std::print("[INFO] ");
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void debug(std::format_string<Args...> fmt, Args &&...args) {
|
||||
if (LogLevel::Debug >= globalLogLevel) {
|
||||
std::print("[DEBUG] ");
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void trace(std::format_string<Args...> fmt, Args &&...args) {
|
||||
if (LogLevel::Trace >= globalLogLevel) {
|
||||
std::print("[TRACE] ");
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
void always(std::format_string<Args...> fmt, Args &&...args) {
|
||||
std::println(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
} // namespace ircolib
|
||||
Vendored
+85
-71
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <types.hpp>
|
||||
#include "types.hpp"
|
||||
#include <cstddef>
|
||||
#include <cstring>
|
||||
#include <functional>
|
||||
#include <bit>
|
||||
@@ -8,139 +9,152 @@
|
||||
#include <concepts>
|
||||
|
||||
namespace ircolib {
|
||||
static inline std::vector<u8> IntegralToBuffer(const std::integral auto &val) {
|
||||
std::vector<u8> ret{};
|
||||
ret.resize(sizeof(val));
|
||||
static inline std::vector<u8> integral_to_buffer(const std::integral auto &val) {
|
||||
std::vector<u8> ret{};
|
||||
ret.resize(sizeof(val));
|
||||
|
||||
memcpy(ret.data(), &val, sizeof(val));
|
||||
memcpy(ret.data(), &val, sizeof(val));
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline constexpr bool IsInsideRange(const std::integral auto& addr,
|
||||
const std::integral auto& start,
|
||||
const std::integral auto& end) {
|
||||
return addr >= start && addr <= end;
|
||||
static inline auto integral_to_slice(const std::integral auto &val) -> std::array<u8, sizeof(val)> {
|
||||
std::array<u8, sizeof(val)> ret{};
|
||||
|
||||
memcpy(ret.data(), &val, sizeof(val));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline constexpr bool is_inside_range(const std::integral auto &addr, const std::integral auto &start,
|
||||
const std::integral auto &end) {
|
||||
return addr >= start && addr <= end;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static constexpr inline T ReadAccess(const u8 *data, const u32 index);
|
||||
static constexpr inline T read_access(const u8 *data, const u32 index);
|
||||
template <typename T>
|
||||
static constexpr inline T ReadAccess(const std::vector<u8> &data, const u32 index);
|
||||
static constexpr inline T read_access(const std::vector<u8> &data, const u32 index);
|
||||
template <typename T, size_t Size>
|
||||
static constexpr inline T ReadAccess(const std::array<u8, Size> &data, const u32 index);
|
||||
static constexpr inline T read_access(const std::array<u8, Size> &data, const u32 index);
|
||||
|
||||
template <typename T>
|
||||
static constexpr inline void WriteAccess(u8 *data, const u32 index, const T val);
|
||||
static constexpr inline void write_access(u8 *data, const u32 index, const T val);
|
||||
template <typename T>
|
||||
static constexpr inline void WriteAccess(std::vector<u8> &data, const u32 index, const T val);
|
||||
static constexpr inline void write_access(std::vector<u8> &data, const u32 index, const T val);
|
||||
template <typename T, size_t Size>
|
||||
static constexpr inline void WriteAccess(std::array<u8, Size> &data, const u32 index, const T val);
|
||||
static constexpr inline void write_access(std::array<u8, Size> &data, const u32 index, const T val);
|
||||
|
||||
template <>
|
||||
constexpr inline u64 ReadAccess(const u8 *data, const u32 index) {
|
||||
u32 hi = *reinterpret_cast<const u32 *>(&data[index + 0]);
|
||||
u32 lo = *reinterpret_cast<const u32 *>(&data[index + 4]);
|
||||
const auto& result = static_cast<u64>(hi) << 32 | static_cast<u64>(lo);
|
||||
return result;
|
||||
constexpr inline u64 read_access(const u8 *data, const u32 index) {
|
||||
u32 hi = *reinterpret_cast<const u32 *>(&data[index + 0]);
|
||||
u32 lo = *reinterpret_cast<const u32 *>(&data[index + 4]);
|
||||
const auto &result = static_cast<u64>(hi) << 32 | static_cast<u64>(lo);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static constexpr inline T ReadAccess(const u8 *data, const u32 index) {
|
||||
return *reinterpret_cast<const T *>(&data[index]);
|
||||
static constexpr inline T read_access(const u8 *data, const u32 index) {
|
||||
return *reinterpret_cast<const T *>(&data[index]);
|
||||
}
|
||||
|
||||
template <>
|
||||
constexpr inline u64 ReadAccess(const std::vector<u8> &data, const u32 index) {
|
||||
u32 hi = *reinterpret_cast<const u32 *>(&data[index + 0]);
|
||||
u32 lo = *reinterpret_cast<const u32 *>(&data[index + 4]);
|
||||
return (static_cast<u64>(hi) << 32) | static_cast<u64>(lo);
|
||||
constexpr inline u64 read_access(const std::vector<u8> &data, const u32 index) {
|
||||
u32 hi = *reinterpret_cast<const u32 *>(&data[index + 0]);
|
||||
u32 lo = *reinterpret_cast<const u32 *>(&data[index + 4]);
|
||||
return (static_cast<u64>(hi) << 32) | static_cast<u64>(lo);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static constexpr inline T ReadAccess(const std::vector<u8> &data, const u32 index) {
|
||||
return *reinterpret_cast<const T *>(&data[index]);
|
||||
static constexpr inline T read_access(const std::vector<u8> &data, const u32 index) {
|
||||
return *reinterpret_cast<const T *>(&data[index]);
|
||||
}
|
||||
|
||||
template <size_t Size>
|
||||
constexpr inline u64 ReadAccess(const std::array<u8, Size> &data, const u32 index) {
|
||||
u32 hi = *reinterpret_cast<const u32 *>(&data[index + 0]);
|
||||
u32 lo = *reinterpret_cast<const u32 *>(&data[index + 4]);
|
||||
return static_cast<u64>(hi) << 32 | static_cast<u64>(lo);
|
||||
static constexpr inline u64 read_access(const std::array<u8, Size> &data, const u32 index) {
|
||||
u32 hi = *reinterpret_cast<const u32 *>(&data[index + 0]);
|
||||
u32 lo = *reinterpret_cast<const u32 *>(&data[index + 4]);
|
||||
return static_cast<u64>(hi) << 32 | static_cast<u64>(lo);
|
||||
}
|
||||
|
||||
template <typename T, size_t Size>
|
||||
static constexpr inline T ReadAccess(const std::array<u8, Size> &data, const u32 index) {
|
||||
return *reinterpret_cast<const T *>(&data[index]);
|
||||
static constexpr inline T read_access(const std::array<u8, Size> &data, const u32 index) {
|
||||
return *reinterpret_cast<const T *>(&data[index]);
|
||||
}
|
||||
|
||||
template <size_t Size>
|
||||
constexpr inline void WriteAccess(std::array<u8, Size> &data, const u32 index, const u64 val) {
|
||||
const u32 hi = val >> 32;
|
||||
const u32 lo = val;
|
||||
static constexpr inline void write_access(std::array<u8, Size> &data, const u32 index, const u64 val) {
|
||||
const u32 hi = val >> 32;
|
||||
const u32 lo = val;
|
||||
|
||||
*reinterpret_cast<u32 *>(&data[index + 0]) = hi;
|
||||
*reinterpret_cast<u32 *>(&data[index + 4]) = lo;
|
||||
*reinterpret_cast<u32 *>(&data[index + 0]) = hi;
|
||||
*reinterpret_cast<u32 *>(&data[index + 4]) = lo;
|
||||
}
|
||||
|
||||
template <typename T, size_t Size>
|
||||
static constexpr inline void WriteAccess(std::array<u8, Size> &data, const u32 index, const T val) {
|
||||
*reinterpret_cast<T *>(&data[index]) = val;
|
||||
static constexpr inline void write_access(std::array<u8, Size> &data, const u32 index, const T val) {
|
||||
*reinterpret_cast<T *>(&data[index]) = val;
|
||||
}
|
||||
|
||||
template <>
|
||||
constexpr inline void WriteAccess(std::vector<u8> &data, const u32 index, const u64 val) {
|
||||
const u32 hi = val >> 32;
|
||||
const u32 lo = val;
|
||||
constexpr inline void write_access(std::vector<u8> &data, const u32 index, const u64 val) {
|
||||
const u32 hi = val >> 32;
|
||||
const u32 lo = val;
|
||||
|
||||
*reinterpret_cast<u32 *>(&data[index + 0]) = hi;
|
||||
*reinterpret_cast<u32 *>(&data[index + 4]) = lo;
|
||||
*reinterpret_cast<u32 *>(&data[index + 0]) = hi;
|
||||
*reinterpret_cast<u32 *>(&data[index + 4]) = lo;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static constexpr inline void WriteAccess(std::vector<u8> &data, const u32 index, const T val) {
|
||||
*reinterpret_cast<T *>(&data[index]) = val;
|
||||
static constexpr inline void write_access(std::vector<u8> &data, const u32 index, const T val) {
|
||||
*reinterpret_cast<T *>(&data[index]) = val;
|
||||
}
|
||||
|
||||
template <>
|
||||
constexpr inline void WriteAccess(u8 *data, const u32 index, const u64 val) {
|
||||
const u32 hi = val >> 32;
|
||||
const u32 lo = val;
|
||||
constexpr inline void write_access(u8 *data, const u32 index, const u64 val) {
|
||||
const u32 hi = val >> 32;
|
||||
const u32 lo = val;
|
||||
|
||||
*reinterpret_cast<u32 *>(&data[index + 0]) = hi;
|
||||
*reinterpret_cast<u32 *>(&data[index + 4]) = lo;
|
||||
*reinterpret_cast<u32 *>(&data[index + 0]) = hi;
|
||||
*reinterpret_cast<u32 *>(&data[index + 4]) = lo;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static constexpr inline void WriteAccess(u8 *data, const u32 index, const T val) {
|
||||
*reinterpret_cast<T *>(&data[index]) = val;
|
||||
static constexpr inline void write_access(u8 *data, const u32 index, const T val) {
|
||||
*reinterpret_cast<T *>(&data[index]) = val;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static constexpr inline void SwapBuffer(std::vector<u8> &data) {
|
||||
for (size_t i = 0; i < data.size(); i += sizeof(T)) {
|
||||
const T original = *reinterpret_cast<T *>(&data[i]);
|
||||
*reinterpret_cast<T *>(&data[i]) = std::byteswap(original);
|
||||
}
|
||||
static constexpr inline void swap_buffer(std::vector<u8> &data) {
|
||||
for (u32 i = 0; i < data.size(); i += sizeof(T)) {
|
||||
const T original = *reinterpret_cast<T *>(&data[i]);
|
||||
*reinterpret_cast<T *>(&data[i]) = std::byteswap(original);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T, size_t Size>
|
||||
static constexpr inline void SwapBuffer(std::array<u8, Size> &data) {
|
||||
for (size_t i = 0; i < data.size(); i += sizeof(T)) {
|
||||
const T original = *reinterpret_cast<T *>(&data[i]);
|
||||
*reinterpret_cast<T *>(&data[i]) = std::byteswap(original);
|
||||
}
|
||||
static constexpr inline void swap_buffer(std::array<u8, Size> &data) {
|
||||
for (u32 i = 0; i < data.size(); i += sizeof(T)) {
|
||||
const T original = *reinterpret_cast<T *>(&data[i]);
|
||||
*reinterpret_cast<T *>(&data[i]) = std::byteswap(original);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
static constexpr inline void swap_buffer(u8 *data, u32 size) {
|
||||
for (u32 i = 0; i < size; i += sizeof(T)) {
|
||||
const T original = *reinterpret_cast<T *>(&data[i]);
|
||||
*reinterpret_cast<T *>(&data[i]) = std::byteswap(original);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
inline void *aligned_alloc(const size_t alignment, const size_t size) { return _aligned_malloc(size, alignment); }
|
||||
inline void *aligned_alloc(const u32 alignment, const u32 size) { return _aligned_malloc(size, alignment); }
|
||||
|
||||
inline void aligned_free(void *ptr) { _aligned_free(ptr); }
|
||||
#else
|
||||
inline void *aligned_alloc(const size_t alignment, const size_t size) {
|
||||
return std::aligned_alloc(alignment, size);
|
||||
}
|
||||
inline void *aligned_alloc(const u32 alignment, const u32 size) { return std::aligned_alloc(alignment, size); }
|
||||
|
||||
inline void aligned_free(void *ptr) { std::free(ptr); }
|
||||
#endif
|
||||
} // namespace Util
|
||||
} // namespace ircolib
|
||||
|
||||
Vendored
+36
-1
@@ -1,5 +1,11 @@
|
||||
#pragma once
|
||||
#include <cstdint>
|
||||
#ifdef USE_NEON
|
||||
#include <sse2neon.h>
|
||||
#else
|
||||
#include <emmintrin.h>
|
||||
#include <smmintrin.h>
|
||||
#endif
|
||||
|
||||
namespace ircolib {
|
||||
using u8 = uint8_t;
|
||||
@@ -10,4 +16,33 @@ using s8 = int8_t;
|
||||
using s16 = int16_t;
|
||||
using s32 = int32_t;
|
||||
using s64 = int64_t;
|
||||
}
|
||||
|
||||
template <typename T, u32 bit>
|
||||
static constexpr bool is_bit_set(const T &val) {
|
||||
return val & (1 << bit);
|
||||
}
|
||||
|
||||
template <typename T, u32 bit>
|
||||
static constexpr void set_bit(T &val) {
|
||||
val |= 1 << bit;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool is_bit_set(const T &val, const u32 &bit) {
|
||||
return val & (1 << bit);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void set_bit(T &val, const u32 &bit) {
|
||||
val |= 1 << bit;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void clear_bit(T &val, const u32 &bit) {
|
||||
val &= ~(1 << bit);
|
||||
}
|
||||
} // namespace ircolib
|
||||
|
||||
constexpr ircolib::u32 operator""_kib(const unsigned long long v) { return v * 1024; }
|
||||
constexpr ircolib::u32 operator""_mib(const unsigned long long v) { return v * 1024 * 1024; }
|
||||
constexpr ircolib::u32 operator""_gib(const unsigned long long v) { return v * 1024 * 1024 * 1024; }
|
||||
|
||||
+7
-6
@@ -38,7 +38,7 @@ Util::IntrusivePtr<Context> InitVulkanContext(WSIPlatform *platform, const unsig
|
||||
|
||||
if (!new_context->init_instance(instance_ext.data(), instance_ext.size(),
|
||||
CONTEXT_CREATION_ENABLE_ADVANCED_WSI_BIT)) {
|
||||
panic("Failed to create Vulkan instance.\n");
|
||||
ircolib::panic("Failed to create Vulkan instance.\n");
|
||||
}
|
||||
|
||||
const auto tmp_surface = platform->create_surface(new_context->get_instance(), VK_NULL_HANDLE);
|
||||
@@ -51,7 +51,7 @@ Util::IntrusivePtr<Context> InitVulkanContext(WSIPlatform *platform, const unsig
|
||||
}
|
||||
|
||||
if (!ret) {
|
||||
panic("Failed to create Vulkan device.\n");
|
||||
ircolib::panic("Failed to create Vulkan device.\n");
|
||||
}
|
||||
|
||||
return new_context;
|
||||
@@ -67,15 +67,15 @@ void ParallelRDP::LoadWSIPlatform(const std::shared_ptr<WSIPlatform> &wsi_platfo
|
||||
|
||||
if (constexpr Context::SystemHandles handles;
|
||||
!wsi->init_from_existing_context(InitVulkanContext(wsi_platform.get(), 1, handles, instanceFactory))) {
|
||||
panic("Failed to initialize WSI: init_from_existing_context() failed");
|
||||
ircolib::panic("Failed to initialize WSI: init_from_existing_context() failed");
|
||||
}
|
||||
|
||||
if (!wsi->init_device()) {
|
||||
panic("Failed to initialize WSI: init_device() failed");
|
||||
ircolib::panic("Failed to initialize WSI: init_device() failed");
|
||||
}
|
||||
|
||||
if (!wsi->init_surface_swapchain()) {
|
||||
panic("Failed to initialize WSI: init_surface_swapchain() failed");
|
||||
ircolib::panic("Failed to initialize WSI: init_surface_swapchain() failed");
|
||||
}
|
||||
|
||||
windowInfo = newWindowInfo;
|
||||
@@ -124,7 +124,8 @@ void ParallelRDP::Init(const std::shared_ptr<WSIPlatform> &wsiPlatform,
|
||||
offset, 8 * 1024 * 1024, 4 * 1024 * 1024, flags);
|
||||
|
||||
if (!command_processor->device_is_supported()) {
|
||||
panic("This device probably does not support 8/16-bit storage. Make sure you're using up-to-date drivers!");
|
||||
ircolib::panic(
|
||||
"This device probably does not support 8/16-bit storage. Make sure you're using up-to-date drivers!");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user