diff options
-rw-r--r-- | src/common/vector_math.h | 12 | ||||
-rw-r--r-- | src/core/memory.cpp | 17 | ||||
-rw-r--r-- | src/video_core/swrasterizer/clipper.cpp | 2 |
3 files changed, 25 insertions, 6 deletions
diff --git a/src/common/vector_math.h b/src/common/vector_math.h index 6e2a5ad60..2b05f66ee 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h @@ -31,6 +31,7 @@ #pragma once #include <cmath> +#include <type_traits> namespace Math { @@ -90,7 +91,8 @@ public: y -= other.y; } - Vec2<decltype(-T{})> operator-() const { + template <typename U = T> + Vec2<std::enable_if_t<std::is_signed<U>::value, U>> operator-() const { return MakeVec(-x, -y); } Vec2<decltype(T{} * T{})> operator*(const Vec2& other) const { @@ -247,7 +249,8 @@ public: z -= other.z; } - Vec3<decltype(-T{})> operator-() const { + template <typename U = T> + Vec3<std::enable_if_t<std::is_signed<U>::value, U>> operator-() const { return MakeVec(-x, -y, -z); } Vec3<decltype(T{} * T{})> operator*(const Vec3& other) const { @@ -462,7 +465,8 @@ public: w -= other.w; } - Vec4<decltype(-T{})> operator-() const { + template <typename U = T> + Vec4<std::enable_if_t<std::is_signed<U>::value, U>> operator-() const { return MakeVec(-x, -y, -z, -w); } Vec4<decltype(T{} * T{})> operator*(const Vec4& other) const { @@ -720,4 +724,4 @@ static inline Vec4<T> MakeVec(const T& x, const Vec3<T>& yzw) { return MakeVec(x, yzw[0], yzw[1], yzw[2]); } -} // namespace +} // namespace Math diff --git a/src/core/memory.cpp b/src/core/memory.cpp index c42f4326b..5ea0694a9 100644 --- a/src/core/memory.cpp +++ b/src/core/memory.cpp @@ -336,8 +336,15 @@ void RasterizerMarkRegionCached(PAddr start, u32 size, int count_delta) { for (unsigned i = 0; i < num_pages; ++i, paddr += PAGE_SIZE) { boost::optional<VAddr> maybe_vaddr = PhysicalToVirtualAddress(paddr); - if (!maybe_vaddr) + // While the physical <-> virtual mapping is 1:1 for the regions supported by the cache, + // some games (like Pokemon Super Mystery Dungeon) will try to use textures that go beyond + // the end address of VRAM, causing the Virtual->Physical translation to fail when flushing + // parts of the texture. + if (!maybe_vaddr) { + LOG_ERROR(HW_Memory, + "Trying to flush a cached region to an invalid physical address %08X", paddr); continue; + } VAddr vaddr = *maybe_vaddr; u8& res_count = current_page_table->cached_res_count[vaddr >> PAGE_BITS]; @@ -349,6 +356,10 @@ void RasterizerMarkRegionCached(PAddr start, u32 size, int count_delta) { if (res_count == 0) { PageType& page_type = current_page_table->attributes[vaddr >> PAGE_BITS]; switch (page_type) { + case PageType::Unmapped: + // It is not necessary for a process to have this region mapped into its address + // space, for example, a system module need not have a VRAM mapping. + break; case PageType::Memory: page_type = PageType::RasterizerCachedMemory; current_page_table->pointers[vaddr >> PAGE_BITS] = nullptr; @@ -367,6 +378,10 @@ void RasterizerMarkRegionCached(PAddr start, u32 size, int count_delta) { if (res_count == 0) { PageType& page_type = current_page_table->attributes[vaddr >> PAGE_BITS]; switch (page_type) { + case PageType::Unmapped: + // It is not necessary for a process to have this region mapped into its address + // space, for example, a system module need not have a VRAM mapping. + break; case PageType::RasterizerCachedMemory: { u8* pointer = GetPointerFromVMA(vaddr & ~PAGE_MASK); if (pointer == nullptr) { diff --git a/src/video_core/swrasterizer/clipper.cpp b/src/video_core/swrasterizer/clipper.cpp index a52129eb7..c1ed48398 100644 --- a/src/video_core/swrasterizer/clipper.cpp +++ b/src/video_core/swrasterizer/clipper.cpp @@ -98,7 +98,7 @@ void ProcessTriangle(const OutputVertex& v0, const OutputVertex& v1, const Outpu auto FlipQuaternionIfOpposite = [](auto& a, const auto& b) { if (Math::Dot(a, b) < float24::Zero()) - a = -a; + a = a * float24::FromFloat32(-1.0f); }; // Flip the quaternions if they are opposite to prevent interpolating them over the wrong |