mirror of
https://github.com/stenzek/duckstation.git
synced 2025-06-06 19:45:33 +00:00
Common: Add 2D vector formatters
This commit is contained in:
parent
69ed6e5e58
commit
58b0ccf3fc
@ -8,6 +8,26 @@
|
||||
|
||||
#include "fmt/format.h"
|
||||
|
||||
template<>
|
||||
struct fmt::formatter<GSVector2i> : formatter<std::string_view>
|
||||
{
|
||||
auto format(const GSVector2i& rc, format_context& ctx) const
|
||||
{
|
||||
const TinyString str = TinyString::from_format("{},{}", rc.x, rc.y);
|
||||
return fmt::formatter<std::string_view>::format(str.view(), ctx);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct fmt::formatter<GSVector2> : formatter<std::string_view>
|
||||
{
|
||||
auto format(const GSVector2& rc, format_context& ctx) const
|
||||
{
|
||||
const TinyString str = TinyString::from_format("{},{}", rc.x, rc.y);
|
||||
return fmt::formatter<std::string_view>::format(str.view(), ctx);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct fmt::formatter<GSVector4i> : formatter<std::string_view>
|
||||
{
|
||||
@ -19,3 +39,13 @@ struct fmt::formatter<GSVector4i> : formatter<std::string_view>
|
||||
return fmt::formatter<std::string_view>::format(str.view(), ctx);
|
||||
}
|
||||
};
|
||||
|
||||
template<>
|
||||
struct fmt::formatter<GSVector4> : formatter<std::string_view>
|
||||
{
|
||||
auto format(const GSVector4& rc, format_context& ctx) const
|
||||
{
|
||||
const TinyString str = TinyString::from_format("{},{},{},{}", rc.x, rc.y, rc.z, rc.w);
|
||||
return fmt::formatter<std::string_view>::format(str.view(), ctx);
|
||||
}
|
||||
};
|
||||
|
@ -359,7 +359,7 @@ public:
|
||||
|
||||
#endif
|
||||
|
||||
ALWAYS_INLINE GSVector2i i8to16() const
|
||||
ALWAYS_INLINE GSVector2i s8to16() const
|
||||
{
|
||||
return GSVector2i(vreinterpret_s32_s16(vget_low_s8(vmovl_s8(vreinterpret_s8_s32(v2s)))));
|
||||
}
|
||||
@ -369,6 +369,23 @@ public:
|
||||
return GSVector2i(vreinterpret_s32_u16(vget_low_u8(vmovl_u8(vreinterpret_u8_s32(v2s)))));
|
||||
}
|
||||
|
||||
ALWAYS_INLINE GSVector2i s8to32() const
|
||||
{
|
||||
return GSVector2i(vget_low_s32(vmovl_s16(vget_low_s16(vmovl_s8(vreinterpret_s8_s32(v2s))))));
|
||||
}
|
||||
|
||||
ALWAYS_INLINE GSVector2i u8to32() const
|
||||
{
|
||||
return GSVector2i(vreinterpret_s32_u32(vget_low_u32(vmovl_u16(vget_low_u16(vmovl_u8(vreinterpret_u8_s32(v2s)))))));
|
||||
}
|
||||
|
||||
ALWAYS_INLINE GSVector2i s16to32() const { return GSVector2i(vget_low_s32(vmovl_s16(vreinterpret_s16_s32(v2s)))); }
|
||||
|
||||
ALWAYS_INLINE GSVector2i u16to32() const
|
||||
{
|
||||
return GSVector2i(vreinterpret_s32_u32(vget_low_u32(vmovl_u16(vreinterpret_u16_s32(v2s)))));
|
||||
}
|
||||
|
||||
template<int i>
|
||||
ALWAYS_INLINE GSVector2i srl() const
|
||||
{
|
||||
|
@ -248,7 +248,12 @@ public:
|
||||
|
||||
GSVector2i upl32() const { return GSVector2i(S32[0], 0); }
|
||||
|
||||
GSVector2i i8to16() const { ALL_LANES_16(ret.S16[i] = S8[i]); }
|
||||
GSVector2i s8to16() const { ALL_LANES_16(ret.S16[i] = S8[i]); }
|
||||
GSVector2i s8to32() const { ALL_LANES_32(ret.S32[i] = S8[i]); }
|
||||
GSVector2i u8to16() const { ALL_LANES_16(ret.U16[i] = U8[i]); }
|
||||
GSVector2i u8to32() const { ALL_LANES_32(ret.U32[i] = U8[i]); }
|
||||
GSVector2i u16to32() const { ALL_LANES_32(ret.U32[i] = U16[i]); }
|
||||
GSVector2i s16to32() const { ALL_LANES_32(ret.S32[i] = S16[i]); }
|
||||
|
||||
template<s32 v>
|
||||
GSVector2i srl() const
|
||||
@ -1244,7 +1249,7 @@ public:
|
||||
GSVector4i s16to32() const { ALL_LANES_32(ret.S32[i] = S16[i]); }
|
||||
GSVector4i s16to64() const { ALL_LANES_64(ret.S64[i] = S16[i]); }
|
||||
GSVector4i s32to64() const { ALL_LANES_64(ret.S64[i] = S32[i]); }
|
||||
GSVector4i u8to16() const { ALL_LANES_64(ret.U16[i] = U8[i]); }
|
||||
GSVector4i u8to16() const { ALL_LANES_16(ret.U16[i] = U8[i]); }
|
||||
GSVector4i u8to32() const { ALL_LANES_32(ret.U32[i] = U8[i]); }
|
||||
GSVector4i u8to64() const { ALL_LANES_64(ret.U64[i] = U8[i]); }
|
||||
GSVector4i u16to32() const { ALL_LANES_32(ret.U32[i] = U16[i]); }
|
||||
@ -1846,10 +1851,7 @@ public:
|
||||
|
||||
GSVector4 hsub(const GSVector4& v) const { return GSVector4(x - y, z - w, v.x - v.y, v.z - v.w); }
|
||||
|
||||
ALWAYS_INLINE float dot(const GSVector4& v) const
|
||||
{
|
||||
return (x * v.x) + (y * v.y) + (z * v.z) + (w * v.w);
|
||||
}
|
||||
ALWAYS_INLINE float dot(const GSVector4& v) const { return (x * v.x) + (y * v.y) + (z * v.z) + (w * v.w); }
|
||||
|
||||
GSVector4 sat(const GSVector4& min, const GSVector4& max) const
|
||||
{
|
||||
@ -2316,10 +2318,7 @@ public:
|
||||
|
||||
ALWAYS_INLINE GSVector2 zw() const { return GSVector2(z, w); }
|
||||
|
||||
ALWAYS_INLINE static GSVector4 xyxy(const GSVector2& l, const GSVector2& h)
|
||||
{
|
||||
return GSVector4(l.x, l.y, h.x, h.y);
|
||||
}
|
||||
ALWAYS_INLINE static GSVector4 xyxy(const GSVector2& l, const GSVector2& h) { return GSVector4(l.x, l.y, h.x, h.y); }
|
||||
|
||||
#define VECTOR4_SHUFFLE_4(xs, xn, ys, yn, zs, zn, ws, wn) \
|
||||
ALWAYS_INLINE GSVector4 xs##ys##zs##ws() const { return GSVector4(F32[xn], F32[yn], F32[zn], F32[wn]); }
|
||||
|
@ -369,10 +369,21 @@ public:
|
||||
ALWAYS_INLINE GSVector2i upl32() const { return GSVector2i(_mm_unpacklo_epi32(m, _mm_setzero_si128())); }
|
||||
ALWAYS_INLINE GSVector2i uph32() const { return GSVector2i(_mm_unpackhi_epi32(m, _mm_setzero_si128())); }
|
||||
|
||||
ALWAYS_INLINE GSVector2i i8to16() const { return GSVector2i(_mm_cvtepi8_epi16(m)); }
|
||||
|
||||
#ifdef CPU_ARCH_SSE41
|
||||
ALWAYS_INLINE GSVector2i u8to16() const { return GSVector2i(_mm_cvtepu8_epi16(m)); }
|
||||
ALWAYS_INLINE GSVector2i u8to32() const { return GSVector2i(_mm_cvtepu8_epi32(m)); }
|
||||
ALWAYS_INLINE GSVector2i s16to32() const { return GSVector2i(_mm_cvtepi16_epi32(m)); }
|
||||
ALWAYS_INLINE GSVector2i u16to32() const { return GSVector2i(_mm_cvtepu16_epi32(m)); }
|
||||
#else
|
||||
// These are a pain, adding only as needed...
|
||||
ALWAYS_INLINE GSVector2i u8to16() const { return upl8(); }
|
||||
ALWAYS_INLINE GSVector2i u8to32() const
|
||||
{
|
||||
return GSVector2i(_mm_unpacklo_epi16(_mm_unpacklo_epi8(m, _mm_setzero_si128()), _mm_setzero_si128()));
|
||||
}
|
||||
|
||||
ALWAYS_INLINE GSVector2i s16to32() const { return upl16().sll32<16>().sra32<16>(); }
|
||||
ALWAYS_INLINE GSVector2i u16to32() const { return upl16(); }
|
||||
#endif
|
||||
|
||||
template<s32 i>
|
||||
|
Loading…
x
Reference in New Issue
Block a user