GPU: Add display rotation option

This commit is contained in:
Stenzek
2024-07-26 22:45:23 +10:00
parent 5656f91bd2
commit 7a3a72ec3d
20 changed files with 252 additions and 15 deletions

View File

@ -21,6 +21,7 @@ add_library(common
fifo_queue.h
file_system.cpp
file_system.h
gsvector.cpp
gsvector.h
gsvector_formatter.h
gsvector_neon.h

View File

@ -56,6 +56,7 @@
<ClCompile Include="error.cpp" />
<ClCompile Include="fastjmp.cpp" />
<ClCompile Include="file_system.cpp" />
<ClCompile Include="gsvector.cpp" />
<ClCompile Include="layered_settings_interface.cpp" />
<ClCompile Include="log.cpp" />
<ClCompile Include="memmap.cpp" />

View File

@ -78,6 +78,7 @@
</ClCompile>
<ClCompile Include="dynamic_library.cpp" />
<ClCompile Include="binary_span_reader_writer.cpp" />
<ClCompile Include="gsvector.cpp" />
</ItemGroup>
<ItemGroup>
<Natvis Include="bitfield.natvis" />

67
src/common/gsvector.cpp Normal file
View File

@ -0,0 +1,67 @@
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
#include "gsvector.h"
#include <cmath>
GSMatrix2x2::GSMatrix2x2(float e00, float e01, float e10, float e11)
{
E[0][0] = e00;
E[0][1] = e01;
E[1][0] = e10;
E[1][1] = e11;
}
GSMatrix2x2 GSMatrix2x2::operator*(const GSMatrix2x2& m) const
{
GSMatrix2x2 ret;
ret.E[0][0] = E[0][0] * m.E[0][0] + E[0][1] * m.E[1][0];
ret.E[0][1] = E[0][0] * m.E[0][1] + E[0][1] * m.E[1][1];
ret.E[1][0] = E[1][0] * m.E[0][0] + E[1][1] * m.E[1][0];
ret.E[1][1] = E[1][0] * m.E[0][1] + E[1][1] * m.E[1][1];
return ret;
}
GSVector2 GSMatrix2x2::operator*(const GSVector2& v) const
{
return GSVector2(row(0).dot(v), row(1).dot(v));
}
GSMatrix2x2 GSMatrix2x2::Identity()
{
GSMatrix2x2 ret;
ret.E[0][0] = 1.0f;
ret.E[0][1] = 0.0f;
ret.E[1][0] = 0.0f;
ret.E[1][1] = 1.0f;
return ret;
}
GSMatrix2x2 GSMatrix2x2::Rotation(float angle_in_radians)
{
const float sin_angle = std::sin(angle_in_radians);
const float cos_angle = std::cos(angle_in_radians);
GSMatrix2x2 ret;
ret.E[0][0] = cos_angle;
ret.E[0][1] = -sin_angle;
ret.E[1][0] = sin_angle;
ret.E[1][1] = cos_angle;
return ret;
}
GSVector2 GSMatrix2x2::row(size_t i) const
{
return GSVector2::load(&E[i][0]);
}
GSVector2 GSMatrix2x2::col(size_t i) const
{
return GSVector2(E[0][i], E[1][i]);
}
void GSMatrix2x2::store(void* m)
{
std::memcpy(m, E, sizeof(E));
}

View File

@ -12,3 +12,24 @@
#else
#include "common/gsvector_nosimd.h"
#endif
class GSMatrix2x2
{
public:
GSMatrix2x2() = default;
GSMatrix2x2(float e00, float e01, float e10, float e11);
GSMatrix2x2 operator*(const GSMatrix2x2& m) const;
GSVector2 operator*(const GSVector2& v) const;
static GSMatrix2x2 Identity();
static GSMatrix2x2 Rotation(float angle_in_radians);
GSVector2 row(size_t i) const;
GSVector2 col(size_t i) const;
void store(void* m);
float E[2][2];
};

View File

@ -800,6 +800,8 @@ public:
return vget_lane_s32(vreinterpret_s32_f32(v2s), i);
}
ALWAYS_INLINE float dot(const GSVector2& v) const { return vaddv_f32(vmul_f32(v2s, v.v2s)); }
ALWAYS_INLINE static GSVector2 zero() { return GSVector2(vdup_n_f32(0.0f)); }
ALWAYS_INLINE static GSVector2 xffffffff() { return GSVector2(vreinterpret_f32_u32(vdup_n_u32(0xFFFFFFFFu))); }

View File

@ -666,6 +666,8 @@ public:
return I32[i];
}
ALWAYS_INLINE float dot(const GSVector2& v) const { return (x * v.x + y * v.y); }
ALWAYS_INLINE static constexpr GSVector2 zero() { return GSVector2::cxpr(0.0f, 0.0f); }
ALWAYS_INLINE static constexpr GSVector2 xffffffff()

View File

@ -643,6 +643,8 @@ public:
return _mm_extract_ps(m, i);
}
ALWAYS_INLINE float dot(const GSVector2& v) const { return _mm_cvtss_f32(_mm_dp_ps(m, v.m, 0x31)); }
ALWAYS_INLINE static GSVector2 zero() { return GSVector2(_mm_setzero_ps()); }
ALWAYS_INLINE static GSVector2 xffffffff() { return zero() == zero(); }