diff options
Diffstat (limited to 'src')
54 files changed, 653 insertions, 488 deletions
diff --git a/src/common/address_space.h b/src/common/address_space.h index 9222b2fdc..8683c23c3 100644 --- a/src/common/address_space.h +++ b/src/common/address_space.h | |||
| @@ -12,7 +12,8 @@ | |||
| 12 | 12 | ||
| 13 | namespace Common { | 13 | namespace Common { |
| 14 | template <typename VaType, size_t AddressSpaceBits> | 14 | template <typename VaType, size_t AddressSpaceBits> |
| 15 | concept AddressSpaceValid = std::is_unsigned_v<VaType> && sizeof(VaType) * 8 >= AddressSpaceBits; | 15 | concept AddressSpaceValid = std::is_unsigned_v<VaType> && sizeof(VaType) * 8 >= |
| 16 | AddressSpaceBits; | ||
| 16 | 17 | ||
| 17 | struct EmptyStruct {}; | 18 | struct EmptyStruct {}; |
| 18 | 19 | ||
| @@ -21,7 +22,7 @@ struct EmptyStruct {}; | |||
| 21 | */ | 22 | */ |
| 22 | template <typename VaType, VaType UnmappedVa, typename PaType, PaType UnmappedPa, | 23 | template <typename VaType, VaType UnmappedVa, typename PaType, PaType UnmappedPa, |
| 23 | bool PaContigSplit, size_t AddressSpaceBits, typename ExtraBlockInfo = EmptyStruct> | 24 | bool PaContigSplit, size_t AddressSpaceBits, typename ExtraBlockInfo = EmptyStruct> |
| 24 | requires AddressSpaceValid<VaType, AddressSpaceBits> | 25 | requires AddressSpaceValid<VaType, AddressSpaceBits> |
| 25 | class FlatAddressSpaceMap { | 26 | class FlatAddressSpaceMap { |
| 26 | public: | 27 | public: |
| 27 | /// The maximum VA that this AS can technically reach | 28 | /// The maximum VA that this AS can technically reach |
| @@ -109,7 +110,7 @@ private: | |||
| 109 | * initial, fast linear pass and a subsequent slower pass that iterates until it finds a free block | 110 | * initial, fast linear pass and a subsequent slower pass that iterates until it finds a free block |
| 110 | */ | 111 | */ |
| 111 | template <typename VaType, VaType UnmappedVa, size_t AddressSpaceBits> | 112 | template <typename VaType, VaType UnmappedVa, size_t AddressSpaceBits> |
| 112 | requires AddressSpaceValid<VaType, AddressSpaceBits> | 113 | requires AddressSpaceValid<VaType, AddressSpaceBits> |
| 113 | class FlatAllocator | 114 | class FlatAllocator |
| 114 | : public FlatAddressSpaceMap<VaType, UnmappedVa, bool, false, false, AddressSpaceBits> { | 115 | : public FlatAddressSpaceMap<VaType, UnmappedVa, bool, false, false, AddressSpaceBits> { |
| 115 | private: | 116 | private: |
diff --git a/src/common/alignment.h b/src/common/alignment.h index 7e897334b..fa715d497 100644 --- a/src/common/alignment.h +++ b/src/common/alignment.h | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | namespace Common { | 10 | namespace Common { |
| 11 | 11 | ||
| 12 | template <typename T> | 12 | template <typename T> |
| 13 | requires std::is_unsigned_v<T> | 13 | requires std::is_unsigned_v<T> |
| 14 | [[nodiscard]] constexpr T AlignUp(T value, size_t size) { | 14 | [[nodiscard]] constexpr T AlignUp(T value, size_t size) { |
| 15 | auto mod{static_cast<T>(value % size)}; | 15 | auto mod{static_cast<T>(value % size)}; |
| 16 | value -= mod; | 16 | value -= mod; |
| @@ -18,31 +18,31 @@ requires std::is_unsigned_v<T> | |||
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | template <typename T> | 20 | template <typename T> |
| 21 | requires std::is_unsigned_v<T> | 21 | requires std::is_unsigned_v<T> |
| 22 | [[nodiscard]] constexpr T AlignUpLog2(T value, size_t align_log2) { | 22 | [[nodiscard]] constexpr T AlignUpLog2(T value, size_t align_log2) { |
| 23 | return static_cast<T>((value + ((1ULL << align_log2) - 1)) >> align_log2 << align_log2); | 23 | return static_cast<T>((value + ((1ULL << align_log2) - 1)) >> align_log2 << align_log2); |
| 24 | } | 24 | } |
| 25 | 25 | ||
| 26 | template <typename T> | 26 | template <typename T> |
| 27 | requires std::is_unsigned_v<T> | 27 | requires std::is_unsigned_v<T> |
| 28 | [[nodiscard]] constexpr T AlignDown(T value, size_t size) { | 28 | [[nodiscard]] constexpr T AlignDown(T value, size_t size) { |
| 29 | return static_cast<T>(value - value % size); | 29 | return static_cast<T>(value - value % size); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | template <typename T> | 32 | template <typename T> |
| 33 | requires std::is_unsigned_v<T> | 33 | requires std::is_unsigned_v<T> |
| 34 | [[nodiscard]] constexpr bool Is4KBAligned(T value) { | 34 | [[nodiscard]] constexpr bool Is4KBAligned(T value) { |
| 35 | return (value & 0xFFF) == 0; | 35 | return (value & 0xFFF) == 0; |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | template <typename T> | 38 | template <typename T> |
| 39 | requires std::is_unsigned_v<T> | 39 | requires std::is_unsigned_v<T> |
| 40 | [[nodiscard]] constexpr bool IsWordAligned(T value) { | 40 | [[nodiscard]] constexpr bool IsWordAligned(T value) { |
| 41 | return (value & 0b11) == 0; | 41 | return (value & 0b11) == 0; |
| 42 | } | 42 | } |
| 43 | 43 | ||
| 44 | template <typename T> | 44 | template <typename T> |
| 45 | requires std::is_integral_v<T> | 45 | requires std::is_integral_v<T> |
| 46 | [[nodiscard]] constexpr bool IsAligned(T value, size_t alignment) { | 46 | [[nodiscard]] constexpr bool IsAligned(T value, size_t alignment) { |
| 47 | using U = typename std::make_unsigned_t<T>; | 47 | using U = typename std::make_unsigned_t<T>; |
| 48 | const U mask = static_cast<U>(alignment - 1); | 48 | const U mask = static_cast<U>(alignment - 1); |
| @@ -50,7 +50,7 @@ requires std::is_integral_v<T> | |||
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | template <typename T, typename U> | 52 | template <typename T, typename U> |
| 53 | requires std::is_integral_v<T> | 53 | requires std::is_integral_v<T> |
| 54 | [[nodiscard]] constexpr T DivideUp(T x, U y) { | 54 | [[nodiscard]] constexpr T DivideUp(T x, U y) { |
| 55 | return (x + (y - 1)) / y; | 55 | return (x + (y - 1)) / y; |
| 56 | } | 56 | } |
| @@ -73,11 +73,11 @@ public: | |||
| 73 | constexpr AlignmentAllocator(const AlignmentAllocator<T2, Align>&) noexcept {} | 73 | constexpr AlignmentAllocator(const AlignmentAllocator<T2, Align>&) noexcept {} |
| 74 | 74 | ||
| 75 | [[nodiscard]] T* allocate(size_type n) { | 75 | [[nodiscard]] T* allocate(size_type n) { |
| 76 | return static_cast<T*>(::operator new (n * sizeof(T), std::align_val_t{Align})); | 76 | return static_cast<T*>(::operator new(n * sizeof(T), std::align_val_t{Align})); |
| 77 | } | 77 | } |
| 78 | 78 | ||
| 79 | void deallocate(T* p, size_type n) { | 79 | void deallocate(T* p, size_type n) { |
| 80 | ::operator delete (p, n * sizeof(T), std::align_val_t{Align}); | 80 | ::operator delete(p, n * sizeof(T), std::align_val_t{Align}); |
| 81 | } | 81 | } |
| 82 | 82 | ||
| 83 | template <typename T2> | 83 | template <typename T2> |
diff --git a/src/common/atomic_helpers.h b/src/common/atomic_helpers.h index aef3b66a4..d997f10ba 100644 --- a/src/common/atomic_helpers.h +++ b/src/common/atomic_helpers.h | |||
| @@ -75,7 +75,7 @@ extern "C" void AnnotateHappensAfter(const char*, int, void*); | |||
| 75 | #if defined(AE_VCPP) || defined(AE_ICC) | 75 | #if defined(AE_VCPP) || defined(AE_ICC) |
| 76 | #define AE_FORCEINLINE __forceinline | 76 | #define AE_FORCEINLINE __forceinline |
| 77 | #elif defined(AE_GCC) | 77 | #elif defined(AE_GCC) |
| 78 | //#define AE_FORCEINLINE __attribute__((always_inline)) | 78 | // #define AE_FORCEINLINE __attribute__((always_inline)) |
| 79 | #define AE_FORCEINLINE inline | 79 | #define AE_FORCEINLINE inline |
| 80 | #else | 80 | #else |
| 81 | #define AE_FORCEINLINE inline | 81 | #define AE_FORCEINLINE inline |
diff --git a/src/common/bit_util.h b/src/common/bit_util.h index e4e6287f3..13368b439 100644 --- a/src/common/bit_util.h +++ b/src/common/bit_util.h | |||
| @@ -45,19 +45,19 @@ template <typename T> | |||
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | template <typename T> | 47 | template <typename T> |
| 48 | requires std::is_unsigned_v<T> | 48 | requires std::is_unsigned_v<T> |
| 49 | [[nodiscard]] constexpr bool IsPow2(T value) { | 49 | [[nodiscard]] constexpr bool IsPow2(T value) { |
| 50 | return std::has_single_bit(value); | 50 | return std::has_single_bit(value); |
| 51 | } | 51 | } |
| 52 | 52 | ||
| 53 | template <typename T> | 53 | template <typename T> |
| 54 | requires std::is_integral_v<T> | 54 | requires std::is_integral_v<T> |
| 55 | [[nodiscard]] T NextPow2(T value) { | 55 | [[nodiscard]] T NextPow2(T value) { |
| 56 | return static_cast<T>(1ULL << ((8U * sizeof(T)) - std::countl_zero(value - 1U))); | 56 | return static_cast<T>(1ULL << ((8U * sizeof(T)) - std::countl_zero(value - 1U))); |
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | template <size_t bit_index, typename T> | 59 | template <size_t bit_index, typename T> |
| 60 | requires std::is_integral_v<T> | 60 | requires std::is_integral_v<T> |
| 61 | [[nodiscard]] constexpr bool Bit(const T value) { | 61 | [[nodiscard]] constexpr bool Bit(const T value) { |
| 62 | static_assert(bit_index < BitSize<T>(), "bit_index must be smaller than size of T"); | 62 | static_assert(bit_index < BitSize<T>(), "bit_index must be smaller than size of T"); |
| 63 | return ((value >> bit_index) & T(1)) == T(1); | 63 | return ((value >> bit_index) & T(1)) == T(1); |
diff --git a/src/common/concepts.h b/src/common/concepts.h index a9acff3e7..61df1d32a 100644 --- a/src/common/concepts.h +++ b/src/common/concepts.h | |||
| @@ -16,9 +16,9 @@ concept IsContiguousContainer = std::contiguous_iterator<typename T::iterator>; | |||
| 16 | // is available on all supported platforms. | 16 | // is available on all supported platforms. |
| 17 | template <typename Derived, typename Base> | 17 | template <typename Derived, typename Base> |
| 18 | concept DerivedFrom = requires { | 18 | concept DerivedFrom = requires { |
| 19 | std::is_base_of_v<Base, Derived>; | 19 | std::is_base_of_v<Base, Derived>; |
| 20 | std::is_convertible_v<const volatile Derived*, const volatile Base*>; | 20 | std::is_convertible_v<const volatile Derived*, const volatile Base*>; |
| 21 | }; | 21 | }; |
| 22 | 22 | ||
| 23 | // TODO: Replace with std::convertible_to when libc++ implements it. | 23 | // TODO: Replace with std::convertible_to when libc++ implements it. |
| 24 | template <typename From, typename To> | 24 | template <typename From, typename To> |
diff --git a/src/common/div_ceil.h b/src/common/div_ceil.h index eebc279c2..c12477d42 100644 --- a/src/common/div_ceil.h +++ b/src/common/div_ceil.h | |||
| @@ -10,14 +10,14 @@ namespace Common { | |||
| 10 | 10 | ||
| 11 | /// Ceiled integer division. | 11 | /// Ceiled integer division. |
| 12 | template <typename N, typename D> | 12 | template <typename N, typename D> |
| 13 | requires std::is_integral_v<N> && std::is_unsigned_v<D> | 13 | requires std::is_integral_v<N> && std::is_unsigned_v<D> |
| 14 | [[nodiscard]] constexpr N DivCeil(N number, D divisor) { | 14 | [[nodiscard]] constexpr N DivCeil(N number, D divisor) { |
| 15 | return static_cast<N>((static_cast<D>(number) + divisor - 1) / divisor); | 15 | return static_cast<N>((static_cast<D>(number) + divisor - 1) / divisor); |
| 16 | } | 16 | } |
| 17 | 17 | ||
| 18 | /// Ceiled integer division with logarithmic divisor in base 2 | 18 | /// Ceiled integer division with logarithmic divisor in base 2 |
| 19 | template <typename N, typename D> | 19 | template <typename N, typename D> |
| 20 | requires std::is_integral_v<N> && std::is_unsigned_v<D> | 20 | requires std::is_integral_v<N> && std::is_unsigned_v<D> |
| 21 | [[nodiscard]] constexpr N DivCeilLog2(N value, D alignment_log2) { | 21 | [[nodiscard]] constexpr N DivCeilLog2(N value, D alignment_log2) { |
| 22 | return static_cast<N>((static_cast<D>(value) + (D(1) << alignment_log2) - 1) >> alignment_log2); | 22 | return static_cast<N>((static_cast<D>(value) + (D(1) << alignment_log2) - 1) >> alignment_log2); |
| 23 | } | 23 | } |
diff --git a/src/common/expected.h b/src/common/expected.h index 6e6c86ee7..5fccfbcbd 100644 --- a/src/common/expected.h +++ b/src/common/expected.h | |||
| @@ -64,7 +64,7 @@ struct no_init_t { | |||
| 64 | * Additionally, this requires E to be trivially destructible | 64 | * Additionally, this requires E to be trivially destructible |
| 65 | */ | 65 | */ |
| 66 | template <typename T, typename E, bool = std::is_trivially_destructible_v<T>> | 66 | template <typename T, typename E, bool = std::is_trivially_destructible_v<T>> |
| 67 | requires std::is_trivially_destructible_v<E> | 67 | requires std::is_trivially_destructible_v<E> |
| 68 | struct expected_storage_base { | 68 | struct expected_storage_base { |
| 69 | constexpr expected_storage_base() : m_val{T{}}, m_has_val{true} {} | 69 | constexpr expected_storage_base() : m_val{T{}}, m_has_val{true} {} |
| 70 | 70 | ||
| @@ -111,7 +111,7 @@ struct expected_storage_base { | |||
| 111 | * Additionally, this requires E to be trivially destructible | 111 | * Additionally, this requires E to be trivially destructible |
| 112 | */ | 112 | */ |
| 113 | template <typename T, typename E> | 113 | template <typename T, typename E> |
| 114 | requires std::is_trivially_destructible_v<E> | 114 | requires std::is_trivially_destructible_v<E> |
| 115 | struct expected_storage_base<T, E, true> { | 115 | struct expected_storage_base<T, E, true> { |
| 116 | constexpr expected_storage_base() : m_val{T{}}, m_has_val{true} {} | 116 | constexpr expected_storage_base() : m_val{T{}}, m_has_val{true} {} |
| 117 | 117 | ||
| @@ -251,7 +251,7 @@ struct expected_operations_base : expected_storage_base<T, E> { | |||
| 251 | * Additionally, this requires E to be trivially copy constructible | 251 | * Additionally, this requires E to be trivially copy constructible |
| 252 | */ | 252 | */ |
| 253 | template <typename T, typename E, bool = std::is_trivially_copy_constructible_v<T>> | 253 | template <typename T, typename E, bool = std::is_trivially_copy_constructible_v<T>> |
| 254 | requires std::is_trivially_copy_constructible_v<E> | 254 | requires std::is_trivially_copy_constructible_v<E> |
| 255 | struct expected_copy_base : expected_operations_base<T, E> { | 255 | struct expected_copy_base : expected_operations_base<T, E> { |
| 256 | using expected_operations_base<T, E>::expected_operations_base; | 256 | using expected_operations_base<T, E>::expected_operations_base; |
| 257 | }; | 257 | }; |
| @@ -261,7 +261,7 @@ struct expected_copy_base : expected_operations_base<T, E> { | |||
| 261 | * Additionally, this requires E to be trivially copy constructible | 261 | * Additionally, this requires E to be trivially copy constructible |
| 262 | */ | 262 | */ |
| 263 | template <typename T, typename E> | 263 | template <typename T, typename E> |
| 264 | requires std::is_trivially_copy_constructible_v<E> | 264 | requires std::is_trivially_copy_constructible_v<E> |
| 265 | struct expected_copy_base<T, E, false> : expected_operations_base<T, E> { | 265 | struct expected_copy_base<T, E, false> : expected_operations_base<T, E> { |
| 266 | using expected_operations_base<T, E>::expected_operations_base; | 266 | using expected_operations_base<T, E>::expected_operations_base; |
| 267 | 267 | ||
| @@ -289,7 +289,7 @@ struct expected_copy_base<T, E, false> : expected_operations_base<T, E> { | |||
| 289 | * Additionally, this requires E to be trivially move constructible | 289 | * Additionally, this requires E to be trivially move constructible |
| 290 | */ | 290 | */ |
| 291 | template <typename T, typename E, bool = std::is_trivially_move_constructible_v<T>> | 291 | template <typename T, typename E, bool = std::is_trivially_move_constructible_v<T>> |
| 292 | requires std::is_trivially_move_constructible_v<E> | 292 | requires std::is_trivially_move_constructible_v<E> |
| 293 | struct expected_move_base : expected_copy_base<T, E> { | 293 | struct expected_move_base : expected_copy_base<T, E> { |
| 294 | using expected_copy_base<T, E>::expected_copy_base; | 294 | using expected_copy_base<T, E>::expected_copy_base; |
| 295 | }; | 295 | }; |
| @@ -299,7 +299,7 @@ struct expected_move_base : expected_copy_base<T, E> { | |||
| 299 | * Additionally, this requires E to be trivially move constructible | 299 | * Additionally, this requires E to be trivially move constructible |
| 300 | */ | 300 | */ |
| 301 | template <typename T, typename E> | 301 | template <typename T, typename E> |
| 302 | requires std::is_trivially_move_constructible_v<E> | 302 | requires std::is_trivially_move_constructible_v<E> |
| 303 | struct expected_move_base<T, E, false> : expected_copy_base<T, E> { | 303 | struct expected_move_base<T, E, false> : expected_copy_base<T, E> { |
| 304 | using expected_copy_base<T, E>::expected_copy_base; | 304 | using expected_copy_base<T, E>::expected_copy_base; |
| 305 | 305 | ||
| @@ -330,9 +330,9 @@ template <typename T, typename E, | |||
| 330 | bool = std::conjunction_v<std::is_trivially_copy_assignable<T>, | 330 | bool = std::conjunction_v<std::is_trivially_copy_assignable<T>, |
| 331 | std::is_trivially_copy_constructible<T>, | 331 | std::is_trivially_copy_constructible<T>, |
| 332 | std::is_trivially_destructible<T>>> | 332 | std::is_trivially_destructible<T>>> |
| 333 | requires std::conjunction_v<std::is_trivially_copy_assignable<E>, | 333 | requires std::conjunction_v<std::is_trivially_copy_assignable<E>, |
| 334 | std::is_trivially_copy_constructible<E>, | 334 | std::is_trivially_copy_constructible<E>, |
| 335 | std::is_trivially_destructible<E>> | 335 | std::is_trivially_destructible<E>> |
| 336 | struct expected_copy_assign_base : expected_move_base<T, E> { | 336 | struct expected_copy_assign_base : expected_move_base<T, E> { |
| 337 | using expected_move_base<T, E>::expected_move_base; | 337 | using expected_move_base<T, E>::expected_move_base; |
| 338 | }; | 338 | }; |
| @@ -342,9 +342,9 @@ struct expected_copy_assign_base : expected_move_base<T, E> { | |||
| 342 | * Additionally, this requires E to be trivially copy assignable | 342 | * Additionally, this requires E to be trivially copy assignable |
| 343 | */ | 343 | */ |
| 344 | template <typename T, typename E> | 344 | template <typename T, typename E> |
| 345 | requires std::conjunction_v<std::is_trivially_copy_assignable<E>, | 345 | requires std::conjunction_v<std::is_trivially_copy_assignable<E>, |
| 346 | std::is_trivially_copy_constructible<E>, | 346 | std::is_trivially_copy_constructible<E>, |
| 347 | std::is_trivially_destructible<E>> | 347 | std::is_trivially_destructible<E>> |
| 348 | struct expected_copy_assign_base<T, E, false> : expected_move_base<T, E> { | 348 | struct expected_copy_assign_base<T, E, false> : expected_move_base<T, E> { |
| 349 | using expected_move_base<T, E>::expected_move_base; | 349 | using expected_move_base<T, E>::expected_move_base; |
| 350 | 350 | ||
| @@ -371,9 +371,9 @@ template <typename T, typename E, | |||
| 371 | bool = std::conjunction_v<std::is_trivially_move_assignable<T>, | 371 | bool = std::conjunction_v<std::is_trivially_move_assignable<T>, |
| 372 | std::is_trivially_move_constructible<T>, | 372 | std::is_trivially_move_constructible<T>, |
| 373 | std::is_trivially_destructible<T>>> | 373 | std::is_trivially_destructible<T>>> |
| 374 | requires std::conjunction_v<std::is_trivially_move_assignable<E>, | 374 | requires std::conjunction_v<std::is_trivially_move_assignable<E>, |
| 375 | std::is_trivially_move_constructible<E>, | 375 | std::is_trivially_move_constructible<E>, |
| 376 | std::is_trivially_destructible<E>> | 376 | std::is_trivially_destructible<E>> |
| 377 | struct expected_move_assign_base : expected_copy_assign_base<T, E> { | 377 | struct expected_move_assign_base : expected_copy_assign_base<T, E> { |
| 378 | using expected_copy_assign_base<T, E>::expected_copy_assign_base; | 378 | using expected_copy_assign_base<T, E>::expected_copy_assign_base; |
| 379 | }; | 379 | }; |
| @@ -383,9 +383,9 @@ struct expected_move_assign_base : expected_copy_assign_base<T, E> { | |||
| 383 | * Additionally, this requires E to be trivially move assignable | 383 | * Additionally, this requires E to be trivially move assignable |
| 384 | */ | 384 | */ |
| 385 | template <typename T, typename E> | 385 | template <typename T, typename E> |
| 386 | requires std::conjunction_v<std::is_trivially_move_assignable<E>, | 386 | requires std::conjunction_v<std::is_trivially_move_assignable<E>, |
| 387 | std::is_trivially_move_constructible<E>, | 387 | std::is_trivially_move_constructible<E>, |
| 388 | std::is_trivially_destructible<E>> | 388 | std::is_trivially_destructible<E>> |
| 389 | struct expected_move_assign_base<T, E, false> : expected_copy_assign_base<T, E> { | 389 | struct expected_move_assign_base<T, E, false> : expected_copy_assign_base<T, E> { |
| 390 | using expected_copy_assign_base<T, E>::expected_copy_assign_base; | 390 | using expected_copy_assign_base<T, E>::expected_copy_assign_base; |
| 391 | 391 | ||
| @@ -412,7 +412,7 @@ struct expected_move_assign_base<T, E, false> : expected_copy_assign_base<T, E> | |||
| 412 | */ | 412 | */ |
| 413 | template <typename T, typename E, bool EnableCopy = std::is_copy_constructible_v<T>, | 413 | template <typename T, typename E, bool EnableCopy = std::is_copy_constructible_v<T>, |
| 414 | bool EnableMove = std::is_move_constructible_v<T>> | 414 | bool EnableMove = std::is_move_constructible_v<T>> |
| 415 | requires std::conjunction_v<std::is_copy_constructible<E>, std::is_move_constructible<E>> | 415 | requires std::conjunction_v<std::is_copy_constructible<E>, std::is_move_constructible<E>> |
| 416 | struct expected_delete_ctor_base { | 416 | struct expected_delete_ctor_base { |
| 417 | expected_delete_ctor_base() = default; | 417 | expected_delete_ctor_base() = default; |
| 418 | expected_delete_ctor_base(const expected_delete_ctor_base&) = default; | 418 | expected_delete_ctor_base(const expected_delete_ctor_base&) = default; |
| @@ -422,7 +422,7 @@ struct expected_delete_ctor_base { | |||
| 422 | }; | 422 | }; |
| 423 | 423 | ||
| 424 | template <typename T, typename E> | 424 | template <typename T, typename E> |
| 425 | requires std::conjunction_v<std::is_copy_constructible<E>, std::is_move_constructible<E>> | 425 | requires std::conjunction_v<std::is_copy_constructible<E>, std::is_move_constructible<E>> |
| 426 | struct expected_delete_ctor_base<T, E, true, false> { | 426 | struct expected_delete_ctor_base<T, E, true, false> { |
| 427 | expected_delete_ctor_base() = default; | 427 | expected_delete_ctor_base() = default; |
| 428 | expected_delete_ctor_base(const expected_delete_ctor_base&) = default; | 428 | expected_delete_ctor_base(const expected_delete_ctor_base&) = default; |
| @@ -432,7 +432,7 @@ struct expected_delete_ctor_base<T, E, true, false> { | |||
| 432 | }; | 432 | }; |
| 433 | 433 | ||
| 434 | template <typename T, typename E> | 434 | template <typename T, typename E> |
| 435 | requires std::conjunction_v<std::is_copy_constructible<E>, std::is_move_constructible<E>> | 435 | requires std::conjunction_v<std::is_copy_constructible<E>, std::is_move_constructible<E>> |
| 436 | struct expected_delete_ctor_base<T, E, false, true> { | 436 | struct expected_delete_ctor_base<T, E, false, true> { |
| 437 | expected_delete_ctor_base() = default; | 437 | expected_delete_ctor_base() = default; |
| 438 | expected_delete_ctor_base(const expected_delete_ctor_base&) = delete; | 438 | expected_delete_ctor_base(const expected_delete_ctor_base&) = delete; |
| @@ -442,7 +442,7 @@ struct expected_delete_ctor_base<T, E, false, true> { | |||
| 442 | }; | 442 | }; |
| 443 | 443 | ||
| 444 | template <typename T, typename E> | 444 | template <typename T, typename E> |
| 445 | requires std::conjunction_v<std::is_copy_constructible<E>, std::is_move_constructible<E>> | 445 | requires std::conjunction_v<std::is_copy_constructible<E>, std::is_move_constructible<E>> |
| 446 | struct expected_delete_ctor_base<T, E, false, false> { | 446 | struct expected_delete_ctor_base<T, E, false, false> { |
| 447 | expected_delete_ctor_base() = default; | 447 | expected_delete_ctor_base() = default; |
| 448 | expected_delete_ctor_base(const expected_delete_ctor_base&) = delete; | 448 | expected_delete_ctor_base(const expected_delete_ctor_base&) = delete; |
| @@ -460,8 +460,8 @@ template < | |||
| 460 | typename T, typename E, | 460 | typename T, typename E, |
| 461 | bool EnableCopy = std::conjunction_v<std::is_copy_constructible<T>, std::is_copy_assignable<T>>, | 461 | bool EnableCopy = std::conjunction_v<std::is_copy_constructible<T>, std::is_copy_assignable<T>>, |
| 462 | bool EnableMove = std::conjunction_v<std::is_move_constructible<T>, std::is_move_assignable<T>>> | 462 | bool EnableMove = std::conjunction_v<std::is_move_constructible<T>, std::is_move_assignable<T>>> |
| 463 | requires std::conjunction_v<std::is_copy_constructible<E>, std::is_move_constructible<E>, | 463 | requires std::conjunction_v<std::is_copy_constructible<E>, std::is_move_constructible<E>, |
| 464 | std::is_copy_assignable<E>, std::is_move_assignable<E>> | 464 | std::is_copy_assignable<E>, std::is_move_assignable<E>> |
| 465 | struct expected_delete_assign_base { | 465 | struct expected_delete_assign_base { |
| 466 | expected_delete_assign_base() = default; | 466 | expected_delete_assign_base() = default; |
| 467 | expected_delete_assign_base(const expected_delete_assign_base&) = default; | 467 | expected_delete_assign_base(const expected_delete_assign_base&) = default; |
| @@ -471,8 +471,8 @@ struct expected_delete_assign_base { | |||
| 471 | }; | 471 | }; |
| 472 | 472 | ||
| 473 | template <typename T, typename E> | 473 | template <typename T, typename E> |
| 474 | requires std::conjunction_v<std::is_copy_constructible<E>, std::is_move_constructible<E>, | 474 | requires std::conjunction_v<std::is_copy_constructible<E>, std::is_move_constructible<E>, |
| 475 | std::is_copy_assignable<E>, std::is_move_assignable<E>> | 475 | std::is_copy_assignable<E>, std::is_move_assignable<E>> |
| 476 | struct expected_delete_assign_base<T, E, true, false> { | 476 | struct expected_delete_assign_base<T, E, true, false> { |
| 477 | expected_delete_assign_base() = default; | 477 | expected_delete_assign_base() = default; |
| 478 | expected_delete_assign_base(const expected_delete_assign_base&) = default; | 478 | expected_delete_assign_base(const expected_delete_assign_base&) = default; |
| @@ -482,8 +482,8 @@ struct expected_delete_assign_base<T, E, true, false> { | |||
| 482 | }; | 482 | }; |
| 483 | 483 | ||
| 484 | template <typename T, typename E> | 484 | template <typename T, typename E> |
| 485 | requires std::conjunction_v<std::is_copy_constructible<E>, std::is_move_constructible<E>, | 485 | requires std::conjunction_v<std::is_copy_constructible<E>, std::is_move_constructible<E>, |
| 486 | std::is_copy_assignable<E>, std::is_move_assignable<E>> | 486 | std::is_copy_assignable<E>, std::is_move_assignable<E>> |
| 487 | struct expected_delete_assign_base<T, E, false, true> { | 487 | struct expected_delete_assign_base<T, E, false, true> { |
| 488 | expected_delete_assign_base() = default; | 488 | expected_delete_assign_base() = default; |
| 489 | expected_delete_assign_base(const expected_delete_assign_base&) = default; | 489 | expected_delete_assign_base(const expected_delete_assign_base&) = default; |
| @@ -493,8 +493,8 @@ struct expected_delete_assign_base<T, E, false, true> { | |||
| 493 | }; | 493 | }; |
| 494 | 494 | ||
| 495 | template <typename T, typename E> | 495 | template <typename T, typename E> |
| 496 | requires std::conjunction_v<std::is_copy_constructible<E>, std::is_move_constructible<E>, | 496 | requires std::conjunction_v<std::is_copy_constructible<E>, std::is_move_constructible<E>, |
| 497 | std::is_copy_assignable<E>, std::is_move_assignable<E>> | 497 | std::is_copy_assignable<E>, std::is_move_assignable<E>> |
| 498 | struct expected_delete_assign_base<T, E, false, false> { | 498 | struct expected_delete_assign_base<T, E, false, false> { |
| 499 | expected_delete_assign_base() = default; | 499 | expected_delete_assign_base() = default; |
| 500 | expected_delete_assign_base(const expected_delete_assign_base&) = default; | 500 | expected_delete_assign_base(const expected_delete_assign_base&) = default; |
diff --git a/src/common/intrusive_red_black_tree.h b/src/common/intrusive_red_black_tree.h index 93046615e..5f6b34e82 100644 --- a/src/common/intrusive_red_black_tree.h +++ b/src/common/intrusive_red_black_tree.h | |||
| @@ -242,19 +242,21 @@ public: | |||
| 242 | 242 | ||
| 243 | template <typename T> | 243 | template <typename T> |
| 244 | concept HasRedBlackKeyType = requires { | 244 | concept HasRedBlackKeyType = requires { |
| 245 | { std::is_same<typename T::RedBlackKeyType, void>::value } -> std::convertible_to<bool>; | 245 | { |
| 246 | }; | 246 | std::is_same<typename T::RedBlackKeyType, void>::value |
| 247 | } -> std::convertible_to<bool>; | ||
| 248 | }; | ||
| 247 | 249 | ||
| 248 | namespace impl { | 250 | namespace impl { |
| 249 | 251 | ||
| 250 | template <typename T, typename Default> | 252 | template <typename T, typename Default> |
| 251 | consteval auto* GetRedBlackKeyType() { | 253 | consteval auto* GetRedBlackKeyType() { |
| 252 | if constexpr (HasRedBlackKeyType<T>) { | 254 | if constexpr (HasRedBlackKeyType<T>) { |
| 253 | return static_cast<typename T::RedBlackKeyType*>(nullptr); | 255 | return static_cast<typename T::RedBlackKeyType*>(nullptr); |
| 254 | } else { | 256 | } else { |
| 255 | return static_cast<Default*>(nullptr); | 257 | return static_cast<Default*>(nullptr); |
| 256 | } | ||
| 257 | } | 258 | } |
| 259 | } | ||
| 258 | 260 | ||
| 259 | } // namespace impl | 261 | } // namespace impl |
| 260 | 262 | ||
diff --git a/src/common/make_unique_for_overwrite.h b/src/common/make_unique_for_overwrite.h index c7413cf51..17f81bba4 100644 --- a/src/common/make_unique_for_overwrite.h +++ b/src/common/make_unique_for_overwrite.h | |||
| @@ -9,17 +9,19 @@ | |||
| 9 | namespace Common { | 9 | namespace Common { |
| 10 | 10 | ||
| 11 | template <class T> | 11 | template <class T> |
| 12 | requires(!std::is_array_v<T>) std::unique_ptr<T> make_unique_for_overwrite() { | 12 | requires(!std::is_array_v<T>) |
| 13 | std::unique_ptr<T> make_unique_for_overwrite() { | ||
| 13 | return std::unique_ptr<T>(new T); | 14 | return std::unique_ptr<T>(new T); |
| 14 | } | 15 | } |
| 15 | 16 | ||
| 16 | template <class T> | 17 | template <class T> |
| 17 | requires std::is_unbounded_array_v<T> std::unique_ptr<T> make_unique_for_overwrite(std::size_t n) { | 18 | requires std::is_unbounded_array_v<T> |
| 19 | std::unique_ptr<T> make_unique_for_overwrite(std::size_t n) { | ||
| 18 | return std::unique_ptr<T>(new std::remove_extent_t<T>[n]); | 20 | return std::unique_ptr<T>(new std::remove_extent_t<T>[n]); |
| 19 | } | 21 | } |
| 20 | 22 | ||
| 21 | template <class T, class... Args> | 23 | template <class T, class... Args> |
| 22 | requires std::is_bounded_array_v<T> | 24 | requires std::is_bounded_array_v<T> |
| 23 | void make_unique_for_overwrite(Args&&...) = delete; | 25 | void make_unique_for_overwrite(Args&&...) = delete; |
| 24 | 26 | ||
| 25 | } // namespace Common | 27 | } // namespace Common |
diff --git a/src/common/polyfill_ranges.h b/src/common/polyfill_ranges.h index ca44bfaef..512dbcbcb 100644 --- a/src/common/polyfill_ranges.h +++ b/src/common/polyfill_ranges.h | |||
| @@ -18,9 +18,9 @@ namespace ranges { | |||
| 18 | 18 | ||
| 19 | template <typename T> | 19 | template <typename T> |
| 20 | concept range = requires(T& t) { | 20 | concept range = requires(T& t) { |
| 21 | begin(t); | 21 | begin(t); |
| 22 | end(t); | 22 | end(t); |
| 23 | }; | 23 | }; |
| 24 | 24 | ||
| 25 | template <typename T> | 25 | template <typename T> |
| 26 | concept input_range = range<T>; | 26 | concept input_range = range<T>; |
| @@ -421,7 +421,7 @@ struct generate_fn { | |||
| 421 | } | 421 | } |
| 422 | 422 | ||
| 423 | template <typename R, std::copy_constructible F> | 423 | template <typename R, std::copy_constructible F> |
| 424 | requires std::invocable<F&> && ranges::output_range<R> | 424 | requires std::invocable<F&> && ranges::output_range<R> |
| 425 | constexpr ranges::iterator_t<R> operator()(R&& r, F gen) const { | 425 | constexpr ranges::iterator_t<R> operator()(R&& r, F gen) const { |
| 426 | return operator()(ranges::begin(r), ranges::end(r), std::move(gen)); | 426 | return operator()(ranges::begin(r), ranges::end(r), std::move(gen)); |
| 427 | } | 427 | } |
diff --git a/src/common/polyfill_thread.h b/src/common/polyfill_thread.h index b2c929d2f..b5ef055db 100644 --- a/src/common/polyfill_thread.h +++ b/src/common/polyfill_thread.h | |||
| @@ -41,17 +41,18 @@ bool StoppableTimedWait(std::stop_token token, const std::chrono::duration<Rep, | |||
| 41 | #include <chrono> | 41 | #include <chrono> |
| 42 | #include <condition_variable> | 42 | #include <condition_variable> |
| 43 | #include <functional> | 43 | #include <functional> |
| 44 | #include <list> | 44 | #include <map> |
| 45 | #include <memory> | 45 | #include <memory> |
| 46 | #include <mutex> | 46 | #include <mutex> |
| 47 | #include <optional> | 47 | #include <optional> |
| 48 | #include <thread> | 48 | #include <thread> |
| 49 | #include <type_traits> | 49 | #include <type_traits> |
| 50 | #include <utility> | ||
| 50 | 51 | ||
| 51 | namespace std { | 52 | namespace std { |
| 52 | namespace polyfill { | 53 | namespace polyfill { |
| 53 | 54 | ||
| 54 | using stop_state_callbacks = list<function<void()>>; | 55 | using stop_state_callback = size_t; |
| 55 | 56 | ||
| 56 | class stop_state { | 57 | class stop_state { |
| 57 | public: | 58 | public: |
| @@ -59,61 +60,69 @@ public: | |||
| 59 | ~stop_state() = default; | 60 | ~stop_state() = default; |
| 60 | 61 | ||
| 61 | bool request_stop() { | 62 | bool request_stop() { |
| 62 | stop_state_callbacks callbacks; | 63 | unique_lock lk{m_lock}; |
| 63 | 64 | ||
| 64 | { | 65 | if (m_stop_requested) { |
| 65 | scoped_lock lk{m_lock}; | 66 | // Already set, nothing to do. |
| 67 | return false; | ||
| 68 | } | ||
| 66 | 69 | ||
| 67 | if (m_stop_requested.load()) { | 70 | // Mark stop requested. |
| 68 | // Already set, nothing to do | 71 | m_stop_requested = true; |
| 69 | return false; | ||
| 70 | } | ||
| 71 | 72 | ||
| 72 | // Set as requested | 73 | while (!m_callbacks.empty()) { |
| 73 | m_stop_requested = true; | 74 | // Get an iterator to the first element. |
| 75 | const auto it = m_callbacks.begin(); | ||
| 74 | 76 | ||
| 75 | // Copy callback list | 77 | // Move the callback function out of the map. |
| 76 | callbacks = m_callbacks; | 78 | function<void()> f; |
| 77 | } | 79 | swap(it->second, f); |
| 80 | |||
| 81 | // Erase the now-empty map element. | ||
| 82 | m_callbacks.erase(it); | ||
| 78 | 83 | ||
| 79 | for (auto callback : callbacks) { | 84 | // Run the callback. |
| 80 | callback(); | 85 | if (f) { |
| 86 | f(); | ||
| 87 | } | ||
| 81 | } | 88 | } |
| 82 | 89 | ||
| 83 | return true; | 90 | return true; |
| 84 | } | 91 | } |
| 85 | 92 | ||
| 86 | bool stop_requested() const { | 93 | bool stop_requested() const { |
| 87 | return m_stop_requested.load(); | 94 | unique_lock lk{m_lock}; |
| 95 | return m_stop_requested; | ||
| 88 | } | 96 | } |
| 89 | 97 | ||
| 90 | stop_state_callbacks::const_iterator insert_callback(function<void()> f) { | 98 | stop_state_callback insert_callback(function<void()> f) { |
| 91 | stop_state_callbacks::const_iterator ret{}; | 99 | unique_lock lk{m_lock}; |
| 92 | bool should_run{}; | ||
| 93 | |||
| 94 | { | ||
| 95 | scoped_lock lk{m_lock}; | ||
| 96 | should_run = m_stop_requested.load(); | ||
| 97 | m_callbacks.push_front(f); | ||
| 98 | ret = m_callbacks.begin(); | ||
| 99 | } | ||
| 100 | 100 | ||
| 101 | if (should_run) { | 101 | if (m_stop_requested) { |
| 102 | f(); | 102 | // Stop already requested. Don't insert anything, |
| 103 | // just run the callback synchronously. | ||
| 104 | if (f) { | ||
| 105 | f(); | ||
| 106 | } | ||
| 107 | return 0; | ||
| 103 | } | 108 | } |
| 104 | 109 | ||
| 110 | // Insert the callback. | ||
| 111 | stop_state_callback ret = ++m_next_callback; | ||
| 112 | m_callbacks.emplace(ret, move(f)); | ||
| 105 | return ret; | 113 | return ret; |
| 106 | } | 114 | } |
| 107 | 115 | ||
| 108 | void remove_callback(stop_state_callbacks::const_iterator it) { | 116 | void remove_callback(stop_state_callback cb) { |
| 109 | scoped_lock lk{m_lock}; | 117 | unique_lock lk{m_lock}; |
| 110 | m_callbacks.erase(it); | 118 | m_callbacks.erase(cb); |
| 111 | } | 119 | } |
| 112 | 120 | ||
| 113 | private: | 121 | private: |
| 114 | mutex m_lock; | 122 | mutable recursive_mutex m_lock; |
| 115 | atomic<bool> m_stop_requested; | 123 | map<stop_state_callback, function<void()>> m_callbacks; |
| 116 | stop_state_callbacks m_callbacks; | 124 | stop_state_callback m_next_callback{0}; |
| 125 | bool m_stop_requested{false}; | ||
| 117 | }; | 126 | }; |
| 118 | 127 | ||
| 119 | } // namespace polyfill | 128 | } // namespace polyfill |
| @@ -204,7 +213,7 @@ public: | |||
| 204 | using callback_type = Callback; | 213 | using callback_type = Callback; |
| 205 | 214 | ||
| 206 | template <typename C> | 215 | template <typename C> |
| 207 | requires constructible_from<Callback, C> | 216 | requires constructible_from<Callback, C> |
| 208 | explicit stop_callback(const stop_token& st, | 217 | explicit stop_callback(const stop_token& st, |
| 209 | C&& cb) noexcept(is_nothrow_constructible_v<Callback, C>) | 218 | C&& cb) noexcept(is_nothrow_constructible_v<Callback, C>) |
| 210 | : m_stop_state(st.m_stop_state) { | 219 | : m_stop_state(st.m_stop_state) { |
| @@ -213,7 +222,7 @@ public: | |||
| 213 | } | 222 | } |
| 214 | } | 223 | } |
| 215 | template <typename C> | 224 | template <typename C> |
| 216 | requires constructible_from<Callback, C> | 225 | requires constructible_from<Callback, C> |
| 217 | explicit stop_callback(stop_token&& st, | 226 | explicit stop_callback(stop_token&& st, |
| 218 | C&& cb) noexcept(is_nothrow_constructible_v<Callback, C>) | 227 | C&& cb) noexcept(is_nothrow_constructible_v<Callback, C>) |
| 219 | : m_stop_state(move(st.m_stop_state)) { | 228 | : m_stop_state(move(st.m_stop_state)) { |
| @@ -223,7 +232,7 @@ public: | |||
| 223 | } | 232 | } |
| 224 | ~stop_callback() { | 233 | ~stop_callback() { |
| 225 | if (m_stop_state && m_callback) { | 234 | if (m_stop_state && m_callback) { |
| 226 | m_stop_state->remove_callback(*m_callback); | 235 | m_stop_state->remove_callback(m_callback); |
| 227 | } | 236 | } |
| 228 | } | 237 | } |
| 229 | 238 | ||
| @@ -234,7 +243,7 @@ public: | |||
| 234 | 243 | ||
| 235 | private: | 244 | private: |
| 236 | shared_ptr<polyfill::stop_state> m_stop_state; | 245 | shared_ptr<polyfill::stop_state> m_stop_state; |
| 237 | optional<polyfill::stop_state_callbacks::const_iterator> m_callback; | 246 | polyfill::stop_state_callback m_callback; |
| 238 | }; | 247 | }; |
| 239 | 248 | ||
| 240 | template <typename Callback> | 249 | template <typename Callback> |
diff --git a/src/common/settings.h b/src/common/settings.h index 4b4da4da2..64db66f37 100644 --- a/src/common/settings.h +++ b/src/common/settings.h | |||
| @@ -131,7 +131,8 @@ public: | |||
| 131 | * @param default_val Intial value of the setting, and default value of the setting | 131 | * @param default_val Intial value of the setting, and default value of the setting |
| 132 | * @param name Label for the setting | 132 | * @param name Label for the setting |
| 133 | */ | 133 | */ |
| 134 | explicit Setting(const Type& default_val, const std::string& name) requires(!ranged) | 134 | explicit Setting(const Type& default_val, const std::string& name) |
| 135 | requires(!ranged) | ||
| 135 | : value{default_val}, default_value{default_val}, label{name} {} | 136 | : value{default_val}, default_value{default_val}, label{name} {} |
| 136 | virtual ~Setting() = default; | 137 | virtual ~Setting() = default; |
| 137 | 138 | ||
| @@ -144,7 +145,8 @@ public: | |||
| 144 | * @param name Label for the setting | 145 | * @param name Label for the setting |
| 145 | */ | 146 | */ |
| 146 | explicit Setting(const Type& default_val, const Type& min_val, const Type& max_val, | 147 | explicit Setting(const Type& default_val, const Type& min_val, const Type& max_val, |
| 147 | const std::string& name) requires(ranged) | 148 | const std::string& name) |
| 149 | requires(ranged) | ||
| 148 | : value{default_val}, | 150 | : value{default_val}, |
| 149 | default_value{default_val}, maximum{max_val}, minimum{min_val}, label{name} {} | 151 | default_value{default_val}, maximum{max_val}, minimum{min_val}, label{name} {} |
| 150 | 152 | ||
| @@ -232,7 +234,8 @@ public: | |||
| 232 | * @param default_val Intial value of the setting, and default value of the setting | 234 | * @param default_val Intial value of the setting, and default value of the setting |
| 233 | * @param name Label for the setting | 235 | * @param name Label for the setting |
| 234 | */ | 236 | */ |
| 235 | explicit SwitchableSetting(const Type& default_val, const std::string& name) requires(!ranged) | 237 | explicit SwitchableSetting(const Type& default_val, const std::string& name) |
| 238 | requires(!ranged) | ||
| 236 | : Setting<Type>{default_val, name} {} | 239 | : Setting<Type>{default_val, name} {} |
| 237 | virtual ~SwitchableSetting() = default; | 240 | virtual ~SwitchableSetting() = default; |
| 238 | 241 | ||
| @@ -245,7 +248,8 @@ public: | |||
| 245 | * @param name Label for the setting | 248 | * @param name Label for the setting |
| 246 | */ | 249 | */ |
| 247 | explicit SwitchableSetting(const Type& default_val, const Type& min_val, const Type& max_val, | 250 | explicit SwitchableSetting(const Type& default_val, const Type& min_val, const Type& max_val, |
| 248 | const std::string& name) requires(ranged) | 251 | const std::string& name) |
| 252 | requires(ranged) | ||
| 249 | : Setting<Type, true>{default_val, min_val, max_val, name} {} | 253 | : Setting<Type, true>{default_val, min_val, max_val, name} {} |
| 250 | 254 | ||
| 251 | /** | 255 | /** |
diff --git a/src/common/tree.h b/src/common/tree.h index f77859209..f4fc43de3 100644 --- a/src/common/tree.h +++ b/src/common/tree.h | |||
| @@ -103,12 +103,12 @@ concept IsRBEntry = CheckRBEntry<T>::value; | |||
| 103 | 103 | ||
| 104 | template <typename T> | 104 | template <typename T> |
| 105 | concept HasRBEntry = requires(T& t, const T& ct) { | 105 | concept HasRBEntry = requires(T& t, const T& ct) { |
| 106 | { t.GetRBEntry() } -> std::same_as<RBEntry<T>&>; | 106 | { t.GetRBEntry() } -> std::same_as<RBEntry<T>&>; |
| 107 | { ct.GetRBEntry() } -> std::same_as<const RBEntry<T>&>; | 107 | { ct.GetRBEntry() } -> std::same_as<const RBEntry<T>&>; |
| 108 | }; | 108 | }; |
| 109 | 109 | ||
| 110 | template <typename T> | 110 | template <typename T> |
| 111 | requires HasRBEntry<T> | 111 | requires HasRBEntry<T> |
| 112 | class RBHead { | 112 | class RBHead { |
| 113 | private: | 113 | private: |
| 114 | T* m_rbh_root = nullptr; | 114 | T* m_rbh_root = nullptr; |
| @@ -130,90 +130,90 @@ public: | |||
| 130 | }; | 130 | }; |
| 131 | 131 | ||
| 132 | template <typename T> | 132 | template <typename T> |
| 133 | requires HasRBEntry<T> | 133 | requires HasRBEntry<T> |
| 134 | [[nodiscard]] constexpr RBEntry<T>& RB_ENTRY(T* t) { | 134 | [[nodiscard]] constexpr RBEntry<T>& RB_ENTRY(T* t) { |
| 135 | return t->GetRBEntry(); | 135 | return t->GetRBEntry(); |
| 136 | } | 136 | } |
| 137 | template <typename T> | 137 | template <typename T> |
| 138 | requires HasRBEntry<T> | 138 | requires HasRBEntry<T> |
| 139 | [[nodiscard]] constexpr const RBEntry<T>& RB_ENTRY(const T* t) { | 139 | [[nodiscard]] constexpr const RBEntry<T>& RB_ENTRY(const T* t) { |
| 140 | return t->GetRBEntry(); | 140 | return t->GetRBEntry(); |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | template <typename T> | 143 | template <typename T> |
| 144 | requires HasRBEntry<T> | 144 | requires HasRBEntry<T> |
| 145 | [[nodiscard]] constexpr T* RB_LEFT(T* t) { | 145 | [[nodiscard]] constexpr T* RB_LEFT(T* t) { |
| 146 | return RB_ENTRY(t).Left(); | 146 | return RB_ENTRY(t).Left(); |
| 147 | } | 147 | } |
| 148 | template <typename T> | 148 | template <typename T> |
| 149 | requires HasRBEntry<T> | 149 | requires HasRBEntry<T> |
| 150 | [[nodiscard]] constexpr const T* RB_LEFT(const T* t) { | 150 | [[nodiscard]] constexpr const T* RB_LEFT(const T* t) { |
| 151 | return RB_ENTRY(t).Left(); | 151 | return RB_ENTRY(t).Left(); |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | template <typename T> | 154 | template <typename T> |
| 155 | requires HasRBEntry<T> | 155 | requires HasRBEntry<T> |
| 156 | [[nodiscard]] constexpr T* RB_RIGHT(T* t) { | 156 | [[nodiscard]] constexpr T* RB_RIGHT(T* t) { |
| 157 | return RB_ENTRY(t).Right(); | 157 | return RB_ENTRY(t).Right(); |
| 158 | } | 158 | } |
| 159 | template <typename T> | 159 | template <typename T> |
| 160 | requires HasRBEntry<T> | 160 | requires HasRBEntry<T> |
| 161 | [[nodiscard]] constexpr const T* RB_RIGHT(const T* t) { | 161 | [[nodiscard]] constexpr const T* RB_RIGHT(const T* t) { |
| 162 | return RB_ENTRY(t).Right(); | 162 | return RB_ENTRY(t).Right(); |
| 163 | } | 163 | } |
| 164 | 164 | ||
| 165 | template <typename T> | 165 | template <typename T> |
| 166 | requires HasRBEntry<T> | 166 | requires HasRBEntry<T> |
| 167 | [[nodiscard]] constexpr T* RB_PARENT(T* t) { | 167 | [[nodiscard]] constexpr T* RB_PARENT(T* t) { |
| 168 | return RB_ENTRY(t).Parent(); | 168 | return RB_ENTRY(t).Parent(); |
| 169 | } | 169 | } |
| 170 | template <typename T> | 170 | template <typename T> |
| 171 | requires HasRBEntry<T> | 171 | requires HasRBEntry<T> |
| 172 | [[nodiscard]] constexpr const T* RB_PARENT(const T* t) { | 172 | [[nodiscard]] constexpr const T* RB_PARENT(const T* t) { |
| 173 | return RB_ENTRY(t).Parent(); | 173 | return RB_ENTRY(t).Parent(); |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | template <typename T> | 176 | template <typename T> |
| 177 | requires HasRBEntry<T> | 177 | requires HasRBEntry<T> |
| 178 | constexpr void RB_SET_LEFT(T* t, T* e) { | 178 | constexpr void RB_SET_LEFT(T* t, T* e) { |
| 179 | RB_ENTRY(t).SetLeft(e); | 179 | RB_ENTRY(t).SetLeft(e); |
| 180 | } | 180 | } |
| 181 | template <typename T> | 181 | template <typename T> |
| 182 | requires HasRBEntry<T> | 182 | requires HasRBEntry<T> |
| 183 | constexpr void RB_SET_RIGHT(T* t, T* e) { | 183 | constexpr void RB_SET_RIGHT(T* t, T* e) { |
| 184 | RB_ENTRY(t).SetRight(e); | 184 | RB_ENTRY(t).SetRight(e); |
| 185 | } | 185 | } |
| 186 | template <typename T> | 186 | template <typename T> |
| 187 | requires HasRBEntry<T> | 187 | requires HasRBEntry<T> |
| 188 | constexpr void RB_SET_PARENT(T* t, T* e) { | 188 | constexpr void RB_SET_PARENT(T* t, T* e) { |
| 189 | RB_ENTRY(t).SetParent(e); | 189 | RB_ENTRY(t).SetParent(e); |
| 190 | } | 190 | } |
| 191 | 191 | ||
| 192 | template <typename T> | 192 | template <typename T> |
| 193 | requires HasRBEntry<T> | 193 | requires HasRBEntry<T> |
| 194 | [[nodiscard]] constexpr bool RB_IS_BLACK(const T* t) { | 194 | [[nodiscard]] constexpr bool RB_IS_BLACK(const T* t) { |
| 195 | return RB_ENTRY(t).IsBlack(); | 195 | return RB_ENTRY(t).IsBlack(); |
| 196 | } | 196 | } |
| 197 | template <typename T> | 197 | template <typename T> |
| 198 | requires HasRBEntry<T> | 198 | requires HasRBEntry<T> |
| 199 | [[nodiscard]] constexpr bool RB_IS_RED(const T* t) { | 199 | [[nodiscard]] constexpr bool RB_IS_RED(const T* t) { |
| 200 | return RB_ENTRY(t).IsRed(); | 200 | return RB_ENTRY(t).IsRed(); |
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | template <typename T> | 203 | template <typename T> |
| 204 | requires HasRBEntry<T> | 204 | requires HasRBEntry<T> |
| 205 | [[nodiscard]] constexpr RBColor RB_COLOR(const T* t) { | 205 | [[nodiscard]] constexpr RBColor RB_COLOR(const T* t) { |
| 206 | return RB_ENTRY(t).Color(); | 206 | return RB_ENTRY(t).Color(); |
| 207 | } | 207 | } |
| 208 | 208 | ||
| 209 | template <typename T> | 209 | template <typename T> |
| 210 | requires HasRBEntry<T> | 210 | requires HasRBEntry<T> |
| 211 | constexpr void RB_SET_COLOR(T* t, RBColor c) { | 211 | constexpr void RB_SET_COLOR(T* t, RBColor c) { |
| 212 | RB_ENTRY(t).SetColor(c); | 212 | RB_ENTRY(t).SetColor(c); |
| 213 | } | 213 | } |
| 214 | 214 | ||
| 215 | template <typename T> | 215 | template <typename T> |
| 216 | requires HasRBEntry<T> | 216 | requires HasRBEntry<T> |
| 217 | constexpr void RB_SET(T* elm, T* parent) { | 217 | constexpr void RB_SET(T* elm, T* parent) { |
| 218 | auto& rb_entry = RB_ENTRY(elm); | 218 | auto& rb_entry = RB_ENTRY(elm); |
| 219 | rb_entry.SetParent(parent); | 219 | rb_entry.SetParent(parent); |
| @@ -223,14 +223,14 @@ constexpr void RB_SET(T* elm, T* parent) { | |||
| 223 | } | 223 | } |
| 224 | 224 | ||
| 225 | template <typename T> | 225 | template <typename T> |
| 226 | requires HasRBEntry<T> | 226 | requires HasRBEntry<T> |
| 227 | constexpr void RB_SET_BLACKRED(T* black, T* red) { | 227 | constexpr void RB_SET_BLACKRED(T* black, T* red) { |
| 228 | RB_SET_COLOR(black, RBColor::RB_BLACK); | 228 | RB_SET_COLOR(black, RBColor::RB_BLACK); |
| 229 | RB_SET_COLOR(red, RBColor::RB_RED); | 229 | RB_SET_COLOR(red, RBColor::RB_RED); |
| 230 | } | 230 | } |
| 231 | 231 | ||
| 232 | template <typename T> | 232 | template <typename T> |
| 233 | requires HasRBEntry<T> | 233 | requires HasRBEntry<T> |
| 234 | constexpr void RB_ROTATE_LEFT(RBHead<T>& head, T* elm, T*& tmp) { | 234 | constexpr void RB_ROTATE_LEFT(RBHead<T>& head, T* elm, T*& tmp) { |
| 235 | tmp = RB_RIGHT(elm); | 235 | tmp = RB_RIGHT(elm); |
| 236 | if (RB_SET_RIGHT(elm, RB_LEFT(tmp)); RB_RIGHT(elm) != nullptr) { | 236 | if (RB_SET_RIGHT(elm, RB_LEFT(tmp)); RB_RIGHT(elm) != nullptr) { |
| @@ -252,7 +252,7 @@ constexpr void RB_ROTATE_LEFT(RBHead<T>& head, T* elm, T*& tmp) { | |||
| 252 | } | 252 | } |
| 253 | 253 | ||
| 254 | template <typename T> | 254 | template <typename T> |
| 255 | requires HasRBEntry<T> | 255 | requires HasRBEntry<T> |
| 256 | constexpr void RB_ROTATE_RIGHT(RBHead<T>& head, T* elm, T*& tmp) { | 256 | constexpr void RB_ROTATE_RIGHT(RBHead<T>& head, T* elm, T*& tmp) { |
| 257 | tmp = RB_LEFT(elm); | 257 | tmp = RB_LEFT(elm); |
| 258 | if (RB_SET_LEFT(elm, RB_RIGHT(tmp)); RB_LEFT(elm) != nullptr) { | 258 | if (RB_SET_LEFT(elm, RB_RIGHT(tmp)); RB_LEFT(elm) != nullptr) { |
| @@ -274,7 +274,7 @@ constexpr void RB_ROTATE_RIGHT(RBHead<T>& head, T* elm, T*& tmp) { | |||
| 274 | } | 274 | } |
| 275 | 275 | ||
| 276 | template <typename T> | 276 | template <typename T> |
| 277 | requires HasRBEntry<T> | 277 | requires HasRBEntry<T> |
| 278 | constexpr void RB_REMOVE_COLOR(RBHead<T>& head, T* parent, T* elm) { | 278 | constexpr void RB_REMOVE_COLOR(RBHead<T>& head, T* parent, T* elm) { |
| 279 | T* tmp; | 279 | T* tmp; |
| 280 | while ((elm == nullptr || RB_IS_BLACK(elm)) && elm != head.Root()) { | 280 | while ((elm == nullptr || RB_IS_BLACK(elm)) && elm != head.Root()) { |
| @@ -358,7 +358,7 @@ constexpr void RB_REMOVE_COLOR(RBHead<T>& head, T* parent, T* elm) { | |||
| 358 | } | 358 | } |
| 359 | 359 | ||
| 360 | template <typename T> | 360 | template <typename T> |
| 361 | requires HasRBEntry<T> | 361 | requires HasRBEntry<T> |
| 362 | constexpr T* RB_REMOVE(RBHead<T>& head, T* elm) { | 362 | constexpr T* RB_REMOVE(RBHead<T>& head, T* elm) { |
| 363 | T* child = nullptr; | 363 | T* child = nullptr; |
| 364 | T* parent = nullptr; | 364 | T* parent = nullptr; |
| @@ -451,7 +451,7 @@ constexpr T* RB_REMOVE(RBHead<T>& head, T* elm) { | |||
| 451 | } | 451 | } |
| 452 | 452 | ||
| 453 | template <typename T> | 453 | template <typename T> |
| 454 | requires HasRBEntry<T> | 454 | requires HasRBEntry<T> |
| 455 | constexpr void RB_INSERT_COLOR(RBHead<T>& head, T* elm) { | 455 | constexpr void RB_INSERT_COLOR(RBHead<T>& head, T* elm) { |
| 456 | T *parent = nullptr, *tmp = nullptr; | 456 | T *parent = nullptr, *tmp = nullptr; |
| 457 | while ((parent = RB_PARENT(elm)) != nullptr && RB_IS_RED(parent)) { | 457 | while ((parent = RB_PARENT(elm)) != nullptr && RB_IS_RED(parent)) { |
| @@ -499,7 +499,7 @@ constexpr void RB_INSERT_COLOR(RBHead<T>& head, T* elm) { | |||
| 499 | } | 499 | } |
| 500 | 500 | ||
| 501 | template <typename T, typename Compare> | 501 | template <typename T, typename Compare> |
| 502 | requires HasRBEntry<T> | 502 | requires HasRBEntry<T> |
| 503 | constexpr T* RB_INSERT(RBHead<T>& head, T* elm, Compare cmp) { | 503 | constexpr T* RB_INSERT(RBHead<T>& head, T* elm, Compare cmp) { |
| 504 | T* parent = nullptr; | 504 | T* parent = nullptr; |
| 505 | T* tmp = head.Root(); | 505 | T* tmp = head.Root(); |
| @@ -534,7 +534,7 @@ constexpr T* RB_INSERT(RBHead<T>& head, T* elm, Compare cmp) { | |||
| 534 | } | 534 | } |
| 535 | 535 | ||
| 536 | template <typename T, typename Compare> | 536 | template <typename T, typename Compare> |
| 537 | requires HasRBEntry<T> | 537 | requires HasRBEntry<T> |
| 538 | constexpr T* RB_FIND(RBHead<T>& head, T* elm, Compare cmp) { | 538 | constexpr T* RB_FIND(RBHead<T>& head, T* elm, Compare cmp) { |
| 539 | T* tmp = head.Root(); | 539 | T* tmp = head.Root(); |
| 540 | 540 | ||
| @@ -553,7 +553,7 @@ constexpr T* RB_FIND(RBHead<T>& head, T* elm, Compare cmp) { | |||
| 553 | } | 553 | } |
| 554 | 554 | ||
| 555 | template <typename T, typename Compare> | 555 | template <typename T, typename Compare> |
| 556 | requires HasRBEntry<T> | 556 | requires HasRBEntry<T> |
| 557 | constexpr T* RB_NFIND(RBHead<T>& head, T* elm, Compare cmp) { | 557 | constexpr T* RB_NFIND(RBHead<T>& head, T* elm, Compare cmp) { |
| 558 | T* tmp = head.Root(); | 558 | T* tmp = head.Root(); |
| 559 | T* res = nullptr; | 559 | T* res = nullptr; |
| @@ -574,7 +574,7 @@ constexpr T* RB_NFIND(RBHead<T>& head, T* elm, Compare cmp) { | |||
| 574 | } | 574 | } |
| 575 | 575 | ||
| 576 | template <typename T, typename U, typename Compare> | 576 | template <typename T, typename U, typename Compare> |
| 577 | requires HasRBEntry<T> | 577 | requires HasRBEntry<T> |
| 578 | constexpr T* RB_FIND_KEY(RBHead<T>& head, const U& key, Compare cmp) { | 578 | constexpr T* RB_FIND_KEY(RBHead<T>& head, const U& key, Compare cmp) { |
| 579 | T* tmp = head.Root(); | 579 | T* tmp = head.Root(); |
| 580 | 580 | ||
| @@ -593,7 +593,7 @@ constexpr T* RB_FIND_KEY(RBHead<T>& head, const U& key, Compare cmp) { | |||
| 593 | } | 593 | } |
| 594 | 594 | ||
| 595 | template <typename T, typename U, typename Compare> | 595 | template <typename T, typename U, typename Compare> |
| 596 | requires HasRBEntry<T> | 596 | requires HasRBEntry<T> |
| 597 | constexpr T* RB_NFIND_KEY(RBHead<T>& head, const U& key, Compare cmp) { | 597 | constexpr T* RB_NFIND_KEY(RBHead<T>& head, const U& key, Compare cmp) { |
| 598 | T* tmp = head.Root(); | 598 | T* tmp = head.Root(); |
| 599 | T* res = nullptr; | 599 | T* res = nullptr; |
| @@ -614,7 +614,7 @@ constexpr T* RB_NFIND_KEY(RBHead<T>& head, const U& key, Compare cmp) { | |||
| 614 | } | 614 | } |
| 615 | 615 | ||
| 616 | template <typename T, typename Compare> | 616 | template <typename T, typename Compare> |
| 617 | requires HasRBEntry<T> | 617 | requires HasRBEntry<T> |
| 618 | constexpr T* RB_FIND_EXISTING(RBHead<T>& head, T* elm, Compare cmp) { | 618 | constexpr T* RB_FIND_EXISTING(RBHead<T>& head, T* elm, Compare cmp) { |
| 619 | T* tmp = head.Root(); | 619 | T* tmp = head.Root(); |
| 620 | 620 | ||
| @@ -631,7 +631,7 @@ constexpr T* RB_FIND_EXISTING(RBHead<T>& head, T* elm, Compare cmp) { | |||
| 631 | } | 631 | } |
| 632 | 632 | ||
| 633 | template <typename T, typename U, typename Compare> | 633 | template <typename T, typename U, typename Compare> |
| 634 | requires HasRBEntry<T> | 634 | requires HasRBEntry<T> |
| 635 | constexpr T* RB_FIND_EXISTING_KEY(RBHead<T>& head, const U& key, Compare cmp) { | 635 | constexpr T* RB_FIND_EXISTING_KEY(RBHead<T>& head, const U& key, Compare cmp) { |
| 636 | T* tmp = head.Root(); | 636 | T* tmp = head.Root(); |
| 637 | 637 | ||
| @@ -648,7 +648,7 @@ constexpr T* RB_FIND_EXISTING_KEY(RBHead<T>& head, const U& key, Compare cmp) { | |||
| 648 | } | 648 | } |
| 649 | 649 | ||
| 650 | template <typename T> | 650 | template <typename T> |
| 651 | requires HasRBEntry<T> | 651 | requires HasRBEntry<T> |
| 652 | constexpr T* RB_NEXT(T* elm) { | 652 | constexpr T* RB_NEXT(T* elm) { |
| 653 | if (RB_RIGHT(elm)) { | 653 | if (RB_RIGHT(elm)) { |
| 654 | elm = RB_RIGHT(elm); | 654 | elm = RB_RIGHT(elm); |
| @@ -669,7 +669,7 @@ constexpr T* RB_NEXT(T* elm) { | |||
| 669 | } | 669 | } |
| 670 | 670 | ||
| 671 | template <typename T> | 671 | template <typename T> |
| 672 | requires HasRBEntry<T> | 672 | requires HasRBEntry<T> |
| 673 | constexpr T* RB_PREV(T* elm) { | 673 | constexpr T* RB_PREV(T* elm) { |
| 674 | if (RB_LEFT(elm)) { | 674 | if (RB_LEFT(elm)) { |
| 675 | elm = RB_LEFT(elm); | 675 | elm = RB_LEFT(elm); |
| @@ -690,7 +690,7 @@ constexpr T* RB_PREV(T* elm) { | |||
| 690 | } | 690 | } |
| 691 | 691 | ||
| 692 | template <typename T> | 692 | template <typename T> |
| 693 | requires HasRBEntry<T> | 693 | requires HasRBEntry<T> |
| 694 | constexpr T* RB_MIN(RBHead<T>& head) { | 694 | constexpr T* RB_MIN(RBHead<T>& head) { |
| 695 | T* tmp = head.Root(); | 695 | T* tmp = head.Root(); |
| 696 | T* parent = nullptr; | 696 | T* parent = nullptr; |
| @@ -704,7 +704,7 @@ constexpr T* RB_MIN(RBHead<T>& head) { | |||
| 704 | } | 704 | } |
| 705 | 705 | ||
| 706 | template <typename T> | 706 | template <typename T> |
| 707 | requires HasRBEntry<T> | 707 | requires HasRBEntry<T> |
| 708 | constexpr T* RB_MAX(RBHead<T>& head) { | 708 | constexpr T* RB_MAX(RBHead<T>& head) { |
| 709 | T* tmp = head.Root(); | 709 | T* tmp = head.Root(); |
| 710 | T* parent = nullptr; | 710 | T* parent = nullptr; |
diff --git a/src/common/vector_math.h b/src/common/vector_math.h index e62eeea2e..0e2095c45 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h | |||
| @@ -348,9 +348,7 @@ public: | |||
| 348 | // _DEFINE_SWIZZLER2 defines a single such function, DEFINE_SWIZZLER2 defines all of them for all | 348 | // _DEFINE_SWIZZLER2 defines a single such function, DEFINE_SWIZZLER2 defines all of them for all |
| 349 | // component names (x<->r) and permutations (xy<->yx) | 349 | // component names (x<->r) and permutations (xy<->yx) |
| 350 | #define _DEFINE_SWIZZLER2(a, b, name) \ | 350 | #define _DEFINE_SWIZZLER2(a, b, name) \ |
| 351 | [[nodiscard]] constexpr Vec2<T> name() const { \ | 351 | [[nodiscard]] constexpr Vec2<T> name() const { return Vec2<T>(a, b); } |
| 352 | return Vec2<T>(a, b); \ | ||
| 353 | } | ||
| 354 | #define DEFINE_SWIZZLER2(a, b, a2, b2, a3, b3, a4, b4) \ | 352 | #define DEFINE_SWIZZLER2(a, b, a2, b2, a3, b3, a4, b4) \ |
| 355 | _DEFINE_SWIZZLER2(a, b, a##b); \ | 353 | _DEFINE_SWIZZLER2(a, b, a##b); \ |
| 356 | _DEFINE_SWIZZLER2(a, b, a2##b2); \ | 354 | _DEFINE_SWIZZLER2(a, b, a2##b2); \ |
| @@ -543,9 +541,7 @@ public: | |||
| 543 | // DEFINE_SWIZZLER2_COMP2 defines two component functions for all component names (x<->r) and | 541 | // DEFINE_SWIZZLER2_COMP2 defines two component functions for all component names (x<->r) and |
| 544 | // permutations (xy<->yx) | 542 | // permutations (xy<->yx) |
| 545 | #define _DEFINE_SWIZZLER2(a, b, name) \ | 543 | #define _DEFINE_SWIZZLER2(a, b, name) \ |
| 546 | [[nodiscard]] constexpr Vec2<T> name() const { \ | 544 | [[nodiscard]] constexpr Vec2<T> name() const { return Vec2<T>(a, b); } |
| 547 | return Vec2<T>(a, b); \ | ||
| 548 | } | ||
| 549 | #define DEFINE_SWIZZLER2_COMP1(a, a2) \ | 545 | #define DEFINE_SWIZZLER2_COMP1(a, a2) \ |
| 550 | _DEFINE_SWIZZLER2(a, a, a##a); \ | 546 | _DEFINE_SWIZZLER2(a, a, a##a); \ |
| 551 | _DEFINE_SWIZZLER2(a, a, a2##a2) | 547 | _DEFINE_SWIZZLER2(a, a, a2##a2) |
| @@ -570,9 +566,7 @@ public: | |||
| 570 | #undef _DEFINE_SWIZZLER2 | 566 | #undef _DEFINE_SWIZZLER2 |
| 571 | 567 | ||
| 572 | #define _DEFINE_SWIZZLER3(a, b, c, name) \ | 568 | #define _DEFINE_SWIZZLER3(a, b, c, name) \ |
| 573 | [[nodiscard]] constexpr Vec3<T> name() const { \ | 569 | [[nodiscard]] constexpr Vec3<T> name() const { return Vec3<T>(a, b, c); } |
| 574 | return Vec3<T>(a, b, c); \ | ||
| 575 | } | ||
| 576 | #define DEFINE_SWIZZLER3_COMP1(a, a2) \ | 570 | #define DEFINE_SWIZZLER3_COMP1(a, a2) \ |
| 577 | _DEFINE_SWIZZLER3(a, a, a, a##a##a); \ | 571 | _DEFINE_SWIZZLER3(a, a, a, a##a##a); \ |
| 578 | _DEFINE_SWIZZLER3(a, a, a, a2##a2##a2) | 572 | _DEFINE_SWIZZLER3(a, a, a, a2##a2##a2) |
| @@ -641,8 +635,8 @@ template <typename T> | |||
| 641 | 635 | ||
| 642 | // linear interpolation via float: 0.0=begin, 1.0=end | 636 | // linear interpolation via float: 0.0=begin, 1.0=end |
| 643 | template <typename X> | 637 | template <typename X> |
| 644 | [[nodiscard]] constexpr decltype(X{} * float{} + X{} * float{}) | 638 | [[nodiscard]] constexpr decltype(X{} * float{} + X{} * float{}) Lerp(const X& begin, const X& end, |
| 645 | Lerp(const X& begin, const X& end, const float t) { | 639 | const float t) { |
| 646 | return begin * (1.f - t) + end * t; | 640 | return begin * (1.f - t) + end * t; |
| 647 | } | 641 | } |
| 648 | 642 | ||
diff --git a/src/core/hle/kernel/k_auto_object.h b/src/core/hle/kernel/k_auto_object.h index 2827763d5..e8118c2b8 100644 --- a/src/core/hle/kernel/k_auto_object.h +++ b/src/core/hle/kernel/k_auto_object.h | |||
| @@ -24,9 +24,7 @@ private: | |||
| 24 | friend class ::Kernel::KClassTokenGenerator; \ | 24 | friend class ::Kernel::KClassTokenGenerator; \ |
| 25 | static constexpr inline auto ObjectType = ::Kernel::KClassTokenGenerator::ObjectType::CLASS; \ | 25 | static constexpr inline auto ObjectType = ::Kernel::KClassTokenGenerator::ObjectType::CLASS; \ |
| 26 | static constexpr inline const char* const TypeName = #CLASS; \ | 26 | static constexpr inline const char* const TypeName = #CLASS; \ |
| 27 | static constexpr inline ClassTokenType ClassToken() { \ | 27 | static constexpr inline ClassTokenType ClassToken() { return ::Kernel::ClassToken<CLASS>; } \ |
| 28 | return ::Kernel::ClassToken<CLASS>; \ | ||
| 29 | } \ | ||
| 30 | \ | 28 | \ |
| 31 | public: \ | 29 | public: \ |
| 32 | YUZU_NON_COPYABLE(CLASS); \ | 30 | YUZU_NON_COPYABLE(CLASS); \ |
| @@ -37,15 +35,9 @@ public: | |||
| 37 | constexpr ClassTokenType Token = ClassToken(); \ | 35 | constexpr ClassTokenType Token = ClassToken(); \ |
| 38 | return TypeObj(TypeName, Token); \ | 36 | return TypeObj(TypeName, Token); \ |
| 39 | } \ | 37 | } \ |
| 40 | static constexpr const char* GetStaticTypeName() { \ | 38 | static constexpr const char* GetStaticTypeName() { return TypeName; } \ |
| 41 | return TypeName; \ | 39 | virtual TypeObj GetTypeObj() ATTRIBUTE { return GetStaticTypeObj(); } \ |
| 42 | } \ | 40 | virtual const char* GetTypeName() ATTRIBUTE { return GetStaticTypeName(); } \ |
| 43 | virtual TypeObj GetTypeObj() ATTRIBUTE { \ | ||
| 44 | return GetStaticTypeObj(); \ | ||
| 45 | } \ | ||
| 46 | virtual const char* GetTypeName() ATTRIBUTE { \ | ||
| 47 | return GetStaticTypeName(); \ | ||
| 48 | } \ | ||
| 49 | \ | 41 | \ |
| 50 | private: \ | 42 | private: \ |
| 51 | constexpr bool operator!=(const TypeObj& rhs) | 43 | constexpr bool operator!=(const TypeObj& rhs) |
| @@ -245,8 +237,8 @@ public: | |||
| 245 | } | 237 | } |
| 246 | 238 | ||
| 247 | template <typename U> | 239 | template <typename U> |
| 248 | requires(std::derived_from<T, U> || | 240 | requires(std::derived_from<T, U> || std::derived_from<U, T>) |
| 249 | std::derived_from<U, T>) constexpr KScopedAutoObject(KScopedAutoObject<U>&& rhs) { | 241 | constexpr KScopedAutoObject(KScopedAutoObject<U>&& rhs) { |
| 250 | if constexpr (std::derived_from<U, T>) { | 242 | if constexpr (std::derived_from<U, T>) { |
| 251 | // Upcast. | 243 | // Upcast. |
| 252 | m_obj = rhs.m_obj; | 244 | m_obj = rhs.m_obj; |
diff --git a/src/core/hle/kernel/k_priority_queue.h b/src/core/hle/kernel/k_priority_queue.h index cb2512b0b..645c5b531 100644 --- a/src/core/hle/kernel/k_priority_queue.h +++ b/src/core/hle/kernel/k_priority_queue.h | |||
| @@ -17,35 +17,41 @@ namespace Kernel { | |||
| 17 | class KThread; | 17 | class KThread; |
| 18 | 18 | ||
| 19 | template <typename T> | 19 | template <typename T> |
| 20 | concept KPriorityQueueAffinityMask = !std::is_reference_v<T> && requires(T & t) { | 20 | concept KPriorityQueueAffinityMask = ! |
| 21 | { t.GetAffinityMask() } -> Common::ConvertibleTo<u64>; | 21 | std::is_reference_v<T>&& requires(T& t) { |
| 22 | {t.SetAffinityMask(0)}; | 22 | { t.GetAffinityMask() } -> Common::ConvertibleTo<u64>; |
| 23 | { t.SetAffinityMask(0) }; | ||
| 23 | 24 | ||
| 24 | { t.GetAffinity(0) } -> std::same_as<bool>; | 25 | { t.GetAffinity(0) } -> std::same_as<bool>; |
| 25 | {t.SetAffinity(0, false)}; | 26 | { t.SetAffinity(0, false) }; |
| 26 | {t.SetAll()}; | 27 | { t.SetAll() }; |
| 27 | }; | 28 | }; |
| 28 | 29 | ||
| 29 | template <typename T> | 30 | template <typename T> |
| 30 | concept KPriorityQueueMember = !std::is_reference_v<T> && requires(T & t) { | 31 | concept KPriorityQueueMember = ! |
| 31 | {typename T::QueueEntry()}; | 32 | std::is_reference_v<T>&& requires(T& t) { |
| 32 | {(typename T::QueueEntry()).Initialize()}; | 33 | { typename T::QueueEntry() }; |
| 33 | {(typename T::QueueEntry()).SetPrev(std::addressof(t))}; | 34 | { (typename T::QueueEntry()).Initialize() }; |
| 34 | {(typename T::QueueEntry()).SetNext(std::addressof(t))}; | 35 | { (typename T::QueueEntry()).SetPrev(std::addressof(t)) }; |
| 35 | { (typename T::QueueEntry()).GetNext() } -> std::same_as<T*>; | 36 | { (typename T::QueueEntry()).SetNext(std::addressof(t)) }; |
| 36 | { (typename T::QueueEntry()).GetPrev() } -> std::same_as<T*>; | 37 | { (typename T::QueueEntry()).GetNext() } -> std::same_as<T*>; |
| 37 | { t.GetPriorityQueueEntry(0) } -> std::same_as<typename T::QueueEntry&>; | 38 | { (typename T::QueueEntry()).GetPrev() } -> std::same_as<T*>; |
| 38 | 39 | { | |
| 39 | {t.GetAffinityMask()}; | 40 | t.GetPriorityQueueEntry(0) |
| 40 | { std::remove_cvref_t<decltype(t.GetAffinityMask())>() } -> KPriorityQueueAffinityMask; | 41 | } -> std::same_as<typename T::QueueEntry&>; |
| 41 | 42 | ||
| 42 | { t.GetActiveCore() } -> Common::ConvertibleTo<s32>; | 43 | { t.GetAffinityMask() }; |
| 43 | { t.GetPriority() } -> Common::ConvertibleTo<s32>; | 44 | { |
| 44 | { t.IsDummyThread() } -> Common::ConvertibleTo<bool>; | 45 | std::remove_cvref_t<decltype(t.GetAffinityMask())>() |
| 45 | }; | 46 | } -> KPriorityQueueAffinityMask; |
| 47 | |||
| 48 | { t.GetActiveCore() } -> Common::ConvertibleTo<s32>; | ||
| 49 | { t.GetPriority() } -> Common::ConvertibleTo<s32>; | ||
| 50 | { t.IsDummyThread() } -> Common::ConvertibleTo<bool>; | ||
| 51 | }; | ||
| 46 | 52 | ||
| 47 | template <typename Member, size_t NumCores_, int LowestPriority, int HighestPriority> | 53 | template <typename Member, size_t NumCores_, int LowestPriority, int HighestPriority> |
| 48 | requires KPriorityQueueMember<Member> | 54 | requires KPriorityQueueMember<Member> |
| 49 | class KPriorityQueue { | 55 | class KPriorityQueue { |
| 50 | public: | 56 | public: |
| 51 | using AffinityMaskType = std::remove_cv_t< | 57 | using AffinityMaskType = std::remove_cv_t< |
diff --git a/src/core/hle/kernel/k_scoped_lock.h b/src/core/hle/kernel/k_scoped_lock.h index 857e21156..59b3e32ae 100644 --- a/src/core/hle/kernel/k_scoped_lock.h +++ b/src/core/hle/kernel/k_scoped_lock.h | |||
| @@ -9,13 +9,14 @@ | |||
| 9 | namespace Kernel { | 9 | namespace Kernel { |
| 10 | 10 | ||
| 11 | template <typename T> | 11 | template <typename T> |
| 12 | concept KLockable = !std::is_reference_v<T> && requires(T & t) { | 12 | concept KLockable = ! |
| 13 | { t.Lock() } -> std::same_as<void>; | 13 | std::is_reference_v<T>&& requires(T& t) { |
| 14 | { t.Unlock() } -> std::same_as<void>; | 14 | { t.Lock() } -> std::same_as<void>; |
| 15 | }; | 15 | { t.Unlock() } -> std::same_as<void>; |
| 16 | }; | ||
| 16 | 17 | ||
| 17 | template <typename T> | 18 | template <typename T> |
| 18 | requires KLockable<T> | 19 | requires KLockable<T> |
| 19 | class [[nodiscard]] KScopedLock { | 20 | class [[nodiscard]] KScopedLock { |
| 20 | public: | 21 | public: |
| 21 | explicit KScopedLock(T* l) : lock_ptr(l) { | 22 | explicit KScopedLock(T* l) : lock_ptr(l) { |
diff --git a/src/core/hle/kernel/k_thread.h b/src/core/hle/kernel/k_thread.h index 9d771de0e..8b8dc51be 100644 --- a/src/core/hle/kernel/k_thread.h +++ b/src/core/hle/kernel/k_thread.h | |||
| @@ -677,7 +677,7 @@ private: | |||
| 677 | union SyncObjectBuffer { | 677 | union SyncObjectBuffer { |
| 678 | std::array<KSynchronizationObject*, Svc::ArgumentHandleCountMax> sync_objects{}; | 678 | std::array<KSynchronizationObject*, Svc::ArgumentHandleCountMax> sync_objects{}; |
| 679 | std::array<Handle, | 679 | std::array<Handle, |
| 680 | Svc::ArgumentHandleCountMax*(sizeof(KSynchronizationObject*) / sizeof(Handle))> | 680 | Svc::ArgumentHandleCountMax * (sizeof(KSynchronizationObject*) / sizeof(Handle))> |
| 681 | handles; | 681 | handles; |
| 682 | constexpr SyncObjectBuffer() {} | 682 | constexpr SyncObjectBuffer() {} |
| 683 | }; | 683 | }; |
| @@ -698,10 +698,8 @@ private: | |||
| 698 | }; | 698 | }; |
| 699 | 699 | ||
| 700 | template <typename T> | 700 | template <typename T> |
| 701 | requires( | 701 | requires(std::same_as<T, KThread> || std::same_as<T, RedBlackKeyType>) |
| 702 | std::same_as<T, KThread> || | 702 | static constexpr int Compare(const T& lhs, const KThread& rhs) { |
| 703 | std::same_as<T, RedBlackKeyType>) static constexpr int Compare(const T& lhs, | ||
| 704 | const KThread& rhs) { | ||
| 705 | const u64 l_key = lhs.GetConditionVariableKey(); | 703 | const u64 l_key = lhs.GetConditionVariableKey(); |
| 706 | const u64 r_key = rhs.GetConditionVariableKey(); | 704 | const u64 r_key = rhs.GetConditionVariableKey(); |
| 707 | 705 | ||
diff --git a/src/core/hle/kernel/k_thread_local_page.h b/src/core/hle/kernel/k_thread_local_page.h index fe0cff084..71254eb55 100644 --- a/src/core/hle/kernel/k_thread_local_page.h +++ b/src/core/hle/kernel/k_thread_local_page.h | |||
| @@ -70,10 +70,8 @@ public: | |||
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | template <typename T> | 72 | template <typename T> |
| 73 | requires(std::same_as<T, KThreadLocalPage> || | 73 | requires(std::same_as<T, KThreadLocalPage> || std::same_as<T, RedBlackKeyType>) |
| 74 | std::same_as<T, RedBlackKeyType>) static constexpr int Compare(const T& lhs, | 74 | static constexpr int Compare(const T& lhs, const KThreadLocalPage& rhs) { |
| 75 | const KThreadLocalPage& | ||
| 76 | rhs) { | ||
| 77 | const VAddr lval = GetRedBlackKey(lhs); | 75 | const VAddr lval = GetRedBlackKey(lhs); |
| 78 | const VAddr rval = GetRedBlackKey(rhs); | 76 | const VAddr rval = GetRedBlackKey(rhs); |
| 79 | 77 | ||
diff --git a/src/input_common/helpers/joycon_protocol/calibration.cpp b/src/input_common/helpers/joycon_protocol/calibration.cpp index f6e7e97d5..d8f040f75 100644 --- a/src/input_common/helpers/joycon_protocol/calibration.cpp +++ b/src/input_common/helpers/joycon_protocol/calibration.cpp | |||
| @@ -13,33 +13,33 @@ CalibrationProtocol::CalibrationProtocol(std::shared_ptr<JoyconHandle> handle) | |||
| 13 | 13 | ||
| 14 | DriverResult CalibrationProtocol::GetLeftJoyStickCalibration(JoyStickCalibration& calibration) { | 14 | DriverResult CalibrationProtocol::GetLeftJoyStickCalibration(JoyStickCalibration& calibration) { |
| 15 | ScopedSetBlocking sb(this); | 15 | ScopedSetBlocking sb(this); |
| 16 | std::vector<u8> buffer; | ||
| 17 | DriverResult result{DriverResult::Success}; | 16 | DriverResult result{DriverResult::Success}; |
| 17 | JoystickLeftSpiCalibration spi_calibration{}; | ||
| 18 | bool has_user_calibration = false; | ||
| 18 | calibration = {}; | 19 | calibration = {}; |
| 19 | 20 | ||
| 20 | result = ReadSPI(CalAddr::USER_LEFT_MAGIC, sizeof(u16), buffer); | ||
| 21 | |||
| 22 | if (result == DriverResult::Success) { | 21 | if (result == DriverResult::Success) { |
| 23 | const bool has_user_calibration = buffer[0] == 0xB2 && buffer[1] == 0xA1; | 22 | result = HasUserCalibration(SpiAddress::USER_LEFT_MAGIC, has_user_calibration); |
| 24 | if (has_user_calibration) { | ||
| 25 | result = ReadSPI(CalAddr::USER_LEFT_DATA, 9, buffer); | ||
| 26 | } else { | ||
| 27 | result = ReadSPI(CalAddr::FACT_LEFT_DATA, 9, buffer); | ||
| 28 | } | ||
| 29 | } | 23 | } |
| 30 | 24 | ||
| 31 | if (result == DriverResult::Success) { | 25 | // Read User defined calibration |
| 32 | calibration.x.max = static_cast<u16>(((buffer[1] & 0x0F) << 8) | buffer[0]); | 26 | if (result == DriverResult::Success && has_user_calibration) { |
| 33 | calibration.y.max = static_cast<u16>((buffer[2] << 4) | (buffer[1] >> 4)); | 27 | result = ReadSPI(SpiAddress::USER_LEFT_DATA, spi_calibration); |
| 34 | calibration.x.center = static_cast<u16>(((buffer[4] & 0x0F) << 8) | buffer[3]); | ||
| 35 | calibration.y.center = static_cast<u16>((buffer[5] << 4) | (buffer[4] >> 4)); | ||
| 36 | calibration.x.min = static_cast<u16>(((buffer[7] & 0x0F) << 8) | buffer[6]); | ||
| 37 | calibration.y.min = static_cast<u16>((buffer[8] << 4) | (buffer[7] >> 4)); | ||
| 38 | } | 28 | } |
| 39 | 29 | ||
| 40 | // Nintendo fix for drifting stick | 30 | // Read Factory calibration |
| 41 | // result = ReadSPI(0x60, 0x86 ,buffer, 16); | 31 | if (result == DriverResult::Success && !has_user_calibration) { |
| 42 | // calibration.deadzone = (u16)((buffer[4] << 8) & 0xF00 | buffer[3]); | 32 | result = ReadSPI(SpiAddress::FACT_LEFT_DATA, spi_calibration); |
| 33 | } | ||
| 34 | |||
| 35 | if (result == DriverResult::Success) { | ||
| 36 | calibration.x.center = GetXAxisCalibrationValue(spi_calibration.center); | ||
| 37 | calibration.y.center = GetYAxisCalibrationValue(spi_calibration.center); | ||
| 38 | calibration.x.min = GetXAxisCalibrationValue(spi_calibration.min); | ||
| 39 | calibration.y.min = GetYAxisCalibrationValue(spi_calibration.min); | ||
| 40 | calibration.x.max = GetXAxisCalibrationValue(spi_calibration.max); | ||
| 41 | calibration.y.max = GetYAxisCalibrationValue(spi_calibration.max); | ||
| 42 | } | ||
| 43 | 43 | ||
| 44 | // Set a valid default calibration if data is missing | 44 | // Set a valid default calibration if data is missing |
| 45 | ValidateCalibration(calibration); | 45 | ValidateCalibration(calibration); |
| @@ -49,33 +49,33 @@ DriverResult CalibrationProtocol::GetLeftJoyStickCalibration(JoyStickCalibration | |||
| 49 | 49 | ||
| 50 | DriverResult CalibrationProtocol::GetRightJoyStickCalibration(JoyStickCalibration& calibration) { | 50 | DriverResult CalibrationProtocol::GetRightJoyStickCalibration(JoyStickCalibration& calibration) { |
| 51 | ScopedSetBlocking sb(this); | 51 | ScopedSetBlocking sb(this); |
| 52 | std::vector<u8> buffer; | ||
| 53 | DriverResult result{DriverResult::Success}; | 52 | DriverResult result{DriverResult::Success}; |
| 53 | JoystickRightSpiCalibration spi_calibration{}; | ||
| 54 | bool has_user_calibration = false; | ||
| 54 | calibration = {}; | 55 | calibration = {}; |
| 55 | 56 | ||
| 56 | result = ReadSPI(CalAddr::USER_RIGHT_MAGIC, sizeof(u16), buffer); | ||
| 57 | |||
| 58 | if (result == DriverResult::Success) { | 57 | if (result == DriverResult::Success) { |
| 59 | const bool has_user_calibration = buffer[0] == 0xB2 && buffer[1] == 0xA1; | 58 | result = HasUserCalibration(SpiAddress::USER_RIGHT_MAGIC, has_user_calibration); |
| 60 | if (has_user_calibration) { | ||
| 61 | result = ReadSPI(CalAddr::USER_RIGHT_DATA, 9, buffer); | ||
| 62 | } else { | ||
| 63 | result = ReadSPI(CalAddr::FACT_RIGHT_DATA, 9, buffer); | ||
| 64 | } | ||
| 65 | } | 59 | } |
| 66 | 60 | ||
| 67 | if (result == DriverResult::Success) { | 61 | // Read User defined calibration |
| 68 | calibration.x.center = static_cast<u16>(((buffer[1] & 0x0F) << 8) | buffer[0]); | 62 | if (result == DriverResult::Success && has_user_calibration) { |
| 69 | calibration.y.center = static_cast<u16>((buffer[2] << 4) | (buffer[1] >> 4)); | 63 | result = ReadSPI(SpiAddress::USER_RIGHT_DATA, spi_calibration); |
| 70 | calibration.x.min = static_cast<u16>(((buffer[4] & 0x0F) << 8) | buffer[3]); | 64 | } |
| 71 | calibration.y.min = static_cast<u16>((buffer[5] << 4) | (buffer[4] >> 4)); | 65 | |
| 72 | calibration.x.max = static_cast<u16>(((buffer[7] & 0x0F) << 8) | buffer[6]); | 66 | // Read Factory calibration |
| 73 | calibration.y.max = static_cast<u16>((buffer[8] << 4) | (buffer[7] >> 4)); | 67 | if (result == DriverResult::Success && !has_user_calibration) { |
| 68 | result = ReadSPI(SpiAddress::FACT_RIGHT_DATA, spi_calibration); | ||
| 74 | } | 69 | } |
| 75 | 70 | ||
| 76 | // Nintendo fix for drifting stick | 71 | if (result == DriverResult::Success) { |
| 77 | // buffer = ReadSPI(0x60, 0x98 , 16); | 72 | calibration.x.center = GetXAxisCalibrationValue(spi_calibration.center); |
| 78 | // joystick.deadzone = (u16)((buffer[4] << 8) & 0xF00 | buffer[3]); | 73 | calibration.y.center = GetYAxisCalibrationValue(spi_calibration.center); |
| 74 | calibration.x.min = GetXAxisCalibrationValue(spi_calibration.min); | ||
| 75 | calibration.y.min = GetYAxisCalibrationValue(spi_calibration.min); | ||
| 76 | calibration.x.max = GetXAxisCalibrationValue(spi_calibration.max); | ||
| 77 | calibration.y.max = GetYAxisCalibrationValue(spi_calibration.max); | ||
| 78 | } | ||
| 79 | 79 | ||
| 80 | // Set a valid default calibration if data is missing | 80 | // Set a valid default calibration if data is missing |
| 81 | ValidateCalibration(calibration); | 81 | ValidateCalibration(calibration); |
| @@ -85,39 +85,41 @@ DriverResult CalibrationProtocol::GetRightJoyStickCalibration(JoyStickCalibratio | |||
| 85 | 85 | ||
| 86 | DriverResult CalibrationProtocol::GetImuCalibration(MotionCalibration& calibration) { | 86 | DriverResult CalibrationProtocol::GetImuCalibration(MotionCalibration& calibration) { |
| 87 | ScopedSetBlocking sb(this); | 87 | ScopedSetBlocking sb(this); |
| 88 | std::vector<u8> buffer; | ||
| 89 | DriverResult result{DriverResult::Success}; | 88 | DriverResult result{DriverResult::Success}; |
| 89 | ImuSpiCalibration spi_calibration{}; | ||
| 90 | bool has_user_calibration = false; | ||
| 90 | calibration = {}; | 91 | calibration = {}; |
| 91 | 92 | ||
| 92 | result = ReadSPI(CalAddr::USER_IMU_MAGIC, sizeof(u16), buffer); | ||
| 93 | |||
| 94 | if (result == DriverResult::Success) { | 93 | if (result == DriverResult::Success) { |
| 95 | const bool has_user_calibration = buffer[0] == 0xB2 && buffer[1] == 0xA1; | 94 | result = HasUserCalibration(SpiAddress::USER_IMU_MAGIC, has_user_calibration); |
| 96 | if (has_user_calibration) { | 95 | } |
| 97 | result = ReadSPI(CalAddr::USER_IMU_DATA, sizeof(IMUCalibration), buffer); | 96 | |
| 98 | } else { | 97 | // Read User defined calibration |
| 99 | result = ReadSPI(CalAddr::FACT_IMU_DATA, sizeof(IMUCalibration), buffer); | 98 | if (result == DriverResult::Success && has_user_calibration) { |
| 100 | } | 99 | result = ReadSPI(SpiAddress::USER_IMU_DATA, spi_calibration); |
| 100 | } | ||
| 101 | |||
| 102 | // Read Factory calibration | ||
| 103 | if (result == DriverResult::Success && !has_user_calibration) { | ||
| 104 | result = ReadSPI(SpiAddress::FACT_IMU_DATA, spi_calibration); | ||
| 101 | } | 105 | } |
| 102 | 106 | ||
| 103 | if (result == DriverResult::Success) { | 107 | if (result == DriverResult::Success) { |
| 104 | IMUCalibration device_calibration{}; | 108 | calibration.accelerometer[0].offset = spi_calibration.accelerometer_offset[0]; |
| 105 | memcpy(&device_calibration, buffer.data(), sizeof(IMUCalibration)); | 109 | calibration.accelerometer[1].offset = spi_calibration.accelerometer_offset[1]; |
| 106 | calibration.accelerometer[0].offset = device_calibration.accelerometer_offset[0]; | 110 | calibration.accelerometer[2].offset = spi_calibration.accelerometer_offset[2]; |
| 107 | calibration.accelerometer[1].offset = device_calibration.accelerometer_offset[1]; | ||
| 108 | calibration.accelerometer[2].offset = device_calibration.accelerometer_offset[2]; | ||
| 109 | 111 | ||
| 110 | calibration.accelerometer[0].scale = device_calibration.accelerometer_scale[0]; | 112 | calibration.accelerometer[0].scale = spi_calibration.accelerometer_scale[0]; |
| 111 | calibration.accelerometer[1].scale = device_calibration.accelerometer_scale[1]; | 113 | calibration.accelerometer[1].scale = spi_calibration.accelerometer_scale[1]; |
| 112 | calibration.accelerometer[2].scale = device_calibration.accelerometer_scale[2]; | 114 | calibration.accelerometer[2].scale = spi_calibration.accelerometer_scale[2]; |
| 113 | 115 | ||
| 114 | calibration.gyro[0].offset = device_calibration.gyroscope_offset[0]; | 116 | calibration.gyro[0].offset = spi_calibration.gyroscope_offset[0]; |
| 115 | calibration.gyro[1].offset = device_calibration.gyroscope_offset[1]; | 117 | calibration.gyro[1].offset = spi_calibration.gyroscope_offset[1]; |
| 116 | calibration.gyro[2].offset = device_calibration.gyroscope_offset[2]; | 118 | calibration.gyro[2].offset = spi_calibration.gyroscope_offset[2]; |
| 117 | 119 | ||
| 118 | calibration.gyro[0].scale = device_calibration.gyroscope_scale[0]; | 120 | calibration.gyro[0].scale = spi_calibration.gyroscope_scale[0]; |
| 119 | calibration.gyro[1].scale = device_calibration.gyroscope_scale[1]; | 121 | calibration.gyro[1].scale = spi_calibration.gyroscope_scale[1]; |
| 120 | calibration.gyro[2].scale = device_calibration.gyroscope_scale[2]; | 122 | calibration.gyro[2].scale = spi_calibration.gyroscope_scale[2]; |
| 121 | } | 123 | } |
| 122 | 124 | ||
| 123 | ValidateCalibration(calibration); | 125 | ValidateCalibration(calibration); |
| @@ -127,10 +129,12 @@ DriverResult CalibrationProtocol::GetImuCalibration(MotionCalibration& calibrati | |||
| 127 | 129 | ||
| 128 | DriverResult CalibrationProtocol::GetRingCalibration(RingCalibration& calibration, | 130 | DriverResult CalibrationProtocol::GetRingCalibration(RingCalibration& calibration, |
| 129 | s16 current_value) { | 131 | s16 current_value) { |
| 132 | constexpr s16 DefaultRingRange{800}; | ||
| 133 | |||
| 130 | // TODO: Get default calibration form ring itself | 134 | // TODO: Get default calibration form ring itself |
| 131 | if (ring_data_max == 0 && ring_data_min == 0) { | 135 | if (ring_data_max == 0 && ring_data_min == 0) { |
| 132 | ring_data_max = current_value + 800; | 136 | ring_data_max = current_value + DefaultRingRange; |
| 133 | ring_data_min = current_value - 800; | 137 | ring_data_min = current_value - DefaultRingRange; |
| 134 | ring_data_default = current_value; | 138 | ring_data_default = current_value; |
| 135 | } | 139 | } |
| 136 | ring_data_max = std::max(ring_data_max, current_value); | 140 | ring_data_max = std::max(ring_data_max, current_value); |
| @@ -143,42 +147,72 @@ DriverResult CalibrationProtocol::GetRingCalibration(RingCalibration& calibratio | |||
| 143 | return DriverResult::Success; | 147 | return DriverResult::Success; |
| 144 | } | 148 | } |
| 145 | 149 | ||
| 150 | DriverResult CalibrationProtocol::HasUserCalibration(SpiAddress address, | ||
| 151 | bool& has_user_calibration) { | ||
| 152 | MagicSpiCalibration spi_magic{}; | ||
| 153 | const DriverResult result{ReadSPI(address, spi_magic)}; | ||
| 154 | has_user_calibration = false; | ||
| 155 | if (result == DriverResult::Success) { | ||
| 156 | has_user_calibration = spi_magic.first == CalibrationMagic::USR_MAGIC_0 && | ||
| 157 | spi_magic.second == CalibrationMagic::USR_MAGIC_1; | ||
| 158 | } | ||
| 159 | return result; | ||
| 160 | } | ||
| 161 | |||
| 162 | u16 CalibrationProtocol::GetXAxisCalibrationValue(std::span<u8> block) const { | ||
| 163 | return static_cast<u16>(((block[1] & 0x0F) << 8) | block[0]); | ||
| 164 | } | ||
| 165 | |||
| 166 | u16 CalibrationProtocol::GetYAxisCalibrationValue(std::span<u8> block) const { | ||
| 167 | return static_cast<u16>((block[2] << 4) | (block[1] >> 4)); | ||
| 168 | } | ||
| 169 | |||
| 146 | void CalibrationProtocol::ValidateCalibration(JoyStickCalibration& calibration) { | 170 | void CalibrationProtocol::ValidateCalibration(JoyStickCalibration& calibration) { |
| 147 | constexpr u16 DefaultStickCenter{2048}; | 171 | constexpr u16 DefaultStickCenter{0x800}; |
| 148 | constexpr u16 DefaultStickRange{1740}; | 172 | constexpr u16 DefaultStickRange{0x6cc}; |
| 149 | 173 | ||
| 150 | if (calibration.x.center == 0xFFF || calibration.x.center == 0) { | 174 | calibration.x.center = ValidateValue(calibration.x.center, DefaultStickCenter); |
| 151 | calibration.x.center = DefaultStickCenter; | 175 | calibration.x.max = ValidateValue(calibration.x.max, DefaultStickRange); |
| 152 | } | 176 | calibration.x.min = ValidateValue(calibration.x.min, DefaultStickRange); |
| 153 | if (calibration.x.max == 0xFFF || calibration.x.max == 0) { | 177 | |
| 154 | calibration.x.max = DefaultStickRange; | 178 | calibration.y.center = ValidateValue(calibration.y.center, DefaultStickCenter); |
| 179 | calibration.y.max = ValidateValue(calibration.y.max, DefaultStickRange); | ||
| 180 | calibration.y.min = ValidateValue(calibration.y.min, DefaultStickRange); | ||
| 181 | } | ||
| 182 | |||
| 183 | void CalibrationProtocol::ValidateCalibration(MotionCalibration& calibration) { | ||
| 184 | constexpr s16 DefaultAccelerometerScale{0x4000}; | ||
| 185 | constexpr s16 DefaultGyroScale{0x3be7}; | ||
| 186 | constexpr s16 DefaultOffset{0}; | ||
| 187 | |||
| 188 | for (auto& sensor : calibration.accelerometer) { | ||
| 189 | sensor.scale = ValidateValue(sensor.scale, DefaultAccelerometerScale); | ||
| 190 | sensor.offset = ValidateValue(sensor.offset, DefaultOffset); | ||
| 155 | } | 191 | } |
| 156 | if (calibration.x.min == 0xFFF || calibration.x.min == 0) { | 192 | for (auto& sensor : calibration.gyro) { |
| 157 | calibration.x.min = DefaultStickRange; | 193 | sensor.scale = ValidateValue(sensor.scale, DefaultGyroScale); |
| 194 | sensor.offset = ValidateValue(sensor.offset, DefaultOffset); | ||
| 158 | } | 195 | } |
| 196 | } | ||
| 159 | 197 | ||
| 160 | if (calibration.y.center == 0xFFF || calibration.y.center == 0) { | 198 | u16 CalibrationProtocol::ValidateValue(u16 value, u16 default_value) const { |
| 161 | calibration.y.center = DefaultStickCenter; | 199 | if (value == 0) { |
| 162 | } | 200 | return default_value; |
| 163 | if (calibration.y.max == 0xFFF || calibration.y.max == 0) { | ||
| 164 | calibration.y.max = DefaultStickRange; | ||
| 165 | } | 201 | } |
| 166 | if (calibration.y.min == 0xFFF || calibration.y.min == 0) { | 202 | if (value == 0xFFF) { |
| 167 | calibration.y.min = DefaultStickRange; | 203 | return default_value; |
| 168 | } | 204 | } |
| 205 | return value; | ||
| 169 | } | 206 | } |
| 170 | 207 | ||
| 171 | void CalibrationProtocol::ValidateCalibration(MotionCalibration& calibration) { | 208 | s16 CalibrationProtocol::ValidateValue(s16 value, s16 default_value) const { |
| 172 | for (auto& sensor : calibration.accelerometer) { | 209 | if (value == 0) { |
| 173 | if (sensor.scale == 0) { | 210 | return default_value; |
| 174 | sensor.scale = 0x4000; | ||
| 175 | } | ||
| 176 | } | 211 | } |
| 177 | for (auto& sensor : calibration.gyro) { | 212 | if (value == 0xFFF) { |
| 178 | if (sensor.scale == 0) { | 213 | return default_value; |
| 179 | sensor.scale = 0x3be7; | ||
| 180 | } | ||
| 181 | } | 214 | } |
| 215 | return value; | ||
| 182 | } | 216 | } |
| 183 | 217 | ||
| 184 | } // namespace InputCommon::Joycon | 218 | } // namespace InputCommon::Joycon |
diff --git a/src/input_common/helpers/joycon_protocol/calibration.h b/src/input_common/helpers/joycon_protocol/calibration.h index afb52a36a..c6fd0f729 100644 --- a/src/input_common/helpers/joycon_protocol/calibration.h +++ b/src/input_common/helpers/joycon_protocol/calibration.h | |||
| @@ -53,9 +53,27 @@ public: | |||
| 53 | DriverResult GetRingCalibration(RingCalibration& calibration, s16 current_value); | 53 | DriverResult GetRingCalibration(RingCalibration& calibration, s16 current_value); |
| 54 | 54 | ||
| 55 | private: | 55 | private: |
| 56 | /// Returns true if the specified address corresponds to the magic value of user calibration | ||
| 57 | DriverResult HasUserCalibration(SpiAddress address, bool& has_user_calibration); | ||
| 58 | |||
| 59 | /// Converts a raw calibration block to an u16 value containing the x axis value | ||
| 60 | u16 GetXAxisCalibrationValue(std::span<u8> block) const; | ||
| 61 | |||
| 62 | /// Converts a raw calibration block to an u16 value containing the y axis value | ||
| 63 | u16 GetYAxisCalibrationValue(std::span<u8> block) const; | ||
| 64 | |||
| 65 | /// Ensures that all joystick calibration values are set | ||
| 56 | void ValidateCalibration(JoyStickCalibration& calibration); | 66 | void ValidateCalibration(JoyStickCalibration& calibration); |
| 67 | |||
| 68 | /// Ensures that all motion calibration values are set | ||
| 57 | void ValidateCalibration(MotionCalibration& calibration); | 69 | void ValidateCalibration(MotionCalibration& calibration); |
| 58 | 70 | ||
| 71 | /// Returns the default value if the value is either zero or 0xFFF | ||
| 72 | u16 ValidateValue(u16 value, u16 default_value) const; | ||
| 73 | |||
| 74 | /// Returns the default value if the value is either zero or 0xFFF | ||
| 75 | s16 ValidateValue(s16 value, s16 default_value) const; | ||
| 76 | |||
| 59 | s16 ring_data_max = 0; | 77 | s16 ring_data_max = 0; |
| 60 | s16 ring_data_default = 0; | 78 | s16 ring_data_default = 0; |
| 61 | s16 ring_data_min = 0; | 79 | s16 ring_data_min = 0; |
diff --git a/src/input_common/helpers/joycon_protocol/common_protocol.cpp b/src/input_common/helpers/joycon_protocol/common_protocol.cpp index 417d0dcc5..0ef240344 100644 --- a/src/input_common/helpers/joycon_protocol/common_protocol.cpp +++ b/src/input_common/helpers/joycon_protocol/common_protocol.cpp | |||
| @@ -22,8 +22,8 @@ void JoyconCommonProtocol::SetNonBlocking() { | |||
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | DriverResult JoyconCommonProtocol::GetDeviceType(ControllerType& controller_type) { | 24 | DriverResult JoyconCommonProtocol::GetDeviceType(ControllerType& controller_type) { |
| 25 | std::vector<u8> buffer; | 25 | std::array<u8, 1> buffer{}; |
| 26 | const auto result = ReadSPI(CalAddr::DEVICE_TYPE, 1, buffer); | 26 | const auto result = ReadRawSPI(SpiAddress::DEVICE_TYPE, buffer); |
| 27 | controller_type = ControllerType::None; | 27 | controller_type = ControllerType::None; |
| 28 | 28 | ||
| 29 | if (result == DriverResult::Success) { | 29 | if (result == DriverResult::Success) { |
| @@ -148,11 +148,13 @@ DriverResult JoyconCommonProtocol::SendVibrationReport(std::span<const u8> buffe | |||
| 148 | return SendData(local_buffer); | 148 | return SendData(local_buffer); |
| 149 | } | 149 | } |
| 150 | 150 | ||
| 151 | DriverResult JoyconCommonProtocol::ReadSPI(CalAddr addr, u8 size, std::vector<u8>& output) { | 151 | DriverResult JoyconCommonProtocol::ReadRawSPI(SpiAddress addr, std::span<u8> output) { |
| 152 | constexpr std::size_t HeaderSize = 20; | ||
| 152 | constexpr std::size_t MaxTries = 10; | 153 | constexpr std::size_t MaxTries = 10; |
| 154 | const auto size = output.size(); | ||
| 153 | std::size_t tries = 0; | 155 | std::size_t tries = 0; |
| 154 | std::array<u8, 5> buffer = {0x00, 0x00, 0x00, 0x00, size}; | 156 | std::array<u8, 5> buffer = {0x00, 0x00, 0x00, 0x00, static_cast<u8>(size)}; |
| 155 | std::vector<u8> local_buffer(size + 20); | 157 | std::vector<u8> local_buffer{}; |
| 156 | 158 | ||
| 157 | buffer[0] = static_cast<u8>(static_cast<u16>(addr) & 0x00FF); | 159 | buffer[0] = static_cast<u8>(static_cast<u16>(addr) & 0x00FF); |
| 158 | buffer[1] = static_cast<u8>((static_cast<u16>(addr) & 0xFF00) >> 8); | 160 | buffer[1] = static_cast<u8>((static_cast<u16>(addr) & 0xFF00) >> 8); |
| @@ -167,8 +169,12 @@ DriverResult JoyconCommonProtocol::ReadSPI(CalAddr addr, u8 size, std::vector<u8 | |||
| 167 | } | 169 | } |
| 168 | } while (local_buffer[15] != buffer[0] || local_buffer[16] != buffer[1]); | 170 | } while (local_buffer[15] != buffer[0] || local_buffer[16] != buffer[1]); |
| 169 | 171 | ||
| 172 | if (local_buffer.size() < size + HeaderSize) { | ||
| 173 | return DriverResult::WrongReply; | ||
| 174 | } | ||
| 175 | |||
| 170 | // Remove header from output | 176 | // Remove header from output |
| 171 | output = std::vector<u8>(local_buffer.begin() + 20, local_buffer.begin() + 20 + size); | 177 | memcpy(output.data(), local_buffer.data() + HeaderSize, size); |
| 172 | return DriverResult::Success; | 178 | return DriverResult::Success; |
| 173 | } | 179 | } |
| 174 | 180 | ||
diff --git a/src/input_common/helpers/joycon_protocol/common_protocol.h b/src/input_common/helpers/joycon_protocol/common_protocol.h index 903bcf402..188f6ecfa 100644 --- a/src/input_common/helpers/joycon_protocol/common_protocol.h +++ b/src/input_common/helpers/joycon_protocol/common_protocol.h | |||
| @@ -97,10 +97,29 @@ public: | |||
| 97 | /** | 97 | /** |
| 98 | * Reads the SPI memory stored on the joycon | 98 | * Reads the SPI memory stored on the joycon |
| 99 | * @param Initial address location | 99 | * @param Initial address location |
| 100 | * @param size in bytes to be read | ||
| 101 | * @returns output buffer containing the responce | 100 | * @returns output buffer containing the responce |
| 102 | */ | 101 | */ |
| 103 | DriverResult ReadSPI(CalAddr addr, u8 size, std::vector<u8>& output); | 102 | DriverResult ReadRawSPI(SpiAddress addr, std::span<u8> output); |
| 103 | |||
| 104 | /** | ||
| 105 | * Reads the SPI memory stored on the joycon | ||
| 106 | * @param Initial address location | ||
| 107 | * @returns output object containing the responce | ||
| 108 | */ | ||
| 109 | template <typename Output> | ||
| 110 | requires std::is_trivially_copyable_v<Output> | ||
| 111 | DriverResult ReadSPI(SpiAddress addr, Output& output) { | ||
| 112 | std::array<u8, sizeof(Output)> buffer; | ||
| 113 | output = {}; | ||
| 114 | |||
| 115 | const auto result = ReadRawSPI(addr, buffer); | ||
| 116 | if (result != DriverResult::Success) { | ||
| 117 | return result; | ||
| 118 | } | ||
| 119 | |||
| 120 | std::memcpy(&output, buffer.data(), sizeof(Output)); | ||
| 121 | return DriverResult::Success; | ||
| 122 | } | ||
| 104 | 123 | ||
| 105 | /** | 124 | /** |
| 106 | * Enables MCU chip on the joycon | 125 | * Enables MCU chip on the joycon |
diff --git a/src/input_common/helpers/joycon_protocol/generic_functions.cpp b/src/input_common/helpers/joycon_protocol/generic_functions.cpp index 63cfb1369..484c208e6 100644 --- a/src/input_common/helpers/joycon_protocol/generic_functions.cpp +++ b/src/input_common/helpers/joycon_protocol/generic_functions.cpp | |||
| @@ -71,8 +71,8 @@ DriverResult GenericProtocol::GetBattery(u32& battery_level) { | |||
| 71 | 71 | ||
| 72 | DriverResult GenericProtocol::GetColor(Color& color) { | 72 | DriverResult GenericProtocol::GetColor(Color& color) { |
| 73 | ScopedSetBlocking sb(this); | 73 | ScopedSetBlocking sb(this); |
| 74 | std::vector<u8> buffer; | 74 | std::array<u8, 12> buffer{}; |
| 75 | const auto result = ReadSPI(CalAddr::COLOR_DATA, 12, buffer); | 75 | const auto result = ReadRawSPI(SpiAddress::COLOR_DATA, buffer); |
| 76 | 76 | ||
| 77 | color = {}; | 77 | color = {}; |
| 78 | if (result == DriverResult::Success) { | 78 | if (result == DriverResult::Success) { |
| @@ -87,8 +87,8 @@ DriverResult GenericProtocol::GetColor(Color& color) { | |||
| 87 | 87 | ||
| 88 | DriverResult GenericProtocol::GetSerialNumber(SerialNumber& serial_number) { | 88 | DriverResult GenericProtocol::GetSerialNumber(SerialNumber& serial_number) { |
| 89 | ScopedSetBlocking sb(this); | 89 | ScopedSetBlocking sb(this); |
| 90 | std::vector<u8> buffer; | 90 | std::array<u8, 16> buffer{}; |
| 91 | const auto result = ReadSPI(CalAddr::SERIAL_NUMBER, 16, buffer); | 91 | const auto result = ReadRawSPI(SpiAddress::SERIAL_NUMBER, buffer); |
| 92 | 92 | ||
| 93 | serial_number = {}; | 93 | serial_number = {}; |
| 94 | if (result == DriverResult::Success) { | 94 | if (result == DriverResult::Success) { |
diff --git a/src/input_common/helpers/joycon_protocol/joycon_types.h b/src/input_common/helpers/joycon_protocol/joycon_types.h index 182d2c15b..14b07bfb5 100644 --- a/src/input_common/helpers/joycon_protocol/joycon_types.h +++ b/src/input_common/helpers/joycon_protocol/joycon_types.h | |||
| @@ -159,13 +159,12 @@ enum class UsbSubCommand : u8 { | |||
| 159 | SEND_UART = 0x92, | 159 | SEND_UART = 0x92, |
| 160 | }; | 160 | }; |
| 161 | 161 | ||
| 162 | enum class CalMagic : u8 { | 162 | enum class CalibrationMagic : u8 { |
| 163 | USR_MAGIC_0 = 0xB2, | 163 | USR_MAGIC_0 = 0xB2, |
| 164 | USR_MAGIC_1 = 0xA1, | 164 | USR_MAGIC_1 = 0xA1, |
| 165 | USRR_MAGI_SIZE = 2, | ||
| 166 | }; | 165 | }; |
| 167 | 166 | ||
| 168 | enum class CalAddr { | 167 | enum class SpiAddress { |
| 169 | SERIAL_NUMBER = 0X6000, | 168 | SERIAL_NUMBER = 0X6000, |
| 170 | DEVICE_TYPE = 0X6012, | 169 | DEVICE_TYPE = 0X6012, |
| 171 | COLOR_EXIST = 0X601B, | 170 | COLOR_EXIST = 0X601B, |
| @@ -396,10 +395,35 @@ struct MotionData { | |||
| 396 | u64 delta_timestamp{}; | 395 | u64 delta_timestamp{}; |
| 397 | }; | 396 | }; |
| 398 | 397 | ||
| 398 | // Output from SPI read command containing user calibration magic | ||
| 399 | struct MagicSpiCalibration { | ||
| 400 | CalibrationMagic first; | ||
| 401 | CalibrationMagic second; | ||
| 402 | }; | ||
| 403 | static_assert(sizeof(MagicSpiCalibration) == 0x2, "MagicSpiCalibration is an invalid size"); | ||
| 404 | |||
| 405 | // Output from SPI read command containing left joystick calibration | ||
| 406 | struct JoystickLeftSpiCalibration { | ||
| 407 | std::array<u8, 3> max; | ||
| 408 | std::array<u8, 3> center; | ||
| 409 | std::array<u8, 3> min; | ||
| 410 | }; | ||
| 411 | static_assert(sizeof(JoystickLeftSpiCalibration) == 0x9, | ||
| 412 | "JoystickLeftSpiCalibration is an invalid size"); | ||
| 413 | |||
| 414 | // Output from SPI read command containing right joystick calibration | ||
| 415 | struct JoystickRightSpiCalibration { | ||
| 416 | std::array<u8, 3> center; | ||
| 417 | std::array<u8, 3> min; | ||
| 418 | std::array<u8, 3> max; | ||
| 419 | }; | ||
| 420 | static_assert(sizeof(JoystickRightSpiCalibration) == 0x9, | ||
| 421 | "JoystickRightSpiCalibration is an invalid size"); | ||
| 422 | |||
| 399 | struct JoyStickAxisCalibration { | 423 | struct JoyStickAxisCalibration { |
| 400 | u16 max{1}; | 424 | u16 max; |
| 401 | u16 min{1}; | 425 | u16 min; |
| 402 | u16 center{0}; | 426 | u16 center; |
| 403 | }; | 427 | }; |
| 404 | 428 | ||
| 405 | struct JoyStickCalibration { | 429 | struct JoyStickCalibration { |
| @@ -407,6 +431,14 @@ struct JoyStickCalibration { | |||
| 407 | JoyStickAxisCalibration y; | 431 | JoyStickAxisCalibration y; |
| 408 | }; | 432 | }; |
| 409 | 433 | ||
| 434 | struct ImuSpiCalibration { | ||
| 435 | std::array<s16, 3> accelerometer_offset; | ||
| 436 | std::array<s16, 3> accelerometer_scale; | ||
| 437 | std::array<s16, 3> gyroscope_offset; | ||
| 438 | std::array<s16, 3> gyroscope_scale; | ||
| 439 | }; | ||
| 440 | static_assert(sizeof(ImuSpiCalibration) == 0x18, "ImuSpiCalibration is an invalid size"); | ||
| 441 | |||
| 410 | struct RingCalibration { | 442 | struct RingCalibration { |
| 411 | s16 default_value; | 443 | s16 default_value; |
| 412 | s16 max_value; | 444 | s16 max_value; |
| @@ -488,14 +520,6 @@ struct InputReportNfcIr { | |||
| 488 | static_assert(sizeof(InputReportNfcIr) == 0x29, "InputReportNfcIr is an invalid size"); | 520 | static_assert(sizeof(InputReportNfcIr) == 0x29, "InputReportNfcIr is an invalid size"); |
| 489 | #pragma pack(pop) | 521 | #pragma pack(pop) |
| 490 | 522 | ||
| 491 | struct IMUCalibration { | ||
| 492 | std::array<s16, 3> accelerometer_offset; | ||
| 493 | std::array<s16, 3> accelerometer_scale; | ||
| 494 | std::array<s16, 3> gyroscope_offset; | ||
| 495 | std::array<s16, 3> gyroscope_scale; | ||
| 496 | }; | ||
| 497 | static_assert(sizeof(IMUCalibration) == 0x18, "IMUCalibration is an invalid size"); | ||
| 498 | |||
| 499 | struct NFCReadBlock { | 523 | struct NFCReadBlock { |
| 500 | u8 start; | 524 | u8 start; |
| 501 | u8 end; | 525 | u8 end; |
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm.cpp b/src/shader_recompiler/backend/glasm/emit_glasm.cpp index 0cb1e193e..fd4a61a4d 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm.cpp | |||
| @@ -279,6 +279,8 @@ void SetupOptions(const IR::Program& program, const Profile& profile, | |||
| 279 | header += "OPTION NV_internal;" | 279 | header += "OPTION NV_internal;" |
| 280 | "OPTION NV_shader_storage_buffer;" | 280 | "OPTION NV_shader_storage_buffer;" |
| 281 | "OPTION NV_gpu_program_fp64;"; | 281 | "OPTION NV_gpu_program_fp64;"; |
| 282 | // TODO: Enable only when MS is used | ||
| 283 | header += "OPTION NV_texture_multisample;"; | ||
| 282 | if (info.uses_int64_bit_atomics) { | 284 | if (info.uses_int64_bit_atomics) { |
| 283 | header += "OPTION NV_shader_atomic_int64;"; | 285 | header += "OPTION NV_shader_atomic_int64;"; |
| 284 | } | 286 | } |
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_bitwise_conversion.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_bitwise_conversion.cpp index 5bfdecc09..2fc2a0ac6 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_bitwise_conversion.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm_bitwise_conversion.cpp | |||
| @@ -43,10 +43,6 @@ void EmitBitCastU64F64(EmitContext&, IR::Inst& inst, const IR::Value& value) { | |||
| 43 | Alias(inst, value); | 43 | Alias(inst, value); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | void EmitBitCastS32F32(EmitContext&, IR::Inst& inst, const IR::Value& value) { | ||
| 47 | Alias(inst, value); | ||
| 48 | } | ||
| 49 | |||
| 50 | void EmitBitCastF16U16(EmitContext&, IR::Inst& inst, const IR::Value& value) { | 46 | void EmitBitCastF16U16(EmitContext&, IR::Inst& inst, const IR::Value& value) { |
| 51 | Alias(inst, value); | 47 | Alias(inst, value); |
| 52 | } | 48 | } |
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp b/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp index e67e80fac..b7bc11416 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp +++ b/src/shader_recompiler/backend/glasm/emit_glasm_image.cpp | |||
| @@ -59,7 +59,7 @@ std::string Image(EmitContext& ctx, IR::TextureInstInfo info, | |||
| 59 | } | 59 | } |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | std::string_view TextureType(IR::TextureInstInfo info) { | 62 | std::string_view TextureType(IR::TextureInstInfo info, bool is_ms = false) { |
| 63 | if (info.is_depth) { | 63 | if (info.is_depth) { |
| 64 | switch (info.type) { | 64 | switch (info.type) { |
| 65 | case TextureType::Color1D: | 65 | case TextureType::Color1D: |
| @@ -88,9 +88,9 @@ std::string_view TextureType(IR::TextureInstInfo info) { | |||
| 88 | return "ARRAY1D"; | 88 | return "ARRAY1D"; |
| 89 | case TextureType::Color2D: | 89 | case TextureType::Color2D: |
| 90 | case TextureType::Color2DRect: | 90 | case TextureType::Color2DRect: |
| 91 | return "2D"; | 91 | return is_ms ? "2DMS" : "2D"; |
| 92 | case TextureType::ColorArray2D: | 92 | case TextureType::ColorArray2D: |
| 93 | return "ARRAY2D"; | 93 | return is_ms ? "ARRAY2DMS" : "ARRAY2D"; |
| 94 | case TextureType::Color3D: | 94 | case TextureType::Color3D: |
| 95 | return "3D"; | 95 | return "3D"; |
| 96 | case TextureType::ColorCube: | 96 | case TextureType::ColorCube: |
| @@ -510,15 +510,16 @@ void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | |||
| 510 | const IR::Value& coord, const IR::Value& offset, ScalarS32 lod, ScalarS32 ms) { | 510 | const IR::Value& coord, const IR::Value& offset, ScalarS32 lod, ScalarS32 ms) { |
| 511 | const auto info{inst.Flags<IR::TextureInstInfo>()}; | 511 | const auto info{inst.Flags<IR::TextureInstInfo>()}; |
| 512 | const auto sparse_inst{PrepareSparse(inst)}; | 512 | const auto sparse_inst{PrepareSparse(inst)}; |
| 513 | const bool is_multisample{ms.type != Type::Void}; | ||
| 513 | const std::string_view sparse_mod{sparse_inst ? ".SPARSE" : ""}; | 514 | const std::string_view sparse_mod{sparse_inst ? ".SPARSE" : ""}; |
| 514 | const std::string_view type{TextureType(info)}; | 515 | const std::string_view type{TextureType(info, is_multisample)}; |
| 515 | const std::string texture{Texture(ctx, info, index)}; | 516 | const std::string texture{Texture(ctx, info, index)}; |
| 516 | const std::string offset_vec{Offset(ctx, offset)}; | 517 | const std::string offset_vec{Offset(ctx, offset)}; |
| 517 | const auto [coord_vec, coord_alloc]{Coord(ctx, coord)}; | 518 | const auto [coord_vec, coord_alloc]{Coord(ctx, coord)}; |
| 518 | const Register ret{ctx.reg_alloc.Define(inst)}; | 519 | const Register ret{ctx.reg_alloc.Define(inst)}; |
| 519 | if (info.type == TextureType::Buffer) { | 520 | if (info.type == TextureType::Buffer) { |
| 520 | ctx.Add("TXF.F{} {},{},{},{}{};", sparse_mod, ret, coord_vec, texture, type, offset_vec); | 521 | ctx.Add("TXF.F{} {},{},{},{}{};", sparse_mod, ret, coord_vec, texture, type, offset_vec); |
| 521 | } else if (ms.type != Type::Void) { | 522 | } else if (is_multisample) { |
| 522 | ctx.Add("MOV.S {}.w,{};" | 523 | ctx.Add("MOV.S {}.w,{};" |
| 523 | "TXFMS.F{} {},{},{},{}{};", | 524 | "TXFMS.F{} {},{},{},{}{};", |
| 524 | coord_vec, ms, sparse_mod, ret, coord_vec, texture, type, offset_vec); | 525 | coord_vec, ms, sparse_mod, ret, coord_vec, texture, type, offset_vec); |
| @@ -531,7 +532,7 @@ void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | |||
| 531 | } | 532 | } |
| 532 | 533 | ||
| 533 | void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | 534 | void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, |
| 534 | ScalarS32 lod) { | 535 | ScalarS32 lod, [[maybe_unused]] const IR::Value& skip_mips) { |
| 535 | const auto info{inst.Flags<IR::TextureInstInfo>()}; | 536 | const auto info{inst.Flags<IR::TextureInstInfo>()}; |
| 536 | const std::string texture{Texture(ctx, info, index)}; | 537 | const std::string texture{Texture(ctx, info, index)}; |
| 537 | const std::string_view type{TextureType(info)}; | 538 | const std::string_view type{TextureType(info)}; |
diff --git a/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h b/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h index eaaf9ba39..1a1ea61d5 100644 --- a/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h +++ b/src/shader_recompiler/backend/glasm/emit_glasm_instructions.h | |||
| @@ -197,7 +197,6 @@ void EmitSelectF64(EmitContext& ctx, ScalarS32 cond, Register true_value, Regist | |||
| 197 | void EmitBitCastU16F16(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | 197 | void EmitBitCastU16F16(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); |
| 198 | void EmitBitCastU32F32(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | 198 | void EmitBitCastU32F32(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); |
| 199 | void EmitBitCastU64F64(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | 199 | void EmitBitCastU64F64(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); |
| 200 | void EmitBitCastS32F32(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | ||
| 201 | void EmitBitCastF16U16(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | 200 | void EmitBitCastF16U16(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); |
| 202 | void EmitBitCastF32U32(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | 201 | void EmitBitCastF32U32(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); |
| 203 | void EmitBitCastF64U64(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); | 202 | void EmitBitCastF64U64(EmitContext& ctx, IR::Inst& inst, const IR::Value& value); |
| @@ -582,7 +581,7 @@ void EmitImageGatherDref(EmitContext& ctx, IR::Inst& inst, const IR::Value& inde | |||
| 582 | void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | 581 | void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, |
| 583 | const IR::Value& coord, const IR::Value& offset, ScalarS32 lod, ScalarS32 ms); | 582 | const IR::Value& coord, const IR::Value& offset, ScalarS32 lod, ScalarS32 ms); |
| 584 | void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | 583 | void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, |
| 585 | ScalarS32 lod); | 584 | ScalarS32 lod, const IR::Value& skip_mips); |
| 586 | void EmitImageQueryLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord); | 585 | void EmitImageQueryLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, Register coord); |
| 587 | void EmitImageGradient(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | 586 | void EmitImageGradient(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, |
| 588 | const IR::Value& coord, const IR::Value& derivatives, | 587 | const IR::Value& coord, const IR::Value& derivatives, |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp index 8e5e6cf1f..1be4a0f59 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_bitwise_conversion.cpp | |||
| @@ -48,10 +48,6 @@ void EmitBitCastU64F64(EmitContext& ctx, IR::Inst& inst, std::string_view value) | |||
| 48 | ctx.AddU64("{}=doubleBitsToUint64({});", inst, value); | 48 | ctx.AddU64("{}=doubleBitsToUint64({});", inst, value); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | void EmitBitCastS32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value) { | ||
| 52 | ctx.AddF32("{}=ftoi({});", inst, value); | ||
| 53 | } | ||
| 54 | |||
| 55 | void EmitBitCastF16U16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst) { | 51 | void EmitBitCastF16U16([[maybe_unused]] EmitContext& ctx, [[maybe_unused]] IR::Inst& inst) { |
| 56 | NotImplemented(); | 52 | NotImplemented(); |
| 57 | } | 53 | } |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp index cecdbb9d6..4be2c25ec 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp +++ b/src/shader_recompiler/backend/glsl/emit_glsl_image.cpp | |||
| @@ -414,7 +414,7 @@ void EmitImageGatherDref(EmitContext& ctx, IR::Inst& inst, const IR::Value& inde | |||
| 414 | 414 | ||
| 415 | void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | 415 | void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, |
| 416 | std::string_view coords, std::string_view offset, std::string_view lod, | 416 | std::string_view coords, std::string_view offset, std::string_view lod, |
| 417 | [[maybe_unused]] std::string_view ms) { | 417 | std::string_view ms) { |
| 418 | const auto info{inst.Flags<IR::TextureInstInfo>()}; | 418 | const auto info{inst.Flags<IR::TextureInstInfo>()}; |
| 419 | if (info.has_bias) { | 419 | if (info.has_bias) { |
| 420 | throw NotImplementedException("EmitImageFetch Bias texture samples"); | 420 | throw NotImplementedException("EmitImageFetch Bias texture samples"); |
| @@ -431,19 +431,24 @@ void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | |||
| 431 | ctx.AddU1("{}=true;", *sparse_inst); | 431 | ctx.AddU1("{}=true;", *sparse_inst); |
| 432 | } | 432 | } |
| 433 | if (!sparse_inst || !supports_sparse) { | 433 | if (!sparse_inst || !supports_sparse) { |
| 434 | if (!offset.empty()) { | 434 | const auto int_coords{CoordsCastToInt(coords, info)}; |
| 435 | ctx.Add("{}=texelFetchOffset({},{},int({}),{});", texel, texture, | 435 | if (!ms.empty()) { |
| 436 | CoordsCastToInt(coords, info), lod, CoordsCastToInt(offset, info)); | 436 | ctx.Add("{}=texelFetch({},{},int({}));", texel, texture, int_coords, ms); |
| 437 | } else if (!offset.empty()) { | ||
| 438 | ctx.Add("{}=texelFetchOffset({},{},int({}),{});", texel, texture, int_coords, lod, | ||
| 439 | CoordsCastToInt(offset, info)); | ||
| 437 | } else { | 440 | } else { |
| 438 | if (info.type == TextureType::Buffer) { | 441 | if (info.type == TextureType::Buffer) { |
| 439 | ctx.Add("{}=texelFetch({},int({}));", texel, texture, coords); | 442 | ctx.Add("{}=texelFetch({},int({}));", texel, texture, coords); |
| 440 | } else { | 443 | } else { |
| 441 | ctx.Add("{}=texelFetch({},{},int({}));", texel, texture, | 444 | ctx.Add("{}=texelFetch({},{},int({}));", texel, texture, int_coords, lod); |
| 442 | CoordsCastToInt(coords, info), lod); | ||
| 443 | } | 445 | } |
| 444 | } | 446 | } |
| 445 | return; | 447 | return; |
| 446 | } | 448 | } |
| 449 | if (!ms.empty()) { | ||
| 450 | throw NotImplementedException("EmitImageFetch Sparse MSAA samples"); | ||
| 451 | } | ||
| 447 | if (!offset.empty()) { | 452 | if (!offset.empty()) { |
| 448 | ctx.AddU1("{}=sparseTexelsResidentARB(sparseTexelFetchOffsetARB({},{},int({}),{},{}));", | 453 | ctx.AddU1("{}=sparseTexelsResidentARB(sparseTexelFetchOffsetARB({},{},int({}),{},{}));", |
| 449 | *sparse_inst, texture, CastToIntVec(coords, info), lod, | 454 | *sparse_inst, texture, CastToIntVec(coords, info), lod, |
| @@ -455,27 +460,27 @@ void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | |||
| 455 | } | 460 | } |
| 456 | 461 | ||
| 457 | void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | 462 | void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, |
| 458 | std::string_view lod) { | 463 | std::string_view lod, const IR::Value& skip_mips_val) { |
| 459 | const auto info{inst.Flags<IR::TextureInstInfo>()}; | 464 | const auto info{inst.Flags<IR::TextureInstInfo>()}; |
| 460 | const auto texture{Texture(ctx, info, index)}; | 465 | const auto texture{Texture(ctx, info, index)}; |
| 466 | const bool skip_mips{skip_mips_val.U1()}; | ||
| 467 | const auto mips{ | ||
| 468 | [&] { return skip_mips ? "0u" : fmt::format("uint(textureQueryLevels({}))", texture); }}; | ||
| 461 | switch (info.type) { | 469 | switch (info.type) { |
| 462 | case TextureType::Color1D: | 470 | case TextureType::Color1D: |
| 463 | return ctx.AddU32x4( | 471 | return ctx.AddU32x4("{}=uvec4(uint(textureSize({},int({}))),0u,0u,{});", inst, texture, lod, |
| 464 | "{}=uvec4(uint(textureSize({},int({}))),0u,0u,uint(textureQueryLevels({})));", inst, | 472 | mips()); |
| 465 | texture, lod, texture); | ||
| 466 | case TextureType::ColorArray1D: | 473 | case TextureType::ColorArray1D: |
| 467 | case TextureType::Color2D: | 474 | case TextureType::Color2D: |
| 468 | case TextureType::ColorCube: | 475 | case TextureType::ColorCube: |
| 469 | case TextureType::Color2DRect: | 476 | case TextureType::Color2DRect: |
| 470 | return ctx.AddU32x4( | 477 | return ctx.AddU32x4("{}=uvec4(uvec2(textureSize({},int({}))),0u,{});", inst, texture, lod, |
| 471 | "{}=uvec4(uvec2(textureSize({},int({}))),0u,uint(textureQueryLevels({})));", inst, | 478 | mips()); |
| 472 | texture, lod, texture); | ||
| 473 | case TextureType::ColorArray2D: | 479 | case TextureType::ColorArray2D: |
| 474 | case TextureType::Color3D: | 480 | case TextureType::Color3D: |
| 475 | case TextureType::ColorArrayCube: | 481 | case TextureType::ColorArrayCube: |
| 476 | return ctx.AddU32x4( | 482 | return ctx.AddU32x4("{}=uvec4(uvec3(textureSize({},int({}))),{});", inst, texture, lod, |
| 477 | "{}=uvec4(uvec3(textureSize({},int({}))),uint(textureQueryLevels({})));", inst, texture, | 483 | mips()); |
| 478 | lod, texture); | ||
| 479 | case TextureType::Buffer: | 484 | case TextureType::Buffer: |
| 480 | throw NotImplementedException("EmitImageQueryDimensions Texture buffers"); | 485 | throw NotImplementedException("EmitImageQueryDimensions Texture buffers"); |
| 481 | } | 486 | } |
diff --git a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h index 4151c89de..8d0a65047 100644 --- a/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h +++ b/src/shader_recompiler/backend/glsl/emit_glsl_instructions.h | |||
| @@ -231,7 +231,6 @@ void EmitSelectF64(EmitContext& ctx, IR::Inst& inst, std::string_view cond, | |||
| 231 | void EmitBitCastU16F16(EmitContext& ctx, IR::Inst& inst); | 231 | void EmitBitCastU16F16(EmitContext& ctx, IR::Inst& inst); |
| 232 | void EmitBitCastU32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value); | 232 | void EmitBitCastU32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value); |
| 233 | void EmitBitCastU64F64(EmitContext& ctx, IR::Inst& inst, std::string_view value); | 233 | void EmitBitCastU64F64(EmitContext& ctx, IR::Inst& inst, std::string_view value); |
| 234 | void EmitBitCastS32F32(EmitContext& ctx, IR::Inst& inst, std::string_view value); | ||
| 235 | void EmitBitCastF16U16(EmitContext& ctx, IR::Inst& inst); | 234 | void EmitBitCastF16U16(EmitContext& ctx, IR::Inst& inst); |
| 236 | void EmitBitCastF32U32(EmitContext& ctx, IR::Inst& inst, std::string_view value); | 235 | void EmitBitCastF32U32(EmitContext& ctx, IR::Inst& inst, std::string_view value); |
| 237 | void EmitBitCastF64U64(EmitContext& ctx, IR::Inst& inst, std::string_view value); | 236 | void EmitBitCastF64U64(EmitContext& ctx, IR::Inst& inst, std::string_view value); |
| @@ -655,7 +654,7 @@ void EmitImageFetch(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | |||
| 655 | std::string_view coords, std::string_view offset, std::string_view lod, | 654 | std::string_view coords, std::string_view offset, std::string_view lod, |
| 656 | std::string_view ms); | 655 | std::string_view ms); |
| 657 | void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | 656 | void EmitImageQueryDimensions(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, |
| 658 | std::string_view lod); | 657 | std::string_view lod, const IR::Value& skip_mips); |
| 659 | void EmitImageQueryLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | 658 | void EmitImageQueryLod(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, |
| 660 | std::string_view coords); | 659 | std::string_view coords); |
| 661 | void EmitImageGradient(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, | 660 | void EmitImageGradient(EmitContext& ctx, IR::Inst& inst, const IR::Value& index, |
diff --git a/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp b/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp index 5d01ec0cd..1b006e811 100644 --- a/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp +++ b/src/shader_recompiler/backend/glsl/glsl_emit_context.cpp | |||
| @@ -61,24 +61,28 @@ std::string OutputDecorator(Stage stage, u32 size) { | |||
| 61 | } | 61 | } |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | std::string_view SamplerType(TextureType type, bool is_depth) { | 64 | std::string_view DepthSamplerType(TextureType type) { |
| 65 | if (is_depth) { | 65 | switch (type) { |
| 66 | switch (type) { | 66 | case TextureType::Color1D: |
| 67 | case TextureType::Color1D: | 67 | return "sampler1DShadow"; |
| 68 | return "sampler1DShadow"; | 68 | case TextureType::ColorArray1D: |
| 69 | case TextureType::ColorArray1D: | 69 | return "sampler1DArrayShadow"; |
| 70 | return "sampler1DArrayShadow"; | 70 | case TextureType::Color2D: |
| 71 | case TextureType::Color2D: | 71 | return "sampler2DShadow"; |
| 72 | return "sampler2DShadow"; | 72 | case TextureType::ColorArray2D: |
| 73 | case TextureType::ColorArray2D: | 73 | return "sampler2DArrayShadow"; |
| 74 | return "sampler2DArrayShadow"; | 74 | case TextureType::ColorCube: |
| 75 | case TextureType::ColorCube: | 75 | return "samplerCubeShadow"; |
| 76 | return "samplerCubeShadow"; | 76 | case TextureType::ColorArrayCube: |
| 77 | case TextureType::ColorArrayCube: | 77 | return "samplerCubeArrayShadow"; |
| 78 | return "samplerCubeArrayShadow"; | 78 | default: |
| 79 | default: | 79 | throw NotImplementedException("Texture type: {}", type); |
| 80 | throw NotImplementedException("Texture type: {}", type); | 80 | } |
| 81 | } | 81 | } |
| 82 | |||
| 83 | std::string_view ColorSamplerType(TextureType type, bool is_multisample = false) { | ||
| 84 | if (is_multisample) { | ||
| 85 | ASSERT(type == TextureType::Color2D || type == TextureType::ColorArray2D); | ||
| 82 | } | 86 | } |
| 83 | switch (type) { | 87 | switch (type) { |
| 84 | case TextureType::Color1D: | 88 | case TextureType::Color1D: |
| @@ -87,9 +91,9 @@ std::string_view SamplerType(TextureType type, bool is_depth) { | |||
| 87 | return "sampler1DArray"; | 91 | return "sampler1DArray"; |
| 88 | case TextureType::Color2D: | 92 | case TextureType::Color2D: |
| 89 | case TextureType::Color2DRect: | 93 | case TextureType::Color2DRect: |
| 90 | return "sampler2D"; | 94 | return is_multisample ? "sampler2DMS" : "sampler2D"; |
| 91 | case TextureType::ColorArray2D: | 95 | case TextureType::ColorArray2D: |
| 92 | return "sampler2DArray"; | 96 | return is_multisample ? "sampler2DMSArray" : "sampler2DArray"; |
| 93 | case TextureType::Color3D: | 97 | case TextureType::Color3D: |
| 94 | return "sampler3D"; | 98 | return "sampler3D"; |
| 95 | case TextureType::ColorCube: | 99 | case TextureType::ColorCube: |
| @@ -677,7 +681,7 @@ void EmitContext::SetupTextures(Bindings& bindings) { | |||
| 677 | texture_buffers.reserve(info.texture_buffer_descriptors.size()); | 681 | texture_buffers.reserve(info.texture_buffer_descriptors.size()); |
| 678 | for (const auto& desc : info.texture_buffer_descriptors) { | 682 | for (const auto& desc : info.texture_buffer_descriptors) { |
| 679 | texture_buffers.push_back({bindings.texture, desc.count}); | 683 | texture_buffers.push_back({bindings.texture, desc.count}); |
| 680 | const auto sampler_type{SamplerType(TextureType::Buffer, false)}; | 684 | const auto sampler_type{ColorSamplerType(TextureType::Buffer)}; |
| 681 | const auto array_decorator{desc.count > 1 ? fmt::format("[{}]", desc.count) : ""}; | 685 | const auto array_decorator{desc.count > 1 ? fmt::format("[{}]", desc.count) : ""}; |
| 682 | header += fmt::format("layout(binding={}) uniform {} tex{}{};", bindings.texture, | 686 | header += fmt::format("layout(binding={}) uniform {} tex{}{};", bindings.texture, |
| 683 | sampler_type, bindings.texture, array_decorator); | 687 | sampler_type, bindings.texture, array_decorator); |
| @@ -686,7 +690,8 @@ void EmitContext::SetupTextures(Bindings& bindings) { | |||
| 686 | textures.reserve(info.texture_descriptors.size()); | 690 | textures.reserve(info.texture_descriptors.size()); |
| 687 | for (const auto& desc : info.texture_descriptors) { | 691 | for (const auto& desc : info.texture_descriptors) { |
| 688 | textures.push_back({bindings.texture, desc.count}); | 692 | textures.push_back({bindings.texture, desc.count}); |
| 689 | const auto sampler_type{SamplerType(desc.type, desc.is_depth)}; | 693 | const auto sampler_type{desc.is_depth ? DepthSamplerType(desc.type) |
| 694 | : ColorSamplerType(desc.type, desc.is_multisample)}; | ||
| 690 | const auto array_decorator{desc.count > 1 ? fmt::format("[{}]", desc.count) : ""}; | 695 | const auto array_decorator{desc.count > 1 ? fmt::format("[{}]", desc.count) : ""}; |
| 691 | header += fmt::format("layout(binding={}) uniform {} tex{}{};", bindings.texture, | 696 | header += fmt::format("layout(binding={}) uniform {} tex{}{};", bindings.texture, |
| 692 | sampler_type, bindings.texture, array_decorator); | 697 | sampler_type, bindings.texture, array_decorator); |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_bitwise_conversion.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_bitwise_conversion.cpp index 50daacd95..c4ca28d11 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_bitwise_conversion.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_bitwise_conversion.cpp | |||
| @@ -18,10 +18,6 @@ void EmitBitCastU64F64(EmitContext&) { | |||
| 18 | throw NotImplementedException("SPIR-V Instruction"); | 18 | throw NotImplementedException("SPIR-V Instruction"); |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | void EmitBitCastS32F32(EmitContext&) { | ||
| 22 | throw NotImplementedException("SPIR-V Instruction"); | ||
| 23 | } | ||
| 24 | |||
| 25 | void EmitBitCastF16U16(EmitContext&) { | 21 | void EmitBitCastF16U16(EmitContext&) { |
| 26 | throw NotImplementedException("SPIR-V Instruction"); | 22 | throw NotImplementedException("SPIR-V Instruction"); |
| 27 | } | 23 | } |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp b/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp index c898ce12f..3b969d915 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp +++ b/src/shader_recompiler/backend/spirv/emit_spirv_image.cpp | |||
| @@ -445,11 +445,13 @@ Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id c | |||
| 445 | TextureImage(ctx, info, index), coords, operands.MaskOptional(), operands.Span()); | 445 | TextureImage(ctx, info, index), coords, operands.MaskOptional(), operands.Span()); |
| 446 | } | 446 | } |
| 447 | 447 | ||
| 448 | Id EmitImageQueryDimensions(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id lod) { | 448 | Id EmitImageQueryDimensions(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id lod, |
| 449 | const IR::Value& skip_mips_val) { | ||
| 449 | const auto info{inst->Flags<IR::TextureInstInfo>()}; | 450 | const auto info{inst->Flags<IR::TextureInstInfo>()}; |
| 450 | const Id image{TextureImage(ctx, info, index)}; | 451 | const Id image{TextureImage(ctx, info, index)}; |
| 451 | const Id zero{ctx.u32_zero_value}; | 452 | const Id zero{ctx.u32_zero_value}; |
| 452 | const auto mips{[&] { return ctx.OpImageQueryLevels(ctx.U32[1], image); }}; | 453 | const bool skip_mips{skip_mips_val.U1()}; |
| 454 | const auto mips{[&] { return skip_mips ? zero : ctx.OpImageQueryLevels(ctx.U32[1], image); }}; | ||
| 453 | switch (info.type) { | 455 | switch (info.type) { |
| 454 | case TextureType::Color1D: | 456 | case TextureType::Color1D: |
| 455 | return ctx.OpCompositeConstruct(ctx.U32[4], ctx.OpImageQuerySizeLod(ctx.U32[1], image, lod), | 457 | return ctx.OpCompositeConstruct(ctx.U32[4], ctx.OpImageQuerySizeLod(ctx.U32[1], image, lod), |
diff --git a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h index e31cdc5e8..a440b557d 100644 --- a/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h +++ b/src/shader_recompiler/backend/spirv/emit_spirv_instructions.h | |||
| @@ -179,7 +179,6 @@ Id EmitSelectF64(EmitContext& ctx, Id cond, Id true_value, Id false_value); | |||
| 179 | void EmitBitCastU16F16(EmitContext& ctx); | 179 | void EmitBitCastU16F16(EmitContext& ctx); |
| 180 | Id EmitBitCastU32F32(EmitContext& ctx, Id value); | 180 | Id EmitBitCastU32F32(EmitContext& ctx, Id value); |
| 181 | void EmitBitCastU64F64(EmitContext& ctx); | 181 | void EmitBitCastU64F64(EmitContext& ctx); |
| 182 | void EmitBitCastS32F32(EmitContext& ctx); | ||
| 183 | void EmitBitCastF16U16(EmitContext&); | 182 | void EmitBitCastF16U16(EmitContext&); |
| 184 | Id EmitBitCastF32U32(EmitContext& ctx, Id value); | 183 | Id EmitBitCastF32U32(EmitContext& ctx, Id value); |
| 185 | void EmitBitCastF64U64(EmitContext& ctx); | 184 | void EmitBitCastF64U64(EmitContext& ctx); |
| @@ -540,7 +539,8 @@ Id EmitImageGatherDref(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, | |||
| 540 | const IR::Value& offset, const IR::Value& offset2, Id dref); | 539 | const IR::Value& offset, const IR::Value& offset2, Id dref); |
| 541 | Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id offset, | 540 | Id EmitImageFetch(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, Id offset, |
| 542 | Id lod, Id ms); | 541 | Id lod, Id ms); |
| 543 | Id EmitImageQueryDimensions(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id lod); | 542 | Id EmitImageQueryDimensions(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id lod, |
| 543 | const IR::Value& skip_mips); | ||
| 544 | Id EmitImageQueryLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords); | 544 | Id EmitImageQueryLod(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords); |
| 545 | Id EmitImageGradient(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, | 545 | Id EmitImageGradient(EmitContext& ctx, IR::Inst* inst, const IR::Value& index, Id coords, |
| 546 | Id derivates, Id offset, Id lod_clamp); | 546 | Id derivates, Id offset, Id lod_clamp); |
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.cpp b/src/shader_recompiler/frontend/ir/ir_emitter.cpp index eb2e49a68..b7caa4246 100644 --- a/src/shader_recompiler/frontend/ir/ir_emitter.cpp +++ b/src/shader_recompiler/frontend/ir/ir_emitter.cpp | |||
| @@ -704,11 +704,6 @@ IR::U32 IREmitter::BitCast<IR::U32, IR::F32>(const IR::F32& value) { | |||
| 704 | } | 704 | } |
| 705 | 705 | ||
| 706 | template <> | 706 | template <> |
| 707 | IR::S32 IREmitter::BitCast<IR::S32, IR::F32>(const IR::F32& value) { | ||
| 708 | return Inst<IR::S32>(Opcode::BitCastS32F32, value); | ||
| 709 | } | ||
| 710 | |||
| 711 | template <> | ||
| 712 | IR::F32 IREmitter::BitCast<IR::F32, IR::U32>(const IR::U32& value) { | 707 | IR::F32 IREmitter::BitCast<IR::F32, IR::U32>(const IR::U32& value) { |
| 713 | return Inst<IR::F32>(Opcode::BitCastF32U32, value); | 708 | return Inst<IR::F32>(Opcode::BitCastF32U32, value); |
| 714 | } | 709 | } |
| @@ -1851,15 +1846,16 @@ Value IREmitter::ImageFetch(const Value& handle, const Value& coords, const Valu | |||
| 1851 | return Inst(op, Flags{info}, handle, coords, offset, lod, multisampling); | 1846 | return Inst(op, Flags{info}, handle, coords, offset, lod, multisampling); |
| 1852 | } | 1847 | } |
| 1853 | 1848 | ||
| 1854 | Value IREmitter::ImageQueryDimension(const Value& handle, const IR::U32& lod) { | 1849 | Value IREmitter::ImageQueryDimension(const Value& handle, const IR::U32& lod, |
| 1850 | const IR::U1& skip_mips) { | ||
| 1855 | const Opcode op{handle.IsImmediate() ? Opcode::BoundImageQueryDimensions | 1851 | const Opcode op{handle.IsImmediate() ? Opcode::BoundImageQueryDimensions |
| 1856 | : Opcode::BindlessImageQueryDimensions}; | 1852 | : Opcode::BindlessImageQueryDimensions}; |
| 1857 | return Inst(op, handle, lod); | 1853 | return Inst(op, handle, lod, skip_mips); |
| 1858 | } | 1854 | } |
| 1859 | 1855 | ||
| 1860 | Value IREmitter::ImageQueryDimension(const Value& handle, const IR::U32& lod, | 1856 | Value IREmitter::ImageQueryDimension(const Value& handle, const IR::U32& lod, |
| 1861 | TextureInstInfo info) { | 1857 | const IR::U1& skip_mips, TextureInstInfo info) { |
| 1862 | return Inst(Opcode::ImageQueryDimensions, Flags{info}, handle, lod); | 1858 | return Inst(Opcode::ImageQueryDimensions, Flags{info}, handle, lod, skip_mips); |
| 1863 | } | 1859 | } |
| 1864 | 1860 | ||
| 1865 | Value IREmitter::ImageQueryLod(const Value& handle, const Value& coords, TextureInstInfo info) { | 1861 | Value IREmitter::ImageQueryLod(const Value& handle, const Value& coords, TextureInstInfo info) { |
diff --git a/src/shader_recompiler/frontend/ir/ir_emitter.h b/src/shader_recompiler/frontend/ir/ir_emitter.h index 7aaaa4ab0..f3c81dbe1 100644 --- a/src/shader_recompiler/frontend/ir/ir_emitter.h +++ b/src/shader_recompiler/frontend/ir/ir_emitter.h | |||
| @@ -320,9 +320,10 @@ public: | |||
| 320 | [[nodiscard]] F32 ImageSampleDrefExplicitLod(const Value& handle, const Value& coords, | 320 | [[nodiscard]] F32 ImageSampleDrefExplicitLod(const Value& handle, const Value& coords, |
| 321 | const F32& dref, const F32& lod, | 321 | const F32& dref, const F32& lod, |
| 322 | const Value& offset, TextureInstInfo info); | 322 | const Value& offset, TextureInstInfo info); |
| 323 | [[nodiscard]] Value ImageQueryDimension(const Value& handle, const IR::U32& lod); | ||
| 324 | [[nodiscard]] Value ImageQueryDimension(const Value& handle, const IR::U32& lod, | 323 | [[nodiscard]] Value ImageQueryDimension(const Value& handle, const IR::U32& lod, |
| 325 | TextureInstInfo info); | 324 | const IR::U1& skip_mips); |
| 325 | [[nodiscard]] Value ImageQueryDimension(const Value& handle, const IR::U32& lod, | ||
| 326 | const IR::U1& skip_mips, TextureInstInfo info); | ||
| 326 | 327 | ||
| 327 | [[nodiscard]] Value ImageQueryLod(const Value& handle, const Value& coords, | 328 | [[nodiscard]] Value ImageQueryLod(const Value& handle, const Value& coords, |
| 328 | TextureInstInfo info); | 329 | TextureInstInfo info); |
| @@ -408,7 +409,8 @@ private: | |||
| 408 | } | 409 | } |
| 409 | 410 | ||
| 410 | template <typename T> | 411 | template <typename T> |
| 411 | requires(sizeof(T) <= sizeof(u32) && std::is_trivially_copyable_v<T>) struct Flags { | 412 | requires(sizeof(T) <= sizeof(u32) && std::is_trivially_copyable_v<T>) |
| 413 | struct Flags { | ||
| 412 | Flags() = default; | 414 | Flags() = default; |
| 413 | Flags(T proxy_) : proxy{proxy_} {} | 415 | Flags(T proxy_) : proxy{proxy_} {} |
| 414 | 416 | ||
diff --git a/src/shader_recompiler/frontend/ir/opcodes.h b/src/shader_recompiler/frontend/ir/opcodes.h index d155afd0f..e300714f3 100644 --- a/src/shader_recompiler/frontend/ir/opcodes.h +++ b/src/shader_recompiler/frontend/ir/opcodes.h | |||
| @@ -38,7 +38,6 @@ constexpr Type U8{Type::U8}; | |||
| 38 | constexpr Type U16{Type::U16}; | 38 | constexpr Type U16{Type::U16}; |
| 39 | constexpr Type U32{Type::U32}; | 39 | constexpr Type U32{Type::U32}; |
| 40 | constexpr Type U64{Type::U64}; | 40 | constexpr Type U64{Type::U64}; |
| 41 | constexpr Type S32{Type::S32}; | ||
| 42 | constexpr Type F16{Type::F16}; | 41 | constexpr Type F16{Type::F16}; |
| 43 | constexpr Type F32{Type::F32}; | 42 | constexpr Type F32{Type::F32}; |
| 44 | constexpr Type F64{Type::F64}; | 43 | constexpr Type F64{Type::F64}; |
diff --git a/src/shader_recompiler/frontend/ir/opcodes.inc b/src/shader_recompiler/frontend/ir/opcodes.inc index 1fe3749cc..4447d67b0 100644 --- a/src/shader_recompiler/frontend/ir/opcodes.inc +++ b/src/shader_recompiler/frontend/ir/opcodes.inc | |||
| @@ -175,7 +175,6 @@ OPCODE(SelectF64, F64, U1, | |||
| 175 | OPCODE(BitCastU16F16, U16, F16, ) | 175 | OPCODE(BitCastU16F16, U16, F16, ) |
| 176 | OPCODE(BitCastU32F32, U32, F32, ) | 176 | OPCODE(BitCastU32F32, U32, F32, ) |
| 177 | OPCODE(BitCastU64F64, U64, F64, ) | 177 | OPCODE(BitCastU64F64, U64, F64, ) |
| 178 | OPCODE(BitCastS32F32, S32, F32, ) | ||
| 179 | OPCODE(BitCastF16U16, F16, U16, ) | 178 | OPCODE(BitCastF16U16, F16, U16, ) |
| 180 | OPCODE(BitCastF32U32, F32, U32, ) | 179 | OPCODE(BitCastF32U32, F32, U32, ) |
| 181 | OPCODE(BitCastF64U64, F64, U64, ) | 180 | OPCODE(BitCastF64U64, F64, U64, ) |
| @@ -483,7 +482,7 @@ OPCODE(BindlessImageSampleDrefExplicitLod, F32, U32, | |||
| 483 | OPCODE(BindlessImageGather, F32x4, U32, Opaque, Opaque, Opaque, ) | 482 | OPCODE(BindlessImageGather, F32x4, U32, Opaque, Opaque, Opaque, ) |
| 484 | OPCODE(BindlessImageGatherDref, F32x4, U32, Opaque, Opaque, Opaque, F32, ) | 483 | OPCODE(BindlessImageGatherDref, F32x4, U32, Opaque, Opaque, Opaque, F32, ) |
| 485 | OPCODE(BindlessImageFetch, F32x4, U32, Opaque, Opaque, U32, Opaque, ) | 484 | OPCODE(BindlessImageFetch, F32x4, U32, Opaque, Opaque, U32, Opaque, ) |
| 486 | OPCODE(BindlessImageQueryDimensions, U32x4, U32, U32, ) | 485 | OPCODE(BindlessImageQueryDimensions, U32x4, U32, U32, U1, ) |
| 487 | OPCODE(BindlessImageQueryLod, F32x4, U32, Opaque, ) | 486 | OPCODE(BindlessImageQueryLod, F32x4, U32, Opaque, ) |
| 488 | OPCODE(BindlessImageGradient, F32x4, U32, Opaque, Opaque, Opaque, Opaque, ) | 487 | OPCODE(BindlessImageGradient, F32x4, U32, Opaque, Opaque, Opaque, Opaque, ) |
| 489 | OPCODE(BindlessImageRead, U32x4, U32, Opaque, ) | 488 | OPCODE(BindlessImageRead, U32x4, U32, Opaque, ) |
| @@ -496,7 +495,7 @@ OPCODE(BoundImageSampleDrefExplicitLod, F32, U32, | |||
| 496 | OPCODE(BoundImageGather, F32x4, U32, Opaque, Opaque, Opaque, ) | 495 | OPCODE(BoundImageGather, F32x4, U32, Opaque, Opaque, Opaque, ) |
| 497 | OPCODE(BoundImageGatherDref, F32x4, U32, Opaque, Opaque, Opaque, F32, ) | 496 | OPCODE(BoundImageGatherDref, F32x4, U32, Opaque, Opaque, Opaque, F32, ) |
| 498 | OPCODE(BoundImageFetch, F32x4, U32, Opaque, Opaque, U32, Opaque, ) | 497 | OPCODE(BoundImageFetch, F32x4, U32, Opaque, Opaque, U32, Opaque, ) |
| 499 | OPCODE(BoundImageQueryDimensions, U32x4, U32, U32, ) | 498 | OPCODE(BoundImageQueryDimensions, U32x4, U32, U32, U1, ) |
| 500 | OPCODE(BoundImageQueryLod, F32x4, U32, Opaque, ) | 499 | OPCODE(BoundImageQueryLod, F32x4, U32, Opaque, ) |
| 501 | OPCODE(BoundImageGradient, F32x4, U32, Opaque, Opaque, Opaque, Opaque, ) | 500 | OPCODE(BoundImageGradient, F32x4, U32, Opaque, Opaque, Opaque, Opaque, ) |
| 502 | OPCODE(BoundImageRead, U32x4, U32, Opaque, ) | 501 | OPCODE(BoundImageRead, U32x4, U32, Opaque, ) |
| @@ -509,7 +508,7 @@ OPCODE(ImageSampleDrefExplicitLod, F32, Opaq | |||
| 509 | OPCODE(ImageGather, F32x4, Opaque, Opaque, Opaque, Opaque, ) | 508 | OPCODE(ImageGather, F32x4, Opaque, Opaque, Opaque, Opaque, ) |
| 510 | OPCODE(ImageGatherDref, F32x4, Opaque, Opaque, Opaque, Opaque, F32, ) | 509 | OPCODE(ImageGatherDref, F32x4, Opaque, Opaque, Opaque, Opaque, F32, ) |
| 511 | OPCODE(ImageFetch, F32x4, Opaque, Opaque, Opaque, U32, Opaque, ) | 510 | OPCODE(ImageFetch, F32x4, Opaque, Opaque, Opaque, U32, Opaque, ) |
| 512 | OPCODE(ImageQueryDimensions, U32x4, Opaque, U32, ) | 511 | OPCODE(ImageQueryDimensions, U32x4, Opaque, U32, U1, ) |
| 513 | OPCODE(ImageQueryLod, F32x4, Opaque, Opaque, ) | 512 | OPCODE(ImageQueryLod, F32x4, Opaque, Opaque, ) |
| 514 | OPCODE(ImageGradient, F32x4, Opaque, Opaque, Opaque, Opaque, Opaque, ) | 513 | OPCODE(ImageGradient, F32x4, Opaque, Opaque, Opaque, Opaque, Opaque, ) |
| 515 | OPCODE(ImageRead, U32x4, Opaque, Opaque, ) | 514 | OPCODE(ImageRead, U32x4, Opaque, Opaque, ) |
diff --git a/src/shader_recompiler/frontend/ir/type.h b/src/shader_recompiler/frontend/ir/type.h index 5a7c706ad..04c8c4ddb 100644 --- a/src/shader_recompiler/frontend/ir/type.h +++ b/src/shader_recompiler/frontend/ir/type.h | |||
| @@ -24,22 +24,21 @@ enum class Type { | |||
| 24 | U16 = 1 << 7, | 24 | U16 = 1 << 7, |
| 25 | U32 = 1 << 8, | 25 | U32 = 1 << 8, |
| 26 | U64 = 1 << 9, | 26 | U64 = 1 << 9, |
| 27 | S32 = 1 << 10, | 27 | F16 = 1 << 10, |
| 28 | F16 = 1 << 11, | 28 | F32 = 1 << 11, |
| 29 | F32 = 1 << 12, | 29 | F64 = 1 << 12, |
| 30 | F64 = 1 << 13, | 30 | U32x2 = 1 << 13, |
| 31 | U32x2 = 1 << 14, | 31 | U32x3 = 1 << 14, |
| 32 | U32x3 = 1 << 15, | 32 | U32x4 = 1 << 15, |
| 33 | U32x4 = 1 << 16, | 33 | F16x2 = 1 << 16, |
| 34 | F16x2 = 1 << 17, | 34 | F16x3 = 1 << 17, |
| 35 | F16x3 = 1 << 18, | 35 | F16x4 = 1 << 18, |
| 36 | F16x4 = 1 << 19, | 36 | F32x2 = 1 << 19, |
| 37 | F32x2 = 1 << 20, | 37 | F32x3 = 1 << 20, |
| 38 | F32x3 = 1 << 21, | 38 | F32x4 = 1 << 21, |
| 39 | F32x4 = 1 << 22, | 39 | F64x2 = 1 << 22, |
| 40 | F64x2 = 1 << 23, | 40 | F64x3 = 1 << 23, |
| 41 | F64x3 = 1 << 24, | 41 | F64x4 = 1 << 24, |
| 42 | F64x4 = 1 << 25, | ||
| 43 | }; | 42 | }; |
| 44 | DECLARE_ENUM_FLAG_OPERATORS(Type) | 43 | DECLARE_ENUM_FLAG_OPERATORS(Type) |
| 45 | 44 | ||
diff --git a/src/shader_recompiler/frontend/ir/value.cpp b/src/shader_recompiler/frontend/ir/value.cpp index 30ba12316..346169328 100644 --- a/src/shader_recompiler/frontend/ir/value.cpp +++ b/src/shader_recompiler/frontend/ir/value.cpp | |||
| @@ -23,8 +23,6 @@ Value::Value(u16 value) noexcept : type{Type::U16}, imm_u16{value} {} | |||
| 23 | 23 | ||
| 24 | Value::Value(u32 value) noexcept : type{Type::U32}, imm_u32{value} {} | 24 | Value::Value(u32 value) noexcept : type{Type::U32}, imm_u32{value} {} |
| 25 | 25 | ||
| 26 | Value::Value(s32 value) noexcept : type{Type::S32}, imm_s32{value} {} | ||
| 27 | |||
| 28 | Value::Value(f32 value) noexcept : type{Type::F32}, imm_f32{value} {} | 26 | Value::Value(f32 value) noexcept : type{Type::F32}, imm_f32{value} {} |
| 29 | 27 | ||
| 30 | Value::Value(u64 value) noexcept : type{Type::U64}, imm_u64{value} {} | 28 | Value::Value(u64 value) noexcept : type{Type::U64}, imm_u64{value} {} |
| @@ -71,7 +69,6 @@ bool Value::operator==(const Value& other) const { | |||
| 71 | return imm_u16 == other.imm_u16; | 69 | return imm_u16 == other.imm_u16; |
| 72 | case Type::U32: | 70 | case Type::U32: |
| 73 | case Type::F32: | 71 | case Type::F32: |
| 74 | case Type::S32: | ||
| 75 | return imm_u32 == other.imm_u32; | 72 | return imm_u32 == other.imm_u32; |
| 76 | case Type::U64: | 73 | case Type::U64: |
| 77 | case Type::F64: | 74 | case Type::F64: |
diff --git a/src/shader_recompiler/frontend/ir/value.h b/src/shader_recompiler/frontend/ir/value.h index 8b34356fd..22e89dd1b 100644 --- a/src/shader_recompiler/frontend/ir/value.h +++ b/src/shader_recompiler/frontend/ir/value.h | |||
| @@ -101,9 +101,8 @@ public: | |||
| 101 | TypedValue() = default; | 101 | TypedValue() = default; |
| 102 | 102 | ||
| 103 | template <IR::Type other_type> | 103 | template <IR::Type other_type> |
| 104 | requires((other_type & type_) != IR::Type::Void) explicit(false) | 104 | requires((other_type & type_) != IR::Type::Void) |
| 105 | TypedValue(const TypedValue<other_type>& value) | 105 | explicit(false) TypedValue(const TypedValue<other_type>& value) : Value(value) {} |
| 106 | : Value(value) {} | ||
| 107 | 106 | ||
| 108 | explicit TypedValue(const Value& value) : Value(value) { | 107 | explicit TypedValue(const Value& value) : Value(value) { |
| 109 | if ((value.Type() & type_) == IR::Type::Void) { | 108 | if ((value.Type() & type_) == IR::Type::Void) { |
| @@ -194,16 +193,16 @@ public: | |||
| 194 | void ReplaceOpcode(IR::Opcode opcode); | 193 | void ReplaceOpcode(IR::Opcode opcode); |
| 195 | 194 | ||
| 196 | template <typename FlagsType> | 195 | template <typename FlagsType> |
| 197 | requires(sizeof(FlagsType) <= sizeof(u32) && std::is_trivially_copyable_v<FlagsType>) | 196 | requires(sizeof(FlagsType) <= sizeof(u32) && std::is_trivially_copyable_v<FlagsType>) |
| 198 | [[nodiscard]] FlagsType Flags() const noexcept { | 197 | [[nodiscard]] FlagsType Flags() const noexcept { |
| 199 | FlagsType ret; | 198 | FlagsType ret; |
| 200 | std::memcpy(reinterpret_cast<char*>(&ret), &flags, sizeof(ret)); | 199 | std::memcpy(reinterpret_cast<char*>(&ret), &flags, sizeof(ret)); |
| 201 | return ret; | 200 | return ret; |
| 202 | } | 201 | } |
| 203 | 202 | ||
| 204 | template <typename FlagsType> | 203 | template <typename FlagsType> |
| 205 | requires(sizeof(FlagsType) <= sizeof(u32) && | 204 | requires(sizeof(FlagsType) <= sizeof(u32) && std::is_trivially_copyable_v<FlagsType>) |
| 206 | std::is_trivially_copyable_v<FlagsType>) void SetFlags(FlagsType value) noexcept { | 205 | void SetFlags(FlagsType value) noexcept { |
| 207 | std::memcpy(&flags, &value, sizeof(value)); | 206 | std::memcpy(&flags, &value, sizeof(value)); |
| 208 | } | 207 | } |
| 209 | 208 | ||
| @@ -268,7 +267,6 @@ using U8 = TypedValue<Type::U8>; | |||
| 268 | using U16 = TypedValue<Type::U16>; | 267 | using U16 = TypedValue<Type::U16>; |
| 269 | using U32 = TypedValue<Type::U32>; | 268 | using U32 = TypedValue<Type::U32>; |
| 270 | using U64 = TypedValue<Type::U64>; | 269 | using U64 = TypedValue<Type::U64>; |
| 271 | using S32 = TypedValue<Type::S32>; | ||
| 272 | using F16 = TypedValue<Type::F16>; | 270 | using F16 = TypedValue<Type::F16>; |
| 273 | using F32 = TypedValue<Type::F32>; | 271 | using F32 = TypedValue<Type::F32>; |
| 274 | using F64 = TypedValue<Type::F64>; | 272 | using F64 = TypedValue<Type::F64>; |
diff --git a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_query.cpp b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_query.cpp index f8cfd4ab6..39af62559 100644 --- a/src/shader_recompiler/frontend/maxwell/translate/impl/texture_query.cpp +++ b/src/shader_recompiler/frontend/maxwell/translate/impl/texture_query.cpp | |||
| @@ -15,11 +15,13 @@ enum class Mode : u64 { | |||
| 15 | SamplePos = 5, | 15 | SamplePos = 5, |
| 16 | }; | 16 | }; |
| 17 | 17 | ||
| 18 | IR::Value Query(TranslatorVisitor& v, const IR::U32& handle, Mode mode, IR::Reg src_reg) { | 18 | IR::Value Query(TranslatorVisitor& v, const IR::U32& handle, Mode mode, IR::Reg src_reg, u64 mask) { |
| 19 | switch (mode) { | 19 | switch (mode) { |
| 20 | case Mode::Dimension: { | 20 | case Mode::Dimension: { |
| 21 | const bool needs_num_mips{((mask >> 3) & 1) != 0}; | ||
| 22 | const IR::U1 skip_mips{v.ir.Imm1(!needs_num_mips)}; | ||
| 21 | const IR::U32 lod{v.X(src_reg)}; | 23 | const IR::U32 lod{v.X(src_reg)}; |
| 22 | return v.ir.ImageQueryDimension(handle, lod); | 24 | return v.ir.ImageQueryDimension(handle, lod, skip_mips); |
| 23 | } | 25 | } |
| 24 | case Mode::TextureType: | 26 | case Mode::TextureType: |
| 25 | case Mode::SamplePos: | 27 | case Mode::SamplePos: |
| @@ -46,7 +48,7 @@ void Impl(TranslatorVisitor& v, u64 insn, std::optional<u32> cbuf_offset) { | |||
| 46 | handle = v.X(src_reg); | 48 | handle = v.X(src_reg); |
| 47 | ++src_reg; | 49 | ++src_reg; |
| 48 | } | 50 | } |
| 49 | const IR::Value query{Query(v, handle, txq.mode, src_reg)}; | 51 | const IR::Value query{Query(v, handle, txq.mode, src_reg, txq.mask)}; |
| 50 | IR::Reg dest_reg{txq.dest_reg}; | 52 | IR::Reg dest_reg{txq.dest_reg}; |
| 51 | for (int element = 0; element < 4; ++element) { | 53 | for (int element = 0; element < 4; ++element) { |
| 52 | if (((txq.mask >> element) & 1) == 0) { | 54 | if (((txq.mask >> element) & 1) == 0) { |
diff --git a/src/shader_recompiler/ir_opt/texture_pass.cpp b/src/shader_recompiler/ir_opt/texture_pass.cpp index 9718c6921..d374c976a 100644 --- a/src/shader_recompiler/ir_opt/texture_pass.cpp +++ b/src/shader_recompiler/ir_opt/texture_pass.cpp | |||
| @@ -355,21 +355,21 @@ TextureInst MakeInst(Environment& env, IR::Block* block, IR::Inst& inst) { | |||
| 355 | }; | 355 | }; |
| 356 | } | 356 | } |
| 357 | 357 | ||
| 358 | TextureType ReadTextureType(Environment& env, const ConstBufferAddr& cbuf) { | 358 | u32 GetTextureHandle(Environment& env, const ConstBufferAddr& cbuf) { |
| 359 | const u32 secondary_index{cbuf.has_secondary ? cbuf.secondary_index : cbuf.index}; | 359 | const u32 secondary_index{cbuf.has_secondary ? cbuf.secondary_index : cbuf.index}; |
| 360 | const u32 secondary_offset{cbuf.has_secondary ? cbuf.secondary_offset : cbuf.offset}; | 360 | const u32 secondary_offset{cbuf.has_secondary ? cbuf.secondary_offset : cbuf.offset}; |
| 361 | const u32 lhs_raw{env.ReadCbufValue(cbuf.index, cbuf.offset) << cbuf.shift_left}; | 361 | const u32 lhs_raw{env.ReadCbufValue(cbuf.index, cbuf.offset) << cbuf.shift_left}; |
| 362 | const u32 rhs_raw{env.ReadCbufValue(secondary_index, secondary_offset) | 362 | const u32 rhs_raw{env.ReadCbufValue(secondary_index, secondary_offset) |
| 363 | << cbuf.secondary_shift_left}; | 363 | << cbuf.secondary_shift_left}; |
| 364 | return env.ReadTextureType(lhs_raw | rhs_raw); | 364 | return lhs_raw | rhs_raw; |
| 365 | } | ||
| 366 | |||
| 367 | TextureType ReadTextureType(Environment& env, const ConstBufferAddr& cbuf) { | ||
| 368 | return env.ReadTextureType(GetTextureHandle(env, cbuf)); | ||
| 365 | } | 369 | } |
| 366 | 370 | ||
| 367 | TexturePixelFormat ReadTexturePixelFormat(Environment& env, const ConstBufferAddr& cbuf) { | 371 | TexturePixelFormat ReadTexturePixelFormat(Environment& env, const ConstBufferAddr& cbuf) { |
| 368 | const u32 secondary_index{cbuf.has_secondary ? cbuf.secondary_index : cbuf.index}; | 372 | return env.ReadTexturePixelFormat(GetTextureHandle(env, cbuf)); |
| 369 | const u32 secondary_offset{cbuf.has_secondary ? cbuf.secondary_offset : cbuf.offset}; | ||
| 370 | const u32 lhs_raw{env.ReadCbufValue(cbuf.index, cbuf.offset)}; | ||
| 371 | const u32 rhs_raw{env.ReadCbufValue(secondary_index, secondary_offset)}; | ||
| 372 | return env.ReadTexturePixelFormat(lhs_raw | rhs_raw); | ||
| 373 | } | 373 | } |
| 374 | 374 | ||
| 375 | class Descriptors { | 375 | class Descriptors { |
| @@ -386,8 +386,10 @@ public: | |||
| 386 | return Add(texture_buffer_descriptors, desc, [&desc](const auto& existing) { | 386 | return Add(texture_buffer_descriptors, desc, [&desc](const auto& existing) { |
| 387 | return desc.cbuf_index == existing.cbuf_index && | 387 | return desc.cbuf_index == existing.cbuf_index && |
| 388 | desc.cbuf_offset == existing.cbuf_offset && | 388 | desc.cbuf_offset == existing.cbuf_offset && |
| 389 | desc.shift_left == existing.shift_left && | ||
| 389 | desc.secondary_cbuf_index == existing.secondary_cbuf_index && | 390 | desc.secondary_cbuf_index == existing.secondary_cbuf_index && |
| 390 | desc.secondary_cbuf_offset == existing.secondary_cbuf_offset && | 391 | desc.secondary_cbuf_offset == existing.secondary_cbuf_offset && |
| 392 | desc.secondary_shift_left == existing.secondary_shift_left && | ||
| 391 | desc.count == existing.count && desc.size_shift == existing.size_shift && | 393 | desc.count == existing.count && desc.size_shift == existing.size_shift && |
| 392 | desc.has_secondary == existing.has_secondary; | 394 | desc.has_secondary == existing.has_secondary; |
| 393 | }); | 395 | }); |
| @@ -405,15 +407,20 @@ public: | |||
| 405 | } | 407 | } |
| 406 | 408 | ||
| 407 | u32 Add(const TextureDescriptor& desc) { | 409 | u32 Add(const TextureDescriptor& desc) { |
| 408 | return Add(texture_descriptors, desc, [&desc](const auto& existing) { | 410 | const u32 index{Add(texture_descriptors, desc, [&desc](const auto& existing) { |
| 409 | return desc.type == existing.type && desc.is_depth == existing.is_depth && | 411 | return desc.type == existing.type && desc.is_depth == existing.is_depth && |
| 410 | desc.has_secondary == existing.has_secondary && | 412 | desc.has_secondary == existing.has_secondary && |
| 411 | desc.cbuf_index == existing.cbuf_index && | 413 | desc.cbuf_index == existing.cbuf_index && |
| 412 | desc.cbuf_offset == existing.cbuf_offset && | 414 | desc.cbuf_offset == existing.cbuf_offset && |
| 415 | desc.shift_left == existing.shift_left && | ||
| 413 | desc.secondary_cbuf_index == existing.secondary_cbuf_index && | 416 | desc.secondary_cbuf_index == existing.secondary_cbuf_index && |
| 414 | desc.secondary_cbuf_offset == existing.secondary_cbuf_offset && | 417 | desc.secondary_cbuf_offset == existing.secondary_cbuf_offset && |
| 418 | desc.secondary_shift_left == existing.secondary_shift_left && | ||
| 415 | desc.count == existing.count && desc.size_shift == existing.size_shift; | 419 | desc.count == existing.count && desc.size_shift == existing.size_shift; |
| 416 | }); | 420 | })}; |
| 421 | // TODO: Read this from TIC | ||
| 422 | texture_descriptors[index].is_multisample |= desc.is_multisample; | ||
| 423 | return index; | ||
| 417 | } | 424 | } |
| 418 | 425 | ||
| 419 | u32 Add(const ImageDescriptor& desc) { | 426 | u32 Add(const ImageDescriptor& desc) { |
| @@ -452,7 +459,8 @@ void PatchImageSampleImplicitLod(IR::Block& block, IR::Inst& inst) { | |||
| 452 | const IR::Value coord(inst.Arg(1)); | 459 | const IR::Value coord(inst.Arg(1)); |
| 453 | const IR::Value handle(ir.Imm32(0)); | 460 | const IR::Value handle(ir.Imm32(0)); |
| 454 | const IR::U32 lod{ir.Imm32(0)}; | 461 | const IR::U32 lod{ir.Imm32(0)}; |
| 455 | const IR::Value texture_size = ir.ImageQueryDimension(handle, lod, info); | 462 | const IR::U1 skip_mips{ir.Imm1(true)}; |
| 463 | const IR::Value texture_size = ir.ImageQueryDimension(handle, lod, skip_mips, info); | ||
| 456 | inst.SetArg( | 464 | inst.SetArg( |
| 457 | 1, ir.CompositeConstruct( | 465 | 1, ir.CompositeConstruct( |
| 458 | ir.FPMul(IR::F32(ir.CompositeExtract(coord, 0)), | 466 | ir.FPMul(IR::F32(ir.CompositeExtract(coord, 0)), |
| @@ -486,10 +494,10 @@ void PatchTexelFetch(IR::Block& block, IR::Inst& inst, TexturePixelFormat pixel_ | |||
| 486 | const IR::F32 w(ir.CompositeExtract(new_inst, 3)); | 494 | const IR::F32 w(ir.CompositeExtract(new_inst, 3)); |
| 487 | const IR::F16F32F64 max_value(ir.Imm32(get_max_value())); | 495 | const IR::F16F32F64 max_value(ir.Imm32(get_max_value())); |
| 488 | const IR::Value converted = | 496 | const IR::Value converted = |
| 489 | ir.CompositeConstruct(ir.FPMul(ir.ConvertSToF(32, 32, ir.BitCast<IR::S32>(x)), max_value), | 497 | ir.CompositeConstruct(ir.FPMul(ir.ConvertSToF(32, 32, ir.BitCast<IR::U32>(x)), max_value), |
| 490 | ir.FPMul(ir.ConvertSToF(32, 32, ir.BitCast<IR::S32>(y)), max_value), | 498 | ir.FPMul(ir.ConvertSToF(32, 32, ir.BitCast<IR::U32>(y)), max_value), |
| 491 | ir.FPMul(ir.ConvertSToF(32, 32, ir.BitCast<IR::S32>(z)), max_value), | 499 | ir.FPMul(ir.ConvertSToF(32, 32, ir.BitCast<IR::U32>(z)), max_value), |
| 492 | ir.FPMul(ir.ConvertSToF(32, 32, ir.BitCast<IR::S32>(w)), max_value)); | 500 | ir.FPMul(ir.ConvertSToF(32, 32, ir.BitCast<IR::U32>(w)), max_value)); |
| 493 | inst.ReplaceUsesWith(converted); | 501 | inst.ReplaceUsesWith(converted); |
| 494 | } | 502 | } |
| 495 | } // Anonymous namespace | 503 | } // Anonymous namespace |
diff --git a/src/shader_recompiler/object_pool.h b/src/shader_recompiler/object_pool.h index 2b42c4ba2..5d648b159 100644 --- a/src/shader_recompiler/object_pool.h +++ b/src/shader_recompiler/object_pool.h | |||
| @@ -10,7 +10,7 @@ | |||
| 10 | namespace Shader { | 10 | namespace Shader { |
| 11 | 11 | ||
| 12 | template <typename T> | 12 | template <typename T> |
| 13 | requires std::is_destructible_v<T> | 13 | requires std::is_destructible_v<T> |
| 14 | class ObjectPool { | 14 | class ObjectPool { |
| 15 | public: | 15 | public: |
| 16 | explicit ObjectPool(size_t chunk_size = 8192) : new_chunk_size{chunk_size} { | 16 | explicit ObjectPool(size_t chunk_size = 8192) : new_chunk_size{chunk_size} { |
| @@ -18,7 +18,7 @@ public: | |||
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | template <typename... Args> | 20 | template <typename... Args> |
| 21 | requires std::is_constructible_v<T, Args...> | 21 | requires std::is_constructible_v<T, Args...> |
| 22 | [[nodiscard]] T* Create(Args&&... args) { | 22 | [[nodiscard]] T* Create(Args&&... args) { |
| 23 | return std::construct_at(Memory(), std::forward<Args>(args)...); | 23 | return std::construct_at(Memory(), std::forward<Args>(args)...); |
| 24 | } | 24 | } |
diff --git a/src/video_core/texture_cache/descriptor_table.h b/src/video_core/texture_cache/descriptor_table.h index ee4240288..1bad83fb4 100644 --- a/src/video_core/texture_cache/descriptor_table.h +++ b/src/video_core/texture_cache/descriptor_table.h | |||
| @@ -19,9 +19,7 @@ public: | |||
| 19 | explicit DescriptorTable(Tegra::MemoryManager& gpu_memory_) : gpu_memory{gpu_memory_} {} | 19 | explicit DescriptorTable(Tegra::MemoryManager& gpu_memory_) : gpu_memory{gpu_memory_} {} |
| 20 | 20 | ||
| 21 | [[nodiscard]] bool Synchronize(GPUVAddr gpu_addr, u32 limit) { | 21 | [[nodiscard]] bool Synchronize(GPUVAddr gpu_addr, u32 limit) { |
| 22 | [[likely]] if (current_gpu_addr == gpu_addr && current_limit == limit) { | 22 | [[likely]] if (current_gpu_addr == gpu_addr && current_limit == limit) { return false; } |
| 23 | return false; | ||
| 24 | } | ||
| 25 | Refresh(gpu_addr, limit); | 23 | Refresh(gpu_addr, limit); |
| 26 | return true; | 24 | return true; |
| 27 | } | 25 | } |
diff --git a/src/video_core/texture_cache/image_info.cpp b/src/video_core/texture_cache/image_info.cpp index 852ec2519..e9100091e 100644 --- a/src/video_core/texture_cache/image_info.cpp +++ b/src/video_core/texture_cache/image_info.cpp | |||
| @@ -100,6 +100,10 @@ ImageInfo::ImageInfo(const TICEntry& config) noexcept { | |||
| 100 | ASSERT_MSG(false, "Invalid texture_type={}", static_cast<int>(config.texture_type.Value())); | 100 | ASSERT_MSG(false, "Invalid texture_type={}", static_cast<int>(config.texture_type.Value())); |
| 101 | break; | 101 | break; |
| 102 | } | 102 | } |
| 103 | if (num_samples > 1) { | ||
| 104 | size.width *= NumSamplesX(config.msaa_mode); | ||
| 105 | size.height *= NumSamplesY(config.msaa_mode); | ||
| 106 | } | ||
| 103 | if (type != ImageType::Linear) { | 107 | if (type != ImageType::Linear) { |
| 104 | // FIXME: Call this without passing *this | 108 | // FIXME: Call this without passing *this |
| 105 | layer_stride = CalculateLayerStride(*this); | 109 | layer_stride = CalculateLayerStride(*this); |
diff --git a/src/video_core/texture_cache/samples_helper.h b/src/video_core/texture_cache/samples_helper.h index d552bccf0..203ac1b11 100644 --- a/src/video_core/texture_cache/samples_helper.h +++ b/src/video_core/texture_cache/samples_helper.h | |||
| @@ -51,4 +51,48 @@ namespace VideoCommon { | |||
| 51 | return 1; | 51 | return 1; |
| 52 | } | 52 | } |
| 53 | 53 | ||
| 54 | [[nodiscard]] inline int NumSamplesX(Tegra::Texture::MsaaMode msaa_mode) { | ||
| 55 | using Tegra::Texture::MsaaMode; | ||
| 56 | switch (msaa_mode) { | ||
| 57 | case MsaaMode::Msaa1x1: | ||
| 58 | return 1; | ||
| 59 | case MsaaMode::Msaa2x1: | ||
| 60 | case MsaaMode::Msaa2x1_D3D: | ||
| 61 | case MsaaMode::Msaa2x2: | ||
| 62 | case MsaaMode::Msaa2x2_VC4: | ||
| 63 | case MsaaMode::Msaa2x2_VC12: | ||
| 64 | return 2; | ||
| 65 | case MsaaMode::Msaa4x2: | ||
| 66 | case MsaaMode::Msaa4x2_D3D: | ||
| 67 | case MsaaMode::Msaa4x2_VC8: | ||
| 68 | case MsaaMode::Msaa4x2_VC24: | ||
| 69 | case MsaaMode::Msaa4x4: | ||
| 70 | return 4; | ||
| 71 | } | ||
| 72 | ASSERT_MSG(false, "Invalid MSAA mode={}", static_cast<int>(msaa_mode)); | ||
| 73 | return 1; | ||
| 74 | } | ||
| 75 | |||
| 76 | [[nodiscard]] inline int NumSamplesY(Tegra::Texture::MsaaMode msaa_mode) { | ||
| 77 | using Tegra::Texture::MsaaMode; | ||
| 78 | switch (msaa_mode) { | ||
| 79 | case MsaaMode::Msaa1x1: | ||
| 80 | case MsaaMode::Msaa2x1: | ||
| 81 | case MsaaMode::Msaa2x1_D3D: | ||
| 82 | return 1; | ||
| 83 | case MsaaMode::Msaa2x2: | ||
| 84 | case MsaaMode::Msaa2x2_VC4: | ||
| 85 | case MsaaMode::Msaa2x2_VC12: | ||
| 86 | case MsaaMode::Msaa4x2: | ||
| 87 | case MsaaMode::Msaa4x2_D3D: | ||
| 88 | case MsaaMode::Msaa4x2_VC8: | ||
| 89 | case MsaaMode::Msaa4x2_VC24: | ||
| 90 | return 2; | ||
| 91 | case MsaaMode::Msaa4x4: | ||
| 92 | return 4; | ||
| 93 | } | ||
| 94 | ASSERT_MSG(false, "Invalid MSAA mode={}", static_cast<int>(msaa_mode)); | ||
| 95 | return 1; | ||
| 96 | } | ||
| 97 | |||
| 54 | } // namespace VideoCommon | 98 | } // namespace VideoCommon |
diff --git a/src/video_core/texture_cache/slot_vector.h b/src/video_core/texture_cache/slot_vector.h index 1e2aad76a..9df6a2903 100644 --- a/src/video_core/texture_cache/slot_vector.h +++ b/src/video_core/texture_cache/slot_vector.h | |||
| @@ -29,7 +29,7 @@ struct SlotId { | |||
| 29 | }; | 29 | }; |
| 30 | 30 | ||
| 31 | template <class T> | 31 | template <class T> |
| 32 | requires std::is_nothrow_move_assignable_v<T> && std::is_nothrow_move_constructible_v<T> | 32 | requires std::is_nothrow_move_assignable_v<T> && std::is_nothrow_move_constructible_v<T> |
| 33 | class SlotVector { | 33 | class SlotVector { |
| 34 | public: | 34 | public: |
| 35 | class Iterator { | 35 | class Iterator { |
diff --git a/src/yuzu/configuration/input_profiles.cpp b/src/yuzu/configuration/input_profiles.cpp index 9bb69cab1..41ef4250a 100644 --- a/src/yuzu/configuration/input_profiles.cpp +++ b/src/yuzu/configuration/input_profiles.cpp | |||
| @@ -58,13 +58,16 @@ std::vector<std::string> InputProfiles::GetInputProfileNames() { | |||
| 58 | std::vector<std::string> profile_names; | 58 | std::vector<std::string> profile_names; |
| 59 | profile_names.reserve(map_profiles.size()); | 59 | profile_names.reserve(map_profiles.size()); |
| 60 | 60 | ||
| 61 | for (const auto& [profile_name, config] : map_profiles) { | 61 | auto it = map_profiles.cbegin(); |
| 62 | while (it != map_profiles.cend()) { | ||
| 63 | const auto& [profile_name, config] = *it; | ||
| 62 | if (!ProfileExistsInFilesystem(profile_name)) { | 64 | if (!ProfileExistsInFilesystem(profile_name)) { |
| 63 | DeleteProfile(profile_name); | 65 | it = map_profiles.erase(it); |
| 64 | continue; | 66 | continue; |
| 65 | } | 67 | } |
| 66 | 68 | ||
| 67 | profile_names.push_back(profile_name); | 69 | profile_names.push_back(profile_name); |
| 70 | ++it; | ||
| 68 | } | 71 | } |
| 69 | 72 | ||
| 70 | std::stable_sort(profile_names.begin(), profile_names.end()); | 73 | std::stable_sort(profile_names.begin(), profile_names.end()); |
diff --git a/src/yuzu/multiplayer/direct_connect.cpp b/src/yuzu/multiplayer/direct_connect.cpp index cbd52da85..d71cc23a7 100644 --- a/src/yuzu/multiplayer/direct_connect.cpp +++ b/src/yuzu/multiplayer/direct_connect.cpp | |||
| @@ -81,20 +81,13 @@ void DirectConnectWindow::Connect() { | |||
| 81 | } | 81 | } |
| 82 | } | 82 | } |
| 83 | } | 83 | } |
| 84 | switch (static_cast<ConnectionType>(ui->connection_type->currentIndex())) { | 84 | if (!ui->ip->hasAcceptableInput()) { |
| 85 | case ConnectionType::TraversalServer: | 85 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::IP_ADDRESS_NOT_VALID); |
| 86 | break; | 86 | return; |
| 87 | case ConnectionType::IP: | 87 | } |
| 88 | if (!ui->ip->hasAcceptableInput()) { | 88 | if (!ui->port->hasAcceptableInput()) { |
| 89 | NetworkMessage::ErrorManager::ShowError( | 89 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::PORT_NOT_VALID); |
| 90 | NetworkMessage::ErrorManager::IP_ADDRESS_NOT_VALID); | 90 | return; |
| 91 | return; | ||
| 92 | } | ||
| 93 | if (!ui->port->hasAcceptableInput()) { | ||
| 94 | NetworkMessage::ErrorManager::ShowError(NetworkMessage::ErrorManager::PORT_NOT_VALID); | ||
| 95 | return; | ||
| 96 | } | ||
| 97 | break; | ||
| 98 | } | 91 | } |
| 99 | 92 | ||
| 100 | // Store settings | 93 | // Store settings |
diff --git a/src/yuzu/multiplayer/direct_connect.ui b/src/yuzu/multiplayer/direct_connect.ui index 57d6ec25a..0dd4e6829 100644 --- a/src/yuzu/multiplayer/direct_connect.ui +++ b/src/yuzu/multiplayer/direct_connect.ui | |||
| @@ -27,19 +27,10 @@ | |||
| 27 | <number>0</number> | 27 | <number>0</number> |
| 28 | </property> | 28 | </property> |
| 29 | <item> | 29 | <item> |
| 30 | <widget class="QComboBox" name="connection_type"> | ||
| 31 | <item> | ||
| 32 | <property name="text"> | ||
| 33 | <string>IP Address</string> | ||
| 34 | </property> | ||
| 35 | </item> | ||
| 36 | </widget> | ||
| 37 | </item> | ||
| 38 | <item> | ||
| 39 | <widget class="QWidget" name="ip_container" native="true"> | 30 | <widget class="QWidget" name="ip_container" native="true"> |
| 40 | <layout class="QHBoxLayout" name="ip_layout"> | 31 | <layout class="QHBoxLayout" name="ip_layout"> |
| 41 | <property name="leftMargin"> | 32 | <property name="leftMargin"> |
| 42 | <number>5</number> | 33 | <number>0</number> |
| 43 | </property> | 34 | </property> |
| 44 | <property name="topMargin"> | 35 | <property name="topMargin"> |
| 45 | <number>0</number> | 36 | <number>0</number> |
| @@ -53,17 +44,17 @@ | |||
| 53 | <item> | 44 | <item> |
| 54 | <widget class="QLabel" name="label_2"> | 45 | <widget class="QLabel" name="label_2"> |
| 55 | <property name="text"> | 46 | <property name="text"> |
| 56 | <string>IP</string> | 47 | <string>Server Address</string> |
| 57 | </property> | 48 | </property> |
| 58 | </widget> | 49 | </widget> |
| 59 | </item> | 50 | </item> |
| 60 | <item> | 51 | <item> |
| 61 | <widget class="QLineEdit" name="ip"> | 52 | <widget class="QLineEdit" name="ip"> |
| 62 | <property name="toolTip"> | 53 | <property name="toolTip"> |
| 63 | <string><html><head/><body><p>IPv4 address of the host</p></body></html></string> | 54 | <string><html><head/><body><p>Server address of the host</p></body></html></string> |
| 64 | </property> | 55 | </property> |
| 65 | <property name="maxLength"> | 56 | <property name="maxLength"> |
| 66 | <number>16</number> | 57 | <number>253</number> |
| 67 | </property> | 58 | </property> |
| 68 | </widget> | 59 | </widget> |
| 69 | </item> | 60 | </item> |
| @@ -85,6 +76,12 @@ | |||
| 85 | <property name="placeholderText"> | 76 | <property name="placeholderText"> |
| 86 | <string notr="true" extracomment="placeholder string that tells user default port">24872</string> | 77 | <string notr="true" extracomment="placeholder string that tells user default port">24872</string> |
| 87 | </property> | 78 | </property> |
| 79 | <property name="maximumSize"> | ||
| 80 | <size> | ||
| 81 | <width>65</width> | ||
| 82 | <height>50</height> | ||
| 83 | </size> | ||
| 84 | </property> | ||
| 88 | </widget> | 85 | </widget> |
| 89 | </item> | 86 | </item> |
| 90 | </layout> | 87 | </layout> |
diff --git a/src/yuzu/multiplayer/validation.h b/src/yuzu/multiplayer/validation.h index dd25af280..cbbe6757b 100644 --- a/src/yuzu/multiplayer/validation.h +++ b/src/yuzu/multiplayer/validation.h | |||
| @@ -38,11 +38,28 @@ private: | |||
| 38 | QRegularExpression(QStringLiteral("^[a-zA-Z0-9._ -]{4,20}")); | 38 | QRegularExpression(QStringLiteral("^[a-zA-Z0-9._ -]{4,20}")); |
| 39 | QRegularExpressionValidator nickname; | 39 | QRegularExpressionValidator nickname; |
| 40 | 40 | ||
| 41 | /// ipv4 address only | 41 | /// ipv4 / ipv6 / hostnames |
| 42 | // TODO remove this when we support hostnames in direct connect | ||
| 43 | QRegularExpression ip_regex = QRegularExpression(QStringLiteral( | 42 | QRegularExpression ip_regex = QRegularExpression(QStringLiteral( |
| 44 | "(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|" | 43 | // IPv4 regex |
| 45 | "2[0-4][0-9]|25[0-5])")); | 44 | "^((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$|" |
| 45 | // IPv6 regex | ||
| 46 | "^((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|" | ||
| 47 | "(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-" | ||
| 48 | "5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|" | ||
| 49 | "(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)" | ||
| 50 | "(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3})|:))|" | ||
| 51 | "(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]" | ||
| 52 | "\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|" | ||
| 53 | "(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[" | ||
| 54 | "0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|" | ||
| 55 | "(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[" | ||
| 56 | "0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|" | ||
| 57 | "(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[" | ||
| 58 | "0-4]\\d|1\\d\\d|[1-9]?\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:))|" | ||
| 59 | "(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?" | ||
| 60 | "\\d)(\\.(25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]?\\d)){3}))|:)))(%.+)?$|" | ||
| 61 | // Hostname regex | ||
| 62 | "^([a-zA-Z0-9]+(-[a-zA-Z0-9]+)*\\.)+[a-zA-Z]{2,}$")); | ||
| 46 | QRegularExpressionValidator ip; | 63 | QRegularExpressionValidator ip; |
| 47 | 64 | ||
| 48 | /// port must be between 0 and 65535 | 65 | /// port must be between 0 and 65535 |