mirror of
https://git.eden-emu.dev/eden-emu/eden.git
synced 2026-09-06 04:06:58 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 49e96351b1 | |||
| 29b2b04a2d | |||
| 76b7a561ba | |||
| 11de264541 |
@@ -0,0 +1,112 @@
|
|||||||
|
diff --git a/include/vk_mem_alloc.h b/include/vk_mem_alloc.h
|
||||||
|
index 8df0364..4856064 100644
|
||||||
|
--- a/include/vk_mem_alloc.h
|
||||||
|
+++ b/include/vk_mem_alloc.h
|
||||||
|
@@ -3017,7 +3017,7 @@ remove them if not needed.
|
||||||
|
|
||||||
|
#if defined(__ANDROID_API__) && (__ANDROID_API__ < 16)
|
||||||
|
#include <cstdlib>
|
||||||
|
-static void* vma_aligned_alloc(size_t alignment, size_t size)
|
||||||
|
+static inline void* vma_aligned_alloc(size_t alignment, size_t size)
|
||||||
|
{
|
||||||
|
// alignment must be >= sizeof(void*)
|
||||||
|
if(alignment < sizeof(void*))
|
||||||
|
@@ -3860,7 +3860,7 @@ Returned value is the found element, if present in the collection or place where
|
||||||
|
new element with value (key) should be inserted.
|
||||||
|
*/
|
||||||
|
template <typename CmpLess, typename IterT, typename KeyT>
|
||||||
|
-static IterT VmaBinaryFindFirstNotLess(IterT beg, IterT end, const KeyT& key, const CmpLess& cmp)
|
||||||
|
+static inline IterT VmaBinaryFindFirstNotLess(IterT beg, IterT end, const KeyT& key, const CmpLess& cmp)
|
||||||
|
{
|
||||||
|
size_t down = 0;
|
||||||
|
size_t up = size_t(end - beg);
|
||||||
|
@@ -3898,7 +3898,7 @@ Warning! O(n^2) complexity. Use only inside VMA_HEAVY_ASSERT.
|
||||||
|
T must be pointer type, e.g. VmaAllocation, VmaPool.
|
||||||
|
*/
|
||||||
|
template<typename T>
|
||||||
|
-static bool VmaValidatePointerArray(uint32_t count, const T* arr)
|
||||||
|
+static inline bool VmaValidatePointerArray(uint32_t count, const T* arr)
|
||||||
|
{
|
||||||
|
for (uint32_t i = 0; i < count; ++i)
|
||||||
|
{
|
||||||
|
@@ -4188,13 +4188,13 @@ static void VmaFree(const VkAllocationCallbacks* pAllocationCallbacks, void* ptr
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
-static T* VmaAllocate(const VkAllocationCallbacks* pAllocationCallbacks)
|
||||||
|
+static inline T* VmaAllocate(const VkAllocationCallbacks* pAllocationCallbacks)
|
||||||
|
{
|
||||||
|
return (T*)VmaMalloc(pAllocationCallbacks, sizeof(T), VMA_ALIGN_OF(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
-static T* VmaAllocateArray(const VkAllocationCallbacks* pAllocationCallbacks, size_t count)
|
||||||
|
+static inline T* VmaAllocateArray(const VkAllocationCallbacks* pAllocationCallbacks, size_t count)
|
||||||
|
{
|
||||||
|
return (T*)VmaMalloc(pAllocationCallbacks, sizeof(T) * count, VMA_ALIGN_OF(T));
|
||||||
|
}
|
||||||
|
@@ -4204,14 +4204,14 @@ static T* VmaAllocateArray(const VkAllocationCallbacks* pAllocationCallbacks, si
|
||||||
|
#define vma_new_array(allocator, type, count) new(VmaAllocateArray<type>((allocator), (count)))(type)
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
-static void vma_delete(const VkAllocationCallbacks* pAllocationCallbacks, T* ptr)
|
||||||
|
+static inline void vma_delete(const VkAllocationCallbacks* pAllocationCallbacks, T* ptr)
|
||||||
|
{
|
||||||
|
ptr->~T();
|
||||||
|
VmaFree(pAllocationCallbacks, ptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
-static void vma_delete_array(const VkAllocationCallbacks* pAllocationCallbacks, T* ptr, size_t count)
|
||||||
|
+static inline void vma_delete_array(const VkAllocationCallbacks* pAllocationCallbacks, T* ptr, size_t count)
|
||||||
|
{
|
||||||
|
if (ptr != VMA_NULL)
|
||||||
|
{
|
||||||
|
@@ -4658,13 +4658,13 @@ void VmaVector<T, AllocatorT>::remove(size_t index)
|
||||||
|
#endif // _VMA_VECTOR_FUNCTIONS
|
||||||
|
|
||||||
|
template<typename T, typename allocatorT>
|
||||||
|
-static void VmaVectorInsert(VmaVector<T, allocatorT>& vec, size_t index, const T& item)
|
||||||
|
+static inline void VmaVectorInsert(VmaVector<T, allocatorT>& vec, size_t index, const T& item)
|
||||||
|
{
|
||||||
|
vec.insert(index, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T, typename allocatorT>
|
||||||
|
-static void VmaVectorRemove(VmaVector<T, allocatorT>& vec, size_t index)
|
||||||
|
+static inline void VmaVectorRemove(VmaVector<T, allocatorT>& vec, size_t index)
|
||||||
|
{
|
||||||
|
vec.remove(index);
|
||||||
|
}
|
||||||
|
@@ -10620,19 +10620,19 @@ static void VmaFree(VmaAllocator hAllocator, void* ptr)
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
-static T* VmaAllocate(VmaAllocator hAllocator)
|
||||||
|
+static inline T* VmaAllocate(VmaAllocator hAllocator)
|
||||||
|
{
|
||||||
|
return (T*)VmaMalloc(hAllocator, sizeof(T), VMA_ALIGN_OF(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
-static T* VmaAllocateArray(VmaAllocator hAllocator, size_t count)
|
||||||
|
+static inline T* VmaAllocateArray(VmaAllocator hAllocator, size_t count)
|
||||||
|
{
|
||||||
|
return (T*)VmaMalloc(hAllocator, sizeof(T) * count, VMA_ALIGN_OF(T));
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
-static void vma_delete(VmaAllocator hAllocator, T* ptr)
|
||||||
|
+static inline void vma_delete(VmaAllocator hAllocator, T* ptr)
|
||||||
|
{
|
||||||
|
if(ptr != VMA_NULL)
|
||||||
|
{
|
||||||
|
@@ -10642,7 +10642,7 @@ static void vma_delete(VmaAllocator hAllocator, T* ptr)
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
-static void vma_delete_array(VmaAllocator hAllocator, T* ptr, size_t count)
|
||||||
|
+static inline void vma_delete_array(VmaAllocator hAllocator, T* ptr, size_t count)
|
||||||
|
{
|
||||||
|
if(ptr != VMA_NULL)
|
||||||
|
{
|
||||||
+2
-1
@@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
cmake_minimum_required(VERSION 3.31)
|
cmake_minimum_required(VERSION 3.31)
|
||||||
|
|
||||||
|
set(CMAKE_OSX_DEPLOYMENT_TARGET "15.0" CACHE STRING "macOS deployment target")
|
||||||
project(yuzu)
|
project(yuzu)
|
||||||
|
|
||||||
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
|
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules")
|
||||||
@@ -512,7 +513,7 @@ endfunction()
|
|||||||
# =============================================
|
# =============================================
|
||||||
|
|
||||||
if (APPLE)
|
if (APPLE)
|
||||||
foreach(fw Carbon Metal Cocoa IOKit CoreVideo CoreMedia Security UniformTypeIdentifiers)
|
foreach(fw Carbon Metal Cocoa IOKit CoreVideo CoreMedia Security UniformTypeIdentifiers Foundation)
|
||||||
find_library(${fw}_LIBRARY ${fw} REQUIRED)
|
find_library(${fw}_LIBRARY ${fw} REQUIRED)
|
||||||
list(APPEND PLATFORM_LIBRARIES ${${fw}_LIBRARY})
|
list(APPEND PLATFORM_LIBRARIES ${${fw}_LIBRARY})
|
||||||
endforeach()
|
endforeach()
|
||||||
|
|||||||
+5
-10
@@ -1,12 +1,4 @@
|
|||||||
{
|
{
|
||||||
"": {
|
|
||||||
"ci": true,
|
|
||||||
"hash": "9f50d993c39529e022ad456163de91ac5934e16faf8fc348f305355fc0a643c534f87ded707e11bd03bcbc0a1760bd20852b6533a67ac0558a078385181cb184",
|
|
||||||
"name": "SDL3",
|
|
||||||
"package": "SDL3",
|
|
||||||
"repo": "crueter-ci/SDL3",
|
|
||||||
"version": "3.4.14-1788231389-147a8ee32d"
|
|
||||||
},
|
|
||||||
"biscuit": {
|
"biscuit": {
|
||||||
"hash": "1229f345b014f7ca544dedb4edb3311e41ba736f9aa9a67f88b5f26f3c983288c6bb6cdedcfb0b8a02c63088a37e6a0d7ba97d9c2a4d721b213916327cffe28a",
|
"hash": "1229f345b014f7ca544dedb4edb3311e41ba736f9aa9a67f88b5f26f3c983288c6bb6cdedcfb0b8a02c63088a37e6a0d7ba97d9c2a4d721b213916327cffe28a",
|
||||||
"min_version": "0.9.1",
|
"min_version": "0.9.1",
|
||||||
@@ -68,10 +60,10 @@
|
|||||||
},
|
},
|
||||||
"discord-rpc": {
|
"discord-rpc": {
|
||||||
"find_args": "MODULE",
|
"find_args": "MODULE",
|
||||||
"hash": "8213c43dcb0f7d479f5861091d111ed12fbdec1e62e6d729d65a4bc181d82f48a35d5fd3cd5c291f2393ac7c9681eabc6b76609755f55376284c8a8d67e148f3",
|
"hash": "8d680b3a16d6f6bf292ad823cf8635595ff986f2a49f758e3009f505b540a9d75194a8cf44cddea75736a8c3e3b5160166e716a0939ce3f18cc463cf648753fe",
|
||||||
"package": "DiscordRPC",
|
"package": "DiscordRPC",
|
||||||
"repo": "eden-emulator/discord-rpc",
|
"repo": "eden-emulator/discord-rpc",
|
||||||
"version": "0d8b2d6a37"
|
"version": "76616d8675"
|
||||||
},
|
},
|
||||||
"enet": {
|
"enet": {
|
||||||
"find_args": "MODULE",
|
"find_args": "MODULE",
|
||||||
@@ -311,6 +303,9 @@
|
|||||||
"find_args": "CONFIG",
|
"find_args": "CONFIG",
|
||||||
"hash": "deb5902ef8db0e329fbd5f3f4385eb0e26bdd9f14f3a2334823fb3fe18f36bc5d235d620d6e5f6fe3551ec3ea7038638899db8778c09f6d5c278f5ff95c3344b",
|
"hash": "deb5902ef8db0e329fbd5f3f4385eb0e26bdd9f14f3a2334823fb3fe18f36bc5d235d620d6e5f6fe3551ec3ea7038638899db8778c09f6d5c278f5ff95c3344b",
|
||||||
"package": "VulkanMemoryAllocator",
|
"package": "VulkanMemoryAllocator",
|
||||||
|
"patches": [
|
||||||
|
"0001-macos-clang.patch"
|
||||||
|
],
|
||||||
"repo": "GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator",
|
"repo": "GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator",
|
||||||
"version": "v3.3.0"
|
"version": "v3.3.0"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -89,6 +89,7 @@ add_library(
|
|||||||
param_package.h
|
param_package.h
|
||||||
parent_of_member.h
|
parent_of_member.h
|
||||||
point.h
|
point.h
|
||||||
|
quaternion.h
|
||||||
range_map.h
|
range_map.h
|
||||||
range_mutex.h
|
range_mutex.h
|
||||||
range_sets.h
|
range_sets.h
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
// SPDX-FileCopyrightText: 2016 Citra Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "common/vector_math.h"
|
||||||
|
|
||||||
|
namespace Common {
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class Quaternion {
|
||||||
|
public:
|
||||||
|
Vec3<T> xyz;
|
||||||
|
T w{};
|
||||||
|
|
||||||
|
[[nodiscard]] Quaternion<decltype(-T{})> Inverse() const {
|
||||||
|
return {-xyz, w};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] Quaternion<decltype(T{} + T{})> operator+(const Quaternion& other) const {
|
||||||
|
return {xyz + other.xyz, w + other.w};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] Quaternion<decltype(T{} - T{})> operator-(const Quaternion& other) const {
|
||||||
|
return {xyz - other.xyz, w - other.w};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] Quaternion<decltype(T{} * T{} - T{} * T{})> operator*(
|
||||||
|
const Quaternion& other) const {
|
||||||
|
return {xyz * other.w + other.xyz * w + Cross(xyz, other.xyz),
|
||||||
|
w * other.w - Dot(xyz, other.xyz)};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] Quaternion<T> Normalized() const {
|
||||||
|
T length = std::sqrt(xyz.Length2() + w * w);
|
||||||
|
return {xyz / length, w / length};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] std::array<decltype(-T{}), 16> ToMatrix() const {
|
||||||
|
const T x2 = xyz[0] * xyz[0];
|
||||||
|
const T y2 = xyz[1] * xyz[1];
|
||||||
|
const T z2 = xyz[2] * xyz[2];
|
||||||
|
|
||||||
|
const T xy = xyz[0] * xyz[1];
|
||||||
|
const T wz = w * xyz[2];
|
||||||
|
const T xz = xyz[0] * xyz[2];
|
||||||
|
const T wy = w * xyz[1];
|
||||||
|
const T yz = xyz[1] * xyz[2];
|
||||||
|
const T wx = w * xyz[0];
|
||||||
|
|
||||||
|
return {1.0f - 2.0f * (y2 + z2),
|
||||||
|
2.0f * (xy + wz),
|
||||||
|
2.0f * (xz - wy),
|
||||||
|
0.0f,
|
||||||
|
2.0f * (xy - wz),
|
||||||
|
1.0f - 2.0f * (x2 + z2),
|
||||||
|
2.0f * (yz + wx),
|
||||||
|
0.0f,
|
||||||
|
2.0f * (xz + wy),
|
||||||
|
2.0f * (yz - wx),
|
||||||
|
1.0f - 2.0f * (x2 + y2),
|
||||||
|
0.0f,
|
||||||
|
0.0f,
|
||||||
|
0.0f,
|
||||||
|
0.0f,
|
||||||
|
1.0f};
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] auto QuaternionRotate(const Quaternion<T>& q, const Vec3<T>& v) {
|
||||||
|
return v + 2 * Cross(q.xyz, Cross(q.xyz, v) + v * q.w);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] inline Quaternion<float> MakeQuaternion(const Vec3<float>& axis, float angle) {
|
||||||
|
return {axis * std::sin(angle / 2), std::cos(angle / 2)};
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Common
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <iterator>
|
#include <iterator>
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
#include "common/make_unique_for_overwrite.h"
|
#include "common/make_unique_for_overwrite.h"
|
||||||
|
|
||||||
@@ -61,7 +65,7 @@ public:
|
|||||||
void resize(size_type size) {
|
void resize(size_type size) {
|
||||||
if (size > buffer_capacity) {
|
if (size > buffer_capacity) {
|
||||||
auto new_buffer = Common::make_unique_for_overwrite<T[]>(size);
|
auto new_buffer = Common::make_unique_for_overwrite<T[]>(size);
|
||||||
std::move(buffer.get(), buffer.get() + buffer_capacity, new_buffer.get());
|
std::memcpy(new_buffer.get(), buffer.get(), buffer_capacity * sizeof(T));
|
||||||
buffer = std::move(new_buffer);
|
buffer = std::move(new_buffer);
|
||||||
buffer_capacity = size;
|
buffer_capacity = size;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
#include <functional>
|
#include <functional>
|
||||||
#include <span>
|
#include <span>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
|
||||||
|
|||||||
+717
-93
@@ -1,4 +1,4 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: 2014 Tony Wasserka
|
// SPDX-FileCopyrightText: 2014 Tony Wasserka
|
||||||
@@ -7,128 +7,752 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __ARM_NEON
|
||||||
|
#include <arm_neon.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <type_traits>
|
#include <type_traits>
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
template <typename T, size_t N>
|
template <typename T>
|
||||||
class Vec {
|
class Vec2;
|
||||||
|
template <typename T>
|
||||||
|
class Vec3;
|
||||||
|
template <typename T>
|
||||||
|
class Vec4;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class Vec2 {
|
||||||
public:
|
public:
|
||||||
std::array<T, N> elems{};
|
T x{};
|
||||||
|
T y{};
|
||||||
|
|
||||||
constexpr Vec() = default;
|
constexpr Vec2() = default;
|
||||||
constexpr Vec(T e0) noexcept : elems{e0} {}
|
constexpr Vec2(const T& x_, const T& y_) : x(x_), y(y_) {}
|
||||||
constexpr Vec(T e0, T e1) noexcept : elems{e0, e1} {}
|
|
||||||
constexpr Vec(T e0, T e1, T e2) noexcept : elems{e0, e1, e2} {}
|
|
||||||
constexpr Vec(T e0, T e1, T e2, T e4) noexcept : elems{e0, e1, e2, e4} {}
|
|
||||||
//explicit constexpr Vec(const std::initializer_list<T> elems_) noexcept : elems{elems_} {}
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr Vec<decltype(T{} + T{}), N> operator+(const Vec o) const noexcept {
|
template <typename T2>
|
||||||
Vec<decltype(T{} + T{}), N> r{};
|
[[nodiscard]] constexpr Vec2<T2> Cast() const {
|
||||||
for (size_t i = 0; i < N; ++i)
|
return Vec2<T2>(static_cast<T2>(x), static_cast<T2>(y));
|
||||||
r.elems[i] = elems[i] + o.elems[i];
|
|
||||||
return r;
|
|
||||||
}
|
}
|
||||||
constexpr Vec<T, N> operator+=(const Vec<T, N> o) noexcept { return *this = *this + o; }
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr Vec<decltype(T{} - T{}), N> operator-(const Vec o) const noexcept {
|
[[nodiscard]] static constexpr Vec2 AssignToAll(const T& f) {
|
||||||
Vec<decltype(T{} - T{}), N> r{};
|
return Vec2{f, f};
|
||||||
for (size_t i = 0; i < N; ++i)
|
}
|
||||||
r.elems[i] = elems[i] - o.elems[i];
|
|
||||||
return r;
|
[[nodiscard]] constexpr Vec2<decltype(T{} + T{})> operator+(const Vec2& other) const {
|
||||||
|
return {x + other.x, y + other.y};
|
||||||
|
}
|
||||||
|
constexpr Vec2& operator+=(const Vec2& other) {
|
||||||
|
x += other.x;
|
||||||
|
y += other.y;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr Vec2<decltype(T{} - T{})> operator-(const Vec2& other) const {
|
||||||
|
return {x - other.x, y - other.y};
|
||||||
|
}
|
||||||
|
constexpr Vec2& operator-=(const Vec2& other) {
|
||||||
|
x -= other.x;
|
||||||
|
y -= other.y;
|
||||||
|
return *this;
|
||||||
}
|
}
|
||||||
constexpr Vec<T, N> operator-=(const Vec<T, N> o) noexcept { return *this = *this - o; }
|
|
||||||
|
|
||||||
template <typename U = T>
|
template <typename U = T>
|
||||||
[[nodiscard]] constexpr Vec<std::enable_if_t<std::is_signed_v<U>, U>, N> operator-() const noexcept {
|
[[nodiscard]] constexpr Vec2<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const {
|
||||||
Vec<U, N> r{};
|
return {-x, -y};
|
||||||
for (size_t i = 0; i < N; ++i)
|
}
|
||||||
r.elems[i] = -elems[i];
|
[[nodiscard]] constexpr Vec2<decltype(T{} * T{})> operator*(const Vec2& other) const {
|
||||||
return r;
|
return {x * other.x, y * other.y};
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] constexpr Vec<decltype(T{} * T{}), N> operator*(const Vec o) const noexcept {
|
|
||||||
Vec<decltype(T{} * T{}), N> r{};
|
|
||||||
for (size_t i = 0; i < N; ++i)
|
|
||||||
r.elems[i] = elems[i] * o.elems[i];
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
template <typename V>
|
template <typename V>
|
||||||
[[nodiscard]] constexpr Vec<decltype(T{} * V{}), N> operator*(const V f) const noexcept {
|
[[nodiscard]] constexpr Vec2<decltype(T{} * V{})> operator*(const V& f) const {
|
||||||
using TV = decltype(T{} * V{});
|
using TV = decltype(T{} * V{});
|
||||||
using C = std::common_type_t<T, V>;
|
using C = std::common_type_t<T, V>;
|
||||||
Vec<TV, N> r{};
|
|
||||||
for (size_t i = 0; i < N; ++i)
|
return {
|
||||||
r.elems[i] = TV(C(elems[i]) * C(f));
|
static_cast<TV>(static_cast<C>(x) * static_cast<C>(f)),
|
||||||
return r;
|
static_cast<TV>(static_cast<C>(y) * static_cast<C>(f)),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
template <typename V>
|
|
||||||
constexpr Vec<T, N> operator*=(const V f) noexcept { return *this = *this * f; }
|
|
||||||
|
|
||||||
template <typename V>
|
template <typename V>
|
||||||
[[nodiscard]] constexpr Vec<decltype(T{} / V{}), N> operator/(const V f) const noexcept {
|
constexpr Vec2& operator*=(const V& f) {
|
||||||
|
*this = *this * f;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename V>
|
||||||
|
[[nodiscard]] constexpr Vec2<decltype(T{} / V{})> operator/(const V& f) const {
|
||||||
using TV = decltype(T{} / V{});
|
using TV = decltype(T{} / V{});
|
||||||
using C = std::common_type_t<T, V>;
|
using C = std::common_type_t<T, V>;
|
||||||
Vec<TV, N> r{};
|
|
||||||
for (size_t i = 0; i < N; ++i)
|
|
||||||
r.elems[i] = TV(C(elems[i]) / C(f));
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
template <typename V>
|
|
||||||
constexpr Vec<T, N> operator/=(const V f) noexcept { return *this = *this / f; }
|
|
||||||
|
|
||||||
[[nodiscard]] constexpr T Length2() const noexcept {
|
|
||||||
T r{};
|
|
||||||
for (size_t i = 0; i < N; ++i)
|
|
||||||
r += elems[i] * elems[i];
|
|
||||||
return r;
|
|
||||||
}
|
|
||||||
// Only implemented for T=float
|
|
||||||
[[nodiscard]] T Length() const { return T(std::sqrt(float(Length2()))); }
|
|
||||||
[[nodiscard]] Vec<T, N> Normalized() const { return *this / Length(); }
|
|
||||||
[[nodiscard]] constexpr T& operator[](std::size_t i) noexcept { return elems[i]; }
|
|
||||||
[[nodiscard]] constexpr const T& operator[](std::size_t i) const noexcept { return elems[i]; }
|
|
||||||
|
|
||||||
[[nodiscard]] std::array<decltype(-T{}), 16> ToMatrix() const {
|
|
||||||
const T x2 = elems[0] * elems[0];
|
|
||||||
const T y2 = elems[1] * elems[1];
|
|
||||||
const T z2 = elems[2] * elems[2];
|
|
||||||
|
|
||||||
const T xy = elems[0] * elems[1];
|
|
||||||
const T wz = elems[3] * elems[2];
|
|
||||||
const T xz = elems[0] * elems[2];
|
|
||||||
const T wy = elems[3] * elems[1];
|
|
||||||
const T yz = elems[1] * elems[2];
|
|
||||||
const T wx = elems[3] * elems[0];
|
|
||||||
return {
|
return {
|
||||||
1.0f - 2.0f * (y2 + z2),
|
static_cast<TV>(static_cast<C>(x) / static_cast<C>(f)),
|
||||||
2.0f * (xy + wz),
|
static_cast<TV>(static_cast<C>(y) / static_cast<C>(f)),
|
||||||
2.0f * (xz - wy),
|
|
||||||
0.0f,
|
|
||||||
2.0f * (xy - wz),
|
|
||||||
1.0f - 2.0f * (x2 + z2),
|
|
||||||
2.0f * (yz + wx),
|
|
||||||
0.0f,
|
|
||||||
2.0f * (xz + wy),
|
|
||||||
2.0f * (yz - wx),
|
|
||||||
1.0f - 2.0f * (x2 + y2),
|
|
||||||
0.0f,
|
|
||||||
0.0f,
|
|
||||||
0.0f,
|
|
||||||
0.0f,
|
|
||||||
1.0f
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename V>
|
||||||
|
constexpr Vec2& operator/=(const V& f) {
|
||||||
|
*this = *this / f;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr T Length2() const {
|
||||||
|
return x * x + y * y;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only implemented for T=float
|
||||||
|
[[nodiscard]] float Length() const;
|
||||||
|
[[nodiscard]] float Normalize(); // returns the previous length, which is often useful
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr T& operator[](std::size_t i) {
|
||||||
|
return *((&x) + i);
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr const T& operator[](std::size_t i) const {
|
||||||
|
return *((&x) + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr void SetZero() {
|
||||||
|
x = 0;
|
||||||
|
y = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Common aliases: UV (texel coordinates), ST (texture coordinates)
|
||||||
|
[[nodiscard]] constexpr T& u() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr T& v() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr T& s() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr T& t() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr const T& u() const {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr const T& v() const {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr const T& s() const {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr const T& t() const {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
|
||||||
|
// swizzlers - create a subvector of specific components
|
||||||
|
[[nodiscard]] constexpr Vec2 yx() const {
|
||||||
|
return Vec2(y, x);
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr Vec2 vu() const {
|
||||||
|
return Vec2(y, x);
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr Vec2 ts() const {
|
||||||
|
return Vec2(y, x);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T, size_t N, typename V>
|
template <typename T, typename V>
|
||||||
[[nodiscard]] constexpr Vec<T, N> operator*(const V f, const Vec<T, N> v) noexcept {
|
[[nodiscard]] constexpr Vec2<T> operator*(const V& f, const Vec2<T>& vec) {
|
||||||
using C = std::common_type_t<T, V>;
|
using C = std::common_type_t<T, V>;
|
||||||
Vec<T, N> r{};
|
|
||||||
for (size_t i = 0; i < N; ++i)
|
return Vec2<T>(static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.x)),
|
||||||
r.elems[i] = T(C(f) * C(v.elems[i]));
|
static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.y)));
|
||||||
return r;
|
}
|
||||||
|
|
||||||
|
using Vec2f = Vec2<float>;
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline float Vec2<float>::Length() const {
|
||||||
|
return std::sqrt(x * x + y * y);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline float Vec2<float>::Normalize() {
|
||||||
|
float length = Length();
|
||||||
|
*this /= length;
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class Vec3 {
|
||||||
|
public:
|
||||||
|
T x{};
|
||||||
|
T y{};
|
||||||
|
T z{};
|
||||||
|
|
||||||
|
constexpr Vec3() = default;
|
||||||
|
constexpr Vec3(const T& x_, const T& y_, const T& z_) : x(x_), y(y_), z(z_) {}
|
||||||
|
|
||||||
|
template <typename T2>
|
||||||
|
[[nodiscard]] constexpr Vec3<T2> Cast() const {
|
||||||
|
return Vec3<T2>(static_cast<T2>(x), static_cast<T2>(y), static_cast<T2>(z));
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] static constexpr Vec3 AssignToAll(const T& f) {
|
||||||
|
return Vec3(f, f, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr Vec3<decltype(T{} + T{})> operator+(const Vec3& other) const {
|
||||||
|
return {x + other.x, y + other.y, z + other.z};
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Vec3& operator+=(const Vec3& other) {
|
||||||
|
x += other.x;
|
||||||
|
y += other.y;
|
||||||
|
z += other.z;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr Vec3<decltype(T{} - T{})> operator-(const Vec3& other) const {
|
||||||
|
return {x - other.x, y - other.y, z - other.z};
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Vec3& operator-=(const Vec3& other) {
|
||||||
|
x -= other.x;
|
||||||
|
y -= other.y;
|
||||||
|
z -= other.z;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename U = T>
|
||||||
|
[[nodiscard]] constexpr Vec3<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const {
|
||||||
|
return {-x, -y, -z};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr Vec3<decltype(T{} * T{})> operator*(const Vec3& other) const {
|
||||||
|
return {x * other.x, y * other.y, z * other.z};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename V>
|
||||||
|
[[nodiscard]] constexpr Vec3<decltype(T{} * V{})> operator*(const V& f) const {
|
||||||
|
using TV = decltype(T{} * V{});
|
||||||
|
using C = std::common_type_t<T, V>;
|
||||||
|
|
||||||
|
return {
|
||||||
|
static_cast<TV>(static_cast<C>(x) * static_cast<C>(f)),
|
||||||
|
static_cast<TV>(static_cast<C>(y) * static_cast<C>(f)),
|
||||||
|
static_cast<TV>(static_cast<C>(z) * static_cast<C>(f)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename V>
|
||||||
|
constexpr Vec3& operator*=(const V& f) {
|
||||||
|
*this = *this * f;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
template <typename V>
|
||||||
|
[[nodiscard]] constexpr Vec3<decltype(T{} / V{})> operator/(const V& f) const {
|
||||||
|
using TV = decltype(T{} / V{});
|
||||||
|
using C = std::common_type_t<T, V>;
|
||||||
|
|
||||||
|
return {
|
||||||
|
static_cast<TV>(static_cast<C>(x) / static_cast<C>(f)),
|
||||||
|
static_cast<TV>(static_cast<C>(y) / static_cast<C>(f)),
|
||||||
|
static_cast<TV>(static_cast<C>(z) / static_cast<C>(f)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename V>
|
||||||
|
constexpr Vec3& operator/=(const V& f) {
|
||||||
|
*this = *this / f;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
void RotateFromOrigin(float roll, float pitch, float yaw) {
|
||||||
|
float temp = y;
|
||||||
|
y = std::cos(roll) * y - std::sin(roll) * z;
|
||||||
|
z = std::sin(roll) * temp + std::cos(roll) * z;
|
||||||
|
|
||||||
|
temp = x;
|
||||||
|
x = std::cos(pitch) * x + std::sin(pitch) * z;
|
||||||
|
z = -std::sin(pitch) * temp + std::cos(pitch) * z;
|
||||||
|
|
||||||
|
temp = x;
|
||||||
|
x = std::cos(yaw) * x - std::sin(yaw) * y;
|
||||||
|
y = std::sin(yaw) * temp + std::cos(yaw) * y;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr T Length2() const {
|
||||||
|
return x * x + y * y + z * z;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only implemented for T=float
|
||||||
|
[[nodiscard]] float Length() const;
|
||||||
|
[[nodiscard]] Vec3 Normalized() const;
|
||||||
|
[[nodiscard]] float Normalize(); // returns the previous length, which is often useful
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr T& operator[](std::size_t i) {
|
||||||
|
return *((&x) + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr const T& operator[](std::size_t i) const {
|
||||||
|
return *((&x) + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr void SetZero() {
|
||||||
|
x = 0;
|
||||||
|
y = 0;
|
||||||
|
z = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Common aliases: UVW (texel coordinates), RGB (colors), STQ (texture coordinates)
|
||||||
|
[[nodiscard]] constexpr T& u() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr T& v() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr T& w() {
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr T& r() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr T& g() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr T& b() {
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr T& s() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr T& t() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr T& q() {
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr const T& u() const {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr const T& v() const {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr const T& w() const {
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr const T& r() const {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr const T& g() const {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr const T& b() const {
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr const T& s() const {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr const T& t() const {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr const T& q() const {
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
|
||||||
|
// swizzlers - create a subvector of specific components
|
||||||
|
// e.g. Vec2 uv() { return Vec2(x,y); }
|
||||||
|
// _DEFINE_SWIZZLER2 defines a single such function, DEFINE_SWIZZLER2 defines all of them for all
|
||||||
|
// component names (x<->r) and permutations (xy<->yx)
|
||||||
|
#define _DEFINE_SWIZZLER2(a, b, name) \
|
||||||
|
[[nodiscard]] constexpr Vec2<T> name() const { return Vec2<T>(a, b); }
|
||||||
|
#define DEFINE_SWIZZLER2(a, b, a2, b2, a3, b3, a4, b4) \
|
||||||
|
_DEFINE_SWIZZLER2(a, b, a##b); \
|
||||||
|
_DEFINE_SWIZZLER2(a, b, a2##b2); \
|
||||||
|
_DEFINE_SWIZZLER2(a, b, a3##b3); \
|
||||||
|
_DEFINE_SWIZZLER2(a, b, a4##b4); \
|
||||||
|
_DEFINE_SWIZZLER2(b, a, b##a); \
|
||||||
|
_DEFINE_SWIZZLER2(b, a, b2##a2); \
|
||||||
|
_DEFINE_SWIZZLER2(b, a, b3##a3); \
|
||||||
|
_DEFINE_SWIZZLER2(b, a, b4##a4)
|
||||||
|
|
||||||
|
DEFINE_SWIZZLER2(x, y, r, g, u, v, s, t);
|
||||||
|
DEFINE_SWIZZLER2(x, z, r, b, u, w, s, q);
|
||||||
|
DEFINE_SWIZZLER2(y, z, g, b, v, w, t, q);
|
||||||
|
#undef DEFINE_SWIZZLER2
|
||||||
|
#undef _DEFINE_SWIZZLER2
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T, typename V>
|
||||||
|
[[nodiscard]] constexpr Vec3<T> operator*(const V& f, const Vec3<T>& vec) {
|
||||||
|
using C = std::common_type_t<T, V>;
|
||||||
|
|
||||||
|
return Vec3<T>(static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.x)),
|
||||||
|
static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.y)),
|
||||||
|
static_cast<T>(static_cast<C>(f) * static_cast<C>(vec.z)));
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline float Vec3<float>::Length() const {
|
||||||
|
return std::sqrt(x * x + y * y + z * z);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline Vec3<float> Vec3<float>::Normalized() const {
|
||||||
|
return *this / Length();
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
inline float Vec3<float>::Normalize() {
|
||||||
|
float length = Length();
|
||||||
|
*this /= length;
|
||||||
|
return length;
|
||||||
|
}
|
||||||
|
|
||||||
|
using Vec3f = Vec3<float>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class Vec4 {
|
||||||
|
public:
|
||||||
|
T x{};
|
||||||
|
T y{};
|
||||||
|
T z{};
|
||||||
|
T w{};
|
||||||
|
|
||||||
|
constexpr Vec4() = default;
|
||||||
|
constexpr Vec4(const T& x_, const T& y_, const T& z_, const T& w_)
|
||||||
|
: x(x_), y(y_), z(z_), w(w_) {}
|
||||||
|
|
||||||
|
template <typename T2>
|
||||||
|
[[nodiscard]] constexpr Vec4<T2> Cast() const {
|
||||||
|
return Vec4<T2>(static_cast<T2>(x), static_cast<T2>(y), static_cast<T2>(z),
|
||||||
|
static_cast<T2>(w));
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] static constexpr Vec4 AssignToAll(const T& f) {
|
||||||
|
return Vec4(f, f, f, f);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr Vec4<decltype(T{} + T{})> operator+(const Vec4& other) const {
|
||||||
|
return {x + other.x, y + other.y, z + other.z, w + other.w};
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Vec4& operator+=(const Vec4& other) {
|
||||||
|
x += other.x;
|
||||||
|
y += other.y;
|
||||||
|
z += other.z;
|
||||||
|
w += other.w;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr Vec4<decltype(T{} - T{})> operator-(const Vec4& other) const {
|
||||||
|
return {x - other.x, y - other.y, z - other.z, w - other.w};
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr Vec4& operator-=(const Vec4& other) {
|
||||||
|
x -= other.x;
|
||||||
|
y -= other.y;
|
||||||
|
z -= other.z;
|
||||||
|
w -= other.w;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename U = T>
|
||||||
|
[[nodiscard]] constexpr Vec4<std::enable_if_t<std::is_signed_v<U>, U>> operator-() const {
|
||||||
|
return {-x, -y, -z, -w};
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr Vec4<decltype(T{} * T{})> operator*(const Vec4& other) const {
|
||||||
|
return {x * other.x, y * other.y, z * other.z, w * other.w};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename V>
|
||||||
|
[[nodiscard]] constexpr Vec4<decltype(T{} * V{})> operator*(const V& f) const {
|
||||||
|
using TV = decltype(T{} * V{});
|
||||||
|
using C = std::common_type_t<T, V>;
|
||||||
|
|
||||||
|
return {
|
||||||
|
static_cast<TV>(static_cast<C>(x) * static_cast<C>(f)),
|
||||||
|
static_cast<TV>(static_cast<C>(y) * static_cast<C>(f)),
|
||||||
|
static_cast<TV>(static_cast<C>(z) * static_cast<C>(f)),
|
||||||
|
static_cast<TV>(static_cast<C>(w) * static_cast<C>(f)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename V>
|
||||||
|
constexpr Vec4& operator*=(const V& f) {
|
||||||
|
*this = *this * f;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename V>
|
||||||
|
[[nodiscard]] constexpr Vec4<decltype(T{} / V{})> operator/(const V& f) const {
|
||||||
|
using TV = decltype(T{} / V{});
|
||||||
|
using C = std::common_type_t<T, V>;
|
||||||
|
|
||||||
|
return {
|
||||||
|
static_cast<TV>(static_cast<C>(x) / static_cast<C>(f)),
|
||||||
|
static_cast<TV>(static_cast<C>(y) / static_cast<C>(f)),
|
||||||
|
static_cast<TV>(static_cast<C>(z) / static_cast<C>(f)),
|
||||||
|
static_cast<TV>(static_cast<C>(w) / static_cast<C>(f)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename V>
|
||||||
|
constexpr Vec4& operator/=(const V& f) {
|
||||||
|
*this = *this / f;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr T Length2() const {
|
||||||
|
return x * x + y * y + z * z + w * w;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr T& operator[](std::size_t i) {
|
||||||
|
return *((&x) + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr const T& operator[](std::size_t i) const {
|
||||||
|
return *((&x) + i);
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr void SetZero() {
|
||||||
|
x = 0;
|
||||||
|
y = 0;
|
||||||
|
z = 0;
|
||||||
|
w = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Common alias: RGBA (colors)
|
||||||
|
[[nodiscard]] constexpr T& r() {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr T& g() {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr T& b() {
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr T& a() {
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] constexpr const T& r() const {
|
||||||
|
return x;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr const T& g() const {
|
||||||
|
return y;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr const T& b() const {
|
||||||
|
return z;
|
||||||
|
}
|
||||||
|
[[nodiscard]] constexpr const T& a() const {
|
||||||
|
return w;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Swizzlers - Create a subvector of specific components
|
||||||
|
// e.g. Vec2 uv() { return Vec2(x,y); }
|
||||||
|
|
||||||
|
// _DEFINE_SWIZZLER2 defines a single such function
|
||||||
|
// DEFINE_SWIZZLER2_COMP1 defines one-component functions for all component names (x<->r)
|
||||||
|
// DEFINE_SWIZZLER2_COMP2 defines two component functions for all component names (x<->r) and
|
||||||
|
// permutations (xy<->yx)
|
||||||
|
#define _DEFINE_SWIZZLER2(a, b, name) \
|
||||||
|
[[nodiscard]] constexpr Vec2<T> name() const { return Vec2<T>(a, b); }
|
||||||
|
#define DEFINE_SWIZZLER2_COMP1(a, a2) \
|
||||||
|
_DEFINE_SWIZZLER2(a, a, a##a); \
|
||||||
|
_DEFINE_SWIZZLER2(a, a, a2##a2)
|
||||||
|
#define DEFINE_SWIZZLER2_COMP2(a, b, a2, b2) \
|
||||||
|
_DEFINE_SWIZZLER2(a, b, a##b); \
|
||||||
|
_DEFINE_SWIZZLER2(a, b, a2##b2); \
|
||||||
|
_DEFINE_SWIZZLER2(b, a, b##a); \
|
||||||
|
_DEFINE_SWIZZLER2(b, a, b2##a2)
|
||||||
|
|
||||||
|
DEFINE_SWIZZLER2_COMP2(x, y, r, g);
|
||||||
|
DEFINE_SWIZZLER2_COMP2(x, z, r, b);
|
||||||
|
DEFINE_SWIZZLER2_COMP2(x, w, r, a);
|
||||||
|
DEFINE_SWIZZLER2_COMP2(y, z, g, b);
|
||||||
|
DEFINE_SWIZZLER2_COMP2(y, w, g, a);
|
||||||
|
DEFINE_SWIZZLER2_COMP2(z, w, b, a);
|
||||||
|
DEFINE_SWIZZLER2_COMP1(x, r);
|
||||||
|
DEFINE_SWIZZLER2_COMP1(y, g);
|
||||||
|
DEFINE_SWIZZLER2_COMP1(z, b);
|
||||||
|
DEFINE_SWIZZLER2_COMP1(w, a);
|
||||||
|
#undef DEFINE_SWIZZLER2_COMP1
|
||||||
|
#undef DEFINE_SWIZZLER2_COMP2
|
||||||
|
#undef _DEFINE_SWIZZLER2
|
||||||
|
|
||||||
|
#define _DEFINE_SWIZZLER3(a, b, c, name) \
|
||||||
|
[[nodiscard]] constexpr Vec3<T> name() const { return Vec3<T>(a, b, c); }
|
||||||
|
#define DEFINE_SWIZZLER3_COMP1(a, a2) \
|
||||||
|
_DEFINE_SWIZZLER3(a, a, a, a##a##a); \
|
||||||
|
_DEFINE_SWIZZLER3(a, a, a, a2##a2##a2)
|
||||||
|
#define DEFINE_SWIZZLER3_COMP3(a, b, c, a2, b2, c2) \
|
||||||
|
_DEFINE_SWIZZLER3(a, b, c, a##b##c); \
|
||||||
|
_DEFINE_SWIZZLER3(a, c, b, a##c##b); \
|
||||||
|
_DEFINE_SWIZZLER3(b, a, c, b##a##c); \
|
||||||
|
_DEFINE_SWIZZLER3(b, c, a, b##c##a); \
|
||||||
|
_DEFINE_SWIZZLER3(c, a, b, c##a##b); \
|
||||||
|
_DEFINE_SWIZZLER3(c, b, a, c##b##a); \
|
||||||
|
_DEFINE_SWIZZLER3(a, b, c, a2##b2##c2); \
|
||||||
|
_DEFINE_SWIZZLER3(a, c, b, a2##c2##b2); \
|
||||||
|
_DEFINE_SWIZZLER3(b, a, c, b2##a2##c2); \
|
||||||
|
_DEFINE_SWIZZLER3(b, c, a, b2##c2##a2); \
|
||||||
|
_DEFINE_SWIZZLER3(c, a, b, c2##a2##b2); \
|
||||||
|
_DEFINE_SWIZZLER3(c, b, a, c2##b2##a2)
|
||||||
|
|
||||||
|
DEFINE_SWIZZLER3_COMP3(x, y, z, r, g, b);
|
||||||
|
DEFINE_SWIZZLER3_COMP3(x, y, w, r, g, a);
|
||||||
|
DEFINE_SWIZZLER3_COMP3(x, z, w, r, b, a);
|
||||||
|
DEFINE_SWIZZLER3_COMP3(y, z, w, g, b, a);
|
||||||
|
DEFINE_SWIZZLER3_COMP1(x, r);
|
||||||
|
DEFINE_SWIZZLER3_COMP1(y, g);
|
||||||
|
DEFINE_SWIZZLER3_COMP1(z, b);
|
||||||
|
DEFINE_SWIZZLER3_COMP1(w, a);
|
||||||
|
#undef DEFINE_SWIZZLER3_COMP1
|
||||||
|
#undef DEFINE_SWIZZLER3_COMP3
|
||||||
|
#undef _DEFINE_SWIZZLER3
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T, typename V>
|
||||||
|
[[nodiscard]] constexpr Vec4<decltype(V{} * T{})> operator*(const V& f, const Vec4<T>& vec) {
|
||||||
|
using TV = decltype(V{} * T{});
|
||||||
|
using C = std::common_type_t<T, V>;
|
||||||
|
|
||||||
|
return {
|
||||||
|
static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.x)),
|
||||||
|
static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.y)),
|
||||||
|
static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.z)),
|
||||||
|
static_cast<TV>(static_cast<C>(f) * static_cast<C>(vec.w)),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
using Vec4f = Vec4<float>;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec2<T>& a, const Vec2<T>& b) {
|
||||||
|
return a.x * b.x + a.y * b.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec3<T>& a, const Vec3<T>& b) {
|
||||||
|
return a.x * b.x + a.y * b.y + a.z * b.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] constexpr decltype(T{} * T{} + T{} * T{}) Dot(const Vec4<T>& a, const Vec4<T>& b) {
|
||||||
|
return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <>
|
||||||
|
[[nodiscard]] inline float Dot(const Vec4<float>& a, const Vec4<float>& b) {
|
||||||
|
#ifdef __ARM_NEON
|
||||||
|
float32x4_t va = vld1q_f32(&a.x);
|
||||||
|
float32x4_t vb = vld1q_f32(&b.x);
|
||||||
|
float32x4_t result = vmulq_f32(va, vb);
|
||||||
|
#if defined(__aarch64__) // Use vaddvq_f32 in ARMv8 architectures
|
||||||
|
return vaddvq_f32(result);
|
||||||
|
#else // Use manual addition for older architectures
|
||||||
|
float32x2_t sum2 = vadd_f32(vget_high_f32(result), vget_low_f32(result));
|
||||||
|
return vget_lane_f32(vpadd_f32(sum2, sum2), 0);
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] constexpr Vec3<decltype(T{} * T{} - T{} * T{})> Cross(const Vec3<T>& a,
|
||||||
|
const Vec3<T>& b) {
|
||||||
|
return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x};
|
||||||
|
}
|
||||||
|
|
||||||
|
// linear interpolation via float: 0.0=begin, 1.0=end
|
||||||
|
template <typename X>
|
||||||
|
[[nodiscard]] constexpr decltype(X{} * float{} + X{} * float{}) Lerp(const X& begin, const X& end,
|
||||||
|
const float t) {
|
||||||
|
return begin * (1.f - t) + end * t;
|
||||||
|
}
|
||||||
|
|
||||||
|
// linear interpolation via int: 0=begin, base=end
|
||||||
|
template <typename X, int base>
|
||||||
|
[[nodiscard]] constexpr decltype((X{} * int{} + X{} * int{}) / base) LerpInt(const X& begin,
|
||||||
|
const X& end,
|
||||||
|
const int t) {
|
||||||
|
return (begin * (base - t) + end * t) / base;
|
||||||
|
}
|
||||||
|
|
||||||
|
// bilinear interpolation. s is for interpolating x00-x01 and x10-x11, and t is for the second
|
||||||
|
// interpolation.
|
||||||
|
template <typename X>
|
||||||
|
[[nodiscard]] constexpr auto BilinearInterp(const X& x00, const X& x01, const X& x10, const X& x11,
|
||||||
|
const float s, const float t) {
|
||||||
|
auto y0 = Lerp(x00, x01, s);
|
||||||
|
auto y1 = Lerp(x10, x11, s);
|
||||||
|
return Lerp(y0, y1, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Utility vector factories
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] constexpr Vec2<T> MakeVec(const T& x, const T& y) {
|
||||||
|
return Vec2<T>{x, y};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] constexpr Vec3<T> MakeVec(const T& x, const T& y, const T& z) {
|
||||||
|
return Vec3<T>{x, y, z};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] constexpr Vec4<T> MakeVec(const T& x, const T& y, const Vec2<T>& zw) {
|
||||||
|
return MakeVec(x, y, zw[0], zw[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] constexpr Vec3<T> MakeVec(const Vec2<T>& xy, const T& z) {
|
||||||
|
return MakeVec(xy[0], xy[1], z);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] constexpr Vec3<T> MakeVec(const T& x, const Vec2<T>& yz) {
|
||||||
|
return MakeVec(x, yz[0], yz[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] constexpr Vec4<T> MakeVec(const T& x, const T& y, const T& z, const T& w) {
|
||||||
|
return Vec4<T>{x, y, z, w};
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] constexpr Vec4<T> MakeVec(const Vec2<T>& xy, const T& z, const T& w) {
|
||||||
|
return MakeVec(xy[0], xy[1], z, w);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] constexpr Vec4<T> MakeVec(const T& x, const Vec2<T>& yz, const T& w) {
|
||||||
|
return MakeVec(x, yz[0], yz[1], w);
|
||||||
|
}
|
||||||
|
|
||||||
|
// NOTE: This has priority over "Vec2<Vec2<T>> MakeVec(const Vec2<T>& x, const Vec2<T>& y)".
|
||||||
|
// Even if someone wanted to use an odd object like Vec2<Vec2<T>>, the compiler would error
|
||||||
|
// out soon enough due to misuse of the returned structure.
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] constexpr Vec4<T> MakeVec(const Vec2<T>& xy, const Vec2<T>& zw) {
|
||||||
|
return MakeVec(xy[0], xy[1], zw[0], zw[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] constexpr Vec4<T> MakeVec(const Vec3<T>& xyz, const T& w) {
|
||||||
|
return MakeVec(xyz[0], xyz[1], xyz[2], w);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[nodiscard]] constexpr Vec4<T> MakeVec(const T& x, const Vec3<T>& yzw) {
|
||||||
|
return MakeVec(x, yzw[0], yzw[1], yzw[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Common
|
} // namespace Common
|
||||||
|
|||||||
@@ -6,13 +6,13 @@
|
|||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#include <boost/asio.hpp>
|
#include <boost/asio.hpp>
|
||||||
#include <boost/version.hpp>
|
#include <boost/version.hpp>
|
||||||
|
|
||||||
#if BOOST_VERSION > 108400 && (!defined(_WINDOWS) && !defined(__ANDROID__)) || defined(YUZU_BOOST_v1)
|
#if BOOST_VERSION > 108400 && (!defined(_WINDOWS) && !defined(__ANDROID__)) || defined(YUZU_BOOST_v1)
|
||||||
#define USE_BOOST_v1
|
#define USE_BOOST_v1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_BOOST_v1
|
#ifdef USE_BOOST_v1
|
||||||
#include <boost/process/v1/async_pipe.hpp>
|
#include <boost/process/v1/async_pipe.hpp>
|
||||||
#else
|
#else
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
#include "common/common_funcs.h"
|
#include "common/common_funcs.h"
|
||||||
|
|
||||||
namespace FileSys {
|
namespace FileSys {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#include "common/literals.h"
|
#include "common/literals.h"
|
||||||
#include "core/file_sys/fssystem/fs_i_storage.h"
|
#include "core/file_sys/fssystem/fs_i_storage.h"
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
#include "core/file_sys/errors.h"
|
#include "core/file_sys/errors.h"
|
||||||
#include "core/file_sys/fssystem/fssystem_bucket_tree.h"
|
#include "core/file_sys/fssystem/fssystem_bucket_tree.h"
|
||||||
#include "core/file_sys/fssystem/fssystem_bucket_tree_utils.h"
|
#include "core/file_sys/fssystem/fssystem_bucket_tree_utils.h"
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#include "common/alignment.h"
|
#include "common/alignment.h"
|
||||||
#include "common/common_funcs.h"
|
#include "common/common_funcs.h"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
#include "core/file_sys/errors.h"
|
#include "core/file_sys/errors.h"
|
||||||
#include "core/file_sys/fssystem/fssystem_bucket_tree.h"
|
#include "core/file_sys/fssystem/fssystem_bucket_tree.h"
|
||||||
#include "core/file_sys/fssystem/fssystem_bucket_tree_utils.h"
|
#include "core/file_sys/fssystem/fssystem_bucket_tree_utils.h"
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
#include <cstddef>
|
||||||
#include "common/literals.h"
|
#include "common/literals.h"
|
||||||
|
|
||||||
#include "core/file_sys/errors.h"
|
#include "core/file_sys/errors.h"
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
#include "common/alignment.h"
|
#include "common/alignment.h"
|
||||||
#include "core/file_sys/fssystem/fs_i_storage.h"
|
#include "core/file_sys/fssystem/fs_i_storage.h"
|
||||||
#include "core/file_sys/fssystem/fs_types.h"
|
#include "core/file_sys/fssystem/fs_types.h"
|
||||||
|
|||||||
@@ -6,6 +6,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
#include <array>
|
||||||
|
#include <cstddef>
|
||||||
#include "core/file_sys/errors.h"
|
#include "core/file_sys/errors.h"
|
||||||
#include "core/file_sys/fssystem/fs_i_storage.h"
|
#include "core/file_sys/fssystem/fs_i_storage.h"
|
||||||
#include "core/file_sys/fssystem/fssystem_bucket_tree.h"
|
#include "core/file_sys/fssystem/fssystem_bucket_tree.h"
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <array>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#include "core/file_sys/fssystem/fs_i_storage.h"
|
#include "core/file_sys/fssystem/fs_i_storage.h"
|
||||||
#include "core/file_sys/fssystem/fs_types.h"
|
#include "core/file_sys/fssystem/fs_types.h"
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
#include <cstddef>
|
||||||
#include "core/file_sys/fssystem/fssystem_compression_common.h"
|
#include "core/file_sys/fssystem/fssystem_compression_common.h"
|
||||||
#include "core/file_sys/fssystem/fssystem_nca_header.h"
|
#include "core/file_sys/fssystem/fssystem_nca_header.h"
|
||||||
#include "core/file_sys/vfs/vfs.h"
|
#include "core/file_sys/vfs/vfs.h"
|
||||||
|
|||||||
@@ -1,8 +1,14 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
#include <array>
|
||||||
|
#include <cstddef>
|
||||||
#include "common/common_funcs.h"
|
#include "common/common_funcs.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/literals.h"
|
#include "common/literals.h"
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#include "common/common_funcs.h"
|
#include "common/common_funcs.h"
|
||||||
#include "common/page_table.h"
|
#include "common/page_table.h"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/bit_field.h"
|
#include "common/bit_field.h"
|
||||||
#include "common/common_funcs.h"
|
#include "common/common_funcs.h"
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <type_traits>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include "common/common_funcs.h"
|
#include "common/common_funcs.h"
|
||||||
|
|||||||
@@ -175,19 +175,10 @@ Result AlbumManager::LoadAlbumScreenShotImage(LoadAlbumScreenShotImageOutput& ou
|
|||||||
return ResultIsNotMounted;
|
return ResultIsNotMounted;
|
||||||
}
|
}
|
||||||
|
|
||||||
out_image_output = {
|
out_image_output = {};
|
||||||
.width = 1280,
|
out_image_output.width = 1280;
|
||||||
.height = 720,
|
out_image_output.height = 720;
|
||||||
.attribute =
|
out_image_output.attribute.orientation = AlbumImageOrientation::None;
|
||||||
{
|
|
||||||
.unknown_0{},
|
|
||||||
.orientation = AlbumImageOrientation::None,
|
|
||||||
.unknown_1{},
|
|
||||||
.unknown_2{},
|
|
||||||
.pad163{},
|
|
||||||
},
|
|
||||||
.pad179{},
|
|
||||||
};
|
|
||||||
|
|
||||||
std::filesystem::path path;
|
std::filesystem::path path;
|
||||||
const auto result = GetFile(path, file_id);
|
const auto result = GetFile(path, file_id);
|
||||||
@@ -211,19 +202,10 @@ Result AlbumManager::LoadAlbumScreenShotThumbnail(
|
|||||||
return ResultIsNotMounted;
|
return ResultIsNotMounted;
|
||||||
}
|
}
|
||||||
|
|
||||||
out_image_output = {
|
out_image_output = {};
|
||||||
.width = 320,
|
out_image_output.width = 320;
|
||||||
.height = 180,
|
out_image_output.height = 180;
|
||||||
.attribute =
|
out_image_output.attribute.orientation = AlbumImageOrientation::None;
|
||||||
{
|
|
||||||
.unknown_0{},
|
|
||||||
.orientation = AlbumImageOrientation::None,
|
|
||||||
.unknown_1{},
|
|
||||||
.unknown_2{},
|
|
||||||
.pad163{},
|
|
||||||
},
|
|
||||||
.pad179{},
|
|
||||||
};
|
|
||||||
|
|
||||||
std::filesystem::path path;
|
std::filesystem::path path;
|
||||||
const auto result = GetFile(path, file_id);
|
const auto result = GetFile(path, file_id);
|
||||||
|
|||||||
@@ -73,13 +73,8 @@ void IScreenShotApplicationService::CaptureAndSaveScreenshot(AlbumReportOption r
|
|||||||
Layout::FramebufferLayout layout =
|
Layout::FramebufferLayout layout =
|
||||||
Layout::DefaultFrameLayout(screenshot_width, screenshot_height);
|
Layout::DefaultFrameLayout(screenshot_width, screenshot_height);
|
||||||
|
|
||||||
const Capture::ScreenShotAttribute attribute{
|
Capture::ScreenShotAttribute attribute{};
|
||||||
.unknown_0{},
|
attribute.orientation = Capture::AlbumImageOrientation::None;
|
||||||
.orientation = Capture::AlbumImageOrientation::None,
|
|
||||||
.unknown_1{},
|
|
||||||
.unknown_2{},
|
|
||||||
.pad163{},
|
|
||||||
};
|
|
||||||
|
|
||||||
renderer.RequestScreenshot(
|
renderer.RequestScreenshot(
|
||||||
image_data.data(),
|
image_data.data(),
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
#include "common/common_funcs.h"
|
#include "common/common_funcs.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
|
||||||
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
#include <fmt/ranges.h>
|
#include <fmt/ranges.h>
|
||||||
|
|
||||||
#include "common/common_funcs.h"
|
#include "common/common_funcs.h"
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <type_traits>
|
||||||
#include <fmt/ranges.h>
|
#include <fmt/ranges.h>
|
||||||
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <type_traits>
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "core/hle/service/psc/time/common.h"
|
#include "core/hle/service/psc/time/common.h"
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
@@ -33,15 +30,15 @@ struct DeviceSettings {
|
|||||||
INSERT_PADDING_BYTES(0x20); // Reserved
|
INSERT_PADDING_BYTES(0x20); // Reserved
|
||||||
|
|
||||||
// nn::settings::system::ConsoleSixAxisSensorAccelerationBias
|
// nn::settings::system::ConsoleSixAxisSensorAccelerationBias
|
||||||
Common::Vec<f32, 3> console_six_axis_sensor_acceleration_bias;
|
Common::Vec3<f32> console_six_axis_sensor_acceleration_bias;
|
||||||
// nn::settings::system::ConsoleSixAxisSensorAngularVelocityBias
|
// nn::settings::system::ConsoleSixAxisSensorAngularVelocityBias
|
||||||
Common::Vec<f32, 3> console_six_axis_sensor_angular_velocity_bias;
|
Common::Vec3<f32> console_six_axis_sensor_angular_velocity_bias;
|
||||||
// nn::settings::system::ConsoleSixAxisSensorAccelerationGain
|
// nn::settings::system::ConsoleSixAxisSensorAccelerationGain
|
||||||
std::array<u8, 0x24> console_six_axis_sensor_acceleration_gain;
|
std::array<u8, 0x24> console_six_axis_sensor_acceleration_gain;
|
||||||
// nn::settings::system::ConsoleSixAxisSensorAngularVelocityGain
|
// nn::settings::system::ConsoleSixAxisSensorAngularVelocityGain
|
||||||
std::array<u8, 0x24> console_six_axis_sensor_angular_velocity_gain;
|
std::array<u8, 0x24> console_six_axis_sensor_angular_velocity_gain;
|
||||||
// nn::settings::system::ConsoleSixAxisSensorAngularVelocityTimeBias
|
// nn::settings::system::ConsoleSixAxisSensorAngularVelocityTimeBias
|
||||||
Common::Vec<f32, 3> console_six_axis_sensor_angular_velocity_time_bias;
|
Common::Vec3<f32> console_six_axis_sensor_angular_velocity_time_bias;
|
||||||
// nn::settings::system::ConsoleSixAxisSensorAngularAcceleration
|
// nn::settings::system::ConsoleSixAxisSensorAngularAcceleration
|
||||||
std::array<u8, 0x24> console_six_axis_sensor_angular_acceleration;
|
std::array<u8, 0x24> console_six_axis_sensor_angular_acceleration;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
||||||
@@ -153,15 +153,15 @@ struct SystemSettings {
|
|||||||
INSERT_PADDING_BYTES(0x7FF8); // Reserved
|
INSERT_PADDING_BYTES(0x7FF8); // Reserved
|
||||||
|
|
||||||
// nn::settings::system::ConsoleSixAxisSensorAccelerationBias
|
// nn::settings::system::ConsoleSixAxisSensorAccelerationBias
|
||||||
Common::Vec<f32, 3> console_six_axis_sensor_acceleration_bias;
|
Common::Vec3<f32> console_six_axis_sensor_acceleration_bias;
|
||||||
// nn::settings::system::ConsoleSixAxisSensorAngularVelocityBias
|
// nn::settings::system::ConsoleSixAxisSensorAngularVelocityBias
|
||||||
Common::Vec<f32, 3> console_six_axis_sensor_angular_velocity_bias;
|
Common::Vec3<f32> console_six_axis_sensor_angular_velocity_bias;
|
||||||
// nn::settings::system::ConsoleSixAxisSensorAccelerationGain
|
// nn::settings::system::ConsoleSixAxisSensorAccelerationGain
|
||||||
std::array<u8, 0x24> console_six_axis_sensor_acceleration_gain;
|
std::array<u8, 0x24> console_six_axis_sensor_acceleration_gain;
|
||||||
// nn::settings::system::ConsoleSixAxisSensorAngularVelocityGain
|
// nn::settings::system::ConsoleSixAxisSensorAngularVelocityGain
|
||||||
std::array<u8, 0x24> console_six_axis_sensor_angular_velocity_gain;
|
std::array<u8, 0x24> console_six_axis_sensor_angular_velocity_gain;
|
||||||
// nn::settings::system::ConsoleSixAxisSensorAngularVelocityTimeBias
|
// nn::settings::system::ConsoleSixAxisSensorAngularVelocityTimeBias
|
||||||
Common::Vec<f32, 3> console_six_axis_sensor_angular_velocity_time_bias;
|
Common::Vec3<f32> console_six_axis_sensor_angular_velocity_time_bias;
|
||||||
// nn::settings::system::ConsoleSixAxisSensorAngularAcceleration
|
// nn::settings::system::ConsoleSixAxisSensorAngularAcceleration
|
||||||
std::array<u8, 0x24> console_six_axis_sensor_angular_velocity_acceleration;
|
std::array<u8, 0x24> console_six_axis_sensor_angular_velocity_acceleration;
|
||||||
INSERT_PADDING_BYTES(0x70); // Reserved
|
INSERT_PADDING_BYTES(0x70); // Reserved
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#include "common/bit_field.h"
|
#include "common/bit_field.h"
|
||||||
#include "common/common_funcs.h"
|
#include "common/common_funcs.h"
|
||||||
|
|||||||
@@ -170,12 +170,12 @@ void EmulatedConsole::SetMotion(const Common::Input::CallbackStatus& callback) {
|
|||||||
auto& emulated = console.motion_values.emulated;
|
auto& emulated = console.motion_values.emulated;
|
||||||
|
|
||||||
raw_status = TransformToMotion(callback);
|
raw_status = TransformToMotion(callback);
|
||||||
emulated.SetAcceleration(Common::Vec<f32, 3>{
|
emulated.SetAcceleration(Common::Vec3f{
|
||||||
raw_status.accel.x.value,
|
raw_status.accel.x.value,
|
||||||
raw_status.accel.y.value,
|
raw_status.accel.y.value,
|
||||||
raw_status.accel.z.value,
|
raw_status.accel.z.value,
|
||||||
});
|
});
|
||||||
emulated.SetGyroscope(Common::Vec<f32, 3>{
|
emulated.SetGyroscope(Common::Vec3f{
|
||||||
raw_status.gyro.x.value,
|
raw_status.gyro.x.value,
|
||||||
raw_status.gyro.y.value,
|
raw_status.gyro.y.value,
|
||||||
raw_status.gyro.z.value,
|
raw_status.gyro.z.value,
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
#include "common/input.h"
|
#include "common/input.h"
|
||||||
#include "common/param_package.h"
|
#include "common/param_package.h"
|
||||||
#include "common/point.h"
|
#include "common/point.h"
|
||||||
|
#include "common/quaternion.h"
|
||||||
#include "common/vector_math.h"
|
#include "common/vector_math.h"
|
||||||
#include "hid_core/frontend/motion_input.h"
|
#include "hid_core/frontend/motion_input.h"
|
||||||
#include "hid_core/hid_types.h"
|
#include "hid_core/hid_types.h"
|
||||||
@@ -42,12 +43,12 @@ using TouchValues = std::array<Common::Input::TouchStatus, MaxTouchDevices>;
|
|||||||
|
|
||||||
// Contains all motion related data that is used on the services
|
// Contains all motion related data that is used on the services
|
||||||
struct ConsoleMotion {
|
struct ConsoleMotion {
|
||||||
Common::Vec<f32, 3> accel{};
|
Common::Vec3f accel{};
|
||||||
Common::Vec<f32, 3> gyro{};
|
Common::Vec3f gyro{};
|
||||||
Common::Vec<f32, 3> rotation{};
|
Common::Vec3f rotation{};
|
||||||
std::array<Common::Vec<f32, 3>, 3> orientation{};
|
std::array<Common::Vec3f, 3> orientation{};
|
||||||
Common::Vec<f32, 4> quaternion{};
|
Common::Quaternion<f32> quaternion{};
|
||||||
Common::Vec<f32, 3> gyro_bias{};
|
Common::Vec3f gyro_bias{};
|
||||||
f32 verticalization_error{};
|
f32 verticalization_error{};
|
||||||
bool is_at_rest{};
|
bool is_at_rest{};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1051,12 +1051,12 @@ void EmulatedController::SetMotion(const Common::Input::CallbackStatus& callback
|
|||||||
auto& emulated = controller.motion_values[index].emulated;
|
auto& emulated = controller.motion_values[index].emulated;
|
||||||
|
|
||||||
raw_status = TransformToMotion(callback);
|
raw_status = TransformToMotion(callback);
|
||||||
emulated.SetAcceleration(Common::Vec<f32, 3>{
|
emulated.SetAcceleration(Common::Vec3f{
|
||||||
raw_status.accel.x.value,
|
raw_status.accel.x.value,
|
||||||
raw_status.accel.y.value,
|
raw_status.accel.y.value,
|
||||||
raw_status.accel.z.value,
|
raw_status.accel.z.value,
|
||||||
});
|
});
|
||||||
emulated.SetGyroscope(Common::Vec<f32, 3>{
|
emulated.SetGyroscope(Common::Vec3f{
|
||||||
raw_status.gyro.x.value,
|
raw_status.gyro.x.value,
|
||||||
raw_status.gyro.y.value,
|
raw_status.gyro.y.value,
|
||||||
raw_status.gyro.z.value,
|
raw_status.gyro.z.value,
|
||||||
|
|||||||
@@ -107,11 +107,11 @@ struct RingSensorForce {
|
|||||||
using NfcState = Common::Input::NfcStatus;
|
using NfcState = Common::Input::NfcStatus;
|
||||||
|
|
||||||
struct ControllerMotion {
|
struct ControllerMotion {
|
||||||
Common::Vec<f32, 3> accel{};
|
Common::Vec3f accel{};
|
||||||
Common::Vec<f32, 3> gyro{};
|
Common::Vec3f gyro{};
|
||||||
Common::Vec<f32, 3> rotation{};
|
Common::Vec3f rotation{};
|
||||||
Common::Vec<f32, 3> euler{};
|
Common::Vec3f euler{};
|
||||||
std::array<Common::Vec<f32, 3>, 3> orientation{};
|
std::array<Common::Vec3f, 3> orientation{};
|
||||||
bool is_at_rest{};
|
bool is_at_rest{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -26,19 +26,20 @@ void MotionInput::SetPID(f32 new_kp, f32 new_ki, f32 new_kd) {
|
|||||||
kd = new_kd;
|
kd = new_kd;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MotionInput::SetAcceleration(const Common::Vec<f32, 3>& acceleration) {
|
void MotionInput::SetAcceleration(const Common::Vec3f& acceleration) {
|
||||||
accel = acceleration;
|
accel = acceleration;
|
||||||
accel[0] = std::clamp(accel[0], -AccelMaxValue, AccelMaxValue);
|
|
||||||
accel[1] = std::clamp(accel[1], -AccelMaxValue, AccelMaxValue);
|
accel.x = std::clamp(accel.x, -AccelMaxValue, AccelMaxValue);
|
||||||
accel[2] = std::clamp(accel[2], -AccelMaxValue, AccelMaxValue);
|
accel.y = std::clamp(accel.y, -AccelMaxValue, AccelMaxValue);
|
||||||
|
accel.z = std::clamp(accel.z, -AccelMaxValue, AccelMaxValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MotionInput::SetGyroscope(const Common::Vec<f32, 3>& gyroscope) {
|
void MotionInput::SetGyroscope(const Common::Vec3f& gyroscope) {
|
||||||
gyro = gyroscope - gyro_bias;
|
gyro = gyroscope - gyro_bias;
|
||||||
|
|
||||||
gyro[0] = std::clamp(gyro[0], -GyroMaxValue, GyroMaxValue);
|
gyro.x = std::clamp(gyro.x, -GyroMaxValue, GyroMaxValue);
|
||||||
gyro[1] = std::clamp(gyro[1], -GyroMaxValue, GyroMaxValue);
|
gyro.y = std::clamp(gyro.y, -GyroMaxValue, GyroMaxValue);
|
||||||
gyro[2] = std::clamp(gyro[2], -GyroMaxValue, GyroMaxValue);
|
gyro.z = std::clamp(gyro.z, -GyroMaxValue, GyroMaxValue);
|
||||||
|
|
||||||
// Auto adjust gyro_bias to minimize drift
|
// Auto adjust gyro_bias to minimize drift
|
||||||
if (!IsMoving(IsAtRestRelaxed)) {
|
if (!IsMoving(IsAtRestRelaxed)) {
|
||||||
@@ -58,25 +59,25 @@ void MotionInput::SetGyroscope(const Common::Vec<f32, 3>& gyroscope) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MotionInput::SetQuaternion(const Common::Vec<f32, 4>& quaternion) {
|
void MotionInput::SetQuaternion(const Common::Quaternion<f32>& quaternion) {
|
||||||
quat = quaternion;
|
quat = quaternion;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MotionInput::SetEulerAngles(const Common::Vec<f32, 3>& euler_angles) {
|
void MotionInput::SetEulerAngles(const Common::Vec3f& euler_angles) {
|
||||||
const float cr = std::cos(euler_angles[0] * 0.5f);
|
const float cr = std::cos(euler_angles.x * 0.5f);
|
||||||
const float sr = std::sin(euler_angles[0] * 0.5f);
|
const float sr = std::sin(euler_angles.x * 0.5f);
|
||||||
const float cp = std::cos(euler_angles[1] * 0.5f);
|
const float cp = std::cos(euler_angles.y * 0.5f);
|
||||||
const float sp = std::sin(euler_angles[1] * 0.5f);
|
const float sp = std::sin(euler_angles.y * 0.5f);
|
||||||
const float cy = std::cos(euler_angles[2] * 0.5f);
|
const float cy = std::cos(euler_angles.z * 0.5f);
|
||||||
const float sy = std::sin(euler_angles[2] * 0.5f);
|
const float sy = std::sin(euler_angles.z * 0.5f);
|
||||||
|
|
||||||
quat[3] = cr * cp * cy + sr * sp * sy;
|
quat.w = cr * cp * cy + sr * sp * sy;
|
||||||
quat[0] = sr * cp * cy - cr * sp * sy;
|
quat.xyz.x = sr * cp * cy - cr * sp * sy;
|
||||||
quat[1] = cr * sp * cy + sr * cp * sy;
|
quat.xyz.y = cr * sp * cy + sr * cp * sy;
|
||||||
quat[2] = cr * cp * sy - sr * sp * cy;
|
quat.xyz.z = cr * cp * sy - sr * sp * cy;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MotionInput::SetGyroBias(const Common::Vec<f32, 3>& bias) {
|
void MotionInput::SetGyroBias(const Common::Vec3f& bias) {
|
||||||
gyro_bias = bias;
|
gyro_bias = bias;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +98,7 @@ void MotionInput::ResetRotations() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MotionInput::ResetQuaternion() {
|
void MotionInput::ResetQuaternion() {
|
||||||
quat = Common::Vec<f32, 4>{0.0f, 0.0f, -1.0f, 0.0f};
|
quat = {{0.0f, 0.0f, -1.0f}, 0.0f};
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MotionInput::IsMoving(f32 sensitivity) const {
|
bool MotionInput::IsMoving(f32 sensitivity) const {
|
||||||
@@ -136,10 +137,10 @@ void MotionInput::UpdateOrientation(u64 elapsed_time) {
|
|||||||
ResetOrientation();
|
ResetOrientation();
|
||||||
}
|
}
|
||||||
// Short name local variable for readability
|
// Short name local variable for readability
|
||||||
f32 q1 = quat[3];
|
f32 q1 = quat.w;
|
||||||
f32 q2 = quat[0];
|
f32 q2 = quat.xyz[0];
|
||||||
f32 q3 = quat[1];
|
f32 q3 = quat.xyz[1];
|
||||||
f32 q4 = quat[2];
|
f32 q4 = quat.xyz[2];
|
||||||
const auto sample_period = static_cast<f32>(elapsed_time) / 1000000.0f;
|
const auto sample_period = static_cast<f32>(elapsed_time) / 1000000.0f;
|
||||||
|
|
||||||
// Ignore invalid elapsed time
|
// Ignore invalid elapsed time
|
||||||
@@ -149,23 +150,23 @@ void MotionInput::UpdateOrientation(u64 elapsed_time) {
|
|||||||
|
|
||||||
const auto normal_accel = accel.Normalized();
|
const auto normal_accel = accel.Normalized();
|
||||||
auto rad_gyro = gyro * std::numbers::pi_v<float> * 2.f;
|
auto rad_gyro = gyro * std::numbers::pi_v<float> * 2.f;
|
||||||
const f32 swap = rad_gyro[0];
|
const f32 swap = rad_gyro.x;
|
||||||
rad_gyro[0] = rad_gyro[1];
|
rad_gyro.x = rad_gyro.y;
|
||||||
rad_gyro[1] = -swap;
|
rad_gyro.y = -swap;
|
||||||
rad_gyro[2] = -rad_gyro[2];
|
rad_gyro.z = -rad_gyro.z;
|
||||||
|
|
||||||
// Clear gyro values if there is no gyro present
|
// Clear gyro values if there is no gyro present
|
||||||
if (only_accelerometer) {
|
if (only_accelerometer) {
|
||||||
rad_gyro[0] = 0;
|
rad_gyro.x = 0;
|
||||||
rad_gyro[1] = 0;
|
rad_gyro.y = 0;
|
||||||
rad_gyro[2] = 0;
|
rad_gyro.z = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore drift correction if acceleration is not reliable
|
// Ignore drift correction if acceleration is not reliable
|
||||||
if (accel.Length() >= 0.75f && accel.Length() <= 1.25f) {
|
if (accel.Length() >= 0.75f && accel.Length() <= 1.25f) {
|
||||||
const f32 ax = -normal_accel[0];
|
const f32 ax = -normal_accel.x;
|
||||||
const f32 ay = normal_accel[1];
|
const f32 ay = normal_accel.y;
|
||||||
const f32 az = -normal_accel[2];
|
const f32 az = -normal_accel.z;
|
||||||
|
|
||||||
// Estimated direction of gravity
|
// Estimated direction of gravity
|
||||||
const f32 vx = 2.0f * (q2 * q4 - q1 * q3);
|
const f32 vx = 2.0f * (q2 * q4 - q1 * q3);
|
||||||
@@ -173,7 +174,7 @@ void MotionInput::UpdateOrientation(u64 elapsed_time) {
|
|||||||
const f32 vz = q1 * q1 - q2 * q2 - q3 * q3 + q4 * q4;
|
const f32 vz = q1 * q1 - q2 * q2 - q3 * q3 + q4 * q4;
|
||||||
|
|
||||||
// Error is cross product between estimated direction and measured direction of gravity
|
// Error is cross product between estimated direction and measured direction of gravity
|
||||||
const Common::Vec<f32, 3> new_real_error{
|
const Common::Vec3f new_real_error = {
|
||||||
az * vx - ax * vz,
|
az * vx - ax * vz,
|
||||||
ay * vz - az * vy,
|
ay * vz - az * vy,
|
||||||
ax * vy - ay * vx,
|
ax * vy - ay * vx,
|
||||||
@@ -201,16 +202,16 @@ void MotionInput::UpdateOrientation(u64 elapsed_time) {
|
|||||||
rad_gyro += 10.0f * kd * derivative_error;
|
rad_gyro += 10.0f * kd * derivative_error;
|
||||||
|
|
||||||
// Emulate gyro values for games that need them
|
// Emulate gyro values for games that need them
|
||||||
gyro[0] = -rad_gyro[1];
|
gyro.x = -rad_gyro.y;
|
||||||
gyro[1] = rad_gyro[0];
|
gyro.y = rad_gyro.x;
|
||||||
gyro[2] = -rad_gyro[2];
|
gyro.z = -rad_gyro.z;
|
||||||
UpdateRotation(elapsed_time);
|
UpdateRotation(elapsed_time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const f32 gx = rad_gyro[1];
|
const f32 gx = rad_gyro.y;
|
||||||
const f32 gy = rad_gyro[0];
|
const f32 gy = rad_gyro.x;
|
||||||
const f32 gz = rad_gyro[2];
|
const f32 gz = rad_gyro.z;
|
||||||
|
|
||||||
// Integrate rate of change of quaternion
|
// Integrate rate of change of quaternion
|
||||||
const f32 pa = q2;
|
const f32 pa = q2;
|
||||||
@@ -221,58 +222,57 @@ void MotionInput::UpdateOrientation(u64 elapsed_time) {
|
|||||||
q3 = pb + (q1 * gy - pa * gz + pc * gx) * (0.5f * sample_period);
|
q3 = pb + (q1 * gy - pa * gz + pc * gx) * (0.5f * sample_period);
|
||||||
q4 = pc + (q1 * gz + pa * gy - pb * gx) * (0.5f * sample_period);
|
q4 = pc + (q1 * gz + pa * gy - pb * gx) * (0.5f * sample_period);
|
||||||
|
|
||||||
quat[3] = q1;
|
quat.w = q1;
|
||||||
quat[0] = q2;
|
quat.xyz[0] = q2;
|
||||||
quat[1] = q3;
|
quat.xyz[1] = q3;
|
||||||
quat[2] = q4;
|
quat.xyz[2] = q4;
|
||||||
quat = quat.Normalized();
|
quat = quat.Normalized();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<Common::Vec<f32, 3>, 3> MotionInput::GetOrientation() const {
|
std::array<Common::Vec3f, 3> MotionInput::GetOrientation() const {
|
||||||
const Common::Vec<f32, 4> quad{
|
const Common::Quaternion<float> quad{
|
||||||
-quat[1],
|
.xyz = {-quat.xyz[1], -quat.xyz[0], -quat.w},
|
||||||
-quat[0],
|
.w = -quat.xyz[2],
|
||||||
-quat[3],
|
|
||||||
-quat[2],
|
|
||||||
};
|
};
|
||||||
const std::array<f32, 16> matrix4x4 = quad.ToMatrix();
|
const std::array<float, 16> matrix4x4 = quad.ToMatrix();
|
||||||
return {Common::Vec<f32, 3>(matrix4x4[0], matrix4x4[1], -matrix4x4[2]),
|
|
||||||
Common::Vec<f32, 3>(matrix4x4[4], matrix4x4[5], -matrix4x4[6]),
|
return {Common::Vec3f(matrix4x4[0], matrix4x4[1], -matrix4x4[2]),
|
||||||
Common::Vec<f32, 3>(-matrix4x4[8], -matrix4x4[9], matrix4x4[10])};
|
Common::Vec3f(matrix4x4[4], matrix4x4[5], -matrix4x4[6]),
|
||||||
|
Common::Vec3f(-matrix4x4[8], -matrix4x4[9], matrix4x4[10])};
|
||||||
}
|
}
|
||||||
|
|
||||||
Common::Vec<f32, 3> MotionInput::GetAcceleration() const {
|
Common::Vec3f MotionInput::GetAcceleration() const {
|
||||||
return accel;
|
return accel;
|
||||||
}
|
}
|
||||||
|
|
||||||
Common::Vec<f32, 3> MotionInput::GetGyroscope() const {
|
Common::Vec3f MotionInput::GetGyroscope() const {
|
||||||
return gyro;
|
return gyro;
|
||||||
}
|
}
|
||||||
|
|
||||||
Common::Vec<f32, 3> MotionInput::GetGyroBias() const {
|
Common::Vec3f MotionInput::GetGyroBias() const {
|
||||||
return gyro_bias;
|
return gyro_bias;
|
||||||
}
|
}
|
||||||
|
|
||||||
Common::Vec<f32, 4> MotionInput::GetQuaternion() const {
|
Common::Quaternion<f32> MotionInput::GetQuaternion() const {
|
||||||
return quat;
|
return quat;
|
||||||
}
|
}
|
||||||
|
|
||||||
Common::Vec<f32, 3> MotionInput::GetRotations() const {
|
Common::Vec3f MotionInput::GetRotations() const {
|
||||||
return rotations;
|
return rotations;
|
||||||
}
|
}
|
||||||
|
|
||||||
Common::Vec<f32, 3> MotionInput::GetEulerAngles() const {
|
Common::Vec3f MotionInput::GetEulerAngles() const {
|
||||||
// roll (x-axis rotation)
|
// roll (x-axis rotation)
|
||||||
const float sinr_cosp = 2 * (quat[3] * quat[0] + quat[1] * quat[2]);
|
const float sinr_cosp = 2 * (quat.w * quat.xyz.x + quat.xyz.y * quat.xyz.z);
|
||||||
const float cosr_cosp = 1 - 2 * (quat[0] * quat[0] + quat[1] * quat[1]);
|
const float cosr_cosp = 1 - 2 * (quat.xyz.x * quat.xyz.x + quat.xyz.y * quat.xyz.y);
|
||||||
|
|
||||||
// pitch (y-axis rotation)
|
// pitch (y-axis rotation)
|
||||||
const float sinp = std::sqrt(1 + 2 * (quat[3] * quat[1] - quat[0] * quat[2]));
|
const float sinp = std::sqrt(1 + 2 * (quat.w * quat.xyz.y - quat.xyz.x * quat.xyz.z));
|
||||||
const float cosp = std::sqrt(1 - 2 * (quat[3] * quat[1] - quat[0] * quat[2]));
|
const float cosp = std::sqrt(1 - 2 * (quat.w * quat.xyz.y - quat.xyz.x * quat.xyz.z));
|
||||||
|
|
||||||
// yaw (z-axis rotation)
|
// yaw (z-axis rotation)
|
||||||
const float siny_cosp = 2 * (quat[3] * quat[2] + quat[0] * quat[1]);
|
const float siny_cosp = 2 * (quat.w * quat.xyz.z + quat.xyz.x * quat.xyz.y);
|
||||||
const float cosy_cosp = 1 - 2 * (quat[1] * quat[1] + quat[2] * quat[2]);
|
const float cosy_cosp = 1 - 2 * (quat.xyz.y * quat.xyz.y + quat.xyz.z * quat.xyz.z);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
std::atan2(sinr_cosp, cosr_cosp),
|
std::atan2(sinr_cosp, cosr_cosp),
|
||||||
@@ -285,13 +285,13 @@ void MotionInput::ResetOrientation() {
|
|||||||
if (!reset_enabled || only_accelerometer) {
|
if (!reset_enabled || only_accelerometer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!IsMoving(IsAtRestRelaxed) && accel[2] <= -0.9f) {
|
if (!IsMoving(IsAtRestRelaxed) && accel.z <= -0.9f) {
|
||||||
++reset_counter;
|
++reset_counter;
|
||||||
if (reset_counter > 900) {
|
if (reset_counter > 900) {
|
||||||
quat[3] = 0;
|
quat.w = 0;
|
||||||
quat[0] = 0;
|
quat.xyz[0] = 0;
|
||||||
quat[1] = 0;
|
quat.xyz[1] = 0;
|
||||||
quat[2] = -1;
|
quat.xyz[2] = -1;
|
||||||
SetOrientationFromAccelerometer();
|
SetOrientationFromAccelerometer();
|
||||||
integral_error = {};
|
integral_error = {};
|
||||||
reset_counter = 0;
|
reset_counter = 0;
|
||||||
@@ -309,15 +309,15 @@ void MotionInput::SetOrientationFromAccelerometer() {
|
|||||||
|
|
||||||
while (!IsCalibrated(0.01f) && ++iterations < 100) {
|
while (!IsCalibrated(0.01f) && ++iterations < 100) {
|
||||||
// Short name local variable for readability
|
// Short name local variable for readability
|
||||||
f32 q1 = quat[3];
|
f32 q1 = quat.w;
|
||||||
f32 q2 = quat[0];
|
f32 q2 = quat.xyz[0];
|
||||||
f32 q3 = quat[1];
|
f32 q3 = quat.xyz[1];
|
||||||
f32 q4 = quat[2];
|
f32 q4 = quat.xyz[2];
|
||||||
|
|
||||||
Common::Vec<f32, 3> rad_gyro;
|
Common::Vec3f rad_gyro;
|
||||||
const f32 ax = -normal_accel[0];
|
const f32 ax = -normal_accel.x;
|
||||||
const f32 ay = normal_accel[1];
|
const f32 ay = normal_accel.y;
|
||||||
const f32 az = -normal_accel[2];
|
const f32 az = -normal_accel.z;
|
||||||
|
|
||||||
// Estimated direction of gravity
|
// Estimated direction of gravity
|
||||||
const f32 vx = 2.0f * (q2 * q4 - q1 * q3);
|
const f32 vx = 2.0f * (q2 * q4 - q1 * q3);
|
||||||
@@ -325,7 +325,7 @@ void MotionInput::SetOrientationFromAccelerometer() {
|
|||||||
const f32 vz = q1 * q1 - q2 * q2 - q3 * q3 + q4 * q4;
|
const f32 vz = q1 * q1 - q2 * q2 - q3 * q3 + q4 * q4;
|
||||||
|
|
||||||
// Error is cross product between estimated direction and measured direction of gravity
|
// Error is cross product between estimated direction and measured direction of gravity
|
||||||
const Common::Vec<f32, 3> new_real_error = {
|
const Common::Vec3f new_real_error = {
|
||||||
az * vx - ax * vz,
|
az * vx - ax * vz,
|
||||||
ay * vz - az * vy,
|
ay * vz - az * vy,
|
||||||
ax * vy - ay * vx,
|
ax * vy - ay * vx,
|
||||||
@@ -338,9 +338,9 @@ void MotionInput::SetOrientationFromAccelerometer() {
|
|||||||
rad_gyro += 5.0f * ki * integral_error;
|
rad_gyro += 5.0f * ki * integral_error;
|
||||||
rad_gyro += 10.0f * kd * derivative_error;
|
rad_gyro += 10.0f * kd * derivative_error;
|
||||||
|
|
||||||
const f32 gx = rad_gyro[1];
|
const f32 gx = rad_gyro.y;
|
||||||
const f32 gy = rad_gyro[0];
|
const f32 gy = rad_gyro.x;
|
||||||
const f32 gz = rad_gyro[2];
|
const f32 gz = rad_gyro.z;
|
||||||
|
|
||||||
// Integrate rate of change of quaternion
|
// Integrate rate of change of quaternion
|
||||||
const f32 pa = q2;
|
const f32 pa = q2;
|
||||||
@@ -351,10 +351,10 @@ void MotionInput::SetOrientationFromAccelerometer() {
|
|||||||
q3 = pb + (q1 * gy - pa * gz + pc * gx) * (0.5f * sample_period);
|
q3 = pb + (q1 * gy - pa * gz + pc * gx) * (0.5f * sample_period);
|
||||||
q4 = pc + (q1 * gz + pa * gy - pb * gx) * (0.5f * sample_period);
|
q4 = pc + (q1 * gz + pa * gy - pb * gx) * (0.5f * sample_period);
|
||||||
|
|
||||||
quat[3] = q1;
|
quat.w = q1;
|
||||||
quat[0] = q2;
|
quat.xyz[0] = q2;
|
||||||
quat[1] = q3;
|
quat.xyz[1] = q3;
|
||||||
quat[2] = q4;
|
quat.xyz[2] = q4;
|
||||||
quat = quat.Normalized();
|
quat = quat.Normalized();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
#include "common/quaternion.h"
|
||||||
#include "common/vector_math.h"
|
#include "common/vector_math.h"
|
||||||
|
|
||||||
namespace Core::HID {
|
namespace Core::HID {
|
||||||
@@ -36,11 +34,11 @@ public:
|
|||||||
MotionInput& operator=(MotionInput&&) = default;
|
MotionInput& operator=(MotionInput&&) = default;
|
||||||
|
|
||||||
void SetPID(f32 new_kp, f32 new_ki, f32 new_kd);
|
void SetPID(f32 new_kp, f32 new_ki, f32 new_kd);
|
||||||
void SetAcceleration(const Common::Vec<f32, 3>& acceleration);
|
void SetAcceleration(const Common::Vec3f& acceleration);
|
||||||
void SetGyroscope(const Common::Vec<f32, 3>& gyroscope);
|
void SetGyroscope(const Common::Vec3f& gyroscope);
|
||||||
void SetQuaternion(const Common::Vec<f32, 4>& quaternion);
|
void SetQuaternion(const Common::Quaternion<f32>& quaternion);
|
||||||
void SetEulerAngles(const Common::Vec<f32, 3>& euler_angles);
|
void SetEulerAngles(const Common::Vec3f& euler_angles);
|
||||||
void SetGyroBias(const Common::Vec<f32, 3>& bias);
|
void SetGyroBias(const Common::Vec3f& bias);
|
||||||
void SetGyroThreshold(f32 threshold);
|
void SetGyroThreshold(f32 threshold);
|
||||||
|
|
||||||
/// Applies a modifier on top of the normal gyro threshold
|
/// Applies a modifier on top of the normal gyro threshold
|
||||||
@@ -55,13 +53,13 @@ public:
|
|||||||
|
|
||||||
void Calibrate();
|
void Calibrate();
|
||||||
|
|
||||||
[[nodiscard]] std::array<Common::Vec<f32, 3>, 3> GetOrientation() const;
|
[[nodiscard]] std::array<Common::Vec3f, 3> GetOrientation() const;
|
||||||
[[nodiscard]] Common::Vec<f32, 3> GetAcceleration() const;
|
[[nodiscard]] Common::Vec3f GetAcceleration() const;
|
||||||
[[nodiscard]] Common::Vec<f32, 3> GetGyroscope() const;
|
[[nodiscard]] Common::Vec3f GetGyroscope() const;
|
||||||
[[nodiscard]] Common::Vec<f32, 3> GetGyroBias() const;
|
[[nodiscard]] Common::Vec3f GetGyroBias() const;
|
||||||
[[nodiscard]] Common::Vec<f32, 3> GetRotations() const;
|
[[nodiscard]] Common::Vec3f GetRotations() const;
|
||||||
[[nodiscard]] Common::Vec<f32, 4> GetQuaternion() const;
|
[[nodiscard]] Common::Quaternion<f32> GetQuaternion() const;
|
||||||
[[nodiscard]] Common::Vec<f32, 3> GetEulerAngles() const;
|
[[nodiscard]] Common::Vec3f GetEulerAngles() const;
|
||||||
|
|
||||||
[[nodiscard]] bool IsMoving(f32 sensitivity) const;
|
[[nodiscard]] bool IsMoving(f32 sensitivity) const;
|
||||||
[[nodiscard]] bool IsCalibrated(f32 sensitivity) const;
|
[[nodiscard]] bool IsCalibrated(f32 sensitivity) const;
|
||||||
@@ -77,24 +75,24 @@ private:
|
|||||||
f32 kd;
|
f32 kd;
|
||||||
|
|
||||||
// PID errors
|
// PID errors
|
||||||
Common::Vec<f32, 3> real_error;
|
Common::Vec3f real_error;
|
||||||
Common::Vec<f32, 3> integral_error;
|
Common::Vec3f integral_error;
|
||||||
Common::Vec<f32, 3> derivative_error;
|
Common::Vec3f derivative_error;
|
||||||
|
|
||||||
// Quaternion containing the device orientation
|
// Quaternion containing the device orientation
|
||||||
Common::Vec<f32, 4> quat;
|
Common::Quaternion<f32> quat;
|
||||||
|
|
||||||
// Number of full rotations in each axis
|
// Number of full rotations in each axis
|
||||||
Common::Vec<f32, 3> rotations;
|
Common::Vec3f rotations;
|
||||||
|
|
||||||
// Acceleration vector measurement in G force
|
// Acceleration vector measurement in G force
|
||||||
Common::Vec<f32, 3> accel;
|
Common::Vec3f accel;
|
||||||
|
|
||||||
// Gyroscope vector measurement in radians/s.
|
// Gyroscope vector measurement in radians/s.
|
||||||
Common::Vec<f32, 3> gyro;
|
Common::Vec3f gyro;
|
||||||
|
|
||||||
// Vector to be subtracted from gyro measurements
|
// Vector to be subtracted from gyro measurements
|
||||||
Common::Vec<f32, 3> gyro_bias;
|
Common::Vec3f gyro_bias;
|
||||||
|
|
||||||
// Minimum gyro amplitude to detect if the device is moving
|
// Minimum gyro amplitude to detect if the device is moving
|
||||||
f32 gyro_threshold = 0.0f;
|
f32 gyro_threshold = 0.0f;
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
|
#include <array>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#include "common/bit_field.h"
|
#include "common/bit_field.h"
|
||||||
#include "common/common_funcs.h"
|
#include "common/common_funcs.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
@@ -605,10 +609,10 @@ static_assert(sizeof(SixAxisSensorAttribute) == 4, "SixAxisSensorAttribute is an
|
|||||||
struct SixAxisSensorState {
|
struct SixAxisSensorState {
|
||||||
s64 delta_time{};
|
s64 delta_time{};
|
||||||
s64 sampling_number{};
|
s64 sampling_number{};
|
||||||
Common::Vec<f32, 3> accel{};
|
Common::Vec3f accel{};
|
||||||
Common::Vec<f32, 3> gyro{};
|
Common::Vec3f gyro{};
|
||||||
Common::Vec<f32, 3> rotation{};
|
Common::Vec3f rotation{};
|
||||||
std::array<Common::Vec<f32, 3>, 3> orientation{};
|
std::array<Common::Vec3f, 3> orientation{};
|
||||||
SixAxisSensorAttribute attribute{};
|
SixAxisSensorAttribute attribute{};
|
||||||
INSERT_PADDING_BYTES(4); // Reserved
|
INSERT_PADDING_BYTES(4); // Reserved
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
@@ -196,7 +196,7 @@ struct ConsoleSixAxisSensorSharedMemoryFormat {
|
|||||||
bool is_seven_six_axis_sensor_at_rest{};
|
bool is_seven_six_axis_sensor_at_rest{};
|
||||||
INSERT_PADDING_BYTES(3); // padding
|
INSERT_PADDING_BYTES(3); // padding
|
||||||
f32 verticalization_error{};
|
f32 verticalization_error{};
|
||||||
Common::Vec<f32, 3> gyro_bias{};
|
Common::Vec3f gyro_bias{};
|
||||||
INSERT_PADDING_BYTES(4); // padding
|
INSERT_PADDING_BYTES(4); // padding
|
||||||
};
|
};
|
||||||
static_assert(sizeof(ConsoleSixAxisSensorSharedMemoryFormat) == 0x20,
|
static_assert(sizeof(ConsoleSixAxisSensorSharedMemoryFormat) == 0x20,
|
||||||
|
|||||||
@@ -46,11 +46,14 @@ void SevenSixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
|||||||
next_seven_sixaxis_state.accel = motion_status.accel;
|
next_seven_sixaxis_state.accel = motion_status.accel;
|
||||||
next_seven_sixaxis_state.gyro = motion_status.gyro;
|
next_seven_sixaxis_state.gyro = motion_status.gyro;
|
||||||
next_seven_sixaxis_state.quaternion = {
|
next_seven_sixaxis_state.quaternion = {
|
||||||
motion_status.quaternion[1],
|
{
|
||||||
motion_status.quaternion[0],
|
motion_status.quaternion.xyz.y,
|
||||||
-motion_status.quaternion[3],
|
motion_status.quaternion.xyz.x,
|
||||||
-motion_status.quaternion[2],
|
-motion_status.quaternion.w,
|
||||||
|
},
|
||||||
|
-motion_status.quaternion.xyz.z,
|
||||||
};
|
};
|
||||||
|
|
||||||
seven_sixaxis_lifo.WriteNextEntry(next_seven_sixaxis_state);
|
seven_sixaxis_lifo.WriteNextEntry(next_seven_sixaxis_state);
|
||||||
transfer_memory_owner->GetMemory().WriteBlock(transfer_memory, &seven_sixaxis_lifo,
|
transfer_memory_owner->GetMemory().WriteBlock(transfer_memory, &seven_sixaxis_lifo,
|
||||||
sizeof(seven_sixaxis_lifo));
|
sizeof(seven_sixaxis_lifo));
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/vector_math.h"
|
#include "common/quaternion.h"
|
||||||
#include "common/typed_address.h"
|
#include "common/typed_address.h"
|
||||||
#include "hid_core/resources/controller_base.h"
|
#include "hid_core/resources/controller_base.h"
|
||||||
#include "hid_core/resources/ring_lifo.h"
|
#include "hid_core/resources/ring_lifo.h"
|
||||||
@@ -51,9 +51,9 @@ private:
|
|||||||
u64 timestamp{};
|
u64 timestamp{};
|
||||||
u64 sampling_number{};
|
u64 sampling_number{};
|
||||||
u64 unknown{};
|
u64 unknown{};
|
||||||
Common::Vec<f32, 3> accel{};
|
Common::Vec3f accel{};
|
||||||
Common::Vec<f32, 3> gyro{};
|
Common::Vec3f gyro{};
|
||||||
Common::Vec<f32, 4> quaternion{};
|
Common::Quaternion<f32> quaternion{};
|
||||||
};
|
};
|
||||||
static_assert(sizeof(SevenSixAxisState) == 0x48, "SevenSixAxisState is an invalid size");
|
static_assert(sizeof(SevenSixAxisState) == 0x48, "SevenSixAxisState is an invalid size");
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
@@ -96,9 +93,9 @@ void SixAxis::OnUpdate(const Core::Timing::CoreTiming& core_timing) {
|
|||||||
.accel = {0, 0, -1.0f},
|
.accel = {0, 0, -1.0f},
|
||||||
.orientation =
|
.orientation =
|
||||||
{
|
{
|
||||||
Common::Vec<f32, 3>{1.0f, 0, 0},
|
Common::Vec3f{1.0f, 0, 0},
|
||||||
Common::Vec<f32, 3>{0, 1.0f, 0},
|
Common::Vec3f{0, 1.0f, 0},
|
||||||
Common::Vec<f32, 3>{0, 0, 1.0f},
|
Common::Vec3f{0, 0, 1.0f},
|
||||||
},
|
},
|
||||||
.attribute = {1},
|
.attribute = {1},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -88,8 +88,8 @@ void Mouse::UpdateStickInput() {
|
|||||||
last_mouse_change *= maximum_stick_range;
|
last_mouse_change *= maximum_stick_range;
|
||||||
}
|
}
|
||||||
|
|
||||||
SetAxis(identifier, mouse_axis_x, last_mouse_change[0]);
|
SetAxis(identifier, mouse_axis_x, last_mouse_change.x);
|
||||||
SetAxis(identifier, mouse_axis_y, -last_mouse_change[1]);
|
SetAxis(identifier, mouse_axis_y, -last_mouse_change.y);
|
||||||
|
|
||||||
// Decay input over time
|
// Decay input over time
|
||||||
const float clamped_length = (std::min)(1.0f, length);
|
const float clamped_length = (std::min)(1.0f, length);
|
||||||
@@ -104,20 +104,20 @@ void Mouse::UpdateMotionInput() {
|
|||||||
const float sensitivity =
|
const float sensitivity =
|
||||||
IsMousePanningEnabled() ? default_motion_panning_sensitivity : default_motion_sensitivity;
|
IsMousePanningEnabled() ? default_motion_panning_sensitivity : default_motion_sensitivity;
|
||||||
|
|
||||||
const float rotation_velocity = std::sqrt(last_motion_change[0] * last_motion_change[0] +
|
const float rotation_velocity = std::sqrt(last_motion_change.x * last_motion_change.x +
|
||||||
last_motion_change[1] * last_motion_change[1]);
|
last_motion_change.y * last_motion_change.y);
|
||||||
|
|
||||||
// Clamp rotation speed
|
// Clamp rotation speed
|
||||||
if (rotation_velocity > maximum_rotation_speed / sensitivity) {
|
if (rotation_velocity > maximum_rotation_speed / sensitivity) {
|
||||||
const float multiplier = maximum_rotation_speed / rotation_velocity / sensitivity;
|
const float multiplier = maximum_rotation_speed / rotation_velocity / sensitivity;
|
||||||
last_motion_change[0] = last_motion_change[0] * multiplier;
|
last_motion_change.x = last_motion_change.x * multiplier;
|
||||||
last_motion_change[1] = last_motion_change[1] * multiplier;
|
last_motion_change.y = last_motion_change.y * multiplier;
|
||||||
}
|
}
|
||||||
|
|
||||||
const BasicMotion motion_data{
|
const BasicMotion motion_data{
|
||||||
.gyro_x = last_motion_change[0] * sensitivity,
|
.gyro_x = last_motion_change.x * sensitivity,
|
||||||
.gyro_y = last_motion_change[1] * sensitivity,
|
.gyro_y = last_motion_change.y * sensitivity,
|
||||||
.gyro_z = last_motion_change[2] * sensitivity,
|
.gyro_z = last_motion_change.z * sensitivity,
|
||||||
.accel_x = 0,
|
.accel_x = 0,
|
||||||
.accel_y = 0,
|
.accel_y = 0,
|
||||||
.accel_z = 0,
|
.accel_z = 0,
|
||||||
@@ -125,46 +125,53 @@ void Mouse::UpdateMotionInput() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (IsMousePanningEnabled()) {
|
if (IsMousePanningEnabled()) {
|
||||||
last_motion_change[0] = 0;
|
last_motion_change.x = 0;
|
||||||
last_motion_change[1] = 0;
|
last_motion_change.y = 0;
|
||||||
}
|
}
|
||||||
last_motion_change[2] = 0;
|
last_motion_change.z = 0;
|
||||||
|
|
||||||
SetMotion(motion_identifier, 0, motion_data);
|
SetMotion(motion_identifier, 0, motion_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mouse::Move(int x, int y, int center_x, int center_y) {
|
void Mouse::Move(int x, int y, int center_x, int center_y) {
|
||||||
if (IsMousePanningEnabled()) {
|
if (IsMousePanningEnabled()) {
|
||||||
auto const mouse_change_int = Common::Vec<int, 2>(x, y) - Common::Vec<int, 2>(center_x, center_y);
|
const auto mouse_change =
|
||||||
auto const mouse_change = Common::Vec<float, 2>(float(mouse_change_int[0]), float(mouse_change_int[1]));
|
(Common::MakeVec(x, y) - Common::MakeVec(center_x, center_y)).Cast<float>();
|
||||||
auto const x_sensitivity = Settings::values.mouse_panning_x_sensitivity.GetValue() * default_panning_sensitivity;
|
const float x_sensitivity =
|
||||||
auto const y_sensitivity = Settings::values.mouse_panning_y_sensitivity.GetValue() * default_panning_sensitivity;
|
Settings::values.mouse_panning_x_sensitivity.GetValue() * default_panning_sensitivity;
|
||||||
auto const deadzone_cw = Settings::values.mouse_panning_deadzone_counterweight.GetValue() * default_deadzone_counterweight;
|
const float y_sensitivity =
|
||||||
last_motion_change += {-mouse_change[1] * x_sensitivity, -mouse_change[0] * y_sensitivity, 0};
|
Settings::values.mouse_panning_y_sensitivity.GetValue() * default_panning_sensitivity;
|
||||||
last_mouse_change[0] += mouse_change[0] * x_sensitivity;
|
const float deadzone_counterweight =
|
||||||
last_mouse_change[1] += mouse_change[1] * y_sensitivity;
|
Settings::values.mouse_panning_deadzone_counterweight.GetValue() *
|
||||||
// Bind the mouse change to [0 <= deadzone_cw <= 1.0]
|
default_deadzone_counterweight;
|
||||||
|
|
||||||
|
last_motion_change += {-mouse_change.y * x_sensitivity, -mouse_change.x * y_sensitivity, 0};
|
||||||
|
last_mouse_change.x += mouse_change.x * x_sensitivity;
|
||||||
|
last_mouse_change.y += mouse_change.y * y_sensitivity;
|
||||||
|
|
||||||
|
// Bind the mouse change to [0 <= deadzone_counterweight <= 1.0]
|
||||||
const float length = last_mouse_change.Length();
|
const float length = last_mouse_change.Length();
|
||||||
if (length < deadzone_cw && length != 0.0f) {
|
if (length < deadzone_counterweight && length != 0.0f) {
|
||||||
last_mouse_change /= length;
|
last_mouse_change /= length;
|
||||||
last_mouse_change *= deadzone_cw;
|
last_mouse_change *= deadzone_counterweight;
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (button_pressed) {
|
if (button_pressed) {
|
||||||
const auto mouse_move = Common::Vec<int, 2>(x, y) - mouse_origin;
|
const auto mouse_move = Common::MakeVec<int>(x, y) - mouse_origin;
|
||||||
const float x_sensitivity =
|
const float x_sensitivity =
|
||||||
Settings::values.mouse_panning_x_sensitivity.GetValue() * default_stick_sensitivity;
|
Settings::values.mouse_panning_x_sensitivity.GetValue() * default_stick_sensitivity;
|
||||||
const float y_sensitivity =
|
const float y_sensitivity =
|
||||||
Settings::values.mouse_panning_y_sensitivity.GetValue() * default_stick_sensitivity;
|
Settings::values.mouse_panning_y_sensitivity.GetValue() * default_stick_sensitivity;
|
||||||
SetAxis(identifier, mouse_axis_x, float(mouse_move[0]) * x_sensitivity);
|
SetAxis(identifier, mouse_axis_x, static_cast<float>(mouse_move.x) * x_sensitivity);
|
||||||
SetAxis(identifier, mouse_axis_y, float(-mouse_move[1]) * y_sensitivity);
|
SetAxis(identifier, mouse_axis_y, static_cast<float>(-mouse_move.y) * y_sensitivity);
|
||||||
|
|
||||||
last_motion_change = {
|
last_motion_change = {
|
||||||
float(-mouse_move[1]) * x_sensitivity,
|
static_cast<float>(-mouse_move.y) * x_sensitivity,
|
||||||
float(-mouse_move[0]) * y_sensitivity,
|
static_cast<float>(-mouse_move.x) * y_sensitivity,
|
||||||
last_motion_change[2],
|
last_motion_change.z,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -213,18 +220,18 @@ void Mouse::ReleaseButton(MouseButton button) {
|
|||||||
SetAxis(identifier, mouse_axis_y, 0);
|
SetAxis(identifier, mouse_axis_y, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
last_motion_change[0] = 0;
|
last_motion_change.x = 0;
|
||||||
last_motion_change[1] = 0;
|
last_motion_change.y = 0;
|
||||||
|
|
||||||
button_pressed = false;
|
button_pressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mouse::MouseWheelChange(int x, int y) {
|
void Mouse::MouseWheelChange(int x, int y) {
|
||||||
wheel_position[0] += x;
|
wheel_position.x += x;
|
||||||
wheel_position[1] += y;
|
wheel_position.y += y;
|
||||||
last_motion_change[2] += static_cast<f32>(y);
|
last_motion_change.z += static_cast<f32>(y);
|
||||||
SetAxis(identifier, wheel_axis_x, static_cast<f32>(wheel_position[0]));
|
SetAxis(identifier, wheel_axis_x, static_cast<f32>(wheel_position.x));
|
||||||
SetAxis(identifier, wheel_axis_y, static_cast<f32>(wheel_position[1]));
|
SetAxis(identifier, wheel_axis_y, static_cast<f32>(wheel_position.y));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mouse::ReleaseAllButtons() {
|
void Mouse::ReleaseAllButtons() {
|
||||||
|
|||||||
@@ -107,11 +107,11 @@ private:
|
|||||||
|
|
||||||
Common::Input::ButtonNames GetUIButtonName(const Common::ParamPackage& params) const;
|
Common::Input::ButtonNames GetUIButtonName(const Common::ParamPackage& params) const;
|
||||||
|
|
||||||
Common::Vec<int, 2> mouse_origin;
|
Common::Vec2<int> mouse_origin;
|
||||||
Common::Vec<int, 2> last_mouse_position;
|
Common::Vec2<int> last_mouse_position;
|
||||||
Common::Vec<float, 2> last_mouse_change;
|
Common::Vec2<float> last_mouse_change;
|
||||||
Common::Vec<float, 3> last_motion_change;
|
Common::Vec3<float> last_motion_change;
|
||||||
Common::Vec<int, 2> wheel_position;
|
Common::Vec2<int> wheel_position;
|
||||||
bool button_pressed = false;
|
bool button_pressed = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -6,55 +6,6 @@
|
|||||||
|
|
||||||
add_library(shader_recompiler STATIC
|
add_library(shader_recompiler STATIC
|
||||||
backend/bindings.h
|
backend/bindings.h
|
||||||
backend/glasm/emit_glasm.cpp
|
|
||||||
backend/glasm/emit_glasm.h
|
|
||||||
backend/glasm/emit_glasm_barriers.cpp
|
|
||||||
backend/glasm/emit_glasm_bitwise_conversion.cpp
|
|
||||||
backend/glasm/emit_glasm_composite.cpp
|
|
||||||
backend/glasm/emit_glasm_context_get_set.cpp
|
|
||||||
backend/glasm/emit_glasm_control_flow.cpp
|
|
||||||
backend/glasm/emit_glasm_convert.cpp
|
|
||||||
backend/glasm/emit_glasm_floating_point.cpp
|
|
||||||
backend/glasm/emit_glasm_image.cpp
|
|
||||||
backend/glasm/emit_glasm_instructions.h
|
|
||||||
backend/glasm/emit_glasm_integer.cpp
|
|
||||||
backend/glasm/emit_glasm_logical.cpp
|
|
||||||
backend/glasm/emit_glasm_memory.cpp
|
|
||||||
backend/glasm/emit_glasm_not_implemented.cpp
|
|
||||||
backend/glasm/emit_glasm_select.cpp
|
|
||||||
backend/glasm/emit_glasm_shared_memory.cpp
|
|
||||||
backend/glasm/emit_glasm_special.cpp
|
|
||||||
backend/glasm/emit_glasm_undefined.cpp
|
|
||||||
backend/glasm/emit_glasm_warp.cpp
|
|
||||||
backend/glasm/glasm_emit_context.cpp
|
|
||||||
backend/glasm/glasm_emit_context.h
|
|
||||||
backend/glasm/reg_alloc.cpp
|
|
||||||
backend/glasm/reg_alloc.h
|
|
||||||
backend/glsl/emit_glsl.cpp
|
|
||||||
backend/glsl/emit_glsl.h
|
|
||||||
backend/glsl/emit_glsl_atomic.cpp
|
|
||||||
backend/glsl/emit_glsl_barriers.cpp
|
|
||||||
backend/glsl/emit_glsl_bitwise_conversion.cpp
|
|
||||||
backend/glsl/emit_glsl_composite.cpp
|
|
||||||
backend/glsl/emit_glsl_context_get_set.cpp
|
|
||||||
backend/glsl/emit_glsl_control_flow.cpp
|
|
||||||
backend/glsl/emit_glsl_convert.cpp
|
|
||||||
backend/glsl/emit_glsl_floating_point.cpp
|
|
||||||
backend/glsl/emit_glsl_image.cpp
|
|
||||||
backend/glsl/emit_glsl_instructions.h
|
|
||||||
backend/glsl/emit_glsl_integer.cpp
|
|
||||||
backend/glsl/emit_glsl_logical.cpp
|
|
||||||
backend/glsl/emit_glsl_memory.cpp
|
|
||||||
backend/glsl/emit_glsl_not_implemented.cpp
|
|
||||||
backend/glsl/emit_glsl_select.cpp
|
|
||||||
backend/glsl/emit_glsl_shared_memory.cpp
|
|
||||||
backend/glsl/emit_glsl_special.cpp
|
|
||||||
backend/glsl/emit_glsl_undefined.cpp
|
|
||||||
backend/glsl/emit_glsl_warp.cpp
|
|
||||||
backend/glsl/glsl_emit_context.cpp
|
|
||||||
backend/glsl/glsl_emit_context.h
|
|
||||||
backend/glsl/var_alloc.cpp
|
|
||||||
backend/glsl/var_alloc.h
|
|
||||||
backend/spirv/emit_spirv.cpp
|
backend/spirv/emit_spirv.cpp
|
||||||
backend/spirv/emit_spirv.h
|
backend/spirv/emit_spirv.h
|
||||||
backend/spirv/emit_spirv_atomic.cpp
|
backend/spirv/emit_spirv_atomic.cpp
|
||||||
@@ -239,9 +190,60 @@ add_library(shader_recompiler STATIC
|
|||||||
program_header.h
|
program_header.h
|
||||||
runtime_info.h
|
runtime_info.h
|
||||||
shader_info.h
|
shader_info.h
|
||||||
varying_state.h
|
varying_state.h)
|
||||||
|
|
||||||
)
|
if (ENABLE_OPENGL)
|
||||||
|
target_sources(shader_recompiler PRIVATE
|
||||||
|
backend/glasm/emit_glasm.cpp
|
||||||
|
backend/glasm/emit_glasm.h
|
||||||
|
backend/glasm/emit_glasm_barriers.cpp
|
||||||
|
backend/glasm/emit_glasm_bitwise_conversion.cpp
|
||||||
|
backend/glasm/emit_glasm_composite.cpp
|
||||||
|
backend/glasm/emit_glasm_context_get_set.cpp
|
||||||
|
backend/glasm/emit_glasm_control_flow.cpp
|
||||||
|
backend/glasm/emit_glasm_convert.cpp
|
||||||
|
backend/glasm/emit_glasm_floating_point.cpp
|
||||||
|
backend/glasm/emit_glasm_image.cpp
|
||||||
|
backend/glasm/emit_glasm_instructions.h
|
||||||
|
backend/glasm/emit_glasm_integer.cpp
|
||||||
|
backend/glasm/emit_glasm_logical.cpp
|
||||||
|
backend/glasm/emit_glasm_memory.cpp
|
||||||
|
backend/glasm/emit_glasm_not_implemented.cpp
|
||||||
|
backend/glasm/emit_glasm_select.cpp
|
||||||
|
backend/glasm/emit_glasm_shared_memory.cpp
|
||||||
|
backend/glasm/emit_glasm_special.cpp
|
||||||
|
backend/glasm/emit_glasm_undefined.cpp
|
||||||
|
backend/glasm/emit_glasm_warp.cpp
|
||||||
|
backend/glasm/glasm_emit_context.cpp
|
||||||
|
backend/glasm/glasm_emit_context.h
|
||||||
|
backend/glasm/reg_alloc.cpp
|
||||||
|
backend/glasm/reg_alloc.h
|
||||||
|
backend/glsl/emit_glsl.cpp
|
||||||
|
backend/glsl/emit_glsl.h
|
||||||
|
backend/glsl/emit_glsl_atomic.cpp
|
||||||
|
backend/glsl/emit_glsl_barriers.cpp
|
||||||
|
backend/glsl/emit_glsl_bitwise_conversion.cpp
|
||||||
|
backend/glsl/emit_glsl_composite.cpp
|
||||||
|
backend/glsl/emit_glsl_context_get_set.cpp
|
||||||
|
backend/glsl/emit_glsl_control_flow.cpp
|
||||||
|
backend/glsl/emit_glsl_convert.cpp
|
||||||
|
backend/glsl/emit_glsl_floating_point.cpp
|
||||||
|
backend/glsl/emit_glsl_image.cpp
|
||||||
|
backend/glsl/emit_glsl_instructions.h
|
||||||
|
backend/glsl/emit_glsl_integer.cpp
|
||||||
|
backend/glsl/emit_glsl_logical.cpp
|
||||||
|
backend/glsl/emit_glsl_memory.cpp
|
||||||
|
backend/glsl/emit_glsl_not_implemented.cpp
|
||||||
|
backend/glsl/emit_glsl_select.cpp
|
||||||
|
backend/glsl/emit_glsl_shared_memory.cpp
|
||||||
|
backend/glsl/emit_glsl_special.cpp
|
||||||
|
backend/glsl/emit_glsl_undefined.cpp
|
||||||
|
backend/glsl/emit_glsl_warp.cpp
|
||||||
|
backend/glsl/glsl_emit_context.cpp
|
||||||
|
backend/glsl/glsl_emit_context.h
|
||||||
|
backend/glsl/var_alloc.cpp
|
||||||
|
backend/glsl/var_alloc.h)
|
||||||
|
endif()
|
||||||
|
|
||||||
target_link_libraries(shader_recompiler PUBLIC common fmt::fmt sirit::sirit)
|
target_link_libraries(shader_recompiler PUBLIC common fmt::fmt sirit::sirit)
|
||||||
|
|
||||||
|
|||||||
@@ -553,17 +553,6 @@ void GlobalMemoryToStorageBufferPass(IR::Program& program, const HostTranslateIn
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Descriptors, typename Descriptor, typename Func>
|
|
||||||
static u32 Add(Descriptors& descriptors, const Descriptor& desc, Func&& pred) {
|
|
||||||
// TODO: Handle arrays
|
|
||||||
const auto it{std::ranges::find_if(descriptors, pred)};
|
|
||||||
if (it != descriptors.end()) {
|
|
||||||
return static_cast<u32>(std::distance(descriptors.begin(), it));
|
|
||||||
}
|
|
||||||
descriptors.push_back(desc);
|
|
||||||
return static_cast<u32>(descriptors.size()) - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void JoinStorageInfo(Info& base, Info& source) {
|
void JoinStorageInfo(Info& base, Info& source) {
|
||||||
auto& descriptors = base.storage_buffers_descriptors;
|
auto& descriptors = base.storage_buffers_descriptors;
|
||||||
for (auto& desc : source.storage_buffers_descriptors) {
|
for (auto& desc : source.storage_buffers_descriptors) {
|
||||||
|
|||||||
@@ -312,10 +312,66 @@ static inline std::optional<ConstBufferAddr> TrackCached(const IR::Value& v, Env
|
|||||||
|
|
||||||
std::optional<ConstBufferAddr> TryGetConstBuffer(const IR::Inst* inst, Environment& env, const HostTranslateInfo& host_info);
|
std::optional<ConstBufferAddr> TryGetConstBuffer(const IR::Inst* inst, Environment& env, const HostTranslateInfo& host_info);
|
||||||
|
|
||||||
|
bool IsSameConstBufferAddr(const ConstBufferAddr& lhs, const ConstBufferAddr& rhs) {
|
||||||
|
return lhs.index == rhs.index && lhs.offset == rhs.offset &&
|
||||||
|
lhs.shift_left == rhs.shift_left && lhs.secondary_index == rhs.secondary_index &&
|
||||||
|
lhs.secondary_offset == rhs.secondary_offset &&
|
||||||
|
lhs.secondary_shift_left == rhs.secondary_shift_left && lhs.count == rhs.count &&
|
||||||
|
lhs.has_secondary == rhs.has_secondary && lhs.dynamic_offset == rhs.dynamic_offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<ConstBufferAddr> TrackPhi(const IR::Inst* phi, Environment& env,
|
||||||
|
const HostTranslateInfo& host_info, bool& ambiguous) {
|
||||||
|
std::optional<ConstBufferAddr> agreed;
|
||||||
|
const size_t num_args{phi->NumArgs()};
|
||||||
|
for (size_t index = 0; index < num_args; ++index) {
|
||||||
|
const IR::Value arg{phi->Arg(index).Resolve()};
|
||||||
|
if (arg.IsImmediate()) {
|
||||||
|
ambiguous = true;
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
const IR::Inst* arg_inst{arg.InstRecursive()};
|
||||||
|
if (arg_inst == phi) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (arg_inst->GetOpcode() == IR::Opcode::Phi) {
|
||||||
|
ambiguous = true;
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
const std::optional<ConstBufferAddr> operand{TrackCached(arg, env, host_info)};
|
||||||
|
if (!operand) {
|
||||||
|
ambiguous = true;
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
if (!agreed) {
|
||||||
|
agreed = operand;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!IsSameConstBufferAddr(*agreed, *operand)) {
|
||||||
|
ambiguous = true;
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!agreed) {
|
||||||
|
ambiguous = true;
|
||||||
|
}
|
||||||
|
return agreed;
|
||||||
|
}
|
||||||
|
|
||||||
std::optional<ConstBufferAddr> Track(const IR::Value& value, Environment& env, const HostTranslateInfo& host_info) {
|
std::optional<ConstBufferAddr> Track(const IR::Value& value, Environment& env, const HostTranslateInfo& host_info) {
|
||||||
return IR::BreadthFirstSearch(value, [&env, &host_info](const IR::Inst* inst) {
|
bool ambiguous = false;
|
||||||
return TryGetConstBuffer(inst, env, host_info);
|
const std::optional<ConstBufferAddr> result{IR::BreadthFirstSearch(
|
||||||
});
|
value, [&env, &host_info, &ambiguous](const IR::Inst* inst)
|
||||||
|
-> std::optional<ConstBufferAddr> {
|
||||||
|
if (inst->GetOpcode() == IR::Opcode::Phi) {
|
||||||
|
return TrackPhi(inst, env, host_info, ambiguous);
|
||||||
|
}
|
||||||
|
return TryGetConstBuffer(inst, env, host_info);
|
||||||
|
})};
|
||||||
|
if (ambiguous) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<u32> TryGetConstant(IR::Value& value, Environment& env) {
|
std::optional<u32> TryGetConstant(IR::Value& value, Environment& env) {
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ add_library(video_core STATIC
|
|||||||
buffer_cache/buffer_cache.h
|
buffer_cache/buffer_cache.h
|
||||||
buffer_cache/memory_tracker_base.h
|
buffer_cache/memory_tracker_base.h
|
||||||
buffer_cache/usage_tracker.h
|
buffer_cache/usage_tracker.h
|
||||||
|
buffer_cache/virtual_range_cache.h
|
||||||
buffer_cache/word_manager.h
|
buffer_cache/word_manager.h
|
||||||
cache_types.h
|
cache_types.h
|
||||||
capture.h
|
capture.h
|
||||||
@@ -166,6 +167,8 @@ add_library(video_core STATIC
|
|||||||
renderer_vulkan/vk_fence_manager.h
|
renderer_vulkan/vk_fence_manager.h
|
||||||
renderer_vulkan/vk_graphics_pipeline.cpp
|
renderer_vulkan/vk_graphics_pipeline.cpp
|
||||||
renderer_vulkan/vk_graphics_pipeline.h
|
renderer_vulkan/vk_graphics_pipeline.h
|
||||||
|
renderer_vulkan/vk_multi_range_buffer.cpp
|
||||||
|
renderer_vulkan/vk_multi_range_buffer.h
|
||||||
renderer_vulkan/vk_master_semaphore.cpp
|
renderer_vulkan/vk_master_semaphore.cpp
|
||||||
renderer_vulkan/vk_master_semaphore.h
|
renderer_vulkan/vk_master_semaphore.h
|
||||||
renderer_vulkan/vk_pipeline_cache.cpp
|
renderer_vulkan/vk_pipeline_cache.cpp
|
||||||
|
|||||||
@@ -112,6 +112,11 @@ void BufferCache<P>::TickFrame() {
|
|||||||
async_buffers_death_ring.clear();
|
async_buffers_death_ring.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class P>
|
||||||
|
void BufferCache<P>::UnmapGPUMemory(size_t as_id, GPUVAddr gpu_addr, size_t size) {
|
||||||
|
virtual_ranges.Unmap(as_id, gpu_addr, size);
|
||||||
|
}
|
||||||
|
|
||||||
template <class P>
|
template <class P>
|
||||||
void BufferCache<P>::WriteMemory(DAddr device_addr, u64 size) {
|
void BufferCache<P>::WriteMemory(DAddr device_addr, u64 size) {
|
||||||
if (memory_tracker.IsRegionGpuModified(device_addr, size)) {
|
if (memory_tracker.IsRegionGpuModified(device_addr, size)) {
|
||||||
@@ -998,11 +1003,56 @@ void BufferCache<P>::BindHostGraphicsUniformBuffer(size_t stage, u32 index, u32
|
|||||||
channel_state->fast_bound_uniform_buffers[stage] &= ~(1u << binding_index);
|
channel_state->fast_bound_uniform_buffers[stage] &= ~(1u << binding_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class P>
|
||||||
|
bool BufferCache<P>::BindMultiRangeStorage(const Binding& binding, bool is_written) {
|
||||||
|
if constexpr (requires { runtime.BindMultiRangeStorageBuffer(u64{}); }) {
|
||||||
|
if (binding.gpu_addr == 0 || binding.size == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (is_written && !runtime.PrefersSparseSources()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const VirtualSegments* segments =
|
||||||
|
virtual_ranges.Query(*gpu_memory, binding.gpu_addr, binding.size);
|
||||||
|
if (!segments || segments->size() < 2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const u64 key = (static_cast<u64>(gpu_memory->GetID()) << 48) ^ binding.gpu_addr;
|
||||||
|
const bool prefer_sparse = runtime.PrefersSparseSources();
|
||||||
|
runtime.ResetMultiRange();
|
||||||
|
for (const VirtualSegment& segment : *segments) {
|
||||||
|
const BufferId buffer_id =
|
||||||
|
FindBuffer(segment.device_addr, segment.size, prefer_sparse);
|
||||||
|
if (!buffer_id) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Buffer& buffer = slot_buffers[buffer_id];
|
||||||
|
TouchBuffer(buffer, buffer_id);
|
||||||
|
if (SynchronizeBuffer(buffer, segment.device_addr, segment.size)) {
|
||||||
|
runtime.InvalidateMultiRange(key);
|
||||||
|
}
|
||||||
|
const u32 offset = buffer.Offset(segment.device_addr);
|
||||||
|
buffer.MarkUsage(offset, segment.size);
|
||||||
|
if (is_written) {
|
||||||
|
MarkWrittenBuffer(buffer_id, segment.device_addr, segment.size);
|
||||||
|
}
|
||||||
|
runtime.PushMultiRangeSource(buffer, offset, segment.size);
|
||||||
|
}
|
||||||
|
return runtime.BindMultiRangeStorageBuffer(key);
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
template <class P>
|
template <class P>
|
||||||
void BufferCache<P>::BindHostGraphicsStorageBuffers(size_t stage) {
|
void BufferCache<P>::BindHostGraphicsStorageBuffers(size_t stage) {
|
||||||
u32 binding_index = 0;
|
u32 binding_index = 0;
|
||||||
ForEachEnabledBit(channel_state->enabled_storage_buffers[stage], [&](u32 index) {
|
ForEachEnabledBit(channel_state->enabled_storage_buffers[stage], [&](u32 index) {
|
||||||
const Binding& binding = channel_state->storage_buffers[stage][index];
|
const Binding& binding = channel_state->storage_buffers[stage][index];
|
||||||
|
const bool is_written = ((channel_state->written_storage_buffers[stage] >> index) & 1) != 0;
|
||||||
|
if (BindMultiRangeStorage(binding, is_written)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Buffer& buffer = slot_buffers[binding.buffer_id];
|
Buffer& buffer = slot_buffers[binding.buffer_id];
|
||||||
TouchBuffer(buffer, binding.buffer_id);
|
TouchBuffer(buffer, binding.buffer_id);
|
||||||
const u32 size = binding.size;
|
const u32 size = binding.size;
|
||||||
@@ -1010,7 +1060,6 @@ void BufferCache<P>::BindHostGraphicsStorageBuffers(size_t stage) {
|
|||||||
|
|
||||||
const u32 offset = buffer.Offset(binding.device_addr);
|
const u32 offset = buffer.Offset(binding.device_addr);
|
||||||
buffer.MarkUsage(offset, size);
|
buffer.MarkUsage(offset, size);
|
||||||
const bool is_written = ((channel_state->written_storage_buffers[stage] >> index) & 1) != 0;
|
|
||||||
|
|
||||||
if (is_written) {
|
if (is_written) {
|
||||||
MarkWrittenBuffer(binding.buffer_id, binding.device_addr, size);
|
MarkWrittenBuffer(binding.buffer_id, binding.device_addr, size);
|
||||||
@@ -1139,6 +1188,11 @@ void BufferCache<P>::BindHostComputeStorageBuffers() {
|
|||||||
u32 binding_index = 0;
|
u32 binding_index = 0;
|
||||||
ForEachEnabledBit(channel_state->enabled_compute_storage_buffers, [&](u32 index) {
|
ForEachEnabledBit(channel_state->enabled_compute_storage_buffers, [&](u32 index) {
|
||||||
const Binding& binding = channel_state->compute_storage_buffers[index];
|
const Binding& binding = channel_state->compute_storage_buffers[index];
|
||||||
|
const bool is_written =
|
||||||
|
((channel_state->written_compute_storage_buffers >> index) & 1) != 0;
|
||||||
|
if (BindMultiRangeStorage(binding, is_written)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Buffer& buffer = slot_buffers[binding.buffer_id];
|
Buffer& buffer = slot_buffers[binding.buffer_id];
|
||||||
TouchBuffer(buffer, binding.buffer_id);
|
TouchBuffer(buffer, binding.buffer_id);
|
||||||
const u32 size = binding.size;
|
const u32 size = binding.size;
|
||||||
@@ -1146,8 +1200,6 @@ void BufferCache<P>::BindHostComputeStorageBuffers() {
|
|||||||
|
|
||||||
const u32 offset = buffer.Offset(binding.device_addr);
|
const u32 offset = buffer.Offset(binding.device_addr);
|
||||||
buffer.MarkUsage(offset, size);
|
buffer.MarkUsage(offset, size);
|
||||||
const bool is_written =
|
|
||||||
((channel_state->written_compute_storage_buffers >> index) & 1) != 0;
|
|
||||||
|
|
||||||
if (is_written) {
|
if (is_written) {
|
||||||
MarkWrittenBuffer(binding.buffer_id, binding.device_addr, size);
|
MarkWrittenBuffer(binding.buffer_id, binding.device_addr, size);
|
||||||
@@ -1440,7 +1492,7 @@ void BufferCache<P>::MarkWrittenBuffer(BufferId buffer_id, DAddr device_addr, u3
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class P>
|
template <class P>
|
||||||
BufferId BufferCache<P>::FindBuffer(DAddr device_addr, u32 size) {
|
BufferId BufferCache<P>::FindBuffer(DAddr device_addr, u32 size, bool sparse_compatible) {
|
||||||
if (device_addr == 0) {
|
if (device_addr == 0) {
|
||||||
return NULL_BUFFER_ID;
|
return NULL_BUFFER_ID;
|
||||||
}
|
}
|
||||||
@@ -1450,10 +1502,18 @@ BufferId BufferCache<P>::FindBuffer(DAddr device_addr, u32 size) {
|
|||||||
Buffer& buffer = slot_buffers[buffer_id];
|
Buffer& buffer = slot_buffers[buffer_id];
|
||||||
WaitForGpuFenceIfNeeded(buffer);
|
WaitForGpuFenceIfNeeded(buffer);
|
||||||
if (buffer.IsInBounds(device_addr, size)) {
|
if (buffer.IsInBounds(device_addr, size)) {
|
||||||
return buffer_id;
|
bool usable = true;
|
||||||
|
if constexpr (requires { buffer.IsSparseCompatible(); }) {
|
||||||
|
if (sparse_compatible && !buffer.IsSparseCompatible()) {
|
||||||
|
usable = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (usable) {
|
||||||
|
return buffer_id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return CreateBuffer(device_addr, size);
|
return CreateBuffer(device_addr, size, sparse_compatible);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class P>
|
template <class P>
|
||||||
@@ -1575,13 +1635,15 @@ void BufferCache<P>::JoinOverlap(BufferId new_buffer_id, BufferId overlap_id,
|
|||||||
}
|
}
|
||||||
|
|
||||||
template <class P>
|
template <class P>
|
||||||
BufferId BufferCache<P>::CreateBuffer(DAddr device_addr, u32 wanted_size) {
|
BufferId BufferCache<P>::CreateBuffer(DAddr device_addr, u32 wanted_size,
|
||||||
|
bool sparse_compatible) {
|
||||||
DAddr device_addr_end = Common::AlignUp(device_addr + wanted_size, CACHING_PAGESIZE);
|
DAddr device_addr_end = Common::AlignUp(device_addr + wanted_size, CACHING_PAGESIZE);
|
||||||
device_addr = Common::AlignDown(device_addr, CACHING_PAGESIZE);
|
device_addr = Common::AlignDown(device_addr, CACHING_PAGESIZE);
|
||||||
wanted_size = static_cast<u32>(device_addr_end - device_addr);
|
wanted_size = static_cast<u32>(device_addr_end - device_addr);
|
||||||
const OverlapResult overlap = ResolveOverlaps(device_addr, wanted_size);
|
const OverlapResult overlap = ResolveOverlaps(device_addr, wanted_size);
|
||||||
const u32 size = static_cast<u32>(overlap.end - overlap.begin);
|
const u32 size = static_cast<u32>(overlap.end - overlap.begin);
|
||||||
const BufferId new_buffer_id = slot_buffers.insert(runtime, overlap.begin, size);
|
const BufferId new_buffer_id =
|
||||||
|
slot_buffers.insert(runtime, overlap.begin, size, sparse_compatible);
|
||||||
auto& new_buffer = slot_buffers[new_buffer_id];
|
auto& new_buffer = slot_buffers[new_buffer_id];
|
||||||
const size_t size_bytes = new_buffer.SizeBytes();
|
const size_t size_bytes = new_buffer.SizeBytes();
|
||||||
runtime.ClearBuffer(new_buffer, 0, size_bytes, 0);
|
runtime.ClearBuffer(new_buffer, 0, size_bytes, 0);
|
||||||
@@ -1934,10 +1996,15 @@ Binding BufferCache<P>::StorageBufferBinding(GPUVAddr ssbo_addr, u32 cbuf_index,
|
|||||||
// The end address used for size calculation does not need to be aligned
|
// The end address used for size calculation does not need to be aligned
|
||||||
const DAddr cpu_end = Common::AlignUp(*device_addr + size, Core::DEVICE_PAGESIZE);
|
const DAddr cpu_end = Common::AlignUp(*device_addr + size, Core::DEVICE_PAGESIZE);
|
||||||
|
|
||||||
|
u32 binding_size = static_cast<u32>(cpu_end - *aligned_device_addr);
|
||||||
|
if (is_written) {
|
||||||
|
binding_size = aligned_size;
|
||||||
|
}
|
||||||
const Binding binding{
|
const Binding binding{
|
||||||
.device_addr = *aligned_device_addr,
|
.device_addr = *aligned_device_addr,
|
||||||
.size = is_written ? aligned_size : static_cast<u32>(cpu_end - *aligned_device_addr),
|
.size = binding_size,
|
||||||
.buffer_id = BufferId{},
|
.buffer_id = BufferId{},
|
||||||
|
.gpu_addr = aligned_gpu_addr,
|
||||||
};
|
};
|
||||||
return binding;
|
return binding;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
#include "common/slot_vector.h"
|
#include "common/slot_vector.h"
|
||||||
#include "video_core/buffer_cache/buffer_base.h"
|
#include "video_core/buffer_cache/buffer_base.h"
|
||||||
|
#include "video_core/buffer_cache/virtual_range_cache.h"
|
||||||
#include "video_core/control/channel_state_cache.h"
|
#include "video_core/control/channel_state_cache.h"
|
||||||
#include "video_core/delayed_destruction_ring.h"
|
#include "video_core/delayed_destruction_ring.h"
|
||||||
#include "video_core/dirty_flags.h"
|
#include "video_core/dirty_flags.h"
|
||||||
@@ -83,6 +84,7 @@ struct Binding {
|
|||||||
DAddr device_addr{};
|
DAddr device_addr{};
|
||||||
u32 size{};
|
u32 size{};
|
||||||
BufferId buffer_id;
|
BufferId buffer_id;
|
||||||
|
GPUVAddr gpu_addr{};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TextureBufferBinding : Binding {
|
struct TextureBufferBinding : Binding {
|
||||||
@@ -215,6 +217,10 @@ public:
|
|||||||
|
|
||||||
void TickFrame();
|
void TickFrame();
|
||||||
|
|
||||||
|
bool BindMultiRangeStorage(const Binding& binding, bool is_written);
|
||||||
|
|
||||||
|
void UnmapGPUMemory(size_t as_id, GPUVAddr gpu_addr, size_t size);
|
||||||
|
|
||||||
void WriteMemory(DAddr device_addr, u64 size);
|
void WriteMemory(DAddr device_addr, u64 size);
|
||||||
|
|
||||||
void CachedWriteMemory(DAddr device_addr, u64 size);
|
void CachedWriteMemory(DAddr device_addr, u64 size);
|
||||||
@@ -414,7 +420,8 @@ private:
|
|||||||
|
|
||||||
void MarkWrittenBuffer(BufferId buffer_id, DAddr device_addr, u32 size);
|
void MarkWrittenBuffer(BufferId buffer_id, DAddr device_addr, u32 size);
|
||||||
|
|
||||||
[[nodiscard]] BufferId FindBuffer(DAddr device_addr, u32 size);
|
[[nodiscard]] BufferId FindBuffer(DAddr device_addr, u32 size,
|
||||||
|
bool sparse_compatible = false);
|
||||||
|
|
||||||
void WaitForGpuFenceIfNeeded(Buffer& buffer);
|
void WaitForGpuFenceIfNeeded(Buffer& buffer);
|
||||||
|
|
||||||
@@ -422,7 +429,8 @@ private:
|
|||||||
|
|
||||||
void JoinOverlap(BufferId new_buffer_id, BufferId overlap_id, bool accumulate_stream_score);
|
void JoinOverlap(BufferId new_buffer_id, BufferId overlap_id, bool accumulate_stream_score);
|
||||||
|
|
||||||
[[nodiscard]] BufferId CreateBuffer(DAddr device_addr, u32 wanted_size);
|
[[nodiscard]] BufferId CreateBuffer(DAddr device_addr, u32 wanted_size,
|
||||||
|
bool sparse_compatible = false);
|
||||||
|
|
||||||
void Register(BufferId buffer_id);
|
void Register(BufferId buffer_id);
|
||||||
|
|
||||||
@@ -514,6 +522,7 @@ private:
|
|||||||
};
|
};
|
||||||
Common::LeastRecentlyUsedCache<LRUItemParams> lru_cache;
|
Common::LeastRecentlyUsedCache<LRUItemParams> lru_cache;
|
||||||
u64 frame_tick = 0;
|
u64 frame_tick = 0;
|
||||||
|
VirtualRangeCache virtual_ranges;
|
||||||
u64 total_used_memory = 0;
|
u64 total_used_memory = 0;
|
||||||
u64 minimum_memory = 0;
|
u64 minimum_memory = 0;
|
||||||
u64 critical_memory = 0;
|
u64 critical_memory = 0;
|
||||||
|
|||||||
@@ -0,0 +1,152 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <limits>
|
||||||
|
#include <mutex>
|
||||||
|
#include <optional>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <boost/container/small_vector.hpp>
|
||||||
|
|
||||||
|
#include "common/common_types.h"
|
||||||
|
#include "video_core/memory_manager.h"
|
||||||
|
|
||||||
|
namespace VideoCommon {
|
||||||
|
|
||||||
|
struct VirtualSegment {
|
||||||
|
GPUVAddr gpu_addr;
|
||||||
|
DAddr device_addr;
|
||||||
|
u32 size;
|
||||||
|
};
|
||||||
|
|
||||||
|
using VirtualSegments = boost::container::small_vector<VirtualSegment, 8>;
|
||||||
|
|
||||||
|
class VirtualRangeCache {
|
||||||
|
public:
|
||||||
|
const VirtualSegments* Query(Tegra::MemoryManager& memory, GPUVAddr gpu_addr, u32 size) {
|
||||||
|
if (has_deferred.load(std::memory_order_acquire)) {
|
||||||
|
ApplyDeferred();
|
||||||
|
}
|
||||||
|
const size_t as_id = memory.GetID();
|
||||||
|
const u64 key = MakeKey(as_id, gpu_addr);
|
||||||
|
const auto it = entries.find(key);
|
||||||
|
if (it != entries.end() && it->second.as_id == as_id &&
|
||||||
|
it->second.gpu_addr == gpu_addr && it->second.size == size) {
|
||||||
|
return &it->second.segments;
|
||||||
|
}
|
||||||
|
Entry entry;
|
||||||
|
entry.as_id = as_id;
|
||||||
|
entry.gpu_addr = gpu_addr;
|
||||||
|
entry.size = size;
|
||||||
|
const auto ranges = memory.GetSubmappedRange(gpu_addr, size);
|
||||||
|
for (const auto& [range_addr, range_size] : ranges) {
|
||||||
|
const std::optional<DAddr> device_addr = memory.GpuToCpuAddress(range_addr);
|
||||||
|
if (!device_addr) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
u32 segment_size = (std::numeric_limits<u32>::max)();
|
||||||
|
if (range_size < static_cast<size_t>(segment_size)) {
|
||||||
|
segment_size = static_cast<u32>(range_size);
|
||||||
|
}
|
||||||
|
entry.segments.push_back(VirtualSegment{
|
||||||
|
.gpu_addr = range_addr,
|
||||||
|
.device_addr = *device_addr,
|
||||||
|
.size = segment_size,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const auto result = entries.insert_or_assign(key, std::move(entry));
|
||||||
|
return &result.first->second.segments;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Unmap(size_t as_id, GPUVAddr gpu_addr, u64 size) {
|
||||||
|
if (size == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::scoped_lock lock{deferred_mutex};
|
||||||
|
if (!deferred.empty()) {
|
||||||
|
DeferredUnmap& last = deferred.back();
|
||||||
|
if (last.as_id == as_id && last.gpu_addr + last.size == gpu_addr) {
|
||||||
|
last.size += size;
|
||||||
|
has_deferred.store(true, std::memory_order_release);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
deferred.push_back(DeferredUnmap{
|
||||||
|
.as_id = as_id,
|
||||||
|
.gpu_addr = gpu_addr,
|
||||||
|
.size = size,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
has_deferred.store(true, std::memory_order_release);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Clear() {
|
||||||
|
{
|
||||||
|
std::scoped_lock lock{deferred_mutex};
|
||||||
|
deferred.clear();
|
||||||
|
}
|
||||||
|
has_deferred.store(false, std::memory_order_release);
|
||||||
|
entries.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Entry {
|
||||||
|
size_t as_id{};
|
||||||
|
GPUVAddr gpu_addr{};
|
||||||
|
u32 size{};
|
||||||
|
VirtualSegments segments;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct DeferredUnmap {
|
||||||
|
size_t as_id;
|
||||||
|
GPUVAddr gpu_addr;
|
||||||
|
u64 size;
|
||||||
|
};
|
||||||
|
|
||||||
|
static u64 MakeKey(size_t as_id, GPUVAddr gpu_addr) {
|
||||||
|
return (static_cast<u64>(as_id) << 48) ^ gpu_addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ApplyDeferred() {
|
||||||
|
std::vector<DeferredUnmap> pending;
|
||||||
|
{
|
||||||
|
std::scoped_lock lock{deferred_mutex};
|
||||||
|
has_deferred.store(false, std::memory_order_release);
|
||||||
|
pending.swap(deferred);
|
||||||
|
}
|
||||||
|
if (pending.empty() || entries.empty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (auto it = entries.begin(); it != entries.end();) {
|
||||||
|
const Entry& entry = it->second;
|
||||||
|
const GPUVAddr entry_end = entry.gpu_addr + entry.size;
|
||||||
|
bool overlaps = false;
|
||||||
|
for (const DeferredUnmap& unmap : pending) {
|
||||||
|
if (unmap.as_id != entry.as_id) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (entry.gpu_addr < unmap.gpu_addr + unmap.size && unmap.gpu_addr < entry_end) {
|
||||||
|
overlaps = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (overlaps) {
|
||||||
|
it = entries.erase(it);
|
||||||
|
} else {
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::unordered_map<u64, Entry> entries;
|
||||||
|
std::vector<DeferredUnmap> deferred;
|
||||||
|
std::mutex deferred_mutex;
|
||||||
|
std::atomic<bool> has_deferred{false};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace VideoCommon
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#include "common/bit_field.h"
|
#include "common/bit_field.h"
|
||||||
#include "common/common_funcs.h"
|
#include "common/common_funcs.h"
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <cstddef>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#include "common/bit_field.h"
|
#include "common/bit_field.h"
|
||||||
#include "common/common_funcs.h"
|
#include "common/common_funcs.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/scratch_buffer.h"
|
#include "common/scratch_buffer.h"
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ constexpr std::array PROGRAM_LUT{
|
|||||||
Buffer::Buffer(BufferCacheRuntime&, VideoCommon::NullBufferParams null_params)
|
Buffer::Buffer(BufferCacheRuntime&, VideoCommon::NullBufferParams null_params)
|
||||||
: VideoCommon::BufferBase(null_params) {}
|
: VideoCommon::BufferBase(null_params) {}
|
||||||
|
|
||||||
Buffer::Buffer(BufferCacheRuntime& runtime, DAddr cpu_addr_, u64 size_bytes_)
|
Buffer::Buffer(BufferCacheRuntime& runtime, DAddr cpu_addr_, u64 size_bytes_, bool)
|
||||||
: VideoCommon::BufferBase(cpu_addr_, size_bytes_) {
|
: VideoCommon::BufferBase(cpu_addr_, size_bytes_) {
|
||||||
buffer.Create();
|
buffer.Create();
|
||||||
if (runtime.device.HasDebuggingToolAttached()) {
|
if (runtime.device.HasDebuggingToolAttached()) {
|
||||||
|
|||||||
@@ -23,7 +23,8 @@ class BufferCacheRuntime;
|
|||||||
|
|
||||||
class Buffer : public VideoCommon::BufferBase {
|
class Buffer : public VideoCommon::BufferBase {
|
||||||
public:
|
public:
|
||||||
explicit Buffer(BufferCacheRuntime&, DAddr cpu_addr, u64 size_bytes);
|
explicit Buffer(BufferCacheRuntime&, DAddr cpu_addr, u64 size_bytes,
|
||||||
|
bool sparse_compatible = false);
|
||||||
explicit Buffer(BufferCacheRuntime&, VideoCommon::NullBufferParams);
|
explicit Buffer(BufferCacheRuntime&, VideoCommon::NullBufferParams);
|
||||||
|
|
||||||
void ImmediateUpload(size_t offset, std::span<const u8> data) noexcept;
|
void ImmediateUpload(size_t offset, std::span<const u8> data) noexcept;
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ size_t BytesPerIndex(VkIndexType index_type) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vk::Buffer CreateBuffer(const Device& device, const MemoryAllocator& memory_allocator, u64 size) {
|
vk::Buffer CreateBuffer(const Device& device, const MemoryAllocator& memory_allocator, u64 size,
|
||||||
|
VkDeviceSize sparse_alignment) {
|
||||||
VkBufferUsageFlags flags =
|
VkBufferUsageFlags flags =
|
||||||
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT |
|
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT |
|
||||||
VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT |
|
VK_BUFFER_USAGE_UNIFORM_TEXEL_BUFFER_BIT | VK_BUFFER_USAGE_STORAGE_TEXEL_BUFFER_BIT |
|
||||||
@@ -82,6 +83,9 @@ vk::Buffer CreateBuffer(const Device& device, const MemoryAllocator& memory_allo
|
|||||||
.queueFamilyIndexCount = 0,
|
.queueFamilyIndexCount = 0,
|
||||||
.pQueueFamilyIndices = nullptr,
|
.pQueueFamilyIndices = nullptr,
|
||||||
};
|
};
|
||||||
|
if (sparse_alignment > 1) {
|
||||||
|
return memory_allocator.CreateBuffer(buffer_ci, MemoryUsage::DeviceLocal, sparse_alignment);
|
||||||
|
}
|
||||||
return memory_allocator.CreateBuffer(buffer_ci, MemoryUsage::DeviceLocal);
|
return memory_allocator.CreateBuffer(buffer_ci, MemoryUsage::DeviceLocal);
|
||||||
}
|
}
|
||||||
} // Anonymous namespace
|
} // Anonymous namespace
|
||||||
@@ -99,10 +103,14 @@ Buffer::Buffer(BufferCacheRuntime& runtime, VideoCommon::NullBufferParams null_p
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Buffer::Buffer(BufferCacheRuntime& runtime, DAddr cpu_addr_, u64 size_bytes_)
|
Buffer::Buffer(BufferCacheRuntime& runtime, DAddr cpu_addr_, u64 size_bytes_,
|
||||||
|
bool sparse_compatible_)
|
||||||
: VideoCommon::BufferBase(cpu_addr_, size_bytes_), device{&runtime.device},
|
: VideoCommon::BufferBase(cpu_addr_, size_bytes_), device{&runtime.device},
|
||||||
scheduler{&runtime.scheduler},
|
scheduler{&runtime.scheduler},
|
||||||
buffer{CreateBuffer(*device, runtime.memory_allocator, SizeBytes())}, tracker{SizeBytes()} {
|
buffer{CreateBuffer(*device, runtime.memory_allocator, SizeBytes(),
|
||||||
|
runtime.SparseAlignmentFor(sparse_compatible_))},
|
||||||
|
tracker{SizeBytes()} {
|
||||||
|
sparse_compatible = sparse_compatible_;
|
||||||
if (runtime.device.HasDebuggingToolAttached()) {
|
if (runtime.device.HasDebuggingToolAttached()) {
|
||||||
buffer.SetObjectNameEXT(fmt::format("Buffer {:#x}", CpuAddr()).c_str());
|
buffer.SetObjectNameEXT(fmt::format("Buffer {:#x}", CpuAddr()).c_str());
|
||||||
}
|
}
|
||||||
@@ -348,7 +356,8 @@ BufferCacheRuntime::BufferCacheRuntime(const Device& device_, MemoryAllocator& m
|
|||||||
: device{device_}, memory_allocator{memory_allocator_}, scheduler{scheduler_},
|
: device{device_}, memory_allocator{memory_allocator_}, scheduler{scheduler_},
|
||||||
staging_pool{staging_pool_}, guest_descriptor_queue{guest_descriptor_queue_},
|
staging_pool{staging_pool_}, guest_descriptor_queue{guest_descriptor_queue_},
|
||||||
quad_index_pass(device, scheduler, descriptor_pool, staging_pool,
|
quad_index_pass(device, scheduler, descriptor_pool, staging_pool,
|
||||||
compute_pass_descriptor_queue) {
|
compute_pass_descriptor_queue),
|
||||||
|
multi_range_buffers(device_, memory_allocator_, scheduler_) {
|
||||||
const VkDriverIdKHR driver_id = device.GetDriverID();
|
const VkDriverIdKHR driver_id = device.GetDriverID();
|
||||||
limit_dynamic_storage_buffers = driver_id == VK_DRIVER_ID_QUALCOMM_PROPRIETARY ||
|
limit_dynamic_storage_buffers = driver_id == VK_DRIVER_ID_QUALCOMM_PROPRIETARY ||
|
||||||
driver_id == VK_DRIVER_ID_ARM_PROPRIETARY;
|
driver_id == VK_DRIVER_ID_ARM_PROPRIETARY;
|
||||||
@@ -536,6 +545,33 @@ void BufferCacheRuntime::ClearBuffer(VkBuffer dest_buffer, u32 offset, size_t si
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool BufferCacheRuntime::BindMultiRangeStorageBuffer(u64 key) {
|
||||||
|
if (multi_range_sources.empty() || multi_range_total == 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const MultiRangeRef ref = multi_range_buffers.Get(key, multi_range_sources, multi_range_total);
|
||||||
|
if (ref.handle == VK_NULL_HANDLE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (ref.needs_gather) {
|
||||||
|
PreCopyBarrier();
|
||||||
|
VkDeviceSize dst_offset = 0;
|
||||||
|
for (const MultiRangeSource& source : multi_range_sources) {
|
||||||
|
const std::array<VideoCommon::BufferCopy, 1> copy{VideoCommon::BufferCopy{
|
||||||
|
.src_offset = static_cast<u64>(source.offset),
|
||||||
|
.dst_offset = static_cast<u64>(dst_offset),
|
||||||
|
.size = static_cast<size_t>(source.size),
|
||||||
|
}};
|
||||||
|
CopyBuffer(ref.handle, source.handle, copy, false);
|
||||||
|
dst_offset += source.size;
|
||||||
|
}
|
||||||
|
PostCopyBarrier();
|
||||||
|
multi_range_buffers.MarkGathered(key);
|
||||||
|
}
|
||||||
|
guest_descriptor_queue.AddBuffer(ref.handle, ref.address, 0, ref.size);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void BufferCacheRuntime::BindIndexBuffer(PrimitiveTopology topology, IndexFormat index_format,
|
void BufferCacheRuntime::BindIndexBuffer(PrimitiveTopology topology, IndexFormat index_format,
|
||||||
u32 base_vertex, u32 num_indices, VkBuffer buffer,
|
u32 base_vertex, u32 num_indices, VkBuffer buffer,
|
||||||
u32 offset, [[maybe_unused]] u32 size) {
|
u32 offset, [[maybe_unused]] u32 size) {
|
||||||
|
|||||||
@@ -8,11 +8,14 @@
|
|||||||
|
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
|
#include <boost/container/small_vector.hpp>
|
||||||
|
|
||||||
#include "video_core/buffer_cache/buffer_cache_base.h"
|
#include "video_core/buffer_cache/buffer_cache_base.h"
|
||||||
#include "video_core/buffer_cache/memory_tracker_base.h"
|
#include "video_core/buffer_cache/memory_tracker_base.h"
|
||||||
#include "video_core/buffer_cache/usage_tracker.h"
|
#include "video_core/buffer_cache/usage_tracker.h"
|
||||||
#include "video_core/engines/maxwell_3d.h"
|
#include "video_core/engines/maxwell_3d.h"
|
||||||
#include "video_core/renderer_vulkan/vk_compute_pass.h"
|
#include "video_core/renderer_vulkan/vk_compute_pass.h"
|
||||||
|
#include "video_core/renderer_vulkan/vk_multi_range_buffer.h"
|
||||||
#include "video_core/renderer_vulkan/vk_staging_buffer_pool.h"
|
#include "video_core/renderer_vulkan/vk_staging_buffer_pool.h"
|
||||||
#include "video_core/renderer_vulkan/vk_update_descriptor.h"
|
#include "video_core/renderer_vulkan/vk_update_descriptor.h"
|
||||||
#include "video_core/surface.h"
|
#include "video_core/surface.h"
|
||||||
@@ -31,7 +34,8 @@ class BufferCacheRuntime;
|
|||||||
class Buffer : public VideoCommon::BufferBase {
|
class Buffer : public VideoCommon::BufferBase {
|
||||||
public:
|
public:
|
||||||
explicit Buffer(BufferCacheRuntime&, VideoCommon::NullBufferParams null_params);
|
explicit Buffer(BufferCacheRuntime&, VideoCommon::NullBufferParams null_params);
|
||||||
explicit Buffer(BufferCacheRuntime& runtime, VAddr cpu_addr_, u64 size_bytes_);
|
explicit Buffer(BufferCacheRuntime& runtime, VAddr cpu_addr_, u64 size_bytes_,
|
||||||
|
bool sparse_compatible_ = false);
|
||||||
|
|
||||||
[[nodiscard]] VkBufferView View(u32 offset, u32 size, VideoCore::Surface::PixelFormat format);
|
[[nodiscard]] VkBufferView View(u32 offset, u32 size, VideoCore::Surface::PixelFormat format);
|
||||||
|
|
||||||
@@ -43,6 +47,14 @@ public:
|
|||||||
return device_address;
|
return device_address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool IsSparseCompatible() const noexcept {
|
||||||
|
return sparse_compatible;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] vk::MemoryLocation Location() const noexcept {
|
||||||
|
return buffer.Location();
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool IsRegionUsed(u64 offset, u64 size) const noexcept {
|
[[nodiscard]] bool IsRegionUsed(u64 offset, u64 size) const noexcept {
|
||||||
return tracker.IsUsed(offset, size);
|
return tracker.IsUsed(offset, size);
|
||||||
}
|
}
|
||||||
@@ -77,6 +89,7 @@ private:
|
|||||||
VkDeviceAddress device_address{};
|
VkDeviceAddress device_address{};
|
||||||
u64 last_usage_tick{};
|
u64 last_usage_tick{};
|
||||||
bool is_null{};
|
bool is_null{};
|
||||||
|
bool sparse_compatible{};
|
||||||
};
|
};
|
||||||
|
|
||||||
class QuadArrayIndexBuffer;
|
class QuadArrayIndexBuffer;
|
||||||
@@ -125,7 +138,7 @@ public:
|
|||||||
|
|
||||||
void PreCopyBarrier();
|
void PreCopyBarrier();
|
||||||
|
|
||||||
void CopyBuffer(VkBuffer src_buffer, VkBuffer dst_buffer,
|
void CopyBuffer(VkBuffer dst_buffer, VkBuffer src_buffer,
|
||||||
std::span<const VideoCommon::BufferCopy> copies, bool barrier,
|
std::span<const VideoCommon::BufferCopy> copies, bool barrier,
|
||||||
bool can_reorder_upload = false);
|
bool can_reorder_upload = false);
|
||||||
|
|
||||||
@@ -155,6 +168,40 @@ public:
|
|||||||
return ref.mapped_span;
|
return ref.mapped_span;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] VkDeviceSize SparseAlignmentFor(bool sparse_compatible) const noexcept {
|
||||||
|
if (!sparse_compatible || !multi_range_buffers.UsesSparse()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return multi_range_buffers.BlockSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool PrefersSparseSources() const noexcept {
|
||||||
|
return multi_range_buffers.UsesSparse();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ResetMultiRange() noexcept {
|
||||||
|
multi_range_sources.clear();
|
||||||
|
multi_range_total = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PushMultiRangeSource(const Buffer& buffer, u32 offset, u32 size) {
|
||||||
|
const vk::MemoryLocation location = buffer.Location();
|
||||||
|
multi_range_sources.push_back(MultiRangeSource{
|
||||||
|
.handle = buffer.Handle(),
|
||||||
|
.memory = location.memory,
|
||||||
|
.memory_offset = location.offset,
|
||||||
|
.offset = offset,
|
||||||
|
.size = size,
|
||||||
|
});
|
||||||
|
multi_range_total += size;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BindMultiRangeStorageBuffer(u64 key);
|
||||||
|
|
||||||
|
void InvalidateMultiRange(u64 key) {
|
||||||
|
multi_range_buffers.Invalidate(key);
|
||||||
|
}
|
||||||
|
|
||||||
void BindUniformBuffer(const Buffer& buffer, u32 offset, u32 size) {
|
void BindUniformBuffer(const Buffer& buffer, u32 offset, u32 size) {
|
||||||
BindBuffer(buffer, offset, size);
|
BindBuffer(buffer, offset, size);
|
||||||
}
|
}
|
||||||
@@ -208,6 +255,10 @@ private:
|
|||||||
std::unique_ptr<Uint8Pass> uint8_pass;
|
std::unique_ptr<Uint8Pass> uint8_pass;
|
||||||
QuadIndexedPass quad_index_pass;
|
QuadIndexedPass quad_index_pass;
|
||||||
|
|
||||||
|
MultiRangeBufferCache multi_range_buffers;
|
||||||
|
boost::container::small_vector<MultiRangeSource, 16> multi_range_sources;
|
||||||
|
VkDeviceSize multi_range_total{};
|
||||||
|
|
||||||
bool limit_dynamic_storage_buffers = false;
|
bool limit_dynamic_storage_buffers = false;
|
||||||
u32 max_dynamic_storage_buffers = (std::numeric_limits<u32>::max)();
|
u32 max_dynamic_storage_buffers = (std::numeric_limits<u32>::max)();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,304 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
#include <mutex>
|
||||||
|
|
||||||
|
#include "video_core/renderer_vulkan/vk_multi_range_buffer.h"
|
||||||
|
#include "video_core/renderer_vulkan/vk_scheduler.h"
|
||||||
|
#include "video_core/vulkan_common/vulkan_device.h"
|
||||||
|
|
||||||
|
namespace Vulkan {
|
||||||
|
|
||||||
|
MultiRangeBufferCache::MultiRangeBufferCache(const Device& device_,
|
||||||
|
MemoryAllocator& memory_allocator_,
|
||||||
|
Scheduler& scheduler_)
|
||||||
|
: device{device_}, memory_allocator{memory_allocator_}, scheduler{scheduler_} {
|
||||||
|
sparse_usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT |
|
||||||
|
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
|
||||||
|
if (device.IsBufferDeviceAddressSupported()) {
|
||||||
|
sparse_usage |= VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT;
|
||||||
|
}
|
||||||
|
if (!device.IsSparseBindingSupported()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const VkDeviceSize queried = QueryBlockSize();
|
||||||
|
if (queried == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
block_size = queried;
|
||||||
|
use_sparse = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
MultiRangeBufferCache::~MultiRangeBufferCache() {
|
||||||
|
const VkDevice logical = *device.GetLogical();
|
||||||
|
const auto& dld = device.GetDispatchLoader();
|
||||||
|
for (auto& [key, entry] : entries) {
|
||||||
|
if (entry.sparse_handle != VK_NULL_HANDLE) {
|
||||||
|
dld.vkDestroyBuffer(logical, entry.sparse_handle, nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
entries.clear();
|
||||||
|
for (const Retired& item : retired) {
|
||||||
|
dld.vkDestroyBuffer(logical, item.handle, nullptr);
|
||||||
|
}
|
||||||
|
retired.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
VkDeviceSize MultiRangeBufferCache::QueryBlockSize() const {
|
||||||
|
const VkDevice logical = *device.GetLogical();
|
||||||
|
const auto& dld = device.GetDispatchLoader();
|
||||||
|
const VkBufferCreateInfo probe_ci{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = VK_BUFFER_CREATE_SPARSE_BINDING_BIT | VK_BUFFER_CREATE_SPARSE_ALIASED_BIT,
|
||||||
|
.size = DEFAULT_BLOCK_SIZE,
|
||||||
|
.usage = sparse_usage,
|
||||||
|
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
||||||
|
.queueFamilyIndexCount = 0,
|
||||||
|
.pQueueFamilyIndices = nullptr,
|
||||||
|
};
|
||||||
|
VkBuffer probe{};
|
||||||
|
if (dld.vkCreateBuffer(logical, &probe_ci, nullptr, &probe) != VK_SUCCESS) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
const VkBufferMemoryRequirementsInfo2 reqs_info{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.buffer = probe,
|
||||||
|
};
|
||||||
|
VkMemoryRequirements2 reqs2{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.memoryRequirements = {},
|
||||||
|
};
|
||||||
|
dld.vkGetBufferMemoryRequirements2(logical, &reqs_info, &reqs2);
|
||||||
|
dld.vkDestroyBuffer(logical, probe, nullptr);
|
||||||
|
return reqs2.memoryRequirements.alignment;
|
||||||
|
}
|
||||||
|
|
||||||
|
u64 MultiRangeBufferCache::HashSources(std::span<const MultiRangeSource> sources) const {
|
||||||
|
u64 hash = 0xcbf29ce484222325ULL;
|
||||||
|
const auto mix = [&hash](u64 value) {
|
||||||
|
hash ^= value;
|
||||||
|
hash *= 0x100000001b3ULL;
|
||||||
|
};
|
||||||
|
for (const MultiRangeSource& source : sources) {
|
||||||
|
mix(reinterpret_cast<u64>(source.handle));
|
||||||
|
mix(static_cast<u64>(source.offset));
|
||||||
|
mix(static_cast<u64>(source.size));
|
||||||
|
}
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MultiRangeBufferCache::CanBindSparse(std::span<const MultiRangeSource> sources) const {
|
||||||
|
if (!use_sparse) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
for (const MultiRangeSource& source : sources) {
|
||||||
|
if (source.memory == VK_NULL_HANDLE) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const VkDeviceSize memory_offset = source.memory_offset + source.offset;
|
||||||
|
if ((memory_offset % block_size) != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((source.size % block_size) != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
VkBuffer MultiRangeBufferCache::CreateSparse(std::span<const MultiRangeSource> sources,
|
||||||
|
VkDeviceSize total) {
|
||||||
|
const VkDevice logical = *device.GetLogical();
|
||||||
|
const auto& dld = device.GetDispatchLoader();
|
||||||
|
const VkBufferCreateInfo buffer_ci{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = VK_BUFFER_CREATE_SPARSE_BINDING_BIT | VK_BUFFER_CREATE_SPARSE_ALIASED_BIT,
|
||||||
|
.size = total,
|
||||||
|
.usage = sparse_usage,
|
||||||
|
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
||||||
|
.queueFamilyIndexCount = 0,
|
||||||
|
.pQueueFamilyIndices = nullptr,
|
||||||
|
};
|
||||||
|
VkBuffer handle{};
|
||||||
|
if (dld.vkCreateBuffer(logical, &buffer_ci, nullptr, &handle) != VK_SUCCESS) {
|
||||||
|
return VK_NULL_HANDLE;
|
||||||
|
}
|
||||||
|
std::vector<VkSparseMemoryBind> binds;
|
||||||
|
binds.reserve(sources.size());
|
||||||
|
VkDeviceSize resource_offset = 0;
|
||||||
|
for (const MultiRangeSource& source : sources) {
|
||||||
|
binds.push_back(VkSparseMemoryBind{
|
||||||
|
.resourceOffset = resource_offset,
|
||||||
|
.size = source.size,
|
||||||
|
.memory = source.memory,
|
||||||
|
.memoryOffset = source.memory_offset + source.offset,
|
||||||
|
.flags = 0,
|
||||||
|
});
|
||||||
|
resource_offset += source.size;
|
||||||
|
}
|
||||||
|
const VkSparseBufferMemoryBindInfo buffer_bind{
|
||||||
|
.buffer = handle,
|
||||||
|
.bindCount = static_cast<u32>(binds.size()),
|
||||||
|
.pBinds = binds.data(),
|
||||||
|
};
|
||||||
|
const VkBindSparseInfo bind_info{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_BIND_SPARSE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.waitSemaphoreCount = 0,
|
||||||
|
.pWaitSemaphores = nullptr,
|
||||||
|
.bufferBindCount = 1,
|
||||||
|
.pBufferBinds = &buffer_bind,
|
||||||
|
.imageOpaqueBindCount = 0,
|
||||||
|
.pImageOpaqueBinds = nullptr,
|
||||||
|
.imageBindCount = 0,
|
||||||
|
.pImageBinds = nullptr,
|
||||||
|
.signalSemaphoreCount = 0,
|
||||||
|
.pSignalSemaphores = nullptr,
|
||||||
|
};
|
||||||
|
const VkFenceCreateInfo fence_ci{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
};
|
||||||
|
vk::Fence fence = device.GetLogical().CreateFence(fence_ci);
|
||||||
|
VkResult bind_result = VK_ERROR_UNKNOWN;
|
||||||
|
{
|
||||||
|
std::scoped_lock lock{scheduler.submit_mutex};
|
||||||
|
bind_result = device.GetGraphicsQueue().BindSparse(bind_info, *fence);
|
||||||
|
}
|
||||||
|
if (bind_result != VK_SUCCESS) {
|
||||||
|
dld.vkDestroyBuffer(logical, handle, nullptr);
|
||||||
|
return VK_NULL_HANDLE;
|
||||||
|
}
|
||||||
|
fence.Wait();
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MultiRangeBufferCache::DestroySparse(VkBuffer handle) {
|
||||||
|
if (handle == VK_NULL_HANDLE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
retired.push_back(Retired{
|
||||||
|
.handle = handle,
|
||||||
|
.tick = scheduler.CurrentTick(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void MultiRangeBufferCache::DrainRetired() {
|
||||||
|
const VkDevice logical = *device.GetLogical();
|
||||||
|
const auto& dld = device.GetDispatchLoader();
|
||||||
|
size_t index = 0;
|
||||||
|
while (index < retired.size()) {
|
||||||
|
if (scheduler.IsFree(retired[index].tick)) {
|
||||||
|
dld.vkDestroyBuffer(logical, retired[index].handle, nullptr);
|
||||||
|
retired[index] = retired.back();
|
||||||
|
retired.pop_back();
|
||||||
|
} else {
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MultiRangeRef MultiRangeBufferCache::Get(u64 key, std::span<const MultiRangeSource> sources,
|
||||||
|
VkDeviceSize total) {
|
||||||
|
if (sources.empty() || total == 0) {
|
||||||
|
return MultiRangeRef{};
|
||||||
|
}
|
||||||
|
if (!retired.empty()) {
|
||||||
|
DrainRetired();
|
||||||
|
}
|
||||||
|
const u64 geometry = HashSources(sources);
|
||||||
|
const auto it = entries.find(key);
|
||||||
|
if (it != entries.end() && it->second.geometry == geometry && it->second.size == total) {
|
||||||
|
Entry& entry = it->second;
|
||||||
|
MultiRangeRef ref{
|
||||||
|
.handle = entry.sparse_handle,
|
||||||
|
.address = entry.address,
|
||||||
|
.size = entry.size,
|
||||||
|
.needs_gather = false,
|
||||||
|
};
|
||||||
|
if (entry.sparse_handle == VK_NULL_HANDLE) {
|
||||||
|
ref.handle = *entry.gathered;
|
||||||
|
ref.needs_gather = entry.dirty;
|
||||||
|
}
|
||||||
|
return ref;
|
||||||
|
}
|
||||||
|
if (it != entries.end()) {
|
||||||
|
DestroySparse(it->second.sparse_handle);
|
||||||
|
entries.erase(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
Entry entry;
|
||||||
|
entry.geometry = geometry;
|
||||||
|
entry.size = total;
|
||||||
|
if (CanBindSparse(sources)) {
|
||||||
|
entry.sparse_handle = CreateSparse(sources, total);
|
||||||
|
}
|
||||||
|
if (entry.sparse_handle == VK_NULL_HANDLE) {
|
||||||
|
VkBufferUsageFlags flags = VK_BUFFER_USAGE_TRANSFER_SRC_BIT |
|
||||||
|
VK_BUFFER_USAGE_TRANSFER_DST_BIT |
|
||||||
|
VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
|
||||||
|
if (device.IsBufferDeviceAddressSupported()) {
|
||||||
|
flags |= VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT;
|
||||||
|
}
|
||||||
|
const VkBufferCreateInfo gather_ci{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.flags = 0,
|
||||||
|
.size = total,
|
||||||
|
.usage = flags,
|
||||||
|
.sharingMode = VK_SHARING_MODE_EXCLUSIVE,
|
||||||
|
.queueFamilyIndexCount = 0,
|
||||||
|
.pQueueFamilyIndices = nullptr,
|
||||||
|
};
|
||||||
|
entry.gathered = memory_allocator.CreateBuffer(gather_ci, MemoryUsage::DeviceLocal);
|
||||||
|
entry.dirty = true;
|
||||||
|
}
|
||||||
|
if (device.IsBufferDeviceAddressSupported()) {
|
||||||
|
VkBuffer address_handle = entry.sparse_handle;
|
||||||
|
if (address_handle == VK_NULL_HANDLE) {
|
||||||
|
address_handle = *entry.gathered;
|
||||||
|
}
|
||||||
|
entry.address = device.GetLogical().GetBufferDeviceAddress(address_handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
MultiRangeRef ref{
|
||||||
|
.handle = entry.sparse_handle,
|
||||||
|
.address = entry.address,
|
||||||
|
.size = entry.size,
|
||||||
|
.needs_gather = false,
|
||||||
|
};
|
||||||
|
if (entry.sparse_handle == VK_NULL_HANDLE) {
|
||||||
|
ref.handle = *entry.gathered;
|
||||||
|
ref.needs_gather = true;
|
||||||
|
}
|
||||||
|
entries.emplace(key, std::move(entry));
|
||||||
|
return ref;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MultiRangeBufferCache::MarkGathered(u64 key) {
|
||||||
|
const auto it = entries.find(key);
|
||||||
|
if (it != entries.end()) {
|
||||||
|
it->second.dirty = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MultiRangeBufferCache::Invalidate(u64 key) {
|
||||||
|
const auto it = entries.find(key);
|
||||||
|
if (it != entries.end()) {
|
||||||
|
it->second.dirty = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MultiRangeBufferCache::Clear() {
|
||||||
|
for (auto& [key, entry] : entries) {
|
||||||
|
DestroySparse(entry.sparse_handle);
|
||||||
|
}
|
||||||
|
entries.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Vulkan
|
||||||
@@ -0,0 +1,100 @@
|
|||||||
|
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
||||||
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <span>
|
||||||
|
#include <unordered_map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include "common/common_types.h"
|
||||||
|
#include "video_core/vulkan_common/vulkan_memory_allocator.h"
|
||||||
|
#include "video_core/vulkan_common/vulkan_wrapper.h"
|
||||||
|
|
||||||
|
namespace Vulkan {
|
||||||
|
|
||||||
|
class Device;
|
||||||
|
class Scheduler;
|
||||||
|
|
||||||
|
struct MultiRangeSource {
|
||||||
|
VkBuffer handle{};
|
||||||
|
VkDeviceMemory memory{};
|
||||||
|
VkDeviceSize memory_offset{};
|
||||||
|
VkDeviceSize offset{};
|
||||||
|
VkDeviceSize size{};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MultiRangeRef {
|
||||||
|
VkBuffer handle{};
|
||||||
|
VkDeviceAddress address{};
|
||||||
|
VkDeviceSize size{};
|
||||||
|
bool needs_gather{};
|
||||||
|
};
|
||||||
|
|
||||||
|
class MultiRangeBufferCache final {
|
||||||
|
public:
|
||||||
|
static constexpr VkDeviceSize DEFAULT_BLOCK_SIZE = 64 * 1024;
|
||||||
|
|
||||||
|
explicit MultiRangeBufferCache(const Device& device_, MemoryAllocator& memory_allocator_,
|
||||||
|
Scheduler& scheduler_);
|
||||||
|
~MultiRangeBufferCache();
|
||||||
|
|
||||||
|
MultiRangeBufferCache(const MultiRangeBufferCache&) = delete;
|
||||||
|
MultiRangeBufferCache& operator=(const MultiRangeBufferCache&) = delete;
|
||||||
|
|
||||||
|
[[nodiscard]] bool UsesSparse() const noexcept {
|
||||||
|
return use_sparse;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] VkDeviceSize BlockSize() const noexcept {
|
||||||
|
return block_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] MultiRangeRef Get(u64 key, std::span<const MultiRangeSource> sources,
|
||||||
|
VkDeviceSize total);
|
||||||
|
|
||||||
|
void MarkGathered(u64 key);
|
||||||
|
|
||||||
|
void Invalidate(u64 key);
|
||||||
|
|
||||||
|
void Clear();
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct Retired {
|
||||||
|
VkBuffer handle{};
|
||||||
|
u64 tick{};
|
||||||
|
};
|
||||||
|
|
||||||
|
struct Entry {
|
||||||
|
vk::Buffer gathered;
|
||||||
|
VkBuffer sparse_handle{};
|
||||||
|
VkDeviceAddress address{};
|
||||||
|
VkDeviceSize size{};
|
||||||
|
u64 geometry{};
|
||||||
|
bool dirty{true};
|
||||||
|
};
|
||||||
|
|
||||||
|
[[nodiscard]] u64 HashSources(std::span<const MultiRangeSource> sources) const;
|
||||||
|
|
||||||
|
[[nodiscard]] bool CanBindSparse(std::span<const MultiRangeSource> sources) const;
|
||||||
|
|
||||||
|
[[nodiscard]] VkBuffer CreateSparse(std::span<const MultiRangeSource> sources,
|
||||||
|
VkDeviceSize total);
|
||||||
|
|
||||||
|
[[nodiscard]] VkDeviceSize QueryBlockSize() const;
|
||||||
|
|
||||||
|
void DestroySparse(VkBuffer handle);
|
||||||
|
|
||||||
|
void DrainRetired();
|
||||||
|
|
||||||
|
const Device& device;
|
||||||
|
MemoryAllocator& memory_allocator;
|
||||||
|
Scheduler& scheduler;
|
||||||
|
bool use_sparse{};
|
||||||
|
VkDeviceSize block_size{DEFAULT_BLOCK_SIZE};
|
||||||
|
VkBufferUsageFlags sparse_usage{};
|
||||||
|
std::unordered_map<u64, Entry> entries;
|
||||||
|
std::vector<Retired> retired;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Vulkan
|
||||||
@@ -338,7 +338,7 @@ void PresentManager::PresentThread(std::stop_token token) {
|
|||||||
// By exchanging the lock ownership we take the swapchain lock
|
// By exchanging the lock ownership we take the swapchain lock
|
||||||
// before the queue lock goes out of scope. This way the swapchain
|
// before the queue lock goes out of scope. This way the swapchain
|
||||||
// lock in WaitPresent is guaranteed to occur after here.
|
// lock in WaitPresent is guaranteed to occur after here.
|
||||||
std::exchange(lock, std::unique_lock{swapchain_mutex});
|
void(std::exchange(lock, std::unique_lock{swapchain_mutex}));
|
||||||
CopyToSwapchain(frame);
|
CopyToSwapchain(frame);
|
||||||
|
|
||||||
// Free the frame for reuse
|
// Free the frame for reuse
|
||||||
|
|||||||
@@ -819,6 +819,7 @@ void RasterizerVulkan::ModifyGPUMemory(size_t as_id, GPUVAddr addr, u64 size) {
|
|||||||
std::scoped_lock lock{texture_cache.mutex};
|
std::scoped_lock lock{texture_cache.mutex};
|
||||||
texture_cache.UnmapGPUMemory(as_id, addr, size);
|
texture_cache.UnmapGPUMemory(as_id, addr, size);
|
||||||
}
|
}
|
||||||
|
buffer_cache.UnmapGPUMemory(as_id, addr, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RasterizerVulkan::SignalFence(std::function<void()>&& func) {
|
void RasterizerVulkan::SignalFence(std::function<void()>&& func) {
|
||||||
|
|||||||
@@ -300,7 +300,7 @@ void Scheduler::WorkerThread(std::stop_token stop_token) {
|
|||||||
// Exchange lock ownership so that we take the execution lock before
|
// Exchange lock ownership so that we take the execution lock before
|
||||||
// the queue lock goes out of scope. This allows us to force execution
|
// the queue lock goes out of scope. This allows us to force execution
|
||||||
// to complete in the next step.
|
// to complete in the next step.
|
||||||
std::exchange(lk, std::unique_lock{execution_mutex});
|
void(std::exchange(lk, std::unique_lock{execution_mutex}));
|
||||||
|
|
||||||
// Perform the work, tracking whether the chunk was a submission
|
// Perform the work, tracking whether the chunk was a submission
|
||||||
// before executing.
|
// before executing.
|
||||||
|
|||||||
@@ -1570,6 +1570,8 @@ void Device::SetupFamilies(VkSurfaceKHR surface) {
|
|||||||
}
|
}
|
||||||
if (graphics) {
|
if (graphics) {
|
||||||
graphics_family = *graphics;
|
graphics_family = *graphics;
|
||||||
|
graphics_family_sparse_binding =
|
||||||
|
(queue_family_properties[*graphics].queueFlags & VK_QUEUE_SPARSE_BINDING_BIT) != 0;
|
||||||
}
|
}
|
||||||
if (present) {
|
if (present) {
|
||||||
present_family = *present;
|
present_family = *present;
|
||||||
|
|||||||
@@ -317,6 +317,10 @@ public:
|
|||||||
return properties.driver.driverID;
|
return properties.driver.driverID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool IsSparseBindingSupported() const {
|
||||||
|
return features.features.sparseBinding && graphics_family_sparse_binding;
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true for tile-based deferred renderers.
|
/// Returns true for tile-based deferred renderers.
|
||||||
bool IsTiler() const {
|
bool IsTiler() const {
|
||||||
switch (GetDriverID()) {
|
switch (GetDriverID()) {
|
||||||
@@ -1146,6 +1150,7 @@ private:
|
|||||||
bool owns_static_pipeline_cache{};
|
bool owns_static_pipeline_cache{};
|
||||||
u32 instance_version{}; ///< Vulkan instance version.
|
u32 instance_version{}; ///< Vulkan instance version.
|
||||||
u32 graphics_family{}; ///< Main graphics queue family index.
|
u32 graphics_family{}; ///< Main graphics queue family index.
|
||||||
|
bool graphics_family_sparse_binding{};
|
||||||
u32 present_family{}; ///< Main present queue family index.
|
u32 present_family{}; ///< Main present queue family index.
|
||||||
|
|
||||||
struct Extensions {
|
struct Extensions {
|
||||||
|
|||||||
@@ -26,350 +26,408 @@
|
|||||||
#include "common/settings.h"
|
#include "common/settings.h"
|
||||||
|
|
||||||
namespace Vulkan {
|
namespace Vulkan {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
// Helpers translating MemoryUsage to flags/usage
|
// Helpers translating MemoryUsage to flags/usage
|
||||||
|
|
||||||
[[maybe_unused]] VkMemoryPropertyFlags MemoryUsagePropertyFlags(MemoryUsage usage) {
|
[[maybe_unused]] VkMemoryPropertyFlags MemoryUsagePropertyFlags(MemoryUsage usage) {
|
||||||
switch (usage) {
|
switch (usage) {
|
||||||
case MemoryUsage::DeviceLocal:
|
case MemoryUsage::DeviceLocal:
|
||||||
return VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
return VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
||||||
case MemoryUsage::Upload:
|
case MemoryUsage::Upload:
|
||||||
return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
|
return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
|
||||||
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
||||||
case MemoryUsage::Download:
|
case MemoryUsage::Download:
|
||||||
return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
|
return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
|
||||||
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
|
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT |
|
||||||
VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
|
VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
|
||||||
case MemoryUsage::Stream:
|
case MemoryUsage::Stream:
|
||||||
return VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
|
return VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT |
|
||||||
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
|
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT |
|
||||||
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
||||||
}
|
|
||||||
ASSERT_MSG(false, "Invalid memory usage={}", usage);
|
|
||||||
return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
|
||||||
}
|
}
|
||||||
|
ASSERT_MSG(false, "Invalid memory usage={}", usage);
|
||||||
|
return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] VkMemoryPropertyFlags MemoryUsagePreferredVmaFlags(MemoryUsage usage) {
|
[[nodiscard]] VkMemoryPropertyFlags MemoryUsagePreferredVmaFlags(MemoryUsage usage) {
|
||||||
if (usage == MemoryUsage::Download) {
|
if (usage == MemoryUsage::Download) {
|
||||||
return VK_MEMORY_PROPERTY_HOST_CACHED_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
return VK_MEMORY_PROPERTY_HOST_CACHED_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
||||||
}
|
|
||||||
return usage != MemoryUsage::DeviceLocal ? VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
|
||||||
: VkMemoryPropertyFlagBits{};
|
|
||||||
}
|
}
|
||||||
|
return usage != MemoryUsage::DeviceLocal ? VK_MEMORY_PROPERTY_HOST_COHERENT_BIT
|
||||||
|
: VkMemoryPropertyFlagBits{};
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] VmaAllocationCreateFlags MemoryUsageVmaFlags(MemoryUsage usage) {
|
[[nodiscard]] VmaAllocationCreateFlags MemoryUsageVmaFlags(MemoryUsage usage) {
|
||||||
switch (usage) {
|
switch (usage) {
|
||||||
case MemoryUsage::Upload:
|
case MemoryUsage::Upload:
|
||||||
case MemoryUsage::Stream:
|
case MemoryUsage::Stream:
|
||||||
return VMA_ALLOCATION_CREATE_MAPPED_BIT |
|
return VMA_ALLOCATION_CREATE_MAPPED_BIT |
|
||||||
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT;
|
VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT;
|
||||||
case MemoryUsage::Download:
|
case MemoryUsage::Download:
|
||||||
return VMA_ALLOCATION_CREATE_MAPPED_BIT |
|
return VMA_ALLOCATION_CREATE_MAPPED_BIT |
|
||||||
VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT;
|
VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT;
|
||||||
case MemoryUsage::DeviceLocal:
|
case MemoryUsage::DeviceLocal:
|
||||||
return {};
|
return {};
|
||||||
}
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] VmaMemoryUsage MemoryUsageVma(MemoryUsage usage) {
|
[[nodiscard]] VmaMemoryUsage MemoryUsageVma(MemoryUsage usage) {
|
||||||
switch (usage) {
|
switch (usage) {
|
||||||
case MemoryUsage::DeviceLocal:
|
case MemoryUsage::DeviceLocal:
|
||||||
case MemoryUsage::Stream:
|
case MemoryUsage::Stream:
|
||||||
return VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE;
|
return VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE;
|
||||||
case MemoryUsage::Upload:
|
case MemoryUsage::Upload:
|
||||||
case MemoryUsage::Download:
|
case MemoryUsage::Download:
|
||||||
return VMA_MEMORY_USAGE_AUTO_PREFER_HOST;
|
return VMA_MEMORY_USAGE_AUTO_PREFER_HOST;
|
||||||
}
|
|
||||||
return VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE;
|
|
||||||
}
|
}
|
||||||
|
return VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE;
|
||||||
|
}
|
||||||
// This avoids calling vkGetBufferMemoryRequirements* directly.
|
} // namespace
|
||||||
template<typename T>
|
|
||||||
static VkBuffer GetVkHandleFromBuffer(const T &buf) {
|
|
||||||
if constexpr (requires { static_cast<VkBuffer>(buf); }) {
|
|
||||||
return static_cast<VkBuffer>(buf);
|
|
||||||
} else if constexpr (requires {{ buf.GetHandle() } -> std::convertible_to<VkBuffer>; }) {
|
|
||||||
return buf.GetHandle();
|
|
||||||
} else if constexpr (requires {{ buf.Handle() } -> std::convertible_to<VkBuffer>; }) {
|
|
||||||
return buf.Handle();
|
|
||||||
} else if constexpr (requires {{ buf.vk_handle() } -> std::convertible_to<VkBuffer>; }) {
|
|
||||||
return buf.vk_handle();
|
|
||||||
} else {
|
|
||||||
static_assert(sizeof(T) == 0, "Cannot extract VkBuffer handle from vk::Buffer");
|
|
||||||
return VK_NULL_HANDLE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
//MemoryCommit is now VMA-backed
|
//MemoryCommit is now VMA-backed
|
||||||
MemoryCommit::MemoryCommit(VmaAllocator alloc, VmaAllocation a,
|
MemoryCommit::MemoryCommit(VmaAllocator alloc, VmaAllocation a,
|
||||||
const VmaAllocationInfo &info) noexcept
|
const VmaAllocationInfo &info) noexcept
|
||||||
: allocator{alloc}, allocation{a}, memory{info.deviceMemory},
|
: allocator{alloc}, allocation{a}, memory{info.deviceMemory},
|
||||||
offset{info.offset}, size{info.size}, mapped_ptr{info.pMappedData} {
|
offset{info.offset}, size{info.size}, mapped_ptr{info.pMappedData} {
|
||||||
// Log GPU memory allocation
|
// Log GPU memory allocation
|
||||||
|
if (GPU::Logging::IsActive() &&
|
||||||
|
Settings::values.gpu_log_memory_tracking.GetValue()) {
|
||||||
|
GPU::Logging::GPULogger::GetInstance().LogMemoryAllocation(
|
||||||
|
reinterpret_cast<uintptr_t>(memory),
|
||||||
|
static_cast<u64>(size),
|
||||||
|
0 // Memory property flags (not easily available from VMA)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MemoryCommit::~MemoryCommit() { Release(); }
|
||||||
|
|
||||||
|
MemoryCommit::MemoryCommit(MemoryCommit &&rhs) noexcept
|
||||||
|
: allocator{std::exchange(rhs.allocator, nullptr)},
|
||||||
|
allocation{std::exchange(rhs.allocation, nullptr)},
|
||||||
|
memory{std::exchange(rhs.memory, VK_NULL_HANDLE)},
|
||||||
|
offset{std::exchange(rhs.offset, 0)},
|
||||||
|
size{std::exchange(rhs.size, 0)},
|
||||||
|
mapped_ptr{std::exchange(rhs.mapped_ptr, nullptr)} {}
|
||||||
|
|
||||||
|
MemoryCommit &MemoryCommit::operator=(MemoryCommit &&rhs) noexcept {
|
||||||
|
if (this != &rhs) {
|
||||||
|
Release();
|
||||||
|
allocator = std::exchange(rhs.allocator, nullptr);
|
||||||
|
allocation = std::exchange(rhs.allocation, nullptr);
|
||||||
|
memory = std::exchange(rhs.memory, VK_NULL_HANDLE);
|
||||||
|
offset = std::exchange(rhs.offset, 0);
|
||||||
|
size = std::exchange(rhs.size, 0);
|
||||||
|
mapped_ptr = std::exchange(rhs.mapped_ptr, nullptr);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::span<u8> MemoryCommit::Map()
|
||||||
|
{
|
||||||
|
if (!allocation) return {};
|
||||||
|
if (!mapped_ptr) {
|
||||||
|
if (vmaMapMemory(allocator, allocation, &mapped_ptr) != VK_SUCCESS) return {};
|
||||||
|
}
|
||||||
|
const size_t n = static_cast<size_t>(std::min<VkDeviceSize>(size,
|
||||||
|
(std::numeric_limits<size_t>::max)()));
|
||||||
|
return std::span<u8>{static_cast<u8 *>(mapped_ptr), n};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::span<const u8> MemoryCommit::Map() const
|
||||||
|
{
|
||||||
|
if (!allocation) return {};
|
||||||
|
if (!mapped_ptr) {
|
||||||
|
void *p = nullptr;
|
||||||
|
if (vmaMapMemory(allocator, allocation, &p) != VK_SUCCESS) return {};
|
||||||
|
const_cast<MemoryCommit *>(this)->mapped_ptr = p;
|
||||||
|
}
|
||||||
|
const size_t n = static_cast<size_t>(std::min<VkDeviceSize>(size,
|
||||||
|
(std::numeric_limits<size_t>::max)()));
|
||||||
|
return std::span<const u8>{static_cast<const u8 *>(mapped_ptr), n};
|
||||||
|
}
|
||||||
|
|
||||||
|
void MemoryCommit::Unmap()
|
||||||
|
{
|
||||||
|
if (allocation && mapped_ptr) {
|
||||||
|
vmaUnmapMemory(allocator, allocation);
|
||||||
|
mapped_ptr = nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void MemoryCommit::Release() {
|
||||||
|
if (allocation && allocator) {
|
||||||
|
// Log GPU memory deallocation
|
||||||
if (GPU::Logging::IsActive() &&
|
if (GPU::Logging::IsActive() &&
|
||||||
Settings::values.gpu_log_memory_tracking.GetValue()) {
|
Settings::values.gpu_log_memory_tracking.GetValue() &&
|
||||||
GPU::Logging::GPULogger::GetInstance().LogMemoryAllocation(
|
memory != VK_NULL_HANDLE) {
|
||||||
reinterpret_cast<uintptr_t>(memory),
|
GPU::Logging::GPULogger::GetInstance().LogMemoryDeallocation(
|
||||||
static_cast<u64>(size),
|
reinterpret_cast<uintptr_t>(memory)
|
||||||
0 // Memory property flags (not easily available from VMA)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
MemoryCommit::~MemoryCommit() { Release(); }
|
if (mapped_ptr) {
|
||||||
|
|
||||||
MemoryCommit::MemoryCommit(MemoryCommit &&rhs) noexcept
|
|
||||||
: allocator{std::exchange(rhs.allocator, nullptr)},
|
|
||||||
allocation{std::exchange(rhs.allocation, nullptr)},
|
|
||||||
memory{std::exchange(rhs.memory, VK_NULL_HANDLE)},
|
|
||||||
offset{std::exchange(rhs.offset, 0)},
|
|
||||||
size{std::exchange(rhs.size, 0)},
|
|
||||||
mapped_ptr{std::exchange(rhs.mapped_ptr, nullptr)} {}
|
|
||||||
|
|
||||||
MemoryCommit &MemoryCommit::operator=(MemoryCommit &&rhs) noexcept {
|
|
||||||
if (this != &rhs) {
|
|
||||||
Release();
|
|
||||||
allocator = std::exchange(rhs.allocator, nullptr);
|
|
||||||
allocation = std::exchange(rhs.allocation, nullptr);
|
|
||||||
memory = std::exchange(rhs.memory, VK_NULL_HANDLE);
|
|
||||||
offset = std::exchange(rhs.offset, 0);
|
|
||||||
size = std::exchange(rhs.size, 0);
|
|
||||||
mapped_ptr = std::exchange(rhs.mapped_ptr, nullptr);
|
|
||||||
}
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::span<u8> MemoryCommit::Map()
|
|
||||||
{
|
|
||||||
if (!allocation) return {};
|
|
||||||
if (!mapped_ptr) {
|
|
||||||
if (vmaMapMemory(allocator, allocation, &mapped_ptr) != VK_SUCCESS) return {};
|
|
||||||
}
|
|
||||||
const size_t n = static_cast<size_t>(std::min<VkDeviceSize>(size,
|
|
||||||
(std::numeric_limits<size_t>::max)()));
|
|
||||||
return std::span<u8>{static_cast<u8 *>(mapped_ptr), n};
|
|
||||||
}
|
|
||||||
|
|
||||||
std::span<const u8> MemoryCommit::Map() const
|
|
||||||
{
|
|
||||||
if (!allocation) return {};
|
|
||||||
if (!mapped_ptr) {
|
|
||||||
void *p = nullptr;
|
|
||||||
if (vmaMapMemory(allocator, allocation, &p) != VK_SUCCESS) return {};
|
|
||||||
const_cast<MemoryCommit *>(this)->mapped_ptr = p;
|
|
||||||
}
|
|
||||||
const size_t n = static_cast<size_t>(std::min<VkDeviceSize>(size,
|
|
||||||
(std::numeric_limits<size_t>::max)()));
|
|
||||||
return std::span<const u8>{static_cast<const u8 *>(mapped_ptr), n};
|
|
||||||
}
|
|
||||||
|
|
||||||
void MemoryCommit::Unmap()
|
|
||||||
{
|
|
||||||
if (allocation && mapped_ptr) {
|
|
||||||
vmaUnmapMemory(allocator, allocation);
|
vmaUnmapMemory(allocator, allocation);
|
||||||
mapped_ptr = nullptr;
|
mapped_ptr = nullptr;
|
||||||
}
|
}
|
||||||
|
vmaFreeMemory(allocator, allocation);
|
||||||
}
|
}
|
||||||
|
allocation = nullptr;
|
||||||
|
allocator = nullptr;
|
||||||
|
memory = VK_NULL_HANDLE;
|
||||||
|
offset = 0;
|
||||||
|
size = 0;
|
||||||
|
}
|
||||||
|
|
||||||
void MemoryCommit::Release() {
|
MemoryAllocator::MemoryAllocator(const Device &device_)
|
||||||
if (allocation && allocator) {
|
: device{device_}, allocator{device.GetAllocator()},
|
||||||
// Log GPU memory deallocation
|
properties{device_.GetPhysical().GetMemoryProperties().memoryProperties},
|
||||||
if (GPU::Logging::IsActive() &&
|
buffer_image_granularity{
|
||||||
Settings::values.gpu_log_memory_tracking.GetValue() &&
|
device_.GetPhysical().GetProperties().limits.bufferImageGranularity} {
|
||||||
memory != VK_NULL_HANDLE) {
|
|
||||||
GPU::Logging::GPULogger::GetInstance().LogMemoryDeallocation(
|
|
||||||
reinterpret_cast<uintptr_t>(memory)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mapped_ptr) {
|
// Preserve the previous "RenderDoc small heap" trimming behavior that we had in original vma minus the heap bug
|
||||||
vmaUnmapMemory(allocator, allocation);
|
if (device.HasDebuggingToolAttached())
|
||||||
mapped_ptr = nullptr;
|
{
|
||||||
}
|
using namespace Common::Literals;
|
||||||
vmaFreeMemory(allocator, allocation);
|
ForEachDeviceLocalHostVisibleHeap(device, [this](size_t heap_idx, VkMemoryHeap &heap) {
|
||||||
}
|
if (heap.size <= 256_MiB) {
|
||||||
allocation = nullptr;
|
for (u32 t = 0; t < properties.memoryTypeCount; ++t) {
|
||||||
allocator = nullptr;
|
if (properties.memoryTypes[t].heapIndex == heap_idx) {
|
||||||
memory = VK_NULL_HANDLE;
|
valid_memory_types &= ~(1u << t);
|
||||||
offset = 0;
|
|
||||||
size = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
MemoryAllocator::MemoryAllocator(const Device &device_)
|
|
||||||
: device{device_}, allocator{device.GetAllocator()},
|
|
||||||
properties{device_.GetPhysical().GetMemoryProperties().memoryProperties},
|
|
||||||
buffer_image_granularity{
|
|
||||||
device_.GetPhysical().GetProperties().limits.bufferImageGranularity} {
|
|
||||||
|
|
||||||
// Preserve the previous "RenderDoc small heap" trimming behavior that we had in original vma minus the heap bug
|
|
||||||
if (device.HasDebuggingToolAttached())
|
|
||||||
{
|
|
||||||
using namespace Common::Literals;
|
|
||||||
ForEachDeviceLocalHostVisibleHeap(device, [this](size_t heap_idx, VkMemoryHeap &heap) {
|
|
||||||
if (heap.size <= 256_MiB) {
|
|
||||||
for (u32 t = 0; t < properties.memoryTypeCount; ++t) {
|
|
||||||
if (properties.memoryTypes[t].heapIndex == heap_idx) {
|
|
||||||
valid_memory_types &= ~(1u << t);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
MemoryAllocator::~MemoryAllocator() = default;
|
MemoryAllocator::~MemoryAllocator() = default;
|
||||||
|
|
||||||
vk::Image MemoryAllocator::CreateImage(const VkImageCreateInfo &ci) const
|
vk::Image MemoryAllocator::CreateImage(const VkImageCreateInfo &ci) const
|
||||||
{
|
{
|
||||||
const VmaAllocationCreateInfo alloc_ci = {
|
const VmaAllocationCreateInfo alloc_ci = {
|
||||||
.flags = VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT,
|
.flags = VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT,
|
||||||
.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE,
|
.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE,
|
||||||
.requiredFlags = 0,
|
|
||||||
.preferredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
|
|
||||||
.memoryTypeBits = 0,
|
|
||||||
.pool = VK_NULL_HANDLE,
|
|
||||||
.pUserData = nullptr,
|
|
||||||
.priority = 0.f,
|
|
||||||
};
|
|
||||||
|
|
||||||
VkImage handle{};
|
|
||||||
VmaAllocation allocation{};
|
|
||||||
VmaAllocationInfo alloc_info{};
|
|
||||||
vk::Check(vmaCreateImage(allocator, &ci, &alloc_ci, &handle, &allocation, &alloc_info));
|
|
||||||
|
|
||||||
// Log GPU memory allocation for images
|
|
||||||
if (GPU::Logging::IsActive() &&
|
|
||||||
Settings::values.gpu_log_memory_tracking.GetValue()) {
|
|
||||||
GPU::Logging::GPULogger::GetInstance().LogMemoryAllocation(
|
|
||||||
reinterpret_cast<uintptr_t>(alloc_info.deviceMemory),
|
|
||||||
static_cast<u64>(alloc_info.size),
|
|
||||||
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return vk::Image(handle, ci.usage, *device.GetLogical(), allocator, allocation,
|
|
||||||
device.GetDispatchLoader());
|
|
||||||
}
|
|
||||||
|
|
||||||
vk::Buffer MemoryAllocator::CreateBuffer(const VkBufferCreateInfo &ci, MemoryUsage usage) const {
|
|
||||||
// MESA will do memcpy() if not marked as host cached, so just force mark it for most buffers
|
|
||||||
auto const anv_flags = (usage == MemoryUsage::Stream
|
|
||||||
&& device.GetDriverID() == VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA)
|
|
||||||
? VK_MEMORY_PROPERTY_HOST_CACHED_BIT : 0;
|
|
||||||
const VmaAllocationCreateInfo alloc_ci = {
|
|
||||||
.flags = VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT | MemoryUsageVmaFlags(usage),
|
|
||||||
.usage = MemoryUsageVma(usage),
|
|
||||||
.requiredFlags = 0,
|
.requiredFlags = 0,
|
||||||
.preferredFlags = MemoryUsagePreferredVmaFlags(usage) | anv_flags,
|
.preferredFlags = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT,
|
||||||
.memoryTypeBits = usage == MemoryUsage::Stream ? 0u : valid_memory_types,
|
.memoryTypeBits = 0,
|
||||||
.pool = VK_NULL_HANDLE,
|
.pool = VK_NULL_HANDLE,
|
||||||
.pUserData = nullptr,
|
.pUserData = nullptr,
|
||||||
.priority = 0.f,
|
.priority = 0.f,
|
||||||
};
|
};
|
||||||
|
|
||||||
VkBuffer handle{};
|
VkImage handle{};
|
||||||
VmaAllocationInfo alloc_info{};
|
VmaAllocation allocation{};
|
||||||
VmaAllocation allocation{};
|
VmaAllocationInfo alloc_info{};
|
||||||
VkMemoryPropertyFlags property_flags{};
|
vk::Check(vmaCreateImage(allocator, &ci, &alloc_ci, &handle, &allocation, &alloc_info));
|
||||||
|
|
||||||
vk::Check(vmaCreateBuffer(allocator, &ci, &alloc_ci, &handle, &allocation, &alloc_info));
|
// Log GPU memory allocation for images
|
||||||
vmaGetAllocationMemoryProperties(allocator, allocation, &property_flags);
|
if (GPU::Logging::IsActive() &&
|
||||||
|
Settings::values.gpu_log_memory_tracking.GetValue()) {
|
||||||
// Log GPU memory allocation for buffers
|
GPU::Logging::GPULogger::GetInstance().LogMemoryAllocation(
|
||||||
if (GPU::Logging::IsActive() &&
|
reinterpret_cast<uintptr_t>(alloc_info.deviceMemory),
|
||||||
Settings::values.gpu_log_memory_tracking.GetValue()) {
|
static_cast<u64>(alloc_info.size),
|
||||||
GPU::Logging::GPULogger::GetInstance().LogMemoryAllocation(
|
VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT
|
||||||
reinterpret_cast<uintptr_t>(alloc_info.deviceMemory),
|
);
|
||||||
static_cast<u64>(alloc_info.size),
|
|
||||||
property_flags
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
u8 *data = reinterpret_cast<u8 *>(alloc_info.pMappedData);
|
|
||||||
const std::span<u8> mapped_data = data ? std::span<u8>{data, ci.size} : std::span<u8>{};
|
|
||||||
const bool is_coherent = (property_flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) != 0;
|
|
||||||
|
|
||||||
return vk::Buffer(handle, *device.GetLogical(), allocator, allocation, mapped_data,
|
|
||||||
is_coherent,
|
|
||||||
device.GetDispatchLoader());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryCommit MemoryAllocator::Commit(const VkMemoryRequirements &reqs, MemoryUsage usage)
|
return vk::Image(handle, ci.usage, *device.GetLogical(), allocator, allocation,
|
||||||
{
|
device.GetDispatchLoader());
|
||||||
const auto vma_usage = MemoryUsageVma(usage);
|
}
|
||||||
VmaAllocationCreateInfo ci{};
|
|
||||||
ci.flags = VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT | MemoryUsageVmaFlags(usage);
|
|
||||||
ci.usage = vma_usage;
|
|
||||||
ci.memoryTypeBits = reqs.memoryTypeBits & valid_memory_types;
|
|
||||||
ci.requiredFlags = 0;
|
|
||||||
ci.preferredFlags = MemoryUsagePreferredVmaFlags(usage);
|
|
||||||
|
|
||||||
VmaAllocation a{};
|
vk::Buffer MemoryAllocator::CreateBuffer(const VkBufferCreateInfo &ci, MemoryUsage usage) const {
|
||||||
VmaAllocationInfo info{};
|
// MESA will do memcpy() if not marked as host cached, so just force mark it for most buffers
|
||||||
|
auto const anv_flags = (usage == MemoryUsage::Stream
|
||||||
|
&& device.GetDriverID() == VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA)
|
||||||
|
? VK_MEMORY_PROPERTY_HOST_CACHED_BIT : 0;
|
||||||
|
const VmaAllocationCreateInfo alloc_ci = {
|
||||||
|
.flags = VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT | MemoryUsageVmaFlags(usage),
|
||||||
|
.usage = MemoryUsageVma(usage),
|
||||||
|
.requiredFlags = 0,
|
||||||
|
.preferredFlags = MemoryUsagePreferredVmaFlags(usage) | anv_flags,
|
||||||
|
.memoryTypeBits = usage == MemoryUsage::Stream ? 0u : valid_memory_types,
|
||||||
|
.pool = VK_NULL_HANDLE,
|
||||||
|
.pUserData = nullptr,
|
||||||
|
.priority = 0.f,
|
||||||
|
};
|
||||||
|
|
||||||
VkResult res = vmaAllocateMemory(allocator, &reqs, &ci, &a, &info);
|
VkBuffer handle{};
|
||||||
|
VmaAllocationInfo alloc_info{};
|
||||||
|
VmaAllocation allocation{};
|
||||||
|
VkMemoryPropertyFlags property_flags{};
|
||||||
|
|
||||||
if (res != VK_SUCCESS) {
|
vk::Check(vmaCreateBuffer(allocator, &ci, &alloc_ci, &handle, &allocation, &alloc_info));
|
||||||
// Relax 1: drop budget constraint
|
vmaGetAllocationMemoryProperties(allocator, allocation, &property_flags);
|
||||||
auto ci2 = ci;
|
|
||||||
ci2.flags &= ~VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT;
|
|
||||||
res = vmaAllocateMemory(allocator, &reqs, &ci2, &a, &info);
|
|
||||||
|
|
||||||
// Relax 2: if we preferred DEVICE_LOCAL, drop that preference
|
// Log GPU memory allocation for buffers
|
||||||
if (res != VK_SUCCESS && (ci.preferredFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) {
|
if (GPU::Logging::IsActive() &&
|
||||||
auto ci3 = ci2;
|
Settings::values.gpu_log_memory_tracking.GetValue()) {
|
||||||
ci3.preferredFlags &= ~VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
GPU::Logging::GPULogger::GetInstance().LogMemoryAllocation(
|
||||||
res = vmaAllocateMemory(allocator, &reqs, &ci3, &a, &info);
|
reinterpret_cast<uintptr_t>(alloc_info.deviceMemory),
|
||||||
}
|
static_cast<u64>(alloc_info.size),
|
||||||
}
|
property_flags
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
u8 *data = reinterpret_cast<u8 *>(alloc_info.pMappedData);
|
||||||
|
const std::span<u8> mapped_data = data ? std::span<u8>{data, ci.size} : std::span<u8>{};
|
||||||
|
const bool is_coherent = (property_flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) != 0;
|
||||||
|
|
||||||
|
return vk::Buffer(handle, *device.GetLogical(), allocator, allocation, mapped_data,
|
||||||
|
is_coherent,
|
||||||
|
device.GetDispatchLoader());
|
||||||
|
}
|
||||||
|
|
||||||
|
vk::Buffer MemoryAllocator::CreateBuffer(const VkBufferCreateInfo &ci, MemoryUsage usage,
|
||||||
|
VkDeviceSize min_alignment) const {
|
||||||
|
if (min_alignment <= 1) {
|
||||||
|
return CreateBuffer(ci, usage);
|
||||||
|
}
|
||||||
|
VkMemoryPropertyFlags anv_flags = 0;
|
||||||
|
if (usage == MemoryUsage::Stream &&
|
||||||
|
device.GetDriverID() == VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA) {
|
||||||
|
anv_flags = VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
|
||||||
|
}
|
||||||
|
u32 memory_type_bits = valid_memory_types;
|
||||||
|
if (usage == MemoryUsage::Stream) {
|
||||||
|
memory_type_bits = 0u;
|
||||||
|
}
|
||||||
|
const VmaAllocationCreateInfo alloc_ci = {
|
||||||
|
.flags = VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT | MemoryUsageVmaFlags(usage),
|
||||||
|
.usage = MemoryUsageVma(usage),
|
||||||
|
.requiredFlags = 0,
|
||||||
|
.preferredFlags = MemoryUsagePreferredVmaFlags(usage) | anv_flags,
|
||||||
|
.memoryTypeBits = memory_type_bits,
|
||||||
|
.pool = VK_NULL_HANDLE,
|
||||||
|
.pUserData = nullptr,
|
||||||
|
.priority = 0.f,
|
||||||
|
};
|
||||||
|
|
||||||
|
const VkDevice logical = *device.GetLogical();
|
||||||
|
const auto &dld = device.GetDispatchLoader();
|
||||||
|
|
||||||
|
VkBuffer handle{};
|
||||||
|
vk::Check(dld.vkCreateBuffer(logical, &ci, nullptr, &handle));
|
||||||
|
|
||||||
|
const VkBufferMemoryRequirementsInfo2 reqs_info{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_BUFFER_MEMORY_REQUIREMENTS_INFO_2,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.buffer = handle,
|
||||||
|
};
|
||||||
|
VkMemoryRequirements2 reqs2{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2,
|
||||||
|
.pNext = nullptr,
|
||||||
|
.memoryRequirements = {},
|
||||||
|
};
|
||||||
|
dld.vkGetBufferMemoryRequirements2(logical, &reqs_info, &reqs2);
|
||||||
|
|
||||||
|
VkMemoryRequirements reqs = reqs2.memoryRequirements;
|
||||||
|
reqs.alignment = (std::max)(reqs.alignment, min_alignment);
|
||||||
|
reqs.memoryTypeBits &= alloc_ci.memoryTypeBits;
|
||||||
|
|
||||||
|
VmaAllocation allocation{};
|
||||||
|
VmaAllocationInfo alloc_info{};
|
||||||
|
VkResult res = vmaAllocateMemory(allocator, &reqs, &alloc_ci, &allocation, &alloc_info);
|
||||||
|
if (res != VK_SUCCESS) {
|
||||||
|
auto relaxed = alloc_ci;
|
||||||
|
relaxed.flags &= ~VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT;
|
||||||
|
res = vmaAllocateMemory(allocator, &reqs, &relaxed, &allocation, &alloc_info);
|
||||||
|
}
|
||||||
|
if (res != VK_SUCCESS) {
|
||||||
|
dld.vkDestroyBuffer(logical, handle, nullptr);
|
||||||
vk::Check(res);
|
vk::Check(res);
|
||||||
return MemoryCommit(allocator, a, info);
|
}
|
||||||
|
const VkResult bind_res = vmaBindBufferMemory(allocator, allocation, handle);
|
||||||
|
if (bind_res != VK_SUCCESS) {
|
||||||
|
vmaFreeMemory(allocator, allocation);
|
||||||
|
dld.vkDestroyBuffer(logical, handle, nullptr);
|
||||||
|
vk::Check(bind_res);
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryCommit MemoryAllocator::Commit(const vk::Buffer &buffer, MemoryUsage usage) {
|
VkMemoryPropertyFlags property_flags{};
|
||||||
// Allocate memory appropriate for this buffer automatically
|
vmaGetAllocationMemoryProperties(allocator, allocation, &property_flags);
|
||||||
const auto vma_usage = MemoryUsageVma(usage);
|
|
||||||
|
|
||||||
VmaAllocationCreateInfo ci{};
|
u8 *data = reinterpret_cast<u8 *>(alloc_info.pMappedData);
|
||||||
ci.flags = VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT | MemoryUsageVmaFlags(usage);
|
std::span<u8> mapped_data{};
|
||||||
ci.usage = vma_usage;
|
if (data) {
|
||||||
ci.requiredFlags = 0;
|
mapped_data = std::span<u8>{data, ci.size};
|
||||||
ci.preferredFlags = MemoryUsagePreferredVmaFlags(usage);
|
}
|
||||||
ci.pool = VK_NULL_HANDLE;
|
const bool is_coherent = (property_flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) != 0;
|
||||||
ci.pUserData = nullptr;
|
|
||||||
ci.priority = 0.0f;
|
|
||||||
|
|
||||||
const VkBuffer raw = *buffer;
|
return vk::Buffer(handle, logical, allocator, allocation, mapped_data, is_coherent, dld);
|
||||||
|
}
|
||||||
|
|
||||||
VmaAllocation a{};
|
MemoryCommit MemoryAllocator::Commit(const VkMemoryRequirements &reqs, MemoryUsage usage)
|
||||||
VmaAllocationInfo info{};
|
{
|
||||||
|
const auto vma_usage = MemoryUsageVma(usage);
|
||||||
|
VmaAllocationCreateInfo ci{};
|
||||||
|
ci.flags = VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT | MemoryUsageVmaFlags(usage);
|
||||||
|
ci.usage = vma_usage;
|
||||||
|
ci.memoryTypeBits = reqs.memoryTypeBits & valid_memory_types;
|
||||||
|
ci.requiredFlags = 0;
|
||||||
|
ci.preferredFlags = MemoryUsagePreferredVmaFlags(usage);
|
||||||
|
|
||||||
// Let VMA infer memory requirements from the buffer
|
VmaAllocation a{};
|
||||||
VkResult res = vmaAllocateMemoryForBuffer(allocator, raw, &ci, &a, &info);
|
VmaAllocationInfo info{};
|
||||||
|
|
||||||
if (res != VK_SUCCESS) {
|
VkResult res = vmaAllocateMemory(allocator, &reqs, &ci, &a, &info);
|
||||||
auto ci2 = ci;
|
|
||||||
ci2.flags &= ~VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT;
|
|
||||||
res = vmaAllocateMemoryForBuffer(allocator, raw, &ci2, &a, &info);
|
|
||||||
|
|
||||||
if (res != VK_SUCCESS && (ci.preferredFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) {
|
if (res != VK_SUCCESS) {
|
||||||
auto ci3 = ci2;
|
// Relax 1: drop budget constraint
|
||||||
ci3.preferredFlags &= ~VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
auto ci2 = ci;
|
||||||
res = vmaAllocateMemoryForBuffer(allocator, raw, &ci3, &a, &info);
|
ci2.flags &= ~VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT;
|
||||||
}
|
res = vmaAllocateMemory(allocator, &reqs, &ci2, &a, &info);
|
||||||
|
|
||||||
|
// Relax 2: if we preferred DEVICE_LOCAL, drop that preference
|
||||||
|
if (res != VK_SUCCESS && (ci.preferredFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) {
|
||||||
|
auto ci3 = ci2;
|
||||||
|
ci3.preferredFlags &= ~VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
||||||
|
res = vmaAllocateMemory(allocator, &reqs, &ci3, &a, &info);
|
||||||
}
|
}
|
||||||
|
|
||||||
vk::Check(res);
|
|
||||||
vk::Check(vmaBindBufferMemory2(allocator, a, 0, raw, nullptr));
|
|
||||||
return MemoryCommit(allocator, a, info);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vk::Check(res);
|
||||||
|
return MemoryCommit(allocator, a, info);
|
||||||
|
}
|
||||||
|
|
||||||
|
MemoryCommit MemoryAllocator::Commit(const vk::Buffer &buffer, MemoryUsage usage) {
|
||||||
|
// Allocate memory appropriate for this buffer automatically
|
||||||
|
const auto vma_usage = MemoryUsageVma(usage);
|
||||||
|
|
||||||
|
VmaAllocationCreateInfo ci{};
|
||||||
|
ci.flags = VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT | MemoryUsageVmaFlags(usage);
|
||||||
|
ci.usage = vma_usage;
|
||||||
|
ci.requiredFlags = 0;
|
||||||
|
ci.preferredFlags = MemoryUsagePreferredVmaFlags(usage);
|
||||||
|
ci.pool = VK_NULL_HANDLE;
|
||||||
|
ci.pUserData = nullptr;
|
||||||
|
ci.priority = 0.0f;
|
||||||
|
|
||||||
|
const VkBuffer raw = *buffer;
|
||||||
|
|
||||||
|
VmaAllocation a{};
|
||||||
|
VmaAllocationInfo info{};
|
||||||
|
|
||||||
|
// Let VMA infer memory requirements from the buffer
|
||||||
|
VkResult res = vmaAllocateMemoryForBuffer(allocator, raw, &ci, &a, &info);
|
||||||
|
|
||||||
|
if (res != VK_SUCCESS) {
|
||||||
|
auto ci2 = ci;
|
||||||
|
ci2.flags &= ~VMA_ALLOCATION_CREATE_WITHIN_BUDGET_BIT;
|
||||||
|
res = vmaAllocateMemoryForBuffer(allocator, raw, &ci2, &a, &info);
|
||||||
|
|
||||||
|
if (res != VK_SUCCESS && (ci.preferredFlags & VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT)) {
|
||||||
|
auto ci3 = ci2;
|
||||||
|
ci3.preferredFlags &= ~VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT;
|
||||||
|
res = vmaAllocateMemoryForBuffer(allocator, raw, &ci3, &a, &info);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vk::Check(res);
|
||||||
|
vk::Check(vmaBindBufferMemory2(allocator, a, 0, raw, nullptr));
|
||||||
|
return MemoryCommit(allocator, a, info);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace Vulkan
|
} // namespace Vulkan
|
||||||
|
|||||||
@@ -107,6 +107,9 @@ namespace Vulkan {
|
|||||||
|
|
||||||
vk::Buffer CreateBuffer(const VkBufferCreateInfo &ci, MemoryUsage usage) const;
|
vk::Buffer CreateBuffer(const VkBufferCreateInfo &ci, MemoryUsage usage) const;
|
||||||
|
|
||||||
|
vk::Buffer CreateBuffer(const VkBufferCreateInfo &ci, MemoryUsage usage,
|
||||||
|
VkDeviceSize min_alignment) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Commits a memory with the specified requirements.
|
* Commits a memory with the specified requirements.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -229,6 +229,7 @@ void Load(VkDevice device, DeviceDispatch& dld) noexcept {
|
|||||||
X(vkGetPipelineExecutableStatisticsKHR);
|
X(vkGetPipelineExecutableStatisticsKHR);
|
||||||
X(vkGetSemaphoreCounterValue);
|
X(vkGetSemaphoreCounterValue);
|
||||||
X(vkMapMemory);
|
X(vkMapMemory);
|
||||||
|
X(vkQueueBindSparse);
|
||||||
X(vkQueueSubmit);
|
X(vkQueueSubmit);
|
||||||
X(vkQueueSubmit2);
|
X(vkQueueSubmit2);
|
||||||
X(vkResetFences);
|
X(vkResetFences);
|
||||||
@@ -539,6 +540,18 @@ void Buffer::SetObjectNameEXT(const char* name) const {
|
|||||||
SetObjectName(dld, owner, handle, VK_OBJECT_TYPE_BUFFER, name);
|
SetObjectName(dld, owner, handle, VK_OBJECT_TYPE_BUFFER, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MemoryLocation Buffer::Location() const noexcept {
|
||||||
|
if (!allocation) {
|
||||||
|
return MemoryLocation{};
|
||||||
|
}
|
||||||
|
VmaAllocationInfo info{};
|
||||||
|
vmaGetAllocationInfo(allocator, allocation, &info);
|
||||||
|
return MemoryLocation{
|
||||||
|
.memory = info.deviceMemory,
|
||||||
|
.offset = info.offset,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
void Buffer::Release() const noexcept {
|
void Buffer::Release() const noexcept {
|
||||||
if (handle) {
|
if (handle) {
|
||||||
vmaDestroyBuffer(allocator, handle, allocation);
|
vmaDestroyBuffer(allocator, handle, allocation);
|
||||||
|
|||||||
@@ -345,6 +345,7 @@ struct DeviceDispatch : InstanceDispatch {
|
|||||||
PFN_vkGetQueryPoolResults vkGetQueryPoolResults{};
|
PFN_vkGetQueryPoolResults vkGetQueryPoolResults{};
|
||||||
PFN_vkGetSemaphoreCounterValue vkGetSemaphoreCounterValue{};
|
PFN_vkGetSemaphoreCounterValue vkGetSemaphoreCounterValue{};
|
||||||
PFN_vkMapMemory vkMapMemory{};
|
PFN_vkMapMemory vkMapMemory{};
|
||||||
|
PFN_vkQueueBindSparse vkQueueBindSparse{};
|
||||||
PFN_vkQueueSubmit vkQueueSubmit{};
|
PFN_vkQueueSubmit vkQueueSubmit{};
|
||||||
PFN_vkQueueSubmit2 vkQueueSubmit2{};
|
PFN_vkQueueSubmit2 vkQueueSubmit2{};
|
||||||
PFN_vkResetFences vkResetFences{};
|
PFN_vkResetFences vkResetFences{};
|
||||||
@@ -740,6 +741,11 @@ private:
|
|||||||
const DeviceDispatch* dld = nullptr;
|
const DeviceDispatch* dld = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct MemoryLocation {
|
||||||
|
VkDeviceMemory memory{};
|
||||||
|
VkDeviceSize offset{};
|
||||||
|
};
|
||||||
|
|
||||||
class Buffer {
|
class Buffer {
|
||||||
public:
|
public:
|
||||||
explicit Buffer(VkBuffer handle_, VkDevice owner_, VmaAllocator allocator_,
|
explicit Buffer(VkBuffer handle_, VkDevice owner_, VmaAllocator allocator_,
|
||||||
@@ -811,6 +817,8 @@ public:
|
|||||||
|
|
||||||
void SetObjectNameEXT(const char* name) const;
|
void SetObjectNameEXT(const char* name) const;
|
||||||
|
|
||||||
|
MemoryLocation Location() const noexcept;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Release() const noexcept;
|
void Release() const noexcept;
|
||||||
|
|
||||||
@@ -843,6 +851,11 @@ public:
|
|||||||
return dld->vkQueueSubmit2(queue, submit_infos.size(), submit_infos.data(), fence);
|
return dld->vkQueueSubmit2(queue, submit_infos.size(), submit_infos.data(), fence);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
VkResult BindSparse(Span<VkBindSparseInfo> bind_infos,
|
||||||
|
VkFence fence = VK_NULL_HANDLE) const noexcept {
|
||||||
|
return dld->vkQueueBindSparse(queue, bind_infos.size(), bind_infos.data(), fence);
|
||||||
|
}
|
||||||
|
|
||||||
VkResult Present(const VkPresentInfoKHR& present_info) const noexcept {
|
VkResult Present(const VkPresentInfoKHR& present_info) const noexcept {
|
||||||
return dld->vkQueuePresentKHR(queue, &present_info);
|
return dld->vkQueuePresentKHR(queue, &present_info);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2936,10 +2936,10 @@ void PlayerControlPreview::DrawArrow(QPainter& p, const QPointF center, const Di
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw motion functions
|
// Draw motion functions
|
||||||
void PlayerControlPreview::Draw3dCube(QPainter& p, QPointF center, const Common::Vec<f32, 3>& euler,
|
void PlayerControlPreview::Draw3dCube(QPainter& p, QPointF center, const Common::Vec3f& euler,
|
||||||
float size) {
|
float size) {
|
||||||
std::array<Common::Vec<f32, 3>, 8> cube{
|
std::array<Common::Vec3f, 8> cube{
|
||||||
Common::Vec<f32, 3>{-0.7f, -1, -0.5f},
|
Common::Vec3f{-0.7f, -1, -0.5f},
|
||||||
{-0.7f, 1, -0.5f},
|
{-0.7f, 1, -0.5f},
|
||||||
{0.7f, 1, -0.5f},
|
{0.7f, 1, -0.5f},
|
||||||
{0.7f, -1, -0.5f},
|
{0.7f, -1, -0.5f},
|
||||||
@@ -2949,38 +2949,30 @@ void PlayerControlPreview::Draw3dCube(QPainter& p, QPointF center, const Common:
|
|||||||
{0.7f, -1, 0.5f},
|
{0.7f, -1, 0.5f},
|
||||||
};
|
};
|
||||||
|
|
||||||
for (Common::Vec<f32, 3>& point : cube) {
|
for (Common::Vec3f& point : cube) {
|
||||||
float temp = point[1];
|
point.RotateFromOrigin(euler.x, euler.y, euler.z);
|
||||||
point[1] = std::cos(euler[0]) * point[1] - std::sin(euler[0]) * point[2];
|
|
||||||
point[2] = std::sin(euler[0]) * temp + std::cos(euler[0]) * point[2];
|
|
||||||
temp = point[0];
|
|
||||||
point[0] = std::cos(euler[1]) * point[0] + std::sin(euler[1]) * point[2];
|
|
||||||
point[2] = -std::sin(euler[1]) * temp + std::cos(euler[1]) * point[2];
|
|
||||||
temp = point[0];
|
|
||||||
point[0] = std::cos(euler[2]) * point[0] - std::sin(euler[2]) * point[1];
|
|
||||||
point[1] = std::sin(euler[2]) * temp + std::cos(euler[2]) * point[1];
|
|
||||||
point *= size;
|
point *= size;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::array<QPointF, 4> front_face{
|
const std::array<QPointF, 4> front_face{
|
||||||
center + QPointF{cube[0][0], cube[0][1]},
|
center + QPointF{cube[0].x, cube[0].y},
|
||||||
center + QPointF{cube[1][0], cube[1][1]},
|
center + QPointF{cube[1].x, cube[1].y},
|
||||||
center + QPointF{cube[2][0], cube[2][1]},
|
center + QPointF{cube[2].x, cube[2].y},
|
||||||
center + QPointF{cube[3][0], cube[3][1]},
|
center + QPointF{cube[3].x, cube[3].y},
|
||||||
};
|
};
|
||||||
const std::array<QPointF, 4> back_face{
|
const std::array<QPointF, 4> back_face{
|
||||||
center + QPointF{cube[4][0], cube[4][1]},
|
center + QPointF{cube[4].x, cube[4].y},
|
||||||
center + QPointF{cube[5][0], cube[5][1]},
|
center + QPointF{cube[5].x, cube[5].y},
|
||||||
center + QPointF{cube[6][0], cube[6][1]},
|
center + QPointF{cube[6].x, cube[6].y},
|
||||||
center + QPointF{cube[7][0], cube[7][1]},
|
center + QPointF{cube[7].x, cube[7].y},
|
||||||
};
|
};
|
||||||
|
|
||||||
DrawPolygon(p, front_face);
|
DrawPolygon(p, front_face);
|
||||||
DrawPolygon(p, back_face);
|
DrawPolygon(p, back_face);
|
||||||
p.drawLine(center + QPointF{cube[0][0], cube[0][1]}, center + QPointF{cube[4][0], cube[4][1]});
|
p.drawLine(center + QPointF{cube[0].x, cube[0].y}, center + QPointF{cube[4].x, cube[4].y});
|
||||||
p.drawLine(center + QPointF{cube[1][0], cube[1][1]}, center + QPointF{cube[5][0], cube[5][1]});
|
p.drawLine(center + QPointF{cube[1].x, cube[1].y}, center + QPointF{cube[5].x, cube[5].y});
|
||||||
p.drawLine(center + QPointF{cube[2][0], cube[2][1]}, center + QPointF{cube[6][0], cube[6][1]});
|
p.drawLine(center + QPointF{cube[2].x, cube[2].y}, center + QPointF{cube[6].x, cube[6].y});
|
||||||
p.drawLine(center + QPointF{cube[3][0], cube[3][1]}, center + QPointF{cube[7][0], cube[7][1]});
|
p.drawLine(center + QPointF{cube[3].x, cube[3].y}, center + QPointF{cube[7].x, cube[7].y});
|
||||||
}
|
}
|
||||||
|
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// SPDX-FileCopyrightText: Copyright 2026 Eden Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2025 Eden Emulator Project
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
|
||||||
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
|
||||||
@@ -198,7 +198,7 @@ private:
|
|||||||
void DrawArrow(QPainter& p, QPointF center, Direction direction, float size);
|
void DrawArrow(QPainter& p, QPointF center, Direction direction, float size);
|
||||||
|
|
||||||
// Draw motion functions
|
// Draw motion functions
|
||||||
void Draw3dCube(QPainter& p, QPointF center, const Common::Vec<f32, 3>& euler, float size);
|
void Draw3dCube(QPainter& p, QPointF center, const Common::Vec3f& euler, float size);
|
||||||
|
|
||||||
// Draw primitive types
|
// Draw primitive types
|
||||||
template <size_t N>
|
template <size_t N>
|
||||||
|
|||||||
@@ -4796,6 +4796,6 @@ void VolumeButton::ResetMultiplier() {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(QT_STATICPLUGIN) || defined(__APPLE__)
|
#if !defined(QT_STATICPLUGIN) || defined(__APPLE__)
|
||||||
#define VMA_IMPLEMENTATION
|
#define VMA_IMPLEMENTATION 1
|
||||||
#include "video_core/vulkan_common/vma.h"
|
#include "video_core/vulkan_common/vma.h"
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ else()
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
# update cached cpmfile content
|
# update cached cpmfile content
|
||||||
string(JSON cpmfile SET "${cpmfile}" "${key}" "${new_object}")
|
string(JSON cpmfile SET "${cpmfile}" "${KEY}" "${new_object}")
|
||||||
|
|
||||||
# write cached cpmfile
|
# write cached cpmfile
|
||||||
get_cpmfile_path(file)
|
get_cpmfile_path(file)
|
||||||
|
|||||||
Reference in New Issue
Block a user